jdk/test/javax/swing/JSlider/6794836/bug6794836.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 5506 202f599c92aa
child 42338 a60f280f803c
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
     2
 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     4
 *
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     8
 *
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    13
 * accompanied this code).
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    14
 *
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1852
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1852
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1852
diff changeset
    21
 * questions.
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    22
 */
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    23
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    24
/*
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    25
 * @test
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
 * @key headful
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    27
 * @bug 6794836
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    28
 * @summary BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    29
 * @author Pavel Porvatov
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    30
 * @run main bug6794836
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    31
 */
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    32
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    33
import javax.swing.*;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    34
import javax.swing.plaf.basic.BasicSliderUI;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    35
import java.lang.reflect.Method;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    36
import java.util.Hashtable;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    37
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    38
public class bug6794836 {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    40
        new bug6794836().run();
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    41
    }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    42
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    43
    public void run() throws Exception {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    44
        JSlider slider = new JSlider(0, Integer.MAX_VALUE);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    45
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    46
        slider.setPaintLabels(true);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    47
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    48
        JLabel minLabel = new JLabel("Min");
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    49
        JLabel maxLabel = new JLabel("Max");
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    50
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    51
        Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    52
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    53
        labelTable.put(Integer.MIN_VALUE, minLabel);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    54
        labelTable.put(Integer.MAX_VALUE, maxLabel);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    55
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    56
        slider.setLabelTable(labelTable);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    57
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    58
        BasicSliderUI ui = (BasicSliderUI) slider.getUI();
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    59
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    60
        if (invokeMethod("getHighestValueLabel", ui) != maxLabel) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    61
            fail("invalid getHighestValueLabel result");
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    62
        }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    63
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    64
        if (invokeMethod("getLowestValueLabel", ui) != minLabel) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    65
            fail("invalid getLowestValueLabel result");
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    66
        }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    67
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    68
        System.out.println("The bug6794836 test passed");
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    69
    }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    70
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    71
    private static Object invokeMethod(String name, BasicSliderUI ui) throws Exception {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    72
        Method method = BasicSliderUI.class.getDeclaredMethod(name, null);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    73
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    74
        method.setAccessible(true);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    75
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    76
        return method.invoke(ui, null);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    77
    }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    78
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    79
    private static void fail(String s) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    80
        throw new RuntimeException("Test failed: " + s);
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    81
    }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
diff changeset
    82
}