Path: blob/master/test/jdk/java/awt/FullScreen/UninitializedDisplayModeChangeTest/UninitializedDisplayModeChangeTest.java
41153 views
/*1* Copyright (c) 2006, 2018, 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* @bug 6358034 6568560 8198613 819833526* @key headful27* @summary Tests that no exception is thrown when display mode is changed28* externally29* @compile UninitializedDisplayModeChangeTest.java DisplayModeChanger.java30* @run main/othervm UninitializedDisplayModeChangeTest31* @run main/othervm -Djava.awt.headless=true UninitializedDisplayModeChangeTest32*/3334import java.awt.EventQueue;35import java.awt.Toolkit;36import java.io.BufferedReader;37import java.io.File;38import java.io.IOException;39import java.io.InputStream;40import java.io.InputStreamReader;41import java.lang.reflect.InvocationTargetException;4243public class UninitializedDisplayModeChangeTest {44public static volatile boolean failed = false;45public static void main(String[] args) {46Toolkit.getDefaultToolkit();47try {48EventQueue.invokeAndWait(new Runnable() {49public void run() {50Thread.currentThread().setDefaultUncaughtExceptionHandler(51new Thread.UncaughtExceptionHandler() {52public void uncaughtException(Thread t,53Throwable e)54{55System.err.println("Exception Detected:");56e.printStackTrace();57failed = true;58}59}60);61}62});63} catch (InterruptedException ex) {64ex.printStackTrace();65} catch (InvocationTargetException ex) {66ex.printStackTrace();67}6869Process childProc;70String classPath = System.getProperty("java.class.path" , ".");71String cmd = new String(System.getProperty("java.home") +72File.separator +73"bin" +74File.separator +75"java -cp " + classPath +76" DisplayModeChanger");7778System.out.println("Launching the display mode changer process");79System.out.println("cmd="+cmd);80try {81childProc = Runtime.getRuntime().exec(cmd);82StreamProcessor err =83new StreamProcessor("stderr", childProc.getErrorStream());84StreamProcessor out =85new StreamProcessor("stdout", childProc.getInputStream());86err.start();87out.start();8889childProc.waitFor();90} catch (Exception e) {91failed = true;92e.printStackTrace();93}9495if (failed) {96throw new RuntimeException("Test Failed: exception detected");97}98System.out.println("Test Passed.");99}100101static class StreamProcessor extends Thread {102InputStream is;103String inputType;104StreamProcessor(String inputType, InputStream is) {105this.inputType = inputType;106this.is = is;107}108public void run() {109try {110InputStreamReader isr = new InputStreamReader(is);111BufferedReader br = new BufferedReader(isr);112String line = null;113while ( (line = br.readLine()) != null) {114System.out.println("Display Changer "+inputType+115" output > " + line);116}117} catch (IOException ioe) {118ioe.printStackTrace();119}120}121}122}123124125