Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/smartcardio/TestConnect.java
41149 views
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 6293769 6294527 6309280
27
* @summary test connect() works
28
* @author Andreas Sterbenz
29
* @modules java.smartcardio/javax.smartcardio
30
* @run main/manual TestConnect
31
*/
32
33
// This test requires special hardware.
34
35
import java.util.List;
36
import javax.smartcardio.TerminalFactory;
37
import javax.smartcardio.Card;
38
import javax.smartcardio.CardChannel;
39
import javax.smartcardio.CardTerminal;
40
41
public class TestConnect extends Utils {
42
43
public static void main(String[] args) throws Exception {
44
CardTerminal terminal = getTerminal(args, "SunPCSC");
45
if (terminal == null) {
46
System.out.println("Skipping the test: " +
47
"no card terminals available");
48
return;
49
}
50
51
Card card = terminal.connect("*");
52
System.out.println("card: " + card);
53
if (card.getProtocol().equals("T=0") == false) {
54
throw new Exception("Not T=0 protocol");
55
}
56
transmit(card);
57
card.disconnect(true);
58
59
try {
60
transmit(card);
61
throw new Exception("transmitted to disconnected card");
62
} catch (IllegalStateException e) {
63
System.out.println("OK: " + e);
64
}
65
66
/* ignore: Solaris bug
67
try {
68
card = terminal.connect("T=1");
69
System.out.println(card);
70
throw new Exception("connected via T=1");
71
} catch (CardException e) {
72
System.out.println("OK: " + e);
73
}
74
*/
75
76
try {
77
card = terminal.connect("T=Foo");
78
System.out.println(card);
79
throw new Exception("connected via T=Foo");
80
} catch (IllegalArgumentException e) {
81
System.out.println("OK: " + e);
82
}
83
84
card = terminal.connect("T=0");
85
System.out.println(card);
86
if (card.getProtocol().equals("T=0") == false) {
87
throw new Exception("Not T=0 protocol");
88
}
89
transmit(card);
90
card.disconnect(false);
91
92
card = terminal.connect("*");
93
System.out.println("card: " + card);
94
if (card.getProtocol().equals("T=0") == false) {
95
throw new Exception("Not T=0 protocol");
96
}
97
transmit(card);
98
card.disconnect(true);
99
100
System.out.println("OK.");
101
}
102
103
private static void transmit(Card card) throws Exception {
104
CardChannel channel = card.getBasicChannel();
105
System.out.println("Transmitting...");
106
transmitTestCommand(channel);
107
}
108
109
}
110
111