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.EvsParams; 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 EvsParamsTest { 31 private static final byte CHANNEL_AWARE_MODE = 7; 32 private static final byte CODEC_MODE_REQUEST = 15; 33 private static final boolean USE_HEADER_FULL_ONLY = true; 34 createEvsParams( final int evsBandwidth, final int evsMode, final byte channelAwareMode, final boolean useHeaderFullOnly, final byte codecModeRequest)35 private EvsParams createEvsParams( 36 final int evsBandwidth, 37 final int evsMode, 38 final byte channelAwareMode, 39 final boolean useHeaderFullOnly, 40 final byte codecModeRequest) { 41 return new EvsParams.Builder() 42 .setEvsbandwidth(evsBandwidth) 43 .setEvsMode(evsMode) 44 .setChannelAwareMode(channelAwareMode) 45 .setHeaderFullOnly(useHeaderFullOnly) 46 .setCodecModeRequest(codecModeRequest) 47 .build(); 48 } 49 50 @Test testConstructorAndGetters()51 public void testConstructorAndGetters() { 52 EvsParams evs = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 53 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 54 55 assertThat(evs.getEvsBandwidth()).isEqualTo(EvsParams.EVS_WIDE_BAND); 56 assertThat(evs.getEvsMode()).isEqualTo(EvsParams.EVS_MODE_7); 57 assertThat(evs.getChannelAwareMode()).isEqualTo(CHANNEL_AWARE_MODE); 58 assertThat(evs.getUseHeaderFullOnly()).isEqualTo(USE_HEADER_FULL_ONLY); 59 assertThat(evs.getCodecModeRequest()).isEqualTo(CODEC_MODE_REQUEST); 60 } 61 62 @Test testParcel()63 public void testParcel() { 64 EvsParams evs = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 65 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 66 67 Parcel parcel = Parcel.obtain(); 68 evs.writeToParcel(parcel, 0); 69 parcel.setDataPosition(0); 70 71 EvsParams parcelConfig = EvsParams.CREATOR.createFromParcel(parcel); 72 assertThat(evs).isEqualTo(parcelConfig); 73 } 74 75 @Test testEqual()76 public void testEqual() { 77 EvsParams evs1 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 78 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 79 80 EvsParams evs2 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 81 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 82 83 assertThat(evs1).isEqualTo(evs2); 84 } 85 86 @Test testNotEqual()87 public void testNotEqual() { 88 EvsParams evs1 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 89 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 90 91 EvsParams evs2 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_6, 92 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 93 94 assertThat(evs1).isNotEqualTo(evs2); 95 96 EvsParams evs3 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 97 (byte) 8, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 98 99 assertThat(evs1).isNotEqualTo(evs3); 100 101 EvsParams evs4 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 102 CHANNEL_AWARE_MODE, false, CODEC_MODE_REQUEST); 103 104 assertThat(evs1).isNotEqualTo(evs4); 105 106 EvsParams evs6 = createEvsParams(EvsParams.EVS_SUPER_WIDE_BAND, EvsParams.EVS_MODE_7, 107 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, CODEC_MODE_REQUEST); 108 109 assertThat(evs1).isNotEqualTo(evs6); 110 111 EvsParams evs7 = createEvsParams(EvsParams.EVS_WIDE_BAND, EvsParams.EVS_MODE_7, 112 CHANNEL_AWARE_MODE, USE_HEADER_FULL_ONLY, (byte) 14); 113 114 assertThat(evs1).isNotEqualTo(evs7); 115 } 116 } 117