Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/smartcardio/ResponseAPDUTest.java
41144 views
1
/*
2
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8049021 8255546
27
* @summary Construct ResponseAPDU from byte array and check NR< SW, SW1, SW2 and toString
28
* @run testng ResponseAPDUTest
29
*/
30
import javax.smartcardio.ResponseAPDU;
31
import static org.testng.Assert.*;
32
import org.testng.annotations.BeforeClass;
33
import org.testng.annotations.Test;
34
35
public class ResponseAPDUTest {
36
37
static final byte[] R1 = {(byte) 0x07, (byte) 0xA0, (byte) 0x00,
38
(byte) 0x00, (byte) 0x00, (byte) 0x62, (byte) 0x81, (byte) 0x01,
39
(byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x24,
40
(byte) 0x05, (byte) 0x00, (byte) 0x0B, (byte) 0x04, (byte) 0xB0,
41
(byte) 0x25, (byte) 0x90, (byte) 0x00};
42
static final ResponseAPDU RAPDU = new ResponseAPDU(R1);
43
static byte[] expectedData;
44
static int expectedNr, expectedSw1, expectedSw2, expectedSw;
45
static String expectedToString;
46
47
@BeforeClass
48
public static void setUpClass() throws Exception {
49
//expected values for data,nr,sw1,sw2 and sw
50
51
int apduLen = R1.length;
52
expectedData = new byte[apduLen - 2];
53
for (int i = 0; i < (apduLen - 2); i++) {
54
expectedData[i] = R1[i];
55
}
56
57
expectedNr = expectedData.length;
58
expectedSw1 = R1[apduLen - 2] & 0xff;
59
expectedSw2 = R1[apduLen - 1] & 0xff;
60
expectedSw = (expectedSw1 << 8) | expectedSw2;
61
62
expectedToString = "ResponseAPDU: " + R1.length +
63
" bytes, SW=" + Integer.toHexString(expectedSw);
64
}
65
66
@Test
67
public static void test() {
68
assertEquals(RAPDU.getBytes(), R1);
69
assertEquals(RAPDU.getData(), expectedData);
70
assertEquals(RAPDU.getNr(), expectedNr);
71
assertEquals(RAPDU.getSW(), expectedSw);
72
assertEquals(RAPDU.getSW1(), expectedSw1);
73
assertEquals(RAPDU.getSW2(), expectedSw2);
74
assertEquals(RAPDU.toString(), expectedToString);
75
}
76
}
77
78