01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Serguei S.Zapreyev
20: * @version $Revision$
21: */package java.lang;
22:
23: import java.io.BufferedReader;
24: import java.io.IOException;
25: import java.io.InputStreamReader;
26:
27: import junit.framework.TestCase;
28:
29: /*
30: * Created on March 29, 2006
31: *
32: * This RuntimeAdditionalTest class is used to test the Core API Runtime class
33: *
34: */
35:
36: /**
37: * ###############################################################################
38: * ###############################################################################
39: * TODO: 1.
40: * ###############################################################################
41: * ###############################################################################
42: */
43:
44: public class RuntimeAdditionalTest37 extends TestCase {
45: /**
46: * check an environment variable appears correctly if exec(..., env, ...) is
47: * used
48: */
49: public void test_36_1() {
50: System.out.println("==test_36===");
51: String command = null;
52: if (RuntimeAdditionalTest0.os.equals("Win")) {
53: command = RuntimeAdditionalTest0.cm
54: + " /C \"echo %Z_S_S_2%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"";
55: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
56: //command = "sh -c \"echo $Z_S_S_2\"";
57: //command = "echo $Z_S_S_2";
58: command = "/usr/bin/env";
59: } else {
60: fail("WARNING (test_1): unknown operating system.");
61: }
62: String procValue = null;
63: try {
64: Process proc = Runtime.getRuntime().exec(command,
65: new String[] { "Z_S_S_2=S_O_M_E_T_H_I_N_G" });
66: BufferedReader br = new BufferedReader(
67: new InputStreamReader(proc.getInputStream()));
68: boolean flg = true;
69: while ((procValue = br.readLine()) != null) {
70: //if (procValue.indexOf("Z_S_S_2=S_O_M_E_T_H_I_N_G") != -1) {
71: if (procValue.indexOf(RuntimeAdditionalTest0.os
72: .equals("Win") ? "S_O_M_E_T_H_I_N_Gx"
73: : "S_O_M_E_T_H_I_N_G") != -1) {
74: //System.out.println(procValue);
75: flg = false;
76: return;
77: }
78: System.out
79: .println("WARNING (test_36): should it be only singl line in env after such exec? ("
80: + procValue + ")");
81: }
82: if (flg) {
83: fail("ERROR (test_36): Z_S_S_2 var should be present and assingned correctly.");
84: }
85: } catch (IOException e) {
86: e.printStackTrace();
87: fail("ERROR (test_36): unexpected exception.");
88: }
89: }
90: }
|