Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 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 
     17 package com.android.internal.telephony;
     18 
     19 import android.os.Parcel;
     20 import android.telephony.CellIdentity;
     21 import android.telephony.CellIdentityTdscdma;
     22 import android.test.AndroidTestCase;
     23 import android.test.suitebuilder.annotation.SmallTest;
     24 
     25 /** Unit tests for {@link CellIdentityTdscdma}. */
     26 
     27 public class CellIdentityTdscdmaTest extends AndroidTestCase {
     28 
     29     // Cell identity ranges from 0 to 268435456.
     30     private static final int CI = 268435456;
     31     // Physical cell id ranges from 0 to 503.
     32     private static final int PCI = 503;
     33     // Tracking area code ranges from 0 to 65535.
     34     private static final int TAC = 65535;
     35     // Absolute RF Channel Number ranges from 0 to 262140.
     36     private static final int EARFCN = 262140;
     37     private static final int MCC = 120;
     38     private static final int MNC = 260;
     39     private static final String MCC_STR = "120";
     40     private static final String MNC_STR = "260";
     41     private static final String ALPHA_LONG = "long";
     42     private static final String ALPHA_SHORT = "short";
     43 
     44     // Location Area Code ranges from 0 to 65535.
     45     private static final int LAC = 65535;
     46     // UMTS Cell Identity ranges from 0 to 268435455.
     47     private static final int CID = 268435455;
     48 
     49     private static final int CPID = 12345;
     50 
     51 
     52     @SmallTest
     53     public void testDefaultConstructor() {
     54         CellIdentityTdscdma ci =
     55                 new CellIdentityTdscdma(MCC_STR, MNC_STR, LAC, CID, CPID);
     56 
     57         assertEquals(MCC_STR, ci.getMccString());
     58         assertEquals(MNC_STR, ci.getMncString());
     59         assertEquals(LAC, ci.getLac());
     60         assertEquals(CID, ci.getCid());
     61         assertEquals(CPID, ci.getCpid());
     62     }
     63 
     64     @SmallTest
     65     public void testConstructorWithEmptyMccMnc() {
     66         CellIdentityTdscdma ci = new CellIdentityTdscdma(null, null, LAC, CID, CPID);
     67 
     68         assertNull(ci.getMccString());
     69         assertNull(ci.getMncString());
     70 
     71         ci = new CellIdentityTdscdma(MCC_STR, null, LAC, CID, CPID);
     72 
     73         assertEquals(MCC_STR, ci.getMccString());
     74         assertNull(ci.getMncString());
     75 
     76         ci = new CellIdentityTdscdma(null, MNC_STR, LAC, CID, CPID);
     77 
     78         assertEquals(MNC_STR, ci.getMncString());
     79         assertNull(ci.getMccString());
     80 
     81         ci = new CellIdentityTdscdma("", "", LAC, CID, CPID);
     82 
     83         assertNull(ci.getMccString());
     84         assertNull(ci.getMncString());
     85     }
     86 
     87     @SmallTest
     88     public void testParcel() {
     89         CellIdentityTdscdma ci = new CellIdentityTdscdma(MCC_STR, MNC_STR, LAC, CID, CPID);
     90 
     91         Parcel p = Parcel.obtain();
     92         ci.writeToParcel(p, 0);
     93         p.setDataPosition(0);
     94 
     95         CellIdentityTdscdma newCi = CellIdentityTdscdma.CREATOR.createFromParcel(p);
     96         assertEquals(ci, newCi);
     97     }
     98 
     99     @SmallTest
    100     public void testParcelWithUnknowMccMnc() {
    101         CellIdentityTdscdma ci =
    102                 new CellIdentityTdscdma(null, null, LAC, CID, CPID, ALPHA_LONG, ALPHA_SHORT);
    103 
    104         Parcel p = Parcel.obtain();
    105         p.writeInt(CellIdentity.TYPE_TDSCDMA);
    106         p.writeString(String.valueOf(Integer.MAX_VALUE));
    107         p.writeString(String.valueOf(Integer.MAX_VALUE));
    108         p.writeString(ALPHA_LONG);
    109         p.writeString(ALPHA_SHORT);
    110         p.writeInt(LAC);
    111         p.writeInt(CID);
    112         p.writeInt(CPID);
    113         p.setDataPosition(0);
    114 
    115         CellIdentityTdscdma newCi = CellIdentityTdscdma.CREATOR.createFromParcel(p);
    116         assertEquals(ci, newCi);
    117     }
    118 
    119     @SmallTest
    120     public void testParcelWithInvalidMccMnc() {
    121         final String invalidMcc = "randomStuff";
    122         final String invalidMnc = "randomStuff";
    123         CellIdentityTdscdma ci =
    124                 new CellIdentityTdscdma(null, null, LAC, CID, CPID, ALPHA_LONG, ALPHA_SHORT);
    125 
    126         Parcel p = Parcel.obtain();
    127         p.writeInt(CellIdentity.TYPE_TDSCDMA);
    128         p.writeString(invalidMcc);
    129         p.writeString(invalidMnc);
    130         p.writeString(ALPHA_LONG);
    131         p.writeString(ALPHA_SHORT);
    132         p.writeInt(LAC);
    133         p.writeInt(CID);
    134         p.writeInt(CPID);
    135         p.setDataPosition(0);
    136 
    137         CellIdentityTdscdma newCi = CellIdentityTdscdma.CREATOR.createFromParcel(p);
    138         assertEquals(ci, newCi);
    139     }
    140 }
    141