CellIdentityTest.java revision 7aa0254d5d8f08163b3702a2a1c9602366f568d8
17aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu/* 27aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * Copyright 2017 The Android Open Source Project 37aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * 47aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * Licensed under the Apache License, Version 2.0 (the "License"); 57aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * you may not use this file except in compliance with the License. 67aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * You may obtain a copy of the License at 77aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * 87aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * http://www.apache.org/licenses/LICENSE-2.0 97aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * 107aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * Unless required by applicable law or agreed to in writing, software 117aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * distributed under the License is distributed on an "AS IS" BASIS, 127aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * See the License for the specific language governing permissions and 147aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu * limitations under the License. 157aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu */ 167aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 177aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yupackage com.android.internal.telephony; 187aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 197aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yuimport android.os.Parcel; 207aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yuimport android.telephony.CellIdentity; 217aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yuimport android.telephony.CellIdentityCdma; 227aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yuimport android.telephony.CellIdentityLte; 237aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yuimport android.test.AndroidTestCase; 247aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yuimport android.test.suitebuilder.annotation.SmallTest; 257aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 267aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yupublic class CellIdentityTest extends AndroidTestCase { 277aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 287aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Cell identity ranges from 0 to 268435456. 297aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int CI = 268435456; 307aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Physical cell id ranges from 0 to 503. 317aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int PCI = 503; 327aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Tracking area code ranges from 0 to 65535. 337aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int TAC = 65535; 347aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Absolute RF Channel Number ranges from 0 to 262140. 357aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int EARFCN = 262140; 367aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int MCC = 120; 377aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int MNC = 260; 387aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final String MCC_STR = "120"; 397aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final String MNC_STR = "260"; 407aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final String ALPHA_LONG = "long"; 417aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final String ALPHA_SHORT = "short"; 427aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 437aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Network Id ranges from 0 to 65535. 447aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int NETWORK_ID = 65535; 457aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // CDMA System Id ranges from 0 to 32767 467aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int SYSTEM_ID = 32767; 477aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Base Station Id ranges from 0 to 65535 487aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int BASESTATION_ID = 65535; 497aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Longitude ranges from -2592000 to 2592000. 507aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int LONGITUDE = 2592000; 517aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu // Latitude ranges from -1296000 to 1296000. 527aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu private static final int LATITUDE = 1296000; 537aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 547aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu @SmallTest 557aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu public void testEquals() { 567aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu CellIdentity ciA = new CellIdentityLte( 577aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 587aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu CellIdentity ciB = new CellIdentityLte( 597aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 607aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 617aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu assertTrue(ciA.equals(ciB)); 627aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 637aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ciA = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 647aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ciB = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 657aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 667aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu assertTrue(ciA.equals(ciB)); 677aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 687aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ciA = new CellIdentityLte(CI, PCI, TAC, EARFCN, MCC_STR, null, ALPHA_LONG, ALPHA_SHORT); 697aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ciB = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 707aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 717aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu assertFalse(ciA.equals(ciB)); 727aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu } 737aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 747aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu @SmallTest 757aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu public void testParcel() { 767aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu CellIdentity ci = new CellIdentityLte(CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG, 777aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ALPHA_SHORT); 787aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 797aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu Parcel p = Parcel.obtain(); 807aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ci.writeToParcel(p, 0); 817aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu p.setDataPosition(0); 827aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 837aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu CellIdentity newCi = CellIdentity.CREATOR.createFromParcel(p); 847aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu assertEquals(ci, newCi); 857aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 867aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ci = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, 877aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ALPHA_LONG, ALPHA_SHORT); 887aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 897aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu p = Parcel.obtain(); 907aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu ci.writeToParcel(p, 0); 917aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu p.setDataPosition(0); 927aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu 937aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu newCi = CellIdentity.CREATOR.createFromParcel(p); 947aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu assertEquals(ci, newCi); 957aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu } 967aa0254d5d8f08163b3702a2a1c9602366f568d8Jack Yu} 97