xref: /AOO41X/main/qadevOOo/runner/lib/TestParameters.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package lib;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import java.util.Hashtable;
31*cdf0e10cSrcweir import util.PropertyName;
32*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
33*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //import com.sun.star.lang.XMultiServiceFactory;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir /**
38*cdf0e10cSrcweir  * TestParameters describes a parameters (in a form of pairs: name, value) to
39*cdf0e10cSrcweir  * be passed to tests and which may affect the test behaviour. That can be,
40*cdf0e10cSrcweir  * for example, standard paths, connection strings, etc. The TestParameters
41*cdf0e10cSrcweir  * also provides XMultiServiceFactory for the test (tests).
42*cdf0e10cSrcweir  */
43*cdf0e10cSrcweir public class TestParameters extends Hashtable {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     /**
46*cdf0e10cSrcweir      * The ConnectionString for Office Connection<br>
47*cdf0e10cSrcweir      * default is 'socket,host=localhost,port=8100'
48*cdf0e10cSrcweir      */
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir     public String ConnectionString="socket,host=localhost,port=8100";
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     /**
53*cdf0e10cSrcweir      * The AppProvider contains the Application Provider<br>
54*cdf0e10cSrcweir      * to control the ServiceFactory.
55*cdf0e10cSrcweir      */
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     public Object AppProvider=null;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     /**
60*cdf0e10cSrcweir      * The Process contains the Process handler<br>
61*cdf0e10cSrcweir      * to control the Application.
62*cdf0e10cSrcweir      */
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     public Object ProcessHandler=null;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     /**
67*cdf0e10cSrcweir      * The AppExecutionCmd contains the full qualified<br>
68*cdf0e10cSrcweir      * command to an Application to be started.
69*cdf0e10cSrcweir      */
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     public String AppExecutionCommand="";
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     /**
74*cdf0e10cSrcweir      * If this parameter is <CODE>true</CODE> the <CODE>OfficeProvider</CODE> tries
75*cdf0e10cSrcweir      * to get the URL to the binary of the office and to fill the
76*cdf0e10cSrcweir      * <CODE>AppExecutionCommand</CODE> with usefull content if needet
77*cdf0e10cSrcweir      */
78*cdf0e10cSrcweir     public boolean AutoRestart = false;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     /**
81*cdf0e10cSrcweir      * Shoert wait time for the Office: default is 500 milliseconds
82*cdf0e10cSrcweir      */
83*cdf0e10cSrcweir     public int ShortWait = 500;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     /**
87*cdf0e10cSrcweir      * The OfficeProvider contains the full qualified
88*cdf0e10cSrcweir      * class that provides a connection to StarOffice<br>
89*cdf0e10cSrcweir      * default is helper.OfficeProvider
90*cdf0e10cSrcweir      */
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     public String OfficeProvider = "helper.OfficeProvider";
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     /**
95*cdf0e10cSrcweir      * The Testbase to be executed by the runner<br>
96*cdf0e10cSrcweir      * default is 'java_fat'
97*cdf0e10cSrcweir      */
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     public String TestBase="java_fat";
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     /**
102*cdf0e10cSrcweir      * The ServiceFactory to create instances
103*cdf0e10cSrcweir      */
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     public Object ServiceFactory;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     /**
108*cdf0e10cSrcweir      * The Path to the component description
109*cdf0e10cSrcweir      */
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     public String DescriptionPath;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     /**
114*cdf0e10cSrcweir      * The Path to the test documents that are loaded during the test <br>
115*cdf0e10cSrcweir      */
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     public String TestDocumentPath="unknown";
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     /**
120*cdf0e10cSrcweir      * 'true' is a log should be written, 'false' elsewhere <br>
121*cdf0e10cSrcweir      * these will be provided by the testcases<br>
122*cdf0e10cSrcweir      * default is true
123*cdf0e10cSrcweir      */
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     public boolean LoggingIsActive=true;
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     /**
128*cdf0e10cSrcweir      * 'true' is a debug information should be written, 'false' elsewhere
129*cdf0e10cSrcweir      * these will be provided by the framework.<br>
130*cdf0e10cSrcweir      * Debug information will always be written on standard out.<br>
131*cdf0e10cSrcweir      * default is true
132*cdf0e10cSrcweir      */
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     public boolean DebugIsActive=false;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     /*
137*cdf0e10cSrcweir      * This parameter contains the testjob to be executed<br>
138*cdf0e10cSrcweir      * by the framework
139*cdf0e10cSrcweir      */
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     public Object TestJob;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     /*
144*cdf0e10cSrcweir      * This parameter contains the class used<br>
145*cdf0e10cSrcweir      * for Logging
146*cdf0e10cSrcweir      */
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     public String LogWriter="stats.SimpleLogWriter";
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     /*
151*cdf0e10cSrcweir      * This parameter contains the class used<br>
152*cdf0e10cSrcweir      * for Logging
153*cdf0e10cSrcweir      */
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     public String OutProducer="stats.SimpleOutProducer";
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     /*
158*cdf0e10cSrcweir      * This parameter contains the timeout used<br>
159*cdf0e10cSrcweir      * by the watcher
160*cdf0e10cSrcweir      */
161*cdf0e10cSrcweir     public Integer TimeOut = new Integer(3000000);
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     /*
164*cdf0e10cSrcweir      * This parameter contains the timeout used<br>
165*cdf0e10cSrcweir      * by the complex tests
166*cdf0e10cSrcweir      */
167*cdf0e10cSrcweir     public Integer ThreadTimeOut = new Integer(3000000);
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     /*
170*cdf0e10cSrcweir      * This parameter contains the time which the office could use to close for
171*cdf0e10cSrcweir      * itself before its destroyed. Default is 15000 ms
172*cdf0e10cSrcweir      */
173*cdf0e10cSrcweir     public Integer OfficeCloseTimeOut = new Integer(15000);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     /**
176*cdf0e10cSrcweir      * Wraper around "get()" with some debug output
177*cdf0e10cSrcweir      * @param key A key of this table.
178*cdf0e10cSrcweir      * @return The value of this key.
179*cdf0e10cSrcweir      * @see java.util.Hashtable
180*cdf0e10cSrcweir      */
181*cdf0e10cSrcweir     public Object get(Object key) {
182*cdf0e10cSrcweir         Object val = super.get(key);
183*cdf0e10cSrcweir         if (val == null && DebugIsActive) {
184*cdf0e10cSrcweir             System.out.print("Have been asked for key \""+key.toString());
185*cdf0e10cSrcweir             System.out.println("\" which is not part of params.");
186*cdf0e10cSrcweir         }
187*cdf0e10cSrcweir         return val;
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     /**
191*cdf0e10cSrcweir      * Special get method for boolean values: for convenience.
192*cdf0e10cSrcweir      * Will return 'false' if the value is not of "Boolean" type.
193*cdf0e10cSrcweir      * @param key A key of this table.
194*cdf0e10cSrcweir      * @return The value of this key, castet to a boolean type.
195*cdf0e10cSrcweir      */
196*cdf0e10cSrcweir     public boolean getBool(Object key) {
197*cdf0e10cSrcweir         Object val = super.get(key);
198*cdf0e10cSrcweir         if (val != null) {
199*cdf0e10cSrcweir             if (val instanceof String) {
200*cdf0e10cSrcweir                 String sVal = (String)val;
201*cdf0e10cSrcweir                 if (sVal.equalsIgnoreCase("true") ||
202*cdf0e10cSrcweir                                                 sVal.equalsIgnoreCase("yes")) {
203*cdf0e10cSrcweir                     return true;
204*cdf0e10cSrcweir                 }
205*cdf0e10cSrcweir                 else if (sVal.equalsIgnoreCase("false") ||
206*cdf0e10cSrcweir                                                 sVal.equalsIgnoreCase("no")) {
207*cdf0e10cSrcweir                     return false;
208*cdf0e10cSrcweir                 }
209*cdf0e10cSrcweir             }
210*cdf0e10cSrcweir             if (val instanceof Boolean)
211*cdf0e10cSrcweir                 return ((Boolean)val).booleanValue();
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir         return false;
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     /**
217*cdf0e10cSrcweir      * Special get method for integer values: for convenience.
218*cdf0e10cSrcweir      * Will return 0 if the value cannot be interpreted as Integer.
219*cdf0e10cSrcweir      * @param key A key of this table.
220*cdf0e10cSrcweir      * @return The value of this key, castet to an int type.
221*cdf0e10cSrcweir      */
222*cdf0e10cSrcweir     public int getInt(Object key) {
223*cdf0e10cSrcweir         Object val = super.get(key);
224*cdf0e10cSrcweir         if ( val != null ) {
225*cdf0e10cSrcweir             if (val instanceof Integer) {
226*cdf0e10cSrcweir                 return ((Integer)val).intValue();
227*cdf0e10cSrcweir             }
228*cdf0e10cSrcweir             else {
229*cdf0e10cSrcweir                 try {
230*cdf0e10cSrcweir                     if ( val instanceof String ) {
231*cdf0e10cSrcweir                         Integer nr = new Integer((String)val);
232*cdf0e10cSrcweir                         if (nr.intValue() > 0) return nr.intValue();
233*cdf0e10cSrcweir                     }
234*cdf0e10cSrcweir                 } catch ( java.lang.NumberFormatException nfe) {}
235*cdf0e10cSrcweir             }
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir         return 0;
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     /**
242*cdf0e10cSrcweir      * Wraper around "put()"
243*cdf0e10cSrcweir      * @param key A key of this table.
244*cdf0e10cSrcweir      * @param val The value of the key.
245*cdf0e10cSrcweir      * @return The value of this key.
246*cdf0e10cSrcweir      * @see java.util.Hashtable
247*cdf0e10cSrcweir      */
248*cdf0e10cSrcweir     public Object put(Object key, Object val) {
249*cdf0e10cSrcweir         return super.put(key,val);
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     /**
253*cdf0e10cSrcweir      * Constructor, defaults for Parameters are set.
254*cdf0e10cSrcweir      */
255*cdf0e10cSrcweir     public TestParameters() {
256*cdf0e10cSrcweir         //fill the propertyset
257*cdf0e10cSrcweir         String user = System.getProperty("user.name");
258*cdf0e10cSrcweir         if ( user != null)
259*cdf0e10cSrcweir         {
260*cdf0e10cSrcweir             String PipeConnectionString = "pipe,name=" + user;
261*cdf0e10cSrcweir             put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString);
262*cdf0e10cSrcweir             put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE);
263*cdf0e10cSrcweir         }
264*cdf0e10cSrcweir         put(PropertyName.CONNECTION_STRING,ConnectionString);
265*cdf0e10cSrcweir         put(PropertyName.TEST_BASE,TestBase);
266*cdf0e10cSrcweir         put(PropertyName.TEST_DOCUMENT_PATH,TestDocumentPath);
267*cdf0e10cSrcweir         put(PropertyName.LOGGING_IS_ACTIVE,LoggingIsActive?Boolean.TRUE:Boolean.FALSE);
268*cdf0e10cSrcweir         put(PropertyName.DEBUG_IS_ACTIVE,DebugIsActive?Boolean.TRUE:Boolean.FALSE);
269*cdf0e10cSrcweir         put(PropertyName.OUT_PRODUCER,OutProducer);
270*cdf0e10cSrcweir         put(PropertyName.SHORT_WAIT,new Integer(ShortWait));
271*cdf0e10cSrcweir         put(PropertyName.OFFICE_PROVIDER,OfficeProvider);
272*cdf0e10cSrcweir         put(PropertyName.LOG_WRITER,LogWriter);
273*cdf0e10cSrcweir         put(PropertyName.APP_EXECUTION_COMMAND,AppExecutionCommand);
274*cdf0e10cSrcweir         put(PropertyName.TIME_OUT,TimeOut);
275*cdf0e10cSrcweir         put(PropertyName.THREAD_TIME_OUT,ThreadTimeOut);
276*cdf0e10cSrcweir         put(PropertyName.AUTO_RESTART,AutoRestart?Boolean.TRUE:Boolean.FALSE);
277*cdf0e10cSrcweir         put(PropertyName.OFFICE_CLOSE_TIME_OUT, OfficeCloseTimeOut);
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir         // get the operating system
280*cdf0e10cSrcweir         put(PropertyName.OPERATING_SYSTEM, getSOCompatibleOSName());
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir         //For compatibility Reasons
283*cdf0e10cSrcweir         put("CNCSTR",ConnectionString);
284*cdf0e10cSrcweir         put("DOCPTH",TestDocumentPath);
285*cdf0e10cSrcweir         System.setProperty("DOCPTH",TestDocumentPath);
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     /**
289*cdf0e10cSrcweir      * @return a XMultiServiceFactory to be used by a test (tests).
290*cdf0e10cSrcweir      */
291*cdf0e10cSrcweir     public Object getMSF() {
292*cdf0e10cSrcweir         Object ret = null;
293*cdf0e10cSrcweir         ret = get("ServiceFactory");
294*cdf0e10cSrcweir         return ret;
295*cdf0e10cSrcweir     }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     public XComponentContext getComponentContext() {
298*cdf0e10cSrcweir         Object context = get( "ComponentContext" );
299*cdf0e10cSrcweir         if ( context == null )
300*cdf0e10cSrcweir         {
301*cdf0e10cSrcweir             XPropertySet factoryProps = (XPropertySet)com.sun.star.uno.UnoRuntime.queryInterface(
302*cdf0e10cSrcweir                 XPropertySet.class, getMSF() );
303*cdf0e10cSrcweir             try
304*cdf0e10cSrcweir             {
305*cdf0e10cSrcweir                 context = com.sun.star.uno.UnoRuntime.queryInterface(
306*cdf0e10cSrcweir                     XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) );
307*cdf0e10cSrcweir                 put( "ComponentContext", context );
308*cdf0e10cSrcweir             }
309*cdf0e10cSrcweir             catch( com.sun.star.beans.UnknownPropertyException e ) { }
310*cdf0e10cSrcweir             catch( com.sun.star.lang.WrappedTargetException e ) { }
311*cdf0e10cSrcweir         }
312*cdf0e10cSrcweir         return (XComponentContext)context;
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     /**
316*cdf0e10cSrcweir      * Convert the system dependent operating system name to a name according
317*cdf0e10cSrcweir      * to OOo rules.
318*cdf0e10cSrcweir      * @return A valid OS name, or "" if the name is not known.
319*cdf0e10cSrcweir      */
320*cdf0e10cSrcweir     String getSOCompatibleOSName() {
321*cdf0e10cSrcweir         String osname = System.getProperty ("os.name").toLowerCase ();
322*cdf0e10cSrcweir         String osarch = System.getProperty ("os.arch");
323*cdf0e10cSrcweir         String operatingSystem = "";
324*cdf0e10cSrcweir         if (osname.indexOf ("windows")>-1) {
325*cdf0e10cSrcweir             operatingSystem = PropertyName.WNTMSCI;
326*cdf0e10cSrcweir         } else if (osname.indexOf ("linux")>-1) {
327*cdf0e10cSrcweir             operatingSystem = PropertyName.UNXLNGI;
328*cdf0e10cSrcweir         } else if (osname.indexOf ("sunos")>-1) {
329*cdf0e10cSrcweir             if (osarch.equals ("x86")) {
330*cdf0e10cSrcweir                 operatingSystem = PropertyName.UNXSOLI;
331*cdf0e10cSrcweir             } else {
332*cdf0e10cSrcweir                 operatingSystem = PropertyName.UNXSOLS;
333*cdf0e10cSrcweir             }
334*cdf0e10cSrcweir         } else if (osname.indexOf ("mac")>-1) {
335*cdf0e10cSrcweir             operatingSystem = PropertyName.UNXMACXI;
336*cdf0e10cSrcweir         } else {
337*cdf0e10cSrcweir             System.out.println("ERROR: not supported platform: " + osname);
338*cdf0e10cSrcweir             System.exit(1);
339*cdf0e10cSrcweir         }
340*cdf0e10cSrcweir         return operatingSystem;
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir }// finish class TestParamenters
344