Skip to content

Commit 09e6880

Browse files
Victor RudometovPaul Hohensee
Victor Rudometov
authored and
Paul Hohensee
committed
8306652: Open source AWT MenuItem related tests
Backport-of: ed1ebd242a4bb82a7074564ea96dc3d26b78f9e1
1 parent 18ec008 commit 09e6880

File tree

4 files changed

+326
-0
lines changed

4 files changed

+326
-0
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
@test
26+
@bug 4257944
27+
@summary PopupMenu.setEnabled fails on Win32
28+
@key headful
29+
@run main EnableTest
30+
*/
31+
32+
import java.awt.AWTEvent;
33+
import java.awt.BorderLayout;
34+
import java.awt.EventQueue;
35+
import java.awt.Frame;
36+
import java.awt.MenuItem;
37+
import java.awt.PopupMenu;
38+
39+
public class EnableTest {
40+
PopupMenu popup = null;
41+
Frame frame;
42+
43+
public static void main(String[] args) throws Exception {
44+
EnableTest test = new EnableTest();
45+
test.start();
46+
}
47+
48+
public void start() throws Exception {
49+
try {
50+
EventQueue.invokeAndWait(() -> {
51+
frame = new Frame("EnableTest");
52+
popup = new PopupMenu("Popup Menu Title");
53+
MenuItem mi1 = new MenuItem("Menu Item");
54+
MenuItem mi2 = new MenuItem("Menu Item");
55+
popup.add(mi1);
56+
popup.addSeparator();
57+
popup.add(mi2);
58+
popup.setEnabled(false);
59+
popup.setLabel("New Label");
60+
mi2.setEnabled(false);
61+
frame.add(popup);
62+
frame.pack();
63+
frame.setLocationRelativeTo(null);
64+
frame.setVisible(true);
65+
});
66+
} finally {
67+
EventQueue.invokeAndWait(() -> {
68+
if (frame != null) {
69+
frame.dispose();
70+
}
71+
});
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
@test
26+
@bug 4261935
27+
@summary Menu display problem when changing the text of the menu(window 98)
28+
@key headful
29+
@run main MenuSetLabelTest
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.EventQueue;
34+
import java.awt.Frame;
35+
import java.awt.Menu;
36+
import java.awt.MenuBar;
37+
import java.awt.MenuItem;
38+
import java.awt.Robot;
39+
40+
public class MenuSetLabelTest {
41+
Menu1 f;
42+
43+
public static void main(String[] args) throws Exception {
44+
MenuSetLabelTest test = new MenuSetLabelTest();
45+
test.start();
46+
}
47+
48+
public void start() throws Exception {
49+
try {
50+
EventQueue.invokeAndWait(() -> {
51+
f = new Menu1();
52+
f.setTitle("MenuSetLabelTest");
53+
f.setSize(300, 200);
54+
f.setLocationRelativeTo(null);
55+
f.setVisible(true);
56+
});
57+
Robot robot = new Robot();
58+
robot.delay(1000);
59+
robot.waitForIdle();
60+
EventQueue.invokeAndWait(() -> {
61+
f.changeMenuLabel();
62+
});
63+
} finally {
64+
EventQueue.invokeAndWait(() -> {
65+
if (f != null) {
66+
f.dispose();
67+
}
68+
});
69+
}
70+
}
71+
72+
}
73+
74+
class Menu1 extends Frame {
75+
76+
String s1 = new String("short");
77+
String s2 = new String("This is a long string");
78+
String s3 = new String("Menu Item string");
79+
80+
MenuBar mb1 = new MenuBar();
81+
Menu f = new Menu(s1);
82+
Menu m = new Menu(s1);
83+
boolean flag = true;
84+
85+
public Menu1()
86+
{
87+
for (int i = 0; i < 5; i++) {
88+
m.add(new MenuItem(s3));
89+
}
90+
for (int i = 0; i < 10; i++) {
91+
f.add(new MenuItem(s3));
92+
}
93+
mb1.add(f);
94+
mb1.add(m);
95+
setMenuBar(mb1);
96+
}
97+
98+
public void changeMenuLabel() {
99+
MenuBar mb = getMenuBar();
100+
Menu m0 = mb.getMenu(0);
101+
Menu m1 = mb.getMenu(1);
102+
103+
if (flag) {
104+
m0.setLabel(s2);
105+
m1.setLabel(s2);
106+
} else {
107+
m0.setLabel(s1);
108+
m1.setLabel(s1);
109+
}
110+
flag = !flag;
111+
}
112+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
@test
26+
@bug 4234266
27+
@summary MenuItem throws NullPointer exception when setting the label with created peer.
28+
@key headful
29+
@run main SetLabelWithPeerCreatedTest
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.EventQueue;
34+
import java.awt.Frame;
35+
import java.awt.Menu;
36+
import java.awt.MenuBar;
37+
import java.awt.MenuItem;
38+
39+
public class SetLabelWithPeerCreatedTest {
40+
Frame frame;
41+
public static void main(String[] args) throws Exception {
42+
SetLabelWithPeerCreatedTest test = new SetLabelWithPeerCreatedTest();
43+
test.start();
44+
}
45+
46+
public void start() throws Exception {
47+
try {
48+
EventQueue.invokeAndWait(() -> {
49+
frame = new Frame("SetLabel with Peer Created Test");
50+
Menu menu = new Menu("Menu");
51+
MenuItem mi = new MenuItem("Item");
52+
MenuBar mb = new MenuBar();
53+
menu.add(mi);
54+
mb.add(menu);
55+
frame.setMenuBar(mb);
56+
frame.setSize(300, 200);
57+
frame.setLocationRelativeTo(null);
58+
mi.setLabel("new label");
59+
frame.setVisible(true);
60+
System.out.println("Test PASSED!");
61+
});
62+
} finally {
63+
EventQueue.invokeAndWait(() -> {
64+
if (frame != null) {
65+
frame.dispose();
66+
}
67+
});
68+
}
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2005, 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+
/*
25+
@test
26+
@bug 5106833
27+
@summary NullPointerException in XMenuPeer.repaintMenuItem
28+
@key headful
29+
@run main SetStateTest
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.EventQueue;
34+
import java.awt.Frame;
35+
import java.awt.Menu;
36+
import java.awt.MenuBar;
37+
import java.awt.CheckboxMenuItem;
38+
39+
public class SetStateTest {
40+
Frame frame;
41+
public static void main(String[] args) throws Exception {
42+
SetStateTest test = new SetStateTest();
43+
test.start();
44+
}
45+
46+
public void start () throws Exception {
47+
try {
48+
EventQueue.invokeAndWait(() -> {
49+
frame = new Frame("SetStateTest");
50+
MenuBar bar = new MenuBar();
51+
Menu menu = new Menu("Menu");
52+
CheckboxMenuItem checkboxMenuItem = new CheckboxMenuItem("Item");
53+
bar.add(menu);
54+
frame.setMenuBar(bar);
55+
menu.add(checkboxMenuItem);
56+
checkboxMenuItem.setState(true);
57+
frame.setSize(300, 200);
58+
frame.setLocationRelativeTo(null);
59+
frame.setVisible(true);
60+
System.out.println("Test PASSED!");
61+
});
62+
} finally {
63+
EventQueue.invokeAndWait(() -> {
64+
if (frame != null) {
65+
frame.dispose();
66+
}
67+
});
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)