Skip to content

Commit afffb37

Browse files
kspeeyuPaul Hohensee
authored andcommitted
8306076: Open source AWT misc tests
Backport-of: f7d45b85a5c664a87c94e0baccd8b9eddce27e2c
1 parent b42886f commit afffb37

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

test/jdk/java/awt/CacheTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2001, 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 4429261
27+
* @summary Checks AWTKeyStroke is cached
28+
* @run main CacheTest
29+
*/
30+
31+
import java.awt.AWTKeyStroke;
32+
import java.awt.EventQueue;
33+
import java.awt.event.KeyEvent;
34+
import java.awt.event.InputEvent;
35+
36+
public class CacheTest {
37+
38+
public static void main(String[] args) throws Exception {
39+
EventQueue.invokeAndWait(() -> {
40+
if (AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X,
41+
InputEvent.ALT_DOWN_MASK) !=
42+
AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X,
43+
InputEvent.ALT_DOWN_MASK)) {
44+
throw new RuntimeException("KeyStroke is not cached");
45+
}
46+
});
47+
}
48+
}// class CacheTest
Lines changed: 70 additions & 0 deletions
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 4154099
27+
@summary Tests that calling removeNotify() on a Frame and then reshowing
28+
the Frame does not crash or lockup
29+
@key headful
30+
@run main RemoveNotifyTest
31+
*/
32+
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 RemoveNotifyTest {
40+
static Frame f;
41+
42+
public static void main(String[] args) throws Exception {
43+
EventQueue.invokeAndWait(() -> {
44+
for (int i = 0; i < 100; i++) {
45+
try {
46+
f = new Frame();
47+
f.setBounds(10, 10, 100, 100);
48+
MenuBar bar = new MenuBar();
49+
Menu menu = new Menu();
50+
menu.add(new MenuItem("foo"));
51+
bar.add(menu);
52+
f.setMenuBar(bar);
53+
54+
for (int j = 0; j < 5; j++) {
55+
f.setVisible(true);
56+
f.removeNotify();
57+
}
58+
} finally {
59+
if (f != null) {
60+
f.dispose();
61+
}
62+
}
63+
}
64+
});
65+
66+
System.out.println("done");
67+
68+
}
69+
70+
}// class RemoveNotifyTest
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2004, 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+
* @test
25+
* @bug 4633887
26+
* @summary setting a null Image in setIconImage should not cause exception.
27+
* @key headful
28+
* @run main NullIconImageTest
29+
*/
30+
31+
import java.awt.EventQueue;
32+
import java.awt.Frame;
33+
34+
public class NullIconImageTest {
35+
static Frame f;
36+
37+
public static void main(String[] args) throws Exception {
38+
EventQueue.invokeAndWait(() -> {
39+
try {
40+
f = new Frame();
41+
f.setVisible(true);
42+
f.setIconImage(null); // This call should not cause an exception.
43+
} finally {
44+
if (f != null) {
45+
f.dispose();
46+
}
47+
}
48+
});
49+
}
50+
51+
}// class NullIconImageTest

0 commit comments

Comments
 (0)