Skip to content

Commit 6ef13ab

Browse files
committed
8339883: Open source several AWT/2D related tests
Backport-of: b26645f64bb6dd3efafaceb92bedeaf8f93906e3
1 parent 743724e commit 6ef13ab

File tree

4 files changed

+315
-0
lines changed

4 files changed

+315
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright (c) 2002, 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+
/*
25+
* @test
26+
* @bug 4131642
27+
* @summary This test shows the ability to create Frames, Windows
28+
* and Canvases with a GraphicsConfiguration. The test should show a number
29+
* of windows with RGB stripes in according to the number of the
30+
* GraphicsConfigurations for each screen. It also displays the size of
31+
* the screen and the GraphicsConfiguration.toString().
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @run main/manual NonDefaultGC
35+
*/
36+
37+
import java.awt.Canvas;
38+
import java.awt.Color;
39+
import java.awt.Dimension;
40+
import java.awt.Graphics;
41+
import java.awt.GraphicsConfiguration;
42+
import java.awt.GraphicsDevice;
43+
import java.awt.GraphicsEnvironment;
44+
import java.awt.Rectangle;
45+
import javax.swing.JFrame;
46+
import javax.swing.SwingUtilities;
47+
48+
public class NonDefaultGC {
49+
50+
private static final String INSTRUCTIONS = """
51+
This test shows the ability to create Frames, Windows and Canvases
52+
with a GraphicsConfiguration.
53+
The test should show a number of windows with RGB stripes according
54+
to the number of the GraphicsConfigurations for each screen.
55+
The window also contains text which displays the size of the screen
56+
and the output GraphicsConfiguration.toString().
57+
The test passes if every screen displays at least one such window.
58+
""";
59+
60+
public static void main(String[] argv) throws Exception {
61+
SwingUtilities.invokeAndWait(NonDefaultGC::createUI);
62+
PassFailJFrame.builder()
63+
.title("GraphicsConfigurationTest")
64+
.instructions(INSTRUCTIONS)
65+
.testTimeOut(5)
66+
.rows(12)
67+
.columns(45)
68+
.build()
69+
.awaitAndCheck();
70+
71+
}
72+
73+
private static void createUI() {
74+
75+
GraphicsEnvironment ge = GraphicsEnvironment.
76+
getLocalGraphicsEnvironment();
77+
GraphicsDevice[] gs = ge.getScreenDevices();
78+
for (int j = 0; j < gs.length; j++) {
79+
GraphicsDevice gd = gs[j];
80+
GraphicsConfiguration[] gc = gd.getConfigurations();
81+
for (int i=0; i < gc.length; i++) {
82+
JFrame f = new JFrame(gs[j].getDefaultConfiguration());
83+
PassFailJFrame.addTestWindow(f); // to ensure it is disposed.
84+
GCCanvas c = new GCCanvas(gc[i]);
85+
Rectangle gcBounds = gc[i].getBounds();
86+
int xoffs = gcBounds.x;
87+
int yoffs = gcBounds.y;
88+
f.getContentPane().add(c);
89+
f.setTitle("Screen# "+ j +", GC# "+ i);
90+
f.setSize(300, 150);
91+
f.setLocation((i*50)+xoffs, (i*60)+yoffs);
92+
f.show();
93+
}
94+
}
95+
}
96+
}
97+
98+
class GCCanvas extends Canvas {
99+
100+
GraphicsConfiguration gc;
101+
Rectangle bounds;
102+
103+
public GCCanvas(GraphicsConfiguration gc) {
104+
super(gc);
105+
this.gc = gc;
106+
bounds = gc.getBounds();
107+
}
108+
109+
public Dimension getPreferredSize() {
110+
return new Dimension(300, 150);
111+
}
112+
113+
public void paint(Graphics g) {
114+
g.setColor(Color.red);
115+
g.fillRect(0, 0, 100, 150);
116+
g.setColor(Color.green);
117+
g.fillRect(100, 0, 100, 150);
118+
g.setColor(Color.blue);
119+
g.fillRect(200, 0, 100, 150);
120+
g.setColor(Color.black);
121+
g.drawString("ScreenSize="+bounds.width+"X"+ bounds.height, 10, 15);
122+
g.drawString(gc.toString(), 10, 30);
123+
}
124+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
/*
25+
* @test
26+
* @bug 4271200
27+
* @summary This test should show that the default position of a Frame
28+
* should be on the physical screen for the GraphicsConfiguration.
29+
* The togglebutton shows and hides an empty frame on the second monitor.
30+
* The frame should be positioned at 0, 0 and is shown and hidden by clicking the button.
31+
* @library /java/awt/regtesthelpers
32+
* @build PassFailJFrame
33+
* @run main/manual Position
34+
*/
35+
36+
import java.awt.GraphicsDevice;
37+
import java.awt.GraphicsEnvironment;
38+
import java.awt.event.ActionEvent;
39+
import java.awt.event.ActionListener;
40+
import javax.swing.JButton;
41+
import javax.swing.JFrame;
42+
import javax.swing.JPanel;
43+
44+
public class Position extends JPanel implements ActionListener {
45+
46+
static final String INSTRUCTIONS = """
47+
This test should show that the default position of a Frame
48+
should be on the physical screen for the specified GraphicsConfiguration.
49+
There is a window "Show/Hide" button.
50+
The button alternatively shows and hides an empty frame on the second monitor.
51+
The frame should be positioned at 0, 0 and is shown and hidden by clicking the button.
52+
The test passes if it behaves as described and fails otherwise.
53+
""";
54+
55+
static volatile GraphicsDevice gd[];
56+
static volatile JFrame secondFrame;
57+
static volatile boolean on = true;
58+
59+
public Position() {
60+
JPanel p = new JPanel();
61+
JButton b = new JButton("Show/Hide Window on other screen");
62+
b.addActionListener(this);
63+
p.add(b);
64+
add(p);
65+
}
66+
67+
public void actionPerformed(ActionEvent e) {
68+
if (secondFrame == null) {
69+
secondFrame = new JFrame("screen1", gd[1].getDefaultConfiguration());
70+
secondFrame.setSize(500, 500);
71+
PassFailJFrame.addTestWindow(secondFrame);
72+
}
73+
secondFrame.setVisible(on);
74+
on = !on;
75+
}
76+
77+
public static void main(String[] args) throws Exception {
78+
79+
gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
80+
if (gd.length < 2) { /* test runs only on a multi-screen environment */
81+
return;
82+
}
83+
84+
PassFailJFrame.builder()
85+
.title("Screen Device Position Test")
86+
.instructions(INSTRUCTIONS)
87+
.testTimeOut(5)
88+
.rows(10)
89+
.columns(50)
90+
.splitUIBottom(Position::new)
91+
.build()
92+
.awaitAndCheck();
93+
}
94+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2002, 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+
/*
25+
* @test
26+
* @bug 4532352
27+
* @summary This test verifies that the specified background color is rendered
28+
* in the special case of:
29+
* Graphics.drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
30+
* int sx1, int sy1, int sx2, int sy2,
31+
* Color bgColor, ImageObserver observer)
32+
* where no scaling takes place because the source and destination
33+
* bounds have the same width and height.
34+
*/
35+
36+
import java.io.File;
37+
import java.awt.Color;
38+
import java.awt.Graphics2D;
39+
import java.awt.image.BufferedImage;
40+
import javax.imageio.ImageIO;
41+
42+
public class DrawImageBgTest {
43+
44+
public static void main(String argv[]) throws Exception {
45+
46+
int dx, dy, dw, dh;
47+
int sx, sy, sw, sh;
48+
49+
int iw = 250, ih = 250;
50+
String sep = System.getProperty("file.separator");
51+
String dir = System.getProperty("test.src", ".");
52+
String prefix = dir+sep;
53+
BufferedImage img = ImageIO.read(new File(prefix + "duke.gif"));
54+
BufferedImage dest = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
55+
56+
Graphics2D g = dest.createGraphics();
57+
g.setColor(Color.blue);
58+
g.fillRect(0, 0, iw, ih);
59+
60+
// source and destination dimensions are different, results in scaling
61+
dx = 10;
62+
dy = 10;
63+
dw = 100;
64+
dh = 200;
65+
sx = 10;
66+
sy = 10;
67+
sw = 50;
68+
sh = 100;
69+
g.drawImage(img,
70+
dx, dy, dx + dw, dy + dh,
71+
sx, sy, sx + sw, sy + sh,
72+
Color.yellow, null);
73+
74+
int pix1 = dest.getRGB(dx + 1, dy + 1);
75+
76+
// source and destination dimensions are the same, no scaling
77+
dx = 120;
78+
dy = 10;
79+
sx = 10;
80+
sy = 10;
81+
sw = dw = 50;
82+
sh = dh = 100;
83+
g.drawImage(img,
84+
dx, dy, dx + dw, dy + dh,
85+
sx, sy, sx + sw, sy + sh,
86+
Color.yellow, null);
87+
88+
int pix2 = dest.getRGB(dx + 1, dy + 1);
89+
int yellow = Color.yellow.getRGB();
90+
91+
if (pix1 != yellow || pix2 != yellow) {
92+
ImageIO.write(dest, "gif", new File("op.gif"));
93+
throw new RuntimeException("pix1=" + Integer.toHexString(pix1) +
94+
" pix2=" + Integer.toHexString(pix2));
95+
}
96+
}
97+
}

test/jdk/sun/java2d/pipe/duke.gif

1.88 KB
Loading

0 commit comments

Comments
 (0)