1 /*
   2  * Copyright (c) 2012, 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 
  24 /*
  25  * @test
  26  * @bug 7124089 7131021
  27  * @summary Checks for MacOSX specific flags are accepted or rejected, and
  28  *          MacOSX platforms specific environment is consistent.
  29  * @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java
  30  * @run main TestSpecialArgs
  31  */
  32 import java.util.HashMap;
  33 import java.util.HashSet;
  34 import java.util.Map;
  35 import java.util.Set;
  36 
  37 public class TestSpecialArgs extends TestHelper {
  38 
  39     public static void main(String... args) {
  40         final Map<String, String> envMap = new HashMap<>();
  41         envMap.put("_JAVA_LAUNCHER_DEBUG", "true");
  42 
  43         TestResult tr = doExec(envMap, javaCmd, "-XstartOnFirstThread", "-version");
  44         if (isMacOSX) {
  45             if (!tr.contains("In same thread")) {
  46                 System.out.println(tr);
  47                 throw new RuntimeException("Error: not running in the same thread ?");
  48             }
  49             if (!tr.isOK()) {
  50                 System.out.println(tr);
  51                 throw new RuntimeException("Error: arg was rejected ????");
  52             }
  53         } else {
  54             if (tr.isOK()) {
  55                 System.out.println(tr);
  56                 throw new RuntimeException("Error: argument was accepted ????");
  57             }
  58         }
  59 
  60         tr = doExec(javaCmd, "-Xdock:/tmp/not-available", "-version");
  61         if (isMacOSX) {
  62             if (!tr.isOK()) {
  63                 System.out.println(tr);
  64                 throw new RuntimeException("Error: arg was rejected ????");
  65             }
  66         } else {
  67             if (tr.isOK()) {
  68                 System.out.println(tr);
  69                 throw new RuntimeException("Error: argument was accepted ????");
  70             }
  71         }
  72         // MacOSX specific tests ensue......
  73         if (!isMacOSX)
  74             return;
  75         Set<String> envToRemove = new HashSet<>();
  76         Map<String, String> map = System.getenv();
  77         for (String s : map.keySet()) {
  78             if (s.startsWith("JAVA_MAIN_CLASS_")
  79                     || s.startsWith("APP_NAME_")
  80                     || s.startsWith("APP_ICON_")) {
  81                 envToRemove.add(s);
  82             }
  83         }
  84         runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
  85                 "EnvironmentVariables", "JAVA_MAIN_CLASS_*",
  86                 "EnvironmentVariables");
  87 
  88         runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
  89                 "-Xdock:name=TestAppName", "EnvironmentVariables",
  90                 "APP_NAME_*", "TestAppName");
  91 
  92         runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
  93                 "-Xdock:icon=TestAppIcon", "EnvironmentVariables",
  94                 "APP_ICON_*", "TestAppIcon");
  95     }
  96 
  97     static void runTest(Set<String> envToRemove, String... args) {
  98         TestResult tr = doExec(null, envToRemove, args);
  99         if (!tr.isOK()) {
 100             System.err.println(tr.toString());
 101             throw new RuntimeException("Test Fails");
 102         }
 103     }
 104 }