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