Path: blob/master/test/jdk/tools/launcher/TestSpecialArgs.java
66643 views
/*1* Copyright (c) 2012, 2021, 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 7124089 7131021 8042469 8066185 8074373 825891726* @summary Checks for Launcher special flags, such as MacOSX specific flags.27* @modules jdk.compiler28* jdk.zipfs29* @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java30* @run main TestSpecialArgs31*/32import java.io.File;33import java.io.FileNotFoundException;34import java.util.HashMap;35import java.util.HashSet;36import java.util.Map;37import java.util.Set;3839public class TestSpecialArgs extends TestHelper {4041public static void main(String... args) throws Exception {42new TestSpecialArgs().run(args);43}4445@Test46void testDocking() {47final Map<String, String> envMap = new HashMap<>();48envMap.put("_JAVA_LAUNCHER_DEBUG", "true");49TestResult tr = doExec(envMap, javaCmd, "-XstartOnFirstThread", "-version");50if (isMacOSX) {51if (!tr.contains("In same thread")) {52System.out.println(tr);53throw new RuntimeException("Error: not running in the same thread ?");54}55if (!tr.isOK()) {56System.out.println(tr);57throw new RuntimeException("Error: arg was rejected ????");58}59} else {60if (tr.isOK()) {61System.out.println(tr);62throw new RuntimeException("Error: argument was accepted ????");63}64}6566tr = doExec(javaCmd, "-Xdock:/tmp/not-available", "-version");67if (isMacOSX) {68if (!tr.isOK()) {69System.out.println(tr);70throw new RuntimeException("Error: arg was rejected ????");71}72} else {73if (tr.isOK()) {74System.out.println(tr);75throw new RuntimeException("Error: argument was accepted ????");76}77}78// MacOSX specific tests ensue......79if (!isMacOSX) {80return;81}82Set<String> envToRemove = new HashSet<>();83Map<String, String> map = System.getenv();84for (String s : map.keySet()) {85if (s.startsWith("JAVA_MAIN_CLASS_")86|| s.startsWith("APP_NAME_")87|| s.startsWith("APP_ICON_")) {88envToRemove.add(s);89}90}91runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),92"EnvironmentVariables", "JAVA_MAIN_CLASS_*",93"EnvironmentVariables");9495runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),96"-Xdock:name=TestAppName", "EnvironmentVariables",97"APP_NAME_*", "TestAppName");9899runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),100"-Xdock:icon=TestAppIcon", "EnvironmentVariables",101"APP_ICON_*", "TestAppIcon");102}103104void runTest(Set<String> envToRemove, String... args) {105TestResult tr = doExec(null, envToRemove, args);106if (!tr.isOK()) {107System.err.println(tr.toString());108throw new RuntimeException("Test Fails");109}110}111112void checkTestResult(TestResult tr) {113if (!tr.isOK()) {114System.err.println(tr.toString());115throw new RuntimeException("Test Fails");116}117}118}119120121