Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / qadevOOo / runner / base / java_fat.java
blobbd21b0861752d36b9c45576e0162d8b6f44676f1
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 .
18 package base;
20 import helper.APIDescGetter;
21 import helper.AppProvider;
23 import java.io.BufferedReader;
24 import java.io.FileInputStream;
25 import java.io.InputStreamReader;
26 import java.io.PrintWriter;
27 import java.io.UnsupportedEncodingException;
28 import java.util.ArrayList;
29 import lib.MultiMethodTest;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import lib.TestResult;
34 import share.DescEntry;
35 import share.DescGetter;
36 import share.LogWriter;
37 import stats.OutProducerFactory;
38 import stats.Summarizer;
39 import util.DynamicClassLoader;
41 import com.sun.star.lang.XMultiServiceFactory;
43 /**
45 * this class handles tests written in java and running on a fat Office
47 public class java_fat implements TestBase {
49 private boolean logging = true;
50 private DynamicClassLoader m_aDynamicClassLoader = null;
52 private lib.TestParameters m_aParams;
53 private AppProvider m_aOffice;
55 public boolean executeTest(lib.TestParameters _aParams) throws Exception {
56 m_aParams = _aParams;
58 m_aDynamicClassLoader = new DynamicClassLoader();
60 DescGetter dg = new APIDescGetter();
61 String job = (String) m_aParams.get("TestJob");
62 String ExclusionFile = (String) m_aParams.get("ExclusionList");
63 ArrayList<String> exclusions = null;
64 boolean retValue = true;
65 boolean isDebug = m_aParams.getBool("DebugIsActive");
66 logging = m_aParams.getBool("LoggingIsActive");
67 boolean keepdocument = m_aParams.getBool("KeepDocument");
68 boolean newOffice = m_aParams
69 .getBool(util.PropertyName.NEW_OFFICE_INSTANCE);
70 if (keepdocument) {
71 System.setProperty("KeepDocument", "true");
73 if (ExclusionFile != null) {
74 exclusions = getExclusionList(ExclusionFile, isDebug);
77 String sDescriptionPath = (String) m_aParams.get("DescriptionPath");
78 DescEntry[] entries = dg.getDescriptionFor(job, sDescriptionPath,
79 isDebug);
81 if (entries == null) {
82 System.out.println("Couldn't get Description for Job: " + job);
84 return false;
87 m_aOffice = startOffice(m_aParams);
89 boolean firstRun = true;
91 // Run through all entries (e.g. sw.SwXBookmark.*)
93 for (int l = 0; l < entries.length; l++) {
94 DescEntry entry = entries[l];
96 if (entry == null) {
97 continue;
100 if (entry.hasErrorMsg) {
101 System.out.println(entries[l].ErrorMsg);
102 retValue = false;
103 continue;
106 if (!firstRun && newOffice) {
107 if (!m_aOffice.closeExistingOffice(m_aParams, true)) {
108 m_aOffice.disposeManager(m_aParams);
110 startOffice(m_aParams);
112 firstRun = false;
114 XMultiServiceFactory msf = m_aParams.getMSF();
116 if (msf == null) {
117 retValue = false;
118 continue;
121 // get some helper classes
122 Summarizer sumIt = new Summarizer();
123 TestCase tCase = getTestCase(entry);
124 if (tCase == null) {
125 continue;
128 util.utils.pause(2000);
130 System.out.println("Creating: " + entry.entryName);
132 LogWriter log = (LogWriter) m_aDynamicClassLoader
133 .getInstance((String) m_aParams.get("LogWriter"));
134 log.initialize(entry, logging);
135 entry.UserDefinedParams = m_aParams;
137 tCase.setLogWriter((PrintWriter) log);
138 tCase.initializeTestCase(m_aParams);
140 TestEnvironment tEnv = getTestEnvironment(tCase, entry);
141 if (tEnv == null) {
142 continue;
145 for (int j = 0; j < entry.SubEntryCount; j++) {
146 DescEntry aSubEntry = entry.SubEntries[j];
147 final boolean bIsToTest = aSubEntry.isToTest;
148 if (!bIsToTest) {
149 Summarizer.summarizeDown(aSubEntry, "not part of the job");
150 continue;
153 final String sLongEntryName = aSubEntry.longName;
155 if ((exclusions != null)
156 && (exclusions.contains(sLongEntryName))) {
157 Summarizer.summarizeDown(aSubEntry, "known issue");
158 continue;
161 // this will shown in test itself
163 LogWriter ifclog = (LogWriter) m_aDynamicClassLoader
164 .getInstance((String) m_aParams.get("LogWriter"));
166 ifclog.initialize(aSubEntry, logging);
167 aSubEntry.UserDefinedParams = m_aParams;
168 aSubEntry.Logger = ifclog;
170 if (tEnv.isDisposed()) {
171 closeExistingOffice();
172 tEnv = getEnv(entry, m_aParams);
173 tCase = tEnv.getTestCase();
176 lib.TestResult res = null;
178 // run the interface test twice if it failed.
179 int countInterfaceTestRun = 0;
180 boolean finished = false;
181 while (!finished) {
182 try {
183 countInterfaceTestRun++;
184 finished = true;
185 res = executeInterfaceTest(aSubEntry, tEnv, m_aParams);
186 } catch (IllegalArgumentException iae) {
187 System.out.println("Couldn't load class "
188 + aSubEntry.entryName + ":");
189 iae.printStackTrace(System.out);
190 Summarizer.summarizeDown(aSubEntry, iae.getMessage());
191 } catch (java.lang.NoClassDefFoundError iae) {
192 System.out.println("Couldn't load class "
193 + aSubEntry.entryName + ":");
194 iae.printStackTrace(System.out);
195 Summarizer.summarizeDown(aSubEntry, iae.getMessage());
196 } catch (java.lang.RuntimeException e) {
197 closeExistingOffice();
198 tEnv = getEnv(entry, m_aParams);
199 tCase = tEnv.getTestCase();
200 if (countInterfaceTestRun < 2) {
201 finished = false;
202 } else {
203 Summarizer.summarizeDown(aSubEntry, e.toString()
204 + ".FAILED");
208 setState(aSubEntry, res);
210 sumIt.summarizeUp(aSubEntry);
212 LogWriter sumIfc = OutProducerFactory
213 .createOutProducer(m_aParams);
214 aSubEntry.UserDefinedParams = m_aParams;
215 sumIfc.initialize(aSubEntry, logging);
216 sumIfc.summary(aSubEntry);
219 try {
220 if (!keepdocument) {
221 tCase.cleanupTestCase(m_aParams);
223 } catch (Exception e) {
224 System.err.println("couldn't cleanup:" + e.toString());
225 } catch (java.lang.NoClassDefFoundError e) {
226 System.err.println("couldn't cleanup:" + e.toString());
229 sumIt.summarizeUp(entry);
231 LogWriter sumObj = OutProducerFactory.createOutProducer(m_aParams);
233 sumObj.initialize(entry, logging);
234 sumObj.summary(entry);
237 if (entries.length > 0) {
238 System.out.println();
240 int counter = 0;
241 System.out
242 .println("Failures that appeared during scenario execution:");
244 for (int i = 0; i < entries.length; i++) {
245 final String sState = entries[i].State;
246 if (!sState.endsWith("OK")) {
247 System.out.println("\t " + entries[i].longName);
248 counter++;
252 System.out.println(counter + " of " + entries.length
253 + " tests failed");
254 if (counter != 0) {
255 retValue = false;
259 closeExistingOffice();
260 return retValue;
263 private TestEnvironment getTestEnvironment(TestCase tCase, DescEntry entry) {
264 TestEnvironment tEnv = null;
266 try {
267 tEnv = tCase.getTestEnvironment(m_aParams);
268 } catch (Exception e) {
269 System.out.println("Exception while creating "
270 + tCase.getObjectName());
271 System.out.println("Message " + e.getMessage());
272 e.printStackTrace();
273 tEnv = null;
274 } catch (java.lang.UnsatisfiedLinkError e) {
275 System.out.println("Exception while creating "
276 + tCase.getObjectName());
277 System.out.println("Message " + e.getMessage());
278 tEnv = null;
279 } catch (java.lang.NoClassDefFoundError e) {
280 System.out.println("Exception while creating "
281 + tCase.getObjectName());
282 System.out.println("Message " + e.getMessage());
283 tEnv = null;
286 if (tEnv == null) {
287 Summarizer.summarizeDown(entry,
288 "Couldn't create " + tCase.getObjectName());
290 LogWriter sumObj = OutProducerFactory.createOutProducer(m_aParams);
291 entry.UserDefinedParams = m_aParams;
292 sumObj.initialize(entry, logging);
293 sumObj.summary(entry);
295 return tEnv;
298 private TestCase getTestCase(DescEntry _aEntry) {
299 TestCase tCase = null;
301 try {
302 tCase = (TestCase) m_aDynamicClassLoader.getInstance("mod._"
303 + _aEntry.entryName);
304 } catch (java.lang.IllegalArgumentException ie) {
305 _aEntry.ErrorMsg = ie.getMessage();
306 _aEntry.hasErrorMsg = true;
307 } catch (java.lang.NoClassDefFoundError ie) {
308 _aEntry.ErrorMsg = ie.getMessage();
309 _aEntry.hasErrorMsg = true;
312 if (tCase == null) {
313 Summarizer.summarizeDown(_aEntry, _aEntry.ErrorMsg);
315 LogWriter sumObj = OutProducerFactory.createOutProducer(m_aParams);
316 _aEntry.UserDefinedParams = m_aParams;
317 sumObj.initialize(_aEntry, logging);
318 sumObj.summary(_aEntry);
320 return tCase;
323 private void setState(DescEntry aSubEntry, lib.TestResult res) {
324 if (res != null) {
325 for (int k = 0; k < aSubEntry.SubEntryCount; k++) {
326 DescEntry aSubSubEntry = aSubEntry.SubEntries[k];
327 if (res.hasMethod(aSubSubEntry.entryName)) {
328 aSubSubEntry.State = res.getStatusFor(
329 aSubSubEntry.entryName).toString();
335 private TestEnvironment getEnv(DescEntry entry, TestParameters param) throws Exception {
336 TestCase tCase = null;
338 try {
339 tCase = (TestCase) m_aDynamicClassLoader.getInstance("mod._"
340 + entry.entryName);
341 } catch (java.lang.IllegalArgumentException ie) {
342 entry.ErrorMsg = ie.getMessage();
343 entry.hasErrorMsg = true;
344 } catch (java.lang.NoClassDefFoundError ie) {
345 entry.ErrorMsg = ie.getMessage();
346 entry.hasErrorMsg = true;
349 System.out.println("Creating: " + entry.entryName);
351 entry.UserDefinedParams = param;
353 LogWriter log = (LogWriter) m_aDynamicClassLoader
354 .getInstance((String) param.get("LogWriter"));
355 log.initialize(entry, logging);
356 tCase.setLogWriter((PrintWriter) log);
358 try {
359 tCase.initializeTestCase(param);
360 TestEnvironment tEnv = tCase.getTestEnvironment(param);
361 if (tEnv == null) {
362 throw new Exception("Could not get env for '" + entry.entryName + "'");
364 return tEnv;
365 } catch (com.sun.star.lang.DisposedException de) {
366 System.out.println("Office disposed");
367 closeExistingOffice();
368 throw de;
369 } catch (Exception e) {
370 System.out.println(e.getMessage());
372 closeExistingOffice();
374 entry.ErrorMsg = e.getMessage();
375 entry.hasErrorMsg = true;
376 throw e;
380 private void closeExistingOffice() {
381 helper.ProcessHandler ph = (helper.ProcessHandler) m_aParams
382 .get("AppProvider");
384 if (ph != null) {
385 m_aOffice.closeExistingOffice(m_aParams, true);
386 util.utils.pause(5000);
391 private ArrayList<String> getExclusionList(String url, boolean debug) {
392 ArrayList<String> entryList = new ArrayList<String>();
393 String line = "#";
394 BufferedReader exclusion = null;
396 try {
397 InputStreamReader reader = new InputStreamReader(new FileInputStream(url), "UTF-8");
398 exclusion = new BufferedReader(reader);
399 } catch (java.io.UnsupportedEncodingException uee) {
400 if (debug) {
401 System.out.println("Couldn't decode file " + url);
404 return entryList;
405 } catch (java.io.FileNotFoundException fnfe) {
406 if (debug) {
407 System.out.println("Couldn't find file " + url);
410 return entryList;
413 try {
414 while (line != null) {
415 try {
416 if (!line.startsWith("#") && (line.length() > 1)) {
417 entryList.add(line.trim());
420 line = exclusion.readLine();
421 } catch (java.io.IOException ioe) {
422 if (debug) {
423 System.out
424 .println("Exception while reading exclusion list");
427 return entryList;
430 } finally {
431 try {
432 exclusion.close();
433 } catch (java.io.IOException ioe) {
437 return entryList;
440 private TestResult executeInterfaceTest(DescEntry entry,
441 TestEnvironment tEnv, TestParameters param)
442 throws IllegalArgumentException, java.lang.NoClassDefFoundError {
443 MultiMethodTest ifc = (MultiMethodTest) m_aDynamicClassLoader
444 .getInstance(entry.entryName);
445 return ifc.run(entry, tEnv, param);
448 private AppProvider startOffice(lib.TestParameters param) throws UnsupportedEncodingException {
449 if (m_aDynamicClassLoader == null) {
450 m_aDynamicClassLoader = new DynamicClassLoader();
453 String officeProviderName = (String) param.get("OfficeProvider");
454 AppProvider office = (AppProvider) m_aDynamicClassLoader
455 .getInstance(officeProviderName);
457 if (office == null) {
458 System.out.println("ERROR: Wrong parameter 'OfficeProvider', "
459 + " it cannot be instantiated.");
460 System.exit(-1);
463 XMultiServiceFactory msf = (XMultiServiceFactory) office
464 .getManager(param);
466 if (msf != null) {
467 param.put("ServiceFactory", msf);
470 return office;