Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/InputVerifierTest3/InputVerifierTest3.java
41152 views
1
/*
2
* Copyright (c) 2006, 2018, 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
@key headful
27
@bug 6432665
28
@summary Inputverifier is not executed when focus owner is removed
29
@author oleg.sukhodolsky: area=awt.focus
30
@library ../../regtesthelpers
31
@build Util
32
@run main InputVerifierTest3
33
*/
34
35
/**
36
* InputVerifierTest3.java
37
*
38
* summary: Inputverifier is not executed when focus owner is removed
39
*/
40
41
import java.awt.AWTException;
42
import java.awt.BorderLayout;
43
import java.awt.Component;
44
import java.awt.Dialog;
45
import java.awt.FlowLayout;
46
import java.awt.Frame;
47
import java.awt.KeyboardFocusManager;
48
import java.awt.Point;
49
import java.awt.Robot;
50
import java.awt.TextArea;
51
import java.awt.Toolkit;
52
53
import java.awt.event.InputEvent;
54
55
import javax.swing.InputVerifier;
56
import javax.swing.JComponent;
57
import javax.swing.JFrame;
58
import javax.swing.JTextField;
59
60
import test.java.awt.regtesthelpers.Util;
61
62
public class InputVerifierTest3
63
{
64
static volatile boolean verifier_called = false;
65
66
private static void init()
67
{
68
//*** Create instructions for the user here ***
69
70
JFrame frame = new JFrame();
71
frame.getContentPane().setLayout(new FlowLayout());
72
JTextField tf1 = new JTextField(10);
73
tf1.setInputVerifier(new InputVerifier() {
74
public boolean verify(JComponent input) {
75
System.err.println("verify on " + input);
76
verifier_called = true;
77
return true;
78
}
79
});
80
frame.getContentPane().add(tf1);
81
JTextField tf2 = new JTextField(10);
82
frame.getContentPane().add(tf2);
83
84
frame.setSize(200, 200);
85
frame.setVisible(true);
86
87
Robot r = null;
88
try {
89
r = new Robot();
90
} catch (AWTException e) {
91
InputVerifierTest3.fail(e);
92
}
93
94
95
try {
96
Util.waitForIdle(r);
97
Util.clickOnComp(tf1, r);
98
Util.waitForIdle(r);
99
100
101
if (!tf1.isFocusOwner()) {
102
System.out.println("focus owner = " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
103
throw new RuntimeException("tf1 is not a focus owner");
104
}
105
106
frame.getContentPane().remove(tf1);
107
Util.waitForIdle(r);
108
109
if (!tf2.isFocusOwner()) {
110
System.out.println("focus owner = " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
111
throw new RuntimeException("tf2 is not a focus owner");
112
}
113
114
if (!verifier_called) {
115
throw new RuntimeException("verifier was not called");
116
}
117
118
} catch (Exception e) {
119
InputVerifierTest3.fail(e);
120
}
121
122
InputVerifierTest3.pass();
123
124
}//End init()
125
126
/*****************************************************
127
* Standard Test Machinery Section
128
* DO NOT modify anything in this section -- it's a
129
* standard chunk of code which has all of the
130
* synchronisation necessary for the test harness.
131
* By keeping it the same in all tests, it is easier
132
* to read and understand someone else's test, as
133
* well as insuring that all tests behave correctly
134
* with the test harness.
135
* There is a section following this for test-
136
* classes
137
******************************************************/
138
private static boolean theTestPassed = false;
139
private static boolean testGeneratedInterrupt = false;
140
private static String failureMessage = "";
141
142
private static Thread mainThread = null;
143
144
private static int sleepTime = 300000;
145
146
// Not sure about what happens if multiple of this test are
147
// instantiated in the same VM. Being static (and using
148
// static vars), it aint gonna work. Not worrying about
149
// it for now.
150
public static void main( String args[] ) throws InterruptedException
151
{
152
mainThread = Thread.currentThread();
153
try
154
{
155
init();
156
}
157
catch( TestPassedException e )
158
{
159
//The test passed, so just return from main and harness will
160
// interepret this return as a pass
161
return;
162
}
163
//At this point, neither test pass nor test fail has been
164
// called -- either would have thrown an exception and ended the
165
// test, so we know we have multiple threads.
166
167
//Test involves other threads, so sleep and wait for them to
168
// called pass() or fail()
169
try
170
{
171
Thread.sleep( sleepTime );
172
//Timed out, so fail the test
173
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
174
}
175
catch (InterruptedException e)
176
{
177
//The test harness may have interrupted the test. If so, rethrow the exception
178
// so that the harness gets it and deals with it.
179
if( ! testGeneratedInterrupt ) throw e;
180
181
//reset flag in case hit this code more than once for some reason (just safety)
182
testGeneratedInterrupt = false;
183
184
if ( theTestPassed == false )
185
{
186
throw new RuntimeException( failureMessage );
187
}
188
}
189
190
}//main
191
192
public static synchronized void setTimeoutTo( int seconds )
193
{
194
sleepTime = seconds * 1000;
195
}
196
197
public static synchronized void pass()
198
{
199
System.out.println( "The test passed." );
200
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
201
//first check if this is executing in main thread
202
if ( mainThread == Thread.currentThread() )
203
{
204
//Still in the main thread, so set the flag just for kicks,
205
// and throw a test passed exception which will be caught
206
// and end the test.
207
theTestPassed = true;
208
throw new TestPassedException();
209
}
210
theTestPassed = true;
211
testGeneratedInterrupt = true;
212
mainThread.interrupt();
213
}//pass()
214
215
public static synchronized void fail( Exception whyFailed )
216
{
217
System.out.println( "The test failed: " + whyFailed );
218
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
219
//check if this called from main thread
220
if ( mainThread == Thread.currentThread() )
221
{
222
//If main thread, fail now 'cause not sleeping
223
throw new RuntimeException( whyFailed );
224
}
225
theTestPassed = false;
226
testGeneratedInterrupt = true;
227
failureMessage = whyFailed.toString();
228
mainThread.interrupt();
229
}//fail()
230
231
}// class InputVerifierTest3
232
233
//This exception is used to exit from any level of call nesting
234
// when it's determined that the test has passed, and immediately
235
// end the test.
236
class TestPassedException extends RuntimeException
237
{
238
}
239
240