1/* 2 * Copyright (C) 2006 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 junit.framework.TestCase; 20import android.test.suitebuilder.annotation.SmallTest; 21 22public class ATResponseParserTest extends TestCase { 23 @SmallTest 24 public void testBasic() throws Exception { 25 ATResponseParser p = new ATResponseParser("+CREG: 0"); 26 27 assertEquals(0, p.nextInt()); 28 29 assertFalse(p.hasMore()); 30 31 try { 32 p.nextInt(); 33 fail("exception expected"); 34 } catch (ATParseEx ex) { 35 //test pass 36 } 37 38 p = new ATResponseParser("+CREG: 0,1"); 39 assertEquals(0, p.nextInt()); 40 assertEquals(1, p.nextInt()); 41 assertFalse(p.hasMore()); 42 43 p = new ATResponseParser("+CREG: 0, 1"); 44 assertEquals(0, p.nextInt()); 45 assertEquals(1, p.nextInt()); 46 assertFalse(p.hasMore()); 47 48 p = new ATResponseParser("+CREG: 0, 1,"); 49 assertEquals(0, p.nextInt()); 50 assertEquals(1, p.nextInt()); 51 // this seems odd but is probably OK 52 assertFalse(p.hasMore()); 53 try { 54 p.nextInt(); 55 fail("exception expected"); 56 } catch (ATParseEx ex) { 57 //test pass 58 } 59 60 p = new ATResponseParser("+CREG: 0, 1 "); 61 assertEquals(0, p.nextInt()); 62 assertEquals(1, p.nextInt()); 63 assertFalse(p.hasMore()); 64 65 p = new ATResponseParser("0, 1 "); 66 // no prefix -> exception 67 try { 68 p.nextInt(); 69 fail("exception expected"); 70 } catch (ATParseEx ex) { 71 //test pass 72 } 73 74 p = new ATResponseParser("+CREG: 0, 1, 5"); 75 assertFalse(p.nextBoolean()); 76 assertTrue(p.nextBoolean()); 77 try { 78 // is this over-constraining? 79 p.nextBoolean(); 80 fail("exception expected"); 81 } catch (ATParseEx ex) { 82 //test pass 83 } 84 85 p = new ATResponseParser("+CLCC: 1,0,2,0,0,\"+18005551212\",145"); 86 87 assertEquals(1, p.nextInt()); 88 assertFalse(p.nextBoolean()); 89 assertEquals(2, p.nextInt()); 90 assertEquals(0, p.nextInt()); 91 assertEquals(0, p.nextInt()); 92 assertEquals("+18005551212", p.nextString()); 93 assertEquals(145, p.nextInt()); 94 assertFalse(p.hasMore()); 95 96 p = new ATResponseParser("+CLCC: 1,0,2,0,0,\"+18005551212,145"); 97 98 assertEquals(1, p.nextInt()); 99 assertFalse(p.nextBoolean()); 100 assertEquals(2, p.nextInt()); 101 assertEquals(0, p.nextInt()); 102 assertEquals(0, p.nextInt()); 103 try { 104 p.nextString(); 105 fail("expected ex"); 106 } catch (ATParseEx ex) { 107 //test pass 108 } 109 110 p = new ATResponseParser("+FOO: \"\""); 111 assertEquals("", p.nextString()); 112 } 113} 114