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
.ClParser
;
22 import java
.util
.Enumeration
;
24 import java
.util
.Properties
;
25 import java
.util
.StringTokenizer
;
27 import lib
.TestParameters
;
28 import util
.DynamicClassLoader
;
32 * The main class, will call ClParser and CfgParser to <br>
33 * fill the TestParameters.<br>
34 * Will then call the appropriate Testbase to run the tests.
39 private static String
beautifyTime(long _nTime
)
41 long sec
= (_nTime
/ 1000) % 60;
42 long min
= (_nTime
/ (60 * 1000)) % 60;
43 long hour
= _nTime
/ (60 * 60 * 1000);
44 StringBuffer aTime
= new StringBuffer();
45 aTime
.append(helper
.StringHelper
.createValueString((int) hour
, 2)).
47 append(helper
.StringHelper
.createValueString((int) min
, 2)).
49 append(helper
.StringHelper
.createValueString((int) sec
, 2));
50 return aTime
.toString();
54 * Helper to check if there are problems with Cygwin Path variables.
56 private static boolean checkVariableForCygwin(String _sVariable
)
58 if (_sVariable
== null)
62 return _sVariable
.startsWith("/cygdrive");
65 private static boolean checkPathVariable(String _sPath
, String delim
)
67 String sPath
= System
.getProperty(_sPath
);
70 StringTokenizer aTokenEnum
= new StringTokenizer(sPath
, delim
);
71 while (aTokenEnum
.hasMoreElements())
73 String sToken
= (String
) aTokenEnum
.nextElement();
74 if (checkVariableForCygwin(sToken
))
76 System
.err
.println("ERROR: OOoRunner detect cygwin path in '" + _sPath
+ "'");
84 private static void checkAllVariablesForCygwinPath(TestParameters _aParams
)
86 // ----- check all System.getProperty(key) variables -----
87 String sOsName
= System
.getProperty("os.name");
88 if (!sOsName
.toLowerCase().startsWith("windows"))
90 // we need to check only on windows
94 Properties aProps
= System
.getProperties();
95 Enumeration
<?
> aEnum
= aProps
.propertyNames();
96 // Enumeration aEnum = aProps.elements(); // these are only the values
97 boolean bEmergencyStop
= false;
99 while (aEnum
.hasMoreElements())
101 String sKey
= (String
) aEnum
.nextElement();
102 String sValue
= System
.getProperty(sKey
);
104 if (checkVariableForCygwin(sValue
))
106 System
.err
.println("ERROR: OOoRunner detect cygwin path in '" + sKey
+ ":=" + sValue
+ "'");
107 bEmergencyStop
= true;
111 // ----- check path variables separately -----
112 String sDelim
= System
.getProperty("path.separator");
113 bEmergencyStop
|= checkPathVariable("java.library.path", sDelim
);
114 bEmergencyStop
|= checkPathVariable("java.class.path", sDelim
);
115 bEmergencyStop
|= checkPathVariable("sun.boot.class.path", sDelim
);
117 // ----- check all TestParameters -----
118 for (Map
.Entry
<String
, Object
> entry
: _aParams
.entrySet())
120 String sKey
= entry
.getKey();
121 if (entry
.getValue() instanceof String
)
123 String sValue
= (String
) entry
.getValue();
125 if (checkVariableForCygwin(sValue
))
127 System
.err
.println("ERROR: OOoRunner detect cygwin path in '" + sKey
+ ":=" + sValue
+ "'");
128 bEmergencyStop
= true;
139 public static boolean run(String
... args
) throws Exception
141 System
.out
.println("OOoRunner Main() version from 20101118 (yyyymmdd)");
143 final long nStartTime
= System
.currentTimeMillis();
145 DynamicClassLoader dcl
= new DynamicClassLoader();
147 // get a class for test parameters
148 TestParameters param
= new TestParameters();
150 ClParser cli
= new ClParser();
152 //parse the commandline arguments
153 // TODO: no right error message, if no parameter given!
154 cli
.getCommandLineParameter(param
, args
);
156 Object tj
= param
.get("TestJob");
160 System
.out
.println("==========================================================================");
161 System
.out
.println("No TestJob given, please make sure that you ");
162 System
.out
.println("a.) called the OOoRunner with the parameter -o <job> or -sce <scenarioFile>");
163 System
.out
.println("or");
164 System
.out
.println("b.) have an entry called TestJob in your used properties file");
165 System
.out
.println("==========================================================================");
169 System
.out
.println("TestJob: " + tj
);
170 String sName
= "base." + (String
) param
.get("TestBase");
171 TestBase toExecute
= (TestBase
) dcl
.getInstance(sName
);
173 checkAllVariablesForCygwinPath(param
);
175 boolean worked
= toExecute
.executeTest(param
);
176 final long nTime
= System
.currentTimeMillis() - nStartTime
;
177 final String sBeautifyTime
= beautifyTime(nTime
);
179 System
.out
.println("Job run took: " + nTime
+ "ms " + " [" + sBeautifyTime
+ "]");
183 System
.out
.println("Job " + param
.get("TestJob") + " failed");
187 System
.out
.println("Job " + param
.get("TestJob") + " done");
192 public static void main(String
[] args
) throws Exception
194 System
.exit(run(args
) ?
0 : -1);