8353293: Open source several swing tests batch4

Reviewed-by: serb
This commit is contained in:
Damon Nguyen 2025-04-18 17:07:16 +00:00
parent bb08a70bd8
commit a551cc9294
6 changed files with 385 additions and 0 deletions

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4198822
* @summary Tests that the bottom line drawn by
* BasicGraphicsUtils.drawEtchedRect extends to the end.
* @run main DrawEtchedRectTest
*/
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.plaf.basic.BasicGraphicsUtils;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
public class DrawEtchedRectTest {
private static final int WIDTH = 200;
private static final int HEIGHT = 200;
private static final int RANGE = 10;
public static void main(String[] args) throws Exception {
// Draw etched rectangle to a BufferedImage
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
Component sq = new Component() {
public void paint(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, WIDTH, HEIGHT);
BasicGraphicsUtils.drawEtchedRect(g, 0, 0, WIDTH, HEIGHT,
Color.black, Color.black,
Color.black, Color.black);
}
};
sq.paint(g2d);
g2d.dispose();
// Check if connected at bottom-right corner
int c1;
int c2;
for (int i = 1; i < RANGE; i++) {
c1 = image.getRGB(WIDTH - i, HEIGHT - 1);
c2 = image.getRGB(WIDTH - 1, HEIGHT - i);
if (c1 == Color.WHITE.getRGB() || c2 == Color.WHITE.getRGB()) {
ImageIO.write(image, "png", new File("failImage.png"));
throw new RuntimeException("Bottom line is not connected!");
}
}
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4228104
* @summary Tests work of BODY BACKGROUND tag in HTML renderer
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4228104
*/
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class bug4228104 {
static final String INSTRUCTIONS = """
There should be an image displaying dukes under the rows of digits.
If you can see it, the test PASSES. Otherwise, the test FAILS.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug4228104 Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4228104::createUI)
.build()
.awaitAndCheck();
}
static JFrame createUI() {
JFrame f = new JFrame("Background HTML Text Test");
String dir = System.getProperty("test.src",
System.getProperty("user.dir"));
String htmlText1 =
"<html><BODY BACKGROUND=\"file:" + dir
+ "/duke.gif\">\n" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111" +
"<br>111111111111111111";
JLabel button1 = new JLabel(htmlText1);
f.add(button1, BorderLayout.NORTH);
f.setSize(200, 200);
return f;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4220108
* @summary JSlider in JInternalFrame should be painted correctly
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4220108
*/
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
public class bug4220108 {
static final String INSTRUCTIONS = """
If you see a slider in the internal frame, then the test PASSES.
Otherwise the test FAILS.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug4220108 Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4220108::createUI)
.build()
.awaitAndCheck();
}
static JFrame createUI() {
JFrame f = new JFrame("Internal Frame Slider Test");
f.setLayout(new FlowLayout());
JDesktopPane desktop = new JDesktopPane();
f.setContentPane(desktop);
JInternalFrame iFrame =
new JInternalFrame("Slider Frame", true, true, true, true);
JSlider sl = new JSlider();
iFrame.add(sl);
iFrame.add(new JLabel("Label"), BorderLayout.SOUTH);
desktop.add(iFrame);
iFrame.pack();
iFrame.setVisible(true);
f.setSize(300, 200);
return f;
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4199666
* @summary Makes sure initial negative size of a component does not confuse
* JSplitPane.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual NegativeSizeTest
*/
import java.awt.BorderLayout;
import java.awt.CardLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
public class NegativeSizeTest {
static final String INSTRUCTIONS = """
Click on the 'Show JSplitPane' button. If two buttons appear,
click PASS, otherwise click FAIL.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("NegativeSizeTest Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(NegativeSizeTest::createUI)
.build()
.awaitAndCheck();
}
static JFrame createUI() {
JFrame f = new JFrame("Negative Size Test");
CardLayout cardLayout = new CardLayout();
JPanel mainPanel = new JPanel(cardLayout);
JSplitPane splitPane = new JSplitPane();
splitPane.setContinuousLayout(true);
JPanel splitContainer = new JPanel(new BorderLayout());
splitContainer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
splitContainer.add(splitPane, BorderLayout.CENTER);
if (false) {
mainPanel.add(splitContainer, "split");
mainPanel.add(new JPanel(), "blank");
}
else {
mainPanel.add(new JPanel(), "blank");
mainPanel.add(splitContainer, "split");
}
f.add(mainPanel, BorderLayout.CENTER);
JButton button = new JButton("Show JSplitPane");
button.addActionListener(e -> cardLayout.show(mainPanel, "split"));
f.add(button, BorderLayout.SOUTH);
f.setSize(400, 300);
return f;
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4208549
* @summary Makes sure preferred size returned by layout managers used by
* JSplitPane is correct.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual PreferredSizeLayoutTest
*/
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
public class PreferredSizeLayoutTest {
static final String INSTRUCTIONS = """
If the buttons in the JSplitpanes do not have '...' in them,
click PASS, otherwise click FAIL.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("PreferredSizeLayoutTest Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(PreferredSizeLayoutTest::createUI)
.build()
.awaitAndCheck();
}
static JFrame createUI() {
JFrame f = new JFrame("Preferred Size Layout Test");
Container parent = f.getContentPane();
JSplitPane sp = new JSplitPane();
parent.setLayout(new FlowLayout());
sp.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
parent.add(sp);
sp = new JSplitPane();
sp.setOrientation(JSplitPane.VERTICAL_SPLIT);
parent.add(sp);
f.setSize(400, 300);
return f;
}
}