Home | History | Annotate | Download | only in telephony
      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 
     17 package com.android.internal.telephony;
     18 
     19 import android.os.Parcel;
     20 import android.telephony.CellIdentity;
     21 import android.telephony.CellIdentityCdma;
     22 import android.telephony.CellIdentityLte;
     23 import android.test.AndroidTestCase;
     24 import android.test.suitebuilder.annotation.SmallTest;
     25 
     26 public class CellIdentityTest extends AndroidTestCase {
     27 
     28     // Cell identity ranges from 0 to 268435456.
     29     private static final int CI = 268435456;
     30     // Physical cell id ranges from 0 to 503.
     31     private static final int PCI = 503;
     32     // Tracking area code ranges from 0 to 65535.
     33     private static final int TAC = 65535;
     34     // Absolute RF Channel Number ranges from 0 to 262140.
     35     private static final int EARFCN = 262140;
     36     private static final int BANDWIDTH = 5000;  // kHz
     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     // Network Id ranges from 0 to 65535.
     45     private static final int NETWORK_ID  = 65535;
     46     // CDMA System Id ranges from 0 to 32767
     47     private static final int SYSTEM_ID = 32767;
     48     // Base Station Id ranges from 0 to 65535
     49     private static final int BASESTATION_ID = 65535;
     50     // Longitude ranges from -2592000 to 2592000.
     51     private static final int LONGITUDE = 2592000;
     52     // Latitude ranges from -1296000 to 1296000.
     53     private static final int LATITUDE = 1296000;
     54 
     55     @SmallTest
     56     public void testEquals() {
     57         CellIdentity ciA = new CellIdentityLte(
     58                 CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
     59         CellIdentity ciB = new CellIdentityLte(
     60                 CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
     61 
     62         assertTrue(ciA.equals(ciB));
     63 
     64         ciA = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, null, null, ALPHA_LONG,
     65                 ALPHA_SHORT);
     66         ciB = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, null, null, ALPHA_LONG,
     67                 ALPHA_SHORT);
     68 
     69         assertTrue(ciA.equals(ciB));
     70 
     71         ciA = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, null, ALPHA_LONG,
     72                 ALPHA_SHORT);
     73         ciB = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, null, null, ALPHA_LONG,
     74                 ALPHA_SHORT);
     75 
     76         assertFalse(ciA.equals(ciB));
     77     }
     78 
     79     @SmallTest
     80     public void testParcel() {
     81         CellIdentity ci = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR,
     82                 ALPHA_LONG, ALPHA_SHORT);
     83 
     84         Parcel p = Parcel.obtain();
     85         ci.writeToParcel(p, 0);
     86         p.setDataPosition(0);
     87 
     88         CellIdentity newCi = CellIdentity.CREATOR.createFromParcel(p);
     89         assertEquals(ci, newCi);
     90 
     91         ci = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     92                         ALPHA_LONG, ALPHA_SHORT);
     93 
     94         p = Parcel.obtain();
     95         ci.writeToParcel(p, 0);
     96         p.setDataPosition(0);
     97 
     98         newCi = CellIdentity.CREATOR.createFromParcel(p);
     99         assertEquals(ci, newCi);
    100     }
    101 }
    102