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