Skip to content

Commit 6a2cce7

Browse files
author
Andrew Lu
committedJul 19, 2024
8316211: Open source several manual applet tests
Reviewed-by: mbaesken Backport-of: 2f311d59dcbbf7605e52fac0b8ebd35d7d51a48b
1 parent 163309f commit 6a2cce7

File tree

4 files changed

+551
-0
lines changed

4 files changed

+551
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 1998, 2023, 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+
import java.awt.EventQueue;
25+
import java.awt.Frame;
26+
27+
/*
28+
* @test 4033151
29+
* @summary Test that frame default size is minimum possible size
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual DefaultSizeTest
33+
*/
34+
35+
public class DefaultSizeTest {
36+
37+
private static final String INSTRUCTIONS = "An empty frame is created.\n" +
38+
"It should be located to the right of this window\n" +
39+
"and should be the minimum size allowed by the window manager.\n" +
40+
"For any WM, the frame should be very small.\n" +
41+
"If the frame is not large, click Pass or Fail otherwise.";
42+
43+
44+
public static void main(String[] args) throws Exception {
45+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
46+
.title("DefaultSizeTest Instructions Frame")
47+
.instructions(INSTRUCTIONS)
48+
.testTimeOut(5)
49+
.rows(10)
50+
.columns(45)
51+
.build();
52+
53+
EventQueue.invokeAndWait(() -> {
54+
Frame frame = new Frame("DefaultSize");
55+
56+
PassFailJFrame.addTestWindow(frame);
57+
PassFailJFrame
58+
.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
59+
60+
frame.setVisible(true);
61+
});
62+
63+
passFailJFrame.awaitAndCheck();
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 1998, 2023, 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+
import java.awt.Color;
25+
import java.awt.Component;
26+
import java.awt.Container;
27+
import java.awt.Dimension;
28+
import java.awt.EventQueue;
29+
import java.awt.FlowLayout;
30+
import java.awt.Frame;
31+
import java.awt.Graphics;
32+
import java.awt.Rectangle;
33+
import java.awt.Shape;
34+
35+
/*
36+
* @test
37+
* @bug 4116029
38+
* @summary drawString does not honor clipping regions for lightweight components
39+
* @library /java/awt/regtesthelpers
40+
* @build PassFailJFrame
41+
* @run main/manual LightweightCliprect
42+
*/
43+
44+
public class LightweightCliprect {
45+
46+
private static final String INSTRUCTIONS = "If some text is drawn outside the red rectangle, press \"Fail\" button.\n" +
47+
"Otherwise, press \"Pass\" button.";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
51+
.title("LightweightCliprect Instructions Frame")
52+
.instructions(INSTRUCTIONS)
53+
.testTimeOut(5)
54+
.rows(10)
55+
.columns(45)
56+
.build();
57+
58+
EventQueue.invokeAndWait(() -> {
59+
Frame frame = new Frame("DefaultSize");
60+
61+
Container panel = new MyContainer();
62+
MyComponent c = new MyComponent();
63+
panel.add(c);
64+
65+
frame.add(panel);
66+
frame.setSize(400, 300);
67+
68+
PassFailJFrame.addTestWindow(frame);
69+
PassFailJFrame
70+
.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
71+
72+
frame.setVisible(true);
73+
});
74+
75+
passFailJFrame.awaitAndCheck();
76+
}
77+
}
78+
79+
class MyComponent extends Component {
80+
81+
public void paint(Graphics g) {
82+
Color c = g.getColor();
83+
g.setColor(Color.red);
84+
g.fillRect(20, 20, 400, 200);
85+
Shape clip = g.getClip();
86+
g.setClip(20, 20, 400, 200);
87+
//draw the current java version in the component
88+
g.setColor(Color.black);
89+
String version = System.getProperty("java.version");
90+
String vendor = System.getProperty("java.vendor");
91+
int y = 10;
92+
for(int i = 0; i < 30; i++) {
93+
g.drawString("Lightweight: Java version: " + version +
94+
", Vendor: " + vendor, 10, y += 20);
95+
}
96+
g.setColor(c);
97+
g.setClip(clip);
98+
super.paint(g);
99+
}
100+
101+
public Dimension getPreferredSize() {
102+
return new Dimension(300, 300);
103+
}
104+
}
105+
106+
class MyContainer extends Container {
107+
public MyContainer() {
108+
super();
109+
setLayout(new FlowLayout());
110+
}
111+
112+
public void paint(Graphics g) {
113+
Rectangle bounds = new Rectangle(getSize());
114+
g.setColor(Color.cyan);
115+
g.drawRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
116+
super.paint(g);
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) 1998, 2023, 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+
import java.awt.BorderLayout;
25+
import java.awt.Button;
26+
import java.awt.Color;
27+
import java.awt.Event;
28+
import java.awt.EventQueue;
29+
import java.awt.Frame;
30+
import java.awt.Label;
31+
import java.awt.Robot;
32+
import java.awt.TextArea;
33+
import java.awt.event.KeyEvent;
34+
35+
/*
36+
* @test
37+
* @bug 4011219
38+
* @summary Test for function key press/release received by Java client.
39+
* @key headful
40+
*/
41+
42+
public class FunctionKeyTest {
43+
private static FunctionKeyTester frame;
44+
private static Robot robot;
45+
46+
static volatile boolean keyPressReceived;
47+
static volatile boolean keyReleaseReceived;
48+
49+
static final StringBuilder failures = new StringBuilder();
50+
51+
private static void testKey(int keyCode, String keyText) {
52+
keyPressReceived = false;
53+
keyReleaseReceived = false;
54+
55+
robot.keyPress(keyCode);
56+
57+
if (!keyPressReceived) {
58+
failures.append(keyText).append(" key press is not received\n");
59+
}
60+
61+
robot.keyRelease(keyCode);
62+
63+
if (!keyReleaseReceived) {
64+
failures.append(keyText).append(" key release is not received\n");
65+
}
66+
}
67+
68+
public static void main(String[] args) throws Exception {
69+
robot = new Robot();
70+
robot.setAutoWaitForIdle(true);
71+
robot.setAutoDelay(150);
72+
73+
try {
74+
EventQueue.invokeAndWait(() -> {
75+
frame = new FunctionKeyTester();
76+
frame.setSize(200, 200);
77+
frame.setLocationRelativeTo(null);
78+
frame.setVisible(true);
79+
});
80+
81+
robot.waitForIdle();
82+
robot.delay(1000);
83+
84+
testKey(KeyEvent.VK_F11, "F11");
85+
testKey(KeyEvent.VK_F12, "F12");
86+
} finally {
87+
EventQueue.invokeAndWait(() -> {
88+
if (frame != null) {
89+
frame.dispose();
90+
}
91+
});
92+
}
93+
94+
if (failures.length() == 0) {
95+
System.out.println("Passed");
96+
} else {
97+
throw new RuntimeException(failures.toString());
98+
}
99+
}
100+
}
101+
102+
class FunctionKeyTester extends Frame {
103+
Label l = new Label ("NULL");
104+
Button b = new Button();
105+
TextArea log = new TextArea();
106+
107+
FunctionKeyTester() {
108+
super("Function Key Test");
109+
this.setLayout(new BorderLayout());
110+
this.add(BorderLayout.NORTH, l);
111+
this.add(BorderLayout.SOUTH, b);
112+
this.add(BorderLayout.CENTER, log);
113+
log.setFocusable(false);
114+
log.setEditable(false);
115+
l.setBackground(Color.red);
116+
setSize(200, 200);
117+
}
118+
119+
public boolean handleEvent(Event e) {
120+
String message = "e.id=" + e.id + "\n";
121+
System.out.print(message);
122+
log.append(message);
123+
124+
switch (e.id) {
125+
case 403:
126+
FunctionKeyTest.keyPressReceived = true;
127+
break;
128+
case 404:
129+
FunctionKeyTest.keyReleaseReceived = true;
130+
break;
131+
}
132+
133+
return super.handleEvent(e);
134+
}
135+
136+
public boolean keyDown(Event e, int key) {
137+
l.setText("e.key=" + Integer.valueOf(e.key).toString());
138+
return false;
139+
}
140+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/*
2+
* Copyright (c) 1998, 2023, 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+
import java.awt.Frame;
25+
import java.awt.FlowLayout;
26+
import java.awt.Window;
27+
import java.awt.event.ItemEvent;
28+
import java.awt.event.WindowEvent;
29+
import javax.swing.JButton;
30+
import javax.swing.JComboBox;
31+
import javax.swing.JDialog;
32+
import javax.swing.JFrame;
33+
import javax.swing.JLabel;
34+
import javax.swing.JPanel;
35+
import javax.swing.SwingUtilities;
36+
import javax.swing.WindowConstants;
37+
38+
/*
39+
* @test
40+
* @summary test for defaultCloseOperation property for Swing JFrame and JDialog
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual DefaultCloseOperation
44+
*/
45+
46+
public class DefaultCloseOperation extends JPanel {
47+
48+
private static final String INSTRUCTIONS = "Do the following steps:\n\n" +
49+
"- Click the \"Open Frame\" button (a TestFrame will appear)\n" +
50+
"- On the TestFrame, select \"Close\" from the system menu (the window should go away)\n" +
51+
"- Select \"Do Nothing\" from the \"JFrame Default Close Operation\" ComboBox\n" +
52+
"- Click the \"Open Frame\" button\n" +
53+
"- On the TestFrame, select \"Close\" from the system menu (the window should remain open)\n" +
54+
"- Select \"Dispose\" from the \"JFrame Default Close Operation\" ComboBox\n" +
55+
"- On the TestFrame, select \"Close\" from the system menu (the window should go away)\n\n\n" +
56+
"- Click the \"Open Frame\" button\n" +
57+
"- Click the \"Open Dialog\" button (a TestDialog will appear)\n" +
58+
"- On the TestDialog, select \"Close\" from the system menu (the window should go away)\n" +
59+
"- Select \"Do Nothing\" from the \"JDialog Default Close Operation\" ComboBox\n" +
60+
"- Click the \"Open Dialog\" button\n" +
61+
"- On the TestDialog, select \"Close\" from the system menu (the window should remain open)\n" +
62+
"- Select \"Dispose\" from the \"JDialog Default Close Operation\" ComboBox\n" +
63+
"- On the TestDialog, select \"Close\" from the system menu (the window should go away)";
64+
65+
JComboBox<String> frameCloseOp;
66+
67+
CloseOpDialog testDialog;
68+
JComboBox<String> dialogCloseOp;
69+
70+
public static void main(String[] args) throws Exception {
71+
72+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
73+
.title("DefaultCloseOperation Manual Test")
74+
.instructions(INSTRUCTIONS)
75+
.testTimeOut(5)
76+
.rows(20)
77+
.columns(70)
78+
.build();
79+
80+
SwingUtilities.invokeAndWait(() -> {
81+
DefaultCloseOperation dco = new DefaultCloseOperation();
82+
dco.init();
83+
84+
JFrame frame = new JFrame("DefaultCloseOperation");
85+
frame.add(dco);
86+
frame.setSize(500,200);
87+
88+
PassFailJFrame.addTestWindow(frame);
89+
PassFailJFrame
90+
.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
91+
92+
frame.setVisible(true);
93+
});
94+
95+
passFailJFrame.awaitAndCheck();
96+
}
97+
98+
public void init() {
99+
setLayout(new FlowLayout());
100+
101+
CloseOpFrame testFrame = new CloseOpFrame();
102+
testFrame.setLocationRelativeTo(null);
103+
PassFailJFrame.addTestWindow(testFrame);
104+
105+
add(new JLabel("JFrame Default Close Operation:"));
106+
frameCloseOp = new JComboBox<>();
107+
frameCloseOp.addItem("Hide");
108+
frameCloseOp.addItem("Do Nothing");
109+
frameCloseOp.addItem("Dispose");
110+
frameCloseOp.addItemListener(e -> {
111+
if (e.getStateChange() == ItemEvent.SELECTED) {
112+
String item = (String)e.getItem();
113+
switch (item) {
114+
case "Do Nothing":
115+
testFrame
116+
.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
117+
break;
118+
case "Hide":
119+
testFrame
120+
.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
121+
break;
122+
case "Dispose":
123+
testFrame
124+
.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
125+
break;
126+
}
127+
}
128+
});
129+
add(frameCloseOp);
130+
131+
JButton b = new JButton("Open Frame...");
132+
b.addActionListener(e -> testFrame.setVisible(true));
133+
add(b);
134+
135+
testDialog = new CloseOpDialog(testFrame);
136+
testDialog.setLocationRelativeTo(null);
137+
PassFailJFrame.addTestWindow(testDialog);
138+
139+
add(new JLabel("JDialog Default Close Operation:"));
140+
dialogCloseOp = new JComboBox<>();
141+
dialogCloseOp.addItem("Hide");
142+
dialogCloseOp.addItem("Do Nothing");
143+
dialogCloseOp.addItem("Dispose");
144+
dialogCloseOp.addItemListener(e -> {
145+
if (e.getStateChange() == ItemEvent.SELECTED) {
146+
String item = (String)e.getItem();
147+
switch (item) {
148+
case "Do Nothing":
149+
testDialog
150+
.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
151+
break;
152+
case "Hide":
153+
testDialog
154+
.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
155+
break;
156+
case "Dispose":
157+
testDialog
158+
.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
159+
break;
160+
}
161+
}
162+
});
163+
add(dialogCloseOp);
164+
165+
b = new JButton("Open Dialog...");
166+
b.addActionListener(e -> testDialog.setVisible(true));
167+
add(b);
168+
}
169+
170+
public static void verifyCloseOperation(Window window, int op) {
171+
switch (op) {
172+
case WindowConstants.DO_NOTHING_ON_CLOSE:
173+
if (!window.isVisible()) {
174+
PassFailJFrame
175+
.forceFail("defaultCloseOperation=DoNothing failed");
176+
}
177+
break;
178+
case WindowConstants.HIDE_ON_CLOSE:
179+
if (window.isVisible()) {
180+
PassFailJFrame
181+
.forceFail("defaultCloseOperation=Hide failed");
182+
}
183+
break;
184+
case WindowConstants.DISPOSE_ON_CLOSE:
185+
if (window.isVisible() || window.isDisplayable()) {
186+
PassFailJFrame
187+
.forceFail("defaultCloseOperation=Dispose failed");
188+
}
189+
break;
190+
}
191+
}
192+
}
193+
194+
class CloseOpFrame extends JFrame {
195+
196+
public CloseOpFrame() {
197+
super("DefaultCloseOperation Test");
198+
getContentPane().add("Center", new JLabel("Test Frame"));
199+
pack();
200+
}
201+
202+
protected void processWindowEvent(WindowEvent e) {
203+
super.processWindowEvent(e);
204+
205+
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
206+
DefaultCloseOperation
207+
.verifyCloseOperation(this, getDefaultCloseOperation());
208+
}
209+
}
210+
}
211+
212+
class CloseOpDialog extends JDialog {
213+
214+
public CloseOpDialog(Frame owner) {
215+
super(owner, "DefaultCloseOperation Test Dialog");
216+
getContentPane().add("Center", new JLabel("Test Dialog"));
217+
pack();
218+
}
219+
220+
protected void processWindowEvent(WindowEvent e) {
221+
super.processWindowEvent(e);
222+
223+
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
224+
DefaultCloseOperation
225+
.verifyCloseOperation(this, getDefaultCloseOperation());
226+
}
227+
}
228+
}

0 commit comments

Comments
 (0)
Please sign in to comment.