1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew 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 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 { 60cdf0e10cSrcweir String sError = "Must quit. " + _sName + " may be not accessable."; 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 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 92cdf0e10cSrcweir protected abstract Object[] mustInstalledSoftware(); 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 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