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 <rdar://problem/2226724>
  27  @summary Frame.getInsets() does not return expected/meaningful data.
  28  @summary com.apple.junit.javax.swing
  29  @run main R2226724Swing
  30  */
  31 import junit.framework.*;
  32 
  33 import javax.swing.JFrame;
  34 import java.awt.Insets;
  35 import javax.swing.SwingUtilities;
  36 
  37 public class R2226724Swing extends TestCase {
  38 
  39     public static Test suite() {
  40         return new TestSuite(R2226724Swing.class);
  41     }
  42 
  43     public static void main(String argv[]) {
  44         junit.textui.TestRunner.run(suite());
  45     }
  46 
  47     // use "ref" for stdout info; return PASSED or FAILED
  48     public void testInsets() throws Exception {
  49         SwingUtilities.invokeAndWait(new Runnable() {
  50             @Override
  51             public void run() {
  52                 String propertyString = System.getProperties().getProperty("os.name");
  53                 assertNotNull("UNEXPECTED ERROR: Unable to getProperty(\"os.name\").", propertyString);
  54 
  55                 JFrame windowf = new JFrame("WindowFrame");
  56                 windowf.setVisible(true);
  57                 try {
  58                     Insets insets = windowf.getInsets();
  59 
  60                     if (propertyString.equals("Mac OS X") || propertyString.equals("Darwin")) {
  61                         assertTrue("ERROR: Frame.getInsets().top == 0.  Should return height of title bar.", (insets.top != 0));
  62                         assertTrue("ERROR: Frame.getInsets().left != 0.  Mac OS X windows don't have side borders.", (insets.left == 0));
  63                         assertTrue("ERROR: Frame.getInsets().right != 0.  Mac OS X windows don't have side borders.", (insets.right == 0));
  64                         assertTrue("ERROR: Frame.getInsets().bottom != 0.  Mac OS X windows don't have bottom borders.", insets.bottom == 0);
  65                     } else {
  66                         assertTrue("ERROR: Frame.getInsets().left == 0.  Classic windows have side borders.", (insets.left != 0));
  67                         assertTrue("ERROR: Frame.getInsets().right == 0.  Classic windows have side borders.", (insets.right != 0));
  68                         assertTrue("ERROR: Frame.getInsets().bottom == 0.  Classic windows have bottom borders.", (insets.bottom != 0));
  69                     }
  70                 } finally {
  71                     windowf.setVisible(false);
  72                     windowf.dispose();
  73                 }
  74             }
  75         });
  76     }
  77 }