Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java
41152 views
1
/*
2
* Copyright (c) 2009, 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 6774258
28
@summary api/java_awt/Component/index.html#PaintUpdate fails randomly
29
@author dmitry.cherepanov@...: area=awt.painting
30
@run main NoUpdateUponShow
31
*/
32
33
/**
34
* NoUpdateUponShow.java
35
*
36
* summary: System-level painting operations shouldn't make call to update()
37
*/
38
39
import java.awt.*;
40
41
public class NoUpdateUponShow
42
{
43
44
static volatile boolean wasUpdate = false;
45
46
private static void init()
47
{
48
// Create the frame and the button
49
Frame f = new Frame();
50
f.setBounds(100, 100, 200, 200);
51
f.setLayout(new FlowLayout());
52
f.add(new Button() {
53
@Override
54
public void update(Graphics g) {
55
wasUpdate = true;
56
super.update(g);
57
}
58
});
59
f.setVisible(true);
60
61
try {
62
Robot robot = new Robot();
63
robot.waitForIdle();
64
}catch(Exception ex) {
65
ex.printStackTrace();
66
throw new RuntimeException("Unexpected failure");
67
}
68
69
if (wasUpdate) {
70
fail(" Unexpected update. ");
71
} else {
72
pass();
73
}
74
}//End init()
75
76
/*****************************************************
77
* Standard Test Machinery Section
78
* DO NOT modify anything in this section -- it's a
79
* standard chunk of code which has all of the
80
* synchronisation necessary for the test harness.
81
* By keeping it the same in all tests, it is easier
82
* to read and understand someone else's test, as
83
* well as insuring that all tests behave correctly
84
* with the test harness.
85
* There is a section following this for test-
86
* classes
87
******************************************************/
88
private static boolean theTestPassed = false;
89
private static boolean testGeneratedInterrupt = false;
90
private static String failureMessage = "";
91
92
private static Thread mainThread = null;
93
94
private static int sleepTime = 300000;
95
96
// Not sure about what happens if multiple of this test are
97
// instantiated in the same VM. Being static (and using
98
// static vars), it aint gonna work. Not worrying about
99
// it for now.
100
public static void main( String args[] ) throws InterruptedException
101
{
102
mainThread = Thread.currentThread();
103
try
104
{
105
init();
106
}
107
catch( TestPassedException e )
108
{
109
//The test passed, so just return from main and harness will
110
// interepret this return as a pass
111
return;
112
}
113
//At this point, neither test pass nor test fail has been
114
// called -- either would have thrown an exception and ended the
115
// test, so we know we have multiple threads.
116
117
//Test involves other threads, so sleep and wait for them to
118
// called pass() or fail()
119
try
120
{
121
Thread.sleep( sleepTime );
122
//Timed out, so fail the test
123
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
124
}
125
catch (InterruptedException e)
126
{
127
//The test harness may have interrupted the test. If so, rethrow the exception
128
// so that the harness gets it and deals with it.
129
if( ! testGeneratedInterrupt ) throw e;
130
131
//reset flag in case hit this code more than once for some reason (just safety)
132
testGeneratedInterrupt = false;
133
134
if ( theTestPassed == false )
135
{
136
throw new RuntimeException( failureMessage );
137
}
138
}
139
140
}//main
141
142
public static synchronized void setTimeoutTo( int seconds )
143
{
144
sleepTime = seconds * 1000;
145
}
146
147
public static synchronized void pass()
148
{
149
System.out.println( "The test passed." );
150
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
151
//first check if this is executing in main thread
152
if ( mainThread == Thread.currentThread() )
153
{
154
//Still in the main thread, so set the flag just for kicks,
155
// and throw a test passed exception which will be caught
156
// and end the test.
157
theTestPassed = true;
158
throw new TestPassedException();
159
}
160
theTestPassed = true;
161
testGeneratedInterrupt = true;
162
mainThread.interrupt();
163
}//pass()
164
165
public static synchronized void fail()
166
{
167
//test writer didn't specify why test failed, so give generic
168
fail( "it just plain failed! :-)" );
169
}
170
171
public static synchronized void fail( String whyFailed )
172
{
173
System.out.println( "The test failed: " + whyFailed );
174
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
175
//check if this called from main thread
176
if ( mainThread == Thread.currentThread() )
177
{
178
//If main thread, fail now 'cause not sleeping
179
throw new RuntimeException( whyFailed );
180
}
181
theTestPassed = false;
182
testGeneratedInterrupt = true;
183
failureMessage = whyFailed;
184
mainThread.interrupt();
185
}//fail()
186
187
}// class ValidBounds
188
189
//This exception is used to exit from any level of call nesting
190
// when it's determined that the test has passed, and immediately
191
// end the test.
192
class TestPassedException extends RuntimeException
193
{
194
}
195
196