Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / lib / TestParameters.java
blob9d1e171b95d98e1e42f59ab29ebd76b5bd8cb86b
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 ************************************************************************/
28 package lib;
30 import java.util.Hashtable;
31 import util.PropertyName;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.uno.XComponentContext;
35 //import com.sun.star.lang.XMultiServiceFactory;
37 /**
38 * TestParameters describes a parameters (in a form of pairs: name, value) to
39 * be passed to tests and which may affect the test behaviour. That can be,
40 * for example, standard paths, connection strings, etc. The TestParameters
41 * also provides XMultiServiceFactory for the test (tests).
43 public class TestParameters extends Hashtable {
45 /**
46 * The ConnectionString for Office Connection<br>
47 * default is 'socket,host=localhost,port=8100'
50 public String ConnectionString="socket,host=localhost,port=8100";
52 /**
53 * The AppProvider contains the Application Provider<br>
54 * to control the ServiceFactory.
57 public Object AppProvider=null;
59 /**
60 * The Process contains the Process handler<br>
61 * to control the Application.
64 public Object ProcessHandler=null;
66 /**
67 * The AppExecutionCmd contains the full qualified<br>
68 * command to an Application to be started.
71 public String AppExecutionCommand="";
73 /**
74 * If this parameter is <CODE>true</CODE> the <CODE>OfficeProvider</CODE> tries
75 * to get the URL to the binary of the office and to fill the
76 * <CODE>AppExecutionCommand</CODE> with usefull content if needet
78 public boolean AutoRestart = false;
80 /**
81 * Shoert wait time for the Office: default is 500 milliseconds
83 public int ShortWait = 500;
86 /**
87 * The OfficeProvider contains the full qualified
88 * class that provides a connection to StarOffice<br>
89 * default is helper.OfficeProvider
92 public String OfficeProvider = "helper.OfficeProvider";
94 /**
95 * The Testbase to be executed by the runner<br>
96 * default is 'java_fat'
99 public String TestBase="java_fat";
102 * The ServiceFactory to create instances
105 public Object ServiceFactory;
108 * The Path to the component description
111 public String DescriptionPath;
114 * The Path to the test documents that are loaded during the test <br>
117 public String TestDocumentPath="unknown";
120 * 'true' is a log should be written, 'false' elsewhere <br>
121 * these will be provided by the testcases<br>
122 * default is true
125 public boolean LoggingIsActive=true;
128 * 'true' is a debug information should be written, 'false' elsewhere
129 * these will be provided by the framework.<br>
130 * Debug information will always be written on standard out.<br>
131 * default is true
134 public boolean DebugIsActive=false;
137 * This parameter contains the testjob to be executed<br>
138 * by the framework
141 public Object TestJob;
144 * This parameter contains the class used<br>
145 * for Logging
148 public String LogWriter="stats.SimpleLogWriter";
151 * This parameter contains the class used<br>
152 * for Logging
155 public String OutProducer="stats.SimpleOutProducer";
158 * This parameter contains the timeout used<br>
159 * by the watcher
161 public Integer TimeOut = new Integer(3000000);
164 * This parameter contains the timeout used<br>
165 * by the complex tests
167 public Integer ThreadTimeOut = new Integer(3000000);
170 * This parameter contains the time which the office could use to close for
171 * itself before its destroyed. Default is 15000 ms
173 public Integer OfficeCloseTimeOut = new Integer(15000);
176 * Wraper around "get()" with some debug output
177 * @param key A key of this table.
178 * @return The value of this key.
179 * @see java.util.Hashtable
181 public Object get(Object key) {
182 Object val = super.get(key);
183 if (val == null && DebugIsActive) {
184 System.out.print("Have been asked for key \""+key.toString());
185 System.out.println("\" which is not part of params.");
187 return val;
191 * Special get method for boolean values: for convenience.
192 * Will return 'false' if the value is not of "Boolean" type.
193 * @param key A key of this table.
194 * @return The value of this key, castet to a boolean type.
196 public boolean getBool(Object key) {
197 Object val = super.get(key);
198 if (val != null) {
199 if (val instanceof String) {
200 String sVal = (String)val;
201 if (sVal.equalsIgnoreCase("true") ||
202 sVal.equalsIgnoreCase("yes")) {
203 return true;
205 else if (sVal.equalsIgnoreCase("false") ||
206 sVal.equalsIgnoreCase("no")) {
207 return false;
210 if (val instanceof Boolean)
211 return ((Boolean)val).booleanValue();
213 return false;
217 * Special get method for integer values: for convenience.
218 * Will return 0 if the value cannot be interpreted as Integer.
219 * @param key A key of this table.
220 * @return The value of this key, castet to an int type.
222 public int getInt(Object key) {
223 Object val = super.get(key);
224 if ( val != null ) {
225 if (val instanceof Integer) {
226 return ((Integer)val).intValue();
228 else {
229 try {
230 if ( val instanceof String ) {
231 Integer nr = new Integer((String)val);
232 if (nr.intValue() > 0) return nr.intValue();
234 } catch ( java.lang.NumberFormatException nfe) {}
237 return 0;
242 * Wraper around "put()"
243 * @param key A key of this table.
244 * @param val The value of the key.
245 * @return The value of this key.
246 * @see java.util.Hashtable
248 public Object put(Object key, Object val) {
249 return super.put(key,val);
253 * Constructor, defaults for Parameters are set.
255 public TestParameters() {
256 //fill the propertyset
257 String user = System.getProperty("user.name");
258 if ( user != null)
260 String PipeConnectionString = "pipe,name=" + user;
261 put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString);
262 put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE);
264 put(PropertyName.CONNECTION_STRING,ConnectionString);
265 put(PropertyName.TEST_BASE,TestBase);
266 put(PropertyName.TEST_DOCUMENT_PATH,TestDocumentPath);
267 put(PropertyName.LOGGING_IS_ACTIVE,LoggingIsActive?Boolean.TRUE:Boolean.FALSE);
268 put(PropertyName.DEBUG_IS_ACTIVE,DebugIsActive?Boolean.TRUE:Boolean.FALSE);
269 put(PropertyName.OUT_PRODUCER,OutProducer);
270 put(PropertyName.SHORT_WAIT,new Integer(ShortWait));
271 put(PropertyName.OFFICE_PROVIDER,OfficeProvider);
272 put(PropertyName.LOG_WRITER,LogWriter);
273 put(PropertyName.APP_EXECUTION_COMMAND,AppExecutionCommand);
274 put(PropertyName.TIME_OUT,TimeOut);
275 put(PropertyName.THREAD_TIME_OUT,ThreadTimeOut);
276 put(PropertyName.AUTO_RESTART,AutoRestart?Boolean.TRUE:Boolean.FALSE);
277 put(PropertyName.OFFICE_CLOSE_TIME_OUT, OfficeCloseTimeOut);
279 // get the operating system
280 put(PropertyName.OPERATING_SYSTEM, getSOCompatibleOSName());
282 //For compatibility Reasons
283 put("CNCSTR",ConnectionString);
284 put("DOCPTH",TestDocumentPath);
285 System.setProperty("DOCPTH",TestDocumentPath);
289 * @return a XMultiServiceFactory to be used by a test (tests).
291 public Object getMSF() {
292 Object ret = null;
293 ret = get("ServiceFactory");
294 return ret;
297 public XComponentContext getComponentContext() {
298 Object context = get( "ComponentContext" );
299 if ( context == null )
301 XPropertySet factoryProps = (XPropertySet)com.sun.star.uno.UnoRuntime.queryInterface(
302 XPropertySet.class, getMSF() );
305 context = com.sun.star.uno.UnoRuntime.queryInterface(
306 XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) );
307 put( "ComponentContext", context );
309 catch( com.sun.star.beans.UnknownPropertyException e ) { }
310 catch( com.sun.star.lang.WrappedTargetException e ) { }
312 return (XComponentContext)context;
316 * Convert the system dependent operating system name to a name according
317 * to OOo rules.
318 * @return A valid OS name, or "" if the name is not known.
320 String getSOCompatibleOSName() {
321 String osname = System.getProperty ("os.name").toLowerCase ();
322 String osarch = System.getProperty ("os.arch");
323 String operatingSystem = "";
324 if (osname.indexOf ("windows")>-1) {
325 operatingSystem = PropertyName.WNTMSCI;
326 } else if (osname.indexOf ("linux")>-1) {
327 operatingSystem = PropertyName.UNXLNGI;
328 } else if (osname.indexOf ("sunos")>-1) {
329 if (osarch.equals ("x86")) {
330 operatingSystem = PropertyName.UNXSOLI;
331 } else {
332 operatingSystem = PropertyName.UNXSOLS;
334 } else if (osname.indexOf ("mac")>-1) {
335 operatingSystem = PropertyName.UNXMACXI;
336 } else {
337 System.out.println("ERROR: not supported platform: " + osname);
338 System.exit(1);
340 return operatingSystem;
343 }// finish class TestParamenters