author | skovalev |
Wed, 21 Sep 2016 17:09:41 +0300 | |
changeset 41106 | f37e9bfeae01 |
parent 35778 | e2a3c03097de |
permissions | -rw-r--r-- |
2 | 1 |
/* |
35778
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
41106
f37e9bfeae01
8166450: smartcardio related tests failed on compilation during execution with jtreg tool
skovalev
parents:
35778
diff
changeset
|
24 |
/* |
2 | 25 |
* @test |
26 |
* @bug 6293769 6294527 |
|
27 |
* @summary test that the isCardPresent()/waitForX() APIs work correctly |
|
28 |
* @author Andreas Sterbenz |
|
41106
f37e9bfeae01
8166450: smartcardio related tests failed on compilation during execution with jtreg tool
skovalev
parents:
35778
diff
changeset
|
29 |
* @modules java.smartcardio/javax.smartcardio |
2 | 30 |
* @run main/manual TestPresent |
31 |
*/ |
|
32 |
||
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
33 |
// This test requires special hardware. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
34 |
|
25656
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
35 |
import java.util.List; |
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
36 |
import javax.smartcardio.CardTerminal; |
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
37 |
import javax.smartcardio.TerminalFactory; |
2 | 38 |
|
35778
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
39 |
public class TestPresent extends Utils { |
2 | 40 |
|
41 |
private static class Timer { |
|
42 |
private long time = System.currentTimeMillis(); |
|
43 |
long update() { |
|
44 |
long t = System.currentTimeMillis(); |
|
45 |
long diff = t - time; |
|
46 |
time = t; |
|
47 |
return diff; |
|
48 |
} |
|
49 |
long print() { |
|
50 |
long t = update(); |
|
51 |
System.out.println("Elapsed time: " + t + " ms."); |
|
52 |
return t; |
|
53 |
} |
|
54 |
} |
|
55 |
||
56 |
private static boolean isFalse(boolean b) throws Exception { |
|
57 |
if (b) { |
|
58 |
throw new Exception("not false"); |
|
59 |
} |
|
60 |
return b; |
|
61 |
} |
|
62 |
||
63 |
private static boolean isTrue(boolean b) throws Exception { |
|
64 |
if (!b) { |
|
65 |
throw new Exception("not true"); |
|
66 |
} |
|
67 |
return b; |
|
68 |
} |
|
69 |
||
70 |
public static void main(String[] args) throws Exception { |
|
35778
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
71 |
CardTerminal terminal = getTerminal(args); |
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
72 |
if (terminal == null) { |
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
73 |
System.out.println("Skipping the test: " + |
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
74 |
"no card terminals available"); |
e2a3c03097de
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
igerasim
parents:
25656
diff
changeset
|
75 |
return; |
2 | 76 |
} |
77 |
||
78 |
while (terminal.isCardPresent()) { |
|
79 |
System.out.println("*** Remove card!"); |
|
80 |
Thread.sleep(1000); |
|
81 |
} |
|
82 |
||
83 |
Timer timer = new Timer(); |
|
84 |
||
85 |
System.out.println("Testing waitForCardAbsent() with card already absent..."); |
|
86 |
isTrue(terminal.waitForCardAbsent(10)); |
|
87 |
timer.print(); |
|
88 |
isTrue(terminal.waitForCardAbsent(100)); |
|
89 |
timer.print(); |
|
90 |
isTrue(terminal.waitForCardAbsent(10000)); |
|
91 |
timer.print(); |
|
92 |
isTrue(terminal.waitForCardAbsent(0)); |
|
93 |
timer.print(); |
|
94 |
||
95 |
System.out.println("Testing waitForCardPresent() timeout..."); |
|
96 |
isFalse(terminal.waitForCardPresent(10)); |
|
97 |
timer.print(); |
|
98 |
isFalse(terminal.waitForCardPresent(100)); |
|
99 |
timer.print(); |
|
100 |
isFalse(terminal.waitForCardPresent(1000)); |
|
101 |
timer.print(); |
|
102 |
||
103 |
isFalse(terminal.isCardPresent()); |
|
104 |
isFalse(terminal.isCardPresent()); |
|
105 |
||
106 |
System.out.println("*** Insert card!"); |
|
107 |
isTrue(terminal.waitForCardPresent(0)); |
|
108 |
timer.print(); |
|
109 |
||
110 |
isTrue(terminal.isCardPresent()); |
|
111 |
isTrue(terminal.isCardPresent()); |
|
112 |
||
113 |
System.out.println("Testing waitForCardPresent() with card already present..."); |
|
114 |
isTrue(terminal.waitForCardPresent(0)); |
|
115 |
timer.print(); |
|
116 |
isTrue(terminal.waitForCardPresent(10000)); |
|
117 |
timer.print(); |
|
118 |
isTrue(terminal.waitForCardPresent(100)); |
|
119 |
timer.print(); |
|
120 |
isTrue(terminal.waitForCardPresent(10)); |
|
121 |
timer.print(); |
|
122 |
||
123 |
System.out.println("Testing waitForCardAbsent() timeout..."); |
|
124 |
isFalse(terminal.waitForCardAbsent(1000)); |
|
125 |
timer.print(); |
|
126 |
isFalse(terminal.waitForCardAbsent(100)); |
|
127 |
timer.print(); |
|
128 |
isFalse(terminal.waitForCardAbsent(10)); |
|
129 |
timer.print(); |
|
130 |
||
131 |
System.out.println("*** Remove card!"); |
|
132 |
isTrue(terminal.waitForCardAbsent(0)); |
|
133 |
timer.print(); |
|
134 |
||
135 |
isFalse(terminal.isCardPresent()); |
|
136 |
isFalse(terminal.isCardPresent()); |
|
137 |
||
138 |
System.out.println("OK."); |
|
139 |
} |
|
140 |
||
141 |
} |