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