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

Commit 2fa15e91 authored by Rambo Wang's avatar Rambo Wang Committed by Gerrit Code Review
Browse files

Merge "Add UT cases for new introduced SignalStrengthUpdateRequest"

parents 9c18ff8a 1059899c
Loading
Loading
Loading
Loading
+125 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.AccessNetworkConstants;
import android.telephony.SignalStrengthUpdateRequest;
import android.telephony.SignalThresholdInfo;

import androidx.test.filters.SmallTest;

import junit.framework.TestCase;

import org.junit.Test;

import java.util.Collection;
import java.util.List;

public class SignalStrengthUpdateRequestTest extends TestCase {

    private SignalThresholdInfo mRssiInfo = new SignalThresholdInfo.Builder()
            .setRadioAccessNetworkType(AccessNetworkConstants.AccessNetworkType.GERAN)
            .setSignalMeasurementType(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI)
            .setThresholds(new int[]{-109, -103, -97, -89})
            .build();

    private SignalThresholdInfo mRscpInfo = new SignalThresholdInfo.Builder()
            .setRadioAccessNetworkType(AccessNetworkConstants.AccessNetworkType.UTRAN)
            .setSignalMeasurementType(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSCP)
            .setThresholds(new int[]{-115, -105, -95, -85})
            .build();

    @Test
    @SmallTest
    public void testPublicConstructorWithInvalidParam() {
        // null Collection
        validateBuilderWithInvalidParam(null);

        // duplication of SignalMeasurementType in Collection
        validateBuilderWithInvalidParam(List.of(mRssiInfo, mRssiInfo));

        // The following two cases can not turn on until the implement is ready:
        // empty Collections
        // validateBuilderWithInvalidParam(List.of());
    }

    @Test
    @SmallTest
    public void testPublicConstructorWithValidParam() {
        Collection<SignalThresholdInfo> infos = List.of(mRssiInfo, mRscpInfo);
        SignalStrengthUpdateRequest request = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(infos).setReportingRequestedWhileIdle(false).build();
        assertFalse(request.isReportingRequestedWhileIdle());
        assertFalse(request.isSystemThresholdReportingRequestedWhileIdle());
        assertEquals(infos, request.getSignalThresholdInfos());
    }

    @Test
    @SmallTest
    public void testParcel() {
        Collection<SignalThresholdInfo> infos = List.of(mRssiInfo, mRscpInfo);
        SignalStrengthUpdateRequest request = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(infos).setReportingRequestedWhileIdle(true).build();

        Parcel p = Parcel.obtain();
        request.writeToParcel(p, 0);
        p.setDataPosition(0);

        SignalStrengthUpdateRequest newRequest =
                SignalStrengthUpdateRequest.CREATOR.createFromParcel(p);
        assertThat(newRequest).isEqualTo(request);
    }

    @Test
    @SmallTest
    public void testEquals() {
        Collection<SignalThresholdInfo> infos1 = List.of(mRssiInfo, mRscpInfo);
        SignalStrengthUpdateRequest request1 = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(infos1).setReportingRequestedWhileIdle(false).build();

        assertTrue(request1.equals(request1));

        // Ordering does not matter
        Collection<SignalThresholdInfo> infos2 = List.of(mRscpInfo, mRssiInfo);
        SignalStrengthUpdateRequest request2 = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(infos2).setReportingRequestedWhileIdle(false).build();
        assertTrue(request1.equals(request2));

        SignalStrengthUpdateRequest request3 = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(infos1).setReportingRequestedWhileIdle(true).build();
        assertFalse(request1.equals(request3));

        SignalStrengthUpdateRequest request4 = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(infos1).setReportingRequestedWhileIdle(false)
                .setSystemThresholdReportingRequestedWhileIdle(true).build();

        // return false if the object is not SignalStrengthUpdateRequest
        assertFalse(request1.equals("test"));
    }

    private void validateBuilderWithInvalidParam(Collection<SignalThresholdInfo> infos) {
        try {
            new SignalStrengthUpdateRequest.Builder()
                    .setSignalThresholdInfos(infos).setReportingRequestedWhileIdle(false).build();
            fail("Exception expected");
        } catch (IllegalArgumentException | NullPointerException expected) {
        }
    }
}
+11 −1
Original line number Original line Diff line number Diff line
@@ -165,7 +165,7 @@ public class SignalThresholdInfoTest extends TestCase {
                .setSignalMeasurementType(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI)
                .setSignalMeasurementType(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI)
                .setHysteresisMs(0)
                .setHysteresisMs(0)
                .setHysteresisDb(0)
                .setHysteresisDb(0)
                .setThresholds(new int[]{})
                .setThresholdsUnlimited(new int[]{})
                .setIsEnabled(false)
                .setIsEnabled(false)
                .build());
                .build());
        stList.add(new SignalThresholdInfo.Builder()
        stList.add(new SignalThresholdInfo.Builder()
@@ -249,6 +249,16 @@ public class SignalThresholdInfoTest extends TestCase {
        buildWithInvalidParameterThrowException(AccessNetworkConstants.AccessNetworkType.GERAN,
        buildWithInvalidParameterThrowException(AccessNetworkConstants.AccessNetworkType.GERAN,
                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI, null);
                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI, null);


        // Empty thresholds
        buildWithInvalidParameterThrowException(AccessNetworkConstants.AccessNetworkType.GERAN,
                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI, new int[]{});


        // Too long thresholds array
        buildWithInvalidParameterThrowException(AccessNetworkConstants.AccessNetworkType.GERAN,
                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI,
                new int[]{-100, -90, -70, -60, -58});

        // Thresholds value out of range
        // Thresholds value out of range
        for (int signalMeasurementType : INVALID_THRESHOLDS_MAP.keySet()) {
        for (int signalMeasurementType : INVALID_THRESHOLDS_MAP.keySet()) {
            List<Integer> invalidThresholds = INVALID_THRESHOLDS_MAP.get(signalMeasurementType);
            List<Integer> invalidThresholds = INVALID_THRESHOLDS_MAP.get(signalMeasurementType);