Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/smartcardio/ResponseAPDUTest.java
38833 views
/*1* Copyright (c) 2007, 2014, 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 804902126* @summary Construct ResponseAPDU from byte array and check NR< SW, SW1 and SW227* @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;4445@BeforeClass46public static void setUpClass() throws Exception {47//expected values for data,nr,sw1,sw2 and sw4849int apduLen = R1.length;50expectedData = new byte[apduLen - 2];51for (int i = 0; i < (apduLen - 2); i++) {52expectedData[i] = R1[i];53}5455expectedNr = expectedData.length;56expectedSw1 = R1[apduLen - 2] & 0xff;57expectedSw2 = R1[apduLen - 1] & 0xff;58expectedSw = (expectedSw1 << 8) | expectedSw2;59}6061@Test62public static void test() {63assertEquals(RAPDU.getBytes(), R1);64assertEquals(RAPDU.getData(), expectedData);65assertEquals(RAPDU.getNr(), expectedNr);66assertEquals(RAPDU.getSW(), expectedSw);67assertEquals(RAPDU.getSW1(), expectedSw1);68assertEquals(RAPDU.getSW2(), expectedSw2);69}70}717273