test/jdk/java/awt/GraphicsDevice/CheckDisplayModes.java
changeset 59171 85d7af399ef5
parent 47216 71c04702a3d5
equal deleted inserted replaced
59170:945f5bfab0f7 59171:85d7af399ef5
     1 /*
     1 /*
     2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @key headful
    26  * @key headful
    27  * @bug 8007146
    27  * @bug 8007146 8213119
    28  * @summary [macosx] Setting a display mode crashes JDK under VNC
    28  * @summary [macosx] Setting a display mode crashes JDK under VNC
    29  * @author Alexander Scherbatiy
       
    30  * @run main CheckDisplayModes
       
    31  */
    29  */
    32 import java.awt.DisplayMode;
    30 import java.awt.DisplayMode;
    33 import java.awt.GraphicsDevice;
    31 import java.awt.GraphicsDevice;
    34 import java.awt.GraphicsEnvironment;
    32 import java.awt.GraphicsEnvironment;
    35 
    33 
    36 public class CheckDisplayModes {
    34 public class CheckDisplayModes {
    37 
    35 
    38     public static void main(String[] args) {
    36     public static void main(String[] args) {
    39         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    37         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    40         GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    38         for (GraphicsDevice graphicDevice : ge.getScreenDevices()) {
    41         if (!graphicDevice.isDisplayChangeSupported()) {
    39             if (!graphicDevice.isDisplayChangeSupported()) {
    42             System.err.println("Display mode change is not supported on this host. Test is considered passed.");
    40                 System.err.println("Display mode change is not supported on this host. Test is considered passed.");
    43             return;
    41                 continue;
    44         }
    42             }
    45         DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    43             DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    46         checkDisplayMode(defaultDisplayMode);
    44             checkDisplayMode(defaultDisplayMode);
    47         graphicDevice.setDisplayMode(defaultDisplayMode);
    45             graphicDevice.setDisplayMode(defaultDisplayMode);
    48 
    46 
    49         DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    47             DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    50         boolean isDefaultDisplayModeIncluded = false;
    48             boolean isDefaultDisplayModeIncluded = false;
    51         for (DisplayMode displayMode : displayModes) {
    49             for (DisplayMode displayMode : displayModes) {
    52             checkDisplayMode(displayMode);
    50                 checkDisplayMode(displayMode);
    53             graphicDevice.setDisplayMode(displayMode);
    51                 graphicDevice.setDisplayMode(displayMode);
    54             if (defaultDisplayMode.equals(displayMode)) {
    52                 if (defaultDisplayMode.equals(displayMode)) {
    55                 isDefaultDisplayModeIncluded = true;
    53                     isDefaultDisplayModeIncluded = true;
       
    54                 }
    56             }
    55             }
    57         }
       
    58 
    56 
    59         if (!isDefaultDisplayModeIncluded) {
    57             if (!isDefaultDisplayModeIncluded) {
    60             throw new RuntimeException("Default display mode is not included");
    58                 throw new RuntimeException("Default display mode is not included");
       
    59             }
    61         }
    60         }
    62     }
    61     }
    63 
    62 
    64     static void checkDisplayMode(DisplayMode displayMode) {
    63     static void checkDisplayMode(DisplayMode displayMode) {
    65         if (displayMode == null || displayMode.getWidth() <= 1 || displayMode.getHeight() <= 1) {
    64         if (displayMode == null || displayMode.getWidth() <= 1 || displayMode.getHeight() <= 1) {