Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Choice/SelectCurrentItemTest/SelectCurrentItemTest.java
47626 views
1
/*
2
* Copyright (c) 2002, 2014, 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
test 1.3 02/06/25
25
@bug 4902933
26
@summary Test that selecting the current item sends an ItemEvent
27
@author bchristi : area= Choice
28
@run applet SelectCurrentItemTest.html
29
*/
30
31
// Note there is no @ in front of test above. This is so that the
32
// harness will not mistake this file as a test file. It should
33
// only see the html file as a test file. (the harness runs all
34
// valid test files, so it would run this test twice if this file
35
// were valid as well as the html file.)
36
// Also, note the area= after Your Name in the author tag. Here, you
37
// should put which functional area the test falls in. See the
38
// AWT-core home page -> test areas and/or -> AWT team for a list of
39
// areas.
40
// Note also the 'SelectCurrentItemTest.html' in the run tag. This should
41
// be changed to the name of the test.
42
43
44
/**
45
* SelectCurrentItemTest.java
46
*
47
* summary:
48
*/
49
50
import java.applet.Applet;
51
import java.awt.*;
52
import java.awt.event.*;
53
54
//Automated tests should run as applet tests if possible because they
55
// get their environments cleaned up, including AWT threads, any
56
// test created threads, and any system resources used by the test
57
// such as file descriptors. (This is normally not a problem as
58
// main tests usually run in a separate VM, however on some platforms
59
// such as the Mac, separate VMs are not possible and non-applet
60
// tests will cause problems). Also, you don't have to worry about
61
// synchronisation stuff in Applet tests they way you do in main
62
// tests...
63
64
65
public class SelectCurrentItemTest extends Applet implements ItemListener,
66
WindowListener, Runnable
67
{
68
//Declare things used in the test, like buttons and labels here
69
Frame frame;
70
Choice theChoice;
71
Robot robot;
72
73
Object lock = new Object();
74
boolean passed = false;
75
76
public void init()
77
{
78
//Create instructions for the user here, as well as set up
79
// the environment -- set the layout manager, add buttons,
80
// etc.
81
82
this.setLayout (new BorderLayout ());
83
84
String[] instructions =
85
{
86
"This is an AUTOMATIC test",
87
"simply wait until it is done"
88
};
89
Sysout.createDialog( );
90
Sysout.printInstructions( instructions );
91
92
frame = new Frame("SelectCurrentItemTest");
93
theChoice = new Choice();
94
for (int i = 0; i < 10; i++) {
95
theChoice.add(new String("Choice Item " + i));
96
}
97
theChoice.addItemListener(this);
98
frame.add(theChoice);
99
frame.addWindowListener(this);
100
101
try {
102
robot = new Robot();
103
robot.setAutoDelay(500);
104
}
105
catch (AWTException e) {
106
throw new RuntimeException("Unable to create Robot. Test fails.");
107
}
108
109
}//End init()
110
111
public void start ()
112
{
113
//Get things going. Request focus, set size, et cetera
114
setSize (200,200);
115
setVisible(true);
116
validate();
117
118
//What would normally go into main() will probably go here.
119
//Use System.out.println for diagnostic messages that you want
120
//to read after the test is done.
121
//Use Sysout.println for messages you want the tester to read.
122
123
frame.setLocation(1,20);
124
robot.mouseMove(10, 30);
125
frame.pack();
126
frame.setVisible(true);
127
synchronized(lock) {
128
try {
129
lock.wait(120000);
130
}
131
catch(InterruptedException e) {}
132
}
133
robot.waitForIdle();
134
if (!passed) {
135
throw new RuntimeException("TEST FAILED!");
136
}
137
138
// wait to make sure ItemEvent has been processed
139
140
// try {Thread.sleep(10000);} catch (InterruptedException e){}
141
}// start()
142
143
public void run() {
144
try {Thread.sleep(1000);} catch (InterruptedException e){}
145
// get loc of Choice on screen
146
Point loc = theChoice.getLocationOnScreen();
147
// get bounds of Choice
148
Dimension size = theChoice.getSize();
149
robot.mouseMove(loc.x + size.width - 10, loc.y + size.height / 2);
150
151
robot.setAutoDelay(250);
152
robot.mousePress(InputEvent.BUTTON1_MASK);
153
robot.mouseRelease(InputEvent.BUTTON1_MASK);
154
155
robot.setAutoDelay(1000);
156
robot.mouseMove(loc.x + size.width / 2, loc.y + size.height + size.height / 2);
157
robot.setAutoDelay(250);
158
robot.mousePress(InputEvent.BUTTON1_MASK);
159
robot.mouseRelease(InputEvent.BUTTON1_MASK);
160
robot.waitForIdle();
161
synchronized(lock) {
162
lock.notify();
163
}
164
}
165
166
public void itemStateChanged(ItemEvent e) {
167
Sysout.println("ItemEvent received. Test passes");
168
passed = true;
169
}
170
171
public void windowOpened(WindowEvent e) {
172
Sysout.println("windowActivated()");
173
Thread testThread = new Thread(this);
174
testThread.start();
175
}
176
public void windowActivated(WindowEvent e) {
177
}
178
public void windowDeactivated(WindowEvent e) {}
179
public void windowClosed(WindowEvent e) {}
180
public void windowClosing(WindowEvent e) {}
181
public void windowIconified(WindowEvent e) {}
182
public void windowDeiconified(WindowEvent e) {}
183
184
}// class SelectCurrentItemTest
185
186
187
/****************************************************
188
Standard Test Machinery
189
DO NOT modify anything below -- it's a standard
190
chunk of code whose purpose is to make user
191
interaction uniform, and thereby make it simpler
192
to read and understand someone else's test.
193
****************************************************/
194
195
/**
196
This is part of the standard test machinery.
197
It creates a dialog (with the instructions), and is the interface
198
for sending text messages to the user.
199
To print the instructions, send an array of strings to Sysout.createDialog
200
WithInstructions method. Put one line of instructions per array entry.
201
To display a message for the tester to see, simply call Sysout.println
202
with the string to be displayed.
203
This mimics System.out.println but works within the test harness as well
204
as standalone.
205
*/
206
207
class Sysout
208
{
209
private static TestDialog dialog;
210
211
public static void createDialogWithInstructions( String[] instructions )
212
{
213
dialog = new TestDialog( new Frame(), "Instructions" );
214
dialog.printInstructions( instructions );
215
dialog.setVisible(true);
216
println( "Any messages for the tester will display here." );
217
}
218
219
public static void createDialog( )
220
{
221
dialog = new TestDialog( new Frame(), "Instructions" );
222
String[] defInstr = { "Instructions will appear here. ", "" } ;
223
dialog.printInstructions( defInstr );
224
dialog.setLocation(0, 400);
225
dialog.setVisible(true);
226
println( "Any messages for the tester will display here." );
227
}
228
229
230
public static void printInstructions( String[] instructions )
231
{
232
dialog.printInstructions( instructions );
233
}
234
235
236
public static void println( String messageIn )
237
{
238
dialog.displayMessage( messageIn );
239
}
240
241
}// Sysout class
242
243
/**
244
This is part of the standard test machinery. It provides a place for the
245
test instructions to be displayed, and a place for interactive messages
246
to the user to be displayed.
247
To have the test instructions displayed, see Sysout.
248
To have a message to the user be displayed, see Sysout.
249
Do not call anything in this dialog directly.
250
*/
251
class TestDialog extends Dialog
252
{
253
254
TextArea instructionsText;
255
TextArea messageText;
256
int maxStringLength = 80;
257
258
//DO NOT call this directly, go through Sysout
259
public TestDialog( Frame frame, String name )
260
{
261
super( frame, name );
262
int scrollBoth = TextArea.SCROLLBARS_BOTH;
263
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
264
add( "North", instructionsText );
265
266
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
267
add("Center", messageText);
268
269
pack();
270
271
show();
272
}// TestDialog()
273
274
//DO NOT call this directly, go through Sysout
275
public void printInstructions( String[] instructions )
276
{
277
//Clear out any current instructions
278
instructionsText.setText( "" );
279
280
//Go down array of instruction strings
281
282
String printStr, remainingStr;
283
for( int i=0; i < instructions.length; i++ )
284
{
285
//chop up each into pieces maxSringLength long
286
remainingStr = instructions[ i ];
287
while( remainingStr.length() > 0 )
288
{
289
//if longer than max then chop off first max chars to print
290
if( remainingStr.length() >= maxStringLength )
291
{
292
//Try to chop on a word boundary
293
int posOfSpace = remainingStr.
294
lastIndexOf( ' ', maxStringLength - 1 );
295
296
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
297
298
printStr = remainingStr.substring( 0, posOfSpace + 1 );
299
remainingStr = remainingStr.substring( posOfSpace + 1 );
300
}
301
//else just print
302
else
303
{
304
printStr = remainingStr;
305
remainingStr = "";
306
}
307
308
instructionsText.append( printStr + "\n" );
309
310
}// while
311
312
}// for
313
314
}//printInstructions()
315
316
//DO NOT call this directly, go through Sysout
317
public void displayMessage( String messageIn )
318
{
319
messageText.append( messageIn + "\n" );
320
System.out.println(messageIn);
321
}
322
323
}// TestDialog class
324
325