8324238: [macOS] java/awt/Frame/ShapeNotSetSometimes/ShapeNotSetSometimes.java fails with the shape has not been applied msg

Reviewed-by: azvegint, dnguyen
This commit is contained in:
Harshitha Onkar 2024-01-31 17:42:00 +00:00
parent 1f2922ad85
commit 62c9530c05

@ -21,8 +21,6 @@
* questions.
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
@ -44,7 +42,7 @@ import javax.imageio.ImageIO;
* @key headful
* @bug 6988428
* @summary Tests whether shape is always set
* @run main ShapeNotSetSometimes
* @run main/othervm -Dsun.java2d.uiScale=1 ShapeNotSetSometimes
*/
public class ShapeNotSetSometimes {
@ -55,22 +53,24 @@ public class ShapeNotSetSometimes {
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;
private static final int DIM = 300;
private static final int DELTA = 2;
public ShapeNotSetSometimes() throws Exception {
EventQueue.invokeAndWait(this::initializeGUI);
robot.waitForIdle();
robot.delay(1000);
robot.delay(500);
}
private void initializeGUI() {
backgroundFrame = new BackgroundFrame();
backgroundFrame.setUndecorated(true);
backgroundFrame.setBounds(bounds);
backgroundFrame.setSize(DIM, DIM);
backgroundFrame.setLocationRelativeTo(null);
backgroundFrame.setVisible(true);
Area area = new Area();
@ -81,8 +81,10 @@ public class ShapeNotSetSometimes {
area.add(new Area(new Ellipse2D.Float(150, 50, 100, 100)));
area.add(new Area(new Ellipse2D.Float(150, 100, 100, 100)));
// point at the center of white ellipse
innerPoint = new Point(150, 130);
// mid points on the 4 sides - on the green background frame
pointsOutsideToCheck = new Point[] {
new Point(150, 20),
new Point(280, 120),
@ -90,6 +92,7 @@ public class ShapeNotSetSometimes {
new Point(20, 120)
};
// points just outside the ellipse (opposite side of diagonal)
shadedPointsToCheck = new Point[] {
new Point(62, 62),
new Point(240, 185)
@ -97,7 +100,8 @@ public class ShapeNotSetSometimes {
window = new TestFrame();
window.setUndecorated(true);
window.setBounds(bounds);
window.setSize(DIM, DIM);
window.setLocationRelativeTo(null);
window.setShape(area);
window.setVisible(true);
}
@ -108,7 +112,7 @@ public class ShapeNotSetSometimes {
public void paint(Graphics g) {
g.setColor(BACKGROUND_COLOR);
g.fillRect(0, 0, 300, 300);
g.fillRect(0, 0, DIM, DIM);
super.paint(g);
}
@ -120,7 +124,7 @@ public class ShapeNotSetSometimes {
public void paint(Graphics g) {
g.setColor(SHAPE_COLOR);
g.fillRect(0, 0, bounds.width, bounds.height);
g.fillRect(0, 0, DIM, DIM);
super.paint(g);
}
@ -155,17 +159,24 @@ public class ShapeNotSetSometimes {
}
} finally {
EventQueue.invokeAndWait(() -> {
backgroundFrame.dispose();
window.dispose();
if (backgroundFrame != null) {
backgroundFrame.dispose();
}
if (window != null) {
window.dispose();
}
});
}
}
private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpectedColor) {
int screenX = window.getX() + x;
int screenY = window.getY() + y;
robot.mouseMove(screenX, screenY);
robot.waitForIdle();
robot.delay(50);
Color actualColor = robot.getPixelColor(screenX, screenY);
System.out.printf(
@ -176,7 +187,7 @@ public class ShapeNotSetSometimes {
expectedColor
);
if (mustBeExpectedColor != expectedColor.equals(actualColor)) {
if (mustBeExpectedColor != colorCompare(expectedColor, actualColor)) {
captureScreen();
System.out.printf("window.getX() = %3d, window.getY() = %3d\n", window.getX(), window.getY());
System.err.printf(
@ -190,6 +201,15 @@ public class ShapeNotSetSometimes {
}
}
private static boolean colorCompare(Color expected, Color actual) {
if (Math.abs(expected.getRed() - actual.getRed()) <= DELTA
&& Math.abs(expected.getGreen() - actual.getGreen()) <= DELTA
&& Math.abs(expected.getBlue() - actual.getBlue()) <= DELTA) {
return true;
}
return false;
}
private static void captureScreen() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenBounds = new Rectangle(0, 0, screenSize.width, screenSize.height);