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

Commit 4f746244 authored by Megha Patil's avatar Megha Patil
Browse files

Unit Tests for onMemoryAvailaleResult Api

- Unit Testcases covering ERROR, ERROR_RETRY and
OK scenarios
Bug: b/240883268

Test: atest ImsSmsDispatcherTest
Change-Id: Ic96d0437a771ebb9dbe848d89f3641f0cc9a637d
parent 4345e235
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -114,6 +115,73 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
    }

    /**
     * Receive SEND_STATUS_ERROR_RETRY with onMemoryAvailableResult Api and check if
     * sending SMMA Notification is retried once
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailableResultErrorRetry() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 1,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager).onMemoryAvailable(eq(token + 2));
        //2nd Failure should not retry
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 2,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager, times(0)).onMemoryAvailable(eq(token + 3));

    }
    /**
     * Receive SEND_STATUS_OK with onMemoryAvailableResult Api and check if
     * sending SMMA Notification behaviour is correct
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailableResultSuccess() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 1,
                ImsSmsImplBase.SEND_STATUS_OK, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager, times(0)).onMemoryAvailable(eq(token + 2));

    }
    /**
     * Receive SEND_STATUS_ERROR with onMemoryAvailableResult Api and check if
     * sending SMMA Notification behaviour is correct
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailableResultError() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 1,
                ImsSmsImplBase.SEND_STATUS_ERROR, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager, times(0)).onMemoryAvailable(eq(token + 2));

    }
    /**
     * Send an SMS and verify that the token and PDU is correct.
     */