Path: blob/master/test/jdk/java/awt/MouseInfo/MultiscreenPointerInfo.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 MultiscreenPointerInfo30*/3132import java.awt.*;3334/**35* Simply check the result on non-null and results are correct.36*/37public class MultiscreenPointerInfo38{39private static final String successStage = "Test stage completed.Passed.";4041public static void main(String[] args) throws Exception {42GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();43GraphicsDevice[] gds = ge.getScreenDevices();44int gdslen = gds.length;45System.out.println("There are " + gdslen + " Graphics Devices");46if (gdslen < 2) {47System.out.println("Nothing to be done. PASSED automatically.");48return;49}50Rectangle rx = gds[1].getDefaultConfiguration().getBounds();51Robot robot;5253if (rx.x == 0 && rx.y == 0) {54// Assuming independent graphics devices55robot = new Robot(gds[1]);56} else {57// Means we have a virtual device58robot = new Robot(gds[0]);59}60robot.setAutoDelay(0);61robot.setAutoWaitForIdle(true);62robot.delay(10);63robot.waitForIdle();64Point p = new Point(rx.x + 101, rx.y + 99);65robot.mouseMove(p.x, p.y);66PointerInfo pi = MouseInfo.getPointerInfo();67if (pi == null) {68throw new RuntimeException("Test failed. getPointerInfo() returned null value.");69} else {70System.out.println(successStage);71}7273Point piLocation = pi.getLocation();7475if (piLocation.x != p.x || piLocation.y != p.y) {76throw new RuntimeException("Test failed.getPointerInfo() returned incorrect location.");77} else {78System.out.println(successStage);79}8081GraphicsDevice dev = pi.getDevice();8283if (dev != gds[1]) {84throw new RuntimeException("Test failed.getPointerInfo() returned incorrect device.");85} else {86System.out.println(successStage);87}88System.out.println("Test PASSED.");89}90}919293