Skip to content

Commit 79d7613

Browse files
author
Tejesh R
committedSep 9, 2024
8338153: java/awt/Checkbox/CheckboxCheckerScalingTest.java test failed on linux machine
Reviewed-by: abhiscxk, honkar
1 parent f0e84b7 commit 79d7613

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed
 

‎test/jdk/java/awt/Checkbox/CheckboxCheckerScalingTest.java

+26-13
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,47 @@
4646
public class CheckboxCheckerScalingTest {
4747
private static Frame frame;
4848
private static Checkbox checkbox;
49-
private static BufferedImage imageAfterChecked;
50-
private static volatile boolean checkmarkFound = false;
49+
private static volatile Point point;
50+
private static boolean checkmarkFound = false;
51+
private static final int TOLERANCE = 5;
52+
private static final int COLOR_CHECK_THRESHOLD = 8;
53+
private static int colorCounter = 0;
5154

5255
public static void main(String[] args) throws Exception {
5356
System.setProperty("sun.java2d.uiScale", "2");
5457
Robot robot = new Robot();
58+
5559
try {
5660
EventQueue.invokeAndWait(() -> {
57-
frame = new Frame("ComboBox checker scaling test");
61+
frame = new Frame("CheckBox checker scaling test");
5862
checkbox = new Checkbox("one");
5963
checkbox.setState(true);
6064
frame.add(checkbox);
65+
frame.setLocationRelativeTo(null);
6166
frame.pack();
6267
frame.setVisible(true);
6368
});
6469

6570
robot.waitForIdle();
6671
robot.delay(100);
67-
EventQueue.invokeAndWait(() -> {
68-
Point point = checkbox.getLocationOnScreen();
69-
Rectangle rect = new Rectangle(point.x + 5, point.y + 7, 8, 8);
70-
imageAfterChecked = robot.createScreenCapture(rect);
71-
72-
check: {
73-
for (int i = 0; i < imageAfterChecked.getHeight(); i++) {
74-
for (int j = 0; j < imageAfterChecked.getWidth(); j++) {
75-
if (Color.black.getRGB() == imageAfterChecked.getRGB(i, j)) {
72+
EventQueue.invokeAndWait(() -> point = checkbox.getLocationOnScreen());
73+
Rectangle rect = new Rectangle(point.x + 5, point.y + 7, 8, 8);
74+
BufferedImage imageAfterChecked = robot.createScreenCapture(rect);
75+
check:
76+
{
77+
for (int i = 0; i < imageAfterChecked.getHeight(); i++) {
78+
for (int j = 0; j < imageAfterChecked.getWidth(); j++) {
79+
Color pixelColor = new Color(imageAfterChecked.getRGB(i, j));
80+
if (compareColor(pixelColor)) {
81+
if (++colorCounter >= COLOR_CHECK_THRESHOLD) {
7682
checkmarkFound = true;
7783
break check;
7884
}
7985
}
86+
8087
}
8188
}
82-
});
89+
}
8390

8491
if (!checkmarkFound) {
8592
try {
@@ -99,4 +106,10 @@ public static void main(String[] args) throws Exception {
99106
});
100107
}
101108
}
109+
110+
private static boolean compareColor(Color c) {
111+
return Math.abs(Color.black.getRed() - c.getRed()) < TOLERANCE &&
112+
Math.abs(Color.black.getGreen() - c.getGreen()) < TOLERANCE &&
113+
Math.abs(Color.black.getBlue() - c.getBlue()) < TOLERANCE;
114+
}
102115
}

0 commit comments

Comments
 (0)