Update ooo320-m1
[ooovba.git] / qadevOOo / runner / lib / TestParameters.java
blob8ab9a7a23ceafb29b31ca16b027f462b76a78ce0
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: TestParameters.java,v $
10 * $Revision: 1.14.2.1 $
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 ************************************************************************/
31 package lib;
33 import java.util.Hashtable;
34 import util.PropertyName;
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.uno.XComponentContext;
38 //import com.sun.star.lang.XMultiServiceFactory;
40 /**
41 * TestParameters describes a parameters (in a form of pairs: name, value) to
42 * be passed to tests and which may affect the test behaviour. That can be,
43 * for example, standard paths, connection strings, etc. The TestParameters
44 * also provides XMultiServiceFactory for the test (tests).
46 public class TestParameters extends Hashtable {
48 /**
49 * The ConnectionString for Office Connection<br>
50 * default is 'socket,host=localhost,port=8100'
53 public String ConnectionString="socket,host=localhost,port=8100";
55 /**
56 * The AppProvider contains the Application Provider<br>
57 * to control the ServiceFactory.
60 public Object AppProvider=null;
62 /**
63 * The Process contains the Process handler<br>
64 * to control the Application.
67 public Object ProcessHandler=null;
69 /**
70 * The AppExecutionCmd contains the full qualified<br>
71 * command to an Application to be started.
74 public String AppExecutionCommand="";
76 /**
77 * If this parameter is <CODE>true</CODE> the <CODE>OfficeProvider</CODE> tries
78 * to get the URL to the binary of the office and to fill the
79 * <CODE>AppExecutionCommand</CODE> with usefull content if needet
81 public boolean AutoRestart = false;
83 /**
84 * Shoert wait time for the Office: default is 500 milliseconds
86 public int ShortWait = 500;
89 /**
90 * The OfficeProvider contains the full qualified
91 * class that provides a connection to StarOffice<br>
92 * default is helper.OfficeProvider
95 public String OfficeProvider = "helper.OfficeProvider";
97 /**
98 * The Testbase to be executed by the runner<br>
99 * default is 'java_fat'
102 public String TestBase="java_fat";
105 * The ServiceFactory to create instances
108 public Object ServiceFactory;
111 * The Path to the component description
114 public String DescriptionPath;
117 * The Path to the test documents that are loaded during the test <br>
120 public String TestDocumentPath="unkown";
123 * 'true' is a log should be written, 'false' elsewhere <br>
124 * these will be provided by the testcases<br>
125 * default is true
128 public boolean LoggingIsActive=true;
131 * 'true' is a debug information should be written, 'false' elsewhere
132 * these will be provided by the framework.<br>
133 * Debug information will always be written on standard out.<br>
134 * default is true
137 public boolean DebugIsActive=false;
140 * This parameter contains the testjob to be executed<br>
141 * by the framework
144 public Object TestJob;
147 * This parameter contains the class used<br>
148 * for Logging
151 public String LogWriter="stats.SimpleLogWriter";
154 * This parameter contains the class used<br>
155 * for Logging
158 public String OutProducer="stats.SimpleOutProducer";
161 * This parameter contains the timeout used<br>
162 * by the watcher
164 public Integer TimeOut = new Integer(3000000);
167 * This parameter contains the timeout used<br>
168 * by the complex tests
170 public Integer ThreadTimeOut = new Integer(3000000);
173 * This parameter contains the time which the office could use to close for
174 * itself before its destroyed. Default is 15000 ms
176 public Integer OfficeCloseTimeOut = new Integer(15000);
179 * Wraper around "get()" with some debug output
180 * @param key A key of this table.
181 * @return The value of this key.
182 * @see java.util.Hashtable
184 public Object get(Object key) {
185 Object val = super.get(key);
186 if (val == null && DebugIsActive) {
187 System.out.print("Have been asked for key \""+key.toString());
188 System.out.println("\" which is not part of params.");
190 return val;
194 * Special get method for boolean values: for convenience.
195 * Will return 'false' if the value is not of "Boolean" type.
196 * @param key A key of this table.
197 * @return The value of this key, castet to a boolean type.
199 public boolean getBool(Object key) {
200 Object val = super.get(key);
201 if (val != null) {
202 if (val instanceof String) {
203 String sVal = (String)val;
204 if (sVal.equalsIgnoreCase("true") ||
205 sVal.equalsIgnoreCase("yes")) {
206 return true;
208 else if (sVal.equalsIgnoreCase("false") ||
209 sVal.equalsIgnoreCase("no")) {
210 return false;
213 if (val instanceof Boolean)
214 return ((Boolean)val).booleanValue();
216 return false;
220 * Special get method for integer values: for convenience.
221 * Will return 0 if the value cannot be interpreted as Integer.
222 * @param key A key of this table.
223 * @return The value of this key, castet to an int type.
225 public int getInt(Object key) {
226 Object val = super.get(key);
227 if ( val != null ) {
228 if (val instanceof Integer) {
229 return ((Integer)val).intValue();
231 else {
232 try {
233 if ( val instanceof String ) {
234 Integer nr = new Integer((String)val);
235 if (nr.intValue() > 0) return nr.intValue();
237 } catch ( java.lang.NumberFormatException nfe) {}
240 return 0;
245 * Wraper around "put()"
246 * @param key A key of this table.
247 * @param val The value of the key.
248 * @return The value of this key.
249 * @see java.util.Hashtable
251 public Object put(Object key, Object val) {
252 return super.put(key,val);
256 * Constructor, defaults for Parameters are set.
258 public TestParameters() {
259 //fill the propertyset
260 String user = System.getProperty("user.name");
261 if ( user != null)
263 String PipeConnectionString = "pipe,name=" + user;
264 put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString);
265 put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE);
267 put(PropertyName.CONNECTION_STRING,ConnectionString);
268 put(PropertyName.TEST_BASE,TestBase);
269 put(PropertyName.TEST_DOCUMENT_PATH,TestDocumentPath);
270 put(PropertyName.LOGGING_IS_ACTIVE,LoggingIsActive?Boolean.TRUE:Boolean.FALSE);
271 put(PropertyName.DEBUG_IS_ACTIVE,DebugIsActive?Boolean.TRUE:Boolean.FALSE);
272 put(PropertyName.OUT_PRODUCER,OutProducer);
273 put(PropertyName.SHORT_WAIT,new Integer(ShortWait));
274 put(PropertyName.OFFICE_PROVIDER,OfficeProvider);
275 put(PropertyName.LOG_WRITER,LogWriter);
276 put(PropertyName.APP_EXECUTION_COMMAND,AppExecutionCommand);
277 put(PropertyName.TIME_OUT,TimeOut);
278 put(PropertyName.THREAD_TIME_OUT,ThreadTimeOut);
279 put(PropertyName.AUTO_RESTART,AutoRestart?Boolean.TRUE:Boolean.FALSE);
280 put(PropertyName.OFFICE_CLOSE_TIME_OUT, OfficeCloseTimeOut);
282 // get the operating system
283 put(PropertyName.OPERATING_SYSTEM, getSOCompatibleOSName());
285 //For compatibility Reasons
286 put("CNCSTR",ConnectionString);
287 put("DOCPTH",TestDocumentPath);
288 System.setProperty("DOCPTH",TestDocumentPath);
292 * @return a XMultiServiceFactory to be used by a test (tests).
294 public Object getMSF() {
295 Object ret = null;
296 ret = get("ServiceFactory");
297 return ret;
300 public XComponentContext getComponentContext() {
301 Object context = get( "ComponentContext" );
302 if ( context == null )
304 XPropertySet factoryProps = (XPropertySet)com.sun.star.uno.UnoRuntime.queryInterface(
305 XPropertySet.class, getMSF() );
308 context = com.sun.star.uno.UnoRuntime.queryInterface(
309 XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) );
310 put( "ComponentContext", context );
312 catch( com.sun.star.beans.UnknownPropertyException e ) { }
313 catch( com.sun.star.lang.WrappedTargetException e ) { }
315 return (XComponentContext)context;
319 * Convert the system dependent operating system name to a name according
320 * to OOo rules.
321 * @return A valid OS name, or "" if the name is not known.
323 String getSOCompatibleOSName() {
324 String osname = System.getProperty ("os.name").toLowerCase ();
325 String osarch = System.getProperty ("os.arch");
326 String operatingSystem = "";
327 if (osname.indexOf ("windows")>-1) {
328 operatingSystem = PropertyName.WNTMSCI;
329 } else if (osname.indexOf ("linux")>-1) {
330 operatingSystem = PropertyName.UNXLNGI;
331 } else if (osname.indexOf ("sunos")>-1) {
332 if (osarch.equals ("x86")) {
333 operatingSystem = PropertyName.UNXSOLI;
334 } else {
335 operatingSystem = PropertyName.UNXSOLS;
337 } else if (osname.indexOf ("mac")>-1) {
338 operatingSystem = PropertyName.UNXMACXI;
339 } else {
340 System.out.println("ERROR: not supported platform: " + osname);
341 System.exit(1);
343 return operatingSystem;
346 }// finish class TestParamenters