Skip to content

Commit

Permalink
8129827: [TEST_BUG] Test java/awt/Robot/RobotWheelTest/RobotWheelTest…
Browse files Browse the repository at this point in the history
….java fails

Backport-of: a1efb95536fb3995780336604cc727f921770c63
  • Loading branch information
GoeLin committed Sep 22, 2022
1 parent 7d0854b commit 9cfcae0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -469,7 +469,6 @@ java/awt/image/VolatileImage/CustomCompositeTest.java 8199002 windows-all,linux-
java/awt/image/VolatileImage/GradientPaints.java 8199003 linux-all
java/awt/JAWT/JAWT.sh 8197798 windows-all,linux-all
java/awt/Debug/DumpOnKey/DumpOnKey.java 8202667 windows-all
java/awt/Robot/RobotWheelTest/RobotWheelTest.java 8129827 generic-all
java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java 8202926 linux-all
java/awt/datatransfer/ConstructFlavoredObjectTest/ConstructFlavoredObjectTest.java 8202860 linux-all
java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java 8202790 macosx-all,linux-all
Expand Down
47 changes: 37 additions & 10 deletions test/jdk/java/awt/Robot/RobotWheelTest/RobotWheelTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, 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 @@ -20,10 +20,12 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import java.awt.Button;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Robot;
import java.util.concurrent.atomic.AtomicInteger;

import jdk.test.lib.Platform;

Expand All @@ -40,22 +42,46 @@
public class RobotWheelTest {

private static final int NUMTESTS = 20;
private static volatile int wheelRotation;

private static AtomicInteger wheelRotation = new AtomicInteger();
private static int wheelSign = Platform.isOSX() ? -1 : 1;

static Robot robot;

static void waitTillSuccess(int i) {
boolean success = false;

for (int t = 0; t < 5; t++) {
if (i == wheelSign * wheelRotation.get()) {
success = true;
break;
}
System.out.printf(
"attempt #%d failed. wheelRotation = %d, expected value = %d\n",
t, wheelRotation.get(), i
);
robot.delay(100);
}

if (!success) {
throw new RuntimeException("wheelRotation = " + wheelRotation.get()
+ ", expected value = " + i);
}
}

public static void main(String[] args) throws Exception {
robot = new Robot();

Frame frame = null;
try {
int wheelSign = Platform.isOSX() ? -1 : 1;

frame = new Frame();
frame.setSize(200, 200);
Button button = new Button("WheelButton");
button.addMouseWheelListener(e -> wheelRotation = e.getWheelRotation());
button.addMouseWheelListener(e -> wheelRotation.addAndGet(e.getWheelRotation()));
frame.add(button);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

Robot robot = new Robot();
robot.setAutoDelay(100);
robot.waitForIdle();

Expand All @@ -69,12 +95,13 @@ public static void main(String[] args) throws Exception {
if (i == 0) {
continue;
}

wheelRotation.set(0);

robot.mouseWheel(i);
robot.waitForIdle();
if (i != wheelSign * wheelRotation) {
throw new RuntimeException("wheelRotation = " + wheelRotation
+ ", expected value = " + i);
}

waitTillSuccess(i);
}
} finally {
if (frame != null) {
Expand Down

1 comment on commit 9cfcae0

@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.