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. should be adopted for linux
038: * ###############################################################################
039: * ###############################################################################
040: */
041:
042: public class RuntimeAdditionalTest10 extends TestCase {
043: /**
044: * read, write info using streams of two process (cat <->java) using the
045: * "exitValue - IllegalThreadStateException" loop to try to read p1-out to
046: * write p2-in and to read p2-out again to calculate bytes to check their
047: * equality
048: */
049: public void test_11() {
050: System.out.println("==test_11===");
051: //String cmnd = null;
052: String cmnd1 = null;
053: String cmnd2 = null;
054: if (RuntimeAdditionalTest0.os.equals("Win")) {
055: //cmnd1 = RuntimeAdditionalTest0.cm+" /C cat \"C:\\WINNT\\system32\\cmd.exe\"";
056: //\\//\\cmnd1 = RuntimeAdditionalTest0.cm+" /C cat \"C:\\IJE\\orp\\ZSS\\___LOG.1\"";
057: cmnd1 = RuntimeAdditionalTest0.cm + " /C cat \""
058: + RuntimeAdditionalTest0.textFile + "\"";
059: //cmnd1 = RuntimeAdditionalTest0.cm+" /C cat \"C:\\Documents and Settings\\All
060: // Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg\"";
061: //cmnd2 = RuntimeAdditionalTest0.cm+" /C cat";
062: //\\//\\cmnd2 = "java -cp
063: // \""+System.getProperty("java.class.path")+"\" RuntimeAdditionalSupport2";
064: // cmnd2 = "java "
065: // + (System.getProperty("java.class.path").length() > 0 ? "-cp "
066: // + System.getProperty("java.class.path")
067: // : "") + " klazz2";
068: String ttt = System.getProperty("vm.boot.class.path")
069: + (System.getProperty("java.class.path").length() > 0 ? File.pathSeparator
070: + System.getProperty("java.class.path")
071: : "");
072: cmnd2 = RuntimeAdditionalTest0.javaStarter
073: + " -Xbootclasspath/a:" + ttt + " -cp " + ttt
074: + " java.lang.RuntimeAdditionalSupport2";
075: // System.out.println(cmnd2);
076: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
077: //cmnd = "sh -c \"cat -v /lib/ld.so\"";
078: //\\//\\cmnd1 = "cat -v /lib/ld.so";
079: cmnd1 = "/bin/cat -v \"" + RuntimeAdditionalTest0.libFile
080: + "\"";
081: //cmnd2 = "sh -c cat";
082: //\\//\\cmnd2 = "java -cp
083: // \""+System.getProperty("java.class.path")+"\" RuntimeAdditionalSupport2";
084: // cmnd2 = "java "
085: // + (System.getProperty("java.class.path").length() > 0 ? "-cp "
086: // + System.getProperty("java.class.path")
087: // : "") + " RuntimeAdditionalSupport2";
088: String ttt = System.getProperty("vm.boot.class.path")
089: + (System.getProperty("java.class.path").length() > 0 ? File.pathSeparator
090: + System.getProperty("java.class.path")
091: : "");
092: cmnd2 = RuntimeAdditionalTest0.javaStarter
093: + " -Xbootclasspath/a:" + ttt + " -cp " + ttt
094: + " java.lang.RuntimeAdditionalSupport2";
095: //System.out.println(cmnd2);
096: return;
097: } else {
098: fail("WARNING (test_1): unknown operating system.");
099: }
100:
101: Process pi3 = null;
102: Process pi4 = null;
103: try {
104: pi3 = Runtime.getRuntime().exec(cmnd1);
105: pi4 = Runtime.getRuntime().exec(cmnd2);
106: try {
107: Thread.sleep(2000);
108: } catch (Exception e) {
109: }
110: pi3.getOutputStream();
111: pi3.getErrorStream();
112: java.io.InputStream is = pi3.getInputStream();
113: java.io.OutputStream os4 = pi4.getOutputStream();
114: pi4.getErrorStream();
115: java.io.InputStream is4 = pi4.getInputStream();
116: while (is4.available() == 0) {
117: }
118: Thread.sleep(1000);
119: byte[] bbb5 = new byte[is4.available()];
120: is4.read(bbb5);
121: //System.out.println(new String(bbb5));
122: int c1 = 0;
123: int c2 = 0;
124: //int s1 = 0;
125: //int s2 = 0;
126: while (true) {
127: try {
128: while ((is.available()) != 0) {
129: os4.write(/*s1 = */is.read());
130: c1++;
131: os4.write(10);
132: c1++;
133: try {
134: os4.flush();
135: } catch (java.io.IOException e) {
136: }
137: /* System.out.println(Character.toString((char)( s2 =*/is4
138: .read()/* ))) */;
139: /* System.out.println(Character.toString((char)( s2 =*/is4
140: .read()/* ))) */;
141: c2 += 2;
142: /*
143: * while ((is4.available()) != 0) { c2++;
144: * System.out.println(Character.toString((char)(s2=is4.read())));
145: * System.out.println(s1+"|"+s2); try {
146: * Thread.sleep(1000); } catch (Exception e) { } }
147: */
148: }
149: //System.out.println(7777777);
150: pi3.exitValue();
151: break;
152: } catch (IllegalThreadStateException e) {
153: continue;
154: }
155: }
156: while (true) {
157: try {
158: while ((is4.available()) != 0) {
159: c2++;
160: /* System.out.println(Character.toString((char) */is4
161: .read()/* )) */;
162: }
163: //System.out.println(888888);
164: if (c2 == c1) {
165: if ((is4.available()) == 0) {
166: //System.out.println("test_11 PASSED.");
167: } else {
168: fail("test_11 FAILED.");
169: }
170: try {
171: pi4.exitValue();
172: } catch (IllegalThreadStateException e) {
173: pi4.destroy();
174: return;
175: }
176: } else if (is4.available() == 0) {
177: int i = 0;
178: for (; i < 500; i++) {
179: if (is4.available() != 0) {
180: break;
181: }
182: try {
183: Thread.sleep(10);
184: } catch (Exception e) {
185: }
186: }
187: //System.out.println(i);
188: if (i == 500 && is4.available() == 0) {
189: //System.out.println(c1+"|"+c2);
190: try {
191: pi4.exitValue();
192: } catch (IllegalThreadStateException e) {
193: pi4.destroy();
194: }
195: fail("test_11 FAILED.");
196: }
197: }
198: } catch (IllegalThreadStateException e) {
199: continue;
200: }
201: }
202:
203: } catch (Exception eeee) {
204: eeee.printStackTrace();
205: fail("ERROR (test_11): unexpected exception.");
206: }
207: try {
208: pi3.exitValue();
209: } catch (IllegalThreadStateException e) {
210: pi3.destroy();
211: }
212: try {
213: pi4.exitValue();
214: } catch (IllegalThreadStateException e) {
215: pi4.destroy();
216: }
217: }
218: }
|