001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Serguei S.Zapreyev
020: * @version $Revision$
021: */package java.lang;
022:
023: import java.io.File;
024:
025: import junit.framework.TestCase;
026:
027: /*
028: * Created on March 29, 2006
029: *
030: * This RuntimeAdditionalTest class is used to test the Core API Runtime class
031: *
032: */
033:
034: /**
035: * ###############################################################################
036: * ###############################################################################
037: * TODO: 1.
038: * ###############################################################################
039: * ###############################################################################
040: */
041:
042: public class RuntimeAdditionalTest41 extends TestCase {
043: /**
044: * create tree-process and cat-process, organize their one_byte-interconnection using flushing
045: */
046: public void test_39() {
047: System.out.println("==test_39===");
048: String tds = System.getProperty("java.io.tmpdir")
049: + File.separator + System.getProperty("user.name")
050: + "_" + System.getProperty("user.name") + "_"
051: + System.getProperty("user.name");
052: File fff = new File(tds);
053: fff.mkdir();
054: fff.deleteOnExit();
055: for (int ind = 0; ind < 300; ind++) {
056: (fff = new File(tds + File.separator
057: + System.getProperty("user.name")
058: + Integer.toString(ind, 10))).mkdir();
059: fff.deleteOnExit();
060: }
061: String cmnd1 = null;
062: String cmnd2 = null;
063: if (RuntimeAdditionalTest0.os.equals("Win")) {
064: //cmnd1 = RuntimeAdditionalTest0.cm + " /C tree \"C:\\Documents and Settings\"";
065: //cmnd2 = RuntimeAdditionalTest0.cm + " /C cat";
066: ///**/cmnd1 = "C:\\WINNT\\system32\\tree.com \"C:\\Documents and Settings\\All Users\"";
067: ///**/cmnd1 = "C:\\WINNT\\system32\\tree.com \""+tds+"\"";
068: /**/cmnd1 = RuntimeAdditionalTest0.treeStarter + " \""
069: + tds + "\"";
070: /**/System.out.println(cmnd1);
071: ///**/cmnd2 = "C:\\CygWin\\bin\\cat.exe";
072: /**/cmnd2 = RuntimeAdditionalTest0.catStarter;
073: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
074: //cmnd1 = "sh -c \"tree /lib\"";
075: //cmnd1 = "/usr/bin/tree /lib";
076: //cmnd1 = "/usr/bin/tree /bin";
077: //cmnd2 = "sh -c cat";
078: cmnd1 = RuntimeAdditionalTest0.treeStarter + " /bin";
079: cmnd2 = RuntimeAdditionalTest0.catStarter;
080: } else {
081: fail("WARNING (test_39): unknown operating system.");
082: }
083: try {
084:
085: //Process pi3 = Runtime.getRuntime().exec(cmnd1);
086: //Process pi4 = Runtime.getRuntime().exec(cmnd2);
087: Process pi3 = Runtime.getRuntime().exec(cmnd1);
088: try {
089: Thread.sleep(2000);
090: } catch (Exception e) {
091: }
092: pi3.getOutputStream();
093: pi3.getErrorStream();
094: java.io.InputStream is = pi3.getInputStream();
095: while ((is.available()) == 0) {
096: }
097: //System.out.println("control point 1");
098: /**/RuntimeAdditionalTest0.doMessage("control point 1");
099: Process pi4 = Runtime.getRuntime().exec(cmnd2);
100: java.io.OutputStream os4 = pi4.getOutputStream();
101: pi4.getErrorStream();
102: java.io.InputStream is4 = pi4.getInputStream();
103:
104: int b1;
105: int ia;
106: int ii = 0;
107: MMM: while (true) {
108: //System.out.println("control point 2");
109: while ((ia = is.available()) != 0) {
110: //System.out.println("control point 3");
111: if (RuntimeAdditionalTest0.os.equals("Win")) {
112: b1 = is.read();
113: os4.write(b1);
114: os4.write(10);
115: os4.flush();
116: //System.out.println("control point 4");
117: while ((ia = is4.available()) != 2) {
118: /**/RuntimeAdditionalTest0
119: .doMessage(Integer.toString(ia, 10)
120: + "\n");
121: try {
122: pi3.exitValue();
123: if (ii > 300 + 300 * System
124: .getProperty("user.name")
125: .length())
126: break MMM;
127: } catch (IllegalThreadStateException _) {
128: continue;
129: }
130: break;
131: }
132: //System.out.println("control point 5 "+ii);
133: if (ia > 2) {
134: byte[] bb = new byte[ia];
135: is4.read(bb);
136: if (ii < 200)
137: fail("ERROR (test_39): flush() problem.");
138: }
139: if (is4.available() > 0) /**/
140: System.out
141: .print(Character
142: .toString((char) /**/is4
143: .read()/**/))/**/;
144: if (is4.available() > 0)
145: is4.read();
146: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
147: os4.write(is.read());
148: os4.write(10);
149: os4.flush();
150: while ((ia = is4.available()) == 0) {
151: } //due to our available() impl
152: /*System.out.print(Character.toString((char)*/is4
153: .read()/*))*/;
154: while ((ia = is4.available()) == 0) {
155: } //due to our available() impl
156: is4.read();
157: try {
158: Thread.sleep(10);
159: } catch (Exception e) {
160: }
161: if (is4.available() > 0) {
162: byte[] bb = new byte[ia];
163: is4.read(bb);
164: fail("ERROR (test_39): flush() problem.");
165: }
166: }
167: ii++;
168: if (ii > 2000) {
169: break MMM;//return;
170: }
171: }
172: try {
173: pi3.exitValue();
174: while ((ia = is.available()) != 0) {
175: os4.write(is.read());
176: if ((ia = is4.available()) == 0) {
177: os4.flush();
178: if (is4.available() != 1) {
179: fail("ERROR (test_39): 3.");
180: }
181: } else if (ia > 1) {
182: fail("ERROR (test_39): 4.");
183: }
184: is4.read();
185: }
186: break;
187: } catch (IllegalThreadStateException e) {
188: continue;
189: }
190: }
191: try {
192: pi4.exitValue();
193: } catch (IllegalThreadStateException e) {
194: pi4.destroy();
195: }
196:
197: RuntimeAdditionalTest0.killCat();
198: RuntimeAdditionalTest0.killTree();
199: } catch (Exception eeee) {
200: eeee.printStackTrace();
201: fail("ERROR (test_39): unexpected exception.");
202: }
203: }
204: }
|