1/*
2 * Copyright (C) 2009 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 */
16package com.android.internal.telephony;
17
18import android.os.Parcel;
19import android.test.AndroidTestCase;
20import android.telephony.NeighboringCellInfo;
21import android.test. suitebuilder.annotation.SmallTest;
22
23import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
24import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE;
25import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS;
26import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS;
27
28public class NeighboringCellInfoTest extends AndroidTestCase {
29    @SmallTest
30    public void testConstructor() {
31        int rssi = 31;
32        NeighboringCellInfo nc;
33
34        nc = new NeighboringCellInfo(rssi, "FFFFFFF", NETWORK_TYPE_EDGE);
35        assertEquals(NETWORK_TYPE_EDGE, nc.getNetworkType());
36        assertEquals(rssi, nc.getRssi());
37        assertEquals(0xfff, nc.getLac());
38        assertEquals(0xffff, nc.getCid());
39        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getPsc());
40
41        nc = new NeighboringCellInfo(rssi, "1FF", NETWORK_TYPE_UMTS);
42        assertEquals(NETWORK_TYPE_UMTS, nc.getNetworkType());
43        assertEquals(rssi, nc.getRssi());
44        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getCid());
45        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getLac());
46        assertEquals(0x1ff, nc.getPsc());
47
48        nc = new NeighboringCellInfo(rssi, "1FF", NETWORK_TYPE_UNKNOWN);
49        assertEquals(NETWORK_TYPE_UNKNOWN, nc.getNetworkType());
50        assertEquals(rssi, nc.getRssi());
51        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getCid());
52        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getLac());
53        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getPsc());
54    }
55
56    @SmallTest
57    public void testParcel() {
58        int rssi = 20;
59
60        NeighboringCellInfo nc = new NeighboringCellInfo(rssi, "12345678", NETWORK_TYPE_GPRS);
61        assertEquals(NETWORK_TYPE_GPRS, nc.getNetworkType());
62        assertEquals(rssi, nc.getRssi());
63        assertEquals(0x1234, nc.getLac());
64        assertEquals(0x5678, nc.getCid());
65        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getPsc());
66
67        Parcel p = Parcel.obtain();
68        p.setDataPosition(0);
69        nc.writeToParcel(p, 0);
70
71        p.setDataPosition(0);
72        NeighboringCellInfo nw = new NeighboringCellInfo(p);
73        assertEquals(NETWORK_TYPE_GPRS, nw.getNetworkType());
74        assertEquals(rssi, nw.getRssi());
75        assertEquals(0x1234, nw.getLac());
76        assertEquals(0x5678, nw.getCid());
77        assertEquals(NeighboringCellInfo.UNKNOWN_CID, nw.getPsc());
78     }
79}
80