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