Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/smartcardio/TestMultiplePresent.java
38840 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 6239117 6445367
27
* @summary test that CardTerminals.waitForCard() works
28
* @author Andreas Sterbenz
29
* @ignore requires special hardware
30
* @run main/manual TestPresent
31
*/
32
33
import java.util.List;
34
import javax.smartcardio.CardTerminal;
35
import javax.smartcardio.CardTerminals;
36
import javax.smartcardio.TerminalFactory;
37
import static javax.smartcardio.CardTerminals.State.*;
38
39
public class TestMultiplePresent {
40
41
public static void main(String[] args) throws Exception {
42
Utils.setLibrary(args);
43
TerminalFactory factory = Utils.getTerminalFactory(null);
44
if (factory == null) {
45
System.out.println("Skipping the test: " +
46
"no card terminals available");
47
return;
48
}
49
System.out.println(factory);
50
51
CardTerminals terminals = factory.terminals();
52
List<CardTerminal> list = terminals.list();
53
System.out.println("Terminals: " + list);
54
boolean multipleReaders = true;
55
if (list.size() < 2) {
56
if (list.isEmpty()) {
57
System.out.println("Skipping the test: " +
58
"no card terminals available");
59
return;
60
}
61
System.out.println("Only one reader present, using simplified test");
62
multipleReaders = false;
63
}
64
65
while (true) {
66
boolean present = false;
67
for (CardTerminal terminal : list) {
68
present |= terminal.isCardPresent();
69
}
70
if (present == false) {
71
break;
72
}
73
System.out.println("*** Remove all cards!");
74
Thread.sleep(1000);
75
}
76
System.out.println("OK");
77
78
List<CardTerminal> result;
79
80
result = terminals.list(CARD_PRESENT);
81
if (result.size() != 0) {
82
throw new Exception("List not empty: " + result);
83
}
84
85
if (terminals.waitForChange(1000)) {
86
throw new Exception("no timeout");
87
}
88
if (terminals.waitForChange(1000)) {
89
throw new Exception("no timeout");
90
}
91
result = terminals.list(CARD_PRESENT);
92
if (result.size() != 0) {
93
throw new Exception("List not empty: " + result);
94
}
95
96
System.out.println("*** Insert card!");
97
terminals.waitForChange();
98
99
result = terminals.list(CARD_INSERTION);
100
System.out.println(result);
101
if (result.size() != 1) {
102
throw new Exception("no card present");
103
}
104
CardTerminal t1 = result.get(0);
105
106
result = terminals.list(CARD_INSERTION);
107
System.out.println(result);
108
if ((result.size() != 1) || (result.get(0) != t1)) {
109
throw new Exception("no card present");
110
}
111
112
if (terminals.list(CARD_REMOVAL).size() != 0) {
113
throw new Exception("List not empty: " + result);
114
}
115
if (terminals.list(CARD_REMOVAL).size() != 0) {
116
throw new Exception("List not empty: " + result);
117
}
118
119
120
if (terminals.waitForChange(1000)) {
121
throw new Exception("no timeout");
122
}
123
124
if (terminals.list(CARD_REMOVAL).size() != 0) {
125
throw new Exception("List not empty: " + result);
126
}
127
128
if (multipleReaders) {
129
System.out.println("*** Insert card into other reader!");
130
terminals.waitForChange();
131
132
result = terminals.list(CARD_INSERTION);
133
System.out.println(result);
134
if (result.size() != 1) {
135
throw new Exception("no card present");
136
}
137
CardTerminal t2 = result.get(0);
138
if (t1.getName().equals(t2.getName())) {
139
throw new Exception("same terminal");
140
}
141
142
System.out.println("*** Remove card from 2nd reader!");
143
terminals.waitForChange();
144
145
if (terminals.list(CARD_INSERTION).size() != 0) {
146
throw new Exception("List not empty: " + result);
147
}
148
result = terminals.list(CARD_REMOVAL);
149
if ((result.size() != 1) || (result.get(0) != t2)) {
150
throw new Exception("no or wrong terminal");
151
}
152
}
153
154
System.out.println("*** Remove card from 1st reader!");
155
terminals.waitForChange();
156
157
if (terminals.list(CARD_INSERTION).size() != 0) {
158
throw new Exception("List not empty: " + result);
159
}
160
result = terminals.list(CARD_REMOVAL);
161
if ((result.size() != 1) || (result.get(0) != t1)) {
162
throw new Exception("no or wrong terminal");
163
}
164
165
System.out.println("OK.");
166
}
167
168
}
169
170