Basic.java revision 0
0N/A * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689 0N/A * 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313 0N/A * 6464154 6523983 6206031 0N/A * @summary Basic tests for Process and Environment Variable code 0N/A * @author Martin Buchholz 0N/A // compare windows-style, by canonicalizing to upper case, 0N/A // not lower case as String.compareToIgnoreCase does 0N/A "-----------------------------------------------------";
0N/A fail(
"Sorted string contents differ");
0N/A // Ignore magic environment variables added by the launcher 0N/A // You might think the system streams would be 0N/A // buffered, and in fact they are implemented using 0N/A // BufferedOutputStream, but each and every print 0N/A // causes immediate operating system I/O. 0N/A // Not on PATH at all; directories don't exist 0N/A fail(
"Expected IOException not thrown");
0N/A // Not on PATH at all; directories exist 0N/A fail(
"Expected IOException not thrown");
0N/A // Can't execute a directory -- permission denied 0N/A // Report EACCES errno 0N/A fail(
"Expected IOException not thrown");
0N/A // continue searching if EACCES 0N/A // Check empty PATH component means current directory 0N/A // If prog found on both parent and child's PATH, 0N/A // parent's is used. 0N/A else throw new Error(
"JavaChild invocation error");
0N/A "Basic$JavaChild"});
0N/A // If round trip conversion works, should be able to set env vars 0N/A // correctly in child. 0N/A public static boolean is() {
return is; }
0N/A private static final boolean is =
0N/A public static boolean is() {
return is; }
0N/A private static final boolean is =
0N/A public static boolean is() {
return is; }
0N/A private static final boolean is =
0N/A // MacOS X would probably also qualify 0N/A // /bin/false returns an *unspecified* non-zero number. 0N/A /** Returns true if we can expect English OS error strings */ 0N/A //---------------------------------------------------------------- 0N/A // Basic tests for setting, replacing and deleting envvars 0N/A //---------------------------------------------------------------- 0N/A // Remove non-existent env var 0N/A //---------------------------------------------------------------- 0N/A // Pass Empty environment to child 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // System.getenv() is read-only. 0N/A //---------------------------------------------------------------- 0N/A fail(
"Expected UnsupportedOperationException not thrown");
0N/A //---------------------------------------------------------------- 0N/A // System.getenv() always returns the same object in our implementation. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // You can't create an env var name containing "=", 0N/A // or an env var name or value containing NUL. 0N/A //---------------------------------------------------------------- 0N/A new Fun(){
void f(){ m.
put(
"FOO\u0000",
"BAR");}},
0N/A new Fun(){
void f(){ m.
put(
"FOO",
"BAR\u0000");}});
0N/A //---------------------------------------------------------------- 0N/A // Commands must never be null. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Put in a command; get the same one back out. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Commands must contain at least one element. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Commands must not contain null elements at start() time. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Command lists are growable. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Nulls in environment updates generate NullPointerException 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Non-String types in environment updates generate ClassCastException 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Check query operations on environment maps 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Nulls in environment queries are forbidden. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Non-String types in environment queries are forbidden. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Illegal String values in environment queries are (grumble) OK 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Put in a directory; get the same one back out. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // If round-trip conversion works, check envvar pass-through to child 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // A surprisingly large number of ways to delete an environment var. 0N/A //---------------------------------------------------------------- 0N/A // Legally fabricate a ProcessEnvironment.StringEntry, 0N/A // even though it's private. 0N/A //---------------------------------------------------------------- 0N/A // A surprisingly small number of ways to add an environment var. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // A few ways to modify an environment var. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Fiddle with environment sizes 0N/A //---------------------------------------------------------------- 0N/A // Check for environment independence 0N/A //---------------------------------------------------------------- 0N/A // Check that various map invariants hold 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Check effects on external "env" command. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Test Runtime.exec(...envp...) 0N/A // Check for sort order of environment variables on Windows. 0N/A //---------------------------------------------------------------- 0N/A // '+' < 'A' < 'Z' < '_' < 'a' < 'z' < '~' 0N/A "+=+",
"_=_",
"~=~"};
0N/A // On Windows, Java must keep the environment sorted. 0N/A // Order is random on Unix, so this test does the sort. 0N/A //---------------------------------------------------------------- 0N/A // System.getenv() must be consistent with System.getenv(String) 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Fiddle with working directory in child 0N/A //---------------------------------------------------------------- 0N/A {
".",
"..",
"/",
"/bin",
0N/A "C:",
"c:",
"C:/",
"c:\\",
"\\",
"\\bin" };
0N/A //---------------------------------------------------------------- 0N/A // Windows has tricky semi-case-insensitive semantics 0N/A //---------------------------------------------------------------- 0N/A "Windows environment variables are not case insensitive");
0N/A //---------------------------------------------------------------- 0N/A // Test proper Unicode child environment transfer 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Test Runtime.exec(...envp...) with envstrings with initial `=' 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Test Runtime.exec(...envp...) with envstrings without any `=' 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Test Runtime.exec(...envp...) with envstrings containing NULs 0N/A //---------------------------------------------------------------- 0N/A "FO\u0000=B\u0000R"};
0N/A "Incorrect handling of envstrings containing NULs");
0N/A //---------------------------------------------------------------- 0N/A // Test the redirectErrorStream property 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // We can find true and false when PATH is null 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // PATH search algorithm on Unix 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Parent's, not child's PATH is used 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Attempt to start bogus program "" 0N/A //---------------------------------------------------------------- 0N/A fail(
"Expected IOException not thrown");
0N/A //---------------------------------------------------------------- 0N/A // Check that attempt to execute program name with funny 0N/A // characters throws an exception containing those characters. 0N/A //---------------------------------------------------------------- 0N/A fail(
"Expected IOException not thrown");
0N/A //---------------------------------------------------------------- 0N/A // Attempt to start process in nonexistent directory fails. 0N/A //---------------------------------------------------------------- 0N/A fail(
"Expected IOException not thrown");
0N/A //---------------------------------------------------------------- 0N/A // This would deadlock, if not for the fact that 0N/A // interprocess pipe buffers are at least 4096 bytes. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Attempt to start process with insufficient permissions fails. 0N/A //---------------------------------------------------------------- 0N/A fail(
"Expected IOException not thrown");
0N/A //e.printStackTrace(); 0N/A //---------------------------------------------------------------- 0N/A // Check for correct security permission behavior 0N/A //---------------------------------------------------------------- 0N/A // No permissions required to CREATE a ProcessBuilder 0N/A // environment permission by itself insufficient 0N/A // exec permission by itself insufficient 0N/A // Both permissions? OK. 0N/A // Don't need environment permission unless READING environment 0N/A // Don't need environment permission unless READING environment 0N/A // Restore "normal" state without a security manager 0N/A //---------------------------------------------------------------- 0N/A // A Policy class designed to make permissions fiddling very easy. 0N/A //---------------------------------------------------------------- 0N/A //---------------------------------------------------------------- 0N/A // Results of a command 0N/A //---------------------------------------------------------------- 0N/A //--------------------- Infrastructure --------------------------- 0N/A else fail(x +
" not equal to " + y);}