bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / lib / TestParameters.java
blob66050ee6ea8e842685702f6b12d934ddc38d7d8d
1 /*
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 .
19 package lib;
21 import java.util.HashMap;
22 import util.PropertyName;
23 import com.sun.star.beans.XPropertySet;
24 import com.sun.star.uno.XComponentContext;
26 //import com.sun.star.lang.XMultiServiceFactory;
28 /**
29 * TestParameters describes a parameters (in a form of pairs: name, value) to
30 * be passed to tests and which may affect the test behaviour. That can be,
31 * for example, standard paths, connection strings, etc. The TestParameters
32 * also provides XMultiServiceFactory for the test (tests).
34 public class TestParameters extends HashMap<String,Object> {
36 /**
37 * The ConnectionString for Office Connection<br>
38 * default is 'socket,host=localhost,port=8100'
41 public String ConnectionString="socket,host=localhost,port=8100";
43 /**
44 * The AppProvider contains the Application Provider<br>
45 * to control the ServiceFactory.
48 public Object AppProvider=null;
50 /**
51 * The Process contains the Process handler<br>
52 * to control the Application.
55 public Object ProcessHandler=null;
57 /**
58 * The AppExecutionCmd contains the full qualified<br>
59 * command to an Application to be started.
62 public String AppExecutionCommand="";
64 /**
65 * If this parameter is <CODE>true</CODE> the <CODE>OfficeProvider</CODE> tries
66 * to get the URL to the binary of the office and to fill the
67 * <CODE>AppExecutionCommand</CODE> with useful content if needet
69 public boolean AutoRestart = false;
71 /**
72 * Shoert wait time for the Office: default is 500 milliseconds
74 public int ShortWait = 500;
77 /**
78 * The OfficeProvider contains the full qualified
79 * class that provides a connection to StarOffice<br>
80 * default is helper.OfficeProvider
83 public String OfficeProvider = "helper.OfficeProvider";
85 /**
86 * The Testbase to be executed by the runner<br>
87 * default is 'java_fat'
90 public String TestBase="java_fat";
92 /**
93 * The ServiceFactory to create instances
96 public Object ServiceFactory;
98 /**
99 * The Path to the component description
102 public String DescriptionPath;
105 * The Path to the test documents that are loaded during the test <br>
108 public String TestDocumentPath="unknown";
111 * 'true' is a log should be written, 'false' elsewhere <br>
112 * these will be provided by the testcases<br>
113 * default is true
116 public boolean LoggingIsActive=true;
119 * 'true' is a debug information should be written, 'false' elsewhere
120 * these will be provided by the framework.<br>
121 * Debug information will always be written on standard out.<br>
122 * default is true
125 public boolean DebugIsActive=false;
128 * This parameter contains the testjob to be executed<br>
129 * by the framework
132 public Object TestJob;
135 * This parameter contains the class used<br>
136 * for Logging
139 public String LogWriter="stats.SimpleLogWriter";
142 * This parameter contains the class used<br>
143 * for Logging
146 public String OutProducer="stats.SimpleOutProducer";
149 * This parameter contains the timeout used<br>
150 * by the watcher
152 public Integer TimeOut = new Integer(3000000);
155 * This parameter contains the timeout used<br>
156 * by the complex tests
158 public Integer ThreadTimeOut = new Integer(3000000);
161 * This parameter contains the time which the office could use to close for
162 * itself before its destroyed. Default is 15000 ms
164 public Integer OfficeCloseTimeOut = new Integer(15000);
167 * Wraper around "get()" with some debug output
168 * @param key A key of this table.
169 * @return The value of this key.
170 * @see java.util.HashMap
172 public Object get(Object key) {
173 Object val = super.get(key);
174 if (val == null && DebugIsActive) {
175 System.out.print("Have been asked for key \""+key.toString());
176 System.out.println("\" which is not part of params.");
178 return val;
182 * Special get method for boolean values: for convenience.
183 * Will return 'false' if the value is not of "Boolean" type.
184 * @param key A key of this table.
185 * @return The value of this key, castet to a boolean type.
187 public boolean getBool(Object key) {
188 Object val = super.get(key);
189 if (val != null) {
190 if (val instanceof String) {
191 String sVal = (String)val;
192 if (sVal.equalsIgnoreCase("true") ||
193 sVal.equalsIgnoreCase("yes")) {
194 return true;
196 else if (sVal.equalsIgnoreCase("false") ||
197 sVal.equalsIgnoreCase("no")) {
198 return false;
201 if (val instanceof Boolean)
202 return ((Boolean)val).booleanValue();
204 return false;
208 * Special get method for integer values: for convenience.
209 * Will return 0 if the value cannot be interpreted as Integer.
210 * @param key A key of this table.
211 * @return The value of this key, castet to an int type.
213 public int getInt(Object key) {
214 Object val = super.get(key);
215 if ( val != null ) {
216 if (val instanceof Integer) {
217 return ((Integer)val).intValue();
219 else {
220 try {
221 if ( val instanceof String ) {
222 Integer nr = new Integer((String)val);
223 if (nr.intValue() > 0) return nr.intValue();
225 } catch ( java.lang.NumberFormatException nfe) {}
228 return 0;
233 * Wrapper around "put()"
234 * @param key A key of this table.
235 * @param val The value of the key.
236 * @return The value of this key.
237 * @see java.util.HashMap
239 public Object put(String key, Object val) {
240 return super.put(key,val);
244 * Constructor, defaults for Parameters are set.
246 public TestParameters() {
247 //fill the propertyset
248 String user = System.getProperty("user.name");
249 if ( user != null)
251 String PipeConnectionString = "pipe,name=" + user;
252 put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString);
253 put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE);
255 put(PropertyName.CONNECTION_STRING,ConnectionString);
256 put(PropertyName.TEST_BASE,TestBase);
257 put(PropertyName.TEST_DOCUMENT_PATH,TestDocumentPath);
258 put(PropertyName.LOGGING_IS_ACTIVE,LoggingIsActive?Boolean.TRUE:Boolean.FALSE);
259 put(PropertyName.DEBUG_IS_ACTIVE,DebugIsActive?Boolean.TRUE:Boolean.FALSE);
260 put(PropertyName.OUT_PRODUCER,OutProducer);
261 put(PropertyName.SHORT_WAIT,new Integer(ShortWait));
262 put(PropertyName.OFFICE_PROVIDER,OfficeProvider);
263 put(PropertyName.LOG_WRITER,LogWriter);
264 put(PropertyName.APP_EXECUTION_COMMAND,AppExecutionCommand);
265 put(PropertyName.TIME_OUT,TimeOut);
266 put(PropertyName.THREAD_TIME_OUT,ThreadTimeOut);
267 put(PropertyName.AUTO_RESTART,AutoRestart?Boolean.TRUE:Boolean.FALSE);
268 put(PropertyName.OFFICE_CLOSE_TIME_OUT, OfficeCloseTimeOut);
270 // get the operating system
271 put(PropertyName.OPERATING_SYSTEM, getSOCompatibleOSName());
273 //For compatibility Reasons
274 put("CNCSTR",ConnectionString);
275 put("DOCPTH",TestDocumentPath);
276 System.setProperty("DOCPTH",TestDocumentPath);
280 * @return a XMultiServiceFactory to be used by a test (tests).
282 public Object getMSF() {
283 Object ret = null;
284 ret = get("ServiceFactory");
285 return ret;
288 public XComponentContext getComponentContext() {
289 Object context = get( "ComponentContext" );
290 if ( context == null )
292 XPropertySet factoryProps = com.sun.star.uno.UnoRuntime.queryInterface(
293 XPropertySet.class, getMSF() );
296 context = com.sun.star.uno.UnoRuntime.queryInterface(
297 XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) );
298 put( "ComponentContext", context );
300 catch( com.sun.star.beans.UnknownPropertyException e ) { }
301 catch( com.sun.star.lang.WrappedTargetException e ) { }
303 return (XComponentContext)context;
307 * Convert the system dependent operating system name to a name according
308 * to OOo rules.
309 * @return A valid OS name, or "" if the name is not known.
311 String getSOCompatibleOSName() {
312 String osname = System.getProperty ("os.name").toLowerCase ();
313 String osarch = System.getProperty ("os.arch");
314 String operatingSystem = "";
315 if (osname.indexOf ("windows")>-1) {
316 operatingSystem = PropertyName.WNTMSCI;
317 } else if (osname.indexOf ("linux")>-1 || osname.indexOf ("kfreebsd")>-1) {
318 operatingSystem = PropertyName.UNXLNGI;
319 } else if (osname.indexOf ("sunos")>-1) {
320 if (osarch.equals ("x86")) {
321 operatingSystem = PropertyName.UNXSOLI;
322 } else {
323 operatingSystem = PropertyName.UNXSOLS;
325 } else if (osname.indexOf ("mac")>-1) {
326 operatingSystem = PropertyName.UNXMACXI;
327 } else {
328 System.out.println("ERROR: not supported platform: " + osname);
329 System.exit(1);
331 return operatingSystem;
334 }// finish class TestParamenters