Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fe1dbf4 authored by Jack Yu's avatar Jack Yu
Browse files

Added Sms 7-bit encoding translation unit tests

bug: 25691379
Change-Id: Ic362c92a699390cb69299992b1f7155d8712f5e5
parent 0efec89b
Loading
Loading
Loading
Loading
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;

import java.io.UnsupportedEncodingException;
import static org.mockito.Mockito.doReturn;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

public class Sms7BitEncodingTranslatorTest extends TelephonyTest {
    @Before
    public void setUp() throws Exception {
        logd("+Setup!");
        super.setUp(getClass().getSimpleName());
        logd("-Setup!");
    }

    @Test
    @SmallTest
    public void testNoTranslate() {
        assertEquals("123", Sms7BitEncodingTranslator.translate("123"));
    }

    @Test
    @SmallTest
    public void testCommonTranslate() {
        String s = null;
        try {
            s = new String(new byte[]{(byte)0x00, (byte)0xD3,
                    (byte)0x00, (byte)0xCF, (byte)0x01, (byte)0x04}, "UTF-16");
        } catch (UnsupportedEncodingException e) {
            fail(e.toString());
        }
        assertEquals("OIA", Sms7BitEncodingTranslator.translate(s));
    }

    @Test
    @SmallTest
    public void testGsmTranslate() {
        String s = null;
        try {
            s = new String(new byte[]{(byte)0x22, (byte)0x1A,
                    (byte)0x21, (byte)0x22, (byte)0x00, (byte)0xE7}, "UTF-16");
        } catch (UnsupportedEncodingException e) {
            fail(e.toString());
        }
        assertEquals("??Ç", Sms7BitEncodingTranslator.translate(s));
    }

    @Test
    @SmallTest
    public void testCdmaTranslate() {

        TelephonyManager telephonyManager = TelephonyManager.from(mContextFixture.getTestDouble());
        doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(telephonyManager).getCurrentPhoneType();

        String s = null;
        try {
            s = new String(new byte[]{(byte)0x00, (byte)0xD2,
                    (byte)0x00, (byte)0xD9, (byte)0x00, (byte)0xE7}, "UTF-16");
        } catch (UnsupportedEncodingException e) {
            fail(e.toString());
        }
        assertEquals("OUc", Sms7BitEncodingTranslator.translate(s));
    }
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.CellLocation;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.test.suitebuilder.annotation.SmallTest;
@@ -155,6 +156,11 @@ public abstract class TelephonyTest {
        mContextFixture = new ContextFixture();
        mPhone.mCi = mSimulatedCommands;

        field = TelephonyManager.class.getDeclaredField("sInstance");
        field.setAccessible(true);
        field.set(null, mContextFixture.getTestDouble().
                getSystemService(Context.TELEPHONY_SERVICE));

        doReturn(mSST).when(mTelephonyComponentFactory).
                makeServiceStateTracker(any(GsmCdmaPhone.class), any(CommandsInterface.class));
        doReturn(mIccCardProxy).when(mTelephonyComponentFactory).