Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Mixing/Validating.java
41149 views
1
/*
2
* Copyright (c) 2008, 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 6682046 8198002
28
@summary Mixing code does not always recalculate shapes correctly when resizing components
29
@author anthony.petrov@...: area=awt.mixing
30
@library ../regtesthelpers
31
@build Util
32
@run main Validating
33
*/
34
35
/**
36
* Validating.java
37
*
38
* summary: Mixing code does not always recalculate shapes correctly when resizing components
39
*/
40
41
import java.awt.Button;
42
import java.awt.event.InputEvent;
43
import java.awt.Frame;
44
import java.awt.Point;
45
import java.awt.Robot;
46
import java.awt.Toolkit;
47
import test.java.awt.regtesthelpers.Util;
48
49
public class Validating
50
{
51
static volatile boolean clickPassed = false;
52
53
private static void init()
54
{
55
if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
56
System.out.println("The test environment does not support maximization. The test cannot be performed.");
57
pass();
58
return;
59
}
60
61
// Create the frame with a button.
62
Frame f = new Frame();
63
Button b = new Button("ok");
64
b.addActionListener(new java.awt.event.ActionListener() {
65
public void actionPerformed(java.awt.event.ActionEvent e) {
66
clickPassed = true;
67
}
68
});
69
f.add(b);
70
// Make the frame maximized
71
f.setExtendedState(Frame.MAXIMIZED_BOTH);
72
f.pack();
73
f.setVisible(true);
74
75
Robot robot = Util.createRobot();
76
robot.setAutoDelay(20);
77
78
Util.waitForIdle(robot);
79
80
// Now let's attempt to click in the middle of the button
81
// (i.e. in the middle of the window).
82
// If the button doesn't receive the click, it means that the test
83
// failed: the shape of the button was not enlarged.
84
Point heavyLoc = b.getLocationOnScreen();
85
robot.mouseMove(heavyLoc.x + b.getWidth() / 2, heavyLoc.y + b.getHeight() / 2);
86
87
robot.mousePress(InputEvent.BUTTON1_MASK);
88
robot.mouseRelease(InputEvent.BUTTON1_MASK);
89
Util.waitForIdle(robot);
90
91
if (clickPassed) {
92
pass();
93
} else {
94
fail("The button cannot be clicked.");
95
}
96
}//End init()
97
98
99
100
/*****************************************************
101
* Standard Test Machinery Section
102
* DO NOT modify anything in this section -- it's a
103
* standard chunk of code which has all of the
104
* synchronisation necessary for the test harness.
105
* By keeping it the same in all tests, it is easier
106
* to read and understand someone else's test, as
107
* well as insuring that all tests behave correctly
108
* with the test harness.
109
* There is a section following this for test-
110
* classes
111
******************************************************/
112
private static boolean theTestPassed = false;
113
private static boolean testGeneratedInterrupt = false;
114
private static String failureMessage = "";
115
116
private static Thread mainThread = null;
117
118
private static int sleepTime = 300000;
119
120
// Not sure about what happens if multiple of this test are
121
// instantiated in the same VM. Being static (and using
122
// static vars), it aint gonna work. Not worrying about
123
// it for now.
124
public static void main( String args[] ) throws InterruptedException
125
{
126
mainThread = Thread.currentThread();
127
try
128
{
129
init();
130
}
131
catch( TestPassedException e )
132
{
133
//The test passed, so just return from main and harness will
134
// interepret this return as a pass
135
return;
136
}
137
//At this point, neither test pass nor test fail has been
138
// called -- either would have thrown an exception and ended the
139
// test, so we know we have multiple threads.
140
141
//Test involves other threads, so sleep and wait for them to
142
// called pass() or fail()
143
try
144
{
145
Thread.sleep( sleepTime );
146
//Timed out, so fail the test
147
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
148
}
149
catch (InterruptedException e)
150
{
151
//The test harness may have interrupted the test. If so, rethrow the exception
152
// so that the harness gets it and deals with it.
153
if( ! testGeneratedInterrupt ) throw e;
154
155
//reset flag in case hit this code more than once for some reason (just safety)
156
testGeneratedInterrupt = false;
157
158
if ( theTestPassed == false )
159
{
160
throw new RuntimeException( failureMessage );
161
}
162
}
163
164
}//main
165
166
public static synchronized void setTimeoutTo( int seconds )
167
{
168
sleepTime = seconds * 1000;
169
}
170
171
public static synchronized void pass()
172
{
173
System.out.println( "The test passed." );
174
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
175
//first check if this is executing in main thread
176
if ( mainThread == Thread.currentThread() )
177
{
178
//Still in the main thread, so set the flag just for kicks,
179
// and throw a test passed exception which will be caught
180
// and end the test.
181
theTestPassed = true;
182
throw new TestPassedException();
183
}
184
theTestPassed = true;
185
testGeneratedInterrupt = true;
186
mainThread.interrupt();
187
}//pass()
188
189
public static synchronized void fail()
190
{
191
//test writer didn't specify why test failed, so give generic
192
fail( "it just plain failed! :-)" );
193
}
194
195
public static synchronized void fail( String whyFailed )
196
{
197
System.out.println( "The test failed: " + whyFailed );
198
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
199
//check if this called from main thread
200
if ( mainThread == Thread.currentThread() )
201
{
202
//If main thread, fail now 'cause not sleeping
203
throw new RuntimeException( whyFailed );
204
}
205
theTestPassed = false;
206
testGeneratedInterrupt = true;
207
failureMessage = whyFailed;
208
mainThread.interrupt();
209
}//fail()
210
211
}// class Validating
212
213
//This exception is used to exit from any level of call nesting
214
// when it's determined that the test has passed, and immediately
215
// end the test.
216
class TestPassedException extends RuntimeException
217
{
218
}
219
220