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/TestPresent.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 6293769 6294527
27
* @summary test that the isCardPresent()/waitForX() APIs work correctly
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.TerminalFactory;
36
37
public class TestPresent extends Utils {
38
39
private static class Timer {
40
private long time = System.currentTimeMillis();
41
long update() {
42
long t = System.currentTimeMillis();
43
long diff = t - time;
44
time = t;
45
return diff;
46
}
47
long print() {
48
long t = update();
49
System.out.println("Elapsed time: " + t + " ms.");
50
return t;
51
}
52
}
53
54
private static boolean isFalse(boolean b) throws Exception {
55
if (b) {
56
throw new Exception("not false");
57
}
58
return b;
59
}
60
61
private static boolean isTrue(boolean b) throws Exception {
62
if (!b) {
63
throw new Exception("not true");
64
}
65
return b;
66
}
67
68
public static void main(String[] args) throws Exception {
69
CardTerminal terminal = getTerminal(args);
70
if (terminal == null) {
71
System.out.println("Skipping the test: " +
72
"no card terminals available");
73
return;
74
}
75
76
while (terminal.isCardPresent()) {
77
System.out.println("*** Remove card!");
78
Thread.sleep(1000);
79
}
80
81
Timer timer = new Timer();
82
83
System.out.println("Testing waitForCardAbsent() with card already absent...");
84
isTrue(terminal.waitForCardAbsent(10));
85
timer.print();
86
isTrue(terminal.waitForCardAbsent(100));
87
timer.print();
88
isTrue(terminal.waitForCardAbsent(10000));
89
timer.print();
90
isTrue(terminal.waitForCardAbsent(0));
91
timer.print();
92
93
System.out.println("Testing waitForCardPresent() timeout...");
94
isFalse(terminal.waitForCardPresent(10));
95
timer.print();
96
isFalse(terminal.waitForCardPresent(100));
97
timer.print();
98
isFalse(terminal.waitForCardPresent(1000));
99
timer.print();
100
101
isFalse(terminal.isCardPresent());
102
isFalse(terminal.isCardPresent());
103
104
System.out.println("*** Insert card!");
105
isTrue(terminal.waitForCardPresent(0));
106
timer.print();
107
108
isTrue(terminal.isCardPresent());
109
isTrue(terminal.isCardPresent());
110
111
System.out.println("Testing waitForCardPresent() with card already present...");
112
isTrue(terminal.waitForCardPresent(0));
113
timer.print();
114
isTrue(terminal.waitForCardPresent(10000));
115
timer.print();
116
isTrue(terminal.waitForCardPresent(100));
117
timer.print();
118
isTrue(terminal.waitForCardPresent(10));
119
timer.print();
120
121
System.out.println("Testing waitForCardAbsent() timeout...");
122
isFalse(terminal.waitForCardAbsent(1000));
123
timer.print();
124
isFalse(terminal.waitForCardAbsent(100));
125
timer.print();
126
isFalse(terminal.waitForCardAbsent(10));
127
timer.print();
128
129
System.out.println("*** Remove card!");
130
isTrue(terminal.waitForCardAbsent(0));
131
timer.print();
132
133
isFalse(terminal.isCardPresent());
134
isFalse(terminal.isCardPresent());
135
136
System.out.println("OK.");
137
}
138
139
}
140
141