1 /* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 6239117 27 * @summary test connect works correctly if called multiple times/card removed 28 * @author Andreas Sterbenz 29 * @ignore requires special hardware 30 * @run main/manual TestTransmit 31 */ 32 33 import javax.smartcardio.Card; 34 import javax.smartcardio.CardException; 35 import javax.smartcardio.CardChannel; 36 import javax.smartcardio.CardTerminal; 37 38 public class TestConnectAgain extends Utils { 39 main(String[] args)40 public static void main(String[] args) throws Exception { 41 CardTerminal terminal = getTerminal(args); 42 if (terminal == null) { 43 System.out.println("Skipping the test: " + 44 "no card terminals available"); 45 return; 46 } 47 48 Card card = terminal.connect("T=0"); 49 CardChannel channel = card.getBasicChannel(); 50 transmitTestCommand(channel); 51 52 Card card2 = terminal.connect("*"); 53 if (card != card2) { 54 throw new Exception("Different card object"); 55 } 56 card2 = terminal.connect("T=0"); 57 if (card != card2) { 58 throw new Exception("Different card object"); 59 } 60 61 System.out.println("Remove card!"); 62 terminal.waitForCardAbsent(0); 63 64 try { 65 transmitTestCommand(channel); 66 throw new Exception(); 67 } catch (CardException e) { 68 System.out.println("OK: " + e); 69 } 70 71 System.out.println("Insert card!"); 72 terminal.waitForCardPresent(0); 73 74 try { 75 transmitTestCommand(channel); 76 throw new Exception(); 77 } catch (IllegalStateException e) { 78 System.out.println("OK: " + e); 79 } 80 81 card = terminal.connect("*"); 82 if (card == card2) { 83 throw new Exception("Old card object"); 84 } 85 86 try { 87 transmitTestCommand(channel); 88 throw new Exception(); 89 } catch (IllegalStateException e) { 90 System.out.println("OK: " + e); 91 } 92 93 channel = card.getBasicChannel(); 94 transmitTestCommand(channel); 95 96 card2 = terminal.connect("*"); 97 if (card != card2) { 98 throw new Exception("Different card object"); 99 } 100 101 // disconnect 102 card.disconnect(true); 103 104 System.out.println("OK."); 105 } 106 107 } 108