8338153: java/awt/Checkbox/CheckboxCheckerScalingTest.java test failed on linux machine
Reviewed-by: abhiscxk, honkar
This commit is contained in:
parent
f0e84b7617
commit
79d761358c
@ -46,40 +46,47 @@ import javax.imageio.ImageIO;
|
|||||||
public class CheckboxCheckerScalingTest {
|
public class CheckboxCheckerScalingTest {
|
||||||
private static Frame frame;
|
private static Frame frame;
|
||||||
private static Checkbox checkbox;
|
private static Checkbox checkbox;
|
||||||
private static BufferedImage imageAfterChecked;
|
private static volatile Point point;
|
||||||
private static volatile boolean checkmarkFound = false;
|
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 {
|
public static void main(String[] args) throws Exception {
|
||||||
System.setProperty("sun.java2d.uiScale", "2");
|
System.setProperty("sun.java2d.uiScale", "2");
|
||||||
Robot robot = new Robot();
|
Robot robot = new Robot();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EventQueue.invokeAndWait(() -> {
|
EventQueue.invokeAndWait(() -> {
|
||||||
frame = new Frame("ComboBox checker scaling test");
|
frame = new Frame("CheckBox checker scaling test");
|
||||||
checkbox = new Checkbox("one");
|
checkbox = new Checkbox("one");
|
||||||
checkbox.setState(true);
|
checkbox.setState(true);
|
||||||
frame.add(checkbox);
|
frame.add(checkbox);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
robot.waitForIdle();
|
robot.waitForIdle();
|
||||||
robot.delay(100);
|
robot.delay(100);
|
||||||
EventQueue.invokeAndWait(() -> {
|
EventQueue.invokeAndWait(() -> point = checkbox.getLocationOnScreen());
|
||||||
Point point = checkbox.getLocationOnScreen();
|
Rectangle rect = new Rectangle(point.x + 5, point.y + 7, 8, 8);
|
||||||
Rectangle rect = new Rectangle(point.x + 5, point.y + 7, 8, 8);
|
BufferedImage imageAfterChecked = robot.createScreenCapture(rect);
|
||||||
imageAfterChecked = robot.createScreenCapture(rect);
|
check:
|
||||||
|
{
|
||||||
check: {
|
for (int i = 0; i < imageAfterChecked.getHeight(); i++) {
|
||||||
for (int i = 0; i < imageAfterChecked.getHeight(); i++) {
|
for (int j = 0; j < imageAfterChecked.getWidth(); j++) {
|
||||||
for (int j = 0; j < imageAfterChecked.getWidth(); j++) {
|
Color pixelColor = new Color(imageAfterChecked.getRGB(i, j));
|
||||||
if (Color.black.getRGB() == imageAfterChecked.getRGB(i, j)) {
|
if (compareColor(pixelColor)) {
|
||||||
|
if (++colorCounter >= COLOR_CHECK_THRESHOLD) {
|
||||||
checkmarkFound = true;
|
checkmarkFound = true;
|
||||||
break check;
|
break check;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (!checkmarkFound) {
|
if (!checkmarkFound) {
|
||||||
try {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user