jdk/test/java/awt/GraphicsDevice/CheckDisplayModes.java
author katleman
Thu, 03 Sep 2015 14:24:43 -0700
changeset 32450 f036508e86e7
parent 18124 b036434f6675
child 39056 d99e63b6d962
permissions -rw-r--r--
Added tag jdk9-b80 for changeset 56a580f0c008
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16470
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     1
/*
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     4
 *
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     8
 *
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    13
 * accompanied this code).
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    14
 *
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    18
 *
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    21
 * questions.
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    22
 */
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    23
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    24
/*
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    25
 * @test
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    26
 * @bug 8007146
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    27
 * @summary [macosx] Setting a display mode crashes JDK under VNC
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    28
 * @author Alexander Scherbatiy
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    29
 * @run main CheckDisplayModes
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    30
 */
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    31
import java.awt.DisplayMode;
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    32
import java.awt.GraphicsDevice;
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    33
import java.awt.GraphicsEnvironment;
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    34
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    35
public class CheckDisplayModes {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    36
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    37
    public static void main(String[] args) {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    38
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    39
        GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
18124
b036434f6675 8012569: TEST_BUG: java/awt/GraphicsDevice/CheckDisplayModes.java fails
kshefov
parents: 16470
diff changeset
    40
        if (!graphicDevice.isDisplayChangeSupported()) {
b036434f6675 8012569: TEST_BUG: java/awt/GraphicsDevice/CheckDisplayModes.java fails
kshefov
parents: 16470
diff changeset
    41
            System.err.println("Display mode change is not supported on this host. Test is considered passed.");
b036434f6675 8012569: TEST_BUG: java/awt/GraphicsDevice/CheckDisplayModes.java fails
kshefov
parents: 16470
diff changeset
    42
            return;
b036434f6675 8012569: TEST_BUG: java/awt/GraphicsDevice/CheckDisplayModes.java fails
kshefov
parents: 16470
diff changeset
    43
        }
16470
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    44
        DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    45
        checkDisplayMode(defaultDisplayMode);
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    46
        graphicDevice.setDisplayMode(defaultDisplayMode);
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    47
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    48
        DisplayMode[] displayModes = graphicDevice.getDisplayModes();
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    49
        boolean isDefaultDisplayModeIncluded = false;
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    50
        for (DisplayMode displayMode : displayModes) {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    51
            checkDisplayMode(displayMode);
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    52
            graphicDevice.setDisplayMode(displayMode);
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    53
            if (defaultDisplayMode.equals(displayMode)) {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    54
                isDefaultDisplayModeIncluded = true;
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    55
            }
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    56
        }
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    57
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    58
        if (!isDefaultDisplayModeIncluded) {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    59
            throw new RuntimeException("Default display mode is not included");
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    60
        }
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    61
    }
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    62
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    63
    static void checkDisplayMode(DisplayMode displayMode) {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    64
        if (displayMode == null || displayMode.getWidth() <= 1 || displayMode.getHeight() <= 1) {
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    65
            throw new RuntimeException("invalid display mode");
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    66
        }
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    67
    }
ccc74e8572d5 8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
diff changeset
    68
}