1 /*
   2  * Copyright (c) 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 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  * @bug 6429675
  27  * @summary Test that Minimum size is always smaller or equal to Maximum Size.
  28  * @run main MaxMinSize
  29  */
  30 
  31 import java.awt.Dimension;
  32 import java.awt.Frame;
  33 
  34 public class MaxMinSize {
  35     Frame frame;
  36 
  37     MaxMinSize() {
  38         frame = new Frame();
  39         frame.setSize(200, 200);
  40         frame.setVisible(true);
  41     }
  42 
  43     public void doTest() {
  44         Dimension min = new Dimension(500, 500);
  45         Dimension max = new Dimension(600, 600);
  46         frame.setMinimumSize(min);
  47         frame.setMaximumSize(max);
  48         if (!min.equals(frame.getMinimumSize()) &&
  49                 !max.equals(frame.getMaximumSize())) {
  50             dispose();
  51             throw new RuntimeException("Incorrect Maximum or Minimum size");
  52         }
  53 
  54         // Test that If Maximum size is smaller than current Minimum size
  55         // then Maximum size is set to Minimum size.
  56         max = new Dimension(400, 400);
  57         frame.setMinimumSize(min);
  58         frame.setMaximumSize(max);
  59         if (!min.equals(frame.getMaximumSize()) &&
  60                 !frame.getMinimumSize().equals(frame.getMaximumSize())) {
  61             dispose();
  62             throw new RuntimeException("Maximum & Minimum size should be same");
  63         }
  64 
  65         // Test that If Minimum size is greater than current Maximum size
  66         // then Maximum size is set to Minimum size.
  67         max = new Dimension(700, 700);
  68         min = new Dimension(800, 800);
  69         frame.setMaximumSize(max);
  70         frame.setMinimumSize(min);
  71         if (!min.equals(frame.getMaximumSize()) &&
  72                 !frame.getMinimumSize().equals(frame.getMaximumSize())) {
  73             dispose();
  74             throw new RuntimeException("Maximum & Minimum size should be same");
  75         }
  76     }
  77 
  78     public void dispose() {
  79         frame.dispose();
  80     }
  81 
  82     public static void main(String args[]) {
  83         MaxMinSize test = new MaxMinSize();
  84         test.doTest();
  85         test.dispose();
  86     }
  87 }