Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61641ce3 authored by Nathan Harold's avatar Nathan Harold
Browse files

Test Range Checks for CellIdentityGsm

Add tests to ensure that the constructor for CellIdentityGsm
actually validates the ranges of input. In particular, test that
the ranges for BSIC are strictly checked at 0-63.

Bug: 122048189
Test: atest CellIdentityTest
Change-Id: Ifc00caa78086e4b4ee6834975d497025cc7bb0f3
parent 1bbf37f7
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ package com.android.internal.telephony;
import android.os.Parcel;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityCdma;
import android.telephony.CellIdentityGsm;
import android.telephony.CellIdentityLte;
import android.telephony.CellInfo;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

@@ -52,6 +54,36 @@ public class CellIdentityTest extends AndroidTestCase {
    // Latitude ranges from -1296000 to 1296000.
    private static final int LATITUDE = 1296000;

    private static final int MAX_LAC = 65535;
    private static final int MAX_CID = 65535;
    private static final int MAX_ARFCN = 65535;
    private static final int MAX_BSIC = 63;

    @SmallTest
    public void testConstructCellIdentityGsm() {
        // Test values below zero (these must all be non-negative)
        CellIdentityGsm gsm = new CellIdentityGsm(-1, -1, -1, -1, null, null, null, null);
        assertEquals(CellInfo.UNAVAILABLE, gsm.getLac());
        assertEquals(CellInfo.UNAVAILABLE, gsm.getCid());
        assertEquals(CellInfo.UNAVAILABLE, gsm.getArfcn());
        assertEquals(CellInfo.UNAVAILABLE, gsm.getBsic());

        // Test max values of LAC, CID, ARFCN, and BSIC
        gsm = new CellIdentityGsm(MAX_LAC, MAX_CID, MAX_ARFCN, MAX_BSIC, null, null, null, null);
        assertEquals(MAX_LAC, gsm.getLac());
        assertEquals(MAX_CID, gsm.getCid());
        assertEquals(MAX_ARFCN, gsm.getArfcn());
        assertEquals(MAX_BSIC, gsm.getBsic());

        // Test max values + 1 of LAC, CID, ARFCN, and BSIC
        gsm = new CellIdentityGsm(
                MAX_LAC + 1, MAX_CID + 1, MAX_ARFCN + 1, MAX_BSIC + 1, null, null, null, null);
        assertEquals(CellInfo.UNAVAILABLE, gsm.getLac());
        assertEquals(CellInfo.UNAVAILABLE, gsm.getCid());
        assertEquals(CellInfo.UNAVAILABLE, gsm.getArfcn());
        assertEquals(CellInfo.UNAVAILABLE, gsm.getBsic());
    }

    @SmallTest
    public void testEquals() {
        CellIdentity ciA = new CellIdentityLte(