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

Commit 5bb1ce32 authored by Brad Ebinger's avatar Brad Ebinger Committed by Gerrit Code Review
Browse files

Merge "Adds tests to ensure correct API behavior"

parents 7c1aac23 f6b308a3
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ public class ImsFeatureTest {
    }

    private TestImsFeature mTestImsFeature;
    private CapabilityCallback mCapabilityCallback;

    @Mock
    private IImsFeatureStatusCallback mTestStatusCallback;
@@ -77,14 +76,11 @@ public class ImsFeatureTest {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mTestImsFeature = new TestImsFeature();
        mCapabilityCallback = Mockito.spy(new CapabilityCallback());
        mTestImsFeature.addCapabilityCallback(mCapabilityCallback);
    }

    @After
    public void tearDown() {
        mTestImsFeature = null;
        mCapabilityCallback = null;
    }

    @Test
@@ -167,14 +163,17 @@ public class ImsFeatureTest {
    @SmallTest
    @Test
    public void testSetCapabilityConfigError() throws Exception {
        CapabilityCallback capabilityCallback = Mockito.spy(new CapabilityCallback());
        mTestImsFeature.addCapabilityCallback(capabilityCallback);

        CapabilityChangeRequest request = new CapabilityChangeRequest();
        request.addCapabilitiesToEnableForTech(TestImsFeature.CAPABILITY_TEST_1,
                ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);

        mTestImsFeature.setCapabilitiesResult = ImsFeature.CAPABILITY_ERROR_GENERIC;
        mTestImsFeature.requestChangeEnabledCapabilities(request, mCapabilityCallback);
        mTestImsFeature.requestChangeEnabledCapabilities(request, capabilityCallback);

        verify(mCapabilityCallback).onChangeCapabilityConfigurationError(
        verify(capabilityCallback).onChangeCapabilityConfigurationError(
                eq(TestImsFeature.CAPABILITY_TEST_1),
                eq(ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN),
                eq(ImsFeature.CAPABILITY_ERROR_GENERIC));
@@ -197,6 +196,9 @@ public class ImsFeatureTest {
    @SmallTest
    @Test
    public void testNotifyCapabilityStatusChangedCallback() throws Exception {
        CapabilityCallback capabilityCallback = Mockito.spy(new CapabilityCallback());
        mTestImsFeature.addCapabilityCallback(capabilityCallback);

        ImsFeature.Capabilities status =
                new ImsFeature.Capabilities();
        status.addCapabilities(TestImsFeature.CAPABILITY_TEST_1);
@@ -205,7 +207,7 @@ public class ImsFeatureTest {
        mTestImsFeature.capabilitiesStatusChanged(status);

        assertEquals(status.getMask(), mTestImsFeature.queryCapabilityStatus().getMask());
        verify(mCapabilityCallback).onCapabilitiesStatusChanged(
        verify(capabilityCallback).onCapabilitiesStatusChanged(
                eq(TestImsFeature.CAPABILITY_TEST_1 | TestImsFeature.CAPABILITY_TEST_2));
    }

@@ -254,4 +256,23 @@ public class ImsFeatureTest {

        assertEquals(request, result);
    }

    @SmallTest
    @Test
    public void testCapabilityCallbackWhenRegistering() throws Exception {
        CapabilityCallback capabilityCallback = Mockito.spy(new CapabilityCallback());

        // Signal the status has changed
        ImsFeature.Capabilities status =
                new ImsFeature.Capabilities();
        status.addCapabilities(TestImsFeature.CAPABILITY_TEST_1);
        status.addCapabilities(TestImsFeature.CAPABILITY_TEST_2);
        mTestImsFeature.capabilitiesStatusChanged(status);

        // addCapabilityCallback should cause capabilityCallback to call back with status.
        mTestImsFeature.addCapabilityCallback(capabilityCallback);
        assertEquals(status.getMask(), mTestImsFeature.queryCapabilityStatus().getMask());
        verify(capabilityCallback).onCapabilitiesStatusChanged(
                eq(TestImsFeature.CAPABILITY_TEST_1 | TestImsFeature.CAPABILITY_TEST_2));
    }
}
+97 −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 android.telephony.ims;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import android.os.IBinder;
import android.os.RemoteException;
import android.telephony.AccessNetworkConstants;
import android.telephony.ims.aidl.IImsRegistrationCallback;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.TelephonyTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

public class ImsMmTelManagerTests extends TelephonyTest {

    @Mock
    IBinder mMockBinder;
    @Mock
    ITelephony mMockTelephonyInterface;

    public class LocalCallback extends ImsMmTelManager.RegistrationCallback {
        int mRegResult = -1;

        @Override
        public void onRegistered(int imsRadioTech) {
            mRegResult = imsRadioTech;
        }
    }

    @Before
    public void setUp() throws Exception {
        super.setUp("ImsMmTelManagerTests");
        doReturn(mMockTelephonyInterface).when(mMockBinder).queryLocalInterface(anyString());
        mServiceManagerMockedServices.put("phone", mMockBinder);
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    /**
     * Ensure that LTE-> WWAN and IWLAN-> WLAN map correctly as well as ensure that wacky values
     * result in a -1 result.
     */
    @SmallTest
    @Test
    public void testCallbackValues() throws RemoteException {
        LocalCallback cb = new LocalCallback();
        ImsMmTelManager managerUT = new ImsMmTelManager(0);
        managerUT.registerImsRegistrationCallback(Runnable::run, cb);
        // Capture the RegistrationCallback that was registered.
        ArgumentCaptor<IImsRegistrationCallback> callbackCaptor =
                ArgumentCaptor.forClass(IImsRegistrationCallback.class);
        verify(mMockTelephonyInterface).registerImsRegistrationCallback(anyInt(),
                callbackCaptor.capture());

        IImsRegistrationCallback cbBinder = callbackCaptor.getValue();
        // Ensure the transport types are correct
        cbBinder.onRegistered(ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
        assertEquals(AccessNetworkConstants.TransportType.WWAN, cb.mRegResult);
        cbBinder.onRegistered(ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
        assertEquals(AccessNetworkConstants.TransportType.WLAN, cb.mRegResult);
        cbBinder.onRegistered(ImsRegistrationImplBase.REGISTRATION_TECH_NONE);
        assertEquals(-1, cb.mRegResult);
        // Wacky value
        cbBinder.onRegistered(0xDEADBEEF);
        assertEquals(-1, cb.mRegResult);
    }
}