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

Commit 0ec19d5f authored by Megha Patil's avatar Megha Patil Committed by Android (Google) Code Review
Browse files

Merge "Unit Testing for RP-SMMA Implementation in frameworks"

parents 247d78fb f75e8abf
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -98,6 +98,18 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        super.tearDown();
    }

   /**
     * Send Memory Availability Notification and verify that the token is correct.
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailable() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
    }
    /**
     * Send an SMS and verify that the token and PDU is correct.
     */
+26 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.telephony;
import static com.android.internal.telephony.SmsResponse.NO_ERROR_CODE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@@ -33,6 +34,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.os.AsyncResult;
import android.os.Message;
import android.provider.Telephony.Sms.Intents;
import android.telephony.PhoneNumberUtils;
@@ -96,6 +98,30 @@ public class SmsDispatchersControllerTest extends TelephonyTest {
        assertTrue(mSmsDispatchersController.isIms());
    }

    @Test @SmallTest
    public void testReportSmsMemoryStatus() throws Exception {
        int eventReportMemoryStatusDone = 3;
        SmsStorageMonitor smsStorageMonnitor = new SmsStorageMonitor(mPhone);
        Message result = smsStorageMonnitor.obtainMessage(eventReportMemoryStatusDone);
        ImsSmsDispatcher mImsSmsDispatcher = Mockito.mock(ImsSmsDispatcher.class);
        mSmsDispatchersController.setImsSmsDispatcher(mImsSmsDispatcher);
        mSmsDispatchersController.reportSmsMemoryStatus(result);
        AsyncResult ar = (AsyncResult) result.obj;
        verify(mImsSmsDispatcher).onMemoryAvailable();
        assertNull(ar.exception);
    }

    @Test @SmallTest
    public void testReportSmsMemoryStatusFailure() throws Exception {
        int eventReportMemoryStatusDone = 3;
        SmsStorageMonitor smsStorageMonnitor = new SmsStorageMonitor(mPhone);
        Message result = smsStorageMonnitor.obtainMessage(eventReportMemoryStatusDone);
        mSmsDispatchersController.setImsSmsDispatcher(null);
        mSmsDispatchersController.reportSmsMemoryStatus(result);
        AsyncResult ar = (AsyncResult) result.obj;
        assertNotNull(ar.exception);
    }

    @Test @SmallTest @FlakyTest
    public void testSendImsGmsTest() throws Exception {
        switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM);
+40 −0
Original line number Diff line number Diff line
@@ -20,8 +20,11 @@ import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Message;
import android.provider.Telephony;
import android.test.suitebuilder.annotation.MediumTest;
@@ -34,6 +37,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;


@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -137,6 +142,41 @@ public class SmsStorageMonitorTest extends TelephonyTest {
                .reportSmsMemoryStatus(eq(false), any(Message.class));
    }

    @Test @SmallTest
    public void testReportSmsMemoryStatusToIms() {
        Resources mockResources = Mockito.mock(Resources.class);
        doReturn(mockResources).when(mContext).getResources();
        doReturn(true).when(mockResources).getBoolean(anyInt());
        doReturn(true).when(mIccSmsInterfaceManager.mDispatchersController).isIms();

        mSimulatedCommands.notifyRadioOn();
        processAllMessages();

        verify(mSimulatedCommandsVerifier, never()).reportSmsMemoryStatus(anyBoolean(),
                any(Message.class));

        // Send DEVICE_STORAGE_FULL
        mContextFixture.getTestDouble().sendBroadcast(
                new Intent(Intent.ACTION_DEVICE_STORAGE_FULL));
        processAllMessages();

        verify(mSimulatedCommandsVerifier).reportSmsMemoryStatus(eq(false), any(Message.class));
        assertFalse(mSmsStorageMonitor.isStorageAvailable());

        mSimulatedCommands.notifyRadioOn();
        processAllMessages();

        verify(mSimulatedCommandsVerifier).reportSmsMemoryStatus(eq(false), any(Message.class));

        // Send DEVICE_STORAGE_NOT_FULL
        mContextFixture.getTestDouble().sendBroadcast(
                new Intent(Intent.ACTION_DEVICE_STORAGE_NOT_FULL));
        processAllMessages();

        verify(mIccSmsInterfaceManager.mDispatchersController)
                .reportSmsMemoryStatus(any(Message.class));
    }

    @Test @SmallTest
    public void testReportSmsMemoryStatusDuringRetry() {
        mSimulatedCommands.setReportSmsMemoryStatusFailResponse(true);