8339883: Open source several AWT/2D related tests
Reviewed-by: psadhukhan, honkar
This commit is contained in:
parent
858b4f127a
commit
b26645f64b
124
test/jdk/java/awt/GraphicsConfiguration/NonDefaultGC.java
Normal file
124
test/jdk/java/awt/GraphicsConfiguration/NonDefaultGC.java
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2024, 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 4131642
|
||||
* @summary This test shows the ability to create Frames, Windows
|
||||
* and Canvases with a GraphicsConfiguration. The test should show a number
|
||||
* of windows with RGB stripes in according to the number of the
|
||||
* GraphicsConfigurations for each screen. It also displays the size of
|
||||
* the screen and the GraphicsConfiguration.toString().
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual NonDefaultGC
|
||||
*/
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class NonDefaultGC {
|
||||
|
||||
private static final String INSTRUCTIONS = """
|
||||
This test shows the ability to create Frames, Windows and Canvases
|
||||
with a GraphicsConfiguration.
|
||||
The test should show a number of windows with RGB stripes according
|
||||
to the number of the GraphicsConfigurations for each screen.
|
||||
The window also contains text which displays the size of the screen
|
||||
and the output GraphicsConfiguration.toString().
|
||||
The test passes if every screen displays at least one such window.
|
||||
""";
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
SwingUtilities.invokeAndWait(NonDefaultGC::createUI);
|
||||
PassFailJFrame.builder()
|
||||
.title("GraphicsConfigurationTest")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.testTimeOut(5)
|
||||
.rows(12)
|
||||
.columns(45)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
|
||||
}
|
||||
|
||||
private static void createUI() {
|
||||
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.
|
||||
getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] gs = ge.getScreenDevices();
|
||||
for (int j = 0; j < gs.length; j++) {
|
||||
GraphicsDevice gd = gs[j];
|
||||
GraphicsConfiguration[] gc = gd.getConfigurations();
|
||||
for (int i=0; i < gc.length; i++) {
|
||||
JFrame f = new JFrame(gs[j].getDefaultConfiguration());
|
||||
PassFailJFrame.addTestWindow(f); // to ensure it is disposed.
|
||||
GCCanvas c = new GCCanvas(gc[i]);
|
||||
Rectangle gcBounds = gc[i].getBounds();
|
||||
int xoffs = gcBounds.x;
|
||||
int yoffs = gcBounds.y;
|
||||
f.getContentPane().add(c);
|
||||
f.setTitle("Screen# "+ j +", GC# "+ i);
|
||||
f.setSize(300, 150);
|
||||
f.setLocation((i*50)+xoffs, (i*60)+yoffs);
|
||||
f.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GCCanvas extends Canvas {
|
||||
|
||||
GraphicsConfiguration gc;
|
||||
Rectangle bounds;
|
||||
|
||||
public GCCanvas(GraphicsConfiguration gc) {
|
||||
super(gc);
|
||||
this.gc = gc;
|
||||
bounds = gc.getBounds();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(300, 150);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0, 0, 100, 150);
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(100, 0, 100, 150);
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(200, 0, 100, 150);
|
||||
g.setColor(Color.black);
|
||||
g.drawString("ScreenSize="+bounds.width+"X"+ bounds.height, 10, 15);
|
||||
g.drawString(gc.toString(), 10, 30);
|
||||
}
|
||||
}
|
94
test/jdk/java/awt/GraphicsConfiguration/Position.java
Normal file
94
test/jdk/java/awt/GraphicsConfiguration/Position.java
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2024, 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 4271200
|
||||
* @summary This test should show that the default position of a Frame
|
||||
* should be on the physical screen for the GraphicsConfiguration.
|
||||
* The togglebutton shows and hides an empty frame on the second monitor.
|
||||
* The frame should be positioned at 0, 0 and is shown and hidden by clicking the button.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual Position
|
||||
*/
|
||||
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Position extends JPanel implements ActionListener {
|
||||
|
||||
static final String INSTRUCTIONS = """
|
||||
This test should show that the default position of a Frame
|
||||
should be on the physical screen for the specified GraphicsConfiguration.
|
||||
There is a window "Show/Hide" button.
|
||||
The button alternatively shows and hides an empty frame on the second monitor.
|
||||
The frame should be positioned at 0, 0 and is shown and hidden by clicking the button.
|
||||
The test passes if it behaves as described and fails otherwise.
|
||||
""";
|
||||
|
||||
static volatile GraphicsDevice gd[];
|
||||
static volatile JFrame secondFrame;
|
||||
static volatile boolean on = true;
|
||||
|
||||
public Position() {
|
||||
JPanel p = new JPanel();
|
||||
JButton b = new JButton("Show/Hide Window on other screen");
|
||||
b.addActionListener(this);
|
||||
p.add(b);
|
||||
add(p);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (secondFrame == null) {
|
||||
secondFrame = new JFrame("screen1", gd[1].getDefaultConfiguration());
|
||||
secondFrame.setSize(500, 500);
|
||||
PassFailJFrame.addTestWindow(secondFrame);
|
||||
}
|
||||
secondFrame.setVisible(on);
|
||||
on = !on;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
|
||||
if (gd.length < 2) { /* test runs only on a multi-screen environment */
|
||||
return;
|
||||
}
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Screen Device Position Test")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.testTimeOut(5)
|
||||
.rows(10)
|
||||
.columns(50)
|
||||
.splitUIBottom(Position::new)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
97
test/jdk/sun/java2d/pipe/DrawImageBgTest.java
Normal file
97
test/jdk/sun/java2d/pipe/DrawImageBgTest.java
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2024, 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 4532352
|
||||
* @summary This test verifies that the specified background color is rendered
|
||||
* in the special case of:
|
||||
* Graphics.drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
|
||||
* int sx1, int sy1, int sx2, int sy2,
|
||||
* Color bgColor, ImageObserver observer)
|
||||
* where no scaling takes place because the source and destination
|
||||
* bounds have the same width and height.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DrawImageBgTest {
|
||||
|
||||
public static void main(String argv[]) throws Exception {
|
||||
|
||||
int dx, dy, dw, dh;
|
||||
int sx, sy, sw, sh;
|
||||
|
||||
int iw = 250, ih = 250;
|
||||
String sep = System.getProperty("file.separator");
|
||||
String dir = System.getProperty("test.src", ".");
|
||||
String prefix = dir+sep;
|
||||
BufferedImage img = ImageIO.read(new File(prefix + "duke.gif"));
|
||||
BufferedImage dest = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D g = dest.createGraphics();
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(0, 0, iw, ih);
|
||||
|
||||
// source and destination dimensions are different, results in scaling
|
||||
dx = 10;
|
||||
dy = 10;
|
||||
dw = 100;
|
||||
dh = 200;
|
||||
sx = 10;
|
||||
sy = 10;
|
||||
sw = 50;
|
||||
sh = 100;
|
||||
g.drawImage(img,
|
||||
dx, dy, dx + dw, dy + dh,
|
||||
sx, sy, sx + sw, sy + sh,
|
||||
Color.yellow, null);
|
||||
|
||||
int pix1 = dest.getRGB(dx + 1, dy + 1);
|
||||
|
||||
// source and destination dimensions are the same, no scaling
|
||||
dx = 120;
|
||||
dy = 10;
|
||||
sx = 10;
|
||||
sy = 10;
|
||||
sw = dw = 50;
|
||||
sh = dh = 100;
|
||||
g.drawImage(img,
|
||||
dx, dy, dx + dw, dy + dh,
|
||||
sx, sy, sx + sw, sy + sh,
|
||||
Color.yellow, null);
|
||||
|
||||
int pix2 = dest.getRGB(dx + 1, dy + 1);
|
||||
int yellow = Color.yellow.getRGB();
|
||||
|
||||
if (pix1 != yellow || pix2 != yellow) {
|
||||
ImageIO.write(dest, "gif", new File("op.gif"));
|
||||
throw new RuntimeException("pix1=" + Integer.toHexString(pix1) +
|
||||
" pix2=" + Integer.toHexString(pix2));
|
||||
}
|
||||
}
|
||||
}
|
BIN
test/jdk/sun/java2d/pipe/duke.gif
Normal file
BIN
test/jdk/sun/java2d/pipe/duke.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in New Issue
Block a user