test/jdk/javax/swing/GroupLayout/7071166/bug7071166.java
author serb
Fri, 16 Feb 2018 12:24:38 -0800
changeset 49090 82c1fe23c469
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196196: Headful tests should not be run in headless mode Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10104
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     1
/*
49090
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
10104
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     4
 *
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     8
 *
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    13
 * accompanied this code).
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    14
 *
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    18
 *
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    21
 * questions.
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    22
 */
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    23
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    24
/*
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    25
 * @test
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    26
 * @bug 7071166
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    27
 * @summary LayoutStyle.getPreferredGap() - IAE is expected but not thrown
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    28
 * @author Pavel Porvatov
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    29
 */
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    30
49090
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    31
import java.awt.Container;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    32
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    33
import javax.swing.JButton;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    34
import javax.swing.LayoutStyle;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    35
import javax.swing.SwingUtilities;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    36
import javax.swing.UIManager;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    37
import javax.swing.UnsupportedLookAndFeelException;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    38
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    39
import static javax.swing.SwingConstants.EAST;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    40
import static javax.swing.SwingConstants.NORTH;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    41
import static javax.swing.SwingConstants.NORTH_EAST;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    42
import static javax.swing.SwingConstants.NORTH_WEST;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    43
import static javax.swing.SwingConstants.SOUTH;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    44
import static javax.swing.SwingConstants.SOUTH_EAST;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    45
import static javax.swing.SwingConstants.SOUTH_WEST;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    46
import static javax.swing.SwingConstants.WEST;
10104
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    47
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    48
public class bug7071166 {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    49
    private static final int[] POSITIONS = {NORTH, EAST, SOUTH, WEST, // valid positions
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    50
            NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST, 123, -456}; // invalid positions
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    51
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    53
        for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {
49090
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    54
            try {
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    55
                UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    56
            } catch (final UnsupportedLookAndFeelException ignored) {
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    57
                continue;
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    58
            }
10104
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    59
            System.out.println("LookAndFeel: " + lookAndFeelInfo.getName());
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    60
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    61
            SwingUtilities.invokeAndWait(new Runnable() {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    62
                public void run() {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    63
                    LayoutStyle layoutStyle = LayoutStyle.getInstance();
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    64
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    65
                    System.out.println("LayoutStyle: " + layoutStyle);
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    66
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    67
                    for (int i = 0; i < POSITIONS.length; i++) {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    68
                        int position = POSITIONS[i];
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    69
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    70
                        try {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    71
                            layoutStyle.getPreferredGap(new JButton(), new JButton(),
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    72
                                    LayoutStyle.ComponentPlacement.RELATED, position, new Container());
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    73
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    74
                            if (i > 3) {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    75
                                throw new RuntimeException("IllegalArgumentException is not thrown for position " +
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    76
                                        position);
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    77
                            }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    78
                        } catch (IllegalArgumentException e) {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    79
                            if (i <= 3) {
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    80
                                throw new RuntimeException("IllegalArgumentException is thrown for position " +
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    81
                                        position);
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    82
                            }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    83
                        }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    84
                    }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    85
                }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    86
            });
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    87
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    88
            System.out.println("passed");
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    89
        }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    90
    }
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents:
diff changeset
    91
}