1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 import java.awt.Frame; 24 import java.io.File; 25 import java.io.IOException; 26 import java.io.InputStream; 27 import java.util.concurrent.TimeUnit; 28 29 /** 30 * @test 31 * @key headful 32 * @bug 8081019 33 * @summary Check peer to null in CPlatformWindow.checkZoom() method 34 * @author Alexandr Scherbatiy 35 */ 36 public class bug8081019 { 37 38 private static final String RUN_PROCESS = "RUN_PROCESS"; 39 private static final String RUN_TEST = "RUN_TEST"; 40 41 public static void main(String[] args) throws Exception { 42 String command = RUN_PROCESS; 43 44 if (0 < args.length) { 45 command = args[0]; 46 } 47 48 switch (command) { 49 case RUN_PROCESS: 50 runProcess(); 51 break; 52 case RUN_TEST: 53 runTest(); 54 break; 55 default: 56 throw new RuntimeException("Unknown command: " + command); 57 } 58 } 59 60 private static void runTest() throws Exception { 61 System.setSecurityManager(new SecurityManager()); 62 Frame f = new Frame("Test frame"); 63 f.setVisible(true); 64 f.setVisible(false); 65 f.dispose(); 66 } 67 68 private static void runProcess() throws Exception { 69 String javaPath = System.getProperty("java.home", ""); 70 String command = javaPath + File.separator + "bin" + File.separator + "java" 71 + " " + bug8081019.class.getName() + " " + RUN_TEST; 72 73 Process process = Runtime.getRuntime().exec(command); 74 boolean processExit = process.waitFor(20, TimeUnit.SECONDS); 75 76 dumpStream(process.getErrorStream(), "error stream"); 77 dumpStream(process.getInputStream(), "input stream"); 78 79 if (!processExit) { 80 process.destroy(); 81 throw new RuntimeException("" 82 + "The sub process has not exited!"); 83 } 84 } 85 86 public static void dumpStream(InputStream in, String name) throws IOException { 87 System.out.println("--- dump " + name + " ---"); 88 String tempString; 89 int count = in.available(); 90 boolean exception = false; 91 while (count > 0) { 92 byte[] b = new byte[count]; 93 in.read(b); 94 tempString = new String(b); 95 if (!exception) { 96 exception = tempString.indexOf("Exception") != -1 97 || tempString.indexOf("Error") != -1; 98 } 99 System.out.println(tempString); 100 count = in.available(); 101 } 102 103 if (exception) { 104 throw new RuntimeException("Exception in the output!"); 105 } 106 } 107 }