Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/List/ListFlickers/ListFlickers.java
41154 views
1
/*
2
* Copyright (c) 2008, 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
@bug 6471693
27
@summary Moving the vertical scroll bar of List leads flickering.
28
@author Dmitry Cherepanov area=awt.list
29
@run main/manual ListFlickers
30
*/
31
32
import java.awt.*;
33
import java.awt.event.*;
34
35
public class ListFlickers
36
{
37
38
//*** test-writer defined static variables go here ***
39
40
41
private static void init()
42
{
43
//*** Create instructions for the user here ***
44
45
String[] instructions =
46
{
47
"drag the scrollbar of the list up and down,",
48
"if the list flickers then the test fails,",
49
"otherwise it passes."
50
};
51
Sysout.createDialog( );
52
Sysout.printInstructions( instructions );
53
54
55
Frame f = new Frame();
56
List list = new List(10, false);
57
for (int i = 0; i < 100; i++) {
58
list.add(" item "+i);
59
}
60
f.add(list);
61
f.setBounds(100,100,300,300);
62
f.setVisible(true);
63
64
}//End init()
65
66
67
68
/*****************************************************
69
* Standard Test Machinery Section
70
* DO NOT modify anything in this section -- it's a
71
* standard chunk of code which has all of the
72
* synchronisation necessary for the test harness.
73
* By keeping it the same in all tests, it is easier
74
* to read and understand someone else's test, as
75
* well as insuring that all tests behave correctly
76
* with the test harness.
77
* There is a section following this for test-defined
78
* classes
79
******************************************************/
80
private static boolean theTestPassed = false;
81
private static boolean testGeneratedInterrupt = false;
82
private static String failureMessage = "";
83
84
private static Thread mainThread = null;
85
86
private static int sleepTime = 300000;
87
88
public static void main( String args[] ) throws InterruptedException
89
{
90
mainThread = Thread.currentThread();
91
try
92
{
93
init();
94
}
95
catch( TestPassedException e )
96
{
97
//The test passed, so just return from main and harness will
98
// interepret this return as a pass
99
return;
100
}
101
//At this point, neither test passed nor test failed has been
102
// called -- either would have thrown an exception and ended the
103
// test, so we know we have multiple threads.
104
105
//Test involves other threads, so sleep and wait for them to
106
// called pass() or fail()
107
try
108
{
109
Thread.sleep( sleepTime );
110
//Timed out, so fail the test
111
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
112
}
113
catch (InterruptedException e)
114
{
115
if( ! testGeneratedInterrupt ) throw e;
116
117
//reset flag in case hit this code more than once for some reason (just safety)
118
testGeneratedInterrupt = false;
119
if ( theTestPassed == false )
120
{
121
throw new RuntimeException( failureMessage );
122
}
123
}
124
125
}//main
126
127
public static synchronized void setTimeoutTo( int seconds )
128
{
129
sleepTime = seconds * 1000;
130
}
131
132
public static synchronized void pass()
133
{
134
Sysout.println( "The test passed." );
135
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
136
//first check if this is executing in main thread
137
if ( mainThread == Thread.currentThread() )
138
{
139
//Still in the main thread, so set the flag just for kicks,
140
// and throw a test passed exception which will be caught
141
// and end the test.
142
theTestPassed = true;
143
throw new TestPassedException();
144
}
145
//pass was called from a different thread, so set the flag and interrupt
146
// the main thead.
147
theTestPassed = true;
148
testGeneratedInterrupt = true;
149
if (mainThread != null){
150
mainThread.interrupt();
151
}
152
}//pass()
153
154
public static synchronized void fail()
155
{
156
//test writer didn't specify why test failed, so give generic
157
fail( "it just plain failed! :-)" );
158
}
159
160
public static synchronized void fail( String whyFailed )
161
{
162
Sysout.println( "The test failed: " + whyFailed );
163
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
164
//check if this called from main thread
165
if ( mainThread == Thread.currentThread() )
166
{
167
//If main thread, fail now 'cause not sleeping
168
throw new RuntimeException( whyFailed );
169
}
170
theTestPassed = false;
171
testGeneratedInterrupt = true;
172
failureMessage = whyFailed;
173
mainThread.interrupt();
174
}//fail()
175
176
}// class ManualMainTest
177
178
//This exception is used to exit from any level of call nesting
179
// when it's determined that the test has passed, and immediately
180
// end the test.
181
class TestPassedException extends RuntimeException
182
{
183
}
184
185
//*********** End Standard Test Machinery Section **********
186
187
188
//************ Begin classes defined for the test ****************
189
190
// make listeners in a class defined here, and instantiate them in init()
191
192
/* Example of a class which may be written as part of a test
193
class NewClass implements anInterface
194
{
195
static int newVar = 0;
196
197
public void eventDispatched(AWTEvent e)
198
{
199
//Counting events to see if we get enough
200
eventCount++;
201
202
if( eventCount == 20 )
203
{
204
//got enough events, so pass
205
206
ManualMainTest.pass();
207
}
208
else if( tries == 20 )
209
{
210
//tried too many times without getting enough events so fail
211
212
ManualMainTest.fail();
213
}
214
215
}// eventDispatched()
216
217
}// NewClass class
218
219
*/
220
221
222
//************** End classes defined for the test *******************
223
224
225
226
227
/****************************************************
228
Standard Test Machinery
229
DO NOT modify anything below -- it's a standard
230
chunk of code whose purpose is to make user
231
interaction uniform, and thereby make it simpler
232
to read and understand someone else's test.
233
****************************************************/
234
235
/**
236
This is part of the standard test machinery.
237
It creates a dialog (with the instructions), and is the interface
238
for sending text messages to the user.
239
To print the instructions, send an array of strings to Sysout.createDialog
240
WithInstructions method. Put one line of instructions per array entry.
241
To display a message for the tester to see, simply call Sysout.println
242
with the string to be displayed.
243
This mimics System.out.println but works within the test harness as well
244
as standalone.
245
*/
246
247
class Sysout
248
{
249
private static TestDialog dialog;
250
private static boolean numbering = false;
251
private static int messageNumber = 0;
252
253
public static void createDialogWithInstructions( String[] instructions )
254
{
255
dialog = new TestDialog( new Frame(), "Instructions" );
256
dialog.printInstructions( instructions );
257
dialog.setVisible(true);
258
println( "Any messages for the tester will display here." );
259
}
260
261
public static void createDialog( )
262
{
263
dialog = new TestDialog( new Frame(), "Instructions" );
264
String[] defInstr = { "Instructions will appear here. ", "" } ;
265
dialog.printInstructions( defInstr );
266
dialog.setVisible(true);
267
println( "Any messages for the tester will display here." );
268
}
269
270
271
/* Enables message counting for the tester. */
272
public static void enableNumbering(boolean enable){
273
numbering = enable;
274
}
275
276
public static void printInstructions( String[] instructions )
277
{
278
dialog.printInstructions( instructions );
279
}
280
281
282
public static void println( String messageIn )
283
{
284
if (numbering) {
285
messageIn = "" + messageNumber + " " + messageIn;
286
messageNumber++;
287
}
288
dialog.displayMessage( messageIn );
289
}
290
291
}// Sysout class
292
293
/**
294
This is part of the standard test machinery. It provides a place for the
295
test instructions to be displayed, and a place for interactive messages
296
to the user to be displayed.
297
To have the test instructions displayed, see Sysout.
298
To have a message to the user be displayed, see Sysout.
299
Do not call anything in this dialog directly.
300
*/
301
class TestDialog extends Dialog implements ActionListener
302
{
303
304
TextArea instructionsText;
305
TextArea messageText;
306
int maxStringLength = 80;
307
Panel buttonP = new Panel();
308
Button passB = new Button( "pass" );
309
Button failB = new Button( "fail" );
310
311
//DO NOT call this directly, go through Sysout
312
public TestDialog( Frame frame, String name )
313
{
314
super( frame, name );
315
int scrollBoth = TextArea.SCROLLBARS_BOTH;
316
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
317
add( "North", instructionsText );
318
319
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
320
add("Center", messageText);
321
322
passB = new Button( "pass" );
323
passB.setActionCommand( "pass" );
324
passB.addActionListener( this );
325
buttonP.add( "East", passB );
326
327
failB = new Button( "fail" );
328
failB.setActionCommand( "fail" );
329
failB.addActionListener( this );
330
buttonP.add( "West", failB );
331
332
add( "South", buttonP );
333
pack();
334
335
setVisible(true);
336
}// TestDialog()
337
338
//DO NOT call this directly, go through Sysout
339
public void printInstructions( String[] instructions )
340
{
341
//Clear out any current instructions
342
instructionsText.setText( "" );
343
344
//Go down array of instruction strings
345
346
String printStr, remainingStr;
347
for( int i=0; i < instructions.length; i++ )
348
{
349
//chop up each into pieces maxSringLength long
350
remainingStr = instructions[ i ];
351
while( remainingStr.length() > 0 )
352
{
353
//if longer than max then chop off first max chars to print
354
if( remainingStr.length() >= maxStringLength )
355
{
356
//Try to chop on a word boundary
357
int posOfSpace = remainingStr.
358
lastIndexOf( ' ', maxStringLength - 1 );
359
360
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
361
362
printStr = remainingStr.substring( 0, posOfSpace + 1 );
363
remainingStr = remainingStr.substring( posOfSpace + 1 );
364
}
365
//else just print
366
else
367
{
368
printStr = remainingStr;
369
remainingStr = "";
370
}
371
372
instructionsText.append( printStr + "\n" );
373
374
}// while
375
376
}// for
377
378
}//printInstructions()
379
380
//DO NOT call this directly, go through Sysout
381
public void displayMessage( String messageIn )
382
{
383
messageText.append( messageIn + "\n" );
384
System.out.println(messageIn);
385
}
386
387
//catch presses of the passed and failed buttons.
388
//simply call the standard pass() or fail() static methods of
389
//ManualMainTest
390
public void actionPerformed( ActionEvent e )
391
{
392
if( e.getActionCommand() == "pass" )
393
{
394
ListFlickers.pass();
395
}
396
else
397
{
398
ListFlickers.fail();
399
}
400
}
401
402
}// TestDialog class
403
404