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
  • Loading branch information
caojoshua committed Oct 14, 2022
1 parent 00b7ef3 commit f144ec0
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions jdk/test/java/awt/Robot/RobotWheelTest/RobotWheelTest.java
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f144ec0

Please sign in to comment.