Skip to content

Commit 6666153

Browse files
author
Satyen Subramaniam
committed
8353293: Open source several swing tests batch4
Backport-of: a551cc929426590bfbbcaa4bd8bee5e4e8cfe16d
1 parent ed29bfa commit 6666153

File tree

6 files changed

+385
-0
lines changed

6 files changed

+385
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 4198822
27+
* @summary Tests that the bottom line drawn by
28+
* BasicGraphicsUtils.drawEtchedRect extends to the end.
29+
* @run main DrawEtchedRectTest
30+
*/
31+
32+
import java.awt.Color;
33+
import java.awt.Component;
34+
import java.awt.Graphics;
35+
import java.awt.Graphics2D;
36+
import java.awt.image.BufferedImage;
37+
import java.io.File;
38+
39+
import javax.imageio.ImageIO;
40+
import javax.swing.plaf.basic.BasicGraphicsUtils;
41+
42+
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
43+
44+
public class DrawEtchedRectTest {
45+
private static final int WIDTH = 200;
46+
private static final int HEIGHT = 200;
47+
private static final int RANGE = 10;
48+
49+
public static void main(String[] args) throws Exception {
50+
// Draw etched rectangle to a BufferedImage
51+
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, TYPE_INT_ARGB);
52+
Graphics2D g2d = image.createGraphics();
53+
Component sq = new Component() {
54+
public void paint(Graphics g) {
55+
g.setColor(Color.WHITE);
56+
g.fillRect(0, 0, WIDTH, HEIGHT);
57+
BasicGraphicsUtils.drawEtchedRect(g, 0, 0, WIDTH, HEIGHT,
58+
Color.black, Color.black,
59+
Color.black, Color.black);
60+
}
61+
};
62+
sq.paint(g2d);
63+
g2d.dispose();
64+
65+
// Check if connected at bottom-right corner
66+
int c1;
67+
int c2;
68+
for (int i = 1; i < RANGE; i++) {
69+
c1 = image.getRGB(WIDTH - i, HEIGHT - 1);
70+
c2 = image.getRGB(WIDTH - 1, HEIGHT - i);
71+
if (c1 == Color.WHITE.getRGB() || c2 == Color.WHITE.getRGB()) {
72+
ImageIO.write(image, "png", new File("failImage.png"));
73+
throw new RuntimeException("Bottom line is not connected!");
74+
}
75+
}
76+
}
77+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 4228104
27+
* @summary Tests work of BODY BACKGROUND tag in HTML renderer
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4228104
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
35+
import javax.swing.JFrame;
36+
import javax.swing.JLabel;
37+
38+
public class bug4228104 {
39+
static final String INSTRUCTIONS = """
40+
There should be an image displaying dukes under the rows of digits.
41+
If you can see it, the test PASSES. Otherwise, the test FAILS.
42+
""";
43+
44+
public static void main(String[] args) throws Exception {
45+
PassFailJFrame.builder()
46+
.title("bug4228104 Test Instructions")
47+
.instructions(INSTRUCTIONS)
48+
.columns(40)
49+
.testUI(bug4228104::createUI)
50+
.build()
51+
.awaitAndCheck();
52+
}
53+
54+
static JFrame createUI() {
55+
JFrame f = new JFrame("Background HTML Text Test");
56+
String dir = System.getProperty("test.src",
57+
System.getProperty("user.dir"));
58+
String htmlText1 =
59+
"<html><BODY BACKGROUND=\"file:" + dir
60+
+ "/duke.gif\">\n" +
61+
"<br>111111111111111111" +
62+
"<br>111111111111111111" +
63+
"<br>111111111111111111" +
64+
"<br>111111111111111111" +
65+
"<br>111111111111111111" +
66+
"<br>111111111111111111" +
67+
"<br>111111111111111111" +
68+
"<br>111111111111111111" +
69+
"<br>111111111111111111";
70+
JLabel button1 = new JLabel(htmlText1);
71+
f.add(button1, BorderLayout.NORTH);
72+
f.setSize(200, 200);
73+
return f;
74+
}
75+
}
1.88 KB
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 4220108
27+
* @summary JSlider in JInternalFrame should be painted correctly
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4220108
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.FlowLayout;
35+
36+
import javax.swing.JDesktopPane;
37+
import javax.swing.JFrame;
38+
import javax.swing.JInternalFrame;
39+
import javax.swing.JLabel;
40+
import javax.swing.JSlider;
41+
42+
public class bug4220108 {
43+
static final String INSTRUCTIONS = """
44+
If you see a slider in the internal frame, then the test PASSES.
45+
Otherwise the test FAILS.
46+
""";
47+
48+
public static void main(String[] args) throws Exception {
49+
PassFailJFrame.builder()
50+
.title("bug4220108 Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.columns(40)
53+
.testUI(bug4220108::createUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
static JFrame createUI() {
59+
JFrame f = new JFrame("Internal Frame Slider Test");
60+
f.setLayout(new FlowLayout());
61+
JDesktopPane desktop = new JDesktopPane();
62+
f.setContentPane(desktop);
63+
64+
JInternalFrame iFrame =
65+
new JInternalFrame("Slider Frame", true, true, true, true);
66+
JSlider sl = new JSlider();
67+
iFrame.add(sl);
68+
iFrame.add(new JLabel("Label"), BorderLayout.SOUTH);
69+
desktop.add(iFrame);
70+
iFrame.pack();
71+
iFrame.setVisible(true);
72+
f.setSize(300, 200);
73+
return f;
74+
}
75+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 4199666
27+
* @summary Makes sure initial negative size of a component does not confuse
28+
* JSplitPane.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual NegativeSizeTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.CardLayout;
36+
37+
import javax.swing.BorderFactory;
38+
import javax.swing.JButton;
39+
import javax.swing.JFrame;
40+
import javax.swing.JPanel;
41+
import javax.swing.JSplitPane;
42+
43+
public class NegativeSizeTest {
44+
static final String INSTRUCTIONS = """
45+
Click on the 'Show JSplitPane' button. If two buttons appear,
46+
click PASS, otherwise click FAIL.
47+
""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.title("NegativeSizeTest Test Instructions")
52+
.instructions(INSTRUCTIONS)
53+
.columns(40)
54+
.testUI(NegativeSizeTest::createUI)
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
static JFrame createUI() {
60+
JFrame f = new JFrame("Negative Size Test");
61+
CardLayout cardLayout = new CardLayout();
62+
JPanel mainPanel = new JPanel(cardLayout);
63+
64+
JSplitPane splitPane = new JSplitPane();
65+
splitPane.setContinuousLayout(true);
66+
JPanel splitContainer = new JPanel(new BorderLayout());
67+
splitContainer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
68+
splitContainer.add(splitPane, BorderLayout.CENTER);
69+
70+
if (false) {
71+
mainPanel.add(splitContainer, "split");
72+
mainPanel.add(new JPanel(), "blank");
73+
}
74+
else {
75+
mainPanel.add(new JPanel(), "blank");
76+
mainPanel.add(splitContainer, "split");
77+
}
78+
79+
f.add(mainPanel, BorderLayout.CENTER);
80+
81+
JButton button = new JButton("Show JSplitPane");
82+
button.addActionListener(e -> cardLayout.show(mainPanel, "split"));
83+
f.add(button, BorderLayout.SOUTH);
84+
f.setSize(400, 300);
85+
return f;
86+
}
87+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 4208549
27+
* @summary Makes sure preferred size returned by layout managers used by
28+
* JSplitPane is correct.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual PreferredSizeLayoutTest
32+
*/
33+
34+
import java.awt.Container;
35+
import java.awt.FlowLayout;
36+
37+
import javax.swing.JFrame;
38+
import javax.swing.JSplitPane;
39+
40+
public class PreferredSizeLayoutTest {
41+
static final String INSTRUCTIONS = """
42+
If the buttons in the JSplitpanes do not have '...' in them,
43+
click PASS, otherwise click FAIL.
44+
""";
45+
46+
public static void main(String[] args) throws Exception {
47+
PassFailJFrame.builder()
48+
.title("PreferredSizeLayoutTest Test Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.columns(40)
51+
.testUI(PreferredSizeLayoutTest::createUI)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
static JFrame createUI() {
57+
JFrame f = new JFrame("Preferred Size Layout Test");
58+
Container parent = f.getContentPane();
59+
JSplitPane sp = new JSplitPane();
60+
61+
parent.setLayout(new FlowLayout());
62+
63+
sp.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
64+
parent.add(sp);
65+
sp = new JSplitPane();
66+
sp.setOrientation(JSplitPane.VERTICAL_SPLIT);
67+
parent.add(sp);
68+
f.setSize(400, 300);
69+
return f;
70+
}
71+
}

0 commit comments

Comments
 (0)