1 /* 2 * Copyright (C) 2017 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 17 package android.telephony.embms.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.fail; 21 22 import android.telephony.MbmsGroupCallSession; 23 import android.telephony.cts.embmstestapp.CtsGroupCallService; 24 import android.telephony.mbms.GroupCallCallback; 25 import android.telephony.mbms.MbmsErrors; 26 27 import java.util.ArrayList; 28 import java.util.Arrays; 29 import java.util.Collections; 30 import java.util.List; 31 import org.junit.Test; 32 33 public class MbmsGroupCallSessionTest extends MbmsGroupCallTestBase { 34 @Test 35 public void testDuplicateSession() throws Exception { 36 try { 37 MbmsGroupCallSession failure = MbmsGroupCallSession.create( 38 mContext, mCallbackExecutor, mCallback); 39 fail("Duplicate create should've thrown an exception"); 40 } catch (IllegalStateException e) { 41 // Succeed 42 } 43 } 44 45 @Test 46 public void testClose() throws Exception { 47 mGroupCallSession.close(); 48 49 // Make sure we can't use it anymore 50 try { 51 mGroupCallSession.startGroupCall(0, Collections.emptyList(), Collections.emptyList(), 52 mCallbackExecutor, new GroupCallCallback() {}); 53 fail("GroupCall session should not be usable after close"); 54 } catch (IllegalStateException e) { 55 // Succeed 56 } 57 58 // Make sure that the middleware got the call to close 59 List<List<Object>> closeCalls = getMiddlewareCalls(CtsGroupCallService.METHOD_CLOSE); 60 assertEquals(1, closeCalls.size()); 61 } 62 63 @Test 64 public void testErrorDelivery() throws Exception { 65 mMiddlewareControl.forceErrorCode( 66 MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE); 67 mGroupCallSession.startGroupCall(0, Collections.emptyList(), Collections.emptyList(), 68 mCallbackExecutor, new GroupCallCallback() {}); 69 assertEquals(MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE, 70 mCallback.waitOnError().arg1); 71 } 72 73 @Test 74 public void testCallbacks() throws Exception { 75 List<Integer> expectCurrentSais = Arrays.asList(10, 14, 17); 76 List<List<Integer>> expectAvailableSais = new ArrayList<List<Integer>>() {{ 77 add(expectCurrentSais); 78 add(Arrays.asList(11, 15, 17)); 79 }}; 80 mMiddlewareControl.fireAvailableSaisUpdated(expectCurrentSais, expectAvailableSais); 81 SomeArgs callbackResult = mCallback.waitOnAvailableSaisUpdatedCalls(); 82 assertEquals(callbackResult.arg1, expectCurrentSais); 83 assertEquals(callbackResult.arg2, expectAvailableSais); 84 85 String interfaceName = "TEST"; 86 int index = 10; 87 mMiddlewareControl.fireServiceInterfaceAvailable(interfaceName, index); 88 callbackResult = mCallback.waitOnServiceInterfaceAvailableCalls(); 89 assertEquals(interfaceName, callbackResult.arg1); 90 assertEquals(index, callbackResult.arg2); 91 } 92 } 93