update dev300-m58
[ooovba.git] / qadevOOo / runner / org / openoffice / Runner.java
blobf716abfcebdf2bfd8432fb2045a4914d85cb543f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Runner.java,v $
10 * $Revision: 1.5.8.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package org.openoffice;
32 import java.util.Enumeration;
33 import java.util.Properties;
34 import java.util.StringTokenizer;
35 import lib.TestParameters;
36 import util.DynamicClassLoader;
37 import base.TestBase;
38 import helper.ClParser;
39 import helper.CfgParser;
41 /**
42 * The main class, will call ClParser and CfgParser to <br>
43 * fill the TestParameters.<br>
44 * Will then call the appropriate Testbase to run the tests.
46 public class Runner
49 private static long m_nStartTime;
51 public static long getRunnerStartTime()
53 return m_nStartTime;
56 simple helper functions to start/stop a timer, to know how long a process need in milliseconds
59 private static long getTime()
61 return System.currentTimeMillis();
64 private static void setStartTime(long _nStartTime)
66 m_nStartTime = _nStartTime;
70 return the time, which is done until last startTime()
72 public static long meanTime(long _nCurrentTimer)
74 if (_nCurrentTimer == 0)
76 System.out.println("Forgotten to initialise a start timer?");
77 return 0;
79 long nMeanTime = getTime();
80 return nMeanTime - _nCurrentTimer;
83 private static String beautifyTime(long _nTime)
85 long sec = (_nTime / 1000) % 60;
86 long min = (_nTime / (60 * 1000)) % 60;
87 long hour = _nTime / (60 * 60 * 1000);
88 StringBuffer aTime = new StringBuffer();
89 aTime.append(helper.StringHelper.createValueString((int) hour, 2)).
90 append(':').
91 append(helper.StringHelper.createValueString((int) min, 2)).
92 append(':').
93 append(helper.StringHelper.createValueString((int) sec, 2));
94 return aTime.toString();
97 /**
98 Helper to check if there are problems with Cygwin Path variables.
100 private static boolean checkVariableForCygwin(String _sVariable)
102 if (_sVariable == null)
104 return false;
106 if (_sVariable.startsWith("/cygdrive"))
108 return true;
110 return false;
113 private static boolean checkPathVariable(String _sPath, String delim)
115 String sPath = System.getProperty(_sPath);
116 if (sPath != null)
118 StringTokenizer aTokenEnum = new StringTokenizer(sPath, delim);
119 while (aTokenEnum.hasMoreElements())
121 String sToken = (String) aTokenEnum.nextElement();
122 if (checkVariableForCygwin(sToken))
124 System.err.println("ERROR: OOoRunner detect cygwin path in '" + _sPath + "'");
125 return true;
129 return false;
132 private static void checkAllVariablesForCygwinPath(TestParameters _aParams)
134 // ----- check all System.getProperty(key) variables -----
135 String sOsName = System.getProperty("os.name");
136 if (!sOsName.toLowerCase().startsWith("windows"))
138 // we need to check only on windows
139 return;
142 Properties aProps = System.getProperties();
143 Enumeration aEnum = aProps.propertyNames();
144 // Enumeration aEnum = aProps.elements(); // these are only the values
145 boolean bEmergencyStop = false;
147 while (aEnum.hasMoreElements())
149 String sKey = (String) aEnum.nextElement();
150 String sValue = System.getProperty(sKey);
152 if (checkVariableForCygwin(sValue))
154 System.err.println("ERROR: OOoRunner detect cygwin path in '" + sKey + ":=" + sValue + "'");
155 bEmergencyStop = true;
159 // ----- check path variables separatly -----
160 String sDelim = System.getProperty("path.separator");
161 bEmergencyStop |= checkPathVariable("java.library.path", sDelim);
162 bEmergencyStop |= checkPathVariable("java.class.path", sDelim);
163 bEmergencyStop |= checkPathVariable("sun.boot.class.path", sDelim);
165 // ----- check all TestParameters -----
166 aEnum = _aParams.keys();
167 while (aEnum.hasMoreElements())
169 String sKey = (String) aEnum.nextElement();
170 if (_aParams.get(sKey) instanceof String)
172 String sValue = (String) _aParams.get(sKey);
174 if (checkVariableForCygwin(sValue))
176 System.err.println("ERROR: OOoRunner detect cygwin path in '" + sKey + ":=" + sValue + "'");
177 bEmergencyStop = true;
182 if (bEmergencyStop)
184 System.exit(-1);
188 public static void main(String[] args)
190 System.out.println("OOoRunner Main() version from 20090825 (yyyymmdd)");
192 setStartTime(getTime());
194 DynamicClassLoader dcl = new DynamicClassLoader();
196 // get a class for test parameters
197 TestParameters param = new TestParameters();
199 ClParser cli = new ClParser();
201 //parse the commandline arguments if an ini-parameter is given
202 String iniFile = cli.getIniPath(args);
204 //initialize cfgParser with ini-path
205 CfgParser ini = new CfgParser(iniFile);
207 //parse ConfigFile
208 ini.getIniParameters(param);
211 //parse the commandline arguments if an runnerprops-parameter is given
212 String runnerIniFile = cli.getRunnerIniPath(args);
214 //initialize cfgParser with ini-path
215 CfgParser runnerIni = new CfgParser(runnerIniFile);
217 //parse ConfigFile
218 runnerIni.getIniParameters(param);
220 //parse the commandline arguments
221 // TODO: no right error message, if no parameter given!
222 cli.getCommandLineParameter(param, args);
224 Object tj = param.get("TestJob");
226 if (tj == null)
228 System.out.println("==========================================================================");
229 System.out.println("No TestJob given, please make sure that you ");
230 System.out.println("a.) called the OOoRunner with the paramter -o <job> or -sce <scenarioFile>");
231 System.out.println("or");
232 System.out.println("b.) have an entry called TestJob in your used properties file");
233 System.out.println("==========================================================================");
234 System.exit(-1);
237 System.out.println("TestJob: " + tj);
238 String sName = "base." + (String) param.get("TestBase");
239 TestBase toExecute = (TestBase) dcl.getInstance(sName);
241 checkAllVariablesForCygwinPath(param);
243 boolean worked = toExecute.executeTest(param);
244 long nTime = meanTime(getRunnerStartTime());
245 String sBeautifyTime = beautifyTime(nTime);
247 System.out.println("Job run took: " + nTime + "ms " + " [" + sBeautifyTime + "]");
249 if (!worked)
251 System.out.println("Job " + param.get("TestJob") + " failed");
252 System.exit(-1);
254 else
256 System.out.println("Job " + param.get("TestJob") + " done");
257 System.exit(0);