Path: blob/master/test/jdk/java/net/URLClassLoader/getresourceasstream/TestDriver.java
41153 views
/*1* Copyright (c) 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*/2223/**24* @test25* @bug 510344926* @summary REGRESSION: getResourceAsStream is broken in JDK1.5.0-rc27* @library /test/lib28* @build jdk.test.lib.Utils29* jdk.test.lib.Asserts30* jdk.test.lib.JDKToolFinder31* jdk.test.lib.JDKToolLauncher32* jdk.test.lib.Platform33* jdk.test.lib.process.*34* Test35* @run main/othervm TestDriver36*/3738import jdk.test.lib.JDKToolFinder;39import jdk.test.lib.process.ProcessTools;4041import java.io.IOException;42import java.nio.file.Files;43import java.nio.file.Path;44import java.nio.file.Paths;45import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;4647public class TestDriver {48private static final String ARCHIVE_NAME = "test.jar";49private static final String TEST_NAME = "Test";50private static final String POLICY_FILE = "policy";51public static void main(String[] args)52throws Throwable {5354Path userDir = Paths.get(System.getProperty("user.dir"));55String java = JDKToolFinder.getTestJDKTool("java");56String basename = userDir.getFileName().toString();57setup(userDir);58ProcessBuilder[] tests = new ProcessBuilder[]{59new ProcessBuilder(60java, TEST_NAME, "./" + ARCHIVE_NAME61),62new ProcessBuilder(63java, "-cp", ".",64"-Djava.security.policy=file:./policy",65"-Djava.security.manager",66TEST_NAME, "./" + ARCHIVE_NAME67),68new ProcessBuilder(69java, "-cp", ".",70"-Djava.security.policy=file:./policy",71"-Djava.security.manager",72TEST_NAME, "./" + ARCHIVE_NAME73),74new ProcessBuilder(75java, "-cp", "..",76"-Djava.security.policy=file:../policy",77"-Djava.security.manager",78TEST_NAME, "../" + ARCHIVE_NAME79).directory(userDir.resolve("tmp").toFile()),80new ProcessBuilder(81java, "-cp", basename,82"-Djava.security.policy=file:" + basename + "/policy",83"-Djava.security.manager",84TEST_NAME, basename + "/" + ARCHIVE_NAME85).directory(userDir.resolve("..").toFile())};86for (ProcessBuilder test : tests) {87runTest(test);88}89}9091private static void setup(Path userDir) throws IOException {92Path src = Paths.get(System.getProperty("test.src"));93Path testJar = src.resolve(ARCHIVE_NAME);94Path policy = src.resolve(POLICY_FILE);95Path testClass = Paths.get(System.getProperty("test.classes"),96TEST_NAME + ".class");97Files.copy(testJar, userDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);98Files.copy(policy, userDir.resolve(POLICY_FILE), REPLACE_EXISTING);99Files.copy(testClass, userDir.resolve(TEST_NAME + ".class"),100REPLACE_EXISTING);101Files.createDirectories(userDir.resolve("tmp"));102}103104private static void runTest(ProcessBuilder pb) throws Exception {105System.out.println("Testing with command: [" + pb.command() + "]");106ProcessTools.executeProcess(pb)107.outputTo(System.out)108.errorTo(System.err)109.shouldHaveExitValue(0);110}111}112113114