Skip to content

Commit

Permalink
8320113: [macos14] : ShapeNotSetSometimes.java fails intermittently o…
Browse files Browse the repository at this point in the history
…n macOS 14

Backport-of: f1b73350c237021c04ceac2f29f1f378630bd651
  • Loading branch information
Andrew Lu committed Mar 12, 2024
1 parent 7f5afa1 commit c8e9f1d
Showing 1 changed file with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -124,7 +129,7 @@ public void paint(Graphics g) {
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();
}
Expand All @@ -136,7 +141,6 @@ private void doTest() throws Exception {

EventQueue.invokeAndWait(window::toFront);
robot.waitForIdle();

robot.delay(500);

try {
Expand Down Expand Up @@ -173,8 +177,8 @@ private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpecte
);

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,
Expand All @@ -185,4 +189,18 @@ private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpecte
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();
}
}
}

1 comment on commit c8e9f1d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.