Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/MouseInfo/GetPointerInfoTest.java
47525 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@summary unit test for getPointerInfo() from MouseInfo class26@author [email protected]: area=27@bug 400955528@run main GetPointerInfoTest29*/3031import java.awt.*;3233/**34* Simply check the result on non-null and results are correct.35*/36public class GetPointerInfoTest {37private static final String successStage = "Test stage completed.Passed.";3839public static void main(String[] args) throws Exception {40GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();41GraphicsDevice[] gds = ge.getScreenDevices();42int gdslen = gds.length;43System.out.println("There are " + gdslen + " Graphics Devices");44if (gdslen == 0) {45System.out.println("Nothing to be done.");46return;47}48Robot robot = new Robot(gds[0]);49robot.setAutoDelay(0);50robot.setAutoWaitForIdle(true);51robot.delay(10);52robot.waitForIdle();53Point p = new Point(101, 99);54robot.mouseMove(p.x, p.y);5556PointerInfo pi = MouseInfo.getPointerInfo();57if (pi == null) {58throw new RuntimeException("Test failed. getPointerInfo() returned null value.");59} else {60System.out.println(successStage);61}62Point piLocation = pi.getLocation();6364if (piLocation.x != p.x || piLocation.y != p.y) {65throw new RuntimeException("Test failed.getPointerInfo() returned incorrect result.");66} else {67System.out.println(successStage);68}6970System.out.println("Test PASSED.");71}72}737475