Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java
38828 views
/*1* Copyright 2009 Red Hat, Inc. All Rights Reserved.2* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25@test26@bug 672108827@summary X11 Window sizes should be what we set them to28@author Omair Majid <[email protected]>: area=awt.toplevel29@run main TestFrameSize30*/3132/**33* TestFrameSize.java34*35* Summary: test that X11 Awt windows are drawn with correct sizes36*37* Test fails if size of window is wrong38*/3940import java.awt.*;4142public class TestFrameSize {4344static Dimension desiredDimensions = new Dimension(200, 200);45static Frame mainWindow;4647private static Dimension getClientSize(Frame window) {48Dimension size = window.getSize();49Insets insets = window.getInsets();5051System.out.println("getClientSize() for " + window);52System.out.println(" size: " + size);53System.out.println(" insets: " + insets);5455return new Dimension(56size.width - insets.left - insets.right,57size.height - insets.top - insets.bottom);58}5960public static void drawGui() {61mainWindow = new Frame("");62mainWindow.setPreferredSize(desiredDimensions);63mainWindow.pack();6465Dimension actualDimensions = mainWindow.getSize();66System.out.println("Desired dimensions: " + desiredDimensions.toString());67System.out.println("Actual dimensions: " + actualDimensions.toString());68if (!actualDimensions.equals(desiredDimensions)) {69throw new RuntimeException("Incorrect widow size");70}7172// pack() guarantees to preserve the size of the client area after73// showing the window.74Dimension clientSize1 = getClientSize(mainWindow);75System.out.println("Client size before showing: " + clientSize1);7677mainWindow.setVisible(true);7879try {80Robot robot = new Robot();81robot.waitForIdle();82}catch(Exception ex) {83ex.printStackTrace();84throw new RuntimeException("Unexpected failure.");85}8687Dimension clientSize2 = getClientSize(mainWindow);88System.out.println("Client size after showing: " + clientSize2);8990if (!clientSize2.equals(clientSize1)) {91throw new RuntimeException("Incorrect client area size.");92}93}9495public static void main(String[] args) {96try {97drawGui();98} finally {99if (mainWindow != null) {100mainWindow.dispose();101}102}103}104}105106107