update dev300-m58
[ooovba.git] / qadevOOo / runner / org / openoffice / RunnerService.java
blob8097e4ad935986d7a3c4685be7622179fc25b761
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: RunnerService.java,v $
10 * $Revision: 1.8 $
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 org.openoffice;
33 import share.LogWriter;
34 import stats.InternalLogWriter;
35 import lib.TestParameters;
36 import util.DynamicClassLoader;
37 import base.TestBase;
38 import helper.ClParser;
39 import helper.CfgParser;
40 import com.sun.star.beans.XPropertyAccess;
41 import com.sun.star.beans.PropertyValue;
42 import com.sun.star.task.XJob;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.comp.loader.FactoryHelper;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.lang.XServiceInfo;
47 import com.sun.star.lang.XSingleServiceFactory;
48 import com.sun.star.lang.XTypeProvider;
49 import com.sun.star.uno.Type;
50 import com.sun.star.registry.XRegistryKey;
51 import com.sun.star.beans.NamedValue;
53 import java.util.Vector;
55 /**
56 * The main class, will call ClParser and CfgParser to <br>
57 * fill the TestParameters.<br>
58 * Will then call the appropriate Testbase to run the tests.
60 public class RunnerService implements XJob, XServiceInfo,
61 XTypeProvider, XPropertyAccess {
63 static public final String __serviceName = "org.openoffice.Runner";
64 static public final String __implName = "org.openoffice.RunnerService";
65 static private XMultiServiceFactory xMSF = null;
67 /**
68 * ct'tor
69 * Construct an own office provider for tests
71 public RunnerService(XMultiServiceFactory xMSF) {
74 public Object execute(NamedValue[] args) {
75 // construct valid arguments from the given stuff
76 int arg_length=args.length;
77 String[] arguments = new String[arg_length*2];
78 for ( int i=0; i< arg_length; i++ ) {
79 arguments[i*2] = args[i].Name;
80 Object o = args[i].Value;
81 arguments[i*2+1] = o.toString();
84 TestParameters param = new TestParameters();
85 DynamicClassLoader dcl = new DynamicClassLoader();
88 // take the standard log writer
89 String standardLogWriter = param.LogWriter;
90 String standardOutProducer = param.OutProducer;
92 ClParser cli = new ClParser();
94 //parse the arguments if an ini-parameter is given
95 String iniFile = cli.getIniPath(arguments);
97 //initialize cfgParser with ini-path
98 CfgParser ini = new CfgParser(iniFile);
100 //parse ConfigFile
101 ini.getIniParameters(param);
104 //parse the commandline arguments if an runnerprops-parameter is given
105 String runnerIniFile = cli.getRunnerIniPath(arguments);
107 //initialize cfgParser with ini-path
108 CfgParser runnerIni = new CfgParser(runnerIniFile);
110 //parse ConfigFile
111 runnerIni.getIniParameters(param);
113 //parse the commandline arguments
114 cli.getCommandLineParameter(param,arguments);
116 // now compare the standard log writer with the parameters:
117 // if we have a new one, use the new, else use the internal
118 // log writer
119 if (((String)param.get("LogWriter")).equals(standardLogWriter))
120 param.put("LogWriter", "stats.InternalLogWriter");
121 if (((String)param.get("OutProducer")).equals(standardOutProducer))
122 param.put("OutProducer", "stats.InternalLogWriter");
123 LogWriter log = (LogWriter) dcl.getInstance(
124 (String)param.get("LogWriter"));
126 param.put("ServiceFactory", xMSF);
128 param.ServiceFactory = xMSF; //(XMultiServiceFactory)
129 // appProvider.getManager(param);
131 log.println("TestJob: "+param.get("TestJob"));
133 TestBase toExecute = (TestBase)dcl.getInstance("base.java_fat_service");
135 boolean worked = toExecute.executeTest(param);
136 if (!worked)
137 log.println("Test did not execute correctly.");
139 String returnString = "";
140 if (log instanceof InternalLogWriter)
141 returnString = ((InternalLogWriter)log).getLog();
142 return returnString;
146 * This function provides the service name
147 * @return the service name
149 public String getServiceName() {
150 return __serviceName;
154 * Get all implemented types of this class.
155 * @return An array of implemented interface types.
156 * @see com.sun.star.lang.XTypeProvider
158 public Type[] getTypes() {
159 Type[] type = new Type[5];
160 type[0] = new Type(XInterface.class);
161 type[1] = new Type(XTypeProvider.class);
162 type[2] = new Type(XJob.class);
163 type[3] = new Type(XServiceInfo.class);
164 type[4] = new Type(XPropertyAccess.class);
165 return type;
169 * Get the implementation id.
170 * @return An empty implementation id.
171 * @see com.sun.star.lang.XTypeProvider
173 public byte[] getImplementationId() {
174 return new byte[0];
177 * Function for reading the implementation name.
179 * @return the implementation name
180 * @see com.sun.star.lang.XServiceInfo
182 public String getImplementationName() {
183 return __implName;
187 * Does the implementation support this service?
189 * @param serviceName The name of the service in question
190 * @return true, if service is supported, false otherwise
191 * @see com.sun.star.lang.XServiceInfo
193 public boolean supportsService(String serviceName) {
194 if(serviceName.equals(__serviceName))
195 return true;
196 return false;
200 * Function for reading all supported services
202 * @return An aaray with all supported service names
203 * @see com.sun.star.lang.XServiceInfo
205 public String[] getSupportedServiceNames() {
206 String[] supServiceNames = {__serviceName};
207 return supServiceNames;
211 * Return all valid testcases from the object descriptions
212 * @return The valid testcases as property values
214 public PropertyValue[] getPropertyValues() {
215 PropertyValue[] pVal = null;
216 java.net.URL url = this.getClass().getResource("/objdsc");
217 if (url == null) {
218 pVal = new PropertyValue[1];
219 pVal[0] = new PropertyValue();
220 pVal[0].Name = "Error";
221 pVal[0].Value = "OOoRunner.jar file doesn't contain object " +
222 "descriptions: don't know what to test.";
223 return pVal;
226 Vector v = new Vector(600);
227 try {
228 // open connection to Jar
229 java.net.JarURLConnection con =
230 (java.net.JarURLConnection)url.openConnection();
231 // get Jar file from connection
232 java.util.jar.JarFile f = con.getJarFile();
233 // Enumerate over all entries
234 java.util.Enumeration aEnum = f.entries();
236 while (aEnum.hasMoreElements()) {
237 String entry = aEnum.nextElement().toString();
238 if (entry.endsWith(".csv")) {
240 String module = null;
241 String object = null;
243 int startIndex = entry.indexOf("objdsc/") + 7;
244 int endIndex = entry.lastIndexOf('/');
245 /* int endIndex = entry.indexOf('.');
246 module = entry.substring(startIndex, endIndex);
247 startIndex = 0;
248 endIndex = module.lastIndexOf('/'); */
249 module = entry.substring(startIndex, endIndex);
251 // special cases
252 if (entry.indexOf("/file/") != -1 || entry.indexOf("/xmloff/") != -1) {
253 endIndex = entry.indexOf(".csv");
254 object = entry.substring(0, endIndex);
255 endIndex = object.lastIndexOf('.');
256 startIndex = object.indexOf('.');
257 while (startIndex != endIndex) {
258 object = object.substring(startIndex+1);
259 startIndex = object.indexOf('.');
260 endIndex = object.lastIndexOf('.');
263 /* else if (entry.indexOf("/xmloff/") != -1) {
264 endIndex = entry.indexOf(".csv");
265 object = entry.substring(0, endIndex);
266 endIndex = entry.lastIndexOf('.');
267 while (object.indexOf('.') != endIndex) {
268 object = object.substring(object.indexOf('.')+1);
270 } */
271 else {
272 startIndex = 0;
273 endIndex = entry.indexOf(".csv");
274 object = entry.substring(startIndex, endIndex);
275 startIndex = object.lastIndexOf('.');
276 object = object.substring(startIndex+1);
278 v.add(module+"."+object);
282 catch(java.io.IOException e) {
283 e.printStackTrace();
286 int size = v.size();
288 String[] sTestCases = new String[size];
289 v.toArray(sTestCases);
290 java.util.Arrays.sort(sTestCases);
292 pVal = new PropertyValue[size];
293 for (int i=0; i<size; i++) {
294 pVal[i] = new PropertyValue();
295 pVal[i].Name = "TestCase"+i;
296 pVal[i].Value = sTestCases[i];
298 return pVal;
304 * Gives a factory for creating the service.
305 * This method is called by the <code>JavaLoader</code>
306 * <p>
307 * @return returns a <code>XSingleServiceFactory</code> for creating the component
308 * @param implName the name of the implementation for which a service is desired
309 * @param multiFactory the service manager to be used if needed
310 * @param regKey the registryKey
311 * @see com.sun.star.comp.loader.JavaLoader
313 public static XSingleServiceFactory __getServiceFactory(String implName,
314 XMultiServiceFactory multiFactory, XRegistryKey regKey)
316 XSingleServiceFactory xSingleServiceFactory = null;
318 if (implName.equals(RunnerService.class.getName()))
319 xSingleServiceFactory = FactoryHelper.getServiceFactory(
320 RunnerService.class, __serviceName, multiFactory, regKey);
321 xMSF = multiFactory;
322 return xSingleServiceFactory;
326 * Writes the service information into the given registry key.
327 * This method is called by the <code>JavaLoader</code>
328 * <p>
329 * @return returns true if the operation succeeded
330 * @param regKey the registryKey
331 * @see com.sun.star.comp.loader.JavaLoader
333 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
334 return FactoryHelper.writeRegistryServiceInfo(RunnerService.class.getName(),
335 __serviceName, regKey);
339 * empty: not needed here.
341 public void setPropertyValues(PropertyValue[] propertyValue)
342 throws com.sun.star.beans.UnknownPropertyException,
343 com.sun.star.beans.PropertyVetoException,
344 com.sun.star.lang.IllegalArgumentException,
345 com.sun.star.lang.WrappedTargetException {
346 // empty implementation