8320113: [macos14] : ShapeNotSetSometimes.java fails intermittently on macOS 14

Reviewed-by: dnguyen, azvegint, kizune
This commit is contained in:
Harshitha Onkar
2024-01-19 21:42:34 +00:00
parent 8700de66e4
commit f1b73350c2

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,45 +21,50 @@
* questions.
*/
/*
@test
@key headful
@bug 6988428
@summary Tests whether shape is always set
@author anthony.petrov@oracle.com: area=awt.toplevel
@run main ShapeNotSetSometimes
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/*
* @test
* @key headful
* @bug 6988428
* @summary Tests whether shape is always set
* @run main ShapeNotSetSometimes
*/
public class ShapeNotSetSometimes {
private Frame backgroundFrame;
private Frame window;
private static final Color BACKGROUND_COLOR = Color.GREEN;
private static final Color SHAPE_COLOR = Color.WHITE;
private Point[] pointsOutsideToCheck;
private Point[] shadedPointsToCheck;
private Point innerPoint;
private final Rectangle bounds = new Rectangle(220, 400, 300, 300);
private static Robot robot;
private static final Color BACKGROUND_COLOR = Color.GREEN;
private static final Color SHAPE_COLOR = Color.WHITE;
public ShapeNotSetSometimes() throws Exception {
EventQueue.invokeAndWait(this::initializeGUI);
robot.waitForIdle();
robot.delay(1000);
}
private void initializeGUI() {
@@ -124,7 +129,7 @@ public class ShapeNotSetSometimes {
public static void main(String[] args) throws Exception {
robot = new Robot();
for(int i = 0; i < 50; i++) {
for (int i = 1; i <= 50; i++) {
System.out.println("Attempt " + i);
new ShapeNotSetSometimes().doTest();
}
@@ -136,7 +141,6 @@ public class ShapeNotSetSometimes {
EventQueue.invokeAndWait(window::toFront);
robot.waitForIdle();
robot.delay(500);
try {
@@ -173,8 +177,8 @@ public class ShapeNotSetSometimes {
);
if (mustBeExpectedColor != expectedColor.equals(actualColor)) {
captureScreen();
System.out.printf("window.getX() = %3d, window.getY() = %3d\n", window.getX(), window.getY());
System.err.printf(
"Checking for transparency failed: point: %3d, %3d\n\tactual %s\n\texpected %s%s\n",
screenX,
@@ -185,4 +189,18 @@ public class ShapeNotSetSometimes {
throw new RuntimeException("Test failed. The shape has not been applied.");
}
}
private static void captureScreen() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenBounds = new Rectangle(0, 0, screenSize.width, screenSize.height);
try {
ImageIO.write(
robot.createScreenCapture(screenBounds),
"png",
new File("Screenshot.png")
);
} catch (IOException e) {
e.printStackTrace();
}
}
}