From 79d761358c5ee19b9028ad89d7c6a33dff6aa64a Mon Sep 17 00:00:00 2001
From: Tejesh R
Date: Mon, 9 Sep 2024 05:17:09 +0000
Subject: [PATCH] 8338153: java/awt/Checkbox/CheckboxCheckerScalingTest.java
test failed on linux machine
Reviewed-by: abhiscxk, honkar
---
.../Checkbox/CheckboxCheckerScalingTest.java | 39 ++++++++++++-------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/test/jdk/java/awt/Checkbox/CheckboxCheckerScalingTest.java b/test/jdk/java/awt/Checkbox/CheckboxCheckerScalingTest.java
index a07620dbd38..f2ceba47d0d 100644
--- a/test/jdk/java/awt/Checkbox/CheckboxCheckerScalingTest.java
+++ b/test/jdk/java/awt/Checkbox/CheckboxCheckerScalingTest.java
@@ -46,40 +46,47 @@ import javax.imageio.ImageIO;
public class CheckboxCheckerScalingTest {
private static Frame frame;
private static Checkbox checkbox;
- private static BufferedImage imageAfterChecked;
- private static volatile boolean checkmarkFound = false;
+ private static volatile Point point;
+ private static boolean checkmarkFound = false;
+ private static final int TOLERANCE = 5;
+ private static final int COLOR_CHECK_THRESHOLD = 8;
+ private static int colorCounter = 0;
public static void main(String[] args) throws Exception {
System.setProperty("sun.java2d.uiScale", "2");
Robot robot = new Robot();
+
try {
EventQueue.invokeAndWait(() -> {
- frame = new Frame("ComboBox checker scaling test");
+ frame = new Frame("CheckBox checker scaling test");
checkbox = new Checkbox("one");
checkbox.setState(true);
frame.add(checkbox);
+ frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(100);
- EventQueue.invokeAndWait(() -> {
- Point point = checkbox.getLocationOnScreen();
- Rectangle rect = new Rectangle(point.x + 5, point.y + 7, 8, 8);
- imageAfterChecked = robot.createScreenCapture(rect);
-
- check: {
- for (int i = 0; i < imageAfterChecked.getHeight(); i++) {
- for (int j = 0; j < imageAfterChecked.getWidth(); j++) {
- if (Color.black.getRGB() == imageAfterChecked.getRGB(i, j)) {
+ EventQueue.invokeAndWait(() -> point = checkbox.getLocationOnScreen());
+ Rectangle rect = new Rectangle(point.x + 5, point.y + 7, 8, 8);
+ BufferedImage imageAfterChecked = robot.createScreenCapture(rect);
+ check:
+ {
+ for (int i = 0; i < imageAfterChecked.getHeight(); i++) {
+ for (int j = 0; j < imageAfterChecked.getWidth(); j++) {
+ Color pixelColor = new Color(imageAfterChecked.getRGB(i, j));
+ if (compareColor(pixelColor)) {
+ if (++colorCounter >= COLOR_CHECK_THRESHOLD) {
checkmarkFound = true;
break check;
}
}
+
}
}
- });
+ }
if (!checkmarkFound) {
try {
@@ -99,4 +106,10 @@ public class CheckboxCheckerScalingTest {
});
}
}
+
+ private static boolean compareColor(Color c) {
+ return Math.abs(Color.black.getRed() - c.getRed()) < TOLERANCE &&
+ Math.abs(Color.black.getGreen() - c.getGreen()) < TOLERANCE &&
+ Math.abs(Color.black.getBlue() - c.getBlue()) < TOLERANCE;
+ }
}