From 04e71b3db84fd5f7fc4eefb49a33154ea91ec9fc Mon Sep 17 00:00:00 2001 From: Wink Saville <> Date: Thu, 2 Apr 2009 11:00:54 -0700 Subject: AI 144245: Fix merge conflict for megering in the CDMA changes in to master from donutburger. Automated import of CL 144245 --- .../src/com/android/unit_tests/SMSTest.java | 6 +- .../android/internal/telephony/AdnRecordTest.java | 176 ++++++++++++ .../internal/telephony/GsmAlphabetTest.java | 309 +++++++++++++++++++++ .../internal/telephony/SMSDispatcherTest.java | 97 +++++++ .../internal/telephony/SimPhoneBookTest.java | 106 +++++++ .../com/android/internal/telephony/SimSmsTest.java | 60 ++++ .../android/internal/telephony/SimUtilsTest.java | 79 ++++++ .../android/internal/telephony/TelephonyTests.java | 12 +- .../internal/telephony/gsm/AdnRecordTest.java | 176 ------------ .../internal/telephony/gsm/GsmAlphabetTest.java | 309 --------------------- .../internal/telephony/gsm/SMSDispatcherTest.java | 97 ------- .../internal/telephony/gsm/SimPhoneBookTest.java | 106 ------- .../android/internal/telephony/gsm/SimSmsTest.java | 60 ---- .../internal/telephony/gsm/SimUtilsTest.java | 79 ------ .../policy/impl/LockPatternKeyguardViewTest.java | 9 +- 15 files changed, 840 insertions(+), 841 deletions(-) create mode 100644 tests/CoreTests/com/android/internal/telephony/AdnRecordTest.java create mode 100644 tests/CoreTests/com/android/internal/telephony/GsmAlphabetTest.java create mode 100644 tests/CoreTests/com/android/internal/telephony/SMSDispatcherTest.java create mode 100644 tests/CoreTests/com/android/internal/telephony/SimPhoneBookTest.java create mode 100644 tests/CoreTests/com/android/internal/telephony/SimSmsTest.java create mode 100644 tests/CoreTests/com/android/internal/telephony/SimUtilsTest.java delete mode 100644 tests/CoreTests/com/android/internal/telephony/gsm/AdnRecordTest.java delete mode 100644 tests/CoreTests/com/android/internal/telephony/gsm/GsmAlphabetTest.java delete mode 100644 tests/CoreTests/com/android/internal/telephony/gsm/SMSDispatcherTest.java delete mode 100644 tests/CoreTests/com/android/internal/telephony/gsm/SimPhoneBookTest.java delete mode 100644 tests/CoreTests/com/android/internal/telephony/gsm/SimSmsTest.java delete mode 100644 tests/CoreTests/com/android/internal/telephony/gsm/SimUtilsTest.java (limited to 'tests') diff --git a/tests/AndroidTests/src/com/android/unit_tests/SMSTest.java b/tests/AndroidTests/src/com/android/unit_tests/SMSTest.java index ce0b53d..360352b 100644 --- a/tests/AndroidTests/src/com/android/unit_tests/SMSTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/SMSTest.java @@ -16,10 +16,10 @@ package com.android.unit_tests; -import com.android.internal.telephony.gsm.GsmAlphabet; -import com.android.internal.telephony.gsm.SmsHeader; +import com.android.internal.telephony.GsmAlphabet; +import com.android.internal.telephony.SmsHeader; +import com.android.internal.telephony.gsm.SmsMessage; import com.android.internal.util.HexDump; -import android.telephony.gsm.SmsMessage; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; diff --git a/tests/CoreTests/com/android/internal/telephony/AdnRecordTest.java b/tests/CoreTests/com/android/internal/telephony/AdnRecordTest.java new file mode 100644 index 0000000..8a4a285 --- /dev/null +++ b/tests/CoreTests/com/android/internal/telephony/AdnRecordTest.java @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2006 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 junit.framework.TestCase; +import android.test.suitebuilder.annotation.SmallTest; + +/** + * {@hide} + */ +public class AdnRecordTest extends TestCase { + + @SmallTest + public void testBasic() throws Exception { + AdnRecord adn; + + // + // Typical record + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C07918150367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("+18056377243", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // Empty records, empty strings + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")); + + assertEquals("", adn.getAlphaTag()); + assertEquals("", adn.getNumber()); + assertTrue(adn.isEmpty()); + + // + // Record too short + // + adn = new AdnRecord(IccUtils.hexStringToBytes( "FF")); + + assertEquals("", adn.getAlphaTag()); + assertEquals("", adn.getNumber()); + assertTrue(adn.isEmpty()); + + // + // TOA = 0xff ("control string") + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C07FF8150367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("18056377243", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // TOA = 0x81 (unknown) + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C07818150367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("18056377243", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // Number Length is too long + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C0F918150367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // Number Length is zero (invalid) + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C00918150367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // Number Length is 2, first number byte is FF, TOA is international + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C0291FF50367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // Number Length is 2, first number digit is valid, TOA is international + // + adn = new AdnRecord( + IccUtils.hexStringToBytes("566F696365204D61696C0291F150367742F3FFFFFFFFFFFF")); + + assertEquals("Voice Mail", adn.getAlphaTag()); + assertEquals("+1", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // An extended record + // + adn = new AdnRecord( + IccUtils.hexStringToBytes( + "4164676A6DFFFFFFFFFFFFFFFFFFFFFF0B918188551512C221436587FF01")); + + assertEquals("Adgjm", adn.getAlphaTag()); + assertEquals("+18885551212,12345678", adn.getNumber()); + assertFalse(adn.isEmpty()); + assertTrue(adn.hasExtendedRecord()); + + adn.appendExtRecord(IccUtils.hexStringToBytes("0206092143658709ffffffffff")); + + assertEquals("Adgjm", adn.getAlphaTag()); + assertEquals("+18885551212,12345678901234567890", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // An extended record with an invalid extension + // + adn = new AdnRecord( + IccUtils.hexStringToBytes( + "4164676A6DFFFFFFFFFFFFFFFFFFFFFF0B918188551512C221436587FF01")); + + assertEquals("Adgjm", adn.getAlphaTag()); + assertEquals("+18885551212,12345678", adn.getNumber()); + assertFalse(adn.isEmpty()); + assertTrue(adn.hasExtendedRecord()); + + adn.appendExtRecord(IccUtils.hexStringToBytes("0106092143658709ffffffffff")); + + assertEquals("Adgjm", adn.getAlphaTag()); + assertEquals("+18885551212,12345678", adn.getNumber()); + assertFalse(adn.isEmpty()); + + // + // An extended record with an invalid extension + // + adn = new AdnRecord( + IccUtils.hexStringToBytes( + "4164676A6DFFFFFFFFFFFFFFFFFFFFFF0B918188551512C221436587FF01")); + + assertEquals("Adgjm", adn.getAlphaTag()); + assertEquals("+18885551212,12345678", adn.getNumber()); + assertFalse(adn.isEmpty()); + assertTrue(adn.hasExtendedRecord()); + + adn.appendExtRecord(IccUtils.hexStringToBytes("020B092143658709ffffffffff")); + + assertEquals("Adgjm", adn.getAlphaTag()); + assertEquals("+18885551212,12345678", adn.getNumber()); + assertFalse(adn.isEmpty()); + } +} + + diff --git a/tests/CoreTests/com/android/internal/telephony/GsmAlphabetTest.java b/tests/CoreTests/com/android/internal/telephony/GsmAlphabetTest.java new file mode 100644 index 0000000..5df8991 --- /dev/null +++ b/tests/CoreTests/com/android/internal/telephony/GsmAlphabetTest.java @@ -0,0 +1,309 @@ +/* + * Copyright (C) 2006 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 junit.framework.TestCase; + +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.SmallTest; +import android.test.suitebuilder.annotation.Suppress; + +public class GsmAlphabetTest extends TestCase { + + private static final String sGsmExtendedChars = "{|}\\[~]\f\u20ac"; + + @SmallTest + public void test7bitWithHeader() throws Exception { + byte[] data = new byte[3]; + data[0] = (byte) 1; + data[1] = (byte) 2; + data[2] = (byte) 2; + SmsHeader header = new SmsHeader(); + header.add(new SmsHeader.Element(SmsHeader.CONCATENATED_8_BIT_REFERENCE, data)); + + String message = "aaaaaaaaaabbbbbbbbbbcccccccccc"; + byte[] userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header.toByteArray()); + int septetCount = GsmAlphabet.countGsmSeptets(message, false); + String parsedMessage = GsmAlphabet.gsm7BitPackedToString( + userData, header.toByteArray().length+1, septetCount, 1); + assertEquals(message, parsedMessage); + } + + // TODO: This method should *really* be a series of individual test methods. + @LargeTest + public void testBasic() throws Exception { + // '@' maps to char 0 + assertEquals(0, GsmAlphabet.charToGsm('@')); + + // `a (a with grave accent) maps to last GSM charater + assertEquals(0x7f, GsmAlphabet.charToGsm('\u00e0')); + + // + // These are the extended chars + // They should all return GsmAlphabet.GSM_EXTENDED_ESCAPE + // + + for (int i = 0, s = sGsmExtendedChars.length(); i < s; i++) { + assertEquals(GsmAlphabet.GSM_EXTENDED_ESCAPE, + GsmAlphabet.charToGsm(sGsmExtendedChars.charAt(i))); + + } + + // euro symbol + assertEquals(GsmAlphabet.GSM_EXTENDED_ESCAPE, + GsmAlphabet.charToGsm('\u20ac')); + + // An unmappable char (the 'cent' char) maps to a space + assertEquals(GsmAlphabet.charToGsm(' '), + GsmAlphabet.charToGsm('\u00a2')); + + // unmappable = space = 1 septet + assertEquals(1, GsmAlphabet.countGsmSeptets('\u00a2')); + + // + // Test extended table + // + + for (int i = 0, s = sGsmExtendedChars.length(); i < s; i++) { + assertEquals(sGsmExtendedChars.charAt(i), + GsmAlphabet.gsmExtendedToChar( + GsmAlphabet.charToGsmExtended(sGsmExtendedChars.charAt(i)))); + + } + + // Unmappable extended char + assertEquals(GsmAlphabet.charToGsm(' '), + GsmAlphabet.charToGsmExtended('@')); + + // + // gsmToChar() + // + + assertEquals('@', GsmAlphabet.gsmToChar(0)); + + // `a (a with grave accent) maps to last GSM charater + assertEquals('\u00e0', GsmAlphabet.gsmToChar(0x7f)); + + assertEquals('\uffff', + GsmAlphabet.gsmToChar(GsmAlphabet.GSM_EXTENDED_ESCAPE)); + + // Out-of-range/unmappable value + assertEquals(' ', GsmAlphabet.gsmToChar(0x80)); + + // + // gsmExtendedToChar() + // + + assertEquals('{', GsmAlphabet.gsmExtendedToChar(0x28)); + + // No double-escapes + assertEquals(' ', GsmAlphabet.gsmExtendedToChar( + GsmAlphabet.GSM_EXTENDED_ESCAPE)); + + // Unmappable + assertEquals(' ', GsmAlphabet.gsmExtendedToChar(0)); + + // + // stringTo7BitPacked, gsm7BitPackedToString + // + + byte[] packed; + StringBuilder testString = new StringBuilder(300); + + // Check all alignment cases + for (int i = 0; i < 9; i++, testString.append('@')) { + packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + assertEquals(testString.toString(), + GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); + } + + // Check full non-extended alphabet + for (int i = 0; i < 0x80; i++) { + char c; + + if (i == GsmAlphabet.GSM_EXTENDED_ESCAPE) { + continue; + } + + c = GsmAlphabet.gsmToChar(i); + testString.append(c); + + // These are all non-extended chars, so it should be + // one septet per char + assertEquals(1, GsmAlphabet.countGsmSeptets(c)); + } + + packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + assertEquals(testString.toString(), + GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); + + // Test extended chars too + + testString.append(sGsmExtendedChars); + + for (int i = 0, s = sGsmExtendedChars.length(); i < s; i++) { + // These are all extended chars, so it should be + // two septets per char + assertEquals(2, GsmAlphabet.countGsmSeptets(sGsmExtendedChars.charAt(i))); + + } + + packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + assertEquals(testString.toString(), + GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); + + // stringTo7BitPacked handles up to 255 septets + + testString.setLength(0); + for (int i = 0; i < 255; i++) { + testString.append('@'); + } + + packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + assertEquals(testString.toString(), + GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); + + // > 255 septets throws runtime exception + testString.append('@'); + + try { + GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + fail("expected exception"); + } catch (EncodeException ex) { + // exception expected + } + + // Try 254 septets with 127 extended chars + + testString.setLength(0); + for (int i = 0; i < (255 / 2); i++) { + testString.append('{'); + } + + packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + assertEquals(testString.toString(), + GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); + + // > 255 septets throws runtime exception + testString.append('{'); + + try { + GsmAlphabet.stringToGsm7BitPacked(testString.toString()); + fail("expected exception"); + } catch (EncodeException ex) { + // exception expected + } + + // + // 8 bit unpacked format + // + // Note: we compare hex strings here + // because Assert doesnt have array-comparisons + + byte unpacked[]; + + unpacked = IccUtils.hexStringToBytes("566F696365204D61696C"); + assertEquals("Voice Mail", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + assertEquals(IccUtils.bytesToHexString(unpacked), + IccUtils.bytesToHexString( + GsmAlphabet.stringToGsm8BitPacked("Voice Mail"))); + + unpacked = GsmAlphabet.stringToGsm8BitPacked(sGsmExtendedChars); + // two bytes for every extended char + assertEquals(2 * sGsmExtendedChars.length(), unpacked.length); + assertEquals(sGsmExtendedChars, + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + // should be two bytes per extended char + assertEquals(2 * sGsmExtendedChars.length(), unpacked.length); + + // Test truncation of unaligned extended chars + unpacked = new byte[3]; + GsmAlphabet.stringToGsm8BitUnpackedField(sGsmExtendedChars, unpacked, + 0, unpacked.length); + + // Should be one extended char and an 0xff at the end + + assertEquals(0xff, 0xff & unpacked[2]); + assertEquals(sGsmExtendedChars.substring(0, 1), + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + // Test truncation of normal chars + unpacked = new byte[3]; + GsmAlphabet.stringToGsm8BitUnpackedField("abcd", unpacked, + 0, unpacked.length); + + assertEquals("abc", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + // Test truncation of mixed normal and extended chars + unpacked = new byte[3]; + GsmAlphabet.stringToGsm8BitUnpackedField("a{cd", unpacked, + 0, unpacked.length); + + assertEquals("a{", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + // Test padding after normal char + unpacked = new byte[3]; + GsmAlphabet.stringToGsm8BitUnpackedField("a", unpacked, + 0, unpacked.length); + + assertEquals("a", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + assertEquals(0xff, 0xff & unpacked[1]); + assertEquals(0xff, 0xff & unpacked[2]); + + // Test malformed input -- escape char followed by end of field + unpacked[0] = 0; + unpacked[1] = 0; + unpacked[2] = GsmAlphabet.GSM_EXTENDED_ESCAPE; + + assertEquals("@@", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); + + // non-zero offset + assertEquals("@", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1)); + + // test non-zero offset + unpacked[0] = 0; + GsmAlphabet.stringToGsm8BitUnpackedField("abcd", unpacked, + 1, unpacked.length - 1); + + + assertEquals(0, unpacked[0]); + + assertEquals("ab", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1)); + + // test non-zero offset with truncated extended char + unpacked[0] = 0; + + GsmAlphabet.stringToGsm8BitUnpackedField("a{", unpacked, + 1, unpacked.length - 1); + + assertEquals(0, unpacked[0]); + + assertEquals("a", + GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1)); + } +} + diff --git a/tests/CoreTests/com/android/internal/telephony/SMSDispatcherTest.java b/tests/CoreTests/com/android/internal/telephony/SMSDispatcherTest.java new file mode 100644 index 0000000..5d5d1f9 --- /dev/null +++ b/tests/CoreTests/com/android/internal/telephony/SMSDispatcherTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2007 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.test.suitebuilder.annotation.MediumTest; +import com.android.internal.telephony.TestPhoneNotifier; +import com.android.internal.telephony.gsm.SmsMessage; +import com.android.internal.telephony.test.SimulatedCommands; +import com.android.internal.telephony.test.SimulatedRadioControl; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.Suppress; + +import java.util.Iterator; + +/** + * {@hide} + */ +public class SMSDispatcherTest extends AndroidTestCase { + @MediumTest + public void testCMT1() throws Exception { + SmsMessage sms; + SmsHeader header; + Iterator elements; + + String[] lines = new String[2]; + + lines[0] = "+CMT: ,158"; + lines[1] = "07914140279510F6440A8111110301003BF56080426101748A8C0B05040B" + + "8423F000035502010106276170706C69636174696F6E2F766E642E776170" + + "2E6D6D732D6D65737361676500AF848D0185B4848C8298524F347839776F" + + "7547514D4141424C3641414141536741415A4B554141414141008D908918" + + "802B31363530323438363137392F545950453D504C4D4E008A808E028000" + + "88058103093A8083687474703A2F2F36"; + + sms = SmsMessage.newFromCMT(lines); + header = sms.getUserDataHeader(); + assertNotNull(header); + assertNotNull(sms.getUserData()); + + elements = header.getElements().iterator(); + assertNotNull(elements); + } + + @MediumTest + public void testCMT2() throws Exception { + SmsMessage sms; + SmsHeader header; + Iterator elements; + + String[] lines = new String[2]; + + + lines[0] = "+CMT: ,77"; + lines[1] = "07914140279510F6440A8111110301003BF56080426101848A3B0B05040B8423F" + + "00003550202362E3130322E3137312E3135302F524F347839776F7547514D4141" + + "424C3641414141536741415A4B55414141414100"; + + sms = SmsMessage.newFromCMT(lines); + header = sms.getUserDataHeader(); + System.out.println("header = " + header); + assertNotNull(header); + assertNotNull(sms.getUserData()); + + elements = header.getElements().iterator(); + assertNotNull(elements); + } + + @MediumTest + public void testEfRecord() throws Exception { + SmsMessage sms; + + String s = "03029111000c9194981492631000f269206190022000a053e4534a05358bd3" + + "69f05804259da0219418a40641536a110a0aea408080604028180e888462c1" + + "50341c0f484432a1542c174c46b3e1743c9f9068442a994ea8946ac56ab95e" + + "b0986c46abd96eb89c6ec7ebf97ec0a070482c1a8fc8a472c96c3a9fd0a874" + + "4aad5aafd8ac76cbed7abfe0b0784c2e9bcfe8b47acd6ebbdff0b87c4eafdb" + + "eff8bc7ecfeffbffffffffffffffffffffffffffff"; + byte[] data = IccUtils.hexStringToBytes(s); + + sms = SmsMessage.createFromEfRecord(1, data); + assertNotNull(sms.getMessageBody()); + } +} diff --git a/tests/CoreTests/com/android/internal/telephony/SimPhoneBookTest.java b/tests/CoreTests/com/android/internal/telephony/SimPhoneBookTest.java new file mode 100644 index 0000000..609e768 --- /dev/null +++ b/tests/CoreTests/com/android/internal/telephony/SimPhoneBookTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2006 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.os.ServiceManager; +import android.test.suitebuilder.annotation.Suppress; + +import java.util.List; + +import junit.framework.TestCase; + +@Suppress +public class SimPhoneBookTest extends TestCase { + + public void testBasic() throws Exception { + IIccPhoneBook simPhoneBook = + IIccPhoneBook.Stub.asInterface(ServiceManager.getService("simphonebook")); + assertNotNull(simPhoneBook); + + int size[] = simPhoneBook.getAdnRecordsSize(IccConstants.EF_ADN); + assertNotNull(size); + assertEquals(3, size.length); + assertEquals(size[0] * size[2], size[1]); + assertTrue(size[2] >= 100); + + List adnRecordList = simPhoneBook.getAdnRecordsInEf(IccConstants.EF_ADN); + // do it twice cause the second time shall read from cache only + adnRecordList = simPhoneBook.getAdnRecordsInEf(IccConstants.EF_ADN); + assertNotNull(adnRecordList); + + // Test for phone book update + int adnIndex, listIndex = 0; + AdnRecord originalAdn = null; + // We need to maintain the state of the SIM before and after the test. + // Since this test doesn't mock the SIM we try to get a valid ADN record, + // for 3 tries and if this fails, we bail out. + for (adnIndex = 3 ; adnIndex >= 1; adnIndex--) { + listIndex = adnIndex - 1; // listIndex is zero based. + originalAdn = adnRecordList.get(listIndex); + assertNotNull("Original Adn is Null.", originalAdn); + assertNotNull("Original Adn alpha tag is null.", originalAdn.getAlphaTag()); + assertNotNull("Original Adn number is null.", originalAdn.getNumber()); + + if (originalAdn.getNumber().length() > 0 && + originalAdn.getAlphaTag().length() > 0) { + break; + } + } + if (adnIndex == 0) return; + + AdnRecord emptyAdn = new AdnRecord("", ""); + AdnRecord firstAdn = new AdnRecord("John", "4085550101"); + AdnRecord secondAdn = new AdnRecord("Andy", "6505550102"); + String pin2 = null; + + // udpate by index + boolean success = simPhoneBook.updateAdnRecordsInEfByIndex(IccConstants.EF_ADN, + firstAdn.getAlphaTag(), firstAdn.getNumber(), adnIndex, pin2); + adnRecordList = simPhoneBook.getAdnRecordsInEf(IccConstants.EF_ADN); + AdnRecord tmpAdn = adnRecordList.get(listIndex); + assertTrue(success); + assertTrue(firstAdn.isEqual(tmpAdn)); + + // replace by search + success = simPhoneBook.updateAdnRecordsInEfBySearch(IccConstants.EF_ADN, + firstAdn.getAlphaTag(), firstAdn.getNumber(), + secondAdn.getAlphaTag(), secondAdn.getNumber(), pin2); + adnRecordList = simPhoneBook.getAdnRecordsInEf(IccConstants.EF_ADN); + tmpAdn = adnRecordList.get(listIndex); + assertTrue(success); + assertFalse(firstAdn.isEqual(tmpAdn)); + assertTrue(secondAdn.isEqual(tmpAdn)); + + // erase be search + success = simPhoneBook.updateAdnRecordsInEfBySearch(IccConstants.EF_ADN, + secondAdn.getAlphaTag(), secondAdn.getNumber(), + emptyAdn.getAlphaTag(), emptyAdn.getNumber(), pin2); + adnRecordList = simPhoneBook.getAdnRecordsInEf(IccConstants.EF_ADN); + tmpAdn = adnRecordList.get(listIndex); + assertTrue(success); + assertTrue(tmpAdn.isEmpty()); + + // restore the orginial adn + success = simPhoneBook.updateAdnRecordsInEfByIndex(IccConstants.EF_ADN, + originalAdn.getAlphaTag(), originalAdn.getNumber(), adnIndex, + pin2); + adnRecordList = simPhoneBook.getAdnRecordsInEf(IccConstants.EF_ADN); + tmpAdn = adnRecordList.get(listIndex); + assertTrue(success); + assertTrue(originalAdn.isEqual(tmpAdn)); + } +} diff --git a/tests/CoreTests/com/android/internal/telephony/SimSmsTest.java b/tests/CoreTests/com/android/internal/telephony/SimSmsTest.java new file mode 100644 index 0000000..1609680 --- /dev/null +++ b/tests/CoreTests/com/android/internal/telephony/SimSmsTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2006 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.os.ServiceManager; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; + +import java.util.List; + +import junit.framework.TestCase; + +public class SimSmsTest extends TestCase { + + @MediumTest + @Suppress // TODO: suppress this test for now since it doesn't work on the emulator + public void testBasic() throws Exception { + + ISms sms = ISms.Stub.asInterface(ServiceManager.getService("isms")); + assertNotNull(sms); + + List records = sms.getAllMessagesFromIccEf(); + assertNotNull(records); + assertTrue(records.size() >= 0); + + int firstNullIndex = -1; + int firstValidIndex = -1; + byte[] pdu = null; + for (int i = 0; i < records.size(); i++) { + SmsRawData data = records.get(i); + if (data != null && firstValidIndex == -1) { + firstValidIndex = i; + pdu = data.getBytes(); + } + if (data == null && firstNullIndex == -1) { + firstNullIndex = i; + } + if (firstNullIndex != -1 && firstValidIndex != -1) { + break; + } + } + if (firstNullIndex == -1 || firstValidIndex == -1) + return; + assertNotNull(pdu); + } +} diff --git a/tests/CoreTests/com/android/internal/telephony/SimUtilsTest.java b/tests/CoreTests/com/android/internal/telephony/SimUtilsTest.java new file mode 100644 index 0000000..e733af9 --- /dev/null +++ b/tests/CoreTests/com/android/internal/telephony/SimUtilsTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2006 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 com.android.internal.telephony.gsm.SimTlv; +import com.android.internal.telephony.IccUtils; +import junit.framework.TestCase; +import android.test.suitebuilder.annotation.SmallTest; + + +public class SimUtilsTest extends TestCase { + + @SmallTest + public void testBasic() throws Exception { + byte[] data, data2; + + /* + * bcdToString() + */ + + // An EF[ICCID] record + data = IccUtils.hexStringToBytes("981062400510444868f2"); + assertEquals("8901260450014484862", IccUtils.bcdToString(data, 0, data.length)); + + // skip the first and last bytes + assertEquals("0126045001448486", IccUtils.bcdToString(data, 1, data.length - 2)); + + // Stops on invalid BCD value + data = IccUtils.hexStringToBytes("98F062400510444868f2"); + assertEquals("890", IccUtils.bcdToString(data, 0, data.length)); + + /* + * bcdByteToInt() + */ + + assertEquals(98, IccUtils.bcdByteToInt((byte) 0x89)); + + // Out of range is treated as 0 + assertEquals(8, IccUtils.bcdByteToInt((byte) 0x8c)); + + /* + * adnStringFieldToString() + */ + + + data = IccUtils.hexStringToBytes("00566f696365204d61696c07918150367742f3ffffffffffff"); + // Again, skip prepended 0 + // (this is an EF[ADN] record) + assertEquals("Voice Mail", IccUtils.adnStringFieldToString(data, 1, data.length - 15)); + + data = IccUtils.hexStringToBytes("809673539A5764002F004DFFFFFFFFFF"); + // (this is from an EF[ADN] record) + assertEquals("\u9673\u539A\u5764/M", IccUtils.adnStringFieldToString(data, 0, data.length)); + + data = IccUtils.hexStringToBytes("810A01566fec6365204de0696cFFFFFF"); + // (this is made up to test since I don't have a real one) + assertEquals("Vo\u00ECce M\u00E0il", IccUtils.adnStringFieldToString(data, 0, data.length)); + + data = IccUtils.hexStringToBytes("820505302D82d32d31"); + // Example from 3GPP TS 11.11 V18.1.3.0 annex B + assertEquals("-\u0532\u0583-1", IccUtils.adnStringFieldToString(data, 0, data.length)); + } + +} + diff --git a/tests/CoreTests/com/android/internal/telephony/TelephonyTests.java b/tests/CoreTests/com/android/internal/telephony/TelephonyTests.java index eb2bd23..b4fb324 100644 --- a/tests/CoreTests/com/android/internal/telephony/TelephonyTests.java +++ b/tests/CoreTests/com/android/internal/telephony/TelephonyTests.java @@ -16,13 +16,13 @@ package com.android.internal.telephony; -import com.android.internal.telephony.gsm.AdnRecordTest; +import com.android.internal.telephony.AdnRecordTest; import com.android.internal.telephony.gsm.GSMPhoneTest; -import com.android.internal.telephony.gsm.GsmAlphabetTest; -import com.android.internal.telephony.gsm.SMSDispatcherTest; -import com.android.internal.telephony.gsm.SimPhoneBookTest; -import com.android.internal.telephony.gsm.SimSmsTest; -import com.android.internal.telephony.gsm.SimUtilsTest; +import com.android.internal.telephony.GsmAlphabetTest; +import com.android.internal.telephony.SMSDispatcherTest; +import com.android.internal.telephony.SimPhoneBookTest; +import com.android.internal.telephony.SimSmsTest; +import com.android.internal.telephony.SimUtilsTest; import junit.framework.TestSuite; diff --git a/tests/CoreTests/com/android/internal/telephony/gsm/AdnRecordTest.java b/tests/CoreTests/com/android/internal/telephony/gsm/AdnRecordTest.java deleted file mode 100644 index 6cafdf0..0000000 --- a/tests/CoreTests/com/android/internal/telephony/gsm/AdnRecordTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) 2006 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.gsm; - -import junit.framework.TestCase; -import android.test.suitebuilder.annotation.SmallTest; - -/** - * {@hide} - */ -public class AdnRecordTest extends TestCase { - - @SmallTest - public void testBasic() throws Exception { - AdnRecord adn; - - // - // Typical record - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C07918150367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("+18056377243", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // Empty records, empty strings - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")); - - assertEquals("", adn.getAlphaTag()); - assertEquals("", adn.getNumber()); - assertTrue(adn.isEmpty()); - - // - // Record too short - // - adn = new AdnRecord(SimUtils.hexStringToBytes( "FF")); - - assertEquals("", adn.getAlphaTag()); - assertEquals("", adn.getNumber()); - assertTrue(adn.isEmpty()); - - // - // TOA = 0xff ("control string") - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C07FF8150367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("18056377243", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // TOA = 0x81 (unknown) - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C07818150367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("18056377243", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // Number Length is too long - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C0F918150367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // Number Length is zero (invalid) - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C00918150367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // Number Length is 2, first number byte is FF, TOA is international - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C0291FF50367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // Number Length is 2, first number digit is valid, TOA is international - // - adn = new AdnRecord( - SimUtils.hexStringToBytes("566F696365204D61696C0291F150367742F3FFFFFFFFFFFF")); - - assertEquals("Voice Mail", adn.getAlphaTag()); - assertEquals("+1", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // An extended record - // - adn = new AdnRecord( - SimUtils.hexStringToBytes( - "4164676A6DFFFFFFFFFFFFFFFFFFFFFF0B918188551512C221436587FF01")); - - assertEquals("Adgjm", adn.getAlphaTag()); - assertEquals("+18885551212,12345678", adn.getNumber()); - assertFalse(adn.isEmpty()); - assertTrue(adn.hasExtendedRecord()); - - adn.appendExtRecord(SimUtils.hexStringToBytes("0206092143658709ffffffffff")); - - assertEquals("Adgjm", adn.getAlphaTag()); - assertEquals("+18885551212,12345678901234567890", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // An extended record with an invalid extension - // - adn = new AdnRecord( - SimUtils.hexStringToBytes( - "4164676A6DFFFFFFFFFFFFFFFFFFFFFF0B918188551512C221436587FF01")); - - assertEquals("Adgjm", adn.getAlphaTag()); - assertEquals("+18885551212,12345678", adn.getNumber()); - assertFalse(adn.isEmpty()); - assertTrue(adn.hasExtendedRecord()); - - adn.appendExtRecord(SimUtils.hexStringToBytes("0106092143658709ffffffffff")); - - assertEquals("Adgjm", adn.getAlphaTag()); - assertEquals("+18885551212,12345678", adn.getNumber()); - assertFalse(adn.isEmpty()); - - // - // An extended record with an invalid extension - // - adn = new AdnRecord( - SimUtils.hexStringToBytes( - "4164676A6DFFFFFFFFFFFFFFFFFFFFFF0B918188551512C221436587FF01")); - - assertEquals("Adgjm", adn.getAlphaTag()); - assertEquals("+18885551212,12345678", adn.getNumber()); - assertFalse(adn.isEmpty()); - assertTrue(adn.hasExtendedRecord()); - - adn.appendExtRecord(SimUtils.hexStringToBytes("020B092143658709ffffffffff")); - - assertEquals("Adgjm", adn.getAlphaTag()); - assertEquals("+18885551212,12345678", adn.getNumber()); - assertFalse(adn.isEmpty()); - } -} - - diff --git a/tests/CoreTests/com/android/internal/telephony/gsm/GsmAlphabetTest.java b/tests/CoreTests/com/android/internal/telephony/gsm/GsmAlphabetTest.java deleted file mode 100644 index f36d96b..0000000 --- a/tests/CoreTests/com/android/internal/telephony/gsm/GsmAlphabetTest.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright (C) 2006 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.gsm; - -import junit.framework.TestCase; - -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; - -public class GsmAlphabetTest extends TestCase { - - private static final String sGsmExtendedChars = "{|}\\[~]\f\u20ac"; - - @SmallTest - public void test7bitWithHeader() throws Exception { - byte[] data = new byte[3]; - data[0] = (byte) 1; - data[1] = (byte) 2; - data[2] = (byte) 2; - SmsHeader header = new SmsHeader(); - header.add(new SmsHeader.Element(SmsHeader.CONCATENATED_8_BIT_REFERENCE, data)); - - String message = "aaaaaaaaaabbbbbbbbbbcccccccccc"; - byte[] userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header.toByteArray()); - int septetCount = GsmAlphabet.countGsmSeptets(message, false); - String parsedMessage = GsmAlphabet.gsm7BitPackedToString( - userData, header.toByteArray().length+1, septetCount, 1); - assertEquals(message, parsedMessage); - } - - // TODO: This method should *really* be a series of individual test methods. - @LargeTest - public void testBasic() throws Exception { - // '@' maps to char 0 - assertEquals(0, GsmAlphabet.charToGsm('@')); - - // `a (a with grave accent) maps to last GSM charater - assertEquals(0x7f, GsmAlphabet.charToGsm('\u00e0')); - - // - // These are the extended chars - // They should all return GsmAlphabet.GSM_EXTENDED_ESCAPE - // - - for (int i = 0, s = sGsmExtendedChars.length(); i < s; i++) { - assertEquals(GsmAlphabet.GSM_EXTENDED_ESCAPE, - GsmAlphabet.charToGsm(sGsmExtendedChars.charAt(i))); - - } - - // euro symbol - assertEquals(GsmAlphabet.GSM_EXTENDED_ESCAPE, - GsmAlphabet.charToGsm('\u20ac')); - - // An unmappable char (the 'cent' char) maps to a space - assertEquals(GsmAlphabet.charToGsm(' '), - GsmAlphabet.charToGsm('\u00a2')); - - // unmappable = space = 1 septet - assertEquals(1, GsmAlphabet.countGsmSeptets('\u00a2')); - - // - // Test extended table - // - - for (int i = 0, s = sGsmExtendedChars.length(); i < s; i++) { - assertEquals(sGsmExtendedChars.charAt(i), - GsmAlphabet.gsmExtendedToChar( - GsmAlphabet.charToGsmExtended(sGsmExtendedChars.charAt(i)))); - - } - - // Unmappable extended char - assertEquals(GsmAlphabet.charToGsm(' '), - GsmAlphabet.charToGsmExtended('@')); - - // - // gsmToChar() - // - - assertEquals('@', GsmAlphabet.gsmToChar(0)); - - // `a (a with grave accent) maps to last GSM charater - assertEquals('\u00e0', GsmAlphabet.gsmToChar(0x7f)); - - assertEquals('\uffff', - GsmAlphabet.gsmToChar(GsmAlphabet.GSM_EXTENDED_ESCAPE)); - - // Out-of-range/unmappable value - assertEquals(' ', GsmAlphabet.gsmToChar(0x80)); - - // - // gsmExtendedToChar() - // - - assertEquals('{', GsmAlphabet.gsmExtendedToChar(0x28)); - - // No double-escapes - assertEquals(' ', GsmAlphabet.gsmExtendedToChar( - GsmAlphabet.GSM_EXTENDED_ESCAPE)); - - // Unmappable - assertEquals(' ', GsmAlphabet.gsmExtendedToChar(0)); - - // - // stringTo7BitPacked, gsm7BitPackedToString - // - - byte[] packed; - StringBuilder testString = new StringBuilder(300); - - // Check all alignment cases - for (int i = 0; i < 9; i++, testString.append('@')) { - packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - assertEquals(testString.toString(), - GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); - } - - // Check full non-extended alphabet - for (int i = 0; i < 0x80; i++) { - char c; - - if (i == GsmAlphabet.GSM_EXTENDED_ESCAPE) { - continue; - } - - c = GsmAlphabet.gsmToChar(i); - testString.append(c); - - // These are all non-extended chars, so it should be - // one septet per char - assertEquals(1, GsmAlphabet.countGsmSeptets(c)); - } - - packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - assertEquals(testString.toString(), - GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); - - // Test extended chars too - - testString.append(sGsmExtendedChars); - - for (int i = 0, s = sGsmExtendedChars.length(); i < s; i++) { - // These are all extended chars, so it should be - // two septets per char - assertEquals(2, GsmAlphabet.countGsmSeptets(sGsmExtendedChars.charAt(i))); - - } - - packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - assertEquals(testString.toString(), - GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); - - // stringTo7BitPacked handles up to 255 septets - - testString.setLength(0); - for (int i = 0; i < 255; i++) { - testString.append('@'); - } - - packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - assertEquals(testString.toString(), - GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); - - // > 255 septets throws runtime exception - testString.append('@'); - - try { - GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - fail("expected exception"); - } catch (EncodeException ex) { - // exception expected - } - - // Try 254 septets with 127 extended chars - - testString.setLength(0); - for (int i = 0; i < (255 / 2); i++) { - testString.append('{'); - } - - packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - assertEquals(testString.toString(), - GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0])); - - // > 255 septets throws runtime exception - testString.append('{'); - - try { - GsmAlphabet.stringToGsm7BitPacked(testString.toString()); - fail("expected exception"); - } catch (EncodeException ex) { - // exception expected - } - - // - // 8 bit unpacked format - // - // Note: we compare hex strings here - // because Assert doesnt have array-comparisons - - byte unpacked[]; - - unpacked = SimUtils.hexStringToBytes("566F696365204D61696C"); - assertEquals("Voice Mail", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - assertEquals(SimUtils.bytesToHexString(unpacked), - SimUtils.bytesToHexString( - GsmAlphabet.stringToGsm8BitPacked("Voice Mail"))); - - unpacked = GsmAlphabet.stringToGsm8BitPacked(sGsmExtendedChars); - // two bytes for every extended char - assertEquals(2 * sGsmExtendedChars.length(), unpacked.length); - assertEquals(sGsmExtendedChars, - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - // should be two bytes per extended char - assertEquals(2 * sGsmExtendedChars.length(), unpacked.length); - - // Test truncation of unaligned extended chars - unpacked = new byte[3]; - GsmAlphabet.stringToGsm8BitUnpackedField(sGsmExtendedChars, unpacked, - 0, unpacked.length); - - // Should be one extended char and an 0xff at the end - - assertEquals(0xff, 0xff & unpacked[2]); - assertEquals(sGsmExtendedChars.substring(0, 1), - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - // Test truncation of normal chars - unpacked = new byte[3]; - GsmAlphabet.stringToGsm8BitUnpackedField("abcd", unpacked, - 0, unpacked.length); - - assertEquals("abc", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - // Test truncation of mixed normal and extended chars - unpacked = new byte[3]; - GsmAlphabet.stringToGsm8BitUnpackedField("a{cd", unpacked, - 0, unpacked.length); - - assertEquals("a{", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - // Test padding after normal char - unpacked = new byte[3]; - GsmAlphabet.stringToGsm8BitUnpackedField("a", unpacked, - 0, unpacked.length); - - assertEquals("a", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - assertEquals(0xff, 0xff & unpacked[1]); - assertEquals(0xff, 0xff & unpacked[2]); - - // Test malformed input -- escape char followed by end of field - unpacked[0] = 0; - unpacked[1] = 0; - unpacked[2] = GsmAlphabet.GSM_EXTENDED_ESCAPE; - - assertEquals("@@", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length)); - - // non-zero offset - assertEquals("@", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1)); - - // test non-zero offset - unpacked[0] = 0; - GsmAlphabet.stringToGsm8BitUnpackedField("abcd", unpacked, - 1, unpacked.length - 1); - - - assertEquals(0, unpacked[0]); - - assertEquals("ab", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1)); - - // test non-zero offset with truncated extended char - unpacked[0] = 0; - - GsmAlphabet.stringToGsm8BitUnpackedField("a{", unpacked, - 1, unpacked.length - 1); - - assertEquals(0, unpacked[0]); - - assertEquals("a", - GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1)); - } -} - diff --git a/tests/CoreTests/com/android/internal/telephony/gsm/SMSDispatcherTest.java b/tests/CoreTests/com/android/internal/telephony/gsm/SMSDispatcherTest.java deleted file mode 100644 index 6db230f..0000000 --- a/tests/CoreTests/com/android/internal/telephony/gsm/SMSDispatcherTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2007 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.gsm; - -import android.test.suitebuilder.annotation.MediumTest; -import com.android.internal.telephony.TestPhoneNotifier; -import com.android.internal.telephony.test.SimulatedCommands; -import com.android.internal.telephony.test.SimulatedRadioControl; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.Suppress; -import android.telephony.gsm.SmsMessage; - -import java.util.Iterator; - -/** - * {@hide} - */ -public class SMSDispatcherTest extends AndroidTestCase { - @MediumTest - public void testCMT1() throws Exception { - SmsMessage sms; - SmsHeader header; - Iterator elements; - - String[] lines = new String[2]; - - lines[0] = "+CMT: ,158"; - lines[1] = "07914140279510F6440A8111110301003BF56080426101748A8C0B05040B" - + "8423F000035502010106276170706C69636174696F6E2F766E642E776170" - + "2E6D6D732D6D65737361676500AF848D0185B4848C8298524F347839776F" - + "7547514D4141424C3641414141536741415A4B554141414141008D908918" - + "802B31363530323438363137392F545950453D504C4D4E008A808E028000" - + "88058103093A8083687474703A2F2F36"; - - sms = SmsMessage.newFromCMT(lines); - header = sms.getUserDataHeader(); - assertNotNull(header); - assertNotNull(sms.getUserData()); - - elements = header.getElements().iterator(); - assertNotNull(elements); - } - - @MediumTest - public void testCMT2() throws Exception { - SmsMessage sms; - SmsHeader header; - Iterator elements; - - String[] lines = new String[2]; - - - lines[0] = "+CMT: ,77"; - lines[1] = "07914140279510F6440A8111110301003BF56080426101848A3B0B05040B8423F" - + "00003550202362E3130322E3137312E3135302F524F347839776F7547514D4141" - + "424C3641414141536741415A4B55414141414100"; - - sms = SmsMessage.newFromCMT(lines); - header = sms.getUserDataHeader(); - System.out.println("header = " + header); - assertNotNull(header); - assertNotNull(sms.getUserData()); - - elements = header.getElements().iterator(); - assertNotNull(elements); - } - - @MediumTest - public void testEfRecord() throws Exception { - SmsMessage sms; - - String s = "03029111000c9194981492631000f269206190022000a053e4534a05358bd3" - + "69f05804259da0219418a40641536a110a0aea408080604028180e888462c1" - + "50341c0f484432a1542c174c46b3e1743c9f9068442a994ea8946ac56ab95e" - + "b0986c46abd96eb89c6ec7ebf97ec0a070482c1a8fc8a472c96c3a9fd0a874" - + "4aad5aafd8ac76cbed7abfe0b0784c2e9bcfe8b47acd6ebbdff0b87c4eafdb" - + "eff8bc7ecfeffbffffffffffffffffffffffffffff"; - byte[] data = SimUtils.hexStringToBytes(s); - - sms = SmsMessage.createFromEfRecord(1, data); - assertNotNull(sms.getMessageBody()); - } -} diff --git a/tests/CoreTests/com/android/internal/telephony/gsm/SimPhoneBookTest.java b/tests/CoreTests/com/android/internal/telephony/gsm/SimPhoneBookTest.java deleted file mode 100644 index db55bca..0000000 --- a/tests/CoreTests/com/android/internal/telephony/gsm/SimPhoneBookTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2006 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.gsm; - -import android.os.ServiceManager; -import android.test.suitebuilder.annotation.Suppress; - -import java.util.List; - -import junit.framework.TestCase; - -@Suppress -public class SimPhoneBookTest extends TestCase { - - public void testBasic() throws Exception { - ISimPhoneBook simPhoneBook = - ISimPhoneBook.Stub.asInterface(ServiceManager.getService("simphonebook")); - assertNotNull(simPhoneBook); - - int size[] = simPhoneBook.getAdnRecordsSize(SimConstants.EF_ADN); - assertNotNull(size); - assertEquals(3, size.length); - assertEquals(size[0] * size[2], size[1]); - assertTrue(size[2] >= 100); - - List adnRecordList = simPhoneBook.getAdnRecordsInEf(SimConstants.EF_ADN); - // do it twice cause the second time shall read from cache only - adnRecordList = simPhoneBook.getAdnRecordsInEf(SimConstants.EF_ADN); - assertNotNull(adnRecordList); - - // Test for phone book update - int adnIndex, listIndex = 0; - AdnRecord originalAdn = null; - // We need to maintain the state of the SIM before and after the test. - // Since this test doesn't mock the SIM we try to get a valid ADN record, - // for 3 tries and if this fails, we bail out. - for (adnIndex = 3 ; adnIndex >= 1; adnIndex--) { - listIndex = adnIndex - 1; // listIndex is zero based. - originalAdn = adnRecordList.get(listIndex); - assertNotNull("Original Adn is Null.", originalAdn); - assertNotNull("Original Adn alpha tag is null.", originalAdn.getAlphaTag()); - assertNotNull("Original Adn number is null.", originalAdn.getNumber()); - - if (originalAdn.getNumber().length() > 0 && - originalAdn.getAlphaTag().length() > 0) { - break; - } - } - if (adnIndex == 0) return; - - AdnRecord emptyAdn = new AdnRecord("", ""); - AdnRecord firstAdn = new AdnRecord("John", "4085550101"); - AdnRecord secondAdn = new AdnRecord("Andy", "6505550102"); - String pin2 = null; - - // udpate by index - boolean success = simPhoneBook.updateAdnRecordsInEfByIndex(SimConstants.EF_ADN, - firstAdn.getAlphaTag(), firstAdn.getNumber(), adnIndex, pin2); - adnRecordList = simPhoneBook.getAdnRecordsInEf(SimConstants.EF_ADN); - AdnRecord tmpAdn = adnRecordList.get(listIndex); - assertTrue(success); - assertTrue(firstAdn.isEqual(tmpAdn)); - - // replace by search - success = simPhoneBook.updateAdnRecordsInEfBySearch(SimConstants.EF_ADN, - firstAdn.getAlphaTag(), firstAdn.getNumber(), - secondAdn.getAlphaTag(), secondAdn.getNumber(), pin2); - adnRecordList = simPhoneBook.getAdnRecordsInEf(SimConstants.EF_ADN); - tmpAdn = adnRecordList.get(listIndex); - assertTrue(success); - assertFalse(firstAdn.isEqual(tmpAdn)); - assertTrue(secondAdn.isEqual(tmpAdn)); - - // erase be search - success = simPhoneBook.updateAdnRecordsInEfBySearch(SimConstants.EF_ADN, - secondAdn.getAlphaTag(), secondAdn.getNumber(), - emptyAdn.getAlphaTag(), emptyAdn.getNumber(), pin2); - adnRecordList = simPhoneBook.getAdnRecordsInEf(SimConstants.EF_ADN); - tmpAdn = adnRecordList.get(listIndex); - assertTrue(success); - assertTrue(tmpAdn.isEmpty()); - - // restore the orginial adn - success = simPhoneBook.updateAdnRecordsInEfByIndex(SimConstants.EF_ADN, - originalAdn.getAlphaTag(), originalAdn.getNumber(), adnIndex, - pin2); - adnRecordList = simPhoneBook.getAdnRecordsInEf(SimConstants.EF_ADN); - tmpAdn = adnRecordList.get(listIndex); - assertTrue(success); - assertTrue(originalAdn.isEqual(tmpAdn)); - } -} diff --git a/tests/CoreTests/com/android/internal/telephony/gsm/SimSmsTest.java b/tests/CoreTests/com/android/internal/telephony/gsm/SimSmsTest.java deleted file mode 100644 index 6ced23d..0000000 --- a/tests/CoreTests/com/android/internal/telephony/gsm/SimSmsTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2006 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.gsm; - -import android.os.ServiceManager; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -import java.util.List; - -import junit.framework.TestCase; - -public class SimSmsTest extends TestCase { - - @MediumTest - @Suppress // TODO: suppress this test for now since it doesn't work on the emulator - public void testBasic() throws Exception { - - ISms sms = ISms.Stub.asInterface(ServiceManager.getService("isms")); - assertNotNull(sms); - - List records = sms.getAllMessagesFromSimEf(); - assertNotNull(records); - assertTrue(records.size() >= 0); - - int firstNullIndex = -1; - int firstValidIndex = -1; - byte[] pdu = null; - for (int i = 0; i < records.size(); i++) { - SmsRawData data = records.get(i); - if (data != null && firstValidIndex == -1) { - firstValidIndex = i; - pdu = data.getBytes(); - } - if (data == null && firstNullIndex == -1) { - firstNullIndex = i; - } - if (firstNullIndex != -1 && firstValidIndex != -1) { - break; - } - } - if (firstNullIndex == -1 || firstValidIndex == -1) - return; - assertNotNull(pdu); - } -} diff --git a/tests/CoreTests/com/android/internal/telephony/gsm/SimUtilsTest.java b/tests/CoreTests/com/android/internal/telephony/gsm/SimUtilsTest.java deleted file mode 100644 index 3fbc8f5..0000000 --- a/tests/CoreTests/com/android/internal/telephony/gsm/SimUtilsTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2006 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.gsm; - -import com.android.internal.telephony.gsm.SimTlv; -import com.android.internal.telephony.gsm.SimUtils; -import junit.framework.TestCase; -import android.test.suitebuilder.annotation.SmallTest; - - -public class SimUtilsTest extends TestCase { - - @SmallTest - public void testBasic() throws Exception { - byte[] data, data2; - - /* - * bcdToString() - */ - - // An EF[ICCID] record - data = SimUtils.hexStringToBytes("981062400510444868f2"); - assertEquals("8901260450014484862", SimUtils.bcdToString(data, 0, data.length)); - - // skip the first and last bytes - assertEquals("0126045001448486", SimUtils.bcdToString(data, 1, data.length - 2)); - - // Stops on invalid BCD value - data = SimUtils.hexStringToBytes("98F062400510444868f2"); - assertEquals("890", SimUtils.bcdToString(data, 0, data.length)); - - /* - * bcdByteToInt() - */ - - assertEquals(98, SimUtils.bcdByteToInt((byte) 0x89)); - - // Out of range is treated as 0 - assertEquals(8, SimUtils.bcdByteToInt((byte) 0x8c)); - - /* - * adnStringFieldToString() - */ - - - data = SimUtils.hexStringToBytes("00566f696365204d61696c07918150367742f3ffffffffffff"); - // Again, skip prepended 0 - // (this is an EF[ADN] record) - assertEquals("Voice Mail", SimUtils.adnStringFieldToString(data, 1, data.length - 15)); - - data = SimUtils.hexStringToBytes("809673539A5764002F004DFFFFFFFFFF"); - // (this is from an EF[ADN] record) - assertEquals("\u9673\u539A\u5764/M", SimUtils.adnStringFieldToString(data, 0, data.length)); - - data = SimUtils.hexStringToBytes("810A01566fec6365204de0696cFFFFFF"); - // (this is made up to test since I don't have a real one) - assertEquals("Vo\u00ECce M\u00E0il", SimUtils.adnStringFieldToString(data, 0, data.length)); - - data = SimUtils.hexStringToBytes("820505302D82d32d31"); - // Example from 3GPP TS 11.11 V18.1.3.0 annex B - assertEquals("-\u0532\u0583-1", SimUtils.adnStringFieldToString(data, 0, data.length)); - } - -} - diff --git a/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java b/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java index 0368651..fd05fed 100644 --- a/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java +++ b/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java @@ -17,8 +17,7 @@ package com.android.internal.policy.impl; import android.content.Context; - -import com.android.internal.telephony.SimCard; +import com.android.internal.telephony.IccCard; import android.test.AndroidTestCase; import android.view.View; import android.view.KeyEvent; @@ -39,7 +38,7 @@ public class LockPatternKeyguardViewTest extends AndroidTestCase { private static class MockUpdateMonitor extends KeyguardUpdateMonitor { - public SimCard.State simState = SimCard.State.READY; + public IccCard.State simState = IccCard.State.READY; public boolean inPortrait = false; public boolean keyboardOpen = false; @@ -48,7 +47,7 @@ public class LockPatternKeyguardViewTest extends AndroidTestCase { } @Override - public SimCard.State getSimState() { + public IccCard.State getSimState() { return simState; } @@ -339,7 +338,7 @@ public class LockPatternKeyguardViewTest extends AndroidTestCase { public void testMenuDoesntGoToUnlockScreenOnWakeWhenPukLocked() { // PUK locked - mUpdateMonitor.simState = SimCard.State.PUK_REQUIRED; + mUpdateMonitor.simState = IccCard.State.PUK_REQUIRED; // wake by menu mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU); -- cgit v1.1