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

Commit 2727dda5 authored by Pengquan Meng's avatar Pengquan Meng Committed by android-build-merger
Browse files

Merge "Add test for NR cellInfo" am: 29cbb8d1

am: 2e8be297

Change-Id: Id0a16fb8822a6fee593b5e4f52f3ecaf500caccc
parents f54e0c86 2e8be297
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -4,20 +4,21 @@ android_test {
    srcs: ["**/*.java"],

    libs: [
        "android.test.runner",
        "ims-common",
        "android.test.base",
        "android.test.mock",
        "android.test.runner",
        "ims-common",
    ],

    static_libs: [
        "guava",
        "android-support-test",
        "frameworks-base-testutils",
        "services.core",
        "telephony-common",
        "guava",
        "mockito-target-minus-junit4",
        "android-support-test",
        "platform-test-annotations",
        "services.core",
        "telephony-common",
        "truth-prebuilt",
    ],

    platform_apis: true,
+103 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import static com.google.common.truth.Truth.assertThat;

import android.os.Parcel;
import android.telephony.CellIdentityNr;
import android.telephony.CellInfo;
import android.test.AndroidTestCase;

import org.junit.Test;

public class CellIdentityNrTest extends AndroidTestCase {
    private static final String MCC = "310";
    private static final String MNC = "260";
    private static final String ANOTHER_MCC = "134";
    private static final String ANOTHER_MNC = "256";
    private static final String ALPHAL = "long operator name";
    private static final String ALPHAS = "lon";
    private static final int NRARFCN = 13456;
    private static final int PCI = 123;
    private static final int TAC = 32767;

    @Test
    public void testGetMethod() {
        // GIVEN an instance of CellIdentityNr
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, MCC, MNC, ALPHAL, ALPHAS);

        // THEN the get method should return correct value
        assertThat(cellIdentityNr.getType()).isEqualTo(CellInfo.TYPE_NR);
        assertThat(cellIdentityNr.getChannelNumber()).isEqualTo(NRARFCN);
        assertThat(cellIdentityNr.getPci()).isEqualTo(PCI);
        assertThat(cellIdentityNr.getTac()).isEqualTo(TAC);
        assertThat(cellIdentityNr.getOperatorAlphaLong()).isEqualTo(ALPHAL);
        assertThat(cellIdentityNr.getOperatorAlphaShort()).isEqualTo(ALPHAS);
        assertThat(cellIdentityNr.getMccString()).isEqualTo(MCC);
        assertThat(cellIdentityNr.getMncString()).isEqualTo(MNC);
    }

    @Test
    public void testEquals_sameParameters() {
        // GIVEN an instance of CellIdentityNr, and create another object with the same parameters
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, MCC, MNC, ALPHAL, ALPHAS);
        CellIdentityNr anotherCellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, MCC, MNC, ALPHAL, ALPHAS);

        // THEN this two objects are equivalent
        assertThat(cellIdentityNr).isEqualTo(anotherCellIdentityNr);
    }

    @Test
    public void testEquals_differentParameters() {
        // GIVEN an instance of CellIdentityNr, and create another object with different parameters
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, MCC, MNC, ALPHAL, ALPHAS);
        CellIdentityNr anotherCellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, ANOTHER_MCC, ANOTHER_MNC, ALPHAL, ALPHAS);

        // THEN this two objects are different
        assertThat(cellIdentityNr).isNotEqualTo(anotherCellIdentityNr);
    }

    @Test
    public void testParcel() {
        // GIVEN an instance of CellIdentityNr
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, MCC, MNC, ALPHAL, ALPHAS);

        // WHEN write the object to parcel and create another object with that parcel
        Parcel parcel = Parcel.obtain();
        cellIdentityNr.writeToParcel(parcel, 0 /* type */);
        parcel.setDataPosition(0);
        CellIdentityNr anotherCellIdentityNr = CellIdentityNr.CREATOR.createFromParcel(parcel);

        // THEN the new object is equal to the old one
        assertThat(anotherCellIdentityNr).isEqualTo(anotherCellIdentityNr);
        assertThat(anotherCellIdentityNr.getType()).isEqualTo(CellInfo.TYPE_NR);
        assertThat(anotherCellIdentityNr.getChannelNumber()).isEqualTo(NRARFCN);
        assertThat(anotherCellIdentityNr.getPci()).isEqualTo(PCI);
        assertThat(anotherCellIdentityNr.getTac()).isEqualTo(TAC);
        assertThat(anotherCellIdentityNr.getOperatorAlphaLong()).isEqualTo(ALPHAL);
        assertThat(anotherCellIdentityNr.getOperatorAlphaShort()).isEqualTo(ALPHAS);
        assertThat(anotherCellIdentityNr.getMccString()).isEqualTo(MCC);
        assertThat(anotherCellIdentityNr.getMncString()).isEqualTo(MNC);
    }
}
+149 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import static com.google.common.truth.Truth.assertThat;

import android.os.Parcel;
import android.telephony.CellSignalStrength;
import android.telephony.CellSignalStrengthNr;
import android.test.AndroidTestCase;

import com.google.common.collect.BoundType;
import com.google.common.collect.Range;

import org.junit.Test;

public class CellSignalStrengthNrTest extends AndroidTestCase {
    private static final int CSIRSRP = -123;
    private static final int CSIRSRQ = -111;
    private static final int ANOTHER_CSIRSRP = -111;
    private static final int ANOTHER_CSIRSRQ = -120;
    private static final int INVALID_CSIRSRP = Integer.MAX_VALUE;
    private static final int CSISINR = 64;
    private static final int SSRSRP = -112;
    private static final int SSRSRQ = -94;
    private static final int SSSINR = 32;

    @Test
    public void testGetMethod() {
        // GIVEN an instance of CellSignalStrengthNr
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // THEN the get method should return correct value
        assertThat(css.getCsiRsrp()).isEqualTo(CSIRSRP);
        assertThat(css.getCsiRsrq()).isEqualTo(CSIRSRQ);
        assertThat(css.getCsiSinr()).isEqualTo(CSISINR);
        assertThat(css.getSsRsrp()).isEqualTo(SSRSRP);
        assertThat(css.getSsRsrq()).isEqualTo(SSRSRQ);
        assertThat(css.getSsSinr()).isEqualTo(SSSINR);
    }

    @Test
    public void testEquals_sameParameters() {
        // GIVEN an instance of CellSignalStrengthNr and another object with the same parameters
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);
        CellSignalStrengthNr anotherCss = new CellSignalStrengthNr(
                CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // THEN this two objects are equivalent
        assertThat(css).isEqualTo(anotherCss);
    }

    @Test
    public void testEquals_differentParameters() {
        // GIVEN an instance of CellSignalStrengthNr and another object with some different
        // parameters
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);
        CellSignalStrengthNr anotherCss = new CellSignalStrengthNr(
                ANOTHER_CSIRSRP, ANOTHER_CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // THEN this two objects are different
        assertThat(css).isNotEqualTo(anotherCss);
    }

    @Test
    public void testAusLevel_validValue() {
        // GIVEN an instance of CellSignalStrengthNr with valid csirsrp
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // THEN the asu level is in range [0, 97]
        assertThat(css.getAsuLevel()).isIn(Range.range(0, BoundType.CLOSED, 97, BoundType.CLOSED));
    }

    @Test
    public void testAsuLevel_invalidValue() {
        // GIVEN an instance of CellSignalStrengthNr with invalid csirsrp
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                INVALID_CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // THEN the asu level is unknown
        assertThat(css.getAsuLevel()).isEqualTo(CellSignalStrengthNr.UNKNOWN_ASU_LEVEL);
    }

    @Test
    public void testSignalLevel_validValue() {
        for (int csiRsrp = -140; csiRsrp <= -44; csiRsrp++) {
            // GIVEN an instance of CellSignalStrengthNr with valid csirsrp
            CellSignalStrengthNr css = new CellSignalStrengthNr(
                    csiRsrp, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

            // THEN the signal level is valid
            assertThat(css.getLevel()).isAnyOf(
                    CellSignalStrength.SIGNAL_STRENGTH_GREAT,
                    CellSignalStrength.SIGNAL_STRENGTH_GOOD,
                    CellSignalStrength.SIGNAL_STRENGTH_MODERATE,
                    CellSignalStrength.SIGNAL_STRENGTH_POOR);
        }
    }

    @Test
    public void testSignalLevel_invalidValue() {
        // GIVEN an instance of CellSignalStrengthNr with invalid csirsrp
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                INVALID_CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // THEN the signal level is unknown
        assertThat(css.getLevel()).isEqualTo(CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN);
    }

    @Test
    public void testParcel() {
        // GIVEN an instance of CellSignalStrengthNr
        CellSignalStrengthNr css = new CellSignalStrengthNr(
                CSIRSRP, CSIRSRQ, CSISINR, SSRSRP, SSRSRQ, SSSINR);

        // WHEN write the object to parcel and create another object with that parcel
        Parcel parcel = Parcel.obtain();
        css.writeToParcel(parcel, 0 /* type */);
        parcel.setDataPosition(0);
        CellSignalStrengthNr anotherCss = CellSignalStrengthNr.CREATOR.createFromParcel(parcel);

        // THEN the new object is equal to the old one
        assertThat(anotherCss).isEqualTo(css);
        assertThat(anotherCss.getCsiRsrp()).isEqualTo(CSIRSRP);
        assertThat(anotherCss.getCsiRsrq()).isEqualTo(CSIRSRQ);
        assertThat(anotherCss.getCsiSinr()).isEqualTo(CSISINR);
        assertThat(anotherCss.getSsRsrp()).isEqualTo(SSRSRP);
        assertThat(anotherCss.getSsRsrq()).isEqualTo(SSRSRQ);
        assertThat(anotherCss.getSsSinr()).isEqualTo(SSSINR);
    }
}