Path: blob/master/test/jdk/javax/smartcardio/ResponseAPDUTest.java
41144 views
/*1* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8049021 825554626* @summary Construct ResponseAPDU from byte array and check NR< SW, SW1, SW2 and toString27* @run testng ResponseAPDUTest28*/29import javax.smartcardio.ResponseAPDU;30import static org.testng.Assert.*;31import org.testng.annotations.BeforeClass;32import org.testng.annotations.Test;3334public class ResponseAPDUTest {3536static final byte[] R1 = {(byte) 0x07, (byte) 0xA0, (byte) 0x00,37(byte) 0x00, (byte) 0x00, (byte) 0x62, (byte) 0x81, (byte) 0x01,38(byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x24,39(byte) 0x05, (byte) 0x00, (byte) 0x0B, (byte) 0x04, (byte) 0xB0,40(byte) 0x25, (byte) 0x90, (byte) 0x00};41static final ResponseAPDU RAPDU = new ResponseAPDU(R1);42static byte[] expectedData;43static int expectedNr, expectedSw1, expectedSw2, expectedSw;44static String expectedToString;4546@BeforeClass47public static void setUpClass() throws Exception {48//expected values for data,nr,sw1,sw2 and sw4950int apduLen = R1.length;51expectedData = new byte[apduLen - 2];52for (int i = 0; i < (apduLen - 2); i++) {53expectedData[i] = R1[i];54}5556expectedNr = expectedData.length;57expectedSw1 = R1[apduLen - 2] & 0xff;58expectedSw2 = R1[apduLen - 1] & 0xff;59expectedSw = (expectedSw1 << 8) | expectedSw2;6061expectedToString = "ResponseAPDU: " + R1.length +62" bytes, SW=" + Integer.toHexString(expectedSw);63}6465@Test66public static void test() {67assertEquals(RAPDU.getBytes(), R1);68assertEquals(RAPDU.getData(), expectedData);69assertEquals(RAPDU.getNr(), expectedNr);70assertEquals(RAPDU.getSW(), expectedSw);71assertEquals(RAPDU.getSW1(), expectedSw1);72assertEquals(RAPDU.getSW2(), expectedSw2);73assertEquals(RAPDU.toString(), expectedToString);74}75}767778