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