Skip to content

Commit da0dd46

Browse files
committed
8341239: Open source closed frame tests # 3
Backport-of: ff3e849b8a1de3741dcd728636e1a804996f96fe
1 parent 8c5fa69 commit da0dd46

File tree

4 files changed

+366
-0
lines changed

4 files changed

+366
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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.Frame;
26+
import java.awt.Label;
27+
import java.awt.Menu;
28+
import java.awt.MenuBar;
29+
import java.awt.MenuItem;
30+
import java.awt.ScrollPane;
31+
import java.awt.Window;
32+
import java.util.List;
33+
34+
/*
35+
* @test
36+
* @bug 4084766
37+
* @summary Test for bug(s): 4084766
38+
* @library /java/awt/regtesthelpers
39+
* @build PassFailJFrame
40+
* @run main/manual FrameMenuPackTest
41+
*/
42+
43+
public class FrameMenuPackTest {
44+
private static final String INSTRUCTIONS = """
45+
Check that both frames that appear are properly packed with
46+
the scrollpane visible.
47+
""";
48+
49+
public static void main(String[] argv) throws Exception {
50+
PassFailJFrame.builder()
51+
.title("FrameMenuPackTest Instructions")
52+
.instructions(INSTRUCTIONS)
53+
.columns(45)
54+
.testUI(FrameMenuPackTest::createAndShowUI)
55+
.positionTestUIRightRow()
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
private static List<Window> createAndShowUI() {
61+
// Frame without menu, packs correctly
62+
PackedFrame f1 = new PackedFrame(false);
63+
f1.pack();
64+
65+
// Frame with menu, doesn't pack right
66+
PackedFrame f2 = new PackedFrame(true);
67+
f2.pack();
68+
69+
return List.of(f1, f2);
70+
}
71+
72+
private static class PackedFrame extends Frame {
73+
public PackedFrame(boolean withMenu) {
74+
super("PackedFrame");
75+
76+
MenuBar menubar;
77+
Menu fileMenu;
78+
MenuItem foo;
79+
ScrollPane sp;
80+
81+
sp = new ScrollPane();
82+
sp.add(new Label("Label in ScrollPane"));
83+
System.out.println(sp.getMinimumSize());
84+
85+
this.setLayout(new BorderLayout());
86+
this.add(sp, "Center");
87+
this.add(new Label("Label in Frame"), "South");
88+
89+
if (withMenu) {
90+
menubar = new MenuBar();
91+
fileMenu = new Menu("File");
92+
foo = new MenuItem("foo");
93+
fileMenu.add(foo);
94+
menubar.add(fileMenu);
95+
this.setMenuBar(menubar);
96+
}
97+
}
98+
}
99+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2000, 2024, 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.Button;
25+
import java.awt.Frame;
26+
import java.awt.GridLayout;
27+
import java.awt.Window;
28+
import java.awt.event.ActionListener;
29+
30+
/*
31+
* @test
32+
* @bug 4097207
33+
* @summary setSize() on a Frame does not resize its content
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual FrameResizeTest_3
37+
*/
38+
39+
public class FrameResizeTest_3 {
40+
41+
private static final String INSTRUCTIONS = """
42+
1. You would see a frame titled 'TestFrame' with 2 buttons
43+
named 'setSize(500,500)' and 'setSize(400,400)'
44+
2. Click any button and you would see the frame resized
45+
3. If the buttons get resized along with the frame
46+
(ie., to fit the frame), press Pass else press Fail.
47+
""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.title("FrameResizeTest_3 Instructions")
52+
.instructions(INSTRUCTIONS)
53+
.columns(45)
54+
.logArea(6)
55+
.testUI(FrameResizeTest_3::createTestUI)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
private static Window createTestUI() {
61+
Frame frame = new Frame("TestFrame");
62+
frame.setLayout(new GridLayout(2, 1));
63+
64+
Button butSize500 = new Button("setSize(500,500)");
65+
Button butSize400 = new Button("setSize(400,400)");
66+
67+
ActionListener actionListener = e -> {
68+
if (e.getSource() instanceof Button) {
69+
if (e.getSource() == butSize500) {
70+
frame.setSize(500, 500);
71+
PassFailJFrame.log("New bounds: " + frame.getBounds());
72+
} else if (e.getSource() == butSize400) {
73+
frame.setSize(400, 400);
74+
PassFailJFrame.log("New bounds: " + frame.getBounds());
75+
}
76+
}
77+
};
78+
butSize500.addActionListener(actionListener);
79+
butSize400.addActionListener(actionListener);
80+
frame.add(butSize500);
81+
frame.add(butSize400);
82+
83+
frame.setSize(270, 200);
84+
return frame;
85+
}
86+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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+
/* Note that although this test makes use of Swing classes, like JFrame and */
25+
/* JButton, it is really an AWT test, because it tests mechanism of sending */
26+
/* paint events. */
27+
28+
import javax.swing.JButton;
29+
import javax.swing.JFrame;
30+
import javax.swing.JPanel;
31+
import java.awt.BorderLayout;
32+
33+
/*
34+
* @test
35+
* @bug 4174831
36+
* @summary Tests that frame do not flicker on diagonal resize
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @run main/manual FrameResizeTest_4
40+
*/
41+
42+
public class FrameResizeTest_4 {
43+
private static final String INSTRUCTIONS = """
44+
Try enlarging the frame diagonally.
45+
If buttons inside frame excessively repaint themselves and flicker
46+
while you enlarge frame, the test fails.
47+
Otherwise, it passes.
48+
""";
49+
50+
public static void main(String[] args) throws Exception {
51+
PassFailJFrame.builder()
52+
.title("FrameResizeTest_4 Instructions")
53+
.instructions(INSTRUCTIONS)
54+
.columns(45)
55+
.testUI(FrameResizeTest_4::createTestUI)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
private static JFrame createTestUI() {
61+
JFrame f = new JFrame("FrameResizeTest_4 Flickering Frame");
62+
63+
JPanel panel = new JPanel(new BorderLayout());
64+
panel.add(new JButton("West"), BorderLayout.WEST);
65+
panel.add(new JButton("East"), BorderLayout.EAST);
66+
panel.add(new JButton("North"), BorderLayout.NORTH);
67+
panel.add(new JButton("South"), BorderLayout.SOUTH);
68+
panel.add(new JButton("Center"), BorderLayout.CENTER);
69+
f.setContentPane(panel);
70+
71+
f.pack();
72+
f.setBounds(100, 50, 300, 200);
73+
74+
return f;
75+
}
76+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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.Button;
25+
import java.awt.Frame;
26+
import java.awt.GridLayout;
27+
28+
/*
29+
* @test
30+
* @summary Test to make sure non-resizable Frames can be resized with the
31+
* setSize() method.
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @run main/manual FrameResizeTest_5
35+
*/
36+
37+
public class FrameResizeTest_5 {
38+
private static final String INSTRUCTIONS = """
39+
This tests the programmatic resizability of non-resizable Frames.
40+
Even when a Frame is set to be non-resizable, it should still be
41+
programmatically resizable using the setSize() method.
42+
43+
Initially the Frame will be resizable. Try using the "Smaller"
44+
and "Larger" buttons to verify that the Frame resizes correctly.
45+
Then, click the "Toggle" button to make the Frame non-resizable.
46+
Again, verify that clicking the "Larger" and "Smaller" buttons
47+
causes the Frame to get larger and smaller. If the Frame does
48+
not change size, or does not re-layout correctly, the test fails.
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame.builder()
53+
.title("FrameResizeTest_5 Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.columns(45)
56+
.logArea(6)
57+
.testUI(TestFrame::new)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static class TestFrame extends Frame {
63+
Button bLarger, bSmaller, bCheck, bToggle;
64+
65+
public TestFrame() {
66+
super("Frame Resize Test");
67+
setSize(200, 200);
68+
bLarger = new Button("Larger");
69+
bLarger.addActionListener(e -> {
70+
setSize(400, 400);
71+
validate();
72+
});
73+
bSmaller = new Button("Smaller");
74+
bSmaller.addActionListener(e -> {
75+
setSize(200, 100);
76+
validate();
77+
});
78+
bCheck = new Button("Resizable?");
79+
bCheck.addActionListener(e -> {
80+
if (isResizable()) {
81+
PassFailJFrame.log("Frame is resizable");
82+
setResizable(true);
83+
} else {
84+
PassFailJFrame.log("Frame is not resizable");
85+
setResizable(false);
86+
}
87+
});
88+
bToggle = new Button("Toggle");
89+
bToggle.addActionListener(e -> {
90+
if (isResizable()) {
91+
PassFailJFrame.log("Frame is now not resizable");
92+
setResizable(false);
93+
} else {
94+
PassFailJFrame.log("Frame is now resizable");
95+
setResizable(true);
96+
}
97+
});
98+
setLayout(new GridLayout(4, 1));
99+
add(bSmaller);
100+
add(bLarger);
101+
add(bCheck);
102+
add(bToggle);
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)