Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / base / java_fat_service.java
blob0c8fd17e43ecc3cb8450af8f44f4a520c8e95bbf
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 base;
31 import java.io.PrintWriter;
33 import lib.TestParameters;
34 import lib.TestCase;
35 import lib.MultiMethodTest;
36 import lib.TestEnvironment;
37 import util.DynamicClassLoader;
39 import com.sun.star.lang.XMultiServiceFactory;
41 import share.DescEntry;
42 import share.DescGetter;
43 import helper.APIDescGetter;
45 import share.LogWriter;
46 import stats.Summarizer;
48 /**
49 * this class handles tests written in java and running on a fat Office
50 * with the runner as a service.
52 public class java_fat_service implements TestBase {
54 static protected boolean debug = false;
55 protected LogWriter log = null;
57 public boolean executeTest(lib.TestParameters param) {
58 DynamicClassLoader dcl = new DynamicClassLoader();
59 log = (LogWriter)dcl.getInstance((String)param.get("LogWriter"));
60 debug = ((Boolean) param.get("DebugIsActive")).booleanValue();
62 DescGetter dg = new APIDescGetter();
63 String job = (String) param.get("TestJob");
64 boolean retValue = true;
66 //get Job-Descriptions
67 log.println("Getting Descriptions for Job: "+job);
68 DescEntry[] entries = dg.getDescriptionFor(job,
69 (String) param.get("DescriptionPath"),debug);
71 if (entries == null ) {
72 log.println("Couldn't get Description for Job");
73 return false;
76 String conStr = (String) param.get("ConnectionString");
78 XMultiServiceFactory msf = (XMultiServiceFactory)param.getMSF();
80 for (int l=0;l<entries.length;l++) {
82 if (entries[l] == null ) {
83 continue;
86 if (entries[l].hasErrorMsg) {
87 log.println(entries[l].ErrorMsg);
88 continue;
91 DescEntry entry = entries[l];
93 //get some helper classes
94 Summarizer sumIt = new Summarizer();
96 TestCase tCase = null;
97 try {
98 tCase = (TestCase)
99 dcl.getInstance("mod._"+entry.entryName);
100 } catch (java.lang.IllegalArgumentException ie) {
101 entry.ErrorMsg=ie.getMessage();
102 entry.hasErrorMsg=true;
105 if (tCase == null) {
106 sumIt.summarizeDown(entry,entry.ErrorMsg);
107 LogWriter sumObj = (LogWriter)dcl.getInstance(
108 (String)param.get("OutProducer"));
109 sumObj.initialize(entry,true);
110 entry.UserDefinedParams = param;
111 sumObj.summary(entry);
112 continue;
115 log.println("Creating: "+tCase.getObjectName());
117 log.initialize(entry,true);
118 entry.UserDefinedParams = param;
119 TestEnvironment tEnv = null;
120 try {
121 tCase.setLogWriter((PrintWriter) log);
122 tCase.initializeTestCase(param);
123 tEnv = tCase.getTestEnvironment(param);
124 } catch (Exception e) {
125 log.println("Exception while creating "+tCase.getObjectName());
126 log.println("Exception: " + e);
127 log.println("Message "+e.getMessage());
128 tEnv = null;
130 if (tEnv == null) {
131 sumIt.summarizeDown(entry,"Couldn't create "+tCase.getObjectName());
132 LogWriter sumObj = (LogWriter)dcl.getInstance(
133 (String)param.get("OutProducer"));
134 sumObj.initialize(entry,true);
135 entry.UserDefinedParams = param;
136 sumObj.summary(entry);
137 continue;
139 log.println("Created "+tCase.getObjectName()+"\n");
141 for (int j=0;j<entry.SubEntryCount;j++) {
142 if (!entry.SubEntries[j].isToTest) {
143 Summarizer.summarizeDown(entry.SubEntries[j],"not part of the job");
144 continue;
147 log.println("running: "+entry.SubEntries[j].entryName);
149 LogWriter ifclog = (LogWriter)dcl.getInstance(
150 (String)param.get("LogWriter"));
152 ifclog.initialize(entry.SubEntries[j],true);
153 entry.SubEntries[j].UserDefinedParams = param;
154 entry.SubEntries[j].Logger = ifclog;
156 if (tEnv == null || tEnv.isDisposed()) {
157 tEnv = getEnv(entry,param);
160 MultiMethodTest ifc = null;
161 lib.TestResult res = null;
162 try {
163 ifc = (MultiMethodTest) dcl.getInstance(
164 entry.SubEntries[j].entryName);
165 res = ifc.run(entry.SubEntries[j],tEnv,param);
166 } catch (IllegalArgumentException iae) {
167 log.println("Couldn't load class "+entry.SubEntries[j].entryName);
168 log.println("**** "+iae.getMessage()+" ****");
169 Summarizer.summarizeDown(entry.SubEntries[j],iae.getMessage());
170 } catch (java.lang.RuntimeException e) {
171 tEnv = getEnv(entry,param);
172 ifc = (MultiMethodTest) dcl.getInstance(
173 entry.SubEntries[j].entryName);
174 if ((tEnv != null) && (ifc != null)) {
175 res = ifc.run(entry.SubEntries[j],tEnv,param);
177 else
179 res = null;
182 if (res != null) {
183 for (int k=0;k<entry.SubEntries[j].SubEntryCount;k++) {
184 if (res.hasMethod(entry.SubEntries[j].SubEntries[k].entryName)) {
185 entry.SubEntries[j].SubEntries[k].State=
186 res.getStatusFor(entry.SubEntries[j].SubEntries[k].entryName).toString();
190 sumIt.summarizeUp(entry.SubEntries[j]);
192 LogWriter sumIfc = (LogWriter)dcl.getInstance(
193 (String)param.get("OutProducer"));
195 sumIfc.initialize(entry.SubEntries[j],true);
196 entry.SubEntries[j].UserDefinedParams = param;
197 sumIfc.summary(entry.SubEntries[j]);
199 try {
200 tCase.cleanupTestCase(param);
201 } catch (Exception e) {
202 e.printStackTrace((PrintWriter)log);
204 sumIt.summarizeUp(entry);
205 LogWriter sumObj = (LogWriter)dcl.getInstance(
206 (String)param.get("OutProducer"));
207 sumObj.initialize(entry,true);
208 sumObj.summary(entry);
210 if (entries.length > 1) {
211 log.println("");
212 int counter = 0;
213 log.println("Failures that appeared during scenario execution:");
214 for (int i=0;i<entries.length;i++) {
215 if (! entries[i].State.endsWith("OK")) {
216 log.println("\t "+entries[i].longName);
217 counter++;
220 log.println(counter +" of "+entries.length + " tests failed" );
223 return retValue;
226 protected TestEnvironment getEnv(DescEntry entry, TestParameters param) {
227 DynamicClassLoader dcl = new DynamicClassLoader();
228 log = (LogWriter)dcl.getInstance((String)param.get("LogWriter"));
229 XMultiServiceFactory msf = (XMultiServiceFactory)param.getMSF();
231 TestCase tCase = null;
235 tCase = (TestCase) dcl.getInstance("mod._"+entry.entryName);
237 catch (java.lang.IllegalArgumentException ie)
239 entry.ErrorMsg=ie.getMessage();
240 entry.hasErrorMsg=true;
243 log.println("Creating: "+tCase.getObjectName());
244 // LogWriter log = (LogWriter)dcl.getInstance( (String)param.get("LogWriter"));
245 log.initialize(entry,true);
246 entry.UserDefinedParams = param;
247 tCase.setLogWriter((PrintWriter) log);
248 TestEnvironment tEnv = null;
251 tCase.initializeTestCase(param);
252 tEnv = tCase.getTestEnvironment(param);
254 catch (com.sun.star.lang.DisposedException de)
256 log.println("Office disposed");
258 return tEnv;
261 // protected void shortWait(int millis) {
262 // try {
263 // Thread.sleep(millis);
264 // } catch (java.lang.InterruptedException ie) {}
265 // }