Path: blob/master/test/jdk/javax/swing/JOptionPane/8081019/bug8081019.java
41155 views
/*1* Copyright (c) 2015, 2017, 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*/22import java.awt.Frame;23import java.io.File;24import java.io.IOException;25import java.io.InputStream;26import java.util.concurrent.TimeUnit;2728/**29* @test30* @key headful31* @bug 808101932* @summary Check peer to null in CPlatformWindow.checkZoom() method33* @author Alexandr Scherbatiy34*/35public class bug8081019 {3637private static final String RUN_PROCESS = "RUN_PROCESS";38private static final String RUN_TEST = "RUN_TEST";3940public static void main(String[] args) throws Exception {41String command = RUN_PROCESS;4243if (0 < args.length) {44command = args[0];45}4647switch (command) {48case RUN_PROCESS:49runProcess();50break;51case RUN_TEST:52runTest();53break;54default:55throw new RuntimeException("Unknown command: " + command);56}57}5859private static void runTest() throws Exception {60System.setSecurityManager(new SecurityManager());61Frame f = new Frame("Test frame");62f.setVisible(true);63f.setVisible(false);64f.dispose();65}6667private static void runProcess() throws Exception {68String javaPath = System.getProperty("java.home", "");69String command = javaPath + File.separator + "bin" + File.separator + "java"70+ " -Djava.security.manager=allow " + bug8081019.class.getName() + " " + RUN_TEST;7172Process process = Runtime.getRuntime().exec(command);73boolean processExit = process.waitFor(20, TimeUnit.SECONDS);7475dumpStream(process.getErrorStream(), "error stream");76dumpStream(process.getInputStream(), "input stream");7778if (!processExit) {79process.destroy();80throw new RuntimeException(""81+ "The sub process has not exited!");82}83}8485public static void dumpStream(InputStream in, String name) throws IOException {86System.out.println("--- dump " + name + " ---");87String tempString;88int count = in.available();89boolean exception = false;90while (count > 0) {91byte[] b = new byte[count];92in.read(b);93tempString = new String(b);94if (!exception) {95exception = tempString.indexOf("Exception") != -196|| tempString.indexOf("Error") != -1;97}98System.out.println(tempString);99count = in.available();100}101102if (exception) {103throw new RuntimeException("Exception in the output!");104}105}106}107108109