Path: blob/master/test/jdk/tools/launcher/MiscTests.java
41144 views
/*1* Copyright (c) 2010, 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 6856415 8154212 815447026* @summary Miscellaneous tests, Exceptions27* @modules jdk.compiler28* jdk.zipfs29* @compile -XDignore.symbol.file MiscTests.java30* @run main MiscTests31*/323334import java.io.File;35import java.io.IOException;36import java.util.ArrayList;37import java.util.HashMap;38import java.util.List;39import java.util.Map;4041public class MiscTests extends TestHelper {4243/**44* Test with class path set on the command line via -Djava.class.path45*/46static void testWithClassPathSetViaProperty() throws IOException {47final String mainClass = "Foo";4849File source = new File(mainClass + ".java");5051List<String> scratch = new ArrayList<>();52scratch.add("public class Foo {");53scratch.add("public static void main(String... args) {");54scratch.add("}");55scratch.add("}");56createFile(source, scratch);5758compile(mainClass + ".java");5960String dir = new File(mainClass + ".class").getAbsoluteFile().getParent();61TestResult tr = doExec(javaCmd, "-Djava.class.path=" + dir, mainClass);62for (String s : tr.testOutput) {63System.out.println(s);64}65}6667/**68* 6856415: Checks to ensure that proper exceptions are thrown by java69*/70static void test6856415() throws IOException {7172final String mainClass = "Foo6856415";7374List<String> scratch = new ArrayList<>();75scratch.add("public class Foo6856415 {");76scratch.add("public static void main(String... args) {");77scratch.add("java.security.Provider p = new sun.security.pkcs11.SunPKCS11();");78scratch.add("java.security.Security.insertProviderAt(p, 1);");79scratch.add("}");80scratch.add("}");81createFile(new File(mainClass + ".java"), scratch);8283compile(mainClass + ".java",84"--add-modules=jdk.crypto.cryptoki",85"--add-exports=jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED");8687File testJar = new File("Foo.jar");88testJar.delete();89String jarArgs[] = {90(debug) ? "cvfe" : "cfe",91testJar.getAbsolutePath(),92mainClass,93mainClass + ".class"94};95createJar(jarArgs);9697TestResult tr = doExec(javaCmd,98"-Djava.security.manager", "-jar", testJar.getName(), "foo.bak");99if (!tr.contains("java.security.AccessControlException:" +100" access denied (\"java.lang.RuntimePermission\"" +101" \"accessClassInPackage.sun.security.pkcs11\")")) {102System.out.println(tr);103}104}105106static void testJLDEnv() {107final Map<String, String> envToSet = new HashMap<>();108envToSet.put("_JAVA_LAUNCHER_DEBUG", "true");109for (String cmd : new String[] { javaCmd, javacCmd }) {110TestResult tr = doExec(envToSet, cmd, "-version");111tr.checkPositive();112String javargs = cmd.equals(javacCmd) ? "on" : "off";113String progname = cmd.equals(javacCmd) ? "javac" : "java";114if (!tr.isOK()115|| !tr.matches("\\s*debug:on$")116|| !tr.matches("\\s*javargs:" + javargs + "$")117|| !tr.matches("\\s*program name:" + progname + "$")) {118System.out.println(tr);119}120}121}122123public static void main(String... args) throws IOException {124testWithClassPathSetViaProperty();125test6856415();126testJLDEnv();127if (testExitValue != 0) {128throw new Error(testExitValue + " tests failed");129}130}131}132133134