1 /**
2  * Copyright (C) 2024 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 com.android.telephony.imsmedia.tests;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.os.Parcel;
22 import android.telephony.imsmedia.RtpReceptionStats;
23 
24 import androidx.test.runner.AndroidJUnit4;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 @RunWith(AndroidJUnit4.class)
30 public class RtpReceptionStatsTest {
31     private static final int INVALID_NUMBER = -1;
32     private static final int RTP_TIMESTAMP = 100;
33     private static final int RTCPSR_TIMESTAMP = 4390;
34     private static final long RTCPSR_NTP_TIMESTAMP = Long.MAX_VALUE;
35     private static final int JITTER_BUFFER_MS = 60;
36     private static final int ROUND_TRIP_TIME_MS = 100;
37 
38     @Test
testConstructorAndGetters()39     public void testConstructorAndGetters() {
40         RtpReceptionStats stats = createRtpReceptionStats();
41         assertThat(stats.getRtpTimestamp()).isEqualTo(RTP_TIMESTAMP);
42         assertThat(stats.getRtcpSrTimestamp()).isEqualTo(RTCPSR_TIMESTAMP);
43         assertThat(stats.getRtcpSrNtpTimestamp()).isEqualTo(RTCPSR_NTP_TIMESTAMP);
44         assertThat(stats.getJitterBufferMs()).isEqualTo(JITTER_BUFFER_MS);
45         assertThat(stats.getRoundTripTimeMs()).isEqualTo(ROUND_TRIP_TIME_MS);
46     }
47 
48     @Test
testParcel()49     public void testParcel() {
50         RtpReceptionStats stats = createRtpReceptionStats();
51 
52         Parcel parcel = Parcel.obtain();
53         stats.writeToParcel(parcel, 0);
54         parcel.setDataPosition(0);
55 
56         RtpReceptionStats parcelParams = RtpReceptionStats.CREATOR.createFromParcel(parcel);
57         assertThat(stats).isEqualTo(parcelParams);
58     }
59 
60     @Test
testEqual()61     public void testEqual() {
62         RtpReceptionStats stats1 = createRtpReceptionStats();
63         RtpReceptionStats stats2 = createRtpReceptionStats();
64 
65         assertThat(stats1).isEqualTo(stats2);
66     }
67 
68     @Test
testNotEqual()69     public void testNotEqual() {
70         RtpReceptionStats stats1 = createRtpReceptionStats();
71 
72         RtpReceptionStats stats2 = new RtpReceptionStats.Builder()
73                 .setRtpTimestamp(500)
74                 .setRtcpSrTimestamp(RTCPSR_TIMESTAMP)
75                 .setRtcpSrNtpTimestamp(RTCPSR_NTP_TIMESTAMP)
76                 .setJitterBufferMs(JITTER_BUFFER_MS)
77                 .setRoundTripTimeMs(ROUND_TRIP_TIME_MS)
78                 .build();
79 
80         assertThat(stats1).isNotEqualTo(stats2);
81 
82         RtpReceptionStats stats3 = new RtpReceptionStats.Builder()
83                 .setRtpTimestamp(RTP_TIMESTAMP)
84                 .setRtcpSrTimestamp(6)
85                 .setRtcpSrNtpTimestamp(RTCPSR_NTP_TIMESTAMP)
86                 .setJitterBufferMs(JITTER_BUFFER_MS)
87                 .setRoundTripTimeMs(ROUND_TRIP_TIME_MS)
88                 .build();
89 
90         assertThat(stats1).isNotEqualTo(stats3);
91 
92         RtpReceptionStats stats4 = new RtpReceptionStats.Builder()
93                 .setRtpTimestamp(RTP_TIMESTAMP)
94                 .setRtcpSrTimestamp(RTCPSR_TIMESTAMP)
95                 .setRtcpSrNtpTimestamp(10)
96                 .setJitterBufferMs(JITTER_BUFFER_MS)
97                 .setRoundTripTimeMs(ROUND_TRIP_TIME_MS)
98                 .build();
99 
100         assertThat(stats1).isNotEqualTo(stats4);
101 
102         RtpReceptionStats stats5 = new RtpReceptionStats.Builder()
103                 .setRtpTimestamp(RTP_TIMESTAMP)
104                 .setRtcpSrTimestamp(RTCPSR_TIMESTAMP)
105                 .setRtcpSrNtpTimestamp(RTCPSR_NTP_TIMESTAMP)
106                 .setJitterBufferMs(120)
107                 .setRoundTripTimeMs(ROUND_TRIP_TIME_MS)
108                 .build();
109 
110         assertThat(stats1).isNotEqualTo(stats5);
111 
112         RtpReceptionStats stats6 = new RtpReceptionStats.Builder()
113                 .setRtpTimestamp(RTP_TIMESTAMP)
114                 .setRtcpSrTimestamp(RTCPSR_TIMESTAMP)
115                 .setRtcpSrNtpTimestamp(RTCPSR_NTP_TIMESTAMP)
116                 .setJitterBufferMs(JITTER_BUFFER_MS)
117                 .setRoundTripTimeMs(200)
118                 .build();
119 
120         assertThat(stats1).isNotEqualTo(stats6);
121     }
122 
123     /**
124      * create the RtpReceptionStats instance
125      * @return Returns the instance
126      */
createRtpReceptionStats()127     public static RtpReceptionStats createRtpReceptionStats() {
128         return new RtpReceptionStats.Builder()
129                 .setRtpTimestamp(RTP_TIMESTAMP)
130                 .setRtcpSrTimestamp(RTCPSR_TIMESTAMP)
131                 .setRtcpSrNtpTimestamp(RTCPSR_NTP_TIMESTAMP)
132                 .setJitterBufferMs(JITTER_BUFFER_MS)
133                 .setRoundTripTimeMs(ROUND_TRIP_TIME_MS)
134                 .build();
135     }
136 }
137