blob: 8ae0479ffef71e7a74430d50b40fc4f177c1ebd5 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 6358034
27 * @bug 6568560
28 * @summary Tests that no exception is thrown when display mode is changed
29 * externally
30 * @compile UninitializedDisplayModeChangeTest.java DisplayModeChanger.java
31 * @run main/othervm UninitializedDisplayModeChangeTest
32 * @run main/othervm -Dsun.java2d.opengl=true UninitializedDisplayModeChangeTest
33 */
34
35import java.awt.EventQueue;
36import java.awt.Toolkit;
37import java.io.BufferedReader;
38import java.io.File;
39import java.io.IOException;
40import java.io.InputStream;
41import java.io.InputStreamReader;
42import java.lang.reflect.InvocationTargetException;
43
44public class UninitializedDisplayModeChangeTest {
45 public static volatile boolean failed = false;
46 public static void main(String[] args) {
47 Toolkit.getDefaultToolkit();
48 try {
49 EventQueue.invokeAndWait(new Runnable() {
50 public void run() {
51 Thread.currentThread().setDefaultUncaughtExceptionHandler(
52 new Thread.UncaughtExceptionHandler() {
53 public void uncaughtException(Thread t,
54 Throwable e)
55 {
56 System.err.println("Exception Detected:");
57 e.printStackTrace();
58 failed = true;
59 }
60 }
61 );
62 }
63 });
64 } catch (InterruptedException ex) {
65 ex.printStackTrace();
66 } catch (InvocationTargetException ex) {
67 ex.printStackTrace();
68 }
69
70 Process childProc;
71 String classPath = System.getProperty("java.class.path" , ".");
72 String cmd = new String(System.getProperty("java.home") +
73 File.separator +
74 "bin" +
75 File.separator +
76 "java -cp " + classPath +
77 " DisplayModeChanger");
78
79 System.out.println("Launching the display mode changer process");
80 System.out.println("cmd="+cmd);
81 try {
82 childProc = Runtime.getRuntime().exec(cmd);
83 StreamProcessor err =
84 new StreamProcessor("stderr", childProc.getErrorStream());
85 StreamProcessor out =
86 new StreamProcessor("stdout", childProc.getInputStream());
87 err.start();
88 out.start();
89
90 childProc.waitFor();
91 } catch (Exception e) {
92 failed = true;
93 e.printStackTrace();
94 }
95
96 if (failed) {
97 throw new RuntimeException("Test Failed: exception detected");
98 }
99 System.out.println("Test Passed.");
100 }
101
102 static class StreamProcessor extends Thread {
103 InputStream is;
104 String inputType;
105 StreamProcessor(String inputType, InputStream is) {
106 this.inputType = inputType;
107 this.is = is;
108 }
109 public void run() {
110 try {
111 InputStreamReader isr = new InputStreamReader(is);
112 BufferedReader br = new BufferedReader(isr);
113 String line = null;
114 while ( (line = br.readLine()) != null) {
115 System.out.println("Display Changer "+inputType+
116 " output > " + line);
117 }
118 } catch (IOException ioe) {
119 ioe.printStackTrace();
120 }
121 }
122 }
123}