xref: /AOO41X/main/testtools/qa/cliversioning/VersionTestCase.java (revision 5c44d1b36a617948eb37f3a4224ecb71d4faa9a5)
1*5c44d1b3SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5c44d1b3SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5c44d1b3SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5c44d1b3SAndrew Rist  * distributed with this work for additional information
6*5c44d1b3SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5c44d1b3SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5c44d1b3SAndrew Rist  * "License"); you may not use this file except in compliance
9*5c44d1b3SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5c44d1b3SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5c44d1b3SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5c44d1b3SAndrew Rist  * software distributed under the License is distributed on an
15*5c44d1b3SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5c44d1b3SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5c44d1b3SAndrew Rist  * specific language governing permissions and limitations
18*5c44d1b3SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5c44d1b3SAndrew Rist  *************************************************************/
21*5c44d1b3SAndrew Rist 
22*5c44d1b3SAndrew Rist 
23cdf0e10cSrcweir package cliversion;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import complexlib.ComplexTestCase;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir public class VersionTestCase extends ComplexTestCase
30cdf0e10cSrcweir {
getTestMethodNames()31cdf0e10cSrcweir     public String[] getTestMethodNames()
32cdf0e10cSrcweir     {
33cdf0e10cSrcweir         return new String[]
34cdf0e10cSrcweir         {
35cdf0e10cSrcweir             "checkVersion"
36cdf0e10cSrcweir         };
37cdf0e10cSrcweir     }
38cdf0e10cSrcweir 
checkVersion()39cdf0e10cSrcweir     public void checkVersion()
40cdf0e10cSrcweir     {
41cdf0e10cSrcweir         int retVal = 0;
42cdf0e10cSrcweir         try
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir             String testProgram = System.getProperty("cli_test_program");
45cdf0e10cSrcweir             if (testProgram == null || testProgram.length() == 0)
46cdf0e10cSrcweir                 failed("Check the make file. Java must be called with -Dcli_ure_test=pathtoexe");
47cdf0e10cSrcweir             String unoPath = System.getProperty("path");
48cdf0e10cSrcweir             if (unoPath == null || unoPath.length() == 0)
49cdf0e10cSrcweir                 failed("Check the make file. Java must be called with -Duno_path=path_to_ure_bin_folder");
50cdf0e10cSrcweir             String sSystemRoot = System.getProperty("SystemRoot");
51cdf0e10cSrcweir             if (sSystemRoot == null || sSystemRoot.length() == 0)
52cdf0e10cSrcweir                 failed("Check the make file. Java  must be called with -DSystemRoot=%SystemRoot%.");
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //            System.out.println("UNO_PATH="+unoPath);
55cdf0e10cSrcweir             //We need to set the PATH because otherwise it appears that runtests inherits the PATH
56cdf0e10cSrcweir             //from build environment. Then the bootstrapping fails because the libraries
57cdf0e10cSrcweir             //are not used from the office.
58cdf0e10cSrcweir             //.NET 2 requires SystemRoot being set.
59cdf0e10cSrcweir             String[] arEnv = new String[] {
60cdf0e10cSrcweir                     "PATH=" + unoPath, "SystemRoot=" + sSystemRoot};
61cdf0e10cSrcweir             Process proc = null;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir             proc = Runtime.getRuntime().exec(testProgram, arEnv);
64cdf0e10cSrcweir             Reader outReader = new Reader(proc.getInputStream());
65cdf0e10cSrcweir             Reader errReader = new Reader(proc.getErrorStream());
66cdf0e10cSrcweir             proc.waitFor();
67cdf0e10cSrcweir             retVal = proc.exitValue();
68cdf0e10cSrcweir         } catch(Exception e)
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             e.printStackTrace();
71cdf0e10cSrcweir             System.out.println(e.getMessage());
72cdf0e10cSrcweir             failed("Unexpected exception.");
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir         if (retVal != 0)
75cdf0e10cSrcweir             failed("Tests for library versioning failed.");
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir /*  This reads reads from an InputStream and discards the data.
81cdf0e10cSrcweir  */
82cdf0e10cSrcweir class Reader extends Thread
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     java.io.InputStream is;
Reader(java.io.InputStream stream)85cdf0e10cSrcweir     public Reader(java.io.InputStream stream)
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         is = stream;
88cdf0e10cSrcweir         start();
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
run()91cdf0e10cSrcweir     public void run()
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         try
94cdf0e10cSrcweir         {
95cdf0e10cSrcweir             byte[] buf = new byte[1024];
96cdf0e10cSrcweir             while (-1 != is.read(buf));
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         catch (java.io.IOException exc)
99cdf0e10cSrcweir         {
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir }
103