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 .
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
.util
.ArrayList
;
28 import lib
.MultiMethodTest
;
30 import lib
.TestEnvironment
;
31 import lib
.TestParameters
;
32 import lib
.TestResult
;
33 import share
.DescEntry
;
34 import share
.DescGetter
;
35 import share
.LogWriter
;
36 import stats
.OutProducerFactory
;
37 import stats
.Summarizer
;
38 import util
.DynamicClassLoader
;
40 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 * this class handles tests written in java and running on a fat Office
46 public class java_fat
implements TestBase
{
48 private boolean logging
= true;
49 private DynamicClassLoader m_aDynamicClassLoader
= null;
51 private lib
.TestParameters m_aParams
;
52 private AppProvider m_aOffice
;
54 public boolean executeTest(lib
.TestParameters _aParams
) throws Exception
{
57 m_aDynamicClassLoader
= new DynamicClassLoader();
59 DescGetter dg
= new APIDescGetter();
60 String job
= (String
) m_aParams
.get("TestJob");
61 String ExclusionFile
= (String
) m_aParams
.get("ExclusionList");
62 ArrayList
<String
> exclusions
= null;
63 boolean retValue
= true;
64 boolean isDebug
= m_aParams
.getBool("DebugIsActive");
65 logging
= m_aParams
.getBool("LoggingIsActive");
66 boolean keepdocument
= m_aParams
.getBool("KeepDocument");
67 boolean newOffice
= m_aParams
68 .getBool(util
.PropertyName
.NEW_OFFICE_INSTANCE
);
70 System
.setProperty("KeepDocument", "true");
72 if (ExclusionFile
!= null) {
73 exclusions
= getExclusionList(ExclusionFile
, isDebug
);
76 String sDescriptionPath
= (String
) m_aParams
.get("DescriptionPath");
77 DescEntry
[] entries
= dg
.getDescriptionFor(job
, sDescriptionPath
,
80 if (entries
== null) {
81 System
.out
.println("Couldn't get Description for Job: " + job
);
86 m_aOffice
= startOffice(m_aParams
);
88 boolean firstRun
= true;
90 // Run through all entries (e.g. sw.SwXBookmark.*)
92 for (int l
= 0; l
< entries
.length
; l
++) {
93 DescEntry entry
= entries
[l
];
99 if (entry
.hasErrorMsg
) {
100 System
.out
.println(entries
[l
].ErrorMsg
);
105 if (!firstRun
&& newOffice
) {
106 if (!m_aOffice
.closeExistingOffice(m_aParams
, true)) {
107 m_aOffice
.disposeManager(m_aParams
);
109 startOffice(m_aParams
);
113 XMultiServiceFactory msf
= m_aParams
.getMSF();
120 // get some helper classes
121 Summarizer sumIt
= new Summarizer();
122 TestCase tCase
= getTestCase(entry
);
127 util
.utils
.pause(2000);
129 System
.out
.println("Creating: " + entry
.entryName
);
131 LogWriter log
= (LogWriter
) m_aDynamicClassLoader
132 .getInstance((String
) m_aParams
.get("LogWriter"));
133 log
.initialize(entry
, logging
);
134 entry
.UserDefinedParams
= m_aParams
;
136 tCase
.setLogWriter((PrintWriter
) log
);
137 tCase
.initializeTestCase(m_aParams
);
139 TestEnvironment tEnv
= getTestEnvironment(tCase
, entry
);
144 tCase
.getObjectName();
146 for (int j
= 0; j
< entry
.SubEntryCount
; j
++) {
147 DescEntry aSubEntry
= entry
.SubEntries
[j
];
148 final boolean bIsToTest
= aSubEntry
.isToTest
;
150 Summarizer
.summarizeDown(aSubEntry
, "not part of the job");
154 final String sLongEntryName
= aSubEntry
.longName
;
156 if ((exclusions
!= null)
157 && (exclusions
.contains(sLongEntryName
))) {
158 Summarizer
.summarizeDown(aSubEntry
, "known issue");
162 // this will shown in test itself
164 LogWriter ifclog
= (LogWriter
) m_aDynamicClassLoader
165 .getInstance((String
) m_aParams
.get("LogWriter"));
167 ifclog
.initialize(aSubEntry
, logging
);
168 aSubEntry
.UserDefinedParams
= m_aParams
;
169 aSubEntry
.Logger
= ifclog
;
171 if (tEnv
.isDisposed()) {
172 closeExistingOffice();
173 tEnv
= getEnv(entry
, m_aParams
);
174 tCase
= tEnv
.getTestCase();
177 lib
.TestResult res
= null;
179 // run the interface test twice if it failed.
180 int countInterfaceTestRun
= 0;
181 boolean finished
= false;
184 countInterfaceTestRun
++;
186 res
= executeInterfaceTest(aSubEntry
, tEnv
, m_aParams
);
187 } catch (IllegalArgumentException iae
) {
188 System
.out
.println("Couldn't load class "
189 + aSubEntry
.entryName
);
191 .println("**** " + iae
.getMessage() + " ****");
192 Summarizer
.summarizeDown(aSubEntry
, iae
.getMessage());
193 } catch (java
.lang
.NoClassDefFoundError iae
) {
194 System
.out
.println("Couldn't load class "
195 + aSubEntry
.entryName
);
197 .println("**** " + iae
.getMessage() + " ****");
198 Summarizer
.summarizeDown(aSubEntry
, iae
.getMessage());
199 } catch (java
.lang
.RuntimeException e
) {
200 closeExistingOffice();
201 tEnv
= getEnv(entry
, m_aParams
);
202 tCase
= tEnv
.getTestCase();
203 if (countInterfaceTestRun
< 2) {
206 Summarizer
.summarizeDown(aSubEntry
, e
.toString()
211 setState(aSubEntry
, res
);
213 sumIt
.summarizeUp(aSubEntry
);
215 LogWriter sumIfc
= OutProducerFactory
216 .createOutProducer(m_aParams
);
217 aSubEntry
.UserDefinedParams
= m_aParams
;
218 sumIfc
.initialize(aSubEntry
, logging
);
219 sumIfc
.summary(aSubEntry
);
224 tCase
.cleanupTestCase(m_aParams
);
226 } catch (Exception e
) {
227 System
.err
.println("couldn't cleanup:" + e
.toString());
228 } catch (java
.lang
.NoClassDefFoundError e
) {
229 System
.err
.println("couldn't cleanup:" + e
.toString());
232 sumIt
.summarizeUp(entry
);
234 LogWriter sumObj
= OutProducerFactory
.createOutProducer(m_aParams
);
236 sumObj
.initialize(entry
, logging
);
237 sumObj
.summary(entry
);
240 if (entries
.length
> 0) {
241 System
.out
.println();
245 .println("Failures that appeared during scenario execution:");
247 for (int i
= 0; i
< entries
.length
; i
++) {
248 final String sState
= entries
[i
].State
;
249 if (!sState
.endsWith("OK")) {
250 System
.out
.println("\t " + entries
[i
].longName
);
255 System
.out
.println(counter
+ " of " + entries
.length
262 closeExistingOffice();
266 private TestEnvironment
getTestEnvironment(TestCase tCase
, DescEntry entry
) {
267 TestEnvironment tEnv
= null;
270 tEnv
= tCase
.getTestEnvironment(m_aParams
);
271 } catch (Exception e
) {
272 System
.out
.println("Exception while creating "
273 + tCase
.getObjectName());
274 System
.out
.println("Message " + e
.getMessage());
277 } catch (java
.lang
.UnsatisfiedLinkError e
) {
278 System
.out
.println("Exception while creating "
279 + tCase
.getObjectName());
280 System
.out
.println("Message " + e
.getMessage());
282 } catch (java
.lang
.NoClassDefFoundError e
) {
283 System
.out
.println("Exception while creating "
284 + tCase
.getObjectName());
285 System
.out
.println("Message " + e
.getMessage());
290 Summarizer
.summarizeDown(entry
,
291 "Couldn't create " + tCase
.getObjectName());
293 LogWriter sumObj
= OutProducerFactory
.createOutProducer(m_aParams
);
294 entry
.UserDefinedParams
= m_aParams
;
295 sumObj
.initialize(entry
, logging
);
296 sumObj
.summary(entry
);
301 private TestCase
getTestCase(DescEntry _aEntry
) {
302 TestCase tCase
= null;
305 tCase
= (TestCase
) m_aDynamicClassLoader
.getInstance("mod._"
306 + _aEntry
.entryName
);
307 } catch (java
.lang
.IllegalArgumentException ie
) {
308 _aEntry
.ErrorMsg
= ie
.getMessage();
309 _aEntry
.hasErrorMsg
= true;
310 } catch (java
.lang
.NoClassDefFoundError ie
) {
311 _aEntry
.ErrorMsg
= ie
.getMessage();
312 _aEntry
.hasErrorMsg
= true;
316 Summarizer
.summarizeDown(_aEntry
, _aEntry
.ErrorMsg
);
318 LogWriter sumObj
= OutProducerFactory
.createOutProducer(m_aParams
);
319 _aEntry
.UserDefinedParams
= m_aParams
;
320 sumObj
.initialize(_aEntry
, logging
);
321 sumObj
.summary(_aEntry
);
326 private void setState(DescEntry aSubEntry
, lib
.TestResult res
) {
328 for (int k
= 0; k
< aSubEntry
.SubEntryCount
; k
++) {
329 DescEntry aSubSubEntry
= aSubEntry
.SubEntries
[k
];
330 if (res
.hasMethod(aSubSubEntry
.entryName
)) {
331 aSubSubEntry
.State
= res
.getStatusFor(
332 aSubSubEntry
.entryName
).toString();
338 private TestEnvironment
getEnv(DescEntry entry
, TestParameters param
) throws Exception
{
339 TestCase tCase
= null;
342 tCase
= (TestCase
) m_aDynamicClassLoader
.getInstance("mod._"
344 } catch (java
.lang
.IllegalArgumentException ie
) {
345 entry
.ErrorMsg
= ie
.getMessage();
346 entry
.hasErrorMsg
= true;
347 } catch (java
.lang
.NoClassDefFoundError ie
) {
348 entry
.ErrorMsg
= ie
.getMessage();
349 entry
.hasErrorMsg
= true;
352 System
.out
.println("Creating: " + entry
.entryName
);
354 entry
.UserDefinedParams
= param
;
356 LogWriter log
= (LogWriter
) m_aDynamicClassLoader
357 .getInstance((String
) param
.get("LogWriter"));
358 log
.initialize(entry
, logging
);
359 tCase
.setLogWriter((PrintWriter
) log
);
362 tCase
.initializeTestCase(param
);
363 TestEnvironment tEnv
= tCase
.getTestEnvironment(param
);
365 throw new Exception("Could not get env for '" + entry
.entryName
+ "'");
368 } catch (com
.sun
.star
.lang
.DisposedException de
) {
369 System
.out
.println("Office disposed");
370 closeExistingOffice();
372 } catch (Exception e
) {
373 System
.out
.println(e
.getMessage());
375 closeExistingOffice();
377 entry
.ErrorMsg
= e
.getMessage();
378 entry
.hasErrorMsg
= true;
383 private void closeExistingOffice() {
384 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) m_aParams
388 m_aOffice
.closeExistingOffice(m_aParams
, true);
389 util
.utils
.pause(5000);
394 private ArrayList
<String
> getExclusionList(String url
, boolean debug
) {
395 ArrayList
<String
> entryList
= new ArrayList
<String
>();
397 BufferedReader exclusion
= null;
400 InputStreamReader reader
= new InputStreamReader(new FileInputStream(url
), "UTF-8");
401 exclusion
= new BufferedReader(reader
);
402 } catch (java
.io
.UnsupportedEncodingException uee
) {
404 System
.out
.println("Couldn't decode file " + url
);
408 } catch (java
.io
.FileNotFoundException fnfe
) {
410 System
.out
.println("Couldn't find file " + url
);
417 while (line
!= null) {
419 if (!line
.startsWith("#") && (line
.length() > 1)) {
420 entryList
.add(line
.trim());
423 line
= exclusion
.readLine();
424 } catch (java
.io
.IOException ioe
) {
427 .println("Exception while reading exclusion list");
436 } catch (java
.io
.IOException ioe
) {
443 private TestResult
executeInterfaceTest(DescEntry entry
,
444 TestEnvironment tEnv
, TestParameters param
)
445 throws IllegalArgumentException
, java
.lang
.NoClassDefFoundError
{
446 MultiMethodTest ifc
= (MultiMethodTest
) m_aDynamicClassLoader
447 .getInstance(entry
.entryName
);
448 return ifc
.run(entry
, tEnv
, param
);
451 private AppProvider
startOffice(lib
.TestParameters param
) {
452 if (m_aDynamicClassLoader
== null) {
453 m_aDynamicClassLoader
= new DynamicClassLoader();
456 String officeProviderName
= (String
) param
.get("OfficeProvider");
457 AppProvider office
= (AppProvider
) m_aDynamicClassLoader
458 .getInstance(officeProviderName
);
460 if (office
== null) {
461 System
.out
.println("ERROR: Wrong parameter 'OfficeProvider', "
462 + " it cannot be instantiated.");
466 XMultiServiceFactory msf
= (XMultiServiceFactory
) office
470 param
.put("ServiceFactory", msf
);