1 /*
2  * Copyright (C) 2018 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.internal.telephony.uicc;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.os.Parcel;
22 import android.test.AndroidTestCase;
23 import android.test.suitebuilder.annotation.SmallTest;
24 
25 import java.util.Arrays;
26 
27 /** Unit tests for PlmnActRecord */
28 
29 public class PlmnActRecordTest extends AndroidTestCase {
30 
31     private static final String TEST_PLMN_5DIGIT = "12345";
32     private static final byte[] TEST_RECORD_5DIGIT = new byte[] {
33             (byte) 0x21, (byte) 0xF3, (byte) 0x54, (byte) 0xC0, (byte) 0x80};
34     private static final String TEST_PLMN_6DIGIT = "123456";
35     private static final byte[] TEST_RECORD_6DIGIT = new byte[] {
36             (byte) 0x21, (byte) 0x63, (byte) 0x54, (byte) 0xC0, (byte) 0x80};
37 
38     private static final int ACCESS_TECHS_3GPP = PlmnActRecord.ACCESS_TECH_EUTRAN
39             | PlmnActRecord.ACCESS_TECH_UTRAN | PlmnActRecord.ACCESS_TECH_GSM;
40 
41     @SmallTest
testConstructors()42     public void testConstructors() {
43         PlmnActRecord rec = new PlmnActRecord(TEST_PLMN_5DIGIT, ACCESS_TECHS_3GPP);
44         assertEquals(TEST_PLMN_5DIGIT, rec.plmn);
45         assertEquals(ACCESS_TECHS_3GPP, rec.accessTechs);
46 
47         PlmnActRecord rec2 = new PlmnActRecord(TEST_RECORD_5DIGIT, 0);
48         assertEquals(TEST_PLMN_5DIGIT, rec.plmn);
49         assertEquals(ACCESS_TECHS_3GPP, rec.accessTechs);
50 
51         assertEquals(rec, rec2);
52 
53         rec = new PlmnActRecord(TEST_PLMN_6DIGIT, ACCESS_TECHS_3GPP);
54         assertEquals(TEST_PLMN_6DIGIT, rec.plmn);
55         assertEquals(ACCESS_TECHS_3GPP, rec.accessTechs);
56 
57         rec2 = new PlmnActRecord(TEST_RECORD_6DIGIT, 0);
58         assertEquals(TEST_PLMN_6DIGIT, rec.plmn);
59         assertEquals(ACCESS_TECHS_3GPP, rec.accessTechs);
60 
61         assertEquals(rec, rec2);
62     }
63 
64     @SmallTest
testParcel()65     public void testParcel() {
66         PlmnActRecord par = new PlmnActRecord(TEST_PLMN_5DIGIT, ACCESS_TECHS_3GPP);
67 
68         Parcel p = Parcel.obtain();
69         par.writeToParcel(p, 0);
70         p.setDataPosition(0);
71 
72         PlmnActRecord par2 = PlmnActRecord.CREATOR.createFromParcel(p);
73         assertEquals(par, par2);
74     }
75 
76     @SmallTest
testEncoding()77     public void testEncoding() {
78         PlmnActRecord rec = new PlmnActRecord(TEST_RECORD_5DIGIT, 0);
79         assertTrue(Arrays.equals(rec.getBytes(), TEST_RECORD_5DIGIT));
80 
81         rec = new PlmnActRecord(TEST_RECORD_6DIGIT, 0);
82         assertTrue(Arrays.equals(rec.getBytes(), TEST_RECORD_6DIGIT));
83     }
84 }
85