Home | History | Annotate | Download | only in cts
      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  */
     16 
     17 package android.telephony.cts;
     18 
     19 import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
     20 import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE;
     21 import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS;
     22 import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS;
     23 
     24 import dalvik.annotation.TestLevel;
     25 import dalvik.annotation.TestTargetClass;
     26 import dalvik.annotation.TestTargetNew;
     27 import dalvik.annotation.TestTargets;
     28 
     29 import android.os.Parcel;
     30 import android.telephony.NeighboringCellInfo;
     31 import android.test.AndroidTestCase;
     32 
     33 @TestTargetClass(NeighboringCellInfo.class)
     34 public class NeighboringCellInfoTest extends AndroidTestCase{
     35     private static final int RSSI = 20;
     36     private static final int CID = 0xffff;
     37 
     38     @TestTargets({
     39         @TestTargetNew(
     40             level = TestLevel.COMPLETE,
     41             method = "NeighboringCellInfo",
     42             args = {}
     43         ),
     44         @TestTargetNew(
     45             level = TestLevel.COMPLETE,
     46             method = "NeighboringCellInfo",
     47             args = {int.class, int.class}
     48         ),
     49         @TestTargetNew(
     50             level = TestLevel.COMPLETE,
     51             method = "NeighboringCellInfo",
     52             args = {Parcel.class}
     53         ),
     54         @TestTargetNew(
     55             level = TestLevel.COMPLETE,
     56             method = "getRssi",
     57             args = {}
     58         ),
     59         @TestTargetNew(
     60             level = TestLevel.COMPLETE,
     61             method = "getLac",
     62             args = {}
     63         ),
     64         @TestTargetNew(
     65                 level = TestLevel.COMPLETE,
     66                 method = "getCid",
     67                 args = {}
     68         ),
     69         @TestTargetNew(
     70                 level = TestLevel.COMPLETE,
     71                 method = "getPsc",
     72                 args = {}
     73         ),
     74         @TestTargetNew(
     75             level = TestLevel.COMPLETE,
     76             method = "setRssi",
     77             args = {int.class}
     78         ),
     79         @TestTargetNew(
     80             level = TestLevel.COMPLETE,
     81             method = "setCid",
     82             args = {int.class}
     83         ),
     84         @TestTargetNew(
     85             level = TestLevel.COMPLETE,
     86             method = "describeContents",
     87             args = {}
     88         ),
     89         @TestTargetNew(
     90             level = TestLevel.COMPLETE,
     91             method = "toString",
     92             args = {}
     93         ),
     94         @TestTargetNew(
     95             level = TestLevel.COMPLETE,
     96             method = "writeToParcel",
     97             args = {Parcel.class, int.class}
     98         )
     99     })
    100     public void testNeighboringCellInfo() {
    101         int rssi = 31;
    102         String location = "ffffffff";
    103         NeighboringCellInfo nc;
    104 
    105         // test constructor
    106         nc = new NeighboringCellInfo(rssi, "FFFFFFF", NETWORK_TYPE_EDGE);
    107         assertEquals(NETWORK_TYPE_EDGE, nc.getNetworkType());
    108         assertEquals(rssi, nc.getRssi());
    109         assertEquals(0xfff, nc.getLac());
    110         assertEquals(0xffff, nc.getCid());
    111         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getPsc());
    112 
    113         nc = new NeighboringCellInfo(rssi, "1FF", NETWORK_TYPE_UMTS);
    114         assertEquals(NETWORK_TYPE_UMTS, nc.getNetworkType());
    115         assertEquals(rssi, nc.getRssi());
    116         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getCid());
    117         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getLac());
    118         assertEquals(0x1ff, nc.getPsc());
    119 
    120         nc = new NeighboringCellInfo(rssi, "1FF", NETWORK_TYPE_UNKNOWN);
    121         assertEquals(NETWORK_TYPE_UNKNOWN, nc.getNetworkType());
    122         assertEquals(rssi, nc.getRssi());
    123         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getCid());
    124         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getLac());
    125         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getPsc());
    126 
    127         // test parcel
    128         nc = new NeighboringCellInfo(rssi, "12345678", NETWORK_TYPE_GPRS);
    129         assertEquals(NETWORK_TYPE_GPRS, nc.getNetworkType());
    130         assertEquals(rssi, nc.getRssi());
    131         assertEquals(0x1234, nc.getLac());
    132         assertEquals(0x5678, nc.getCid());
    133         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nc.getPsc());
    134 
    135         Parcel p = Parcel.obtain();
    136         p.setDataPosition(0);
    137         nc.writeToParcel(p, 0);
    138 
    139         p.setDataPosition(0);
    140         NeighboringCellInfo nw = new NeighboringCellInfo(p);
    141         assertEquals(NETWORK_TYPE_GPRS, nw.getNetworkType());
    142         assertEquals(rssi, nw.getRssi());
    143         assertEquals(0x1234, nw.getLac());
    144         assertEquals(0x5678, nw.getCid());
    145         assertEquals(NeighboringCellInfo.UNKNOWN_CID, nw.getPsc());
    146     }
    147 }
    148