2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org
.openoffice
;
20 import helper
.CfgParser
;
21 import helper
.ClParser
;
23 import java
.util
.Enumeration
;
24 import java
.util
.Iterator
;
25 import java
.util
.Properties
;
26 import java
.util
.StringTokenizer
;
28 import lib
.TestParameters
;
29 import util
.DynamicClassLoader
;
33 * The main class, will call ClParser and CfgParser to <br>
34 * fill the TestParameters.<br>
35 * Will then call the appropriate Testbase to run the tests.
40 private static long m_nStartTime
;
42 public static long getRunnerStartTime()
47 simple helper functions to start/stop a timer, to know how long a process need in milliseconds
50 private static long getTime()
52 return System
.currentTimeMillis();
55 private static void setStartTime(long _nStartTime
)
57 m_nStartTime
= _nStartTime
;
61 return the time, which is done until last startTime()
63 public static long meanTime(long _nCurrentTimer
)
65 if (_nCurrentTimer
== 0)
67 System
.out
.println("Forgotten to initialise a start timer?");
70 long nMeanTime
= getTime();
71 return nMeanTime
- _nCurrentTimer
;
74 private static String
beautifyTime(long _nTime
)
76 long sec
= (_nTime
/ 1000) % 60;
77 long min
= (_nTime
/ (60 * 1000)) % 60;
78 long hour
= _nTime
/ (60 * 60 * 1000);
79 StringBuffer aTime
= new StringBuffer();
80 aTime
.append(helper
.StringHelper
.createValueString((int) hour
, 2)).
82 append(helper
.StringHelper
.createValueString((int) min
, 2)).
84 append(helper
.StringHelper
.createValueString((int) sec
, 2));
85 return aTime
.toString();
89 Helper to check if there are problems with Cygwin Path variables.
91 private static boolean checkVariableForCygwin(String _sVariable
)
93 if (_sVariable
== null)
97 if (_sVariable
.startsWith("/cygdrive"))
104 private static boolean checkPathVariable(String _sPath
, String delim
)
106 String sPath
= System
.getProperty(_sPath
);
109 StringTokenizer aTokenEnum
= new StringTokenizer(sPath
, delim
);
110 while (aTokenEnum
.hasMoreElements())
112 String sToken
= (String
) aTokenEnum
.nextElement();
113 if (checkVariableForCygwin(sToken
))
115 System
.err
.println("ERROR: OOoRunner detect cygwin path in '" + _sPath
+ "'");
123 private static void checkAllVariablesForCygwinPath(TestParameters _aParams
)
125 // ----- check all System.getProperty(key) variables -----
126 String sOsName
= System
.getProperty("os.name");
127 if (!sOsName
.toLowerCase().startsWith("windows"))
129 // we need to check only on windows
133 Properties aProps
= System
.getProperties();
134 Enumeration
<?
> aEnum
= aProps
.propertyNames();
135 // Enumeration aEnum = aProps.elements(); // these are only the values
136 boolean bEmergencyStop
= false;
138 while (aEnum
.hasMoreElements())
140 String sKey
= (String
) aEnum
.nextElement();
141 String sValue
= System
.getProperty(sKey
);
143 if (checkVariableForCygwin(sValue
))
145 System
.err
.println("ERROR: OOoRunner detect cygwin path in '" + sKey
+ ":=" + sValue
+ "'");
146 bEmergencyStop
= true;
150 // ----- check path variables separatly -----
151 String sDelim
= System
.getProperty("path.separator");
152 bEmergencyStop
|= checkPathVariable("java.library.path", sDelim
);
153 bEmergencyStop
|= checkPathVariable("java.class.path", sDelim
);
154 bEmergencyStop
|= checkPathVariable("sun.boot.class.path", sDelim
);
156 // ----- check all TestParameters -----
157 Iterator
<String
> aIter
= _aParams
.keySet().iterator();
158 while (aIter
.hasNext())
160 String sKey
= aIter
.next();
161 if (_aParams
.get(sKey
) instanceof String
)
163 String sValue
= (String
) _aParams
.get(sKey
);
165 if (checkVariableForCygwin(sValue
))
167 System
.err
.println("ERROR: OOoRunner detect cygwin path in '" + sKey
+ ":=" + sValue
+ "'");
168 bEmergencyStop
= true;
179 public static boolean run(String
... args
)
181 System
.out
.println("OOoRunner Main() version from 20101118 (yyyymmdd)");
183 setStartTime(getTime());
185 DynamicClassLoader dcl
= new DynamicClassLoader();
187 // get a class for test parameters
188 TestParameters param
= new TestParameters();
190 ClParser cli
= new ClParser();
192 //parse the commandline arguments if an ini-parameter is given
193 String iniFile
= cli
.getIniPath(args
);
195 //initialize cfgParser with ini-path
196 CfgParser ini
= new CfgParser(iniFile
);
199 ini
.getIniParameters(param
);
202 //parse the commandline arguments if an runnerprops-parameter is given
203 String runnerIniFile
= cli
.getRunnerIniPath(args
);
205 //initialize cfgParser with ini-path
206 CfgParser runnerIni
= new CfgParser(runnerIniFile
);
209 runnerIni
.getIniParameters(param
);
211 //parse the commandline arguments
212 // TODO: no right error message, if no parameter given!
213 cli
.getCommandLineParameter(param
, args
);
215 Object tj
= param
.get("TestJob");
219 System
.out
.println("==========================================================================");
220 System
.out
.println("No TestJob given, please make sure that you ");
221 System
.out
.println("a.) called the OOoRunner with the paramter -o <job> or -sce <scenarioFile>");
222 System
.out
.println("or");
223 System
.out
.println("b.) have an entry called TestJob in your used properties file");
224 System
.out
.println("==========================================================================");
228 System
.out
.println("TestJob: " + tj
);
229 String sName
= "base." + (String
) param
.get("TestBase");
230 TestBase toExecute
= (TestBase
) dcl
.getInstance(sName
);
232 checkAllVariablesForCygwinPath(param
);
234 boolean worked
= toExecute
.executeTest(param
);
235 long nTime
= meanTime(getRunnerStartTime());
236 String sBeautifyTime
= beautifyTime(nTime
);
238 System
.out
.println("Job run took: " + nTime
+ "ms " + " [" + sBeautifyTime
+ "]");
242 System
.out
.println("Job " + param
.get("TestJob") + " failed");
246 System
.out
.println("Job " + param
.get("TestJob") + " done");
251 public static void main(String
[] args
)
253 System
.exit(run(args
) ?
0 : -1);