Path: blob/master/test/jdk/java/awt/GraphicsDevice/CheckDisplayModes.java
41149 views
/*1* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 8007146 821311927* @summary [macosx] Setting a display mode crashes JDK under VNC28*/29import java.awt.DisplayMode;30import java.awt.GraphicsDevice;31import java.awt.GraphicsEnvironment;3233public class CheckDisplayModes {3435public static void main(String[] args) {36GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();37for (GraphicsDevice graphicDevice : ge.getScreenDevices()) {38if (!graphicDevice.isDisplayChangeSupported()) {39System.err.println("Display mode change is not supported on this host. Test is considered passed.");40continue;41}42DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();43checkDisplayMode(defaultDisplayMode);44graphicDevice.setDisplayMode(defaultDisplayMode);4546DisplayMode[] displayModes = graphicDevice.getDisplayModes();47boolean isDefaultDisplayModeIncluded = false;48for (DisplayMode displayMode : displayModes) {49checkDisplayMode(displayMode);50graphicDevice.setDisplayMode(displayMode);51if (defaultDisplayMode.equals(displayMode)) {52isDefaultDisplayModeIncluded = true;53}54}5556if (!isDefaultDisplayModeIncluded) {57throw new RuntimeException("Default display mode is not included");58}59}60}6162static void checkDisplayMode(DisplayMode displayMode) {63if (displayMode == null || displayMode.getWidth() <= 1 || displayMode.getHeight() <= 1) {64throw new RuntimeException("invalid display mode");65}66}67}686970