Path: blob/master/test/jdk/sun/security/smartcardio/TestConnect.java
41149 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* @modules java.smartcardio/javax.smartcardio29* @run main/manual TestConnect30*/3132// This test requires special hardware.3334import java.util.List;35import javax.smartcardio.TerminalFactory;36import javax.smartcardio.Card;37import javax.smartcardio.CardChannel;38import javax.smartcardio.CardTerminal;3940public class TestConnect extends Utils {4142public static void main(String[] args) throws Exception {43CardTerminal terminal = getTerminal(args, "SunPCSC");44if (terminal == null) {45System.out.println("Skipping the test: " +46"no card terminals available");47return;48}4950Card card = terminal.connect("*");51System.out.println("card: " + card);52if (card.getProtocol().equals("T=0") == false) {53throw new Exception("Not T=0 protocol");54}55transmit(card);56card.disconnect(true);5758try {59transmit(card);60throw new Exception("transmitted to disconnected card");61} catch (IllegalStateException e) {62System.out.println("OK: " + e);63}6465/* ignore: Solaris bug66try {67card = terminal.connect("T=1");68System.out.println(card);69throw new Exception("connected via T=1");70} catch (CardException e) {71System.out.println("OK: " + e);72}73*/7475try {76card = terminal.connect("T=Foo");77System.out.println(card);78throw new Exception("connected via T=Foo");79} catch (IllegalArgumentException e) {80System.out.println("OK: " + e);81}8283card = terminal.connect("T=0");84System.out.println(card);85if (card.getProtocol().equals("T=0") == false) {86throw new Exception("Not T=0 protocol");87}88transmit(card);89card.disconnect(false);9091card = terminal.connect("*");92System.out.println("card: " + card);93if (card.getProtocol().equals("T=0") == false) {94throw new Exception("Not T=0 protocol");95}96transmit(card);97card.disconnect(true);9899System.out.println("OK.");100}101102private static void transmit(Card card) throws Exception {103CardChannel channel = card.getBasicChannel();104System.out.println("Transmitting...");105transmitTestCommand(channel);106}107108}109110111