xref: /aoo41x/main/testtools/qa/cli/CLITest.java (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package clitest;
28 
29 
30 import complexlib.ComplexTestCase;
31 import java.io.*;
32 
33 public class CLITest extends ComplexTestCase
34 {
35     public String[] getTestMethodNames()
36     {
37         // TODO think about trigger of sub-tests from outside
38         return new String[]
39         {
40             "runCLITests"
41         };
42     }
43 
44     public void runCLITests()
45     {
46         try
47         {
48             String testProgram = System.getProperty("cli_test", "");
49             if (testProgram.length() == 0)
50                 failed("Check the make file. Java must be called with -Dcli_test=pathtoexe");
51 
52             String arg1 = System.getProperty("cli_test_arg", "");
53             if (arg1.length() == 0)
54                 failed("Check the make file. Java must be called with " +
55                        "-Dcli_test_arg=path_to_bootstrap_ini");
56             String[] cmdarray = new String[] {testProgram, arg1};
57 
58             Process proc = null;
59             Reader outReader;
60             Reader errReader;
61             try{
62 
63                 proc = Runtime.getRuntime().exec(cmdarray);
64                 outReader = new Reader(proc.getInputStream());
65                 errReader = new Reader(proc.getErrorStream());
66 
67 
68             }
69             catch(Exception e)
70             {
71                 System.out.println("\n ###" +  e.getMessage() + "\n");
72 
73             }
74 //           System.out.println("### waiting for " + testProgram);
75             proc.waitFor();
76 //            System.out.println("### " + testProgram + " finished");
77             int retVal = proc.exitValue();
78             if (retVal != 0)
79                 failed("CLI test failed.");
80         } catch( java.lang.Exception e)
81         {
82             failed("Unexpected exception.");
83         }
84 
85     }
86 }
87 
88 
89 /*  This reads reads from an InputStream and discards the data.
90  */
91 class Reader extends Thread
92 {
93     InputStream is;
94     public Reader(InputStream stream)
95     {
96         is = stream;
97         start();
98     }
99 
100     public void run()
101     {
102         try
103         {
104             byte[] buf = new byte[1024];
105             while (-1 != is.read(buf));
106         }
107         catch (java.io.IOException exc)
108         {
109         }
110     }
111 }
112