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 static org.junit.Assert.assertEquals;
     20 
     21 import android.os.Parcel;
     22 import android.telephony.CellIdentityCdma;
     23 import android.test.AndroidTestCase;
     24 import android.test.suitebuilder.annotation.SmallTest;
     25 
     26 /** Unit tests for {@link CellIdentityCdma}. */
     27 
     28 public class CellIdentityCdmaTest extends AndroidTestCase {
     29 
     30     // Network Id ranges from 0 to 65535.
     31     private static final int NETWORK_ID  = 65535;
     32     // CDMA System Id ranges from 0 to 32767
     33     private static final int SYSTEM_ID = 32767;
     34     // Base Station Id ranges from 0 to 65535
     35     private static final int BASESTATION_ID = 65535;
     36     // Longitude ranges from -2592000 to 2592000.
     37     private static final int LONGITUDE = 2592000;
     38     // Latitude ranges from -1296000 to 1296000.
     39     private static final int LATITUDE = 1296000;
     40     private static final String ALPHA_LONG = "long";
     41     private static final String ALPHA_SHORT = "short";
     42 
     43     @SmallTest
     44     public void testConstructor() {
     45         CellIdentityCdma  ci =
     46                 new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     47                         ALPHA_LONG, ALPHA_SHORT);
     48 
     49         assertEquals(NETWORK_ID, ci.getNetworkId());
     50         assertEquals(LATITUDE, ci.getLatitude());
     51         assertEquals(LONGITUDE, ci.getLongitude());
     52         assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
     53         assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());
     54     }
     55 
     56     @SmallTest
     57     public void testNullIsland() {
     58         CellIdentityCdma  ci =
     59                 new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, -1, 0,
     60                         ALPHA_LONG, ALPHA_SHORT);
     61 
     62         assertEquals(Integer.MAX_VALUE, ci.getLatitude());
     63         assertEquals(Integer.MAX_VALUE, ci.getLongitude());
     64     }
     65 
     66     @SmallTest
     67     public void testEquals() {
     68         CellIdentityCdma  ciA =
     69                 new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     70                         ALPHA_LONG, ALPHA_SHORT);
     71         CellIdentityCdma  ciB =
     72                 new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     73                         ALPHA_LONG, ALPHA_SHORT);
     74 
     75         assertTrue(ciA.equals(ciB));
     76 
     77         ciA = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     78                 null, null);
     79         ciB = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     80                 null, null);
     81 
     82         assertTrue(ciA.equals(ciB));
     83 
     84         ciA = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     85                 ALPHA_LONG, ALPHA_SHORT);
     86         ciB = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     87                 null, null);
     88 
     89         assertFalse(ciA.equals(ciB));
     90     }
     91 
     92     @SmallTest
     93     public void testParcel() {
     94         CellIdentityCdma  ci =
     95                 new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
     96                         ALPHA_LONG, ALPHA_SHORT);
     97 
     98         Parcel p = Parcel.obtain();
     99         ci.writeToParcel(p, 0);
    100         p.setDataPosition(0);
    101 
    102         CellIdentityCdma newCi = CellIdentityCdma.CREATOR.createFromParcel(p);
    103         assertEquals(ci, newCi);
    104     }
    105 }
    106