Path: blob/master/test/jdk/java/awt/Multiscreen/MultiScreenLocationTest/MultiScreenLocationTest.java
41155 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@bug 801311627@summary Robot moves mouse to point which differs from set in mouseMove on28Unity shell29@author Oleg Pekhovskiy30@library ../../regtesthelpers31@build Util32@run main MultiScreenLocationTest33*/3435import java.awt.AWTException;36import java.awt.Color;37import java.awt.Frame;38import java.awt.GraphicsConfiguration;39import java.awt.GraphicsDevice;40import java.awt.GraphicsEnvironment;41import java.awt.MouseInfo;42import java.awt.Point;43import java.awt.Rectangle;44import java.awt.Robot;45import java.awt.image.BufferedImage;46import test.java.awt.regtesthelpers.Util;4748public class MultiScreenLocationTest {49private static final Point mouseOffset = new Point(150, 150);50private static final Point frameOffset = new Point(100, 100);51private static final Color color = Color.YELLOW;5253private static String getErrorText(final String name, int screen)54{55return name + " test failed on Screen #" + screen + "!";56}5758public static void main(String[] args) throws AWTException59{60GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();61GraphicsDevice[] gds = ge.getScreenDevices();62if (gds.length < 2) {63System.out.println("It's a multiscreen test... skipping!");64return;65}6667for (int i = 0; i < gds.length; ++i) {68GraphicsDevice gd = gds[i];69GraphicsConfiguration gc = gd.getDefaultConfiguration();70Rectangle screen = gc.getBounds();71Robot robot = new Robot(gd);7273// check Robot.mouseMove()74robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);75Point mouse = MouseInfo.getPointerInfo().getLocation();76Point point = screen.getLocation();77point.translate(mouseOffset.x, mouseOffset.y);78if (!point.equals(mouse)) {79throw new RuntimeException(getErrorText("Robot.mouseMove", i));80}8182// check Robot.getPixelColor()83Frame frame = new Frame(gc);84frame.setUndecorated(true);85frame.setSize(100, 100);86frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);87frame.setBackground(color);88frame.setVisible(true);89robot.waitForIdle();90Rectangle bounds = frame.getBounds();91if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {92throw new RuntimeException(getErrorText("Robot.getPixelColor", i));93}9495// check Robot.createScreenCapture()96BufferedImage image = robot.createScreenCapture(bounds);97int rgb = color.getRGB();98if (image.getRGB(0, 0) != rgb99|| image.getRGB(image.getWidth() - 1, 0) != rgb100|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb101|| image.getRGB(0, image.getHeight() - 1) != rgb) {102throw new RuntimeException(103getErrorText("Robot.createScreenCapture", i));104}105frame.dispose();106}107108System.out.println("Test PASSED!");109}110}111112113