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