xref: /AOO42X/main/qadevOOo/runner/org/openoffice/RunnerService.java (revision b0efeae40e43e6d4ccd561d22ec612d42773857b)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package org.openoffice;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import share.LogWriter;
27cdf0e10cSrcweir import stats.InternalLogWriter;
28cdf0e10cSrcweir import lib.TestParameters;
29cdf0e10cSrcweir import util.DynamicClassLoader;
30cdf0e10cSrcweir import base.TestBase;
31cdf0e10cSrcweir import helper.ClParser;
32cdf0e10cSrcweir import helper.CfgParser;
33cdf0e10cSrcweir import com.sun.star.beans.XPropertyAccess;
34cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
35cdf0e10cSrcweir import com.sun.star.task.XJob;
36cdf0e10cSrcweir import com.sun.star.uno.XInterface;
37cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper;
38cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
39cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
40cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
41cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
42cdf0e10cSrcweir import com.sun.star.uno.Type;
43cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
44cdf0e10cSrcweir import com.sun.star.beans.NamedValue;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir import java.util.Vector;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /**
49cdf0e10cSrcweir  * The main class, will call ClParser and CfgParser to <br>
50cdf0e10cSrcweir  * fill the TestParameters.<br>
51cdf0e10cSrcweir  * Will then call the appropriate Testbase to run the tests.
52cdf0e10cSrcweir  */
53cdf0e10cSrcweir public class RunnerService implements XJob, XServiceInfo,
54cdf0e10cSrcweir                                             XTypeProvider, XPropertyAccess {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     static public final String __serviceName = "org.openoffice.Runner";
57cdf0e10cSrcweir     static public final String __implName = "org.openoffice.RunnerService";
58cdf0e10cSrcweir     static private XMultiServiceFactory xMSF = null;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /**
61cdf0e10cSrcweir      * ct'tor
62cdf0e10cSrcweir      * Construct an own office provider for tests
63cdf0e10cSrcweir      */
RunnerService(XMultiServiceFactory xMSF)64cdf0e10cSrcweir     public RunnerService(XMultiServiceFactory xMSF) {
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
execute(NamedValue[] args)67cdf0e10cSrcweir     public Object execute(NamedValue[] args) {
68cdf0e10cSrcweir         // construct valid arguments from the given stuff
69cdf0e10cSrcweir         int arg_length=args.length;
70cdf0e10cSrcweir         String[] arguments = new String[arg_length*2];
71cdf0e10cSrcweir         for ( int i=0; i< arg_length; i++ ) {
72cdf0e10cSrcweir             arguments[i*2] = args[i].Name;
73cdf0e10cSrcweir             Object o = args[i].Value;
74cdf0e10cSrcweir             arguments[i*2+1] = o.toString();
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         TestParameters param = new TestParameters();
78cdf0e10cSrcweir         DynamicClassLoader dcl = new DynamicClassLoader();
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         // take the standard log writer
82cdf0e10cSrcweir         String standardLogWriter = param.LogWriter;
83cdf0e10cSrcweir         String standardOutProducer = param.OutProducer;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         ClParser cli = new ClParser();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         //parse the arguments if an ini-parameter is given
88cdf0e10cSrcweir         String iniFile = cli.getIniPath(arguments);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         //initialize cfgParser with ini-path
91cdf0e10cSrcweir         CfgParser ini = new CfgParser(iniFile);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         //parse ConfigFile
94cdf0e10cSrcweir         ini.getIniParameters(param);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         //parse the commandline arguments if an runnerprops-parameter is given
98cdf0e10cSrcweir         String runnerIniFile = cli.getRunnerIniPath(arguments);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         //initialize cfgParser with ini-path
101cdf0e10cSrcweir         CfgParser runnerIni = new CfgParser(runnerIniFile);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         //parse ConfigFile
104cdf0e10cSrcweir         runnerIni.getIniParameters(param);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         //parse the commandline arguments
107cdf0e10cSrcweir         cli.getCommandLineParameter(param,arguments);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         // now compare the standard log writer with the parameters:
110cdf0e10cSrcweir         // if we have a new one, use the new, else use the internal
111cdf0e10cSrcweir         // log writer
112cdf0e10cSrcweir         if (((String)param.get("LogWriter")).equals(standardLogWriter))
113cdf0e10cSrcweir             param.put("LogWriter", "stats.InternalLogWriter");
114cdf0e10cSrcweir         if (((String)param.get("OutProducer")).equals(standardOutProducer))
115cdf0e10cSrcweir             param.put("OutProducer", "stats.InternalLogWriter");
116cdf0e10cSrcweir         LogWriter log = (LogWriter) dcl.getInstance(
117cdf0e10cSrcweir                                             (String)param.get("LogWriter"));
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         param.put("ServiceFactory", xMSF);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         param.ServiceFactory = xMSF; //(XMultiServiceFactory)
122cdf0e10cSrcweir                                      //       appProvider.getManager(param);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         log.println("TestJob: "+param.get("TestJob"));
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         TestBase toExecute = (TestBase)dcl.getInstance("base.java_fat_service");
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         boolean worked = toExecute.executeTest(param);
129cdf0e10cSrcweir         if (!worked)
130cdf0e10cSrcweir             log.println("Test did not execute correctly.");
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         String returnString = "";
133cdf0e10cSrcweir         if (log instanceof InternalLogWriter)
134cdf0e10cSrcweir             returnString = ((InternalLogWriter)log).getLog();
135cdf0e10cSrcweir         return returnString;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     /**
139cdf0e10cSrcweir      * This function provides the service name
140cdf0e10cSrcweir      * @return the service name
141cdf0e10cSrcweir      */
getServiceName()142cdf0e10cSrcweir     public String getServiceName() {
143cdf0e10cSrcweir         return __serviceName;
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /**
147cdf0e10cSrcweir      * Get all implemented types of this class.
148cdf0e10cSrcweir      * @return An array of implemented interface types.
149cdf0e10cSrcweir      * @see com.sun.star.lang.XTypeProvider
150cdf0e10cSrcweir      */
getTypes()151cdf0e10cSrcweir     public Type[] getTypes() {
152cdf0e10cSrcweir         Type[] type = new Type[5];
153cdf0e10cSrcweir         type[0] = new Type(XInterface.class);
154cdf0e10cSrcweir         type[1] = new Type(XTypeProvider.class);
155cdf0e10cSrcweir         type[2] = new Type(XJob.class);
156cdf0e10cSrcweir         type[3] = new Type(XServiceInfo.class);
157cdf0e10cSrcweir         type[4] = new Type(XPropertyAccess.class);
158cdf0e10cSrcweir         return type;
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     /**
162cdf0e10cSrcweir      * Get the implementation id.
163cdf0e10cSrcweir      * @return An empty implementation id.
164cdf0e10cSrcweir      * @see com.sun.star.lang.XTypeProvider
165cdf0e10cSrcweir      */
getImplementationId()166cdf0e10cSrcweir     public byte[] getImplementationId() {
167cdf0e10cSrcweir         return new byte[0];
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir     /**
170cdf0e10cSrcweir      * Function for reading the implementation name.
171cdf0e10cSrcweir      *
172cdf0e10cSrcweir      * @return the implementation name
173cdf0e10cSrcweir      * @see com.sun.star.lang.XServiceInfo
174cdf0e10cSrcweir      */
getImplementationName()175cdf0e10cSrcweir     public String getImplementationName() {
176cdf0e10cSrcweir         return __implName;
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     /**
180cdf0e10cSrcweir      * Does the implementation support this service?
181cdf0e10cSrcweir      *
182cdf0e10cSrcweir      * @param serviceName The name of the service in question
183cdf0e10cSrcweir      * @return true, if service is supported, false otherwise
184cdf0e10cSrcweir      * @see com.sun.star.lang.XServiceInfo
185cdf0e10cSrcweir      */
supportsService(String serviceName)186cdf0e10cSrcweir     public boolean supportsService(String serviceName) {
187cdf0e10cSrcweir         if(serviceName.equals(__serviceName))
188cdf0e10cSrcweir             return true;
189cdf0e10cSrcweir         return false;
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     /**
193cdf0e10cSrcweir      * Function for reading all supported services
194cdf0e10cSrcweir      *
195cdf0e10cSrcweir      * @return An aaray with all supported service names
196cdf0e10cSrcweir      * @see com.sun.star.lang.XServiceInfo
197cdf0e10cSrcweir      */
getSupportedServiceNames()198cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
199cdf0e10cSrcweir         String[] supServiceNames = {__serviceName};
200cdf0e10cSrcweir         return supServiceNames;
201cdf0e10cSrcweir     }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     /**
204cdf0e10cSrcweir      * Return all valid testcases from the object descriptions
205cdf0e10cSrcweir      * @return The valid testcases as property values
206cdf0e10cSrcweir      */
getPropertyValues()207cdf0e10cSrcweir     public PropertyValue[] getPropertyValues() {
208cdf0e10cSrcweir         PropertyValue[] pVal = null;
209cdf0e10cSrcweir         java.net.URL url = this.getClass().getResource("/objdsc");
210cdf0e10cSrcweir         if (url == null) {
211cdf0e10cSrcweir            pVal = new PropertyValue[1];
212cdf0e10cSrcweir            pVal[0] = new PropertyValue();
213cdf0e10cSrcweir            pVal[0].Name = "Error";
214cdf0e10cSrcweir            pVal[0].Value = "OOoRunner.jar file doesn't contain object " +
215cdf0e10cSrcweir                            "descriptions: don't know what to test.";
216cdf0e10cSrcweir            return pVal;
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         Vector v = new Vector(600);
220cdf0e10cSrcweir         try {
221cdf0e10cSrcweir             // open connection to  Jar
222cdf0e10cSrcweir             java.net.JarURLConnection con =
223cdf0e10cSrcweir                                 (java.net.JarURLConnection)url.openConnection();
224cdf0e10cSrcweir             // get Jar file from connection
225cdf0e10cSrcweir             java.util.jar.JarFile f = con.getJarFile();
226cdf0e10cSrcweir             // Enumerate over all entries
227cdf0e10cSrcweir             java.util.Enumeration aEnum = f.entries();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir             while (aEnum.hasMoreElements()) {
230cdf0e10cSrcweir                 String entry = aEnum.nextElement().toString();
231cdf0e10cSrcweir                 if (entry.endsWith(".csv")) {
232cdf0e10cSrcweir 
233cdf0e10cSrcweir                     String module = null;
234cdf0e10cSrcweir                     String object = null;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir                     int startIndex = entry.indexOf("objdsc/") + 7;
237cdf0e10cSrcweir                     int endIndex = entry.lastIndexOf('/');
238cdf0e10cSrcweir /*                    int endIndex = entry.indexOf('.');
239cdf0e10cSrcweir                     module = entry.substring(startIndex, endIndex);
240cdf0e10cSrcweir                     startIndex = 0;
241cdf0e10cSrcweir                     endIndex = module.lastIndexOf('/'); */
242cdf0e10cSrcweir                     module = entry.substring(startIndex, endIndex);
243cdf0e10cSrcweir 
244cdf0e10cSrcweir                     // special cases
245cdf0e10cSrcweir                     if (entry.indexOf("/file/") != -1 || entry.indexOf("/xmloff/") != -1) {
246cdf0e10cSrcweir                         endIndex = entry.indexOf(".csv");
247cdf0e10cSrcweir                         object = entry.substring(0, endIndex);
248cdf0e10cSrcweir                         endIndex = object.lastIndexOf('.');
249cdf0e10cSrcweir                         startIndex = object.indexOf('.');
250cdf0e10cSrcweir                         while (startIndex != endIndex) {
251cdf0e10cSrcweir                             object = object.substring(startIndex+1);
252cdf0e10cSrcweir                             startIndex = object.indexOf('.');
253cdf0e10cSrcweir                             endIndex = object.lastIndexOf('.');
254cdf0e10cSrcweir                         }
255cdf0e10cSrcweir                     }
256cdf0e10cSrcweir /*                    else if (entry.indexOf("/xmloff/") != -1) {
257cdf0e10cSrcweir                         endIndex = entry.indexOf(".csv");
258cdf0e10cSrcweir                         object = entry.substring(0, endIndex);
259cdf0e10cSrcweir                         endIndex = entry.lastIndexOf('.');
260cdf0e10cSrcweir                         while (object.indexOf('.') != endIndex) {
261cdf0e10cSrcweir                             object = object.substring(object.indexOf('.')+1);
262cdf0e10cSrcweir                         }
263cdf0e10cSrcweir                     } */
264cdf0e10cSrcweir                     else {
265cdf0e10cSrcweir                         startIndex = 0;
266cdf0e10cSrcweir                         endIndex = entry.indexOf(".csv");
267cdf0e10cSrcweir                         object = entry.substring(startIndex, endIndex);
268cdf0e10cSrcweir                         startIndex = object.lastIndexOf('.');
269cdf0e10cSrcweir                         object = object.substring(startIndex+1);
270cdf0e10cSrcweir                     }
271cdf0e10cSrcweir                     v.add(module+"."+object);
272cdf0e10cSrcweir                 }
273cdf0e10cSrcweir             }
274cdf0e10cSrcweir         }
275cdf0e10cSrcweir         catch(java.io.IOException e) {
276cdf0e10cSrcweir            e.printStackTrace();
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         int size = v.size();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         String[] sTestCases = new String[size];
282cdf0e10cSrcweir         v.toArray(sTestCases);
283cdf0e10cSrcweir         java.util.Arrays.sort(sTestCases);
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         pVal = new PropertyValue[size];
286cdf0e10cSrcweir         for (int i=0; i<size; i++) {
287cdf0e10cSrcweir             pVal[i] = new PropertyValue();
288cdf0e10cSrcweir             pVal[i].Name = "TestCase"+i;
289cdf0e10cSrcweir             pVal[i].Value = sTestCases[i];
290cdf0e10cSrcweir         }
291cdf0e10cSrcweir         return pVal;
292cdf0e10cSrcweir    }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 
295cdf0e10cSrcweir    /**
296cdf0e10cSrcweir    *
297cdf0e10cSrcweir    * Gives a factory for creating the service.
298cdf0e10cSrcweir    * This method is called by the <code>JavaLoader</code>
299cdf0e10cSrcweir    * <p>
300cdf0e10cSrcweir    * @return  returns a <code>XSingleServiceFactory</code> for creating the component
301cdf0e10cSrcweir    * @param   implName     the name of the implementation for which a service is desired
302cdf0e10cSrcweir    * @param   multiFactory the service manager to be used if needed
303cdf0e10cSrcweir    * @param   regKey       the registryKey
304cdf0e10cSrcweir    * @see                  com.sun.star.comp.loader.JavaLoader
305cdf0e10cSrcweir    */
__getServiceFactory(String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)306cdf0e10cSrcweir     public static XSingleServiceFactory __getServiceFactory(String implName,
307cdf0e10cSrcweir                     XMultiServiceFactory multiFactory, XRegistryKey regKey)
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         XSingleServiceFactory xSingleServiceFactory = null;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         if (implName.equals(RunnerService.class.getName()))
312cdf0e10cSrcweir             xSingleServiceFactory = FactoryHelper.getServiceFactory(
313cdf0e10cSrcweir                 RunnerService.class, __serviceName, multiFactory, regKey);
314cdf0e10cSrcweir         xMSF = multiFactory;
315cdf0e10cSrcweir         return xSingleServiceFactory;
316cdf0e10cSrcweir     }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir   /**
319cdf0e10cSrcweir    * Writes the service information into the given registry key.
320cdf0e10cSrcweir    * This method is called by the <code>JavaLoader</code>
321cdf0e10cSrcweir    * <p>
322cdf0e10cSrcweir    * @return  returns true if the operation succeeded
323cdf0e10cSrcweir    * @param   regKey       the registryKey
324cdf0e10cSrcweir    * @see                  com.sun.star.comp.loader.JavaLoader
325cdf0e10cSrcweir    */
__writeRegistryServiceInfo(XRegistryKey regKey)326cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
327cdf0e10cSrcweir         return FactoryHelper.writeRegistryServiceInfo(RunnerService.class.getName(),
328cdf0e10cSrcweir         __serviceName, regKey);
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     /**
332cdf0e10cSrcweir      * empty: not needed here.
333cdf0e10cSrcweir      */
setPropertyValues(PropertyValue[] propertyValue)334cdf0e10cSrcweir     public void setPropertyValues(PropertyValue[] propertyValue)
335cdf0e10cSrcweir                         throws com.sun.star.beans.UnknownPropertyException,
336cdf0e10cSrcweir                                com.sun.star.beans.PropertyVetoException,
337cdf0e10cSrcweir                                com.sun.star.lang.IllegalArgumentException,
338cdf0e10cSrcweir                                com.sun.star.lang.WrappedTargetException {
339cdf0e10cSrcweir       // empty implementation
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir }
343