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 junit.framework.TestCase;
024:
025: /*
026: * Created on March 29, 2006
027: *
028: * This RuntimeAdditionalTest class is used to test the Core API Runtime class
029: *
030: */
031:
032: /**
033: * ###############################################################################
034: * ###############################################################################
035: * TODO: 1.
036: * ###############################################################################
037: * ###############################################################################
038: */
039:
040: public class RuntimeAdditionalTest34 extends TestCase {
041: /**
042: * creat two cat-process, one_byte-read from one one_byte-write (using
043: * flushing) to another and one_byte-read there again
044: */
045: public void test_33() { // it, maybe, hangs the test set run
046: System.out.println("==test_33===");
047: //String cmnd = null;
048: String cmnd1 = null;
049: String cmnd2 = null;
050: if (RuntimeAdditionalTest0.os.equals("Win")) {
051: //cmnd1 = RuntimeAdditionalTest0.cm + " /C tree \"C:\\Documents and Settings\"";
052: //cmnd2 = RuntimeAdditionalTest0.cm + " /C cat";
053: cmnd1 = RuntimeAdditionalTest0.treeStarter
054: + " \"C:\\Documents and Settings\"";
055: cmnd2 = RuntimeAdditionalTest0.catStarter;
056: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
057: //cmnd1 = "sh -c \"tree /lib\"";
058: //cmnd1 = "/usr/bin/tree /lib";
059: //cmnd1 = "/usr/bin/tree /bin";
060: //cmnd2 = "sh -c cat";
061: cmnd1 = RuntimeAdditionalTest0.treeStarter + " /bin";
062: cmnd2 = RuntimeAdditionalTest0.catStarter;
063: } else {
064: fail("WARNING (test_1): unknown operating system.");
065: }
066: try {
067: Process pi3 = Runtime.getRuntime().exec(cmnd1);
068: Process pi4 = Runtime.getRuntime().exec(cmnd2);
069: pi3.getOutputStream();
070: pi3.getErrorStream();
071: java.io.InputStream is = pi3.getInputStream();
072: java.io.OutputStream os4 = pi4.getOutputStream();
073: pi4.getErrorStream();
074: java.io.InputStream is4 = pi4.getInputStream();
075:
076: int b1;
077: //int b2;
078: while (true) {
079: while ((is.available()) != 0) {
080: b1 = is.read();
081: os4.write(b1);
082: while ((is4.available()) != 0) {
083: /*b2 =*/is4.read();
084: ///* if (b1!=b2) */System.out.print(Character
085: // .toString((char) b2));
086: }
087: }
088: try {
089: pi3.exitValue();
090: while ((is.available()) != 0) {
091: b1 = is.read();
092: os4.write(b1);
093: while ((is4.available()) != 0) {
094: /*b2 =*/is4.read();
095: //\\//\\System.out.print(Character.toString((char)b2));
096: }
097: }
098: break;
099: } catch (IllegalThreadStateException e) {
100: Thread.sleep(20);
101: continue;
102: }
103: }
104:
105: } catch (Exception eeee) {
106: eeee.printStackTrace();
107: fail("ERROR (test_33): unexpected exception.");
108: }
109: RuntimeAdditionalTest0.killCat();
110: }
111: }
|