1/*
2 * Copyright (C) 2006 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
17package com.android.internal.telephony;
18
19import com.android.internal.telephony.gsm.SimTlv;
20import com.android.internal.telephony.IccUtils;
21import junit.framework.TestCase;
22import android.test.suitebuilder.annotation.SmallTest;
23
24
25public class SimUtilsTest extends TestCase {
26
27    @SmallTest
28    public void testBasic() throws Exception {
29        byte[] data, data2;
30
31        /*
32         * bcdToString()
33         */
34
35        // An EF[ICCID] record
36        data = IccUtils.hexStringToBytes("981062400510444868f2");
37        assertEquals("8901260450014484862", IccUtils.bcdToString(data, 0, data.length));
38
39        // skip the first and last bytes
40        assertEquals("0126045001448486", IccUtils.bcdToString(data, 1, data.length - 2));
41
42        // Stops on invalid BCD value
43        data = IccUtils.hexStringToBytes("98E062400510444868f2");
44        assertEquals("890", IccUtils.bcdToString(data, 0, data.length));
45
46        // skip the high nibble 'F' since some PLMNs have it
47        data = IccUtils.hexStringToBytes("98F062400510444868f2");
48        assertEquals("890260450014484862", IccUtils.bcdToString(data, 0, data.length));
49
50        /*
51         * gsmBcdByteToInt()
52         */
53
54        assertEquals(98, IccUtils.gsmBcdByteToInt((byte) 0x89));
55
56        // Out of range is treated as 0
57        assertEquals(8, IccUtils.gsmBcdByteToInt((byte) 0x8c));
58
59        /*
60         * cdmaBcdByteToInt()
61         */
62
63        assertEquals(89, IccUtils.cdmaBcdByteToInt((byte) 0x89));
64
65        // Out of range is treated as 0
66        assertEquals(80, IccUtils.cdmaBcdByteToInt((byte) 0x8c));
67
68        /*
69         * adnStringFieldToString()
70         */
71
72
73        data = IccUtils.hexStringToBytes("00566f696365204d61696c07918150367742f3ffffffffffff");
74        // Again, skip prepended 0
75        // (this is an EF[ADN] record)
76        assertEquals("Voice Mail", IccUtils.adnStringFieldToString(data, 1, data.length - 15));
77
78        data = IccUtils.hexStringToBytes("809673539A5764002F004DFFFFFFFFFF");
79        // (this is from an EF[ADN] record)
80        assertEquals("\u9673\u539A\u5764/M", IccUtils.adnStringFieldToString(data, 0, data.length));
81
82        data = IccUtils.hexStringToBytes("810A01566fec6365204de0696cFFFFFF");
83        // (this is made up to test since I don't have a real one)
84        assertEquals("Vo\u00ECce M\u00E0il", IccUtils.adnStringFieldToString(data, 0, data.length));
85
86        data = IccUtils.hexStringToBytes("820505302D82d32d31");
87        // Example from 3GPP TS 11.11 V18.1.3.0 annex B
88        assertEquals("-\u0532\u0583-1", IccUtils.adnStringFieldToString(data, 0, data.length));
89    }
90
91}
92