xref: /AOO42X/main/testtools/qa/cli/CLITest.java (revision b0efeae40e43e6d4ccd561d22ec612d42773857b)
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 <<<<<<< HEAD
41     public void runCLITests()
42     {
43         try
44         {
45             String testProgram = System.getProperty("cli_test", "");
46             if (testProgram.length() == 0)
47                 failed("Check the make file. Java must be called with -Dcli_test=pathtoexe");
48 =======
49         String arg1 = System.getProperty("cli_test_arg", "");
50         if (arg1.length() == 0)
51             fail("Check the make file. Java must be called with " +
52                  "-Dcli_test_arg=path_to_bootstrap_ini");
53         String[] cmdarray = new String[] {testProgram, arg1};
54 >>>>>>> 3309286857 (pre-commit auto remove trailing whitespace from java files (#382))
55 
56             String arg1 = System.getProperty("cli_test_arg", "");
57             if (arg1.length() == 0)
58                 failed("Check the make file. Java must be called with " +
59                        "-Dcli_test_arg=path_to_bootstrap_ini");
60             String[] cmdarray = new String[] {testProgram, arg1};
61 
62             Process proc = null;
63             Reader outReader;
64             Reader errReader;
65             try{
66 
67                 proc = Runtime.getRuntime().exec(cmdarray);
68                 outReader = new Reader(proc.getInputStream());
69                 errReader = new Reader(proc.getErrorStream());
70 
71 
72             }
73             catch(Exception e)
74             {
75                 System.out.println("\n ###" +  e.getMessage() + "\n");
76 
77             }
78 //           System.out.println("### waiting for " + testProgram);
79             proc.waitFor();
80 //            System.out.println("### " + testProgram + " finished");
81             int retVal = proc.exitValue();
82             if (retVal != 0)
83                 failed("CLI test failed.");
84         } catch( java.lang.Exception e)
85         {
86             failed("Unexpected exception.");
87         }
88 
89     }
90 }
91 
92 
93 /*  This reads reads from an InputStream and discards the data.
94  */
95 class Reader extends Thread
96 {
97     InputStream is;
98     public Reader(InputStream stream)
99     {
100         is = stream;
101         start();
102     }
103 
104     public void run()
105     {
106         try
107         {
108             byte[] buf = new byte[1024];
109             while (-1 != is.read(buf));
110         }
111         catch (java.io.IOException exc)
112         {
113         }
114     }
115 }
116