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 cliversion;
24 
25 
26 import complexlib.ComplexTestCase;
27 
28 
29 public class VersionTestCase extends ComplexTestCase
30 {
getTestMethodNames()31     public String[] getTestMethodNames()
32     {
33         return new String[]
34         {
35             "checkVersion"
36         };
37     }
38 
checkVersion()39     public void checkVersion()
40     {
41         int retVal = 0;
42         try
43         {
44             String testProgram = System.getProperty("cli_test_program");
45             if (testProgram == null || testProgram.length() == 0)
46                 failed("Check the make file. Java must be called with -Dcli_ure_test=pathtoexe");
47             String unoPath = System.getProperty("path");
48             if (unoPath == null || unoPath.length() == 0)
49                 failed("Check the make file. Java must be called with -Duno_path=path_to_ure_bin_folder");
50             String sSystemRoot = System.getProperty("SystemRoot");
51             if (sSystemRoot == null || sSystemRoot.length() == 0)
52                 failed("Check the make file. Java  must be called with -DSystemRoot=%SystemRoot%.");
53 
54 //            System.out.println("UNO_PATH="+unoPath);
55             //We need to set the PATH because otherwise it appears that runtests inherits the PATH
56             //from build environment. Then the bootstrapping fails because the libraries
57             //are not used from the office.
58             //.NET 2 requires SystemRoot being set.
59             String[] arEnv = new String[] {
60                     "PATH=" + unoPath, "SystemRoot=" + sSystemRoot};
61             Process proc = null;
62 
63             proc = Runtime.getRuntime().exec(testProgram, arEnv);
64             Reader outReader = new Reader(proc.getInputStream());
65             Reader errReader = new Reader(proc.getErrorStream());
66             proc.waitFor();
67             retVal = proc.exitValue();
68         } catch(Exception e)
69         {
70             e.printStackTrace();
71             System.out.println(e.getMessage());
72             failed("Unexpected exception.");
73         }
74         if (retVal != 0)
75             failed("Tests for library versioning failed.");
76     }
77 }
78 
79 
80 /*  This reads reads from an InputStream and discards the data.
81  */
82 class Reader extends Thread
83 {
84     java.io.InputStream is;
Reader(java.io.InputStream stream)85     public Reader(java.io.InputStream stream)
86     {
87         is = stream;
88         start();
89     }
90 
run()91     public void run()
92     {
93         try
94         {
95             byte[] buf = new byte[1024];
96             while (-1 != is.read(buf));
97         }
98         catch (java.io.IOException exc)
99         {
100         }
101     }
102 }
103