Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java
38821 views
/*1* Copyright (c) 2007, 2015, 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 635632226* @summary Tests that embedded frame's graphics configuration is updated27* correctly when it is moved to another screen in multiscreen system,28* XToolkit29* @author [email protected]: area=awt.multiscreen30* @requires (os.family == "linux") | (os.family == "solaris")31* @run main GraphicsConfigTest32*/3334import java.awt.*;35import java.awt.peer.*;36import java.lang.reflect.*;37import java.util.*;38import sun.awt.*;39import sun.awt.X11.*;4041public class GraphicsConfigTest {4243private static void init()44throws InterruptedException, AWTException {45if (!isXToolkit()) {46System.err.println("The test should be run only on XToolkit");47return;48}4950GraphicsEnvironment ge =51GraphicsEnvironment.getLocalGraphicsEnvironment();52GraphicsDevice[] gds = ge.getScreenDevices();53if (gds.length < 2) {54System.err.println("The test should be run only in"55+ " multiscreen configuration");56return;57}5859boolean xinerama = Arrays.stream(gds)60.map((gd) -> gd.getDefaultConfiguration().getBounds())61.filter((r) -> r.x != 0 || r.y != 0).findFirst().isPresent();6263if (!xinerama) {64System.err.println("The test should be run only with Xinerama ON");65return;66}6768Rectangle r0 = gds[0].getDefaultConfiguration().getBounds();69Rectangle r1 = gds[1].getDefaultConfiguration().getBounds();7071System.setProperty("sun.awt.xembedserver", "true");72Frame f = new Frame("F");73try {74final Robot robot = new Robot();7576f.setBounds(r0.x + 100, r0.y + 100, 200, 200);77f.setVisible(true);78robot.waitForIdle();79Thread.sleep(1000);8081Canvas c = new Canvas();82f.add(c);83AWTAccessor.ComponentAccessor acc =84AWTAccessor.getComponentAccessor();85WindowIDProvider wip = (XEmbedCanvasPeer)acc.getPeer(c);86long h = wip.getWindow();8788EmbeddedFrame e = createEmbeddedFrame(h);89((FramePeer)acc.getPeer(e)).setBoundsPrivate(0, 0, 100,90100); // triggers XConfigureEvent91e.registerListeners();92e.setVisible(true);93robot.waitForIdle();94Thread.sleep(1000);9596if (!checkGC(f, e)) {97throw new RuntimeException("Failed at checkpoint 1");98}99100f.setLocation(r1.x + 100, r1.y + 100);101Thread.sleep(100);102((FramePeer)acc.getPeer(e)).setBoundsPrivate(0, 0, 101,103101); // triggers XConfigureEvent104robot.waitForIdle();105Thread.sleep(1000);106107if (!checkGC(f, e)) {108throw new RuntimeException("Failed at checkpoint 2");109}110111f.setLocation(r0.x + 100, r0.y + 100);112Thread.sleep(100);113((FramePeer)acc.getPeer(e)).setBoundsPrivate(0, 0, 102,114102); // triggers XConfigureEvent115robot.waitForIdle();116Thread.sleep(1000);117118if (!checkGC(f, e)) {119throw new RuntimeException("Failed at checkpoint 3");120}121122} finally {123f.dispose();124}125}126127private static boolean isXToolkit() {128return Toolkit.getDefaultToolkit().getClass()129.getName().equals("sun.awt.X11.XToolkit");130}131132private static EmbeddedFrame createEmbeddedFrame(long window) {133try {134Class cl = Class.forName("sun.awt.X11.XEmbeddedFrame");135Constructor cons = cl.getConstructor(136new Class[]{Long.TYPE, Boolean.TYPE});137return (EmbeddedFrame) cons.newInstance(new Object[]{window, true});138} catch (Exception e) {139e.printStackTrace();140throw new RuntimeException("Can't create embedded frame");141}142}143144private static boolean checkGC(Component c, Component d) {145GraphicsConfiguration g1 = c.getGraphicsConfiguration();146System.err.println(g1);147GraphicsConfiguration g2 = d.getGraphicsConfiguration();148System.err.println(g2);149150return g1.equals(g2);151}152153public static void main(String args[]) throws InterruptedException, AWTException {154init();155}156}157158159