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.euicc; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertNotEquals; 22 import static org.junit.Assert.assertNull; 23 import static org.junit.Assert.assertTrue; 24 25 import com.android.internal.telephony.uicc.IccUtils; 26 27 import org.junit.Test; 28 29 public class EuiccSpecVersionTest { 30 @Test testCreate()31 public void testCreate() { 32 EuiccSpecVersion ver = new EuiccSpecVersion(1, 2, 3); 33 assertEquals(1, ver.getMajor()); 34 assertEquals(2, ver.getMinor()); 35 assertEquals(3, ver.getRevision()); 36 } 37 38 @Test testCreateFromBytes()39 public void testCreateFromBytes() { 40 EuiccSpecVersion ver = new EuiccSpecVersion(new byte[] {1, 2, 3}); 41 assertEquals(1, ver.getMajor()); 42 assertEquals(2, ver.getMinor()); 43 assertEquals(3, ver.getRevision()); 44 } 45 46 @Test testCompareTo()47 public void testCompareTo() { 48 EuiccSpecVersion ver1 = new EuiccSpecVersion(1, 2, 3); 49 EuiccSpecVersion ver2 = new EuiccSpecVersion(1, 2, 3); 50 assertEquals(0, ver1.compareTo(ver2)); 51 assertEquals(0, ver2.compareTo(ver1)); 52 assertTrue(ver1.equals(ver2)); 53 assertFalse(ver1.equals(null)); 54 assertFalse(ver1.equals(new Object())); 55 assertEquals(ver1.hashCode(), ver2.hashCode()); 56 57 ver2 = new EuiccSpecVersion(2, 2, 3); 58 assertEquals(-1, ver1.compareTo(ver2)); 59 assertEquals(1, ver2.compareTo(ver1)); 60 assertFalse(ver2.equals(ver1)); 61 assertNotEquals(ver1.hashCode(), ver2.hashCode()); 62 63 ver2 = new EuiccSpecVersion(1, 3, 3); 64 assertEquals(-1, ver1.compareTo(ver2)); 65 assertEquals(1, ver2.compareTo(ver1)); 66 assertFalse(ver2.equals(ver1)); 67 assertNotEquals(ver1.hashCode(), ver2.hashCode()); 68 69 ver2 = new EuiccSpecVersion(1, 2, 4); 70 assertEquals(-1, ver1.compareTo(ver2)); 71 assertEquals(1, ver2.compareTo(ver1)); 72 assertFalse(ver2.equals(ver1)); 73 assertNotEquals(ver1.hashCode(), ver2.hashCode()); 74 75 ver2 = new EuiccSpecVersion(2, 2, 2); 76 assertEquals(-1, ver1.compareTo(ver2)); 77 assertEquals(1, ver2.compareTo(ver1)); 78 79 ver2 = new EuiccSpecVersion(2, 1, 3); 80 assertEquals(-1, ver1.compareTo(ver2)); 81 assertEquals(1, ver2.compareTo(ver1)); 82 83 ver2 = new EuiccSpecVersion(1, 3, 2); 84 assertEquals(-1, ver1.compareTo(ver2)); 85 assertEquals(1, ver2.compareTo(ver1)); 86 } 87 88 @Test testFromOpenChannelResponse()89 public void testFromOpenChannelResponse() { 90 assertEquals(new EuiccSpecVersion(2, 1, 3), 91 EuiccSpecVersion.fromOpenChannelResponse( 92 IccUtils.hexStringToBytes("E00582030201039000"))); 93 } 94 95 @Test testFromOpenChannelResponseError()96 public void testFromOpenChannelResponseError() { 97 // Invalid data 98 assertNull(EuiccSpecVersion.fromOpenChannelResponse( 99 IccUtils.hexStringToBytes("E00F05820202039000"))); 100 // Wrong length 101 assertNull(EuiccSpecVersion.fromOpenChannelResponse( 102 IccUtils.hexStringToBytes("E005820202039000"))); 103 // Wrong tag 104 assertNull(EuiccSpecVersion.fromOpenChannelResponse( 105 IccUtils.hexStringToBytes("E10482030201039000"))); 106 } 107 } 108