1 /*
2 test 1.3 02/06/25
3 @bug 4902933
4 @summary Test that selecting the current item sends an ItemEvent
5 @author bchristi : area= Choice
6 @run applet SelectCurrentItemTest.html
7 */
8
9 // Note there is no @ in front of test above. This is so that the
10 // harness will not mistake this file as a test file. It should
11 // only see the html file as a test file. (the harness runs all
12 // valid test files, so it would run this test twice if this file
13 // were valid as well as the html file.)
14 // Also, note the area= after Your Name in the author tag. Here, you
15 // should put which functional area the test falls in. See the
16 // AWT-core home page -> test areas and/or -> AWT team for a list of
17 // areas.
18 // Note also the 'SelectCurrentItemTest.html' in the run tag. This should
19 // be changed to the name of the test.
20
21
22 /**
23 * SelectCurrentItemTest.java
24 *
25 * summary:
26 */
27
28 import java.applet.Applet;
29 import java.awt.*;
30 import java.awt.event.*;
31 import sun.awt.SunToolkit;
32
33 //Automated tests should run as applet tests if possible because they
34 // get their environments cleaned up, including AWT threads, any
35 // test created threads, and any system resources used by the test
36 // such as file descriptors. (This is normally not a problem as
37 // main tests usually run in a separate VM, however on some platforms
38 // such as the Mac, separate VMs are not possible and non-applet
39 // tests will cause problems). Also, you don't have to worry about
40 // synchronisation stuff in Applet tests they way you do in main
41 // tests...
42
43
44 public class SelectCurrentItemTest extends Applet implements ItemListener,
45 WindowListener, Runnable
46 {
47 //Declare things used in the test, like buttons and labels here
48 Frame frame;
49 Choice theChoice;
50 Robot robot;
51
119 // try {Thread.sleep(10000);} catch (InterruptedException e){}
120 }// start()
121
122 public void run() {
123 try {Thread.sleep(1000);} catch (InterruptedException e){}
124 // get loc of Choice on screen
125 Point loc = theChoice.getLocationOnScreen();
126 // get bounds of Choice
127 Dimension size = theChoice.getSize();
128 robot.mouseMove(loc.x + size.width - 10, loc.y + size.height / 2);
129
130 robot.setAutoDelay(250);
131 robot.mousePress(InputEvent.BUTTON1_MASK);
132 robot.mouseRelease(InputEvent.BUTTON1_MASK);
133
134 robot.setAutoDelay(1000);
135 robot.mouseMove(loc.x + size.width / 2, loc.y + size.height + size.height / 2);
136 robot.setAutoDelay(250);
137 robot.mousePress(InputEvent.BUTTON1_MASK);
138 robot.mouseRelease(InputEvent.BUTTON1_MASK);
139 ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
140 synchronized(lock) {
141 lock.notify();
142 }
143 }
144
145 public void itemStateChanged(ItemEvent e) {
146 Sysout.println("ItemEvent received. Test passes");
147 passed = true;
148 }
149
150 public void windowOpened(WindowEvent e) {
151 Sysout.println("windowActivated()");
152 Thread testThread = new Thread(this);
153 testThread.start();
154 }
155 public void windowActivated(WindowEvent e) {
156 }
157 public void windowDeactivated(WindowEvent e) {}
158 public void windowClosed(WindowEvent e) {}
159 public void windowClosing(WindowEvent e) {}
|
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
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) {}
|