1/*
2 * Copyright 2017 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 static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_ADDRESS;
20import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_DNS;
21import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_GATEWAY;
22import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_IFNAME;
23import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_PCSCF_ADDRESS;
24
25import android.net.LinkAddress;
26import android.net.NetworkUtils;
27import android.os.Parcel;
28import android.telephony.data.DataCallResponse;
29import android.test.AndroidTestCase;
30import android.test.suitebuilder.annotation.SmallTest;
31
32import java.util.Arrays;
33
34public class DataCallResponseTest extends AndroidTestCase {
35
36    @SmallTest
37    public void testParcel() throws Exception {
38        DataCallResponse response = new DataCallResponse(0, -1, 1, 2, "IP", FAKE_IFNAME,
39                Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress(FAKE_ADDRESS), 0)),
40                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_DNS)),
41                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_GATEWAY)),
42                Arrays.asList(FAKE_PCSCF_ADDRESS),
43                1440);
44
45        Parcel p = Parcel.obtain();
46        response.writeToParcel(p, 0);
47        p.setDataPosition(0);
48
49        DataCallResponse newResponse = new DataCallResponse(p);
50        assertEquals(response, newResponse);
51    }
52
53    @SmallTest
54    public void testEquals() throws Exception {
55        DataCallResponse response = new DataCallResponse(0, -1, 1, 2, "IP", FAKE_IFNAME,
56                Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress(FAKE_ADDRESS), 0)),
57                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_DNS)),
58                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_GATEWAY)),
59                Arrays.asList(FAKE_PCSCF_ADDRESS),
60                1440);
61
62        DataCallResponse response1 = new DataCallResponse(0, -1, 1, 2, "IP", FAKE_IFNAME,
63                Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress(FAKE_ADDRESS), 0)),
64                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_DNS)),
65                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_GATEWAY)),
66                Arrays.asList(FAKE_PCSCF_ADDRESS),
67                1440);
68
69        assertEquals(response, response);
70        assertEquals(response, response1);
71
72        DataCallResponse response2 = new DataCallResponse(1, -1, 1, 3, "IP", FAKE_IFNAME,
73                Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress(FAKE_ADDRESS), 0)),
74                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_DNS),
75                        NetworkUtils.numericToInetAddress(FAKE_DNS)),
76                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_GATEWAY)),
77                Arrays.asList(FAKE_PCSCF_ADDRESS, FAKE_PCSCF_ADDRESS),
78                1441);
79        assertNotSame(response1, response2);
80        assertNotSame(response1, null);
81        assertNotSame(response1, new String[1]);
82    }
83}
84