Skip to content

Commit ad76205

Browse files
committed
8353470: Clean up and open source couple AWT Graphics related tests (Part 2)
Clean up and open source four more tests problem listing one for known issues on linux and macos.
1 parent a875733 commit ad76205

File tree

5 files changed

+606
-0
lines changed

5 files changed

+606
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ java/awt/Focus/TestDisabledAutoTransfer.java 8159871 macosx-all,windows-all
143143
java/awt/Focus/TestDisabledAutoTransferSwing.java 6962362 windows-all
144144
java/awt/Focus/ActivateOnProperAppContextTest.java 8136516 macosx-all
145145
java/awt/Focus/FocusPolicyTest.java 7160904 linux-all
146+
java/awt/Graphics/SmallPrimitives.java 8047070 macosx-all,linux-all
146147
java/awt/EventQueue/6980209/bug6980209.java 8198615 macosx-all
147148
java/awt/EventQueue/PushPopDeadlock/PushPopDeadlock.java 8024034 generic-all
148149
java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java 7080150 macosx-all
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
import javax.imageio.ImageIO;
25+
import java.awt.AWTException;
26+
import java.awt.Color;
27+
import java.awt.Dimension;
28+
import java.awt.EventQueue;
29+
import java.awt.Frame;
30+
import java.awt.Graphics;
31+
import java.awt.Insets;
32+
import java.awt.Label;
33+
import java.awt.Panel;
34+
import java.awt.Point;
35+
import java.awt.Rectangle;
36+
import java.awt.Robot;
37+
import java.awt.image.BufferedImage;
38+
import java.io.File;
39+
import java.io.IOException;
40+
import java.lang.reflect.InvocationTargetException;
41+
42+
/*
43+
* @test
44+
* @bug 4191297
45+
* @summary Tests that unreferenced GDI resources are correctly
46+
* destroyed when no longer needed.
47+
* @key headful
48+
* @run main GDIResourceExhaustionTest
49+
*/
50+
51+
public class GDIResourceExhaustionTest extends Frame {
52+
public void initUI() {
53+
setSize(200, 200);
54+
setUndecorated(true);
55+
setLocationRelativeTo(null);
56+
Panel labelPanel = new Panel();
57+
Label label = new Label("Red label");
58+
label.setBackground(Color.red);
59+
labelPanel.add(label);
60+
labelPanel.setLocation(20, 50);
61+
add(labelPanel);
62+
setVisible(true);
63+
}
64+
65+
public void paint(Graphics graphics) {
66+
super.paint(graphics);
67+
for (int rgb = 0; rgb <= 0xfff; rgb++) {
68+
graphics.setColor(new Color(rgb));
69+
graphics.fillRect(0, 0, 5, 5);
70+
}
71+
}
72+
73+
public void requestCoordinates(Rectangle r) {
74+
Insets insets = getInsets();
75+
Point location = getLocationOnScreen();
76+
Dimension size = getSize();
77+
r.x = location.x + insets.left;
78+
r.y = location.y + insets.top;
79+
r.width = size.width - (insets.left + insets.right);
80+
r.height = size.height - (insets.top + insets.bottom);
81+
}
82+
83+
public static void main(String[] args) throws InterruptedException,
84+
InvocationTargetException, AWTException, IOException {
85+
GDIResourceExhaustionTest test = new GDIResourceExhaustionTest();
86+
try {
87+
EventQueue.invokeAndWait(test::initUI);
88+
Robot robot = new Robot();
89+
robot.delay(2000);
90+
Rectangle coords = new Rectangle();
91+
EventQueue.invokeAndWait(() -> {
92+
test.requestCoordinates(coords);
93+
});
94+
robot.mouseMove(coords.x - 50, coords.y - 50);
95+
robot.waitForIdle();
96+
robot.delay(5000);
97+
BufferedImage capture = robot.createScreenCapture(coords);
98+
robot.delay(500);
99+
boolean redFound = false;
100+
int redRGB = Color.red.getRGB();
101+
for (int y = 0; y < capture.getHeight(); y++) {
102+
for (int x = 0; x < capture.getWidth(); x++) {
103+
if (capture.getRGB(x, y) == redRGB) {
104+
redFound = true;
105+
break;
106+
}
107+
if (redFound) {
108+
break;
109+
}
110+
}
111+
}
112+
if (!redFound) {
113+
File errorImage = new File("screenshot.png");
114+
ImageIO.write(capture, "png", errorImage);
115+
throw new RuntimeException("Red label is not detected, possibly GDI resources exhausted");
116+
}
117+
} finally {
118+
EventQueue.invokeAndWait(test::dispose);
119+
}
120+
}
121+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright (c) 1998, 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+
import java.awt.Color;
25+
import java.awt.Dimension;
26+
import java.awt.Font;
27+
import java.awt.FontMetrics;
28+
import java.awt.Frame;
29+
import java.awt.Graphics;
30+
import java.awt.Image;
31+
import java.awt.image.BufferedImage;
32+
import java.lang.reflect.InvocationTargetException;
33+
34+
/*
35+
* @test
36+
* @bug 4081126 4129709
37+
* @summary Test for proper repainting on multiprocessor systems.
38+
* @library /java/awt/regtesthelpers
39+
* @build PassFailJFrame
40+
* @run main/manual RepeatedRepaintTest
41+
*/
42+
public class RepeatedRepaintTest extends Frame {
43+
private Font font = null;
44+
private Image background;
45+
46+
static String INSTRUCTIONS = """
47+
The frame next to this window called "AWT Draw Test" has
48+
some elements drawn on it. Move this window partially outside of the
49+
screen bounds and then drag it back. Repeat it couple of times.
50+
Drag the instructions window over the frame partially obscuring it.
51+
If after number of attempts the frame content stops repainting
52+
press "Fail", otherwise press "Pass".
53+
""";
54+
55+
public RepeatedRepaintTest() {
56+
setTitle("AWT Draw Test");
57+
setSize(300, 300);
58+
background = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
59+
Graphics g = background.getGraphics();
60+
g.setColor(Color.black);
61+
g.fillRect(0, 0, 300, 300);
62+
g.dispose();
63+
}
64+
65+
public void paint(Graphics g) {
66+
Dimension dim = this.getSize();
67+
super.paint(g);
68+
g.drawImage(background, 0, 0, dim.width, dim.height, null);
69+
g.setColor(Color.white);
70+
if (font == null) {
71+
font = new Font("SansSerif", Font.PLAIN, 24);
72+
}
73+
g.setFont(font);
74+
FontMetrics metrics = g.getFontMetrics();
75+
String message = "Draw Test";
76+
g.drawString(message, (dim.width / 2) - (metrics.stringWidth(message) / 2),
77+
(dim.height / 2) + (metrics.getHeight() / 2));
78+
79+
int counter = 50;
80+
for (int i = 0; i < 50; i++) {
81+
counter += 4;
82+
g.drawOval(counter, 50, i, i);
83+
}
84+
85+
counter = 20;
86+
for (int i = 0; i < 100; i++) {
87+
counter += 4;
88+
g.drawOval(counter, 150, i, i);
89+
}
90+
g.setColor(Color.black);
91+
g.drawLine(0, dim.height - 25, dim.width, dim.height - 25);
92+
g.setColor(Color.gray);
93+
g.drawLine(0, dim.height - 24, dim.width, dim.height - 24);
94+
g.setColor(Color.lightGray);
95+
g.drawLine(0, dim.height - 23, dim.width, dim.height - 23);
96+
g.fillRect(0, dim.height - 22, dim.width, dim.height);
97+
98+
99+
g.setXORMode(Color.blue);
100+
g.fillRect(0, 0, 25, dim.height - 26);
101+
g.setColor(Color.red);
102+
g.fillRect(0, 0, 25, dim.height - 26);
103+
g.setColor(Color.green);
104+
g.fillRect(0, 0, 25, dim.height - 26);
105+
g.setPaintMode();
106+
107+
Image img = createImage(50, 50);
108+
Graphics imgGraphics = img.getGraphics();
109+
imgGraphics.setColor(Color.magenta);
110+
imgGraphics.fillRect(0, 0, 50, 50);
111+
imgGraphics.setColor(Color.yellow);
112+
imgGraphics.drawString("offscreen", 0, 20);
113+
imgGraphics.drawString("image", 0, 30);
114+
115+
g.drawImage(img, dim.width - 100, dim.height - 100, Color.blue, null);
116+
117+
g.setXORMode(Color.white);
118+
drawAt(g, 100, 100, 50, 50);
119+
drawAt(g, 105, 105, 50, 50);
120+
drawAt(g, 110, 110, 50, 50);
121+
}
122+
123+
public void drawAt(Graphics g, int x, int y, int width, int height) {
124+
g.setColor(Color.magenta);
125+
g.fillRect(x, y, width, height);
126+
}
127+
128+
public static void main(String[] args) throws InterruptedException,
129+
InvocationTargetException {
130+
PassFailJFrame.builder()
131+
.title("Repeated Repaint Test Instructions")
132+
.instructions(INSTRUCTIONS)
133+
.testUI(RepeatedRepaintTest::new)
134+
.build()
135+
.awaitAndCheck();
136+
}
137+
}

0 commit comments

Comments
 (0)