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.dataconnection;
18
19import android.os.Parcel;
20import android.test.suitebuilder.annotation.SmallTest;
21
22import junit.framework.TestCase;
23
24public class DataProfileTest extends TestCase {
25
26    private ApnSetting mApn1 = new ApnSetting(
27            2163,                   // id
28            "44010",                // numeric
29            "sp-mode",              // name
30            "fake_apn",             // apn
31            "",                     // proxy
32            "",                     // port
33            "",                     // mmsc
34            "",                     // mmsproxy
35            "",                     // mmsport
36            "user",                 // user
37            "passwd",               // password
38            -1,                     // authtype
39            new String[]{"default", "supl"},     // types
40            "IPV6",                 // protocol
41            "IP",                   // roaming_protocol
42            true,                   // carrier_enabled
43            0,                      // bearer
44            0,                      // bearer_bitmask
45            1234,                   // profile_id
46            false,                  // modem_cognitive
47            321,                    // max_conns
48            456,                    // wait_time
49            789,                    // max_conns_time
50            0,                      // mtu
51            "",                     // mvno_type
52            "");                    // mnvo_match_data
53
54    private ApnSetting mApn2 = new ApnSetting(
55            2163,                   // id
56            "44010",                // numeric
57            "sp-mode",              // name
58            "fake_apn",             // apn
59            "",                     // proxy
60            "",                     // port
61            "",                     // mmsc
62            "",                     // mmsproxy
63            "",                     // mmsport
64            "user",                 // user
65            "passwd",               // password
66            -1,                     // authtype
67            new String[]{"default", "supl"},     // types
68            "IP",                   // protocol
69            "IP",                   // roaming_protocol
70            true,                   // carrier_enabled
71            0,                      // bearer
72            0,                      // bearer_bitmask
73            1234,                   // profile_id
74            false,                  // modem_cognitive
75            111,                    // max_conns
76            456,                    // wait_time
77            789,                    // max_conns_time
78            0,                      // mtu
79            "",                     // mvno_type
80            "");                    // mnvo_match_data
81
82    @SmallTest
83    public void testCreateFromApnSetting() throws Exception {
84        DataProfile dp = new DataProfile(mApn1, false);
85        assertEquals(mApn1.profileId, dp.profileId);
86        assertEquals(mApn1.apn, dp.apn);
87        assertEquals(mApn1.protocol, dp.protocol);
88        assertEquals(mApn1.authType, dp.authType);
89        assertEquals(mApn1.user, dp.user);
90        assertEquals(mApn1.password, dp.password);
91        assertEquals(0, dp.type);
92        assertEquals(mApn1.maxConnsTime, dp.maxConnsTime);
93        assertEquals(mApn1.maxConns, dp.maxConns);
94        assertEquals(mApn1.waitTime, dp.waitTime);
95        assertEquals(mApn1.carrierEnabled, dp.enabled);
96    }
97
98    @SmallTest
99    public void testParcel() throws Exception {
100        Parcel p = Parcel.obtain();
101
102        DataProfile[] dps = new DataProfile[]{new DataProfile(mApn1, false),
103                new DataProfile(mApn1, false)};
104
105        DataProfile.toParcel(p, dps);
106        p.setDataPosition(0);
107
108        assertEquals(dps.length, p.readInt());
109        for (int i = 0; i < dps.length; i++) {
110            assertEquals("i = " + i, mApn1.profileId, p.readInt());
111            assertEquals("i = " + i, mApn1.apn, p.readString());
112            assertEquals("i = " + i, mApn1.protocol, p.readString());
113            assertEquals("i = " + i, mApn1.authType, p.readInt());
114            assertEquals("i = " + i, mApn1.user, p.readString());
115            assertEquals("i = " + i, mApn1.password, p.readString());
116            assertEquals("i = " + i, 0, p.readInt());
117            assertEquals("i = " + i, mApn1.maxConnsTime, p.readInt());
118            assertEquals("i = " + i, mApn1.maxConns, p.readInt());
119            assertEquals("i = " + i, mApn1.waitTime, p.readInt());
120            assertEquals("i = " + i, mApn1.carrierEnabled?1:0, p.readInt());
121        }
122    }
123
124    @SmallTest
125    public void testEquals() throws Exception {
126        DataProfile dp1 = new DataProfile(mApn1, false);
127        DataProfile dp2 = new DataProfile(mApn1, false);
128        assertEquals(dp1, dp2);
129
130        dp2 = new DataProfile(mApn1, true);
131        assertFalse(dp1.equals(dp2));
132
133        dp2 = new DataProfile(mApn2, false);
134        assertFalse(dp1.equals(dp2));
135    }
136}
137