Path: blob/master/test/jdk/java/awt/MouseInfo/GetPointerInfoTest.java
41149 views
/*1* Copyright (c) 2014, 2016, 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@key headful26@summary unit test for getPointerInfo() from MouseInfo class27@author [email protected]: area=28@bug 400955529@run main GetPointerInfoTest30*/3132import java.awt.*;3334/**35* Simply check the result on non-null and results are correct.36*/37public class GetPointerInfoTest {38private static final String successStage = "Test stage completed.Passed.";3940public static void main(String[] args) throws Exception {41GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();42GraphicsDevice[] gds = ge.getScreenDevices();43int gdslen = gds.length;44System.out.println("There are " + gdslen + " Graphics Devices");45if (gdslen == 0) {46System.out.println("Nothing to be done.");47return;48}49Robot robot = new Robot(gds[0]);50robot.setAutoDelay(0);51robot.setAutoWaitForIdle(true);52robot.delay(10);53robot.waitForIdle();54Point p = new Point(101, 99);55robot.mouseMove(p.x, p.y);5657PointerInfo pi = MouseInfo.getPointerInfo();58if (pi == null) {59throw new RuntimeException("Test failed. getPointerInfo() returned null value.");60} else {61System.out.println(successStage);62}63Point piLocation = pi.getLocation();6465if (piLocation.x != p.x || piLocation.y != p.y) {66throw new RuntimeException("Test failed.getPointerInfo() returned incorrect result.");67} else {68System.out.println(successStage);69}7071System.out.println("Test PASSED.");72}73}747576