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 10cdf0e10cSrcweir * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22cdf0e10cSrcweir package convwatch; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import complexlib.ComplexTestCase; 25cdf0e10cSrcweir import helper.ProcessHandler; 26cdf0e10cSrcweir import convwatch.GraphicalTestArguments; 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** 29cdf0e10cSrcweir * Some Helperfunctions which are nice in ReferenceBuilder and ConvWatchTest 30cdf0e10cSrcweir */ 31cdf0e10cSrcweir 32cdf0e10cSrcweir public abstract class EnhancedComplexTestCase extends ComplexTestCase 33cdf0e10cSrcweir { 34cdf0e10cSrcweir // public void before() 35cdf0e10cSrcweir // { 36cdf0e10cSrcweir // // System.out.println("before()"); 37cdf0e10cSrcweir // } 38cdf0e10cSrcweir // 39cdf0e10cSrcweir // public void after() 40cdf0e10cSrcweir // { 41cdf0e10cSrcweir // // System.out.println("after()"); 42cdf0e10cSrcweir // } 43cdf0e10cSrcweir checkExistance(String _sScriptFile, String _sName)44cdf0e10cSrcweir void checkExistance(String _sScriptFile, String _sName) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir boolean bBackValue = false; 47cdf0e10cSrcweir // Process testshl = Runtime.getRuntime().exec(scriptFile); 48cdf0e10cSrcweir ProcessHandler aHandler = new ProcessHandler(_sScriptFile); 49cdf0e10cSrcweir bBackValue = aHandler.executeSynchronously(); 50cdf0e10cSrcweir TimeHelper.waitInSeconds(1, "wait after ProcessHandler.executeSynchronously()"); 51cdf0e10cSrcweir 52cdf0e10cSrcweir StringBuffer aBuffer = new StringBuffer(); 53cdf0e10cSrcweir aBuffer.append(aHandler.getErrorText()).append(aHandler.getOutputText()); 54cdf0e10cSrcweir String sText = aBuffer.toString(); 55cdf0e10cSrcweir 56cdf0e10cSrcweir if (sText.length() == 0) 57cdf0e10cSrcweir { 58bb6af6bcSPedro Giffuni String sError = "Must quit. " + _sName + " may be not accessible."; 59cdf0e10cSrcweir assure(sError, false); 60cdf0e10cSrcweir // System.exit(1); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir else 63cdf0e10cSrcweir { 64cdf0e10cSrcweir // System.out.println("Output from script:"); 65cdf0e10cSrcweir // System.out.println(sText); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ----------------------------------------------------------------------------- 70cdf0e10cSrcweir checkEnvironment(Object[] _aList)71cdf0e10cSrcweir protected void checkEnvironment(Object[] _aList) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir // checks if some packages already installed, 74cdf0e10cSrcweir // this function will not return if packages are not installed, 75cdf0e10cSrcweir // it will call System.exit(1)! 76cdf0e10cSrcweir 77cdf0e10cSrcweir if (needCheckForInstalledSoftware()) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir for (int i=0;i<_aList.length;i++) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir String sCommand = (String)_aList[i]; 82cdf0e10cSrcweir // TODO: nice to have, a pair object 83cdf0e10cSrcweir checkExistance(sCommand, sCommand); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir // ----------------------------------------------------------------------------- 89cdf0e10cSrcweir mustInstalledSoftware()90cdf0e10cSrcweir protected abstract Object[] mustInstalledSoftware(); needCheckForInstalledSoftware()91cdf0e10cSrcweir public boolean needCheckForInstalledSoftware() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir String sNEEDCHECK = (String)param.get( PropertyName.CHECK_NEED_TOOLS ); 94cdf0e10cSrcweir // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns 95cdf0e10cSrcweir // with a default of 'false' which is not very helpful if the default should be 'true' 96*21c145e3Smseidel // maybe a getBoolean("name", true) could be a better choice. 97cdf0e10cSrcweir if (sNEEDCHECK == null) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir sNEEDCHECK = "false"; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir if (sNEEDCHECK.toLowerCase().equals("yes") || 102cdf0e10cSrcweir sNEEDCHECK.toLowerCase().equals("true")) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir return true; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir return false; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir // ----------------------------------------------------------------------------- 110cdf0e10cSrcweir getGraphicalTestArguments()111cdf0e10cSrcweir public GraphicalTestArguments getGraphicalTestArguments() 112cdf0e10cSrcweir { 113cdf0e10cSrcweir GraphicalTestArguments aGTA = new GraphicalTestArguments(param); 114cdf0e10cSrcweir if (aGTA.getImportFilterName() != null && aGTA.getImportFilterName().toLowerCase().equals("help")) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir aGTA = null; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir if (aGTA.getExportFilterName() != null && aGTA.getExportFilterName().toLowerCase().equals("help")) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir aGTA = null; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir return aGTA; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir } 125