Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Multiscreen/MultiScreenInsetsTest/MultiScreenInsetsTest.java
38828 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 802044326@summary Frame is not created on the specified GraphicsDevice with two27monitors28@author Oleg Pekhovskiy29@run main MultiScreenInsetsTest30*/3132import java.awt.Frame;33import java.awt.GraphicsConfiguration;34import java.awt.GraphicsDevice;35import java.awt.GraphicsEnvironment;36import java.awt.Insets;37import java.awt.Rectangle;38import java.awt.Toolkit;39import sun.awt.OSInfo;4041public class MultiScreenInsetsTest {42private static final int SIZE = 100;4344public static void main(String[] args) throws InterruptedException {45OSInfo.OSType type = OSInfo.getOSType();46if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {47System.out.println("This test is for Solaris and Linux only..." +48"skipping!");49return;50}5152GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();53GraphicsDevice[] gds = ge.getScreenDevices();54if (gds.length < 2) {55System.out.println("It's a multi-screen test... skipping!");56return;57}5859for (int screen = 0; screen < gds.length; ++screen) {60GraphicsDevice gd = gds[screen];61GraphicsConfiguration gc = gd.getDefaultConfiguration();62Rectangle bounds = gc.getBounds();63Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);6465Frame frame = new Frame(gc);66frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,67bounds.y + (bounds.height - SIZE) / 2);68frame.setSize(SIZE, SIZE);69frame.setUndecorated(true);70frame.setVisible(true);7172// Maximize Frame to reach the struts73frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);74Thread.sleep(2000);7576Rectangle frameBounds = frame.getBounds();77frame.dispose();78if (bounds.x + insets.left != frameBounds.x79|| bounds.y + insets.top != frameBounds.y80|| bounds.width - insets.right - insets.left != frameBounds.width81|| bounds.height - insets.bottom - insets.top != frameBounds.height) {82throw new RuntimeException("Test FAILED! Wrong screen #" +83screen + " insets: " + insets);84}85}86System.out.println("Test PASSED!");87}88}899091