Loading tests/telephonytests/src/com/android/internal/telephony/GsmCdmaCallTest.java +27 −10 Original line number Diff line number Diff line Loading @@ -25,12 +25,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class GsmCdmaCallTest { public class GsmCdmaCallTest extends TelephonyTest { @Mock GsmCdmaCallTracker mCallTracker; @Mock GsmCdmaPhone mPhone; @Mock GsmCdmaConnection mConnection1; @Mock GsmCdmaConnection mConnection2; @Mock DriverCall mDriverCall; Loading @@ -39,15 +36,14 @@ public class GsmCdmaCallTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); doReturn(mPhone).when(mCallTracker).getPhone(); mCallUnderTest = new GsmCdmaCall(mCallTracker); super.setUp(getClass().getSimpleName()); mCallUnderTest = new GsmCdmaCall(mCT); } @After public void tearDown() throws Exception { mCallUnderTest = null; super.tearDown(); } @Test @SmallTest Loading Loading @@ -97,13 +93,34 @@ public class GsmCdmaCallTest { @Test @SmallTest public void testHangup() { //verify hangup calls mCallTracker.hangup //verify hangup calls mCT.hangup try { mCallUnderTest.hangup(); verify(mCallTracker).hangup(mCallUnderTest); verify(mCT).hangup(mCallUnderTest); } catch (Exception e) { fail("Exception " + e + " not expected"); } } @Test @SmallTest public void testConnectionDisconnected() { //attach mDriverCall.state = DriverCall.State.ACTIVE; mCallUnderTest.attach(mConnection1, mDriverCall); mCallUnderTest.attach(mConnection2, mDriverCall); //both connections are active, state not change mCallUnderTest.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mCallUnderTest.getState()); // only one attached connection get disconnected, state not changed doReturn(Call.State.DISCONNECTED).when(mConnection1).getState(); mCallUnderTest.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mCallUnderTest.getState()); doReturn(Call.State.DISCONNECTED).when(mConnection2).getState(); mCallUnderTest.connectionDisconnected(null); assertEquals(Call.State.DISCONNECTED, mCallUnderTest.getState()); } } No newline at end of file tests/telephonytests/src/com/android/internal/telephony/ImsPhoneCallTest.java 0 → 100644 +150 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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 android.test.suitebuilder.annotation.SmallTest; import com.android.ims.ImsStreamMediaProfile; import com.android.internal.telephony.imsphone.ImsPhoneCall; import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; import com.android.internal.telephony.imsphone.ImsPhoneConnection; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; public class ImsPhoneCallTest extends TelephonyTest{ @Mock ImsPhoneConnection mConnection1; @Mock ImsPhoneConnection mConnection2; @Mock ImsStreamMediaProfile mMediaProfile; private ImsPhoneCall mImsCallUT; @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); replaceInstance(ImsPhoneCallTracker.class, "mPhone", mImsCT, mImsPhone); mImsCallUT = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND); } @After public void tearDown() throws Exception { mImsCallUT = null; super.tearDown(); } @Test @SmallTest public void testAttachDetach() { //verify mConnections has 0 connections and is in IDLE state assertEquals(0, mImsCallUT.mConnections.size()); assertEquals(Call.State.IDLE, mImsCallUT.getState()); //attach mImsCallUT.attach(mConnection1, Call.State.ACTIVE); //verify mConnections has 1 connection and is not in idle assertEquals(1, mImsCallUT.mConnections.size()); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); //detach mImsCallUT.detach(mConnection1); //verify mConnections has 0 connections and is in IDLE state assertEquals(0, mImsCallUT.mConnections.size()); assertEquals(Call.State.IDLE, mImsCallUT.getState()); } @Test @SmallTest public void testConnectionDisconnected() { mImsCallUT.attach(mConnection1, Call.State.ACTIVE); mImsCallUT.attach(mConnection2, Call.State.ACTIVE); //both connections are active, state not change mImsCallUT.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); // only one attached connection get disconnected, state not changed doReturn(Call.State.DISCONNECTED).when(mConnection1).getState(); mImsCallUT.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); doReturn(Call.State.DISCONNECTED).when(mConnection2).getState(); mImsCallUT.connectionDisconnected(null); assertEquals(Call.State.DISCONNECTED, mImsCallUT.getState()); } @Test @SmallTest public void testHangup() { try { mImsCallUT.hangup(); verify(mImsCT).hangup(eq(mImsCallUT)); } catch (Exception e) { fail("Exception " + e + " not expected"); } } @Test @SmallTest public void testUpdateRingBackTone() { //Mock local tone mMediaProfile.mAudioDirection = ImsStreamMediaProfile.DIRECTION_INACTIVE; mImsCallProfile.mMediaProfile = mMediaProfile; mImsCallUT.update(null, mImsCall, Call.State.ALERTING); verify(mImsPhone, times(1)).startRingbackTone(); assertEquals(Call.State.ALERTING, mImsCallUT.getState()); mImsCallUT.update(null, mImsCall, Call.State.ACTIVE); verify(mImsPhone, times(1)).stopRingbackTone(); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); } @Test @SmallTest public void testSwitchWith() { // this call in active state with connection 1 attached mImsCallUT.attach(mConnection1, Call.State.ACTIVE); // that call in idle state with connection 2 attached ImsPhoneCall mImsCallThat = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND); mImsCallThat.attach(mConnection2, Call.State.IDLE); mImsCallUT.switchWith(mImsCallThat); assertEquals(Call.State.ACTIVE, mImsCallThat.getState()); assertEquals(Call.State.IDLE, mImsCallUT.getState()); assertEquals(mConnection1, mImsCallThat.getConnections().get(0)); assertEquals(mConnection2, mImsCallUT.getConnections().get(0)); } @Test @SmallTest public void testMultiParty() { doReturn(mImsCall).when(mConnection1).getImsCall(); assertFalse(mImsCallUT.isMultiparty()); verify(mImsCall, times(0)).isMultiparty(); //get the ImsCall from the first Connection mImsCallUT.attach(mConnection1, Call.State.ACTIVE); mImsCallUT.isMultiparty(); verify(mImsCall, times(1)).isMultiparty(); } } Loading
tests/telephonytests/src/com/android/internal/telephony/GsmCdmaCallTest.java +27 −10 Original line number Diff line number Diff line Loading @@ -25,12 +25,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class GsmCdmaCallTest { public class GsmCdmaCallTest extends TelephonyTest { @Mock GsmCdmaCallTracker mCallTracker; @Mock GsmCdmaPhone mPhone; @Mock GsmCdmaConnection mConnection1; @Mock GsmCdmaConnection mConnection2; @Mock DriverCall mDriverCall; Loading @@ -39,15 +36,14 @@ public class GsmCdmaCallTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); doReturn(mPhone).when(mCallTracker).getPhone(); mCallUnderTest = new GsmCdmaCall(mCallTracker); super.setUp(getClass().getSimpleName()); mCallUnderTest = new GsmCdmaCall(mCT); } @After public void tearDown() throws Exception { mCallUnderTest = null; super.tearDown(); } @Test @SmallTest Loading Loading @@ -97,13 +93,34 @@ public class GsmCdmaCallTest { @Test @SmallTest public void testHangup() { //verify hangup calls mCallTracker.hangup //verify hangup calls mCT.hangup try { mCallUnderTest.hangup(); verify(mCallTracker).hangup(mCallUnderTest); verify(mCT).hangup(mCallUnderTest); } catch (Exception e) { fail("Exception " + e + " not expected"); } } @Test @SmallTest public void testConnectionDisconnected() { //attach mDriverCall.state = DriverCall.State.ACTIVE; mCallUnderTest.attach(mConnection1, mDriverCall); mCallUnderTest.attach(mConnection2, mDriverCall); //both connections are active, state not change mCallUnderTest.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mCallUnderTest.getState()); // only one attached connection get disconnected, state not changed doReturn(Call.State.DISCONNECTED).when(mConnection1).getState(); mCallUnderTest.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mCallUnderTest.getState()); doReturn(Call.State.DISCONNECTED).when(mConnection2).getState(); mCallUnderTest.connectionDisconnected(null); assertEquals(Call.State.DISCONNECTED, mCallUnderTest.getState()); } } No newline at end of file
tests/telephonytests/src/com/android/internal/telephony/ImsPhoneCallTest.java 0 → 100644 +150 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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 android.test.suitebuilder.annotation.SmallTest; import com.android.ims.ImsStreamMediaProfile; import com.android.internal.telephony.imsphone.ImsPhoneCall; import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; import com.android.internal.telephony.imsphone.ImsPhoneConnection; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; public class ImsPhoneCallTest extends TelephonyTest{ @Mock ImsPhoneConnection mConnection1; @Mock ImsPhoneConnection mConnection2; @Mock ImsStreamMediaProfile mMediaProfile; private ImsPhoneCall mImsCallUT; @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); replaceInstance(ImsPhoneCallTracker.class, "mPhone", mImsCT, mImsPhone); mImsCallUT = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND); } @After public void tearDown() throws Exception { mImsCallUT = null; super.tearDown(); } @Test @SmallTest public void testAttachDetach() { //verify mConnections has 0 connections and is in IDLE state assertEquals(0, mImsCallUT.mConnections.size()); assertEquals(Call.State.IDLE, mImsCallUT.getState()); //attach mImsCallUT.attach(mConnection1, Call.State.ACTIVE); //verify mConnections has 1 connection and is not in idle assertEquals(1, mImsCallUT.mConnections.size()); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); //detach mImsCallUT.detach(mConnection1); //verify mConnections has 0 connections and is in IDLE state assertEquals(0, mImsCallUT.mConnections.size()); assertEquals(Call.State.IDLE, mImsCallUT.getState()); } @Test @SmallTest public void testConnectionDisconnected() { mImsCallUT.attach(mConnection1, Call.State.ACTIVE); mImsCallUT.attach(mConnection2, Call.State.ACTIVE); //both connections are active, state not change mImsCallUT.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); // only one attached connection get disconnected, state not changed doReturn(Call.State.DISCONNECTED).when(mConnection1).getState(); mImsCallUT.connectionDisconnected(null); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); doReturn(Call.State.DISCONNECTED).when(mConnection2).getState(); mImsCallUT.connectionDisconnected(null); assertEquals(Call.State.DISCONNECTED, mImsCallUT.getState()); } @Test @SmallTest public void testHangup() { try { mImsCallUT.hangup(); verify(mImsCT).hangup(eq(mImsCallUT)); } catch (Exception e) { fail("Exception " + e + " not expected"); } } @Test @SmallTest public void testUpdateRingBackTone() { //Mock local tone mMediaProfile.mAudioDirection = ImsStreamMediaProfile.DIRECTION_INACTIVE; mImsCallProfile.mMediaProfile = mMediaProfile; mImsCallUT.update(null, mImsCall, Call.State.ALERTING); verify(mImsPhone, times(1)).startRingbackTone(); assertEquals(Call.State.ALERTING, mImsCallUT.getState()); mImsCallUT.update(null, mImsCall, Call.State.ACTIVE); verify(mImsPhone, times(1)).stopRingbackTone(); assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); } @Test @SmallTest public void testSwitchWith() { // this call in active state with connection 1 attached mImsCallUT.attach(mConnection1, Call.State.ACTIVE); // that call in idle state with connection 2 attached ImsPhoneCall mImsCallThat = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND); mImsCallThat.attach(mConnection2, Call.State.IDLE); mImsCallUT.switchWith(mImsCallThat); assertEquals(Call.State.ACTIVE, mImsCallThat.getState()); assertEquals(Call.State.IDLE, mImsCallUT.getState()); assertEquals(mConnection1, mImsCallThat.getConnections().get(0)); assertEquals(mConnection2, mImsCallUT.getConnections().get(0)); } @Test @SmallTest public void testMultiParty() { doReturn(mImsCall).when(mConnection1).getImsCall(); assertFalse(mImsCallUT.isMultiparty()); verify(mImsCall, times(0)).isMultiparty(); //get the ImsCall from the first Connection mImsCallUT.attach(mConnection1, Call.State.ACTIVE); mImsCallUT.isMultiparty(); verify(mImsCall, times(1)).isMultiparty(); } }