Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7001973: java/awt/Graphics2D/CopyAreaOOB.java fails #711

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -246,7 +246,6 @@ sun/awt/shell/ShellFolderMemoryLeak.java 8197794 windows-all
sun/java2d/DirectX/OnScreenRenderingResizeTest/OnScreenRenderingResizeTest.java 8022403 generic-all
sun/java2d/DirectX/OverriddenInsetsTest/OverriddenInsetsTest.java 8196102 generic-all
sun/java2d/DirectX/RenderingToCachedGraphicsTest/RenderingToCachedGraphicsTest.java 8196180 windows-all,macosx-all
java/awt/Graphics2D/CopyAreaOOB.java 7001973 windows-all,macosx-all
sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java 8144029 macosx-all,linux-all
sun/java2d/SunGraphics2D/DrawImageBilinear.java 8191406 generic-all
sun/java2d/SunGraphics2D/PolyVertTest.java 6986565 generic-all
Expand Down
66 changes: 21 additions & 45 deletions test/jdk/java/awt/Graphics2D/CopyAreaOOB.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021 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 Down Expand Up @@ -36,15 +36,9 @@

public class CopyAreaOOB extends Canvas {

private static boolean done;
private static Robot robot = null;

public void paint(Graphics g) {
synchronized (this) {
if (done) {
return;
}
}

int w = getWidth();
int h = getHeight();

Expand All @@ -64,10 +58,23 @@ public void paint(Graphics g) {

Toolkit.getDefaultToolkit().sync();

synchronized (this) {
done = true;
notifyAll();
BufferedImage capture = null;
try {
Thread.sleep(500);
if (robot == null) robot = new Robot();
Point pt1 = getLocationOnScreen();
Rectangle rect = new Rectangle(pt1.x, pt1.y, 400, 400);
capture = robot.createScreenCapture(rect);
} catch (Exception e) {
throw new RuntimeException("Problems handling Robot");
}
// Test pixels
testRegion(capture, "green", 0, 0, 400, 10, 0xff00ff00);
testRegion(capture, "original red", 0, 10, 50, 400, 0xffff0000);
testRegion(capture, "background", 50, 10, 60, 400, 0xff000000);
testRegion(capture, "in-between", 60, 10, 110, 20, 0xff000000);
testRegion(capture, "copied red", 60, 20, 110, 400, 0xffff0000);
testRegion(capture, "background", 110, 10, 400, 400, 0xff000000);
}

public Dimension getPreferredSize() {
Expand Down Expand Up @@ -105,42 +112,11 @@ public static void main(String[] args) {
frame.setLocationRelativeTo(null);
frame.setVisible(true);

// Wait until the component's been painted
synchronized (test) {
while (!done) {
try {
test.wait();
} catch (InterruptedException e) {
throw new RuntimeException("Failed: Interrupted");
}
}
}

try {
Thread.sleep(2000);
Thread.sleep(3000);
} catch (InterruptedException ex) {}

// Grab the screen region
BufferedImage capture = null;
try {
Robot robot = new Robot();
Point pt1 = test.getLocationOnScreen();
Rectangle rect = new Rectangle(pt1.x, pt1.y, 400, 400);
capture = robot.createScreenCapture(rect);
} catch (Exception e) {
throw new RuntimeException("Problems creating Robot");
} finally {
if (!show) {
frame.dispose();
}
if (!show) {
frame.dispose();
}

// Test pixels
testRegion(capture, "green", 0, 0, 400, 10, 0xff00ff00);
testRegion(capture, "original red", 0, 10, 50, 400, 0xffff0000);
testRegion(capture, "background", 50, 10, 60, 400, 0xff000000);
testRegion(capture, "in-between", 60, 10, 110, 20, 0xff000000);
testRegion(capture, "copied red", 60, 20, 110, 400, 0xffff0000);
testRegion(capture, "background", 110, 10, 400, 400, 0xff000000);
}
}