Skip to content

Commit 17b080b

Browse files
author
Tejesh R
committed
8353446: Open source several AWT Menu tests - Batch 2
Reviewed-by: abhiscxk
1 parent 2f7806f commit 17b080b

File tree

5 files changed

+596
-0
lines changed

5 files changed

+596
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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 4209511
27+
* @summary Regression test DestroyMenuTest.java Failing
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual DestroyMenuTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Button;
35+
import java.awt.Canvas;
36+
import java.awt.FlowLayout;
37+
import java.awt.Frame;
38+
import java.awt.Graphics;
39+
import java.awt.Label;
40+
import java.awt.Panel;
41+
import java.awt.Scrollbar;
42+
import java.awt.TextField;
43+
44+
public class DestroyMenuTest {
45+
public static void main(String[] args) throws Exception {
46+
String INSTRUCTIONS = """
47+
1. Create many windows by randomly clicking 'Show Menu Test 1',
48+
'Show Menu Test 2', 'Show Menu Test 3' buttons.
49+
2. Ignore the contents of the windows.
50+
Go to the windows created and select menu items inside the menus.
51+
3. Close the windows by selecting menu item File--> Quit.
52+
4. Do the above menu item selections as quickly as possible.
53+
If the program crashes when you select File--> Quit,
54+
then the test FAILS. Otherwise the test is PASS.
55+
""";
56+
PassFailJFrame.builder()
57+
.instructions(INSTRUCTIONS)
58+
.columns(38)
59+
.testUI(DestroyMenuTest::initialize)
60+
.build()
61+
.awaitAndCheck();
62+
}
63+
64+
static Frame initialize() {
65+
Frame f = new Frame("Destroy Menu Test");
66+
Button launchButton = new Button("Show Menu Test 1...");
67+
Button launchButton2 = new Button("Show Menu Test 2...");
68+
Button launchButton3 = new Button("Show Menu Test 3...");
69+
f.setLayout(new FlowLayout());
70+
f.add(launchButton);
71+
f.add(launchButton2);
72+
f.add(launchButton3);
73+
74+
launchButton.addActionListener(event -> {
75+
MenuTest frame = new MenuTest("Menu Test 1");
76+
frame.setBounds(300, 300, 300, 300);
77+
frame.setVisible(true);
78+
});
79+
80+
launchButton2.addActionListener(event -> {
81+
MenuTest frame = new MenuTest("Menu Test 2");
82+
83+
Button closeButton = new Button("Close");
84+
85+
Panel X = new Panel();
86+
X.setLayout(new BorderLayout());
87+
88+
Panel topPanel = new Panel();
89+
Panel bottomPanel = new Panel();
90+
91+
bottomPanel.add(closeButton);
92+
93+
Scrollbar vScrollbar = new Scrollbar(Scrollbar.VERTICAL);
94+
Scrollbar hScrollbar = new Scrollbar(Scrollbar.HORIZONTAL);
95+
hScrollbar.setValues(hScrollbar.getValue(), 0, 0, 50);
96+
vScrollbar.setValues(vScrollbar.getValue(), 0, 0, 50);
97+
topPanel.setLayout(new BorderLayout());
98+
topPanel.add(vScrollbar, BorderLayout.EAST);
99+
topPanel.add(hScrollbar, BorderLayout.SOUTH);
100+
101+
X.add(topPanel, BorderLayout.NORTH);
102+
X.add(bottomPanel, BorderLayout.SOUTH);
103+
frame.add(X, BorderLayout.SOUTH);
104+
frame.setBounds(350, 350, 300, 250);
105+
frame.setVisible(true);
106+
});
107+
108+
launchButton3.addActionListener(event -> {
109+
MenuTest frame = new MenuTest("Menu Test 3");
110+
frame.setBounds(400, 400, 300, 300);
111+
112+
mySimpleCanvas clock = new mySimpleCanvas();
113+
frame.add(clock, BorderLayout.CENTER);
114+
115+
Panel p = new Panel();
116+
Button closeButton = new Button("Close");
117+
p.add(closeButton);
118+
119+
p.add(new Label("Label"));
120+
TextField textField = new TextField(8);
121+
p.add(textField);
122+
f.add(p, BorderLayout.EAST);
123+
124+
frame.add(p, BorderLayout.SOUTH);
125+
frame.setVisible(true);
126+
});
127+
f.pack();
128+
return f;
129+
}
130+
131+
static class mySimpleCanvas extends Canvas {
132+
@Override
133+
public void paint(Graphics g) {
134+
g.drawOval(0, 0, 100, 100);
135+
g.drawOval(2, 2, 100, 100);
136+
g.drawOval(4, 4, 100, 100);
137+
}
138+
}
139+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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.Canvas;
25+
import java.awt.CardLayout;
26+
import java.awt.Frame;
27+
import java.awt.Graphics;
28+
import java.awt.Label;
29+
import java.awt.Menu;
30+
import java.awt.MenuBar;
31+
import java.awt.MenuItem;
32+
import java.awt.Panel;
33+
34+
public class MenuTest extends Frame {
35+
private MenuItem quitItem;
36+
private final Panel cards;
37+
private final CardLayout layout;
38+
39+
public MenuTest(String s) {
40+
super(s);
41+
MenuBar mbar = new MenuBar();
42+
createMenus(mbar);
43+
setMenuBar(mbar);
44+
45+
cards = new Panel();
46+
layout = new CardLayout();
47+
cards.setLayout(layout);
48+
49+
cards.add(new MyPanelOne("Options"), "Options");
50+
cards.add(new MyRectCanvas(), "MyRectCanvas");
51+
cards.add(new MycircleCanvas(), "MyCircleCanvas");
52+
53+
add(cards, "Center");
54+
}
55+
56+
public void createMenus(MenuBar mbar) {
57+
mbar.add(createFileMenu());
58+
mbar.add(createEditMenu());
59+
mbar.add(createOptionMenu1());
60+
mbar.add(createOptionMenu2());
61+
mbar.add(createOptionMenu3());
62+
mbar.add(createOptionMenu4());
63+
}
64+
65+
private Menu createFileMenu() {
66+
Menu fileMenu = new Menu("File");
67+
fileMenu.add(quitItem = new MenuItem("Quit"));
68+
69+
quitItem.addActionListener(event -> {
70+
MenuItem item = (MenuItem) event.getSource();
71+
if (item == quitItem) {
72+
dispose();
73+
}
74+
});
75+
return fileMenu;
76+
}
77+
78+
private Menu createEditMenu() {
79+
Menu editMenu = new Menu("Edit");
80+
81+
editMenu.add("Cut");
82+
editMenu.add("Copy");
83+
editMenu.add("Paste");
84+
editMenu.addSeparator();
85+
editMenu.add("Select all");
86+
editMenu.addSeparator();
87+
editMenu.add("Find");
88+
editMenu.add("Find again");
89+
90+
return editMenu;
91+
}
92+
93+
private Menu createOptionMenu1() {
94+
Menu optionMenu1 = new Menu("Option1");
95+
MenuItem item1, item2, item3;
96+
optionMenu1.add(item1 = new MenuItem("Item1"));
97+
optionMenu1.add(item2 = new MenuItem("Item2"));
98+
optionMenu1.add(item3 = new MenuItem("Item3"));
99+
100+
item1.addActionListener(event -> {
101+
MenuItem mItem = (MenuItem) event.getSource();
102+
if (mItem == item1) {
103+
layout.show(cards, "Options");
104+
}
105+
});
106+
item2.addActionListener(event -> {
107+
MenuItem mItem = (MenuItem) event.getSource();
108+
if (mItem == item2) {
109+
layout.show(cards, "MyRectCanvas");
110+
}
111+
});
112+
item3.addActionListener(event -> {
113+
MenuItem mItem = (MenuItem) event.getSource();
114+
if (mItem == item3) {
115+
layout.show(cards, "MyCircleCanvas");
116+
}
117+
});
118+
return optionMenu1;
119+
}
120+
121+
private Menu createOptionMenu2() {
122+
Menu optionMenu2 = new Menu("Option2");
123+
124+
optionMenu2.add("Item1");
125+
optionMenu2.add("Item2");
126+
127+
return optionMenu2;
128+
}
129+
130+
private Menu createOptionMenu3() {
131+
Menu optionMenu3 = new Menu("Option3");
132+
133+
optionMenu3.add("Item1");
134+
optionMenu3.add("Item2");
135+
optionMenu3.add("Item3");
136+
optionMenu3.add("Item4");
137+
138+
return optionMenu3;
139+
}
140+
141+
private Menu createOptionMenu4() {
142+
Menu optionMenu4 = new Menu("Option3");
143+
144+
optionMenu4.add("Item1");
145+
optionMenu4.add("Item2");
146+
optionMenu4.add("Item3");
147+
148+
return optionMenu4;
149+
}
150+
}
151+
152+
class MyRectCanvas extends Canvas {
153+
@Override
154+
public void paint(Graphics g) {
155+
g.drawRect(0, 0, 100, 100);
156+
}
157+
}
158+
159+
class MyPanelOne extends Panel {
160+
MyPanelOne(String name) {
161+
add(new Label(name + " panel goes here"));
162+
}
163+
}
164+
165+
class MycircleCanvas extends Canvas {
166+
@Override
167+
public void paint(Graphics g) {
168+
g.drawOval(0, 0, 100, 100);
169+
g.drawOval(2, 2, 100, 100);
170+
g.drawOval(4, 4, 100, 100);
171+
}
172+
}

0 commit comments

Comments
 (0)