Path: blob/master/test/jdk/java/awt/Frame/FrameSize/TestFrameSize.java
41153 views
/*1* Copyright 2009 Red Hat, Inc. All Rights Reserved.2* Copyright (c) 2009, 2016, 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@key headful27@bug 672108828@summary X11 Window sizes should be what we set them to29@author Omair Majid <[email protected]>: area=awt.toplevel30@run main TestFrameSize31*/3233/**34* TestFrameSize.java35*36* Summary: test that X11 Awt windows are drawn with correct sizes37*38* Test fails if size of window is wrong39*/4041import java.awt.*;4243public class TestFrameSize {4445static Dimension desiredDimensions = new Dimension(200, 200);46static Frame mainWindow;4748private static Dimension getClientSize(Frame window) {49Dimension size = window.getSize();50Insets insets = window.getInsets();5152System.out.println("getClientSize() for " + window);53System.out.println(" size: " + size);54System.out.println(" insets: " + insets);5556return new Dimension(57size.width - insets.left - insets.right,58size.height - insets.top - insets.bottom);59}6061public static void drawGui() {62mainWindow = new Frame("");63mainWindow.setPreferredSize(desiredDimensions);64mainWindow.pack();6566Dimension actualDimensions = mainWindow.getSize();67System.out.println("Desired dimensions: " + desiredDimensions.toString());68System.out.println("Actual dimensions: " + actualDimensions.toString());69if (!actualDimensions.equals(desiredDimensions)) {70throw new RuntimeException("Incorrect widow size");71}7273// pack() guarantees to preserve the size of the client area after74// showing the window.75Dimension clientSize1 = getClientSize(mainWindow);76System.out.println("Client size before showing: " + clientSize1);7778mainWindow.setVisible(true);7980try {81Robot robot = new Robot();82robot.waitForIdle();83}catch(Exception ex) {84ex.printStackTrace();85throw new RuntimeException("Unexpected failure.");86}8788Dimension clientSize2 = getClientSize(mainWindow);89System.out.println("Client size after showing: " + clientSize2);9091if (!clientSize2.equals(clientSize1)) {92throw new RuntimeException("Incorrect client area size.");93}94}9596public static void main(String[] args) {97try {98drawGui();99} finally {100if (mainWindow != null) {101mainWindow.dispose();102}103}104}105}106107108