Skip to content

Commit 367bcc5

Browse files
author
Tejesh R
committed
8353445: Open source several AWT Menu tests - Batch 1
Reviewed-by: abhiscxk, prr
1 parent 7eab2d9 commit 367bcc5

File tree

5 files changed

+454
-0
lines changed

5 files changed

+454
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,4 +819,5 @@ java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all
819819
java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all
820820
java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all
821821
java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all
822+
java/awt/Menu/MenuVisibilityTest.java 8161110 macosx-all
822823
java/awt/Modal/NativeDialogToFrontBackTest.java 7188049 windows-all,linux-all
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2000, 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 4094620
27+
* @summary MenuItem.enableEvents does not work
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MenuActionEventTest
31+
*/
32+
33+
import java.awt.AWTEvent;
34+
import java.awt.BorderLayout;
35+
import java.awt.Frame;
36+
import java.awt.Menu;
37+
import java.awt.MenuBar;
38+
import java.awt.MenuItem;
39+
import java.awt.event.ActionEvent;
40+
41+
public class MenuActionEventTest {
42+
public static void main(String[] args) throws Exception {
43+
String INSTRUCTIONS = """
44+
1. Click on the Menu and then on Menuitem on the frame.
45+
2. If you find the following message being printed in
46+
the test log area:,
47+
_MenuItem: action event",
48+
click PASS, else click FAIL"
49+
""";
50+
PassFailJFrame.builder()
51+
.instructions(INSTRUCTIONS)
52+
.columns(35)
53+
.testUI(MenuActionEventTest::initialize)
54+
.logArea()
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
static Frame initialize() {
60+
Frame f = new Frame("Menu Action Event Test");
61+
f.setLayout(new BorderLayout());
62+
f.setMenuBar(new MenuBar());
63+
Menu m = new _Menu("Menu");
64+
MenuBar mb = f.getMenuBar();
65+
mb.add(m);
66+
MenuItem mi = new _MenuItem("Menuitem");
67+
m.add(mi);
68+
f.setBounds(204, 152, 396, 300);
69+
return f;
70+
}
71+
72+
static class _Menu extends Menu {
73+
public _Menu(String text) {
74+
super(text);
75+
enableEvents(AWTEvent.ACTION_EVENT_MASK);
76+
}
77+
78+
@Override
79+
protected void processActionEvent(ActionEvent e) {
80+
PassFailJFrame.log("_Menu: action event");
81+
super.processActionEvent(e);
82+
}
83+
}
84+
85+
static class _MenuItem extends MenuItem {
86+
public _MenuItem(String text) {
87+
super(text);
88+
enableEvents(AWTEvent.ACTION_EVENT_MASK);
89+
}
90+
91+
@Override
92+
protected void processActionEvent(ActionEvent e) {
93+
PassFailJFrame.log("_MenuItem: action event");
94+
super.processActionEvent(e);
95+
}
96+
}
97+
98+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2004, 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 5046491 6423258
27+
* @summary CheckboxMenuItem: menu text is missing from test frame
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MenuVisibilityTest
31+
*/
32+
33+
import java.awt.Frame;
34+
import java.awt.Menu;
35+
import java.awt.MenuBar;
36+
import java.awt.MenuItem;
37+
38+
public class MenuVisibilityTest {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS = """
41+
1. Press on a MenuBar with a long name.
42+
2. Select "First item" in an opened menu.
43+
If you see that "First menu item was pressed" in
44+
the test log area, press PASS
45+
Otherwise press FAIL"
46+
""";
47+
PassFailJFrame.builder()
48+
.instructions(INSTRUCTIONS)
49+
.columns(35)
50+
.testUI(MenuVisibilityTest::initialize)
51+
.logArea()
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
public static Frame initialize() {
57+
Frame frame = new Frame("Menu visibility test");
58+
String menuTitle = "I_have_never_seen_so_long_Menu_Title_" +
59+
"!_ehe-eha-ehu-ehi_ugu-gu!!!_;)_BANG_BANG...";
60+
MenuBar menubar = new MenuBar();
61+
Menu menu = new Menu(menuTitle);
62+
MenuItem menuItem = new MenuItem("First item");
63+
menuItem.addActionListener(e ->
64+
PassFailJFrame.log("First menu item was pressed."));
65+
menu.add(menuItem);
66+
menubar.add(menu);
67+
frame.setMenuBar(menubar);
68+
frame.setSize(100, 200);
69+
return frame;
70+
}
71+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright (c) 1998, 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 4039387
27+
* @summary Checks that calling Frame.remove() within hide() doesn't
28+
* cause SEGV
29+
* @key headful
30+
* @run main RmInHideTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Dimension;
35+
import java.awt.EventQueue;
36+
import java.awt.Frame;
37+
import java.awt.Menu;
38+
import java.awt.MenuBar;
39+
import java.awt.MenuItem;
40+
import java.awt.Point;
41+
import java.awt.Robot;
42+
import java.awt.event.ActionEvent;
43+
import java.awt.event.ActionListener;
44+
import java.awt.event.MouseEvent;
45+
46+
public class RmInHideTest {
47+
static volatile Point point;
48+
static RmInHideTestFrame frame;
49+
static volatile Dimension dimension;
50+
51+
public static void main(String[] args) throws Exception {
52+
Robot robot = new Robot();
53+
try {
54+
EventQueue.invokeAndWait(() -> {
55+
frame = new RmInHideTestFrame();
56+
frame.setSize(200, 200);
57+
frame.setVisible(true);
58+
});
59+
robot.waitForIdle();
60+
robot.delay(1000);
61+
EventQueue.invokeAndWait(() -> {
62+
point = frame.getButtonLocation();
63+
dimension = frame.getButtonDimension();
64+
});
65+
robot.mouseMove(point.x + dimension.width / 2, point.y + dimension.height / 2);
66+
robot.mousePress(MouseEvent.BUTTON2_DOWN_MASK);
67+
robot.mouseRelease(MouseEvent.BUTTON2_DOWN_MASK);
68+
robot.waitForIdle();
69+
robot.delay(100);
70+
System.out.println("Test pass");
71+
} finally {
72+
EventQueue.invokeAndWait(() -> {
73+
if (frame != null) {
74+
frame.dispose();
75+
}
76+
});
77+
}
78+
}
79+
80+
static class RmInHideTestFrame extends Frame implements ActionListener {
81+
MenuBar menubar = null;
82+
Button b;
83+
84+
public RmInHideTestFrame() {
85+
super("RmInHideTest");
86+
b = new Button("Hide");
87+
b.setActionCommand("hide");
88+
b.addActionListener(this);
89+
add("Center", b);
90+
91+
MenuBar bar = new MenuBar();
92+
93+
Menu menu = new Menu("Test1", true);
94+
menu.add(new MenuItem("Test1A"));
95+
menu.add(new MenuItem("Test1B"));
96+
menu.add(new MenuItem("Test1C"));
97+
bar.add(menu);
98+
99+
menu = new Menu("Test2", true);
100+
menu.add(new MenuItem("Test2A"));
101+
menu.add(new MenuItem("Test2B"));
102+
menu.add(new MenuItem("Test2C"));
103+
bar.add(menu);
104+
setMenuBar(bar);
105+
}
106+
107+
@Override
108+
public Dimension minimumSize() {
109+
return new Dimension(200, 200);
110+
}
111+
112+
@Override
113+
public void actionPerformed(ActionEvent e) {
114+
String cmd = e.getActionCommand();
115+
if (cmd.equals("hide")) {
116+
hide();
117+
try {
118+
Thread.currentThread().sleep(2000);
119+
} catch (InterruptedException ex) {
120+
// do nothing
121+
}
122+
show();
123+
}
124+
}
125+
126+
@Override
127+
public void hide() {
128+
menubar = getMenuBar();
129+
if (menubar != null) {
130+
remove(menubar);
131+
}
132+
super.hide();
133+
}
134+
135+
136+
@Override
137+
public void show() {
138+
if (menubar != null) {
139+
setMenuBar(menubar);
140+
}
141+
super.show();
142+
}
143+
144+
public Point getButtonLocation() {
145+
return b.getLocationOnScreen();
146+
}
147+
148+
public Dimension getButtonDimension() {
149+
return b.getSize();
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)