FileDocCategorySizeDatePackage
SimPhoneBookTest.javaAPI DocAndroid 1.5 API4509Wed May 06 22:42:02 BST 2009com.android.internal.telephony.gsm

SimPhoneBookTest

public class SimPhoneBookTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestBasic()

        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<AdnRecord> 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));