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.platform.test.annotations.Postsubmit; 20import android.test.suitebuilder.annotation.SmallTest; 21 22import org.junit.After; 23import org.junit.Before; 24import org.junit.Test; 25import org.mockito.Mock; 26 27import java.io.UnsupportedEncodingException; 28 29import static org.junit.Assert.assertEquals; 30import static org.junit.Assert.fail; 31import static org.mockito.Matchers.anyInt; 32import static org.mockito.Mockito.doReturn; 33 34public class Sms7BitEncodingTranslatorTest extends TelephonyTest { 35 36 @Mock 37 UiccSmsController mUiccSmsController; 38 39 @Before 40 public void setUp() throws Exception { 41 logd("+Setup!"); 42 super.setUp(getClass().getSimpleName()); 43 mServiceManagerMockedServices.put("isms", mUiccSmsController); 44 doReturn(false).when(mUiccSmsController).isImsSmsSupportedForSubscriber(anyInt()); 45 logd("-Setup!"); 46 } 47 48 @After 49 public void tearDown() throws Exception { 50 super.tearDown(); 51 } 52 53 @Postsubmit 54 @Test 55 @SmallTest 56 public void testNoTranslate() { 57 assertEquals("123", Sms7BitEncodingTranslator.translate("123")); 58 } 59 60 @Postsubmit 61 @Test 62 @SmallTest 63 public void testCommonTranslate() { 64 String s = null; 65 try { 66 s = new String(new byte[]{(byte)0x00, (byte)0xD3, 67 (byte)0x00, (byte)0xCF, (byte)0x01, (byte)0x04}, "UTF-16"); 68 } catch (UnsupportedEncodingException e) { 69 fail(e.toString()); 70 } 71 assertEquals("OIA", Sms7BitEncodingTranslator.translate(s)); 72 } 73 74 @Postsubmit 75 @Test 76 @SmallTest 77 public void testGsmTranslate() { 78 String s = null; 79 try { 80 s = new String(new byte[]{(byte)0x22, (byte)0x1A, 81 (byte)0x21, (byte)0x22, (byte)0x00, (byte)0xE7}, "UTF-16"); 82 } catch (UnsupportedEncodingException e) { 83 fail(e.toString()); 84 } 85 assertEquals("??Ç", Sms7BitEncodingTranslator.translate(s)); 86 } 87 88 @Postsubmit 89 @Test 90 @SmallTest 91 public void testCdmaTranslate() { 92 93 doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getCurrentPhoneType(); 94 95 String s = null; 96 try { 97 s = new String(new byte[]{(byte)0x00, (byte)0xD2, 98 (byte)0x00, (byte)0xD9, (byte)0x00, (byte)0xE7}, "UTF-16"); 99 } catch (UnsupportedEncodingException e) { 100 fail(e.toString()); 101 } 102 assertEquals("OUc", Sms7BitEncodingTranslator.translate(s)); 103 } 104}