Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Multiscreen/MultiScreenLocationTest/MultiScreenLocationTest.java
38821 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@bug 801311626@summary Robot moves mouse to point which differs from set in mouseMove on27Unity shell28@author Oleg Pekhovskiy29@library ../../regtesthelpers30@build Util31@run main MultiScreenLocationTest32*/3334import java.awt.AWTException;35import java.awt.Color;36import java.awt.Frame;37import java.awt.GraphicsConfiguration;38import java.awt.GraphicsDevice;39import java.awt.GraphicsEnvironment;40import java.awt.MouseInfo;41import java.awt.Point;42import java.awt.Rectangle;43import java.awt.Robot;44import java.awt.image.BufferedImage;45import test.java.awt.regtesthelpers.Util;4647public class MultiScreenLocationTest {48private static final Point mouseOffset = new Point(150, 150);49private static final Point frameOffset = new Point(100, 100);50private static final Color color = Color.YELLOW;5152private static String getErrorText(final String name, int screen)53{54return name + " test failed on Screen #" + screen + "!";55}5657public static void main(String[] args) throws AWTException58{59GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();60GraphicsDevice[] gds = ge.getScreenDevices();61if (gds.length < 2) {62System.out.println("It's a multiscreen test... skipping!");63return;64}6566for (int i = 0; i < gds.length; ++i) {67GraphicsDevice gd = gds[i];68GraphicsConfiguration gc = gd.getDefaultConfiguration();69Rectangle screen = gc.getBounds();70Robot robot = new Robot(gd);7172// check Robot.mouseMove()73robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);74Point mouse = MouseInfo.getPointerInfo().getLocation();75Point point = screen.getLocation();76point.translate(mouseOffset.x, mouseOffset.y);77if (!point.equals(mouse)) {78throw new RuntimeException(getErrorText("Robot.mouseMove", i));79}8081// check Robot.getPixelColor()82Frame frame = new Frame(gc);83frame.setUndecorated(true);84frame.setSize(100, 100);85frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);86frame.setBackground(color);87frame.setVisible(true);88robot.waitForIdle();89Rectangle bounds = frame.getBounds();90if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {91throw new RuntimeException(getErrorText("Robot.getPixelColor", i));92}9394// check Robot.createScreenCapture()95BufferedImage image = robot.createScreenCapture(bounds);96int rgb = color.getRGB();97if (image.getRGB(0, 0) != rgb98|| image.getRGB(image.getWidth() - 1, 0) != rgb99|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb100|| image.getRGB(0, image.getHeight() - 1) != rgb) {101throw new RuntimeException(102getErrorText("Robot.createScreenCapture", i));103}104frame.dispose();105}106107System.out.println("Test PASSED!");108}109}110111112