Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Multiscreen/UpdateGCTest/UpdateGCTest.java
38828 views
/*1* Copyright (c) 2007, 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 4452373 656756426@summary Tests that all the child and toplevel components have27their GraphicsConfiguration updated when the window moves from28one screen to another, on Windows or Linux/Solaris + Xinerama29@author artem.ananiev: area=awt.multiscreen30@library ../../regtesthelpers31@build Util32@run main UpdateGCTest33*/3435import java.awt.*;36import java.awt.event.*;3738import test.java.awt.regtesthelpers.Util;3940public class UpdateGCTest41{42public static void main(String[] args)43{44GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();45GraphicsDevice[] gds = ge.getScreenDevices();46if (gds.length < 2)47{48System.out.println("The test should be run in multi-screen configuration. Test PASSED/skipped");49return;50}51boolean virtualConfig = false;52for (GraphicsDevice gd : gds)53{54GraphicsConfiguration gc = gd.getDefaultConfiguration();55if ((gc.getBounds().x != 0) || (gc.getBounds().y != 0))56{57virtualConfig = true;58break;59}60}61if (!virtualConfig)62{63System.out.println("The test should be run in virtual multi-screen mode. Test PASSED/skipped");64return;65}6667try68{69Robot robot = new Robot();70Util.waitForIdle(robot);7172for (GraphicsDevice gdOrig : gds)73{74GraphicsConfiguration gcOrig = gdOrig.getDefaultConfiguration();7576// test Frame77Frame f = new Frame("F", gcOrig);78f.setSize(200, 200);79f.setLayout(new BorderLayout());80// test Canvas81f.add(new Canvas(gcOrig), BorderLayout.NORTH);82// test lightweight83Container c = new Container() {};84c.setLayout(new BorderLayout());85// test hw inside lw86c.add(new Panel());87c.add(new Canvas(gcOrig));88f.add(c, BorderLayout.SOUTH);89// test Panel90Panel p = new Panel();91p.setLayout(new BorderLayout());92// test nested Canvas93p.add(new Canvas(gcOrig), BorderLayout.NORTH);94// test nested lightweight95p.add(new Component() {}, BorderLayout.SOUTH);96// test nested panel97p.add(new Panel(), BorderLayout.CENTER);98f.add(p, BorderLayout.CENTER);99100f.setVisible(true);101Util.waitForIdle(robot);102103for (GraphicsDevice gd : gds)104{105GraphicsConfiguration gc = gd.getDefaultConfiguration();106107f.setLocation(gc.getBounds().x + 100, gc.getBounds().y + 100);108Util.waitForIdle(robot);109110checkGC(f, gc);111}112}113}114catch (Exception z)115{116System.err.println("Unknown exception caught");117z.printStackTrace(System.err);118throw new RuntimeException("Test FAILED: " + z.getMessage());119}120121System.out.println("Test PASSED");122}123124private static void checkGC(Component c, GraphicsConfiguration gc)125{126if (c.getGraphicsConfiguration() != gc)127{128System.err.println("GC for component (" + c + ") is not updated");129System.err.println("Right GC: " + gc);130System.err.println("Component GC: " + c.getGraphicsConfiguration());131throw new RuntimeException("Test FAILED: component GC is not updated");132}133System.out.println("Checked GC for component (" + c + "): OK");134135if (c instanceof Container)136{137Container cc = (Container)c;138Component[] children = cc.getComponents();139for (Component child : children)140{141checkGC(child, gc);142}143}144}145}146147148