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

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

Closed
wants to merge 3 commits into from
Closed
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
47 changes: 37 additions & 10 deletions jdk/test/java/awt/Robot/RobotWheelTest/RobotWheelTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2015, 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,11 +20,13 @@
* 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 jdk.testlibrary.OSInfo;
import java.util.concurrent.atomic.AtomicInteger;

/*
* @test 1.2 98/08/05
Expand All @@ -38,22 +40,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 = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? -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 = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? -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 @@ -67,12 +93,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