test/jdk/java/awt/MouseInfo/GetPointerInfoTest.java
author jboes
Fri, 08 Nov 2019 11:15:16 +0000
changeset 59029 3786a0962570
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232853: AuthenticationFilter.Cache::remove may throw ConcurrentModificationException Summary: Change implementation to use iterator instead of plain LinkedList Reviewed-by: dfuchs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 30924
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     4
 *
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     8
 *
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    13
 * accompanied this code).
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    14
 *
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    18
 *
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    21
 * questions.
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    22
 */
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    23
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    24
/*
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 30924
diff changeset
    26
  @key headful
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    27
  @summary unit test for getPointerInfo() from MouseInfo class
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    28
  @author dav@sparc.spb.su: area=
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    29
  @bug 4009555
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    30
  @run main GetPointerInfoTest
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    31
*/
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    32
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    33
import java.awt.*;
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    34
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    35
/**
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    36
 * Simply check the result on non-null and results are correct.
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    37
 */
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    38
public class GetPointerInfoTest {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    39
    private static final String successStage = "Test stage completed.Passed.";
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    40
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    42
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    43
        GraphicsDevice[] gds = ge.getScreenDevices();
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    44
        int gdslen = gds.length;
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    45
        System.out.println("There are " + gdslen + " Graphics Devices");
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    46
        if (gdslen == 0) {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    47
            System.out.println("Nothing to be done.");
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    48
            return;
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    49
        }
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    50
        Robot robot = new Robot(gds[0]);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    51
        robot.setAutoDelay(0);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    52
        robot.setAutoWaitForIdle(true);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    53
        robot.delay(10);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    54
        robot.waitForIdle();
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    55
        Point p = new Point(101, 99);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    56
        robot.mouseMove(p.x, p.y);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    57
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    58
        PointerInfo pi = MouseInfo.getPointerInfo();
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    59
        if (pi == null) {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    60
            throw new RuntimeException("Test failed. getPointerInfo() returned null value.");
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    61
        } else {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    62
            System.out.println(successStage);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    63
        }
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    64
        Point piLocation = pi.getLocation();
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    65
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    66
        if (piLocation.x != p.x || piLocation.y != p.y) {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    67
            throw new RuntimeException("Test failed.getPointerInfo() returned incorrect result.");
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    68
        } else {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    69
            System.out.println(successStage);
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    70
        }
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    71
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    72
        System.out.println("Test PASSED.");
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    73
    }
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents:
diff changeset
    74
}