1 /** 2 * Copyright (C) 2022 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.RtcpConfig; 23 import androidx.test.filters.SmallTest; 24 import androidx.test.runner.AndroidJUnit4; 25 26 import org.junit.runner.RunWith; 27 import org.junit.Test; 28 29 @RunWith(AndroidJUnit4.class) 30 public class RtcpConfigTest { 31 private static final String NAME = "name"; 32 private static final int PORT = 3333; 33 private static final int INTERVAL = 66; 34 private static final int BLOCK_TYPES = RtcpConfig.FLAG_RTCPXR_DLRR_REPORT_BLOCK; 35 36 @Test testConstructorAndGetters()37 public void testConstructorAndGetters() { 38 RtcpConfig rtcp = new RtcpConfig.Builder() 39 .setCanonicalName(NAME) 40 .setTransmitPort(PORT) 41 .setIntervalSec(INTERVAL) 42 .setRtcpXrBlockTypes(BLOCK_TYPES) 43 .build(); 44 45 assertThat(rtcp.getCanonicalName()).isEqualTo(NAME); 46 assertThat(rtcp.getTransmitPort()).isEqualTo(PORT); 47 assertThat(rtcp.getIntervalSec()).isEqualTo(INTERVAL); 48 assertThat(rtcp.getRtcpXrBlockTypes()).isEqualTo(BLOCK_TYPES); 49 } 50 51 @Test testParcel()52 public void testParcel() { 53 RtcpConfig rtcp = new RtcpConfig.Builder() 54 .setCanonicalName(NAME) 55 .setTransmitPort(PORT) 56 .setIntervalSec(INTERVAL) 57 .setRtcpXrBlockTypes(BLOCK_TYPES) 58 .build(); 59 60 Parcel parcel = Parcel.obtain(); 61 rtcp.writeToParcel(parcel, 0); 62 parcel.setDataPosition(0); 63 64 RtcpConfig parcelConfig = RtcpConfig.CREATOR.createFromParcel(parcel); 65 assertThat(rtcp).isEqualTo(parcelConfig); 66 } 67 68 @Test testEqual()69 public void testEqual() { 70 RtcpConfig rtcp1 = new RtcpConfig.Builder() 71 .setCanonicalName(NAME) 72 .setTransmitPort(PORT) 73 .setIntervalSec(INTERVAL) 74 .setRtcpXrBlockTypes(BLOCK_TYPES) 75 .build(); 76 77 RtcpConfig rtcp2 = new RtcpConfig.Builder() 78 .setCanonicalName(NAME) 79 .setTransmitPort(PORT) 80 .setIntervalSec(INTERVAL) 81 .setRtcpXrBlockTypes(BLOCK_TYPES) 82 .build(); 83 84 assertThat(rtcp1).isEqualTo(rtcp2); 85 } 86 87 @Test testNotEqual()88 public void testNotEqual() { 89 RtcpConfig rtcp1 = new RtcpConfig.Builder() 90 .setCanonicalName(NAME) 91 .setTransmitPort(PORT) 92 .setIntervalSec(INTERVAL) 93 .setRtcpXrBlockTypes(BLOCK_TYPES) 94 .build(); 95 96 RtcpConfig rtcp2 = new RtcpConfig.Builder() 97 .setCanonicalName(NAME) 98 .setTransmitPort(3334) 99 .setIntervalSec(INTERVAL) 100 .setRtcpXrBlockTypes(BLOCK_TYPES) 101 .build(); 102 103 assertThat(rtcp1).isNotEqualTo(rtcp2); 104 105 RtcpConfig rtcp3 = new RtcpConfig.Builder() 106 .setCanonicalName("differs") 107 .setTransmitPort(PORT) 108 .setIntervalSec(INTERVAL) 109 .setRtcpXrBlockTypes(BLOCK_TYPES) 110 .build(); 111 112 assertThat(rtcp1).isNotEqualTo(rtcp3); 113 114 RtcpConfig rtcp4 = new RtcpConfig.Builder() 115 .setCanonicalName(NAME) 116 .setTransmitPort(PORT) 117 .setIntervalSec(60) 118 .setRtcpXrBlockTypes(BLOCK_TYPES) 119 .build(); 120 121 assertThat(rtcp1).isNotEqualTo(rtcp4); 122 123 RtcpConfig rtcp5 = new RtcpConfig.Builder() 124 .setCanonicalName(NAME) 125 .setTransmitPort(PORT) 126 .setIntervalSec(INTERVAL) 127 .setRtcpXrBlockTypes(RtcpConfig.FLAG_RTCPXR_NONE) 128 .build(); 129 130 assertThat(rtcp1).isNotEqualTo(rtcp5); 131 } 132 } 133