test/jdk/javax/smartcardio/ResponseAPDUTest.java
author thartmann
Mon, 27 May 2019 01:36:04 -0700
changeset 58625 9b54aee889b4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8224062: Improve String index handling Reviewed-by: kvn, rhalade, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     1
/*
44108
8de4ce18c36f 8167525: update jdk tests to remove @compile --add-modules workaround
amlu
parents: 40261
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     4
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     8
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    13
 * accompanied this code).
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    14
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    18
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    21
 * questions.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    22
 */
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    23
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    24
/*
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    25
 * @test
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    26
 * @bug 8049021
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    27
 * @summary Construct ResponseAPDU from byte array and check NR< SW, SW1 and SW2
44108
8de4ce18c36f 8167525: update jdk tests to remove @compile --add-modules workaround
amlu
parents: 40261
diff changeset
    28
 * @run testng ResponseAPDUTest
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    29
 */
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    30
import javax.smartcardio.ResponseAPDU;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    31
import static org.testng.Assert.*;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    32
import org.testng.annotations.BeforeClass;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    33
import org.testng.annotations.Test;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    34
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    35
public class ResponseAPDUTest {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    36
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    37
    static final byte[] R1 = {(byte) 0x07, (byte) 0xA0, (byte) 0x00,
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    38
        (byte) 0x00, (byte) 0x00, (byte) 0x62, (byte) 0x81, (byte) 0x01,
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    39
        (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x24,
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    40
        (byte) 0x05, (byte) 0x00, (byte) 0x0B, (byte) 0x04, (byte) 0xB0,
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    41
        (byte) 0x25, (byte) 0x90, (byte) 0x00};
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    42
    static final ResponseAPDU RAPDU = new ResponseAPDU(R1);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    43
    static byte[] expectedData;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    44
    static int expectedNr, expectedSw1, expectedSw2, expectedSw;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    45
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    46
    @BeforeClass
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    47
    public static void setUpClass() throws Exception {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    48
        //expected values for data,nr,sw1,sw2 and sw
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    49
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    50
        int apduLen = R1.length;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    51
        expectedData = new byte[apduLen - 2];
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    52
        for (int i = 0; i < (apduLen - 2); i++) {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    53
            expectedData[i] = R1[i];
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    54
        }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    55
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    56
        expectedNr = expectedData.length;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    57
        expectedSw1 = R1[apduLen - 2] & 0xff;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    58
        expectedSw2 = R1[apduLen - 1] & 0xff;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    59
        expectedSw = (expectedSw1 << 8) | expectedSw2;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    60
    }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    61
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    62
    @Test
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    63
    public static void test() {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    64
        assertEquals(RAPDU.getBytes(), R1);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    65
        assertEquals(RAPDU.getData(), expectedData);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    66
        assertEquals(RAPDU.getNr(), expectedNr);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    67
        assertEquals(RAPDU.getSW(), expectedSw);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    68
        assertEquals(RAPDU.getSW1(), expectedSw1);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    69
        assertEquals(RAPDU.getSW2(), expectedSw2);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    70
    }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    71
}