1/* 2 * Copyright (C) 2010 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 android.test.suitebuilder.annotation.SmallTest; 20 21import com.android.internal.telephony.dataconnection.ApnSetting; 22 23import junit.framework.TestCase; 24 25public class ApnSettingTest extends TestCase { 26 27 public static final String[] TYPES = {"default", "*"}; 28 29 public static void assertApnSettingEqual(ApnSetting a1, ApnSetting a2) { 30 assertEquals(a1.carrier, a2.carrier); 31 assertEquals(a1.apn, a2.apn); 32 assertEquals(a1.proxy, a2.proxy); 33 assertEquals(a1.port, a2.port); 34 assertEquals(a1.mmsc, a2.mmsc); 35 assertEquals(a1.mmsProxy, a2.mmsProxy); 36 assertEquals(a1.mmsPort, a2.mmsPort); 37 assertEquals(a1.user, a2.user); 38 assertEquals(a1.password, a2.password); 39 assertEquals(a1.authType, a2.authType); 40 assertEquals(a1.id, a2.id); 41 assertEquals(a1.numeric, a2.numeric); 42 assertEquals(a1.protocol, a2.protocol); 43 assertEquals(a1.roamingProtocol, a2.roamingProtocol); 44 assertEquals(a1.types.length, a2.types.length); 45 int i; 46 for (i = 0; i < a1.types.length; i++) { 47 assertEquals(a1.types[i], a2.types[i]); 48 } 49 assertEquals(a1.carrierEnabled, a2.carrierEnabled); 50 assertEquals(a1.bearer, a2.bearer); 51 } 52 53 @SmallTest 54 public void testFromString() throws Exception { 55 String[] dunTypes = {"DUN"}; 56 String[] mmsTypes = {"mms", "*"}; 57 58 ApnSetting expected_apn; 59 String testString; 60 61 // A real-world v1 example string. 62 testString = "Vodafone IT,web.omnitel.it,,,,,,,,,222,10,,DUN"; 63 expected_apn = new ApnSetting( 64 -1, "22210", "Vodafone IT", "web.omnitel.it", "", "", 65 "", "", "", "", "", 0, dunTypes, "IP", "IP",true,0); 66 assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); 67 68 // A v2 string. 69 testString = "[ApnSettingV2] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,14"; 70 expected_apn = new ApnSetting( 71 -1, "12345", "Name", "apn", "", "", 72 "", "", "", "", "", 0, mmsTypes, "IPV6", "IP",true,14); 73 assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); 74 75 // A v2 string with spaces. 76 testString = "[ApnSettingV2] Name,apn, ,,,,,,,,123,45,,mms|*,IPV4V6, IP,true,14"; 77 expected_apn = new ApnSetting( 78 -1, "12345", "Name", "apn", "", "", 79 "", "", "", "", "", 0, mmsTypes, "IPV4V6", "IP",true,14); 80 assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); 81 82 // Return null if insufficient fields given. 83 testString = "[ApnSettingV2] Name,apn,,,,,,,,,123, 45,,mms|*"; 84 assertEquals(null, ApnSetting.fromString(testString)); 85 86 testString = "Name,apn,,,,,,,,,123, 45,"; 87 assertEquals(null, ApnSetting.fromString(testString)); 88 } 89 90 91 @SmallTest 92 public void testToString() throws Exception { 93 String[] types = {"default", "*"}; 94 ApnSetting apn = new ApnSetting( 95 99, "12345", "Name", "apn", "proxy", "port", 96 "mmsc", "mmsproxy", "mmsport", "user", "password", 0, 97 types, "IPV4V6", "IP", true, 14); 98 String expected = "[ApnSettingV2] Name, 99, 12345, apn, proxy, " + 99 "mmsc, mmsproxy, mmsport, port, 0, default | *, " + 100 "IPV4V6, IP, true, 14"; 101 assertEquals(expected, apn.toString()); 102 } 103} 104