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