Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / org / openoffice / Runner.java
blobca995bc9b4f44cc270b76e9a8d80b887d8eda1ec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package org.openoffice;
29 import java.util.Enumeration;
30 import java.util.Properties;
31 import java.util.StringTokenizer;
32 import lib.TestParameters;
33 import util.DynamicClassLoader;
34 import base.TestBase;
35 import helper.ClParser;
36 import helper.CfgParser;
38 /**
39 * The main class, will call ClParser and CfgParser to <br>
40 * fill the TestParameters.<br>
41 * Will then call the appropriate Testbase to run the tests.
43 public class Runner
46 private static long m_nStartTime;
48 public static long getRunnerStartTime()
50 return m_nStartTime;
53 simple helper functions to start/stop a timer, to know how long a process need in milliseconds
56 private static long getTime()
58 return System.currentTimeMillis();
61 private static void setStartTime(long _nStartTime)
63 m_nStartTime = _nStartTime;
67 return the time, which is done until last startTime()
69 public static long meanTime(long _nCurrentTimer)
71 if (_nCurrentTimer == 0)
73 System.out.println("Forgotten to initialise a start timer?");
74 return 0;
76 long nMeanTime = getTime();
77 return nMeanTime - _nCurrentTimer;
80 private static String beautifyTime(long _nTime)
82 long sec = (_nTime / 1000) % 60;
83 long min = (_nTime / (60 * 1000)) % 60;
84 long hour = _nTime / (60 * 60 * 1000);
85 StringBuffer aTime = new StringBuffer();
86 aTime.append(helper.StringHelper.createValueString((int) hour, 2)).
87 append(':').
88 append(helper.StringHelper.createValueString((int) min, 2)).
89 append(':').
90 append(helper.StringHelper.createValueString((int) sec, 2));
91 return aTime.toString();
94 /**
95 Helper to check if there are problems with Cygwin Path variables.
97 private static boolean checkVariableForCygwin(String _sVariable)
99 if (_sVariable == null)
101 return false;
103 if (_sVariable.startsWith("/cygdrive"))
105 return true;
107 return false;
110 private static boolean checkPathVariable(String _sPath, String delim)
112 String sPath = System.getProperty(_sPath);
113 if (sPath != null)
115 StringTokenizer aTokenEnum = new StringTokenizer(sPath, delim);
116 while (aTokenEnum.hasMoreElements())
118 String sToken = (String) aTokenEnum.nextElement();
119 if (checkVariableForCygwin(sToken))
121 System.err.println("ERROR: OOoRunner detect cygwin path in '" + _sPath + "'");
122 return true;
126 return false;
129 private static void checkAllVariablesForCygwinPath(TestParameters _aParams)
131 // ----- check all System.getProperty(key) variables -----
132 String sOsName = System.getProperty("os.name");
133 if (!sOsName.toLowerCase().startsWith("windows"))
135 // we need to check only on windows
136 return;
139 Properties aProps = System.getProperties();
140 Enumeration aEnum = aProps.propertyNames();
141 // Enumeration aEnum = aProps.elements(); // these are only the values
142 boolean bEmergencyStop = false;
144 while (aEnum.hasMoreElements())
146 String sKey = (String) aEnum.nextElement();
147 String sValue = System.getProperty(sKey);
149 if (checkVariableForCygwin(sValue))
151 System.err.println("ERROR: OOoRunner detect cygwin path in '" + sKey + ":=" + sValue + "'");
152 bEmergencyStop = true;
156 // ----- check path variables separatly -----
157 String sDelim = System.getProperty("path.separator");
158 bEmergencyStop |= checkPathVariable("java.library.path", sDelim);
159 bEmergencyStop |= checkPathVariable("java.class.path", sDelim);
160 bEmergencyStop |= checkPathVariable("sun.boot.class.path", sDelim);
162 // ----- check all TestParameters -----
163 aEnum = _aParams.keys();
164 while (aEnum.hasMoreElements())
166 String sKey = (String) aEnum.nextElement();
167 if (_aParams.get(sKey) instanceof String)
169 String sValue = (String) _aParams.get(sKey);
171 if (checkVariableForCygwin(sValue))
173 System.err.println("ERROR: OOoRunner detect cygwin path in '" + sKey + ":=" + sValue + "'");
174 bEmergencyStop = true;
179 if (bEmergencyStop)
181 System.exit(-1);
185 public static boolean run(String... args)
187 System.out.println("OOoRunner Main() version from 20101118 (yyyymmdd)");
189 setStartTime(getTime());
191 DynamicClassLoader dcl = new DynamicClassLoader();
193 // get a class for test parameters
194 TestParameters param = new TestParameters();
196 ClParser cli = new ClParser();
198 //parse the commandline arguments if an ini-parameter is given
199 String iniFile = cli.getIniPath(args);
201 //initialize cfgParser with ini-path
202 CfgParser ini = new CfgParser(iniFile);
204 //parse ConfigFile
205 ini.getIniParameters(param);
208 //parse the commandline arguments if an runnerprops-parameter is given
209 String runnerIniFile = cli.getRunnerIniPath(args);
211 //initialize cfgParser with ini-path
212 CfgParser runnerIni = new CfgParser(runnerIniFile);
214 //parse ConfigFile
215 runnerIni.getIniParameters(param);
217 //parse the commandline arguments
218 // TODO: no right error message, if no parameter given!
219 cli.getCommandLineParameter(param, args);
221 Object tj = param.get("TestJob");
223 if (tj == null)
225 System.out.println("==========================================================================");
226 System.out.println("No TestJob given, please make sure that you ");
227 System.out.println("a.) called the OOoRunner with the paramter -o <job> or -sce <scenarioFile>");
228 System.out.println("or");
229 System.out.println("b.) have an entry called TestJob in your used properties file");
230 System.out.println("==========================================================================");
231 System.exit(-1);
234 System.out.println("TestJob: " + tj);
235 String sName = "base." + (String) param.get("TestBase");
236 TestBase toExecute = (TestBase) dcl.getInstance(sName);
238 checkAllVariablesForCygwinPath(param);
240 boolean worked = toExecute.executeTest(param);
241 long nTime = meanTime(getRunnerStartTime());
242 String sBeautifyTime = beautifyTime(nTime);
244 System.out.println("Job run took: " + nTime + "ms " + " [" + sBeautifyTime + "]");
246 if (!worked)
248 System.out.println("Job " + param.get("TestJob") + " failed");
250 else
252 System.out.println("Job " + param.get("TestJob") + " done");
254 return worked;
257 public static void main(String[] args)
259 System.exit(run(args) ? 0 : -1);