1 /* 2 * Copyright (c) 2011, 2013, 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 it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 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 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Verifies Frame and JFrame sizes relative to window size. 27 * @summary com.apple.junit.java.awt.Window 28 * @library ../../regtesthelpers 29 * @build VisibilityValidator 30 * @run junit MinSizeTest 31 */ 32 33 import test.java.awt.regtesthelpers.VisibilityValidator; 34 import junit.framework.*; 35 import javax.swing.*; 36 import java.awt.*; 37 38 public class MinSizeTest extends TestCase { 39 VisibilityValidator checkpoint; 40 41 public void testAWTMinSize() { 42 Frame f = null; 43 Window w = null; 44 45 try { 46 f = new Frame("frame"); 47 checkpoint = new VisibilityValidator(f); 48 f.setBounds(50,50,10,10); 49 f.setVisible(true); 50 51 w = new Window(f); 52 w.setBounds(250,50,10,10); 53 w.setVisible(true); 54 55 checkpoint.requireVisible(); 56 assertFalse("Frame minimum size is too small: " + f.getSize(), ( (f.getSize().height==10) || (f.getSize().width==10) ) ); 57 assertTrue("Window minimum size is too big: " + w.getSize(), ( (w.getSize().height==10) && (w.getSize().width==10) ) ); 58 } finally { 59 if (w != null) { 60 w.setVisible(false); 61 w.dispose(); 62 } 63 if (f != null) { 64 f.setVisible(false); 65 f.dispose(); 66 } 67 } 68 } 69 70 public void testSwingMinSize() { 71 JFrame jf = null; 72 JFrame jf2 = null; 73 74 try { 75 jf = new JFrame("jframe"); 76 checkpoint = new VisibilityValidator(jf); 77 jf.setBounds(50,250,10,10); 78 jf.setVisible(true); 79 80 jf2 = new JFrame("undecorated"); 81 jf2.setUndecorated(true); 82 jf2.setBounds(250,250,10,10); 83 jf2.setVisible(true); 84 85 checkpoint.requireVisible(); 86 assertFalse("JFrame minimum size is too small: " + jf.getSize(), ( (jf.getSize().height==10) || (jf.getSize().width==10) ) ); 87 assertTrue("Undecorated JFrame minimum size is too big: " + jf2.getSize(), ( (jf2.getSize().height==10) && (jf2.getSize().width==10) ) ); 88 } finally { 89 if (jf2 != null) { 90 jf2.setVisible(false); 91 jf2.dispose(); 92 } 93 if (jf != null) { 94 jf.setVisible(false); 95 jf.dispose(); 96 } 97 } 98 } 99 100 public static Test suite() { 101 return new TestSuite(MinSizeTest.class); 102 } 103 104 public static void main (String[] args) throws RuntimeException { 105 TestResult tr = junit.textui.TestRunner.run(suite()); 106 if ((tr.errorCount() != 0) || (tr.failureCount() != 0)) { 107 throw new RuntimeException("### FAILED: unexpected JUnit errors or failures."); 108 } 109 } 110 } 111