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.AmrParams;
23 import androidx.test.runner.AndroidJUnit4;
24 
25 import org.junit.runner.RunWith;
26 import org.junit.Test;
27 
28 @RunWith(AndroidJUnit4.class)
29 public class AmrParamsTest {
30     private static final boolean OCTET_ALIGNED = true;
31     private static final int MAX_REDUNDANCY_MILLIS = 1001;
32 
createAmrParams(int amrMode, boolean octetAligned, int maxRedundancyMillis)33     private AmrParams createAmrParams(int amrMode,
34             boolean octetAligned, int maxRedundancyMillis) {
35         return new AmrParams.Builder()
36                 .setAmrMode(amrMode)
37                 .setOctetAligned(octetAligned)
38                 .setMaxRedundancyMillis(maxRedundancyMillis)
39                 .build();
40     }
41 
42     @Test
testConstructorAndGetters()43     public void testConstructorAndGetters() {
44         AmrParams amr = createAmrParams(AmrParams.AMR_MODE_5, OCTET_ALIGNED,
45                 MAX_REDUNDANCY_MILLIS);
46 
47         assertThat(amr.getAmrMode()).isEqualTo(AmrParams.AMR_MODE_5);
48         assertThat(amr.getOctetAligned()).isEqualTo(OCTET_ALIGNED);
49         assertThat(amr.getMaxRedundancyMillis()).isEqualTo(MAX_REDUNDANCY_MILLIS);
50     }
51 
52     @Test
testParcel()53     public void testParcel() {
54         AmrParams amr = createAmrParams(AmrParams.AMR_MODE_5, OCTET_ALIGNED, MAX_REDUNDANCY_MILLIS);
55 
56         Parcel parcel = Parcel.obtain();
57         amr.writeToParcel(parcel, 0);
58         parcel.setDataPosition(0);
59 
60         AmrParams parcelConfig = AmrParams.CREATOR.createFromParcel(parcel);
61         assertThat(amr).isEqualTo(parcelConfig);
62     }
63 
64     @Test
testEqual()65     public void testEqual() {
66         AmrParams amr1 = createAmrParams(AmrParams.AMR_MODE_5, OCTET_ALIGNED,
67                 MAX_REDUNDANCY_MILLIS);
68 
69         AmrParams amr2 = createAmrParams(AmrParams.AMR_MODE_5, OCTET_ALIGNED,
70                 MAX_REDUNDANCY_MILLIS);
71 
72         assertThat(amr1).isEqualTo(amr2);
73     }
74 
75     @Test
testNotEqual()76     public void testNotEqual() {
77         AmrParams amr1 = createAmrParams(AmrParams.AMR_MODE_5, OCTET_ALIGNED,
78                 MAX_REDUNDANCY_MILLIS);
79 
80         AmrParams amr2 = createAmrParams(AmrParams.AMR_MODE_6, OCTET_ALIGNED,
81                 MAX_REDUNDANCY_MILLIS);
82 
83         assertThat(amr1).isNotEqualTo(amr2);
84 
85         AmrParams amr3 = createAmrParams(AmrParams.AMR_MODE_5, OCTET_ALIGNED, 1002);
86 
87         assertThat(amr1).isNotEqualTo(amr3);
88 
89         AmrParams amr4 = createAmrParams(AmrParams.AMR_MODE_5, false, MAX_REDUNDANCY_MILLIS);
90 
91         assertThat(amr1).isNotEqualTo(amr4);
92     }
93 }
94