InProgressCallSessionTest.java revision f2d0fa64860a12423fb8709766d6af90fba5e6cf
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.metrics;
18
19import android.test.suitebuilder.annotation.SmallTest;
20
21import com.android.internal.telephony.TelephonyProto;
22import com.android.internal.telephony.TelephonyTest;
23
24import org.junit.After;
25import org.junit.Before;
26import org.junit.Test;
27
28import static org.junit.Assert.assertEquals;
29import static org.junit.Assert.assertFalse;
30import static org.junit.Assert.assertTrue;
31
32public class InProgressCallSessionTest extends TelephonyTest {
33
34    private InProgressCallSession mCallSession;
35
36    @Before
37    public void setUp() throws Exception {
38        super.setUp(getClass().getSimpleName());
39        mCallSession = new InProgressCallSession(mPhone.getPhoneId());
40    }
41
42    @After
43    public void tearDown() throws Exception {
44        super.tearDown();
45    }
46
47    // Test add event
48    @Test
49    @SmallTest
50    public void testAddEvent() {
51        CallSessionEventBuilder builder = new CallSessionEventBuilder(
52                TelephonyProto.TelephonyCallSession.Event.Type.RIL_RESPONSE)
53                .setRilRequest(1)
54                .setRilRequestId(2)
55                .setRilError(3);
56        mCallSession.addEvent(builder);
57        assertEquals(builder.build(), mCallSession.events.getFirst());
58        assertFalse(mCallSession.isEventsDropped());
59    }
60
61    // Test dropped event scenario
62    @Test
63    @SmallTest
64    public void testEventDropped() {
65        for (int i = 0; i < 301; i++) {
66            CallSessionEventBuilder builder = new CallSessionEventBuilder(
67                    TelephonyProto.TelephonyCallSession.Event.Type.RIL_RESPONSE)
68                    .setRilRequest(1)
69                    .setRilRequestId(i + 1)
70                    .setRilError(3);
71            mCallSession.addEvent(builder);
72        }
73
74        assertTrue(mCallSession.isEventsDropped());
75        assertEquals(2, mCallSession.events.getFirst().getRilRequestId());
76    }
77}