1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.telephony;
18
19import android.test.suitebuilder.annotation.SmallTest;
20
21import static org.junit.Assert.*;
22import static org.mockito.Mockito.*;
23
24import org.junit.After;
25import org.junit.Before;
26import org.junit.Test;
27import org.mockito.Mock;
28
29public class GsmCdmaCallTest extends TelephonyTest {
30
31    @Mock GsmCdmaConnection mConnection1;
32    @Mock GsmCdmaConnection mConnection2;
33    @Mock DriverCall mDriverCall;
34
35    private GsmCdmaCall mCallUnderTest;
36
37    @Before
38    public void setUp() throws Exception {
39        super.setUp(getClass().getSimpleName());
40        mCallUnderTest = new GsmCdmaCall(mCT);
41    }
42
43    @After
44    public void tearDown() throws Exception {
45        mCallUnderTest = null;
46        super.tearDown();
47    }
48
49    @Test @SmallTest
50    public void testAttachDetach() {
51        //verify mConnections has 0 connections and is in IDLE state
52        assertEquals(0, mCallUnderTest.mConnections.size());
53        assertEquals(Call.State.IDLE, mCallUnderTest.getState());
54
55        //attach
56        mDriverCall.state = DriverCall.State.ACTIVE;
57        mCallUnderTest.attach(mConnection1, mDriverCall);
58
59        //verify mConnections has 1 connection and is not in idle
60        assertEquals(1, mCallUnderTest.mConnections.size());
61        assertEquals(Call.State.ACTIVE, mCallUnderTest.getState());
62
63        //detach
64        mCallUnderTest.detach(mConnection1);
65
66        //verify mConnections has 0 connections and is in IDLE state
67        assertEquals(0, mCallUnderTest.mConnections.size());
68        assertEquals(Call.State.IDLE, mCallUnderTest.getState());
69    }
70
71    @Test @SmallTest
72    public void testMultiparty() {
73        //verify mConnections has 0 connections and is in IDLE state
74        assertEquals(0, mCallUnderTest.mConnections.size());
75        assertEquals(Call.State.IDLE, mCallUnderTest.getState());
76
77        //verify isMultiparty is false
78        assertEquals(false, mCallUnderTest.isMultiparty());
79
80        //attach
81        mDriverCall.state = DriverCall.State.ACTIVE;
82        mCallUnderTest.attach(mConnection1, mDriverCall);
83
84        //verify isMultiparty is false
85        assertEquals(false, mCallUnderTest.isMultiparty());
86
87        //attach
88        mCallUnderTest.attach(mConnection2, mDriverCall);
89
90        //verify isMultiparty is true
91        assertEquals(true, mCallUnderTest.isMultiparty());
92    }
93
94    @Test @SmallTest
95    public void testHangup() {
96        //verify hangup calls mCT.hangup
97        try {
98            mCallUnderTest.hangup();
99            verify(mCT).hangup(mCallUnderTest);
100        } catch (Exception e) {
101            fail("Exception " + e + " not expected");
102        }
103    }
104
105    @Test @SmallTest
106    public void testConnectionDisconnected() {
107        //attach
108        mDriverCall.state = DriverCall.State.ACTIVE;
109        mCallUnderTest.attach(mConnection1, mDriverCall);
110        mCallUnderTest.attach(mConnection2, mDriverCall);
111
112        //both connections are active, state not change
113        mCallUnderTest.connectionDisconnected(null);
114        assertEquals(Call.State.ACTIVE, mCallUnderTest.getState());
115
116        // only one attached connection get disconnected, state not changed
117        doReturn(Call.State.DISCONNECTED).when(mConnection1).getState();
118        mCallUnderTest.connectionDisconnected(null);
119        assertEquals(Call.State.ACTIVE, mCallUnderTest.getState());
120
121        doReturn(Call.State.DISCONNECTED).when(mConnection2).getState();
122        mCallUnderTest.connectionDisconnected(null);
123        assertEquals(Call.State.DISCONNECTED, mCallUnderTest.getState());
124    }
125
126}