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 RuntimeAdditionalTest11 extends TestCase {
041:
042: /**
043: * read, write info using streams of two process (cat jpg/so <->cat) using
044: * the "exitValue - IllegalThreadStateException" loop to try to read p1-out
045: * to write p2-in and to read p2-out again
046: */
047: public void test_11_1() {
048: System.out.println("==test_11_1===");
049: //String cmnd = null;
050: String cmnd1 = null;
051: String cmnd2 = null;
052: if (RuntimeAdditionalTest0.os.equals("Win")) {
053: //cmnd1 = RuntimeAdditionalTest0.cm+" /C cat \"C:\\WINNT\\system32\\cmd.exe\"";
054: //\\//\\cmnd1 = RuntimeAdditionalTest0.cm+" /C cat \"C:\\Documents and Settings\\All
055: // Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg\"";
056: //cmnd1 = RuntimeAdditionalTest0.cm + " /C cat \"" + RuntimeAdditionalTest0.libFile + "\"";
057: //cmnd2 = RuntimeAdditionalTest0.cm + " /C cat";
058: cmnd1 = RuntimeAdditionalTest0.catStarter + " \""
059: + RuntimeAdditionalTest0.libFile + "\"";
060: cmnd2 = RuntimeAdditionalTest0.catStarter;
061: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
062: //cmnd = "sh -c \"cat -v /lib/ld.so\"";
063: //\\//\\cmnd1 = "cat -v /lib/ld.so";
064: //cmnd1 = "cat -v \"" + RuntimeAdditionalTest0.libFile + "\"";
065: //cmnd2 = "sh -c cat";
066: //cmnd1 = RuntimeAdditionalTest0.catStarter + " -v \"" + RuntimeAdditionalTest0.textFile + "\"";
067: cmnd1 = "/bin/sh -c \"cat "
068: + RuntimeAdditionalTest0.textFile + "\"";
069: cmnd1 = "/bin/cat \"" + RuntimeAdditionalTest0.textFile
070: + "\"";
071: cmnd1 = "/bin/cat " + RuntimeAdditionalTest0.textFile;
072: //cmnd1 = "/usr/bin/pr " + RuntimeAdditionalTest0.textFile;
073: cmnd2 = RuntimeAdditionalTest0.catStarter;
074: } else {
075: fail("WARNING (test_1): unknown operating system.");
076: }
077:
078: try {
079: Process pi3 = Runtime.getRuntime().exec(cmnd1);
080: RuntimeAdditionalTest0.doMessage(cmnd1 + "\n");//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
081: //if(System.getProperty("java.vm.name").indexOf("DRL")!=-1){RuntimeAdditionalTest0.killCat();int i=0,j=0; i=i/j;}
082: //Process pi4 = Runtime.getRuntime().exec(cmnd2);//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
083: //try {
084: // Thread.sleep(2000);
085: //} catch (Exception e) {
086: //}
087: //pi3.getOutputStream();
088: //pi3.getErrorStream();
089:
090: java.io.InputStream is = pi3.getInputStream();
091: ///**/RuntimeAdditionalTest0.doMessage("1:"+cmnd1+"\n");
092: while ((is.available()) == 0) {
093: RuntimeAdditionalTest0.doMessage("1\n");
094: }//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
095: Process pi4 = Runtime.getRuntime().exec(cmnd2);//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
096: java.io.OutputStream os4 = pi4.getOutputStream();
097: pi4.getErrorStream();
098: java.io.InputStream is4 = pi4.getInputStream();
099:
100: int ia;
101: int ia3 = 0;
102: while (true) {
103: RuntimeAdditionalTest0.doMessage(Integer.toString(is
104: .available(), 10)
105: + "1\n");
106: while ((ia = is.available()) != 0) {
107: byte[] bbb = new byte[ia];
108: is.read(bbb);
109: //System.out.println(new String(bbb));
110: //RuntimeAdditionalTest0.doMessage("2:"+new String(bbb)+"\n");
111: os4.write(bbb);
112: int ia2 = 0;
113: while (ia != is4.available()) {
114: ///////////////////////////////////////////////////////////////////////////////////////
115: /**/os4.flush(); //NU, JRK POGODI!
116: ///////////////////////////////////////////////////////////////////////////////////////
117: ia2++;
118: if (ia2 > 5) {
119: System.out
120: .println("Warning (test_11): something wrong in the test - to investigate.");
121: //RuntimeAdditionalTest0.killCat();
122: break;//return;
123: }
124: }
125: while ((ia = is4.available()) != 0) {
126: byte[] bbb4 = new byte[ia];
127: is4.read(bbb4);
128: System.out.println("zz|" + new String(bbb4)
129: + "|zz");
130: //\\//\\System.out.println(new String(bbb4));
131: }
132: }
133: try {
134: pi3.exitValue();
135: while ((ia = is.available()) != 0) {
136: byte[] bbb = new byte[ia];
137: is.read(bbb);
138: os4.write(bbb);
139: while ((ia = is4.available()) != 0) {
140: byte[] bbb4 = new byte[ia];
141: is4.read(bbb4);
142: //\\//\\System.out.println(new String(bbb4));
143: }
144: }
145: break;
146: } catch (IllegalThreadStateException e) {
147: if (ia3++ > 100) {
148: RuntimeAdditionalTest0.killCat();
149: return;
150: }
151: continue;
152: }
153: }
154: } catch (Exception eeee) {
155: eeee.printStackTrace();
156: fail("ERROR (test_11): unexpected exception.");
157: }
158: RuntimeAdditionalTest0.killCat();
159: }
160: }
|