1 /** 2 * Copyright (C) 2023 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 static org.junit.Assert.assertEquals; 22 23 import android.os.Parcel; 24 import android.telephony.imsmedia.RtpContextParams; 25 26 import androidx.test.runner.AndroidJUnit4; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @RunWith(AndroidJUnit4.class) 32 public class RtpContextParamsTest { 33 private static final long SSRC = 4198873603L; 34 private static final long TIMESTAMP = 3277537485L; 35 private static final int SEQUENCE_NUMBER = 4390; 36 private static final long INVALID_SSRC = 4294967296L; 37 private static final int INVALID_SEQUENCE_NUMBER = 65536; 38 private static final int INVALID_NUMBER = -1; 39 40 @Test testConstructorAndGetters()41 public void testConstructorAndGetters() { 42 RtpContextParams rtpContextParams = createRtpContextParams(); 43 44 assertThat(rtpContextParams.getSsrc()).isEqualTo(SSRC); 45 assertThat(rtpContextParams.getTimestamp()).isEqualTo(TIMESTAMP); 46 assertThat(rtpContextParams.getSequenceNumber()).isEqualTo(SEQUENCE_NUMBER); 47 } 48 49 @Test testParcel()50 public void testParcel() { 51 RtpContextParams rtpContextParams = createRtpContextParams(); 52 53 Parcel parcel = Parcel.obtain(); 54 rtpContextParams.writeToParcel(parcel, 0); 55 parcel.setDataPosition(0); 56 57 RtpContextParams parcelParams = RtpContextParams.CREATOR.createFromParcel(parcel); 58 assertThat(rtpContextParams).isEqualTo(parcelParams); 59 } 60 61 @Test testEqual()62 public void testEqual() { 63 RtpContextParams rtpContextParams1 = createRtpContextParams(); 64 RtpContextParams rtpContextParams2 = createRtpContextParams(); 65 66 assertThat(rtpContextParams1).isEqualTo(rtpContextParams2); 67 } 68 69 @Test testNotEqual()70 public void testNotEqual() { 71 RtpContextParams rtpContextParams1 = createRtpContextParams(); 72 73 RtpContextParams rtpContextParams2 = new RtpContextParams.Builder() 74 .setSsrc(198873603) 75 .setTimestamp(TIMESTAMP) 76 .setSequenceNumber(SEQUENCE_NUMBER) 77 .build(); 78 79 assertThat(rtpContextParams1).isNotEqualTo(rtpContextParams2); 80 81 RtpContextParams rtpContextParams3 = new RtpContextParams.Builder() 82 .setSsrc(SSRC) 83 .setTimestamp(327753748) 84 .setSequenceNumber(SEQUENCE_NUMBER) 85 .build(); 86 87 assertThat(rtpContextParams1).isNotEqualTo(rtpContextParams3); 88 89 RtpContextParams rtpContextParams4 = new RtpContextParams.Builder() 90 .setSsrc(SSRC) 91 .setTimestamp(TIMESTAMP) 92 .setSequenceNumber(0) 93 .build(); 94 95 assertThat(rtpContextParams1).isNotEqualTo(rtpContextParams4); 96 } 97 98 @Test(expected = IllegalArgumentException.class) testInvalidSsrc()99 public void testInvalidSsrc() { 100 RtpContextParams rtpContextParams = new RtpContextParams.Builder() 101 .setSsrc(INVALID_SSRC) 102 .setTimestamp(TIMESTAMP) 103 .setSequenceNumber(0) 104 .build(); 105 assertEquals(rtpContextParams.getSsrc(), INVALID_SSRC); 106 } 107 108 @Test(expected = IllegalArgumentException.class) testNegativeSsrc()109 public void testNegativeSsrc() { 110 RtpContextParams rtpContextParams = new RtpContextParams.Builder() 111 .setSsrc(INVALID_NUMBER) 112 .setTimestamp(TIMESTAMP) 113 .setSequenceNumber(0) 114 .build(); 115 assertEquals(rtpContextParams.getSsrc(), INVALID_NUMBER); 116 } 117 118 @Test(expected = IllegalArgumentException.class) testInvalidTimestamp()119 public void testInvalidTimestamp() { 120 RtpContextParams rtpContextParams = new RtpContextParams.Builder() 121 .setSsrc(SSRC) 122 .setTimestamp(Long.MAX_VALUE) 123 .setSequenceNumber(0) 124 .build(); 125 assertEquals(rtpContextParams.getTimestamp(), Long.MAX_VALUE); 126 } 127 128 @Test(expected = IllegalArgumentException.class) testNegativeTimestamp()129 public void testNegativeTimestamp() { 130 RtpContextParams rtpContextParams = new RtpContextParams.Builder() 131 .setSsrc(SSRC) 132 .setTimestamp(INVALID_NUMBER) 133 .setSequenceNumber(0) 134 .build(); 135 assertEquals(rtpContextParams.getTimestamp(), INVALID_NUMBER); 136 } 137 138 @Test(expected = IllegalArgumentException.class) testInvalidSequenceNumber()139 public void testInvalidSequenceNumber() { 140 RtpContextParams rtpContextParams = new RtpContextParams.Builder() 141 .setSsrc(SSRC) 142 .setTimestamp(TIMESTAMP) 143 .setSequenceNumber(INVALID_SEQUENCE_NUMBER) 144 .build(); 145 assertEquals(rtpContextParams.getSequenceNumber(), INVALID_SEQUENCE_NUMBER); 146 } 147 148 @Test(expected = IllegalArgumentException.class) testNegativeSequenceNumber()149 public void testNegativeSequenceNumber() { 150 RtpContextParams rtpContextParams = new RtpContextParams.Builder() 151 .setSsrc(SSRC) 152 .setTimestamp(TIMESTAMP) 153 .setSequenceNumber(INVALID_NUMBER) 154 .build(); 155 assertEquals(rtpContextParams.getSequenceNumber(), INVALID_NUMBER); 156 } 157 createRtpContextParams()158 static RtpContextParams createRtpContextParams() { 159 return new RtpContextParams.Builder() 160 .setSsrc(SSRC) 161 .setTimestamp(TIMESTAMP) 162 .setSequenceNumber(SEQUENCE_NUMBER) 163 .build(); 164 } 165 } 166