Skip to content

Commit 317788f

Browse files
author
Damon Nguyen
committed
8360160: ubuntu-22-04 machine is failing client tests
Reviewed-by: prr, azvegint
1 parent 6aeabd4 commit 317788f

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

test/jdk/java/awt/Frame/FrameVisualTest.java

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,62 +46,71 @@
4646
public class FrameVisualTest {
4747
private static GraphicsConfiguration[] gcs;
4848
private static volatile Frame[] frames;
49-
private static volatile int index;
5049

51-
private static Frame f;
5250
private static Robot robot;
51+
private static volatile int frameNum;
5352
private static volatile Point p;
5453
private static volatile Dimension d;
5554
private static final int TOLERANCE = 5;
55+
private static final int MAX_FRAME_COUNT = 30;
5656

5757
public static void main(String[] args) throws Exception {
58-
gcs = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getConfigurations();
58+
gcs = GraphicsEnvironment.getLocalGraphicsEnvironment()
59+
.getDefaultScreenDevice().getConfigurations();
5960
robot = new Robot();
6061
robot.setAutoDelay(100);
61-
try {
62-
EventQueue.invokeAndWait(() -> {
63-
createAndShowUI();
64-
});
65-
robot.delay(1000);
66-
System.out.println("frames.length: "+frames.length);
67-
for (index = 0; index < frames.length; index++) {
62+
63+
// Limit the number of frames tested if needed
64+
if (gcs.length > MAX_FRAME_COUNT) {
65+
frames = new Frame[MAX_FRAME_COUNT];
66+
} else {
67+
frames = new Frame[gcs.length];
68+
}
69+
System.out.println(gcs.length + " gcs found. Testing "
70+
+ frames.length + " frame(s).");
71+
72+
for (frameNum = 0; frameNum < frames.length; frameNum++) {
73+
try {
74+
EventQueue.invokeAndWait(() -> {
75+
frames[frameNum] = new Frame("Frame w/ gc "
76+
+ frameNum, gcs[frameNum]);
77+
frames[frameNum].setSize(100, 100);
78+
frames[frameNum].setUndecorated(true);
79+
frames[frameNum].setBackground(Color.WHITE);
80+
frames[frameNum].setVisible(true);
81+
System.out.println("Frame " + frameNum + " created");
82+
});
83+
84+
robot.delay(1000);
85+
6886
EventQueue.invokeAndWait(() -> {
69-
p = frames[index].getLocation();
70-
d = frames[index].getSize();
87+
p = frames[frameNum].getLocation();
88+
d = frames[frameNum].getSize();
7189
});
90+
7291
Rectangle rect = new Rectangle(p, d);
7392
BufferedImage img = robot.createScreenCapture(rect);
7493
if (chkImgBackgroundColor(img)) {
7594
try {
76-
ImageIO.write(img, "png", new File("Frame_" + index + ".png"));
95+
ImageIO.write(img, "png",
96+
new File("Frame_"
97+
+ frameNum + ".png"));
7798
} catch (IOException ignored) {}
78-
throw new RuntimeException("Frame visual test failed with non-white background color");
99+
throw new RuntimeException("Frame visual test " +
100+
"failed with non-white background color");
79101
}
80-
}
81-
} finally {
82-
for (index = 0; index < frames.length; index++) {
102+
} finally {
83103
EventQueue.invokeAndWait(() -> {
84-
if (frames[index] != null) {
85-
frames[index].dispose();
104+
if (frames[frameNum] != null) {
105+
frames[frameNum].dispose();
106+
System.out.println("Frame " + frameNum + " disposed");
86107
}
87108
});
88109
}
89110
}
90111
}
91112

92-
private static void createAndShowUI() {
93-
frames = new Frame[gcs.length];
94-
for (int i = 0; i < frames.length; i++) {
95-
frames[i] = new Frame("Frame w/ gc " + i, gcs[i]);
96-
frames[i].setSize(100, 100);
97-
frames[i].setUndecorated(true);
98-
frames[i].setBackground(Color.WHITE);
99-
frames[i].setVisible(true);
100-
}
101-
}
102-
103113
private static boolean chkImgBackgroundColor(BufferedImage img) {
104-
105114
// scan for mid-line and if it is non-white color then return true.
106115
for (int x = 1; x < img.getWidth() - 1; ++x) {
107116
Color c = new Color(img.getRGB(x, img.getHeight() / 2));

0 commit comments

Comments
 (0)