Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / testtools / qa / cli / CLITest.java
blob68cc5dbd40fbda94640642cfdca1e8881925695e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 package clitest;
30 import complexlib.ComplexTestCase;
31 import java.io.*;
33 public class CLITest extends ComplexTestCase
35 public String[] getTestMethodNames()
37 // TODO think about trigger of sub-tests from outside
38 return new String[]
40 "runCLITests"
44 public void runCLITests()
46 try
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");
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};
58 Process proc = null;
59 Reader outReader;
60 Reader errReader;
61 try{
63 proc = Runtime.getRuntime().exec(cmdarray);
64 outReader = new Reader(proc.getInputStream());
65 errReader = new Reader(proc.getErrorStream());
69 catch(Exception e)
71 System.out.println("\n ###" + e.getMessage() + "\n");
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)
82 failed("Unexpected exception.");
89 /* This reads reads from an InputStream and discards the data.
91 class Reader extends Thread
93 InputStream is;
94 public Reader(InputStream stream)
96 is = stream;
97 start();
100 public void run()
104 byte[] buf = new byte[1024];
105 while (-1 != is.read(buf));
107 catch (java.io.IOException exc)