CellIdentityWcdmaTest.java revision abbf305669d446b2e7a3fbeaf91d17e475a7e390
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 17package com.android.internal.telephony; 18 19import static org.junit.Assert.assertEquals; 20 21import android.os.Parcel; 22import android.telephony.CellIdentityWcdma; 23import android.test.AndroidTestCase; 24import android.test.suitebuilder.annotation.SmallTest; 25 26/** Unit tests for {@link CellIdentityWcdma}. */ 27 28public class CellIdentityWcdmaTest extends AndroidTestCase { 29 30 // Location Area Code ranges from 0 to 65535. 31 private static final int LAC = 65535; 32 // UMTS Cell Identity ranges from 0 to 268435455. 33 private static final int CID = 268435455; 34 // Primary Scrambling Coderanges from 0 to 511. 35 private static final int PSC = 511; 36 // UMTS Absolute RF Channel Number ranges from 0 to 65535. 37 private static final int UARFCN = 65535; 38 private static final int MCC = 120; 39 private static final int MNC = 260; 40 private static final String MCC_STR = "120"; 41 private static final String MNC_STR = "260"; 42 private static final String ALPHA_LONG = "long"; 43 private static final String ALPHA_SHORT = "short"; 44 45 @SmallTest 46 public void testDefaultConstructor() { 47 CellIdentityWcdma ci = 48 new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, 49 ALPHA_LONG, ALPHA_SHORT); 50 51 assertEquals(LAC, ci.getLac()); 52 assertEquals(CID, ci.getCid()); 53 assertEquals(PSC, ci.getPsc()); 54 assertEquals(MCC, ci.getMcc()); 55 assertEquals(MNC, ci.getMnc()); 56 assertEquals(MCC_STR, ci.getMccStr()); 57 assertEquals(MNC_STR, ci.getMncStr()); 58 assertEquals(MCC_STR + MNC_STR, ci.getMobileNetworkOperator()); 59 assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong()); 60 assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort()); 61 } 62 63 @SmallTest 64 public void testConstructorWithThreeDigitMnc() { 65 final String mncWithThreeDigit = "061"; 66 CellIdentityWcdma ci = 67 new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, mncWithThreeDigit, 68 ALPHA_LONG, ALPHA_SHORT); 69 70 assertEquals(MCC, ci.getMcc()); 71 assertEquals(61, ci.getMnc()); 72 assertEquals(MCC_STR, ci.getMccStr()); 73 assertEquals(mncWithThreeDigit, ci.getMncStr()); 74 assertEquals(MCC_STR + mncWithThreeDigit, ci.getMobileNetworkOperator()); 75 } 76 77 @SmallTest 78 public void testConstructorWithTwoDigitMnc() { 79 final String mncWithTwoDigit = "61"; 80 CellIdentityWcdma ci = 81 new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, mncWithTwoDigit, 82 ALPHA_LONG, ALPHA_SHORT); 83 84 assertEquals(MCC, ci.getMcc()); 85 assertEquals(61, ci.getMnc()); 86 assertEquals(MCC_STR, ci.getMccStr()); 87 assertEquals(mncWithTwoDigit, ci.getMncStr()); 88 assertEquals(MCC_STR + mncWithTwoDigit, ci.getMobileNetworkOperator()); 89 } 90 91 @SmallTest 92 public void testConstructorWithEmptyMccMnc() { 93 final String integerMaxValue = String.valueOf(Integer.MAX_VALUE); 94 CellIdentityWcdma ci = 95 new CellIdentityWcdma(LAC, CID, PSC, UARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 96 97 assertEquals(Integer.MAX_VALUE, ci.getMcc()); 98 assertEquals(Integer.MAX_VALUE, ci.getMnc()); 99 assertEquals(null, ci.getMccStr()); 100 assertEquals(null, ci.getMncStr()); 101 assertEquals(null, ci.getMobileNetworkOperator()); 102 103 ci = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, null, ALPHA_LONG, ALPHA_SHORT); 104 105 assertEquals(MCC, ci.getMcc()); 106 assertEquals(Integer.MAX_VALUE, ci.getMnc()); 107 assertEquals(MCC_STR, ci.getMccStr()); 108 assertEquals(null, ci.getMncStr()); 109 assertEquals(null, ci.getMobileNetworkOperator()); 110 111 ci = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, "", "", ALPHA_LONG, ALPHA_SHORT); 112 113 assertEquals(Integer.MAX_VALUE, ci.getMcc()); 114 assertEquals(Integer.MAX_VALUE, ci.getMnc()); 115 assertEquals(null, ci.getMccStr()); 116 assertEquals(null, ci.getMncStr()); 117 assertEquals(null, ci.getMobileNetworkOperator()); 118 } 119 120 @SmallTest 121 public void testFormerConstructor() { 122 CellIdentityWcdma ci = 123 new CellIdentityWcdma(MCC, MNC, LAC, CID, PSC); 124 125 assertEquals(LAC, ci.getLac()); 126 assertEquals(CID, ci.getCid()); 127 assertEquals(PSC, ci.getPsc()); 128 assertEquals(MCC, ci.getMcc()); 129 assertEquals(MNC, ci.getMnc()); 130 assertEquals(MCC_STR, ci.getMccStr()); 131 assertEquals(MNC_STR, ci.getMncStr()); 132 assertEquals(MCC_STR + MNC_STR, ci.getMobileNetworkOperator()); 133 assertNull(ci.getOperatorAlphaLong()); 134 assertNull(ci.getOperatorAlphaShort()); 135 } 136 137 @SmallTest 138 public void testEquals() { 139 CellIdentityWcdma ciA = new CellIdentityWcdma( 140 LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 141 CellIdentityWcdma ciB = new CellIdentityWcdma( 142 LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 143 144 assertTrue(ciA.equals(ciB)); 145 146 ciA = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 147 ciB = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 148 149 assertTrue(ciA.equals(ciB)); 150 151 ciA = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, null, ALPHA_LONG, ALPHA_SHORT); 152 ciB = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 153 154 assertFalse(ciA.equals(ciB)); 155 } 156 157 @SmallTest 158 public void testParcel() { 159 CellIdentityWcdma ci = 160 new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, 161 ALPHA_LONG, ALPHA_SHORT); 162 163 Parcel p = Parcel.obtain(); 164 ci.writeToParcel(p, 0); 165 p.setDataPosition(0); 166 167 CellIdentityWcdma newCi = CellIdentityWcdma.CREATOR.createFromParcel(p); 168 assertEquals(ci, newCi); 169 } 170} 171