Path: blob/master/test/jdk/java/awt/Dialog/DialogOverflowSizeTest/DialogSizeOverflowTest.java
41154 views
/*1* Copyright (c) 2003, 2016, 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* @key headful26* @bug 490496127* @summary Test that Dialog with zero sizes won't be created with negative sizes due to overflow in peer code28* @author Andrei Dmitriev: area=awt.toplevel29* @library ../../regtesthelpers30* @build Util31* @run main DialogSizeOverflowTest32*/3334import java.awt.*;35import java.awt.event.*;36import test.java.awt.regtesthelpers.Util;3738public class DialogSizeOverflowTest39{40public static void main(String [] s) {41Robot robot;42Frame f = new Frame("a frame");43final Dialog dlg = new Dialog(f, false);4445f.setVisible(true);4647try {48robot = new Robot();49} catch(AWTException e){50throw new RuntimeException("Test interrupted.", e);51}52Util.waitForIdle(robot);5354dlg.setLocation(100, 100);55dlg.setResizable(false);56dlg.addComponentListener(new ComponentAdapter() {57public void componentResized(ComponentEvent e) {58Dimension size = dlg.getSize();59System.out.println("size.width : size.height "+size.width + " : "+ size.height);60if (size.width > 1000 || size.height > 1000 || size.width < 0 || size.height < 0) {61throw new RuntimeException("Test failed. Size is too large.");62}63}64});65dlg.toBack();66dlg.setVisible(true);6768Util.waitForIdle(robot);69System.out.println("Test passed.");70}71}727374