tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / qadevOOo / runner / org / openoffice / RunnerService.java
blobf61638c4702fbfff4cd0b55c060b837c8c363cea
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 org.openoffice;
21 import helper.ClParser;
23 import java.util.ArrayList;
24 import java.util.jar.JarEntry;
26 import lib.TestParameters;
27 import share.LogWriter;
28 import stats.InternalLogWriter;
29 import util.DynamicClassLoader;
30 import util.PropertyName;
31 import base.TestBase;
33 import com.sun.star.beans.NamedValue;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.beans.XPropertyAccess;
36 import com.sun.star.comp.loader.FactoryHelper;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.lang.XServiceInfo;
39 import com.sun.star.lang.XSingleServiceFactory;
40 import com.sun.star.lang.XTypeProvider;
41 import com.sun.star.registry.XRegistryKey;
42 import com.sun.star.task.XJob;
43 import com.sun.star.uno.Type;
44 import com.sun.star.uno.XInterface;
46 /**
47 * The main class, will call ClParser and CfgParser to <br>
48 * fill the TestParameters.<br>
49 * Will then call the appropriate Testbase to run the tests.
51 public class RunnerService implements XJob, XServiceInfo,
52 XTypeProvider, XPropertyAccess {
54 public static final String __serviceName = "org.openoffice.Runner";
55 public static final String __implName = "org.openoffice.RunnerService";
56 private static XMultiServiceFactory xMSF = null;
58 public Object execute(NamedValue[] args) {
59 // construct valid arguments from the given stuff
60 int arg_length=args.length;
61 String[] arguments = new String[arg_length*2];
62 for ( int i=0; i< arg_length; i++ ) {
63 arguments[i*2] = args[i].Name;
64 Object o = args[i].Value;
65 arguments[i*2+1] = o.toString();
68 TestParameters param = new TestParameters();
69 DynamicClassLoader dcl = new DynamicClassLoader();
72 // take the standard log writer
73 String standardLogWriter = (String) param.get(PropertyName.LOG_WRITER);
74 String standardOutProducer = (String) param.get(PropertyName.OUT_PRODUCER);
76 ClParser cli = new ClParser();
78 //parse the commandline arguments
79 cli.getCommandLineParameter(param,arguments);
81 // now compare the standard log writer with the parameters:
82 // if we have a new one, use the new, else use the internal
83 // log writer
84 if (((String)param.get("LogWriter")).equals(standardLogWriter))
85 param.put("LogWriter", "stats.InternalLogWriter");
86 if (((String)param.get("OutProducer")).equals(standardOutProducer))
87 param.put("OutProducer", "stats.InternalLogWriter");
88 LogWriter log = (LogWriter) dcl.getInstance(
89 (String)param.get("LogWriter"));
91 param.put("ServiceFactory", xMSF);
93 log.println("TestJob: "+param.get("TestJob"));
95 TestBase toExecute = (TestBase)dcl.getInstance("base.java_fat_service");
97 try {
98 boolean worked = toExecute.executeTest(param);
99 if (!worked)
100 log.println("Test did not execute correctly.");
101 } catch (Exception ex) {
102 throw new RuntimeException(ex);
105 String returnString = "";
106 if (log instanceof InternalLogWriter)
107 returnString = ((InternalLogWriter)log).getLog();
108 return returnString;
112 * This function provides the service name
113 * @return the service name
115 public String getServiceName() {
116 return __serviceName;
120 * Get all implemented types of this class.
121 * @return An array of implemented interface types.
122 * @see com.sun.star.lang.XTypeProvider
124 public Type[] getTypes() {
125 Type[] type = new Type[5];
126 type[0] = new Type(XInterface.class);
127 type[1] = new Type(XTypeProvider.class);
128 type[2] = new Type(XJob.class);
129 type[3] = new Type(XServiceInfo.class);
130 type[4] = new Type(XPropertyAccess.class);
131 return type;
135 * Get the implementation id.
136 * @return An empty implementation id.
137 * @see com.sun.star.lang.XTypeProvider
139 public byte[] getImplementationId() {
140 return new byte[0];
143 * Function for reading the implementation name.
145 * @return the implementation name
146 * @see com.sun.star.lang.XServiceInfo
148 public String getImplementationName() {
149 return __implName;
153 * Does the implementation support this service?
155 * @param serviceName The name of the service in question
156 * @return true, if service is supported, false otherwise
157 * @see com.sun.star.lang.XServiceInfo
159 public boolean supportsService(String serviceName) {
160 return serviceName.equals(__serviceName);
164 * Function for reading all supported services
166 * @return An aaray with all supported service names
167 * @see com.sun.star.lang.XServiceInfo
169 public String[] getSupportedServiceNames() {
170 String[] supServiceNames = {__serviceName};
171 return supServiceNames;
175 * Return all valid testcases from the object descriptions
176 * @return The valid testcases as property values
178 public PropertyValue[] getPropertyValues() {
179 PropertyValue[] pVal = null;
180 java.net.URL url = this.getClass().getResource("/objdsc");
181 if (url == null) {
182 pVal = new PropertyValue[1];
183 pVal[0] = new PropertyValue();
184 pVal[0].Name = "Error";
185 pVal[0].Value = "OOoRunner.jar file doesn't contain object " +
186 "descriptions: don't know what to test.";
187 return pVal;
190 ArrayList<String> v = new ArrayList<String>(600);
191 try {
192 // open connection to Jar
193 java.net.JarURLConnection con =
194 (java.net.JarURLConnection)url.openConnection();
195 // get Jar file from connection
196 java.util.jar.JarFile f = con.getJarFile();
197 // Enumerate over all entries
198 java.util.Enumeration<JarEntry> aEnum = f.entries();
200 while (aEnum.hasMoreElements()) {
201 String entry = aEnum.nextElement().toString();
202 if (entry.endsWith(".csv")) {
204 String module = null;
205 String object = null;
207 int startIndex = entry.indexOf("objdsc/") + 7;
208 int endIndex = entry.lastIndexOf('/');
209 module = entry.substring(startIndex, endIndex);
211 // special cases
212 if (entry.indexOf("/file/") != -1 || entry.indexOf("/xmloff/") != -1) {
213 endIndex = entry.indexOf(".csv");
214 object = entry.substring(0, endIndex);
215 endIndex = object.lastIndexOf('.');
216 startIndex = object.indexOf('.');
217 while (startIndex != endIndex) {
218 object = object.substring(startIndex+1);
219 startIndex = object.indexOf('.');
220 endIndex = object.lastIndexOf('.');
223 else {
224 startIndex = 0;
225 endIndex = entry.indexOf(".csv");
226 object = entry.substring(startIndex, endIndex);
227 startIndex = object.lastIndexOf('.');
228 object = object.substring(startIndex+1);
230 v.add(module+"."+object);
234 catch(java.io.IOException e) {
235 e.printStackTrace();
238 int size = v.size();
240 String[] sTestCases = new String[size];
241 v.toArray(sTestCases);
242 java.util.Arrays.sort(sTestCases);
244 pVal = new PropertyValue[size];
245 for (int i=0; i<size; i++) {
246 pVal[i] = new PropertyValue();
247 pVal[i].Name = "TestCase"+i;
248 pVal[i].Value = sTestCases[i];
250 return pVal;
256 * Gives a factory for creating the service.
257 * This method is called by the <code>JavaLoader</code>
258 * <p>
259 * @return returns a <code>XSingleServiceFactory</code> for creating the component
260 * @param implName the name of the implementation for which a service is desired
261 * @param multiFactory the service manager to be used if needed
262 * @param regKey the registryKey
263 * @see com.sun.star.comp.loader.JavaLoader
265 public static XSingleServiceFactory __getServiceFactory(String implName,
266 XMultiServiceFactory multiFactory, XRegistryKey regKey)
268 XSingleServiceFactory xSingleServiceFactory = null;
270 if (implName.equals(RunnerService.class.getName()))
271 xSingleServiceFactory = FactoryHelper.getServiceFactory(
272 RunnerService.class, __serviceName, multiFactory, regKey);
273 xMSF = multiFactory;
274 return xSingleServiceFactory;
278 * Writes the service information into the given registry key.
279 * This method is called by the <code>JavaLoader</code>
280 * <p>
281 * @return returns true if the operation succeeded
282 * @param regKey the registryKey
283 * @see com.sun.star.comp.loader.JavaLoader
285 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
286 return FactoryHelper.writeRegistryServiceInfo(RunnerService.class.getName(),
287 __serviceName, regKey);
291 * empty: not needed here.
293 public void setPropertyValues(PropertyValue[] propertyValue)
294 throws com.sun.star.beans.UnknownPropertyException,
295 com.sun.star.beans.PropertyVetoException,
296 com.sun.star.lang.IllegalArgumentException,
297 com.sun.star.lang.WrappedTargetException {
298 // empty implementation