1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package convwatch; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import complexlib.ComplexTestCase; 27cdf0e10cSrcweir import helper.ProcessHandler; 28cdf0e10cSrcweir import convwatch.GraphicalTestArguments; 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir * Some Helperfunctions which are nice in ReferenceBuilder and ConvWatchTest 32cdf0e10cSrcweir */ 33cdf0e10cSrcweir 34cdf0e10cSrcweir public abstract class EnhancedComplexTestCase extends ComplexTestCase 35cdf0e10cSrcweir { 36cdf0e10cSrcweir // public void before() 37cdf0e10cSrcweir // { 38cdf0e10cSrcweir // // System.out.println("before()"); 39cdf0e10cSrcweir // } 40cdf0e10cSrcweir // 41cdf0e10cSrcweir // public void after() 42cdf0e10cSrcweir // { 43cdf0e10cSrcweir // // System.out.println("after()"); 44cdf0e10cSrcweir // } 45cdf0e10cSrcweir checkExistance(String _sScriptFile, String _sName)46cdf0e10cSrcweir void checkExistance(String _sScriptFile, String _sName) 47cdf0e10cSrcweir { 48cdf0e10cSrcweir boolean bBackValue = false; 49cdf0e10cSrcweir // Process testshl = Runtime.getRuntime().exec(scriptFile); 50cdf0e10cSrcweir ProcessHandler aHandler = new ProcessHandler(_sScriptFile); 51cdf0e10cSrcweir bBackValue = aHandler.executeSynchronously(); 52cdf0e10cSrcweir TimeHelper.waitInSeconds(1, "wait after ProcessHandler.executeSynchronously()"); 53cdf0e10cSrcweir 54cdf0e10cSrcweir StringBuffer aBuffer = new StringBuffer(); 55cdf0e10cSrcweir aBuffer.append(aHandler.getErrorText()).append(aHandler.getOutputText()); 56cdf0e10cSrcweir String sText = aBuffer.toString(); 57cdf0e10cSrcweir 58cdf0e10cSrcweir if (sText.length() == 0) 59cdf0e10cSrcweir { 60*bb6af6bcSPedro Giffuni String sError = "Must quit. " + _sName + " may be not accessible."; 61cdf0e10cSrcweir assure(sError, false); 62cdf0e10cSrcweir // System.exit(1); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir else 65cdf0e10cSrcweir { 66cdf0e10cSrcweir // System.out.println("Output from script:"); 67cdf0e10cSrcweir // System.out.println(sText); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir // ----------------------------------------------------------------------------- 72cdf0e10cSrcweir checkEnvironment(Object[] _aList)73cdf0e10cSrcweir protected void checkEnvironment(Object[] _aList) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir // checks if some packages already installed, 76cdf0e10cSrcweir // this function will not return if packages are not installed, 77cdf0e10cSrcweir // it will call System.exit(1)! 78cdf0e10cSrcweir 79cdf0e10cSrcweir if (needCheckForInstalledSoftware()) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir for (int i=0;i<_aList.length;i++) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir String sCommand = (String)_aList[i]; 84cdf0e10cSrcweir // TODO: nice to have, a pair object 85cdf0e10cSrcweir checkExistance(sCommand, sCommand); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir } 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir // ----------------------------------------------------------------------------- 91cdf0e10cSrcweir mustInstalledSoftware()92cdf0e10cSrcweir protected abstract Object[] mustInstalledSoftware(); needCheckForInstalledSoftware()93cdf0e10cSrcweir public boolean needCheckForInstalledSoftware() 94cdf0e10cSrcweir { 95cdf0e10cSrcweir String sNEEDCHECK = (String)param.get( PropertyName.CHECK_NEED_TOOLS ); 96cdf0e10cSrcweir // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns 97cdf0e10cSrcweir // with a default of 'false' which is not very helpful if the default should be 'true' 98cdf0e10cSrcweir // maybe a getBoolean("name", true) could be a better choise. 99cdf0e10cSrcweir if (sNEEDCHECK == null) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir sNEEDCHECK = "false"; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir if (sNEEDCHECK.toLowerCase().equals("yes") || 104cdf0e10cSrcweir sNEEDCHECK.toLowerCase().equals("true")) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir return true; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir return false; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ----------------------------------------------------------------------------- 112cdf0e10cSrcweir getGraphicalTestArguments()113cdf0e10cSrcweir public GraphicalTestArguments getGraphicalTestArguments() 114cdf0e10cSrcweir { 115cdf0e10cSrcweir GraphicalTestArguments aGTA = new GraphicalTestArguments(param); 116cdf0e10cSrcweir if (aGTA.getImportFilterName() != null && aGTA.getImportFilterName().toLowerCase().equals("help")) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir aGTA = null; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir if (aGTA.getExportFilterName() != null && aGTA.getExportFilterName().toLowerCase().equals("help")) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir aGTA = null; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir return aGTA; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir } 127