FileDocCategorySizeDatePackage
ATResponseParserTest.javaAPI DocAndroid 1.5 API3427Wed May 06 22:42:02 BST 2009com.android.internal.telephony

ATResponseParserTest

public class ATResponseParserTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestBasic()

        ATResponseParser p = new ATResponseParser("+CREG: 0");

        assertEquals(0, p.nextInt());

        assertFalse(p.hasMore());

        try {
            p.nextInt();
            fail("exception expected");
        } catch (ATParseEx ex) {
            //test pass
        }

        p = new ATResponseParser("+CREG: 0,1");
        assertEquals(0, p.nextInt());
        assertEquals(1, p.nextInt());
        assertFalse(p.hasMore());

        p = new ATResponseParser("+CREG: 0, 1");
        assertEquals(0, p.nextInt());
        assertEquals(1, p.nextInt());
        assertFalse(p.hasMore());

        p = new ATResponseParser("+CREG: 0, 1,");
        assertEquals(0, p.nextInt());
        assertEquals(1, p.nextInt());
        // this seems odd but is probably OK
        assertFalse(p.hasMore());
        try {
            p.nextInt();
            fail("exception expected");
        } catch (ATParseEx ex) {
            //test pass
        }

        p = new ATResponseParser("+CREG: 0, 1 ");
        assertEquals(0, p.nextInt());
        assertEquals(1, p.nextInt());
        assertFalse(p.hasMore());

        p = new ATResponseParser("0, 1 ");
        // no prefix -> exception
        try {
            p.nextInt();
            fail("exception expected");
        } catch (ATParseEx ex) {
            //test pass
        }

        p = new ATResponseParser("+CREG: 0, 1, 5");
        assertFalse(p.nextBoolean());
        assertTrue(p.nextBoolean());
        try {
            // is this over-constraining?
            p.nextBoolean();
            fail("exception expected");
        } catch (ATParseEx ex) {
            //test pass
        }

        p = new ATResponseParser("+CLCC: 1,0,2,0,0,\"+18005551212\",145");

        assertEquals(1, p.nextInt());
        assertFalse(p.nextBoolean());
        assertEquals(2, p.nextInt());
        assertEquals(0, p.nextInt());
        assertEquals(0, p.nextInt());
        assertEquals("+18005551212", p.nextString());
        assertEquals(145, p.nextInt());
        assertFalse(p.hasMore());

        p = new ATResponseParser("+CLCC: 1,0,2,0,0,\"+18005551212,145");

        assertEquals(1, p.nextInt());
        assertFalse(p.nextBoolean());
        assertEquals(2, p.nextInt());
        assertEquals(0, p.nextInt());
        assertEquals(0, p.nextInt());
        try {
            p.nextString();
            fail("expected ex");
        } catch (ATParseEx ex) {
            //test pass
        }

        p = new ATResponseParser("+FOO: \"\"");
        assertEquals("", p.nextString());