Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/smartcardio/TestConnect.java
38840 views
/*1* Copyright (c) 2005, 2016, 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 6293769 6294527 630928026* @summary test connect() works27* @author Andreas Sterbenz28* @ignore requires special hardware29* @run main/manual TestConnect30*/3132import java.util.List;33import javax.smartcardio.TerminalFactory;34import javax.smartcardio.Card;35import javax.smartcardio.CardChannel;36import javax.smartcardio.CardTerminal;3738public class TestConnect extends Utils {3940public static void main(String[] args) throws Exception {41CardTerminal terminal = getTerminal(args, "SunPCSC");42if (terminal == null) {43System.out.println("Skipping the test: " +44"no card terminals available");45return;46}4748Card card = terminal.connect("*");49System.out.println("card: " + card);50if (card.getProtocol().equals("T=0") == false) {51throw new Exception("Not T=0 protocol");52}53transmit(card);54card.disconnect(true);5556try {57transmit(card);58throw new Exception("transmitted to disconnected card");59} catch (IllegalStateException e) {60System.out.println("OK: " + e);61}6263/* ignore: Solaris bug64try {65card = terminal.connect("T=1");66System.out.println(card);67throw new Exception("connected via T=1");68} catch (CardException e) {69System.out.println("OK: " + e);70}71*/7273try {74card = terminal.connect("T=Foo");75System.out.println(card);76throw new Exception("connected via T=Foo");77} catch (IllegalArgumentException e) {78System.out.println("OK: " + e);79}8081card = terminal.connect("T=0");82System.out.println(card);83if (card.getProtocol().equals("T=0") == false) {84throw new Exception("Not T=0 protocol");85}86transmit(card);87card.disconnect(false);8889card = terminal.connect("*");90System.out.println("card: " + card);91if (card.getProtocol().equals("T=0") == false) {92throw new Exception("Not T=0 protocol");93}94transmit(card);95card.disconnect(true);9697System.out.println("OK.");98}99100private static void transmit(Card card) throws Exception {101CardChannel channel = card.getBasicChannel();102System.out.println("Transmitting...");103transmitTestCommand(channel);104}105106}107108109