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 RuntimeAdditionalTest30 extends TestCase {
041: /**
042: * create tree(/bin for lin)-process, get streams, read input stream
043: * partialy, destroy process, read the rest then exitValue
044: */
045: public void test_30() {
046: System.out.println("==test_30===");
047: String cmnd = null;
048: if (RuntimeAdditionalTest0.os.equals("Win")) {
049: //cmnd = RuntimeAdditionalTest0.cm + " /C tree \"C:\\Documents and Settings\"";
050: cmnd = RuntimeAdditionalTest0.treeStarter
051: + " \"C:\\Documents and Settings\"";
052: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
053: //cmnd = "sh -c \"tree /lib\"";
054: //cmnd = "/usr/bin/tree /lib";
055: ///**/cmnd = "/usr/bin/tree /bin";
056: /**/cmnd = RuntimeAdditionalTest0.treeStarter + " /bin";
057: //cmnd = "/usr/bin/tree /";
058: } else {
059: fail("WARNING (test_1): unknown operating system.");
060: }
061:
062: try {
063: Process pi3 = Runtime.getRuntime().exec(cmnd);
064: try {
065: Thread.sleep(2000);
066: } catch (Exception e) {
067: }
068: pi3.getOutputStream();
069: pi3.getErrorStream();
070: java.io.InputStream is = pi3.getInputStream();
071:
072: int ia;
073: //int num = 0;
074: while (true) {
075: while ((ia = is.available()) != 0) {
076: //num += ia;
077: //if (num > 5000) {
078: // pi3.destroy();
079: //}
080: byte[] bbb = new byte[ia];
081: is.read(bbb);
082: ///* //\\//\\ */System.out.println(new String(bbb));
083: ///* //\\//\\ */System.out
084: // .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "
085: // + ia);
086: //Thread.sleep(1000);
087: }
088: try {
089: pi3.exitValue();
090: while ((ia = is.available()) != 0) {
091: byte[] bbb = new byte[ia];
092: is.read(bbb);
093: //\\//\\System.out.println(new String(bbb));
094: //\\//\\System.out.println(ia);
095: //Thread.sleep(1000);
096: }
097: break;
098: } catch (IllegalThreadStateException e) {
099: continue;
100: }
101: }
102: /*System.out.println(*/pi3.exitValue()/*)*/;
103: } catch (Exception eeee) {
104: eeee.printStackTrace();
105: fail("ERROR (test_30): unexpected exception.");
106: }
107: }
108: }
|