Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/MouseInfo/MultiscreenPointerInfo.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 MultiscreenPointerInfo29*/3031import java.awt.*;3233/**34* Simply check the result on non-null and results are correct.35*/36public class MultiscreenPointerInfo37{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 < 2) {46System.out.println("Nothing to be done. PASSED automatically.");47return;48}49Rectangle rx = gds[1].getDefaultConfiguration().getBounds();50Robot robot;5152if (rx.x == 0 && rx.y == 0) {53// Assuming independent graphics devices54robot = new Robot(gds[1]);55} else {56// Means we have a virtual device57robot = new Robot(gds[0]);58}59robot.setAutoDelay(0);60robot.setAutoWaitForIdle(true);61robot.delay(10);62robot.waitForIdle();63Point p = new Point(rx.x + 101, rx.y + 99);64robot.mouseMove(p.x, p.y);65PointerInfo pi = MouseInfo.getPointerInfo();66if (pi == null) {67throw new RuntimeException("Test failed. getPointerInfo() returned null value.");68} else {69System.out.println(successStage);70}7172Point piLocation = pi.getLocation();7374if (piLocation.x != p.x || piLocation.y != p.y) {75throw new RuntimeException("Test failed.getPointerInfo() returned incorrect location.");76} else {77System.out.println(successStage);78}7980GraphicsDevice dev = pi.getDevice();8182if (dev != gds[1]) {83throw new RuntimeException("Test failed.getPointerInfo() returned incorrect device.");84} else {85System.out.println(successStage);86}87System.out.println("Test PASSED.");88}89}909192