Sms7BitEncodingTranslatorTest.java revision 1fe1dbf473755c4e812a1218f331759eccacb447
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.internal.telephony; 18 19import android.telephony.TelephonyManager; 20import android.test.suitebuilder.annotation.SmallTest; 21 22import java.io.UnsupportedEncodingException; 23import static org.mockito.Mockito.doReturn; 24import static org.junit.Assert.*; 25import org.junit.Before; 26import org.junit.Test; 27 28public class Sms7BitEncodingTranslatorTest extends TelephonyTest { 29 @Before 30 public void setUp() throws Exception { 31 logd("+Setup!"); 32 super.setUp(getClass().getSimpleName()); 33 logd("-Setup!"); 34 } 35 36 @Test 37 @SmallTest 38 public void testNoTranslate() { 39 assertEquals("123", Sms7BitEncodingTranslator.translate("123")); 40 } 41 42 @Test 43 @SmallTest 44 public void testCommonTranslate() { 45 String s = null; 46 try { 47 s = new String(new byte[]{(byte)0x00, (byte)0xD3, 48 (byte)0x00, (byte)0xCF, (byte)0x01, (byte)0x04}, "UTF-16"); 49 } catch (UnsupportedEncodingException e) { 50 fail(e.toString()); 51 } 52 assertEquals("OIA", Sms7BitEncodingTranslator.translate(s)); 53 } 54 55 @Test 56 @SmallTest 57 public void testGsmTranslate() { 58 String s = null; 59 try { 60 s = new String(new byte[]{(byte)0x22, (byte)0x1A, 61 (byte)0x21, (byte)0x22, (byte)0x00, (byte)0xE7}, "UTF-16"); 62 } catch (UnsupportedEncodingException e) { 63 fail(e.toString()); 64 } 65 assertEquals("??Ç", Sms7BitEncodingTranslator.translate(s)); 66 } 67 68 @Test 69 @SmallTest 70 public void testCdmaTranslate() { 71 72 TelephonyManager telephonyManager = TelephonyManager.from(mContextFixture.getTestDouble()); 73 doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(telephonyManager).getCurrentPhoneType(); 74 75 String s = null; 76 try { 77 s = new String(new byte[]{(byte)0x00, (byte)0xD2, 78 (byte)0x00, (byte)0xD9, (byte)0x00, (byte)0xE7}, "UTF-16"); 79 } catch (UnsupportedEncodingException e) { 80 fail(e.toString()); 81 } 82 assertEquals("OUc", Sms7BitEncodingTranslator.translate(s)); 83 } 84}