xref: /trunk/main/testtools/qa/cli/CLITest.java (revision 5c44d1b3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package clitest;
24 
25 
26 import complexlib.ComplexTestCase;
27 import java.io.*;
28 
29 public class CLITest extends ComplexTestCase
30 {
31     public String[] getTestMethodNames()
32     {
33         // TODO think about trigger of sub-tests from outside
34         return new String[]
35         {
36             "runCLITests"
37         };
38     }
39 
40     public void runCLITests()
41     {
42         try
43         {
44             String testProgram = System.getProperty("cli_test", "");
45             if (testProgram.length() == 0)
46                 failed("Check the make file. Java must be called with -Dcli_test=pathtoexe");
47 
48             String arg1 = System.getProperty("cli_test_arg", "");
49             if (arg1.length() == 0)
50                 failed("Check the make file. Java must be called with " +
51                        "-Dcli_test_arg=path_to_bootstrap_ini");
52             String[] cmdarray = new String[] {testProgram, arg1};
53 
54             Process proc = null;
55             Reader outReader;
56             Reader errReader;
57             try{
58 
59                 proc = Runtime.getRuntime().exec(cmdarray);
60                 outReader = new Reader(proc.getInputStream());
61                 errReader = new Reader(proc.getErrorStream());
62 
63 
64             }
65             catch(Exception e)
66             {
67                 System.out.println("\n ###" +  e.getMessage() + "\n");
68 
69             }
70 //           System.out.println("### waiting for " + testProgram);
71             proc.waitFor();
72 //            System.out.println("### " + testProgram + " finished");
73             int retVal = proc.exitValue();
74             if (retVal != 0)
75                 failed("CLI test failed.");
76         } catch( java.lang.Exception e)
77         {
78             failed("Unexpected exception.");
79         }
80 
81     }
82 }
83 
84 
85 /*  This reads reads from an InputStream and discards the data.
86  */
87 class Reader extends Thread
88 {
89     InputStream is;
90     public Reader(InputStream stream)
91     {
92         is = stream;
93         start();
94     }
95 
96     public void run()
97     {
98         try
99         {
100             byte[] buf = new byte[1024];
101             while (-1 != is.read(buf));
102         }
103         catch (java.io.IOException exc)
104         {
105         }
106     }
107 }
108