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