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 RuntimeAdditionalTest32 extends TestCase {
041: /**
042: * create tree(/bin for lin)-process, get streams, read input stream
043: * partialy, destroy process, read (trying to destroy
044: * repeatedly-intermediately) the rest then exitValue
045: */
046: public void test_31() {
047: System.out.println("==test_31===");
048: String cmnd = null;
049: if (RuntimeAdditionalTest0.os.equals("Win")) {
050: //cmnd = RuntimeAdditionalTest0.cm + " /C tree \"C:\\Documents and Settings\"";
051: cmnd = RuntimeAdditionalTest0.treeStarter
052: + " \"C:\\Documents and Settings\"";
053: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
054: //cmnd = "sh -c \"tree /lib\"";
055: //cmnd = "/usr/bin/tree /lib";
056: //cmnd = "/usr/bin/tree /bin";
057: cmnd = RuntimeAdditionalTest0.treeStarter + " /bin";
058: } else {
059: fail("WARNING (test_1): unknown operating system.");
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: byte[] bbb = new byte[ia];
076: is.read(bbb);
077: //\\//\\System.out.println(new String(bbb));
078: //\\//\\System.out.println(ia);
079: //Thread.sleep(1000);
080: num += ia;
081: if (num > 5000) {
082: pi3.destroy();
083: break;
084: }
085: }
086: try {
087: pi3.exitValue();
088: while ((ia = is.available()) != 0) {
089: byte[] bbb = new byte[ia];
090: is.read(bbb);
091: //\\//\\System.out.println(new String(bbb));
092: //\\//\\System.out.println(ia);
093: //Thread.sleep(1000);
094: num += ia;
095: if (num > 10000) {
096: pi3.destroy();
097: break;
098: }
099: }
100: break;
101: } catch (IllegalThreadStateException e) {
102: if (num > 10000) {
103: pi3.destroy();
104: break;
105: }
106: }
107: }
108: /*System.out.println(*/pi3.exitValue()/*)*/;
109: } catch (Exception eeee) {
110: eeee.printStackTrace();
111: fail("ERROR (test_31): unexpected exception.");
112: }
113: RuntimeAdditionalTest0.killTree();
114: }
115: }
|