8129827: [TEST_BUG] Test java/awt/Robot/RobotWheelTest/RobotWheelTest.java fails

Reviewed-by: psadhukhan
This commit is contained in:
Alexander Zvegintsev 2022-04-23 20:39:39 +00:00
parent 03cbb48e6a
commit a1efb95536
2 changed files with 37 additions and 11 deletions
test/jdk
ProblemList.txt
java/awt/Robot/RobotWheelTest

@ -464,7 +464,6 @@ java/awt/font/TextLayout/LigatureCaretTest.java 8266312 generic-all
java/awt/image/VolatileImage/CustomCompositeTest.java 8199002 windows-all,linux-all
java/awt/image/VolatileImage/GradientPaints.java 8199003 linux-all
java/awt/JAWT/JAWT.sh 8197798 windows-all,linux-all
java/awt/Robot/RobotWheelTest/RobotWheelTest.java 8129827 generic-all
java/awt/datatransfer/ConstructFlavoredObjectTest/ConstructFlavoredObjectTest.java 8202860 linux-all
java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java 8202790 macosx-all,linux-all
java/awt/FileDialog/FilenameFilterTest/FilenameFilterTest.java 8202882 linux-all

@ -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
@ -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;
@ -40,22 +42,46 @@ import jdk.test.lib.Platform;
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();
@ -69,12 +95,13 @@ public class RobotWheelTest {
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) {