diff options
Diffstat (limited to 'qadevOOo')
42 files changed, 3853 insertions, 1817 deletions
diff --git a/qadevOOo/makefile.mk b/qadevOOo/makefile.mk index de756b44a149..b6f816f3ce3d 100755 --- a/qadevOOo/makefile.mk +++ b/qadevOOo/makefile.mk @@ -42,13 +42,14 @@ debug=true # ------------------------------------------------ .INCLUDE : ant.mk - TST: echo $(SOLAR_JAVA) .IF "$(SOLAR_JAVA)"=="TRUE" .IF "$(ANT_HOME)"!="NO_ANT_HOME" ANT_FLAGS+=-Dbuild.source=1.5 +.IF "$(L10N_framework)"=="" ALLTAR: ANTBUILD .ENDIF .ENDIF +.ENDIF diff --git a/qadevOOo/objdsc/qadevOOo/bogus.SelfTest.csv b/qadevOOo/objdsc/qadevOOo/bogus.SelfTest.csv new file mode 100755 index 000000000000..3983a1e88578 --- /dev/null +++ b/qadevOOo/objdsc/qadevOOo/bogus.SelfTest.csv @@ -0,0 +1,7 @@ +# "Name"; +# "com::sun::star::" will overread +# method name which is called +"SelfTest";"com::sun::star::qadevooo::SelfTest";"testmethod()" +"SelfTest";"com::sun::star::qadevooo::SelfTest";"testmethod2()" +"SelfTest";"com::sun::star::qadevooo::SelfTest";"testmethod3()" +# "SelfTest";"com::sun::star::qadevooo::SelfTest#optional";"testmethod4_bogus()" diff --git a/qadevOOo/qa/unoapi/knownissues.xcl b/qadevOOo/qa/unoapi/knownissues.xcl new file mode 100755 index 000000000000..02c509060d97 --- /dev/null +++ b/qadevOOo/qa/unoapi/knownissues.xcl @@ -0,0 +1 @@ +# This file contains all Errors diff --git a/qadevOOo/qa/unoapi/makefile.mk b/qadevOOo/qa/unoapi/makefile.mk new file mode 100755 index 000000000000..936884bfecbc --- /dev/null +++ b/qadevOOo/qa/unoapi/makefile.mk @@ -0,0 +1,44 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.8 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=qadevOOo +TARGET=qa_unoapi + +.INCLUDE: settings.mk + +.INCLUDE: target.mk + +ALLTAR : UNOAPI_TEST + +UNOAPI_TEST: + +$(SOLARENV)$/bin$/checkapi -sce qadevOOo.sce -xcl knownissues.xcl -tdoc $(PWD)$/testdocuments diff --git a/qadevOOo/qa/unoapi/qadevOOo.sce b/qadevOOo/qa/unoapi/qadevOOo.sce new file mode 100755 index 000000000000..8e24c474e7e8 --- /dev/null +++ b/qadevOOo/qa/unoapi/qadevOOo.sce @@ -0,0 +1 @@ +-o qadevOOo.SelfTest diff --git a/qadevOOo/runner/base/basic_fat.java b/qadevOOo/runner/base/basic_fat.java index fe7c541449d6..a46a8abbc9b4 100644 --- a/qadevOOo/runner/base/basic_fat.java +++ b/qadevOOo/runner/base/basic_fat.java @@ -60,12 +60,13 @@ import stats.Summarizer; import util.DynamicClassLoader; - /** * The testbase for executing basic tests. * @see lib.TestBase */ -public class basic_fat implements TestBase { +public class basic_fat implements TestBase +{ + public static boolean debug = false; /** @@ -73,7 +74,8 @@ public class basic_fat implements TestBase { * @param param The test parameters. * @param return True, if the test was executed. */ - public boolean executeTest(TestParameters param) { + public boolean executeTest(TestParameters param) + { DescGetter dg = new APIDescGetter(); String job = (String) param.get("TestJob"); OfficeProvider office = null; @@ -84,11 +86,12 @@ public class basic_fat implements TestBase { System.out.print("Getting Descriptions for Job: " + job + " from "); DescEntry[] entries = dg.getDescriptionFor(job, - (String) param.get( - "DescriptionPath"), - debug); + (String) param.get( + "DescriptionPath"), + debug); - if (entries == null) { + if (entries == null) + { System.out.println("Couldn't get Description for Job"); return false; @@ -97,7 +100,8 @@ public class basic_fat implements TestBase { String ExclusionFile = (String) param.get("ExclusionList"); Vector exclusions = null; - if (ExclusionFile != null) { + if (ExclusionFile != null) + { exclusions = getExclusionList(ExclusionFile, debug); } @@ -106,8 +110,10 @@ public class basic_fat implements TestBase { System.out.print("> Connecting the Office "); System.out.println("With " + conStr); - for (int l = 0; l < entries.length; l++) { - if (entries[l].hasErrorMsg) { + for (int l = 0; l < entries.length; l++) + { + if (entries[l].hasErrorMsg) + { System.out.println(entries[l].ErrorMsg); continue; @@ -116,9 +122,10 @@ public class basic_fat implements TestBase { office = new OfficeProvider(); XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager( - param); + param); - if (msf == null) { + if (msf == null) + { return false; } @@ -134,7 +141,8 @@ public class basic_fat implements TestBase { tCase = (TestCase) new BasicTestCase(entry); - if (tCase == null) { + if (tCase == null) + { sumIt.summarizeDown(entry, entry.ErrorMsg); LogWriter sumObj = OutProducerFactory.createOutProducer(param); @@ -147,21 +155,26 @@ public class basic_fat implements TestBase { System.out.println("Creating: " + tCase.getObjectName()); LogWriter log = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); + (String) param.get("LogWriter")); log.initialize(entry, true); entry.UserDefinedParams = param; tCase.setLogWriter((PrintWriter) log); - try { + try + { tCase.initializeTestCase(param); - } catch (RuntimeException e) { + } + catch (RuntimeException e) + { helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + "AppProvider"); - if (ph != null) { + if (ph != null) + { OfficeWatcher ow = (OfficeWatcher) param.get("Watcher"); - if ((ow != null) && ow.isAlive()) { + if ((ow != null) && ow.isAlive()) + { ow.finish = true; } @@ -174,7 +187,8 @@ public class basic_fat implements TestBase { TestEnvironment tEnv = tCase.getTestEnvironment(param); - if (tEnv == null) { + if (tEnv == null) + { sumIt.summarizeDown(entry, "Unable to create testcase"); LogWriter sumObj = OutProducerFactory.createOutProducer(param); @@ -182,12 +196,14 @@ public class basic_fat implements TestBase { sumObj.summary(entry); helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + "AppProvider"); - if (ph != null) { + if (ph != null) + { OfficeWatcher ow = (OfficeWatcher) param.get("Watcher"); - if ((ow != null) && ow.isAlive()) { + if ((ow != null) && ow.isAlive()) + { ow.finish = true; } @@ -200,36 +216,41 @@ public class basic_fat implements TestBase { System.out.println("created " + tCase.getObjectName()); - for (int j = 0; j < entry.SubEntryCount; j++) { - if (!entry.SubEntries[j].isToTest) { + for (int j = 0; j < entry.SubEntryCount; j++) + { + if (!entry.SubEntries[j].isToTest) + { Summarizer.summarizeDown(entry.SubEntries[j], - "not part of the job"); + "not part of the job"); continue; } if ((exclusions != null) && - (exclusions.contains(entry.SubEntries[j].longName))) { + (exclusions.contains(entry.SubEntries[j].longName))) + { Summarizer.summarizeDown(entry.SubEntries[j], - "known issue"); + "known issue"); continue; } System.out.println("running: " + - entry.SubEntries[j].entryName); + entry.SubEntries[j].entryName); LogWriter ifclog = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); + (String) param.get("LogWriter")); ifclog.initialize(entry.SubEntries[j], true); entry.SubEntries[j].UserDefinedParams = param; entry.SubEntries[j].Logger = ifclog; - if ((tEnv == null) || tEnv.isDisposed()) { + if ((tEnv == null) || tEnv.isDisposed()) + { helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + "AppProvider"); - if (ph != null) { + if (ph != null) + { office.closeExistingOffice(param, true); shortWait(5000); } @@ -250,15 +271,19 @@ public class basic_fat implements TestBase { sumIfc.summary(entry.SubEntries[j]); } - try { + try + { tCase.cleanupTestCase(param); - } catch (Exception e) { + } + catch (Exception e) + { log.println("TestCase already gone"); helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + "AppProvider"); - if (ph != null) { + if (ph != null) + { office.closeExistingOffice(param, true); shortWait(5000); } @@ -271,49 +296,56 @@ public class basic_fat implements TestBase { sumObj.summary(entry); } - if (entries.length > 1) { + if (entries.length > 1) + { System.out.println(); int counter = 0; System.out.println( "Failures that appeared during scenario execution:"); - for (int i = 0; i < entries.length; i++) { - if (!entries[i].State.endsWith("OK")) { + for (int i = 0; i < entries.length; i++) + { + if (!entries[i].State.endsWith("OK")) + { System.out.println("\t " + entries[i].longName); counter++; } } System.out.println(counter + " of " + entries.length + - " tests failed"); + " tests failed"); } helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + "AppProvider"); - if (ph != null) { + if (ph != null) + { office.closeExistingOffice(param, true); } return true; } - protected TestEnvironment getEnv(DescEntry entry, TestParameters param) { + protected TestEnvironment getEnv(DescEntry entry, TestParameters param) + { DynamicClassLoader dcl = new DynamicClassLoader(); String officeProviderName = (String) param.get("OfficeProvider"); AppProvider office = (AppProvider) dcl.getInstance(officeProviderName); - if (office == null) { + if (office == null) + { System.out.println("ERROR: Wrong parameter 'OfficeProvider', " + - " it cannot be instantiated."); + " it cannot be instantiated."); System.exit(-1); } XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager( - param); + param); - if (msf == null) { + if (msf == null) + { return null; } @@ -324,23 +356,27 @@ public class basic_fat implements TestBase { System.out.println("Creating: " + tCase.getObjectName()); LogWriter log = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); + (String) param.get("LogWriter")); log.initialize(entry, true); entry.UserDefinedParams = param; tCase.setLogWriter((PrintWriter) log); TestEnvironment tEnv = null; - try { + try + { tCase.initializeTestCase(param); tEnv = tCase.getTestEnvironment(param); - } catch (java.lang.RuntimeException e) { + } + catch (java.lang.RuntimeException e) + { System.out.println(e.getMessage()); helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + "AppProvider"); - if (ph != null) { + if (ph != null) + { office.closeExistingOffice(param, true); shortWait(5000); } @@ -352,37 +388,52 @@ public class basic_fat implements TestBase { return tEnv; } - protected void shortWait(int millis) { - try { + protected void shortWait(int millis) + { + try + { Thread.sleep(millis); - } catch (java.lang.InterruptedException ie) { + } + catch (java.lang.InterruptedException ie) + { } } - protected Vector getExclusionList(String url, boolean debug) { + protected Vector getExclusionList(String url, boolean debug) + { Vector entryList = new Vector(); String line = "#"; BufferedReader exclusion = null; - try { + try + { exclusion = new BufferedReader(new FileReader(url)); - } catch (java.io.FileNotFoundException fnfe) { - if (debug) { + } + catch (java.io.FileNotFoundException fnfe) + { + if (debug) + { System.out.println("Couldn't find file " + url); } return entryList; } - while (line != null) { - try { - if (!line.startsWith("#")) { + while (line != null) + { + try + { + if (!line.startsWith("#")) + { entryList.add(line); } line = exclusion.readLine(); - } catch (java.io.IOException ioe) { - if (debug) { + } + catch (java.io.IOException ioe) + { + if (debug) + { System.out.println( "Exception while reading exclusion list"); } @@ -391,10 +442,14 @@ public class basic_fat implements TestBase { } } - try { + try + { exclusion.close(); - } catch (java.io.IOException ioe) { - if (debug) { + } + catch (java.io.IOException ioe) + { + if (debug) + { System.out.println("Couldn't close file " + url); } diff --git a/qadevOOo/runner/base/java_complex.java b/qadevOOo/runner/base/java_complex.java index 0690fb8a0138..e3a41ca19d5c 100644 --- a/qadevOOo/runner/base/java_complex.java +++ b/qadevOOo/runner/base/java_complex.java @@ -27,7 +27,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package base; import complexlib.ComplexTestCase; @@ -47,7 +46,8 @@ import util.PropertyName; * Test base for executing a java complex test. * @see base.TestBase */ -public class java_complex implements TestBase{ +public class java_complex implements TestBase +{ /** * This function executes the complex tests given as parameter "-o" or "TestJob". It querys for the correspond class @@ -55,40 +55,42 @@ public class java_complex implements TestBase{ * @param param * @return true of all tests run successfuly, esle false */ - public boolean executeTest(TestParameters param) { + public boolean executeTest(TestParameters param) + { // is there an ini file for the complex tests defined? - String complexIniFileName = ((String)param.get("ComplexIni")); - if (complexIniFileName != null) { + String complexIniFileName = ((String) param.get("ComplexIni")); + if (complexIniFileName != null) + { CfgParser ini = new CfgParser(complexIniFileName); ini.getIniParameters(param); } // get the test job - String testJob = ((String)param.get("TestJob")); + String testJob = ((String) param.get("TestJob")); DescGetter descGetter = new ComplexDescGetter(); // get the test jobs - DescEntry[] entries = descGetter.getDescriptionFor(testJob,null,true); + DescEntry[] entries = descGetter.getDescriptionFor(testJob, null, true); return executeTest(param, entries); } - /** * This function run the given DescEntry[] as ComplexTest * @param param * @param entries * @return true of all tests run successfuly, esle false */ - public boolean executeTest(TestParameters param, DescEntry[] entries) { + public boolean executeTest(TestParameters param, DescEntry[] entries) + { // is there an ini file for the complex tests defined? - String complexIniFileName = ((String)param.get("ComplexIni")); - if (complexIniFileName != null) + String complexIniFileName = ((String) param.get("ComplexIni")); + if (complexIniFileName != null) { CfgParser ini = new CfgParser(complexIniFileName); ini.getIniParameters(param); - } + } DynamicClassLoader dcl = new DynamicClassLoader(); ComplexTestCase testClass = null; @@ -104,40 +106,49 @@ public class java_complex implements TestBase{ // param.put("TimeOut", new Integer(0)); - for (int i=0; i<entries.length; i++) { + for (int i = 0; i < entries.length; i++) + { - if (entries[i] == null) continue; + if (entries[i] == null) + { + continue; + } String iniName = entries[i].longName; iniName = iniName.replace('.', '/'); - CfgParser ini = new CfgParser(iniName+".props"); + CfgParser ini = new CfgParser(iniName + ".props"); ini.getIniParameters(param); - LogWriter log = (LogWriter)dcl.getInstance( - (String)param.get("LogWriter")); + LogWriter log = (LogWriter) dcl.getInstance((String) param.get("LogWriter")); AppProvider office = null; - if (!param.getBool("NoOffice")) { - try { - office = (AppProvider)dcl.getInstance("helper.OfficeProvider"); + if (!param.getBool("NoOffice")) + { + try + { + office = (AppProvider) dcl.getInstance("helper.OfficeProvider"); Object msf = office.getManager(param); - if (msf == null) { + if (msf == null) + { returnVal = false; continue; } - param.put("ServiceFactory",msf); + param.put("ServiceFactory", msf); } - catch(IllegalArgumentException e) { + catch (IllegalArgumentException e) + { office = null; } } - log.initialize(entries[i],param.getBool(PropertyName.LOGGING_IS_ACTIVE)); + log.initialize(entries[i], param.getBool(PropertyName.LOGGING_IS_ACTIVE)); entries[i].Logger = log; // create an instance - try { - testClass = (ComplexTestCase)dcl.getInstance(entries[i].longName); + try + { + testClass = (ComplexTestCase) dcl.getInstance(entries[i].longName); } - catch(java.lang.Exception e) { + catch (java.lang.Exception e) + { e.printStackTrace(); return false; } @@ -146,7 +157,8 @@ public class java_complex implements TestBase{ Summarizer sum = new Summarizer(); sum.summarizeUp(entries[i]); - if (office != null) { + if (office != null) + { office.closeExistingOffice(param, false); } @@ -158,5 +170,4 @@ public class java_complex implements TestBase{ } return returnVal; } - } diff --git a/qadevOOo/runner/base/java_fat.java b/qadevOOo/runner/base/java_fat.java index 64f55e8f0814..c058cb72d5a2 100644 --- a/qadevOOo/runner/base/java_fat.java +++ b/qadevOOo/runner/base/java_fat.java @@ -59,47 +59,55 @@ import util.DynamicClassLoader; * * this class handles tests written in java and running on a fat Office */ -public class java_fat implements TestBase { +public class java_fat implements TestBase +{ - public static boolean debug = false; - public static boolean keepdocument = false; - public static boolean logging = true; - public static boolean newOffice = false; + private static boolean debug = false; + private static boolean keepdocument = false; + private static boolean logging = true; + private static boolean newOffice = false; private DynamicClassLoader dcl = null; - public boolean executeTest(lib.TestParameters param) { - dcl = new DynamicClassLoader(); - - DescGetter dg = new APIDescGetter(); - String job = (String) param.get("TestJob"); - String ExclusionFile = (String) param.get("ExclusionList"); - Vector exclusions = null; - boolean retValue = true; - debug = param.getBool("DebugIsActive"); - logging = param.getBool("LoggingIsActive"); - keepdocument = param.getBool("KeepDocument"); - newOffice = param.getBool(util.PropertyName.NEW_OFFICE_INSTANCE); - if (keepdocument) { - System.setProperty("KeepDocument", "true"); - } - if (ExclusionFile != null) { - exclusions = getExclusionList(ExclusionFile, debug); - } - //get Job-Descriptions - System.out.println("Getting Descriptions for Job: " + job); + private lib.TestParameters m_aParams; + private AppProvider m_aOffice; - DescEntry[] entries = dg.getDescriptionFor(job, - (String) param.get( - "DescriptionPath"), - debug); + public boolean executeTest(lib.TestParameters param) + { + m_aParams = param; - System.out.println(); + dcl = new DynamicClassLoader(); - if (entries == null) { - System.out.println("Couldn't get Description for Job: " + job); + DescGetter dg = new APIDescGetter(); + String job = (String) param.get("TestJob"); + String ExclusionFile = (String) param.get("ExclusionList"); + Vector exclusions = null; + boolean retValue = true; + debug = param.getBool("DebugIsActive"); + logging = param.getBool("LoggingIsActive"); + keepdocument = param.getBool("KeepDocument"); + newOffice = param.getBool(util.PropertyName.NEW_OFFICE_INSTANCE); + if (keepdocument) + { + System.setProperty("KeepDocument", "true"); + } + if (ExclusionFile != null) + { + exclusions = getExclusionList(ExclusionFile, debug); + } + //get Job-Descriptions + System.out.println("Getting Descriptions for Job: " + job); - return false; - } + String sDescriptionPath = (String) param.get("DescriptionPath"); + DescEntry[] entries = dg.getDescriptionFor(job, sDescriptionPath, debug); + + // System.out.println(); + + if (entries == null) + { + System.out.println("Couldn't get Description for Job: " + job); + + return false; + } // String officeProviderName = (String) param.get("OfficeProvider"); // AppProvider office = (AppProvider) dcl.getInstance(officeProviderName); @@ -110,265 +118,281 @@ public class java_fat implements TestBase { // System.exit(-1); // } - AppProvider office = startOffice(param); - - boolean firstRun = true; + m_aOffice = startOffice(param); - for (int l = 0; l < entries.length; l++) { - if (entries[l] == null) { - continue; - } + boolean firstRun = true; - if (entries[l].hasErrorMsg) { - System.out.println(entries[l].ErrorMsg); + for (int l = 0; l < entries.length; l++) + { + if (entries[l] == null) + { + continue; + } - continue; - } + if (entries[l].hasErrorMsg) + { + System.out.println(entries[l].ErrorMsg); + retValue = false; + continue; + } - if (!firstRun && newOffice) { - if (!office.closeExistingOffice(param, true)) { - office.disposeManager(param); + if (!firstRun && newOffice) + { + if (!m_aOffice.closeExistingOffice(param, true)) + { + m_aOffice.disposeManager(param); + } + startOffice(param); } - startOffice(param); - } - firstRun = false; + firstRun = false; // XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager( // param); - XMultiServiceFactory msf = (XMultiServiceFactory) param.getMSF(); + XMultiServiceFactory msf = (XMultiServiceFactory) param.getMSF(); - if (msf == null) { - retValue = false; + if (msf == null) + { + retValue = false; - continue; - } + continue; + } // param.put("ServiceFactory", msf); - DescEntry entry = entries[l]; - - //get some helper classes - Summarizer sumIt = new Summarizer(); - - TestCase tCase = null; - - try { - tCase = (TestCase) dcl.getInstance("mod._" + - entry.entryName); - } catch (java.lang.IllegalArgumentException ie) { - entry.ErrorMsg = ie.getMessage(); - entry.hasErrorMsg = true; - } catch (java.lang.NoClassDefFoundError ie) { - entry.ErrorMsg = ie.getMessage(); - entry.hasErrorMsg = true; - } + DescEntry entry = entries[l]; - if (tCase == null) { - Summarizer.summarizeDown(entry, entry.ErrorMsg); + //get some helper classes + Summarizer sumIt = new Summarizer(); - LogWriter sumObj = OutProducerFactory.createOutProducer(param); - entry.UserDefinedParams = param; - sumObj.initialize(entry, logging); - sumObj.summary(entry); + TestCase tCase = null; - continue; - } + try + { + tCase = (TestCase) dcl.getInstance("mod._" + entry.entryName); + } + catch (java.lang.IllegalArgumentException ie) + { + entry.ErrorMsg = ie.getMessage(); + entry.hasErrorMsg = true; + } + catch (java.lang.NoClassDefFoundError ie) + { + entry.ErrorMsg = ie.getMessage(); + entry.hasErrorMsg = true; + } - if (debug) { - System.out.println("sleeping 5 seconds.."); - } - util.utils.shortWait(5000); + if (tCase == null) + { + Summarizer.summarizeDown(entry, entry.ErrorMsg); - System.out.println("Creating: " + entry.entryName); + LogWriter sumObj = OutProducerFactory.createOutProducer(param); + entry.UserDefinedParams = param; + sumObj.initialize(entry, logging); + sumObj.summary(entry); - LogWriter log = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); - log.initialize(entry, logging); - entry.UserDefinedParams = param; - - TestEnvironment tEnv = null; + continue; + } - try { - tCase.setLogWriter((PrintWriter) log); - tCase.initializeTestCase(param); - tEnv = tCase.getTestEnvironment(param); - } catch (Exception e) { - System.out.println("Exception while creating " + - tCase.getObjectName()); - System.out.println("Message " + e.getMessage()); - e.printStackTrace(); - tEnv = null; - } catch (java.lang.UnsatisfiedLinkError e) { - System.out.println("Exception while creating " + - tCase.getObjectName()); - System.out.println("Message " + e.getMessage()); - tEnv = null; - } catch (java.lang.NoClassDefFoundError e) { - System.out.println("Exception while creating " + - tCase.getObjectName()); - System.out.println("Message " + e.getMessage()); - tEnv = null; - } + if (debug) + { + System.out.println("sleeping 5 seconds.."); + } + util.utils.shortWait(5000); - if (tEnv == null) { - Summarizer.summarizeDown(entry, - "Couldn't create " + - tCase.getObjectName()); + System.out.println("Creating: " + entry.entryName); - LogWriter sumObj = OutProducerFactory.createOutProducer(param); + LogWriter log = (LogWriter) dcl.getInstance((String) param.get("LogWriter")); + log.initialize(entry, logging); entry.UserDefinedParams = param; - sumObj.initialize(entry, logging); - sumObj.summary(entry); - continue; - } - - System.out.println(tCase.getObjectName() + " recreated "); - - for (int j = 0; j < entry.SubEntryCount; j++) { - if (!entry.SubEntries[j].isToTest) { - Summarizer.summarizeDown(entry.SubEntries[j], - "not part of the job"); + TestEnvironment tEnv = null; - continue; + try + { + tCase.setLogWriter((PrintWriter) log); + tCase.initializeTestCase(param); + tEnv = tCase.getTestEnvironment(param); + } + catch (Exception e) + { + System.out.println("Exception while creating " + tCase.getObjectName()); + System.out.println("Message " + e.getMessage()); + e.printStackTrace(); + tEnv = null; + } + catch (java.lang.UnsatisfiedLinkError e) + { + System.out.println("Exception while creating " + tCase.getObjectName()); + System.out.println("Message " + e.getMessage()); + tEnv = null; + } + catch (java.lang.NoClassDefFoundError e) + { + System.out.println("Exception while creating " + tCase.getObjectName()); + System.out.println("Message " + e.getMessage()); + tEnv = null; } - if ((exclusions != null) && (exclusions.contains(entry.SubEntries[j].longName))) { - Summarizer.summarizeDown(entry.SubEntries[j], - "known issue"); + if (tEnv == null) + { + Summarizer.summarizeDown(entry, "Couldn't create " + tCase.getObjectName()); + + LogWriter sumObj = OutProducerFactory.createOutProducer(param); + entry.UserDefinedParams = param; + sumObj.initialize(entry, logging); + sumObj.summary(entry); continue; } - System.out.println("running: '" + entry.SubEntries[j].entryName + "'"); + System.out.println(tCase.getObjectName() + " recreated "); - LogWriter ifclog = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); + for (int j = 0; j < entry.SubEntryCount; j++) + { + DescEntry aSubEntry = entry.SubEntries[j]; + if (!aSubEntry.isToTest) + { + Summarizer.summarizeDown(aSubEntry, "not part of the job"); - ifclog.initialize(entry.SubEntries[j], logging); - entry.SubEntries[j].UserDefinedParams = param; - entry.SubEntries[j].Logger = ifclog; + continue; + } - if ((tEnv == null) || tEnv.isDisposed()) { - helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + if ((exclusions != null) && (exclusions.contains(aSubEntry.longName))) + { + Summarizer.summarizeDown(aSubEntry, "known issue"); - if (ph != null) { - office.closeExistingOffice(param, true); - shortWait(5000); + continue; } - tEnv = getEnv(entry, param); - } + System.out.println("running: '" + aSubEntry.entryName + "'"); - MultiMethodTest ifc = null; - lib.TestResult res = null; - - // run the interface test twice if it failed. - int countInterfaceTestRun = 0; - boolean finished = false; - while (!finished) { - try { - countInterfaceTestRun++; - finished = true; - res = executeInterfaceTest(entry.SubEntries[j], tEnv, param); - } catch (IllegalArgumentException iae) { - System.out.println("Couldn't load class " + - entry.SubEntries[j].entryName); - System.out.println("**** " + iae.getMessage() + " ****"); - Summarizer.summarizeDown(entry.SubEntries[j], - iae.getMessage()); - } catch (java.lang.NoClassDefFoundError iae) { - System.out.println("Couldn't load class " + - entry.SubEntries[j].entryName); - System.out.println("**** " + iae.getMessage() + " ****"); - Summarizer.summarizeDown(entry.SubEntries[j], - iae.getMessage()); - } catch (java.lang.RuntimeException e) { - helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); - - if (ph != null) { - office.closeExistingOffice(param, true); - shortWait(5000); - } + LogWriter ifclog = (LogWriter) dcl.getInstance( (String) param.get("LogWriter")); + ifclog.initialize(aSubEntry, logging); + aSubEntry.UserDefinedParams = param; + aSubEntry.Logger = ifclog; + + if ((tEnv == null) || tEnv.isDisposed()) + { + closeExistingOffice(); tEnv = getEnv(entry, param); - if (countInterfaceTestRun < 2) { - finished = false; - } else { - Summarizer.summarizeDown(entry.SubEntries[j], - e.toString() + ".FAILED"); - } } - } - if (res != null) { - for (int k = 0; k < entry.SubEntries[j].SubEntryCount; k++) { - if (res.hasMethod( - entry.SubEntries[j].SubEntries[k].entryName)) { - entry.SubEntries[j].SubEntries[k].State = res.getStatusFor( - entry.SubEntries[j].SubEntries[k].entryName).toString(); + + // MultiMethodTest ifc = null; + lib.TestResult res = null; + + // run the interface test twice if it failed. + int countInterfaceTestRun = 0; + boolean finished = false; + while (!finished) + { + try + { + countInterfaceTestRun++; + finished = true; + res = executeInterfaceTest(aSubEntry, tEnv, param); + } + catch (IllegalArgumentException iae) + { + System.out.println("Couldn't load class " + aSubEntry.entryName); + System.out.println("**** " + iae.getMessage() + " ****"); + Summarizer.summarizeDown(aSubEntry, iae.getMessage()); + } + catch (java.lang.NoClassDefFoundError iae) + { + System.out.println("Couldn't load class " + aSubEntry.entryName); + System.out.println("**** " + iae.getMessage() + " ****"); + Summarizer.summarizeDown(aSubEntry, iae.getMessage()); + } + catch (java.lang.RuntimeException e) + { + closeExistingOffice(); + tEnv = getEnv(entry, param); + if (countInterfaceTestRun < 2) + { + finished = false; + } + else + { + Summarizer.summarizeDown(aSubEntry, e.toString() + ".FAILED"); + } } } - } + setState(aSubEntry, res); - sumIt.summarizeUp(entry.SubEntries[j]); + sumIt.summarizeUp(aSubEntry); - LogWriter sumIfc = OutProducerFactory.createOutProducer(param); - entry.SubEntries[j].UserDefinedParams = param; - sumIfc.initialize(entry.SubEntries[j], logging); - sumIfc.summary(entry.SubEntries[j]); - } + LogWriter sumIfc = OutProducerFactory.createOutProducer(param); + aSubEntry.UserDefinedParams = param; + sumIfc.initialize(aSubEntry, logging); + sumIfc.summary(aSubEntry); + } - try { - if (!keepdocument) { - tCase.cleanupTestCase(param); + try + { + if (!keepdocument) + { + tCase.cleanupTestCase(param); + } + } + catch (Exception e) + { + System.out.println("couldn't cleanup"); + } + catch (java.lang.NoClassDefFoundError e) + { + System.out.println("couldn't cleanup"); } - } catch (Exception e) { - System.out.println("couldn't cleanup"); - } catch (java.lang.NoClassDefFoundError e) { - System.out.println("couldn't cleanup"); - } - sumIt.summarizeUp(entry); + sumIt.summarizeUp(entry); - LogWriter sumObj = OutProducerFactory.createOutProducer(param); + LogWriter sumObj = OutProducerFactory.createOutProducer(param); - sumObj.initialize(entry, logging); - sumObj.summary(entry); - } + sumObj.initialize(entry, logging); + sumObj.summary(entry); + } - if (entries.length > 1) { - System.out.println(); + if (entries.length > 0) + { + System.out.println(); - int counter = 0; - System.out.println( - "Failures that appeared during scenario execution:"); + int counter = 0; + System.out.println("Failures that appeared during scenario execution:"); - for (int i = 0; i < entries.length; i++) { - if (!entries[i].State.endsWith("OK")) { - System.out.println("\t " + entries[i].longName); - counter++; + for (int i = 0; i < entries.length; i++) + { + if (!entries[i].State.endsWith("OK")) + { + System.out.println("\t " + entries[i].longName); + counter++; + } } + + System.out.println(counter + " of " + entries.length + " tests failed"); } - System.out.println(counter + " of " + entries.length + - " tests failed"); + closeExistingOffice(); + return retValue; } - helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); - - if (ph != null) { - office.closeExistingOffice(param, true); - shortWait(5000); + private void setState(DescEntry aSubEntry, lib.TestResult res) + { + if (res != null) + { + for (int k = 0; k < aSubEntry.SubEntryCount; k++) + { + DescEntry aSubSubEntry = aSubEntry.SubEntries[k]; + if (res.hasMethod( aSubSubEntry.entryName)) + { + aSubSubEntry.State = res.getStatusFor(aSubSubEntry.entryName).toString(); + } + } } - - return retValue; } - protected TestEnvironment getEnv(DescEntry entry, TestParameters param) { + private TestEnvironment getEnv(DescEntry entry, TestParameters param) + { // if (dcl == null) // dcl = new DynamicClassLoader(); // String officeProviderName = (String) param.get("OfficeProvider"); @@ -389,143 +413,172 @@ public class java_fat implements TestBase { // // param.put("ServiceFactory", msf); - AppProvider office = startOffice(param); + // AppProvider office = startOffice(param); - TestCase tCase = null; + TestCase tCase = null; - try { - tCase = (TestCase) dcl.getInstance("mod._" + entry.entryName); - } catch (java.lang.IllegalArgumentException ie) { - entry.ErrorMsg = ie.getMessage(); - entry.hasErrorMsg = true; - } catch (java.lang.NoClassDefFoundError ie) { - entry.ErrorMsg = ie.getMessage(); - entry.hasErrorMsg = true; - } + try + { + tCase = (TestCase) dcl.getInstance("mod._" + entry.entryName); + } + catch (java.lang.IllegalArgumentException ie) + { + entry.ErrorMsg = ie.getMessage(); + entry.hasErrorMsg = true; + } + catch (java.lang.NoClassDefFoundError ie) + { + entry.ErrorMsg = ie.getMessage(); + entry.hasErrorMsg = true; + } - System.out.println("Creating: " + entry.entryName); + System.out.println("Creating: " + entry.entryName); - entry.UserDefinedParams = param; + entry.UserDefinedParams = param; - LogWriter log = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); - log.initialize(entry, logging); - tCase.setLogWriter((PrintWriter) log); + LogWriter log = (LogWriter) dcl.getInstance((String) param.get("LogWriter")); + log.initialize(entry, logging); + tCase.setLogWriter((PrintWriter) log); - TestEnvironment tEnv = null; + TestEnvironment tEnv = null; - try { - tCase.initializeTestCase(param); - tEnv = tCase.getTestEnvironment(param); - } catch (com.sun.star.lang.DisposedException de) { - System.out.println("Office disposed"); + try + { + tCase.initializeTestCase(param); + tEnv = tCase.getTestEnvironment(param); + } + catch (com.sun.star.lang.DisposedException de) + { + System.out.println("Office disposed"); + closeExistingOffice(); + } + catch (lib.StatusException e) + { + System.out.println(e.getMessage()); - helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + closeExistingOffice(); - if (ph != null) { - office.closeExistingOffice(param, true); - shortWait(5000); + entry.ErrorMsg = e.getMessage(); + entry.hasErrorMsg = true; } - } catch (lib.StatusException e) { - System.out.println(e.getMessage()); - helper.ProcessHandler ph = (helper.ProcessHandler) param.get( - "AppProvider"); + return tEnv; + } - if (ph != null) { - office.closeExistingOffice(param, true); + private void closeExistingOffice() + { + helper.ProcessHandler ph = (helper.ProcessHandler) m_aParams.get("AppProvider"); + + if (ph != null) + { + m_aOffice.closeExistingOffice(m_aParams, true); shortWait(5000); } - entry.ErrorMsg = e.getMessage(); - entry.hasErrorMsg = true; } - return tEnv; - } - - protected void shortWait(int millis) { - try { - Thread.sleep(millis); - } catch (java.lang.InterruptedException ie) { + private void shortWait(int millis) + { + try + { + Thread.sleep(millis); + } + catch (java.lang.InterruptedException ie) + { + } } - } - protected Vector getExclusionList(String url, boolean debug) { - Vector entryList = new Vector(); - String line = "#"; - BufferedReader exclusion = null; + private Vector getExclusionList(String url, boolean debug) + { + Vector entryList = new Vector(); + String line = "#"; + BufferedReader exclusion = null; - try { - exclusion = new BufferedReader(new FileReader(url)); - } catch (java.io.FileNotFoundException fnfe) { - if (debug) { - System.out.println("Couldn't find file " + url); + try + { + exclusion = new BufferedReader(new FileReader(url)); } + catch (java.io.FileNotFoundException fnfe) + { + if (debug) + { + System.out.println("Couldn't find file " + url); + } - return entryList; - } + return entryList; + } - while (line != null) { - try { - if (!line.startsWith("#") && (line.length() > 1)) { - entryList.add(line.trim()); + while (line != null) + { + try + { + if (!line.startsWith("#") && (line.length() > 1)) + { + entryList.add(line.trim()); + } + + line = exclusion.readLine(); } + catch (java.io.IOException ioe) + { + if (debug) + { + System.out.println("Exception while reading exclusion list"); + } - line = exclusion.readLine(); - } catch (java.io.IOException ioe) { - if (debug) { - System.out.println( - "Exception while reading exclusion list"); + return entryList; } + } - return entryList; + try + { + exclusion.close(); } - } + catch (java.io.IOException ioe) + { + if (debug) + { + System.out.println("Couldn't close file " + url); + } - try { - exclusion.close(); - } catch (java.io.IOException ioe) { - if (debug) { - System.out.println("Couldn't close file " + url); + return entryList; } return entryList; } - return entryList; - } - private TestResult executeInterfaceTest( DescEntry entry, TestEnvironment tEnv, TestParameters param) - throws IllegalArgumentException, java.lang.NoClassDefFoundError { - MultiMethodTest ifc = (MultiMethodTest) dcl.getInstance(entry.entryName); - return ifc.run(entry, tEnv, param); - } + throws IllegalArgumentException, java.lang.NoClassDefFoundError + { + MultiMethodTest ifc = (MultiMethodTest) dcl.getInstance(entry.entryName); + return ifc.run(entry, tEnv, param); + } - private AppProvider startOffice(lib.TestParameters param) { + private AppProvider startOffice(lib.TestParameters param) + { - if (dcl == null) { - dcl = new DynamicClassLoader(); - } + if (dcl == null) + { + dcl = new DynamicClassLoader(); + } - String officeProviderName = (String) param.get("OfficeProvider"); - AppProvider office = (AppProvider) dcl.getInstance(officeProviderName); + String officeProviderName = (String) param.get("OfficeProvider"); + AppProvider office = (AppProvider) dcl.getInstance(officeProviderName); - if (office == null) { - System.out.println("ERROR: Wrong parameter 'OfficeProvider', " + - " it cannot be instantiated."); - System.exit(-1); - } + if (office == null) + { + System.out.println("ERROR: Wrong parameter 'OfficeProvider', " + " it cannot be instantiated."); + System.exit(-1); + } - XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager( - param); + XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(param); - if (msf != null){ - param.put("ServiceFactory", msf); - } + if (msf != null) + { + param.put("ServiceFactory", msf); + } - return office; - } + return office; + } } diff --git a/qadevOOo/runner/basicrunner/basichelper/Filter.java b/qadevOOo/runner/basicrunner/basichelper/Filter.java index e83bab160d54..5a66d42a4016 100644 --- a/qadevOOo/runner/basicrunner/basichelper/Filter.java +++ b/qadevOOo/runner/basicrunner/basichelper/Filter.java @@ -35,6 +35,7 @@ import com.sun.star.lang.XTypeProvider; import com.sun.star.uno.Type; import com.sun.star.container.XNameAccess; import com.sun.star.container.NoSuchElementException; +import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.document.XFilter; @@ -226,7 +227,7 @@ class FilterImpl implements XInitialization, XTypeProvider, XNameAccess { public void initialize(Object[] parm1) throws com.sun.star.uno.Exception { XFilter oFilter = (XFilter)UnoRuntime.queryInterface( XFilter.class, parm1[0]); - PropertyValue[] FilterDesc = (PropertyValue[])UnoRuntime.queryInterface(PropertyValue[].class, parm1[1]); + PropertyValue[] FilterDesc = (PropertyValue[])AnyConverter.toArray(parm1[1]); aState = "just initialized"; FilterThread aThread = new FilterThread(oFilter, FilterDesc); aThread.start(); diff --git a/qadevOOo/runner/complexlib/Assurance.java b/qadevOOo/runner/complexlib/Assurance.java index 05784b032391..8ee4119c149c 100644 --- a/qadevOOo/runner/complexlib/Assurance.java +++ b/qadevOOo/runner/complexlib/Assurance.java @@ -32,6 +32,9 @@ package complexlib; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + /** * * @author ll93751 @@ -41,6 +44,8 @@ package complexlib; */ public class Assurance { + public static final boolean CONTINUE = true; + /** State of the current test method **/ protected boolean state = true; @@ -238,6 +243,96 @@ public class Assurance assureEquals( message, expected, actual, false ); } + /** invokes a given method on a given object, and assures a certain exception is caught + * @param _message is the message to print when the check fails + * @param _object is the object to invoke the method on + * @param _methodName is the name of the method to invoke + * @param _methodArgs are the arguments to pass to the method. + * @param _argClasses are the classes to assume for the arguments of the methods + * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + protected void assureException( final String _message, final Object _object, final String _methodName, + final Class[] _argClasses, final Object[] _methodArgs, final Class _expectedExceptionClass ) + { + Class objectClass = _object.getClass(); + + boolean noExceptionAllowed = ( _expectedExceptionClass == null ); + + boolean caughtExpected = noExceptionAllowed ? true : false; + try + { + Method method = objectClass.getMethod( _methodName, _argClasses ); + method.invoke(_object, _methodArgs ); + } + catch ( InvocationTargetException e ) + { + caughtExpected = noExceptionAllowed + ? false + : ( e.getTargetException().getClass().equals( _expectedExceptionClass ) ); + } + catch( Exception e ) + { + caughtExpected = false; + } + + assure( _message, caughtExpected ); + } + + /** invokes a given method on a given object, and assures a certain exception is caught + * @param _message is the message to print when the check fails + * @param _object is the object to invoke the method on + * @param _methodName is the name of the method to invoke + * @param _methodArgs are the arguments to pass to the method. Those implicitly define + * the classes of the arguments of the method which is called. + * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + protected void assureException( final String _message, final Object _object, final String _methodName, + final Object[] _methodArgs, final Class _expectedExceptionClass ) + { + Class[] argClasses = new Class[ _methodArgs.length ]; + for ( int i=0; i<_methodArgs.length; ++i ) + argClasses[i] = _methodArgs[i].getClass(); + assureException( _message, _object, _methodName, argClasses, _methodArgs, _expectedExceptionClass ); + } + + /** invokes a given method on a given object, and assures a certain exception is caught + * @param _object is the object to invoke the method on + * @param _methodName is the name of the method to invoke + * @param _methodArgs are the arguments to pass to the method. Those implicitly define + * the classes of the arguments of the method which is called. + * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + protected void assureException( final Object _object, final String _methodName, final Object[] _methodArgs, + final Class _expectedExceptionClass ) + { + assureException( + "did not catch the expected exception (" + + ( ( _expectedExceptionClass == null ) ? "none" : _expectedExceptionClass.getName() ) + + ") while calling " + _object.getClass().getName() + "." + _methodName, + _object, _methodName, _methodArgs, _expectedExceptionClass ); + } + + /** invokes a given method on a given object, and assures a certain exception is caught + * @param _object is the object to invoke the method on + * @param _methodName is the name of the method to invoke + * @param _methodArgs are the arguments to pass to the method + * @param _argClasses are the classes to assume for the arguments of the methods + * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + protected void assureException( final Object _object, final String _methodName, final Class[] _argClasses, + final Object[] _methodArgs, final Class _expectedExceptionClass ) + { + assureException( + "did not catch the expected exception (" + + ( ( _expectedExceptionClass == null ) ? "none" : _expectedExceptionClass.getName() ) + + ") while calling " + _object.getClass().getName() + "." + _methodName, + _object, _methodName, _argClasses, _methodArgs, _expectedExceptionClass ); + } + /** * Mark the currently executed method as failed. * This function generates "Test did fail." as standard message. diff --git a/qadevOOo/runner/complexlib/ComplexTestCase.java b/qadevOOo/runner/complexlib/ComplexTestCase.java index 4fb5d757fb0e..18f89681c96e 100644 --- a/qadevOOo/runner/complexlib/ComplexTestCase.java +++ b/qadevOOo/runner/complexlib/ComplexTestCase.java @@ -27,7 +27,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package complexlib; import java.lang.reflect.Method; @@ -38,11 +37,11 @@ import share.LogWriter; import share.ComplexTest; import java.io.PrintWriter; - /** * Base class for all complex tests. */ -public abstract class ComplexTestCase extends Assurance implements ComplexTest { +public abstract class ComplexTestCase extends Assurance implements ComplexTest +{ /** The test parameters **/ protected static TestParameters param = null; @@ -59,7 +58,8 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { **/ protected int mThreadTimeOut = 0; /** Continue a test even if it did fail **/ - public static final boolean CONTINUE = true; + // public static final boolean CONTINUE = true; + /** End a test if it did fail **/ public static final boolean BREAK = true; @@ -70,31 +70,42 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { * @param entry The name of the test method that should be called. * @param environment The environment for the test. */ - public void executeMethods(DescEntry entry, TestParameters environment) { + public void executeMethods(DescEntry entry, TestParameters environment) + { // get the environment param = environment; log = entry.Logger; mThreadTimeOut = param.getInt("ThreadTimeOut"); - if (mThreadTimeOut == 0) { + if (mThreadTimeOut == 0) + { mThreadTimeOut = 300000; } // start with the before() method boolean beforeWorked = true; - try { - Method before = this.getClass().getMethod("before", new Class[]{}); - before.invoke(this, new Object[]{}); - } catch (java.lang.NoSuchMethodException e) { + try + { + Method before = this.getClass().getMethod("before", new Class[] {} ); + before.invoke(this, new Object[] {} ); + } + catch (java.lang.NoSuchMethodException e) + { // simply ignore - } catch (java.lang.IllegalAccessException e) { + } + catch (java.lang.IllegalAccessException e) + { log.println("Cannot access the 'before()' method, although it" + " is there. Is this ok?"); - } catch (java.lang.reflect.InvocationTargetException e) { + } + catch (java.lang.reflect.InvocationTargetException e) + { beforeWorked = false; Throwable t = e.getTargetException(); - if (!(t instanceof RuntimeException) || state) { + if (!(t instanceof RuntimeException) || state) + { log.println(t.toString()); - if (message == null) { + if (message == null) + { message = "Exception in before() method.\n\r" + t.getMessage(); } state = false; @@ -104,12 +115,16 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { //executeMethodTests - for (int i = 0; i < entry.SubEntries.length; i++) { + for (int i = 0; i < entry.SubEntries.length; i++) + { subEntry = entry.SubEntries[i]; - if (beforeWorked) { + if (beforeWorked) + { state = true; message = ""; - } else { + } + else + { // set all test methods on failed, if 'before()' did not work. subEntry.State = message; subEntry.hasErrorMsg = true; @@ -117,18 +132,25 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { continue; } Method testMethod = null; - try { + try + { String entryName = subEntry.entryName; Object[] parameter = null; - if (entryName.indexOf("(") != -1) { - String sParameter = (entryName.substring(entryName.indexOf("(") +1 , entryName.indexOf(")"))); + if (entryName.indexOf("(") != -1) + { + String sParameter = (entryName.substring(entryName.indexOf("(") + 1, entryName.indexOf(")"))); mTestMethodName = entryName; - parameter = new String[] {sParameter}; + parameter = new String[] + { + sParameter + }; entryName = entryName.substring(0, entryName.indexOf("(")); - testMethod = this.getClass().getMethod(entryName, new Class[]{String.class }); - } else { - testMethod = this.getClass().getMethod(entryName, new Class[]{}); + testMethod = this.getClass().getMethod(entryName, new Class[] { String.class }); + } + else + { + testMethod = this.getClass().getMethod(entryName, new Class[] {} ); mTestMethodName = entryName; } @@ -136,7 +158,8 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { log.println("Starting " + mTestMethodName); th.start(); - try { + try + { // some tests are very dynamic in its exceution time so that // a threadTimeOut fials. In this cases the logging mechanisim // is a usefull way to detect that a office respective a test @@ -150,38 +173,48 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { int sleepingStep = 1000; int factor = 0; - while (th.isAlive() && (lastPing != newPing || factor * sleepingStep < mThreadTimeOut)) { + while (th.isAlive() && (lastPing != newPing || factor * sleepingStep < mThreadTimeOut)) + { Thread.sleep(sleepingStep); factor++; // if a test starts the office itself it the watcher is a // new one. share.Watcher ow = (share.Watcher) param.get("Watcher"); - if (ow != null) { + if (ow != null) + { lastPing = newPing; newPing = ow.getPing(); //System.out.println("lastPing: '" + lastPing + "' newPing '" + newPing + "'"); factor = 0; } } - } catch (InterruptedException e) { } - if (th.isAlive()) { + catch (InterruptedException e) + { + } + if (th.isAlive()) + { log.println("Destroy " + mTestMethodName); th.destroy(); subEntry.State = "Test did sleep for " + (mThreadTimeOut / 1000) + " seconds and has been killed!"; subEntry.hasErrorMsg = true; subEntry.ErrorMsg = subEntry.State; continue; - } else { + } + else + { log.println("Finished " + mTestMethodName); - if (th.hasErrorMessage()) { + if (th.hasErrorMessage()) + { subEntry.State = th.getErrorMessage(); subEntry.hasErrorMsg = true; subEntry.ErrorMsg = subEntry.State; continue; } } - } catch (java.lang.Exception e) { + } + catch (java.lang.Exception e) + { log.println(e.getClass().getName()); String msg = e.getMessage(); log.println("Message: " + msg); @@ -196,22 +229,34 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { subEntry.ErrorMsg = message; } - if (beforeWorked) { + if (beforeWorked) + { // the after() method - try { - Method after = this.getClass().getMethod("after", new Class[]{}); - after.invoke(this, new Object[]{}); - } catch (java.lang.NoSuchMethodException e) { + try + { + Method after = this.getClass().getMethod("after", new Class[] {}); + after.invoke(this, new Object[] {} ); + } + catch (java.lang.NoSuchMethodException e) + { // simply ignore - } catch (java.lang.IllegalAccessException e) { + } + catch (java.lang.IllegalAccessException e) + { // simply ignore - } catch (java.lang.reflect.InvocationTargetException e) { + } + catch (java.lang.reflect.InvocationTargetException e) + { Throwable t = e.getTargetException(); - if (!(t instanceof StatusException)) { + if (!(t instanceof StatusException)) + { log.println(t.toString()); - if (message == null) { + if (message == null) + { message = "Exception in after() method.\n\r" + t.getMessage(); - } else { + } + else + { message += "Exception in \'after()\' method.\n\r" + t.getMessage(); } log.println("Message: " + message); @@ -232,9 +277,8 @@ public abstract class ComplexTestCase extends Assurance implements ComplexTest { * Override to give an own name. * @return As default, the name of this class. */ - public String getTestObjectName() { + public String getTestObjectName() + { return this.getClass().getName(); } - - -}
\ No newline at end of file +} diff --git a/qadevOOo/runner/complexlib/MethodThread.java b/qadevOOo/runner/complexlib/MethodThread.java index b08b93b532fd..e068323fd41e 100644 --- a/qadevOOo/runner/complexlib/MethodThread.java +++ b/qadevOOo/runner/complexlib/MethodThread.java @@ -7,7 +7,8 @@ import java.lang.reflect.Method; * Invoke a method of a class in an own thread. Provide a method to end * the thread. */ -public class MethodThread extends Thread { +public class MethodThread extends Thread +{ /** The method that should be executed **/ private Method mTestMethod = null; @@ -19,7 +20,6 @@ public class MethodThread extends Thread { private String mErrMessage = null; /** Did an Exception happen? **/ private boolean mExceptionHappened = false; - private Object[] mParameter = null; /** @@ -28,13 +28,15 @@ public class MethodThread extends Thread { * @param invokeClass The class where the method is invoked. * @param log The logging mechanism. */ - public MethodThread(Method testMethod, Object invokeClass, PrintWriter log) { + public MethodThread(Method testMethod, Object invokeClass, PrintWriter log) + { mTestMethod = testMethod; mInvokeClass = invokeClass; mLog = log; } - public MethodThread(Method testMethod, Object invokeClass, Object[] parameter, PrintWriter log) { + public MethodThread(Method testMethod, Object invokeClass, Object[] parameter, PrintWriter log) + { mTestMethod = testMethod; mInvokeClass = invokeClass; mParameter = parameter; @@ -44,22 +46,29 @@ public class MethodThread extends Thread { /** * Invoke the method. */ - public void run() { - try { + public void run() + { + try + { mTestMethod.invoke(mInvokeClass, mParameter); } - catch(IllegalAccessException e) { + catch (IllegalAccessException e) + { e.printStackTrace(mLog); mErrMessage = e.getMessage(); mExceptionHappened = true; } - catch(java.lang.reflect.InvocationTargetException e) { + catch (java.lang.reflect.InvocationTargetException e) + { Throwable t = e.getTargetException(); - if (!(t instanceof ComplexTestCase.AssureException)) { + if (!(t instanceof ComplexTestCase.AssureException)) + { t.printStackTrace(mLog); mErrMessage = t.getMessage(); if (mErrMessage == null) + { mErrMessage = t.toString(); + } mExceptionHappened = true; } @@ -70,7 +79,8 @@ public class MethodThread extends Thread { * Get the error message * @return The error message. */ - public String getErrorMessage() { + public String getErrorMessage() + { return mErrMessage; } @@ -78,18 +88,22 @@ public class MethodThread extends Thread { * Is there an error message? * @return True, if an error did happen. */ - public boolean hasErrorMessage() { + public boolean hasErrorMessage() + { return mExceptionHappened; } /** * Stop the running method. */ - public void destroy() { - try { + public void destroy() + { + try + { interrupt(); } - catch(SecurityException e) { + catch (SecurityException e) + { e.printStackTrace(mLog); mErrMessage = e.getMessage(); mExceptionHappened = true; diff --git a/qadevOOo/runner/complexlib/ShowTargets.java b/qadevOOo/runner/complexlib/ShowTargets.java new file mode 100644 index 000000000000..c48db7092d09 --- /dev/null +++ b/qadevOOo/runner/complexlib/ShowTargets.java @@ -0,0 +1,141 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ShowTargets.java,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complexlib; + +/** + * + * @author fs93730 + */ +public class ShowTargets +{ + /** Creates a new instance of ShowTargets */ + public ShowTargets() + { + } + + public static void main( String[] args ) + { + java.util.Vector targets = new java.util.Vector(); + java.util.Vector descs = new java.util.Vector(); + + targets.add( "run" ); + descs.add( "runs all complex tests in this module" ); + + int maxTargetLength = 3; + + for ( int i = 0; i < args.length; ++i ) + { + String completePotentialClassName = args[i].replace( '/', '.' ); + + // filter + if ( completePotentialClassName.endsWith( ".TestCase" ) ) + continue; + if ( completePotentialClassName.endsWith( ".TestSkeleton" ) ) + continue; + + // get the class + Class potentialTestClass = null; + try { potentialTestClass = Class.forName( completePotentialClassName ); } + catch( java.lang.ClassNotFoundException e ) + { + continue; + } + + // see if it is derived from complexlib.ComplexTestCase + Class superClass = potentialTestClass.getSuperclass(); + while ( superClass != null ) + { + if ( superClass.getName().equals( "complexlib.ComplexTestCase" ) ) + { + String bareClassName = completePotentialClassName.substring( completePotentialClassName.lastIndexOf( '.' ) + 1 ); + String target = "run_" + bareClassName; + targets.add( target ); + descs.add( getShortTestDescription( potentialTestClass ) ); + + if ( maxTargetLength < target.length() ) + maxTargetLength = target.length(); + break; + } + superClass = superClass.getSuperclass(); + } + } + + System.out.println( "possible targets:" ); + for ( int i=0; i<targets.size(); ++i ) + { + // target + String target = (String)targets.get(i); + // 'tab' + System.out.print( " " + target ); + for ( int s = maxTargetLength - target.length(); s>0; --s ) + System.out.print( " " ); + // description + System.out.println( " (" + (String)descs.get(i) + ")" ); + } + } + + /** determines if the test denoted by a given Class is an interactive test + */ + static private boolean isInteractiveTest( Class testClass ) + { + java.lang.reflect.Method interactiveTestMethod = null; + try { interactiveTestMethod = testClass.getMethod( "isInteractiveTest", new Class[]{} ); } + catch( Exception e ) { } + + if ( interactiveTestMethod != null ) + { + try + { + Boolean result = (Boolean)interactiveTestMethod.invoke( null, new Object[]{} ); + return result.booleanValue(); + } + catch( Exception e ) { } + } + return false; + } + + static private String getShortTestDescription( Class _testClass ) + { + java.lang.reflect.Method getShortDescriptionMethod = null; + try { getShortDescriptionMethod = _testClass.getMethod( "getShortTestDescription", new Class[]{} ); } + catch( Exception e ) { } + + if ( getShortDescriptionMethod != null ) + { + try + { + return (String)getShortDescriptionMethod.invoke( null, new Object[]{} ); + } + catch( Exception e ) { } + } + return "no description provided by the test"; + } +} diff --git a/qadevOOo/runner/complexlib/makefile.mk b/qadevOOo/runner/complexlib/makefile.mk index 950b70f293be..1e8c70d58889 100644 --- a/qadevOOo/runner/complexlib/makefile.mk +++ b/qadevOOo/runner/complexlib/makefile.mk @@ -44,7 +44,7 @@ TARGET = runner_complexlib JARFILES = ridl.jar jurt.jar unoil.jar -JAVAFILES = ComplexTestCase.java MethodThread.java +JAVAFILES = ComplexTestCase.java MethodThread.java ShowTargets.java JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) diff --git a/qadevOOo/runner/graphical/IniFile.java b/qadevOOo/runner/graphical/IniFile.java index c1aa6456d166..1934dc39731a 100644 --- a/qadevOOo/runner/graphical/IniFile.java +++ b/qadevOOo/runner/graphical/IniFile.java @@ -27,9 +27,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package graphical; +import java.io.BufferedReader; import java.io.File; import java.io.RandomAccessFile; import java.util.ArrayList; @@ -37,10 +37,11 @@ import java.util.Enumeration; /** Helper class to give a simple API to read/write windows like ini files - */ +*/ /* public */ // is only need, if we need this class outside package convwatch -class IniFile implements Enumeration +public class IniFile implements Enumeration { + /** * internal representation of the ini file content. * Problem, if ini file changed why other write something difference, we don't realise this. @@ -48,13 +49,13 @@ class IniFile implements Enumeration private String m_sFilename; private ArrayList m_aList; boolean m_bListContainUnsavedChanges = false; - private int m_aEnumerationPos = 0; + /** open a ini file by it's name @param _sFilename string a filename, if the file doesn't exist, a new empty ini file will create. write back to disk only if there are really changes. - */ + */ public IniFile(String _sFilename) { m_sFilename = _sFilename; @@ -66,23 +67,23 @@ class IniFile implements Enumeration // } } - public void insertFirstComment(String [] _aList) - { - if (m_aList.size() == 0) + public void insertFirstComment(String[] _aList) { - // can only insert if there is nothing else already in the ini file - for (int i=0; i<_aList.length;i++) + if (m_aList.size() == 0) { - m_aList.add(_aList[i]); + // can only insert if there is nothing else already in the ini file + for (int i = 0; i < _aList.length; i++) + { + m_aList.add(_aList[i]); + } } } - } private ArrayList loadLines() { File aFile = new File(m_sFilename); ArrayList aLines = new ArrayList(); - if (! aFile.exists()) + if (!aFile.exists()) { GlobalLogWriter.get().println("couldn't find file '" + m_sFilename + "', will be created."); // DebugHelper.exception(BasicErrorCode.SbERR_FILE_NOT_FOUND, ""); @@ -90,14 +91,15 @@ class IniFile implements Enumeration return aLines; } RandomAccessFile aReader = null; + // BufferedReader aReader; try { - aReader = new RandomAccessFile(aFile,"r"); + aReader = new RandomAccessFile(aFile, "r"); String aLine = ""; while (aLine != null) { aLine = aReader.readLine(); - if (aLine != null) + if (aLine != null && aLine.length() > 0) { aLines.add(aLine); } @@ -135,28 +137,29 @@ class IniFile implements Enumeration { return m_aList.size() > 1 ? true : false; } -/** - * Check if a given Section and Key exists in the ini file - * @param _sSectionName - * @param _sKey - * @return true if the given Section, Key exists, now you can get the value - */ + + /** + * Check if a given Section and Key exists in the ini file + * @param _sSectionName + * @param _sKey + * @return true if the given Section, Key exists, now you can get the value + */ public boolean hasValue(String _sSectionName, String _sKey) - { - int n = findKey(_sSectionName, _sKey); - if (n > 0) { - return true; + int n = findKey(_sSectionName, _sKey); + if (n > 0) + { + return true; + } + return false; } - return false; - } // ----------------------------------------------------------------------------- private boolean isRemark(String _sLine) { - if ( ((_sLine.length() < 2) ) || - ( _sLine.startsWith("#")) || - ( _sLine.startsWith(";")) ) + if (((_sLine.length() < 2)) || + (_sLine.startsWith("#")) || + (_sLine.startsWith(";"))) { return true; } @@ -165,7 +168,7 @@ class IniFile implements Enumeration private String getItem(int i) { - return (String)m_aList.get(i); + return (String) m_aList.get(i); } private String buildSectionName(String _sSectionName) @@ -173,16 +176,18 @@ class IniFile implements Enumeration String sFindSection = "[" + _sSectionName + "]"; return sFindSection; } + private String sectionToString(String _sSectionName) - { - String sKeyName = _sSectionName; - if (sKeyName.startsWith("[") && - sKeyName.endsWith("]")) { - sKeyName = sKeyName.substring(1, sKeyName.length() - 1); + String sKeyName = _sSectionName; + if (sKeyName.startsWith("[") && + sKeyName.endsWith("]")) + { + sKeyName = sKeyName.substring(1, sKeyName.length() - 1); + } + return sKeyName; } - return sKeyName; - } + private String toLowerIfNeed(String _sName) { return _sName.toLowerCase(); @@ -194,11 +199,11 @@ class IniFile implements Enumeration String sFindSection = toLowerIfNeed(buildSectionName(_sSection)); // ----------- find _sSection --------------- int i; - for (i=0; i<m_aList.size();i++) + for (i = 0; i < m_aList.size(); i++) { String sLine = toLowerIfNeed(getItem(i).trim()); if (isRemark(sLine)) - { + { continue; } if (sFindSection.equals("[]")) @@ -220,14 +225,14 @@ class IniFile implements Enumeration * @return true if the given _sSection was found */ public boolean hasSection(String _sSection) - { - int i = findSection(_sSection); - if (i == -1) { - return false; + int i = findSection(_sSection); + if (i == -1) + { + return false; + } + return true; } - return true; - } // return the line number, where the key is found. private int findKey(String _sSection, String _sKey) @@ -245,7 +250,7 @@ class IniFile implements Enumeration private int findKeyFromKnownSection(int _nSectionIndex, String _sKey) { _sKey = toLowerIfNeed(_sKey); - for (int j=_nSectionIndex + 1; j<m_aList.size();j++) + for (int j = _nSectionIndex + 1; j < m_aList.size(); j++) { String sLine = getItem(j).trim(); @@ -270,7 +275,7 @@ class IniFile implements Enumeration { return j; } - } + } } return -1; } @@ -280,7 +285,7 @@ class IniFile implements Enumeration { _sKey = toLowerIfNeed(_sKey); int i = _nSectionIndex + 1; - for (int j=i; j<m_aList.size();j++) + for (int j = i; j < m_aList.size(); j++) { String sLine = getItem(j).trim(); @@ -318,7 +323,7 @@ class IniFile implements Enumeration int nEqual = sLine.indexOf("="); if (nEqual >= 0) { - String sKey = sLine.substring(0, nEqual).trim(); + String sKey = sLine.substring(0, nEqual).trim(); String sValue = sLine.substring(nEqual + 1).trim(); return sValue; } @@ -332,7 +337,6 @@ class IniFile implements Enumeration */ // private int m_nCurrentPosition; // private String m_sOldKey; - public String getValue(String _sSection, String _sKey) { String sValue = ""; @@ -359,7 +363,6 @@ class IniFile implements Enumeration // } // return ""; // } - /** * Returns the value at Section, Key converted to an integer * Check with hasValue(Section, Key) to check before you get into trouble. @@ -369,31 +372,32 @@ class IniFile implements Enumeration * @return */ public int getIntValue(String _sSection, String _sKey, int _nDefault) - { - String sValue = getValue(_sSection, _sKey); - int nValue = _nDefault; - if (sValue.length() > 0) { - try + String sValue = getValue(_sSection, _sKey); + int nValue = _nDefault; + if (sValue.length() > 0) { - nValue = Integer.valueOf(sValue).intValue(); - } - catch(java.lang.NumberFormatException e) - { - GlobalLogWriter.get().println("IniFile.getIntValue(): Caught a number format exception, return the default value."); + try + { + nValue = Integer.valueOf(sValue).intValue(); + } + catch (java.lang.NumberFormatException e) + { + GlobalLogWriter.get().println("IniFile.getIntValue(): Caught a number format exception, return the default value."); + } } + return nValue; } - return nValue; - } public void close() - { - store(); - } + { + store(); + } + /** write back the ini file to the disk, only if there exist changes - * @deprecated use close() instead! - */ + * @deprecated use close() instead! + */ public void store() { if (m_bListContainUnsavedChanges == false) @@ -423,22 +427,26 @@ class IniFile implements Enumeration try { RandomAccessFile aWriter = new RandomAccessFile(aFile, "rw"); - for (int i=0; i<m_aList.size();i++) + for (int i = 0; i < m_aList.size(); i++) { String sLine = getItem(i); + if (sLine.startsWith("[")) + { + // write an extra empty line before next section. + aWriter.writeByte((int) '\n'); + } aWriter.writeBytes(sLine); - aWriter.writeByte((int)'\n'); + aWriter.writeByte((int) '\n'); } aWriter.close(); } - catch (java.io.FileNotFoundException fne) { GlobalLogWriter.get().println("couldn't open file for writing " + m_sFilename); GlobalLogWriter.get().println("Message: " + fne.getMessage()); // DebugHelper.exception(BasicErrorCode.SbERR_FILE_NOT_FOUND, ""); } - catch(java.io.IOException ie) + catch (java.io.IOException ie) { GlobalLogWriter.get().println("Exception occurs while writing to file " + m_sFilename); GlobalLogWriter.get().println("Message: " + ie.getMessage()); @@ -446,12 +454,16 @@ class IniFile implements Enumeration } } + public void insertValue(String _sSection, String _sKey, int _nValue) + { + insertValue(_sSection, _sKey, String.valueOf(_nValue)); + } + public void insertValue(String _sSection, String _sKey, long _nValue) + { + insertValue(_sSection, _sKey, String.valueOf(_nValue)); + } - public void insertValue(String _sSection, String _sKey, int _nValue) - { - insertValue(_sSection, _sKey, String.valueOf(_nValue)); - } /** insert a value there are 3 cases @@ -551,71 +563,71 @@ class IniFile implements Enumeration // // return sLocalValue; // } - -public void removeSection(String _sSectionToRemove) -{ - // first, search for the name - int i = findSection(_sSectionToRemove); - if (i == -1) { - // Section to remove not found, do nothing. - return; - } - // second, find the next section - int j = findNextSection(i + 1); - if (j == -1) + public void removeSection(String _sSectionToRemove) { - // if we are at the end, use size() as second section - j = m_aList.size(); - } - // remove all between first and second section - for(int k=i; k<j; k++) - { - m_aList.remove(i); + // first, search for the name + int i = findSection(_sSectionToRemove); + if (i == -1) + { + // Section to remove not found, do nothing. + return; + } + // second, find the next section + int j = findNextSection(i + 1); + if (j == -1) + { + // if we are at the end, use size() as second section + j = m_aList.size(); + } + // remove all between first and second section + for (int k = i; k < j; k++) + { + m_aList.remove(i); + } + // mark the list as changed + m_bListContainUnsavedChanges = true; } - // mark the list as changed - m_bListContainUnsavedChanges = true; - } /** * some tests for this class */ - public static void main(String[] args) { - String sTempFile = System.getProperty("java.io.tmpdir"); - sTempFile += "inifile"; - + public static void main(String[] args) + { + String sTempFile = System.getProperty("java.io.tmpdir"); + sTempFile += "inifile"; - IniFile aIniFile = new IniFile(sTempFile); - String sValue = aIniFile.getValue("Section", "Key"); - // insert a new value to a already exist section - aIniFile.insertValue("Section", "Key2", "a new value in a existing section"); - // replace a value - aIniFile.insertValue("Section", "Key", "replaced value"); - // create a new value - aIniFile.insertValue("New Section", "Key", "a new key value pair"); - aIniFile.insertValue("New Section", "Key2", "a new second key value pair"); - String sValue2 = aIniFile.getValue("Section2", "Key"); + IniFile aIniFile = new IniFile(sTempFile); + String sValue = aIniFile.getValue("Section", "Key"); + // insert a new value to a already exist section + aIniFile.insertValue("Section", "Key2", "a new value in a existing section"); + // replace a value + aIniFile.insertValue("Section", "Key", "replaced value"); + // create a new value + aIniFile.insertValue("New Section", "Key", "a new key value pair"); + aIniFile.insertValue("New Section", "Key2", "a new second key value pair"); - aIniFile.removeSection("Section"); - aIniFile.removeSection("New Section"); + String sValue2 = aIniFile.getValue("Section2", "Key"); - aIniFile.close(); - } + aIniFile.removeSection("Section"); + aIniFile.removeSection("New Section"); + aIniFile.close(); + } /** * Enumeration Interface * @return true, if there are more Key values */ public boolean hasMoreElements() - { - if (m_aEnumerationPos >=0 && - m_aEnumerationPos < m_aList.size()) { - return true; + if (m_aEnumerationPos >= 0 && + m_aEnumerationPos < m_aList.size()) + { + return true; + } + return false; } - return false; - } /** * Find the next line, which starts with '[' @@ -623,40 +635,57 @@ public void removeSection(String _sSectionToRemove) * @return the line where '[' found or -1 */ private int findNextSection(int i) - { - if (i >= 0) { - while (i < m_aList.size()) + if (i >= 0) { - String sLine = (String)m_aList.get(i); - if (sLine.startsWith("[")) + while (i < m_aList.size()) { - return i; + String sLine = (String) m_aList.get(i); + if (sLine.startsWith("[")) + { + return i; + } + i++; } - i++; } + return -1; } - return -1; - } /** * Enumeration Interface * @return a key without the enveloped '[' ']' */ public Object nextElement() - { - int nLineWithSection = findNextSection(m_aEnumerationPos); - if (nLineWithSection != -1) { - String sSection = (String)m_aList.get(nLineWithSection); - m_aEnumerationPos = findNextSection(nLineWithSection + 1); - sSection = sectionToString(sSection); - return sSection; + int nLineWithSection = findNextSection(m_aEnumerationPos); + if (nLineWithSection != -1) + { + String sSection = (String) m_aList.get(nLineWithSection); + m_aEnumerationPos = findNextSection(nLineWithSection + 1); + sSection = sectionToString(sSection); + return sSection; + } + else + { + m_aEnumerationPos = m_aList.size(); + } + return null; } - else + + /** + * Helper to count the occurence of Sections + * @return returns the count of '^['.*']$' Elements + */ + public int getElementCount() { - m_aEnumerationPos = m_aList.size(); + int nCount = 0; + int nPosition = 0; + while ((nPosition = findNextSection(nPosition)) != -1) + { + nCount++; + nPosition++; + } + return nCount; } - return null; - } } + diff --git a/qadevOOo/runner/graphical/JPEGComparator.java b/qadevOOo/runner/graphical/JPEGComparator.java index 6bde326dacb1..126d06e11ffc 100644 --- a/qadevOOo/runner/graphical/JPEGComparator.java +++ b/qadevOOo/runner/graphical/JPEGComparator.java @@ -160,10 +160,9 @@ public class JPEGComparator extends EnhancedComplexTestCase assure("File '" + sJPEGFilename + "' doesn't exists.", aFile.exists(), true); if (aFile.exists()) { + GlobalLogWriter.println("Page: " + i); checkOnePicture(sJPEGFilename, _sResult, _aParams); } - - } } else @@ -265,6 +264,9 @@ public class JPEGComparator extends EnhancedComplexTestCase _aParams.getTestParameters().put("current_state", sStatusRunThrough); _aParams.getTestParameters().put("current_info", sStatusMessage); _aParams.getTestParameters().put("current_ok_status", ok_status); + + // if we have a ugly page, we must return this as a FAILED STATUS in Log file! + // assure( "There exist pages marked as ugly.", ugly == 0) } private void checkOnePicture(String _sDocumentName, String _sResult, ParameterHelper _aParams) @@ -510,14 +512,20 @@ public class JPEGComparator extends EnhancedComplexTestCase * between old and new graphics. The font of the new graphics is little bit bigger, * so the pixel count between old graphics and new graphics is twice the more. * + * @param _sOldGfx path & name to the jpeg file (1) + * @param _sNewGfx path & name to the other jpeg file (2) + * @param _sDiffGfx path & name to the new difference file which shows the difference between (1) and (2) + * @return the count of different pixels + * @throws java.io.IOException if file access is not possible */ - public int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx) + + public static int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx) throws java.io.IOException { // new count pixels - int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx); - int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx); - int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx); + final int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx); + final int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx); + final int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx); int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic); @@ -536,7 +544,7 @@ public class JPEGComparator extends EnhancedComplexTestCase return nPercent; } - public int compareJPEG(String _sOldGfx, String _sNewGfx, String _sDiffGfx) + private static int compareJPEG(String _sOldGfx, String _sNewGfx, String _sDiffGfx) { String sComposite = "composite"; if (OSHelper.isWindows()) @@ -568,6 +576,15 @@ public class JPEGComparator extends EnhancedComplexTestCase String sBack = aHandler.getOutputText(); GlobalLogWriter.get().println("'" + sBack + "'"); } + else + { + // creates an extra smaller difference picture + File aDiffFile = new File(_sDiffGfx); + if (aDiffFile.exists()) + { + JPEGCreator.convertToNearSameFileWithWidth340(_sDiffGfx); + } + } return nExitCode; } @@ -621,7 +638,7 @@ public class JPEGComparator extends EnhancedComplexTestCase } catch(java.lang.NumberFormatException e) { - GlobalLogWriter.get().println("Number format exception"); + GlobalLogWriter.get().println("identify(): Number format exception"); nResult = 0; } return nResult; diff --git a/qadevOOo/runner/graphical/JPEGCreator.java b/qadevOOo/runner/graphical/JPEGCreator.java index e3475c43ddfb..afda4eb39b07 100644 --- a/qadevOOo/runner/graphical/JPEGCreator.java +++ b/qadevOOo/runner/graphical/JPEGCreator.java @@ -76,6 +76,8 @@ public class JPEGCreator extends EnhancedComplexTestCase int nPages = countPages(sJPEGNameSchema); if (nPages > 0) { + createSmallPictures(sJPEGNameSchema); + String sIndexFile = FileHelper.appendPath(_sResult, "index.ini"); File aIndexFile = new File(sIndexFile); if (aIndexFile.exists()) @@ -91,6 +93,109 @@ public class JPEGCreator extends EnhancedComplexTestCase } /** + * Create a lot of smaller and nicer Pictures of the big fat pages. + * Looks better + * @param _sJPEGSchema + */ + public void createSmallPictures(String _sJPEGSchema) + { + int nPages = 0; + if (_sJPEGSchema.length() > 0) + { + // TODO: if there doesn't exists a '%04d' in the schema we will return 9999 which is a little bit wrong here. + for (int i=1;i<10000;i++) + { + String sJPEGFilename = getFilenameForJPEGSchema(_sJPEGSchema, i); + if (FileHelper.exists(sJPEGFilename)) + { + convertToNearSameFileWithWidth340(sJPEGFilename); + // m_aFileList.add(sNewJPEGFilename); // as long as the files exist, fill the array + nPages ++; + } + else + { + break; // stop file check + } + } + } + // return nPages; + } + +/** + * convert a picture to a new picture with 340 pixel width. + * @param _sJPEGFilename + */ +public static void convertToNearSameFileWithWidth340(String _sJPEGFilename) +{ + String sNewJPEGFilename; + sNewJPEGFilename = util.utils.replaceAll13(_sJPEGFilename, ".jpg", "_w340.jpg"); + convertToWidth340(_sJPEGFilename, sNewJPEGFilename); +} + + /** + * convert chart2_Regression.ods.ps_180DPI_0001.jpg -filter Catrom -resize +340x chart2_Regression.ods.ps_180DPI_0001_w340.jpg + +Point wie bisher +Cubic schlecht, weil unscharf +... +Triangle ganz brauchbar (default?) +Catrom am besten + + * @param _sFrom + * @param _To + */ +private static void convertToWidth340(String _sFrom, String _To) +{ + // int nResult = 0; + + String sConvertEXE = "convert"; + if (OSHelper.isLinuxIntel()) + { + sConvertEXE = "convert"; + } + if (OSHelper.isWindows()) + { + sConvertEXE = "convert.exe"; + } + + String[] sCommandArray = + { + sConvertEXE, + _sFrom, + "-filter", "Catrom", + "-resize", "340x", + _To + }; + ProcessHandler aHandler = new ProcessHandler(sCommandArray); + boolean bBackValue = aHandler.executeSynchronously(); + int nExitCode = aHandler.getExitCode(); + + String sBack = aHandler.getOutputText(); + if (sBack.length() > 0) + { + GlobalLogWriter.get().println("'" + sBack + "'"); + } + // try to interpret the result, which we get as a String +// try +// { +// int nIdx = sBack.indexOf("\n"); +// if (nIdx > 0) +// { +// sBack = sBack.substring(0, nIdx); +// } +// +// nResult = Integer.valueOf(sBack).intValue(); +// } +// catch(java.lang.NumberFormatException e) +// { +// GlobalLogWriter.get().println("Number format exception"); +// nResult = 0; +// } + // return nResult; +} + +/** * create out of a given Postscript/PDF _sFile a list of JPEGs, one for every page * @param _sFile * @param _sAdditional diff --git a/qadevOOo/runner/graphical/PixelCounter.java b/qadevOOo/runner/graphical/PixelCounter.java index 5664682d154d..02f4a4d8361d 100644 --- a/qadevOOo/runner/graphical/PixelCounter.java +++ b/qadevOOo/runner/graphical/PixelCounter.java @@ -34,7 +34,7 @@ package graphical; // ----------------------------------------------------------------------------- abstract class CountPixel { - int m_nCount = 0; + protected int m_nCount = 0; public int getCount() {return m_nCount;} public abstract void count(int _nRGB); } @@ -47,9 +47,9 @@ class CountNotWhite extends CountPixel // System.out.println("CountWhite()"); } - public void count(final int pixel) + public void countold(final int pixel) { - final int alpha = (pixel >> 24) & 0xff; + // final int alpha = (pixel >> 24) & 0xff; final int red = (pixel >> 16) & 0xff; final int green = (pixel >> 8) & 0xff; final int blue = (pixel ) & 0xff; @@ -61,6 +61,28 @@ class CountNotWhite extends CountPixel } ++m_nCount; } + public void count(final int pixel) + { + // final int alpha = (pixel >> 24) & 0xff; + final int blue = (pixel ) & 0xff; + if (blue != 0xff) + { + ++m_nCount; + return; + } + final int green = (pixel >> 8) & 0xff; + if (green != 0xff) + { + ++m_nCount; + return; + } + final int red = (pixel >> 16) & 0xff; + if (red != 0xff) + { + ++m_nCount; + return; + } + } } // ----------------------------------------------------------------------------- @@ -71,9 +93,9 @@ class CountNotBlack extends CountPixel // System.out.println("CountBlack()"); } - public void count(final int pixel) + public void countold(final int pixel) { - final int alpha = (pixel >> 24) & 0xff; + // final int alpha = (pixel >> 24) & 0xff; final int red = (pixel >> 16) & 0xff; final int green = (pixel >> 8) & 0xff; final int blue = (pixel ) & 0xff; @@ -84,6 +106,28 @@ class CountNotBlack extends CountPixel } ++m_nCount; } + public void count(final int pixel) + { + // final int alpha = (pixel >> 24) & 0xff; + final int blue = (pixel ) & 0xff; + if (blue != 0x00) + { + ++m_nCount; + return; + } + final int green = (pixel >> 8) & 0xff; + if (green != 0x00) + { + ++m_nCount; + return; + } + final int red = (pixel >> 16) & 0xff; + if (red != 0x00) + { + ++m_nCount; + return; + } + } } // ----------------------------------------------------------------------------- @@ -157,7 +201,7 @@ public class PixelCounter { throws java.io.IOException { ImageHelper aImage = ImageHelper.createImageHelper(_sFile); - int nw = graphics_stuff.countNotWhitePixel(aImage); + final int nw = graphics_stuff.countNotWhitePixel(aImage); return nw; } @@ -165,7 +209,7 @@ public class PixelCounter { throws java.io.IOException { ImageHelper aImage = ImageHelper.createImageHelper(_sFile); - int nw = graphics_stuff.countNotBlackPixel(aImage); + final int nw = graphics_stuff.countNotBlackPixel(aImage); return nw; } diff --git a/qadevOOo/runner/helper/APIDescGetter.java b/qadevOOo/runner/helper/APIDescGetter.java index cf57c0d26110..036487fb9856 100644 --- a/qadevOOo/runner/helper/APIDescGetter.java +++ b/qadevOOo/runner/helper/APIDescGetter.java @@ -42,7 +42,6 @@ import java.util.StringTokenizer; import share.DescEntry; import share.DescGetter; - /** * This is the Office-API specific DescGetter<br> * <br> @@ -68,11 +67,11 @@ import share.DescGetter; * -sce sw.SwXBodyText,sw.SwXBookmark<br> * runs the module test of <B>Sw.SwXBodyText</B> and <B>sw.SwXBookmark</B><br> */ +public class APIDescGetter extends DescGetter +{ -public class APIDescGetter extends DescGetter { private static String fullJob = null; - /* * gets the needed information about a StarOffice component * @param descPath Path to the ComponentDescription @@ -80,102 +79,136 @@ public class APIDescGetter extends DescGetter { * @param debug if true some debug information is displayed on standard out */ public DescEntry[] getDescriptionFor(String job, String descPath, - boolean debug) { + boolean debug) + { - if (job.startsWith("-o")) { + if (job.startsWith("-o")) + { job = job.substring(3, job.length()).trim(); - if (job.indexOf(".") < 0) { + if (job.indexOf(".") < 0) + { return null; } // special in case several Interfaces are given comma separated - if (job.indexOf(",") < 0) { + if (job.indexOf(",") < 0) + { DescEntry entry = getDescriptionForSingleJob(job, descPath, - debug); - - if (entry != null) { - return new DescEntry[] { entry }; - } else { + debug); + + if (entry != null) + { + return new DescEntry[] + { + entry + }; + } + else + { return null; } - } else { + } + else + { ArrayList subs = getSubInterfaces(job); String partjob = job.substring(0, job.indexOf(",")).trim(); DescEntry entry = getDescriptionForSingleJob(partjob, descPath, - debug); + debug); - if (entry != null) { - for (int i = 0; i < entry.SubEntryCount; i++) { + if (entry != null) + { + for (int i = 0; i < entry.SubEntryCount; i++) + { String subEntry = entry.SubEntries[i].longName; int cpLength = entry.longName.length(); subEntry = subEntry.substring(cpLength + 2, - subEntry.length()); + subEntry.length()); - if (subs.contains(subEntry)) { + if (subs.contains(subEntry)) + { entry.SubEntries[i].isToTest = true; } } - return new DescEntry[] { entry }; - } else { + return new DescEntry[] + { + entry + }; + } + else + { return null; } } } - if (job.startsWith("-p")) { + if (job.startsWith("-p")) + { job = job.substring(3, job.length()).trim(); String[] scenario = createScenario(descPath, job, debug); - if (scenario == null) { + if (scenario == null) + { return null; } DescEntry[] entries = new DescEntry[scenario.length]; - for (int i=0;i<scenario.length;i++) { + for (int i = 0; i < scenario.length; i++) + { entries[i] = getDescriptionForSingleJob( - scenario[i].substring(3).trim(), descPath, debug); + scenario[i].substring(3).trim(), descPath, debug); } - if (job.equals("listall")) { + if (job.equals("listall")) + { util.dbg.printArray(scenario); System.exit(0); } return entries; } - if (job.startsWith("-sce")) { + if (job.startsWith("-sce")) + { job = job.substring(5, job.length()).trim(); File sceFile = new File(job); if (sceFile.exists()) + { return getScenario(job, descPath, debug); - else { + } + else + { //look the scenarion like this? : // sw.SwXBodyText,sw.SwXTextCursor ArrayList subs = getSubObjects(job); DescEntry[] entries = new DescEntry[subs.size()]; - for (int i=0; i<subs.size(); i++){ + for (int i = 0; i < subs.size(); i++) + { entries[i] = getDescriptionForSingleJob( - (String)subs.get(i), descPath, debug); + (String) subs.get(i), descPath, debug); } return entries; } - } else { + } + else + { return null; } } protected DescEntry getDescriptionForSingleJob(String job, String descPath, - boolean debug) { + boolean debug) + { boolean isSingleInterface = job.indexOf("::") > 0; fullJob = job; - if (isSingleInterface) { + if (isSingleInterface) + { job = job.substring(0, job.indexOf("::")); } - if (job.startsWith("bugs")) { + if (job.startsWith("bugs")) + { DescEntry Entry = new DescEntry(); Entry.entryName = job; Entry.longName = job; @@ -191,14 +224,19 @@ public class APIDescGetter extends DescGetter { DescEntry entry = null; - if (descPath != null) { - if (debug) { + if (descPath != null) + { + if (debug) + { System.out.println("## reading from File " + descPath); } entry = getFromDirectory(descPath, job, debug); - } else { - if (debug) { + } + else + { + if (debug) + { System.out.println("## reading from jar"); } @@ -207,139 +245,136 @@ public class APIDescGetter extends DescGetter { boolean foundInterface = false; - if (isSingleInterface && (entry != null)) { - for (int i = 0; i < entry.SubEntryCount; i++) { - if (!(entry.SubEntries[i].longName).equals(fullJob)) { + if (isSingleInterface && (entry != null)) + { + for (int i = 0; i < entry.SubEntryCount; i++) + { + if (!(entry.SubEntries[i].longName).equals(fullJob)) + { entry.SubEntries[i].isToTest = false; - } else { + } + else + { foundInterface = true; entry.SubEntries[i].isToTest = true; } } } - if (isSingleInterface && !foundInterface || entry == null) { + if (isSingleInterface && !foundInterface || entry == null) + { return setErrorDescription(entry, - "couldn't find a description for test '" + fullJob+ "'"); + "couldn't find a description for test '" + fullJob + "'"); } return entry; } protected static DescEntry[] getSubEntries(BufferedReader cvsFile, - DescEntry parent, boolean debug) { + DescEntry parent, boolean debug) + { String line = ""; String old_ifc_name = ""; ArrayList ifc_names = new ArrayList(); ArrayList meth_names = new ArrayList(); DescEntry ifcDesc = null; - DescEntry methDesc = null; - String entryType = "service"; - while (line != null) { - try { + while (line != null) + { + try + { line = cvsFile.readLine(); + if (line == null) + { + continue; + } + if (line.startsWith("#")) + { + continue; + } + if (line.length() <= 0) + { + continue; + } +// TODO Probleme here + // int nFirstSemicolon = line.indexOf(";"); + // int nLastSemicolon = line.lastIndexOf(";"); + + String unknown; + String ifc_name = ""; // = line.substring(line.indexOf(";") + 2, line.lastIndexOf(";") - 1); + String meth_name = ""; // = line.substring(line.lastIndexOf(";") + 2, line.length() - 1); + StringTokenizer aToken = new StringTokenizer(line, ";"); + if (aToken.countTokens() < 3) + { + System.out.println("Wrong format: Line '" + line + "' is not supported."); + continue; + } + if (aToken.hasMoreTokens()) + { + unknown = StringHelper.removeQuoteIfExists(aToken.nextToken()); + } + if (aToken.hasMoreTokens()) + { + ifc_name = StringHelper.removeQuoteIfExists(aToken.nextToken()); + } + if (aToken.hasMoreTokens()) + { + meth_name = StringHelper.removeQuoteIfExists(aToken.nextToken()); + } - if ((line != null) && (line.length() > 0)) { - String ifc_name = line.substring(line.indexOf(";") + 2, - line.lastIndexOf(";") - 1); - String meth_name = line.substring(line.lastIndexOf(";") + 2, - line.length() - 1); - - methDesc = new DescEntry(); - - if (meth_name.indexOf("#optional") > 0) { - methDesc.isOptional = true; - meth_name = meth_name.substring(0, - meth_name.indexOf("#")); - } - - if (meth_name.endsWith("()")) { - methDesc.EntryType = "method"; - entryType = "interface"; - } else { - methDesc.EntryType = "property"; - entryType = "service"; - } - - methDesc.entryName = meth_name; - methDesc.isToTest = true; - - String withoutHash = ifc_name; - - if (ifc_name.indexOf("#optional") > 0) { - withoutHash = ifc_name.substring(0, - ifc_name.indexOf("#")); - } - - methDesc.longName = parent.entryName + "::" + - withoutHash + "::" + meth_name; + // String ifc_name = line.substring(line.indexOf(";") + 2, line.lastIndexOf(";") - 1); + // String meth_name = line.substring(line.lastIndexOf(";") + 2, line.length() - 1); - if (!ifc_name.equals(old_ifc_name)) { - if (ifcDesc != null) { - ifcDesc.SubEntries = getDescArray( - meth_names.toArray()); - ifcDesc.SubEntryCount = meth_names.size(); + DescEntry methDesc = createDescEntry(meth_name, ifc_name, parent); - //mark service/interface as optional if all methods/properties are optional - boolean allOptional = true; + if (!ifc_name.equals(old_ifc_name)) + { + if (ifcDesc != null) + { + ifcDesc.SubEntries = getDescArray(meth_names.toArray()); + ifcDesc.SubEntryCount = meth_names.size(); - for (int k = 0; k < ifcDesc.SubEntryCount; k++) { - if (!ifcDesc.SubEntries[k].isOptional) { - allOptional = false; - } - } + //mark service/interface as optional if all methods/properties are optional + boolean allOptional = true; - if (!ifcDesc.isOptional && allOptional) { - ifcDesc.isOptional = allOptional; + for (int k = 0; k < ifcDesc.SubEntryCount; k++) + { + if (!ifcDesc.SubEntries[k].isOptional) + { + allOptional = false; } - - meth_names.clear(); - ifc_names.add(ifcDesc); - } - - ifcDesc = new DescEntry(); - ifcDesc.isToTest = true; - old_ifc_name = ifc_name; - - if (ifc_name.indexOf("#optional") > 0) { - ifcDesc.isOptional = true; - ifc_name = ifc_name.substring(0, - ifc_name.indexOf("#")); } - StringTokenizer st = new StringTokenizer(ifc_name, ":"); - String className = ""; - - int count = 3; - - if (ifc_name.startsWith("drafts")) { - count = 4; + if (!ifcDesc.isOptional && allOptional) + { + ifcDesc.isOptional = allOptional; } - for (int i = 0; st.hasMoreTokens(); i++) { - String token = st.nextToken(); - - // skipping (drafts.)com.sun.star - if (i >= count) { - if (!st.hasMoreTokens()) { - // inserting '_' before the last token - token = "_" + token; - } + meth_names.clear(); + ifc_names.add(ifcDesc); + } - className += ("." + token); - } - } + ifcDesc = new DescEntry(); + ifcDesc.isToTest = true; + old_ifc_name = ifc_name; - ifcDesc.EntryType = entryType; - ifcDesc.entryName = "ifc" + className; - ifcDesc.longName = parent.entryName + "::" + - ifc_name; + if (ifc_name.indexOf("#optional") > 0) + { + ifcDesc.isOptional = true; + ifc_name = ifc_name.substring(0, ifc_name.indexOf("#")); } - meth_names.add(methDesc); + String className = createClassName(ifc_name); + + ifcDesc.EntryType = entryType; + ifcDesc.entryName = "ifc" + className; + ifcDesc.longName = parent.entryName + "::" + ifc_name; } - } catch (java.io.IOException ioe) { + meth_names.add(methDesc); + + } + catch (java.io.IOException ioe) + { parent.hasErrorMsg = true; parent.ErrorMsg = "IOException while reading the description"; @@ -353,13 +388,16 @@ public class APIDescGetter extends DescGetter { //mark service/interface as optional if all methods/properties are optional boolean allOptional = true; - for (int k = 0; k < ifcDesc.SubEntryCount; k++) { - if (!ifcDesc.SubEntries[k].isOptional) { + for (int k = 0; k < ifcDesc.SubEntryCount; k++) + { + if (!ifcDesc.SubEntries[k].isOptional) + { allOptional = false; } } - if (!ifcDesc.isOptional && allOptional) { + if (!ifcDesc.isOptional && allOptional) + { ifcDesc.isOptional = allOptional; } @@ -367,26 +405,106 @@ public class APIDescGetter extends DescGetter { return getDescArray(makeArray(ifc_names)); } + private static String createClassName(String _ifc_name) + { + StringTokenizer st = new StringTokenizer(_ifc_name, ":"); + String className = ""; + + int count = 3; + + if (_ifc_name.startsWith("drafts")) + { + count = 4; + } + + for (int i = 0; st.hasMoreTokens(); i++) + { + String token = st.nextToken(); + + // skipping (drafts.)com.sun.star + if (i >= count) + { + if (!st.hasMoreTokens()) + { + // inserting '_' before the last token + token = "_" + token; + } + + className += ("." + token); + } + } + return className; + } + + private static String entryType; + + private static DescEntry createDescEntry(String meth_name, String ifc_name, DescEntry parent) + { + entryType = "service"; + DescEntry methDesc = new DescEntry(); + + if (meth_name.indexOf("#optional") > 0) + { + methDesc.isOptional = true; + meth_name = meth_name.substring(0, meth_name.indexOf("#")); + } + + if (meth_name.endsWith("()")) + { + methDesc.EntryType = "method"; + entryType = "interface"; + } + else + { + methDesc.EntryType = "property"; + entryType = "service"; + } + + methDesc.entryName = meth_name; + methDesc.isToTest = true; + + + String withoutHash = ifc_name; + + if (ifc_name.indexOf("#optional") > 0) + { + withoutHash = ifc_name.substring(0, ifc_name.indexOf("#")); + } + + methDesc.longName = parent.entryName + "::" + withoutHash + "::" + meth_name; + + return methDesc; + } + + private static void createIfcName(String ifc_name, ArrayList meth_names, DescEntry ifcDesc) + { + } /** * This method ensures that XComponent will be the last in the list of interfaces */ - protected static Object[] makeArray(ArrayList entries) { + protected static Object[] makeArray(ArrayList entries) + { Object[] entriesArray = entries.toArray(); ArrayList returnArray = new ArrayList(); Object addAtEnd = null; - for (int k = 0; k < entriesArray.length; k++) { + for (int k = 0; k < entriesArray.length; k++) + { DescEntry entry = (DescEntry) entriesArray[k]; - if (entry.entryName.equals("ifc.lang._XComponent")) { + if (entry.entryName.equals("ifc.lang._XComponent")) + { addAtEnd = entry; - } else { + } + else + { returnArray.add(entry); } } - if (addAtEnd != null) { + if (addAtEnd != null) + { returnArray.add(addAtEnd); } @@ -394,40 +512,50 @@ public class APIDescGetter extends DescGetter { } protected static DescEntry setErrorDescription(DescEntry entry, - String ErrorMsg) { + String ErrorMsg) + { if (entry == null) + { entry = new DescEntry(); + } entry.hasErrorMsg = true; entry.ErrorMsg = "Error while getting description for test '" + - fullJob + "' as an API test: " + ErrorMsg; + fullJob + "' as an API test: " + ErrorMsg; return entry; } - protected static DescEntry[] getDescArray(Object[] list) { + protected static DescEntry[] getDescArray(Object[] list) + { DescEntry[] entries = new DescEntry[list.length]; - for (int i = 0; i < list.length; i++) { + for (int i = 0; i < list.length; i++) + { entries[i] = (DescEntry) list[i]; } return entries; } - protected DescEntry getFromClassPath(String aEntry, boolean debug) { + protected DescEntry getFromClassPath(String aEntry, boolean debug) + { int dotindex = aEntry.indexOf('.'); - if (dotindex == -1) { + if (dotindex == -1) + { return null; } String module = null; String shortName = null; - if (aEntry.indexOf(".uno") == -1) { + if (aEntry.indexOf(".uno") == -1) + { module = aEntry.substring(0, aEntry.indexOf('.')); shortName = aEntry.substring(aEntry.indexOf('.') + 1); - } else { + } + else + { module = aEntry.substring(0, aEntry.lastIndexOf('.')); shortName = aEntry.substring(aEntry.lastIndexOf('.') + 1); } @@ -443,22 +571,28 @@ public class APIDescGetter extends DescGetter { java.net.URL url = this.getClass().getResource("/objdsc/" + module); - if (url == null) { + if (url == null) + { return setErrorDescription(theEntry, - "couldn't find module '" + module + "'"); + "couldn't find module '" + module + "'"); } - try { + try + { java.net.URLConnection con = url.openConnection(); - if (con instanceof java.net.JarURLConnection) { + String sEndsWithCSVName = "." + shortName.trim() + ".csv"; + if (con instanceof java.net.JarURLConnection) + { // get Jar file from connection java.util.jar.JarFile f = ((java.net.JarURLConnection) con).getJarFile(); // Enumerate over all entries java.util.Enumeration e = f.entries(); - while (e.hasMoreElements()) { + String sStartModule = "/" + module + "/"; + while (e.hasMoreElements()) + { String entry = e.nextElement().toString(); @@ -466,49 +600,51 @@ public class APIDescGetter extends DescGetter { // System.out.println("### Read from connetion: " + entry); // } - if ((entry.lastIndexOf("/" + module + "/") != -1) && - entry.endsWith("." + shortName.trim() + ".csv")) { - InputStream input = this.getClass() - .getResourceAsStream("/" + - entry); - csvFile = new BufferedReader( - new InputStreamReader(input)); - + if ((entry.lastIndexOf(sStartModule) != -1) && + entry.endsWith(sEndsWithCSVName)) + { + InputStream input = this.getClass().getResourceAsStream("/" + entry); + csvFile = new BufferedReader(new InputStreamReader(input)); break; } } - } else { + } + else + { InputStream in = con.getInputStream(); - java.io.BufferedReader buf = new java.io.BufferedReader( - new InputStreamReader(in)); + java.io.BufferedReader buf = new java.io.BufferedReader(new InputStreamReader(in)); boolean found = false; - while (buf.ready() && !found) { + while (buf.ready() && !found) + { String entry = buf.readLine(); - if (entry.endsWith(shortName.trim() + ".csv")) { + if (entry.endsWith(sEndsWithCSVName)) + { System.out.println("FOUND ####"); - InputStream input = this.getClass() - .getResourceAsStream("/objdsc/" + - module + - "/" + - entry); + InputStream input = this.getClass().getResourceAsStream("/objdsc/" + + module + + "/" + + entry); csvFile = new BufferedReader( - new InputStreamReader(input)); + new InputStreamReader(input)); found = true; } } buf.close(); } - } catch (java.io.IOException e) { + } + catch (java.io.IOException e) + { e.printStackTrace(); } - if (csvFile == null) { + if (csvFile == null) + { return setErrorDescription(theEntry, - "couldn't find component '" + - theEntry.entryName + "'"); + "couldn't find component '" + + theEntry.entryName + "'"); } DescEntry[] subEntries = getSubEntries(csvFile, theEntry, debug); @@ -520,10 +656,12 @@ public class APIDescGetter extends DescGetter { } protected static DescEntry getFromDirectory(String descPath, String entry, - boolean debug) { + boolean debug) + { int dotindex = entry.indexOf('.'); - if (dotindex == -1) { + if (dotindex == -1) + { return null; } @@ -531,10 +669,13 @@ public class APIDescGetter extends DescGetter { String module = null; String shortName = null; - if (entry.indexOf(".uno") == -1) { + if (entry.indexOf(".uno") == -1) + { module = entry.substring(0, entry.indexOf('.')); shortName = entry.substring(entry.indexOf('.') + 1); - } else { + } + else + { module = entry.substring(0, entry.lastIndexOf('.')); shortName = entry.substring(entry.lastIndexOf('.') + 1); } @@ -546,7 +687,8 @@ public class APIDescGetter extends DescGetter { aEntry.EntryType = "component"; aEntry.isToTest = true; - if (debug) { + if (debug) + { System.out.println("Parsing Description Path: " + descPath); System.out.println("Searching module: " + module); System.out.println("For the Component " + shortName); @@ -554,34 +696,41 @@ public class APIDescGetter extends DescGetter { File modPath = new File(descPath + fs + module); - if (!modPath.exists()) { + if (!modPath.exists()) + { return setErrorDescription(aEntry, - "couldn't find module '" + module + "'"); + "couldn't find module '" + module + "'"); } String[] files = modPath.list(); String found = "none"; - for (int i = 0; i < files.length; i++) { - if (files[i].endsWith("." + shortName + ".csv")) { + for (int i = 0; i < files.length; i++) + { + if (files[i].endsWith("." + shortName + ".csv")) + { found = files[i]; System.out.println("found " + found); break; } } - if (found.equals("none")) { + if (found.equals("none")) + { return setErrorDescription(aEntry, - "couldn't find component '" + entry + "'"); + "couldn't find component '" + entry + "'"); } String aUrl = descPath + fs + module + fs + found; BufferedReader csvFile = null; - try { + try + { csvFile = new BufferedReader(new FileReader(aUrl)); - } catch (java.io.FileNotFoundException fnfe) { + } + catch (java.io.FileNotFoundException fnfe) + { return setErrorDescription(aEntry, "couldn't find file '" + aUrl + "'"); } @@ -593,14 +742,17 @@ public class APIDescGetter extends DescGetter { return aEntry; } - protected ArrayList getSubInterfaces(String job) { + protected ArrayList getSubInterfaces(String job) + { ArrayList namesList = new ArrayList(); StringTokenizer st = new StringTokenizer(job, ","); - for (int i = 0; st.hasMoreTokens(); i++) { + for (int i = 0; st.hasMoreTokens(); i++) + { String token = st.nextToken(); - if (token.indexOf(".") < 0) { + if (token.indexOf(".") < 0) + { namesList.add(token); } } @@ -608,11 +760,13 @@ public class APIDescGetter extends DescGetter { return namesList; } - protected ArrayList getSubObjects(String job) { + protected ArrayList getSubObjects(String job) + { ArrayList namesList = new ArrayList(); StringTokenizer st = new StringTokenizer(job, ","); - for (int i = 0; st.hasMoreTokens(); i++) { + for (int i = 0; st.hasMoreTokens(); i++) + { namesList.add(st.nextToken()); } @@ -620,17 +774,23 @@ public class APIDescGetter extends DescGetter { } protected String[] createScenario(String descPath, String job, - boolean debug) { + boolean debug) + { String[] scenario = null; - if (descPath != null) { - if (debug) { + if (descPath != null) + { + if (debug) + { System.out.println("## reading from File " + descPath); } scenario = getScenarioFromDirectory(descPath, job, debug); - } else { - if (debug) { + } + else + { + if (debug) + { System.out.println("## reading from jar"); } @@ -641,31 +801,46 @@ public class APIDescGetter extends DescGetter { } protected String[] getScenarioFromDirectory(String descPath, String job, - boolean debug) { + boolean debug) + { String[] modules = null; ArrayList componentList = new ArrayList(); - if (!job.equals("unknown") && !job.equals("listall")) { - modules = new String[] { job }; - } else { + if (!job.equals("unknown") && !job.equals("listall")) + { + modules = new String[] + { + job + }; + } + else + { File dirs = new File(descPath); - if (!dirs.exists()) { + if (!dirs.exists()) + { modules = null; - } else { + } + else + { modules = dirs.list(); } } - for (int i=0;i<modules.length;i++) { - if (! isUnusedModule(modules[i])) { - File moduleDir = new File(descPath+System.getProperty("file.separator")+modules[i]); - if (moduleDir.exists()) { + for (int i = 0; i < modules.length; i++) + { + if (!isUnusedModule(modules[i])) + { + File moduleDir = new File(descPath + System.getProperty("file.separator") + modules[i]); + if (moduleDir.exists()) + { String[] components = moduleDir.list(); - for (int j=0;j<components.length;j++) { - if (components[j].endsWith(".csv")) { + for (int j = 0; j < components.length; j++) + { + if (components[j].endsWith(".csv")) + { String toAdd = getComponentForString(components[j], modules[i]); - toAdd = "-o "+modules[i]+"."+toAdd; + toAdd = "-o " + modules[i] + "." + toAdd; componentList.add(toAdd); } } @@ -676,7 +851,8 @@ public class APIDescGetter extends DescGetter { String[] scenario = new String[componentList.size()]; Collections.sort(componentList); - for (int i = 0; i < componentList.size(); i++) { + for (int i = 0; i < componentList.size(); i++) + { scenario[i] = (String) componentList.get(i); } @@ -684,67 +860,79 @@ public class APIDescGetter extends DescGetter { } - protected String[] getScenarioFromClassPath(String job, boolean debug) { + protected String[] getScenarioFromClassPath(String job, boolean debug) + { String subdir = "/"; - if (!job.equals("unknown") && !job.equals("listall")) { + if (!job.equals("unknown") && !job.equals("listall")) + { subdir += job; } java.net.URL url = this.getClass().getResource("/objdsc" + subdir); - if (url == null) { + if (url == null) + { return null; } ArrayList scenarioList = new ArrayList(); - try { + try + { java.net.URLConnection con = url.openConnection(); - if (con instanceof java.net.JarURLConnection) { + if (con instanceof java.net.JarURLConnection) + { // get Jar file from connection java.util.jar.JarFile f = ((java.net.JarURLConnection) con).getJarFile(); // Enumerate over all entries java.util.Enumeration e = f.entries(); - while (e.hasMoreElements()) { + while (e.hasMoreElements()) + { String entry = e.nextElement().toString(); if (entry.startsWith("objdsc" + subdir) && (entry.indexOf("CVS") < 0) && - !entry.endsWith("/")) { + !entry.endsWith("/")) + { int startMod = entry.indexOf("/"); int endMod = entry.lastIndexOf("/"); String module = entry.substring(startMod + 1, endMod); String component = getComponentForString( - entry.substring(endMod + 1, - entry.length()), - module); + entry.substring(endMod + 1, + entry.length()), + module); - if (!isUnusedModule(module)) { + if (!isUnusedModule(module)) + { scenarioList.add("-o " + module + "." + - component); + component); } } } } - } catch (java.io.IOException e) { + } + catch (java.io.IOException e) + { e.printStackTrace(); } String[] scenario = new String[scenarioList.size()]; Collections.sort(scenarioList); - for (int i = 0; i < scenarioList.size(); i++) { + for (int i = 0; i < scenarioList.size(); i++) + { scenario[i] = (String) scenarioList.get(i); } return scenario; } - protected String getComponentForString(String full, String module) { + protected String getComponentForString(String full, String module) + { String component = ""; @@ -755,18 +943,20 @@ public class APIDescGetter extends DescGetter { int lastdot = full.lastIndexOf("."); component = full.substring(lastdot + 1, full.length()); - if (module.equals("file") || module.equals("xmloff")) { + if (module.equals("file") || module.equals("xmloff")) + { String withoutComponent = full.substring(0, lastdot); int preLastDot = withoutComponent.lastIndexOf("."); component = withoutComponent.substring(preLastDot + 1, - withoutComponent.length()) + - "." + component; + withoutComponent.length()) + + "." + component; } return component; } - protected boolean isUnusedModule(String moduleName) { + protected boolean isUnusedModule(String moduleName) + { ArrayList removed = new ArrayList(); removed.add("acceptor"); removed.add("brdgfctr"); diff --git a/qadevOOo/runner/helper/CfgParser.java b/qadevOOo/runner/helper/CfgParser.java index 95ea722481a8..19d2d561f666 100644 --- a/qadevOOo/runner/helper/CfgParser.java +++ b/qadevOOo/runner/helper/CfgParser.java @@ -27,7 +27,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package helper; import lib.TestParameters; @@ -41,48 +40,65 @@ import util.PropertyName; * <br> * inside TestParameters */ -public class CfgParser { +public class CfgParser +{ + protected boolean debug = false; - protected String iniFile=""; + protected String iniFile = ""; - public CfgParser(String ini) { + public CfgParser(String ini) + { if (ini != null) + { this.iniFile = ini; + } } - public void getIniParameters(TestParameters param) { + public void getIniParameters(TestParameters param) + { debug = param.DebugIsActive; Properties cfg = null; - if (iniFile.equals("")) { + if (iniFile.equals("")) + { //no iniFile given, search one in the users home directory cfg = getProperties(getDefaultFileName(true)); //try to search the user dir if no iniFile could be found yet - if (cfg == null) { + if (cfg == null) + { cfg = getProperties(getDefaultFileName(false)); } - } else { + } + else + { cfg = getProperties(iniFile); } - if (cfg != null) { + if (cfg != null) + { Enumeration cfgEnum = cfg.keys(); - while (cfgEnum.hasMoreElements()) { + while (cfgEnum.hasMoreElements()) + { String pName = (String) cfgEnum.nextElement(); Object pValue = cfg.getProperty(pName); - if (pValue instanceof String) pValue = ((String)pValue).trim(); + if (pValue instanceof String) + { + pValue = ((String) pValue).trim(); + } - param.put(pName.trim(),pValue); + param.put(pName.trim(), pValue); - if (pName.equals(PropertyName.TEST_DOCUMENT_PATH)) { + if (pName.equals(PropertyName.TEST_DOCUMENT_PATH)) + { - param.put("DOCPTH",(String)pValue); - System.setProperty("DOCPTH",(String)pValue); + param.put("DOCPTH", (String) pValue); + System.setProperty("DOCPTH", (String) pValue); } - if (pName.equals(PropertyName.SRC_ROOT)) { + else if (pName.equals(PropertyName.SRC_ROOT)) + { - System.setProperty(pName,(String)pValue); + System.setProperty(pName, (String) pValue); } } @@ -93,45 +109,57 @@ public class CfgParser { //check for platform dependend parameters //this would have a $OperatingSystem as prefix String os = (String) param.get(PropertyName.OPERATING_SYSTEM); - if (os != null && os.length()>1) { + if (os != null && os.length() > 1) + { //found something that could be a prefex //check all parameters for this Enumeration keys = param.keys(); - while (keys.hasMoreElements()) { + while (keys.hasMoreElements()) + { String key = (String) keys.nextElement(); - if (key.startsWith(os)) { + if (key.startsWith(os)) + { Object oldValue = param.get(key); - String newKey = key.substring(os.length()+1); + String newKey = key.substring(os.length() + 1); param.remove(key); - param.put(newKey,oldValue); + param.put(newKey, oldValue); } } } } - protected Properties getProperties(String name) { + protected Properties getProperties(String name) + { // get the resource file Properties prop = new Properties(); - if ( debug ) { - System.out.println("Looking for "+name); + if (debug) + { + System.out.println("Looking for " + name); } - try { + try + { FileInputStream propFile = new FileInputStream(name); prop.load(propFile); - System.out.println("Parsing properties from "+name); + System.out.println("Parsing properties from " + name); propFile.close(); - } catch (Exception e) { - try { - java.net.URL url = this.getClass().getResource("/"+name); - if (url != null) { - System.out.println("Parsing properties from "+name); + } + catch (Exception e) + { + try + { + java.net.URL url = this.getClass().getResource("/" + name); + if (url != null) + { + System.out.println("Parsing properties from " + name); java.net.URLConnection connection = url.openConnection(); java.io.InputStream in = connection.getInputStream(); prop.load(in); } - } catch (Exception ex) { + } + catch (Exception ex) + { //Exception while reading prop-file, returning null return null; } @@ -140,22 +168,28 @@ public class CfgParser { return prop; } - protected String getDefaultFileName(boolean home) { + protected String getDefaultFileName(boolean home) + { String fileSeparator = System.getProperty("file.separator"); String path = ""; - if (home) { + if (home) + { //look inside the home directory path = System.getProperty("user.home"); - } else { + } + else + { path = System.getProperty("user.dir"); } - if (fileSeparator.equals("/")) { + if (fileSeparator.equals("/")) + { //suppose I'm on Unix-platform - return path+fileSeparator+".runner.props"; - } else { + return path + fileSeparator + ".runner.props"; + } + else + { //suppose I'm on Windows - return path+fileSeparator+"runner.props"; + return path + fileSeparator + "runner.props"; } } - } diff --git a/qadevOOo/runner/helper/ClParser.java b/qadevOOo/runner/helper/ClParser.java index eddd351fdb0a..c88b14a6028b 100644 --- a/qadevOOo/runner/helper/ClParser.java +++ b/qadevOOo/runner/helper/ClParser.java @@ -39,54 +39,74 @@ import util.utils; * This class parses commandline Argument and stores <br> * them into TestParameter */ -public class ClParser { +public class ClParser +{ /* * Parses the commandline argument and puts them<br> * into the TestParameters */ - public void getCommandLineParameter(TestParameters param, String[] args) { + public void getCommandLineParameter(TestParameters param, String[] args) + { Properties mapping = getMapping(); - for (int i = 0; i < args.length;) { + for (int i = 0; i < args.length;) + { String pName = getParameterFor(mapping, args[i]).trim(); String pValue = ""; - if (pName.equals("TestJob")) { - if (args.length > (i + 1)) { + if (pName.equals("TestJob")) + { + if (args.length > (i + 1)) + { pValue = args[i].trim() + " " + args[i + 1].trim(); i += 2; - } else { + } + else + { pValue = args[i].trim() + " unknown"; i += 2; } - } else { - if ((i + 1) < args.length) { + } + else + { + if ((i + 1) < args.length) + { pValue = args[i + 1].trim(); - if (pValue.startsWith("-")) { + if (pValue.startsWith("-")) + { i++; pValue = "yes"; - } else if (pValue.startsWith("'")) { + } + else if (pValue.startsWith("'")) + { i++; - while (!pValue.endsWith("'")) { + while (!pValue.endsWith("'")) + { i++; pValue = pValue + " " + args[i].trim(); } pValue = utils.replaceAll13(pValue, "'", ""); i++; - } else { + } + else + { i += 2; } - if (pName.equals("TestDocumentPath")) { + if (pName.equals("TestDocumentPath")) + { System.setProperty("DOCPTH", pValue); } - if (pName.equals(PropertyName.SRC_ROOT)) { - System.setProperty(pName,pValue); + else if (pName.equals(PropertyName.SRC_ROOT)) + { + System.setProperty(pName, pValue); } - } else { + } + else + { pValue = "yes"; i++; } @@ -100,11 +120,14 @@ public class ClParser { * This method returns the path to a Configuration file <br> * if defined as command line parameter, an empty String elsewhere */ - public String getIniPath(String[] args) { + public String getIniPath(String[] args) + { String iniFile = ""; - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-ini")) { + for (int i = 0; i < args.length; i++) + { + if (args[i].equals("-ini")) + { iniFile = args[i + 1]; break; } @@ -117,11 +140,14 @@ public class ClParser { * This method returns the path to a Configuration file <br> * if defined as command line parameter, an empty String elsewhere */ - public String getRunnerIniPath(String[] args) { + public String getRunnerIniPath(String[] args) + { String iniFile = ""; - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-runnerini")) { + for (int i = 0; i < args.length; i++) + { + if (args[i].equals("-runnerini")) + { iniFile = args[i + 1]; break; } @@ -133,7 +159,8 @@ public class ClParser { /* * This method maps commandline Parameters to TestParameters */ - protected Properties getMapping() { + protected Properties getMapping() + { Properties map = new Properties(); map.setProperty("-cs", "ConnectionString"); map.setProperty("-tb", "TestBase"); @@ -153,10 +180,12 @@ public class ClParser { return map; } - protected String getParameterFor(Properties map, String name) { + protected String getParameterFor(Properties map, String name) + { String ret = map.getProperty(name); - if (ret == null) { + if (ret == null) + { ret = name.substring(1); } diff --git a/qadevOOo/runner/helper/ComplexDescGetter.java b/qadevOOo/runner/helper/ComplexDescGetter.java index 90f6bbbf133b..5ed9efcbb702 100644 --- a/qadevOOo/runner/helper/ComplexDescGetter.java +++ b/qadevOOo/runner/helper/ComplexDescGetter.java @@ -40,45 +40,56 @@ import share.LogWriter; /** * */ -public class ComplexDescGetter extends DescGetter { +public class ComplexDescGetter extends DescGetter +{ ComplexTest testClass; /** Creates new ComplexDescGetter */ - public ComplexDescGetter() { + public ComplexDescGetter() + { testClass = null; } public DescEntry[] getDescriptionFor(String entry, String DescPath, - boolean debug) { + boolean debug) + { // read scenario file - if (entry.startsWith("-sce")) { - DescEntry[] entries = getScenario(entry.substring(5),null,debug); + if (entry.startsWith("-sce")) + { + DescEntry[] entries = getScenario(entry.substring(5), null, debug); return entries; } // one single job - else if (entry.startsWith("-o")) { + else if (entry.startsWith("-o")) + { DescEntry dEntry = getDescriptionForSingleJob(entry.substring(3), null, debug); if (dEntry != null) - return new DescEntry[] {dEntry}; + { + return new DescEntry[] + { + dEntry + }; + } } - System.out.println("Could not get a testjob with parameter '" - + entry +"'"); + System.out.println("Could not get a testjob with parameter '" + entry + "'"); // no job available return null; } - - protected DescEntry getDescriptionForSingleJob(String className, String descPath, boolean debug) { + protected DescEntry getDescriptionForSingleJob(String className, String descPath, boolean debug) + { DynamicClassLoader dcl = new DynamicClassLoader(); String methodNames[] = null; - if (debug) { + if (debug) + { System.out.println("Searching Class: " + className); } int index = className.indexOf("::"); - if (index != -1) { + if (index != -1) + { // case1: method() // case2: method(param1,param2) // case3: method1(param1,param2),method2(param1,param2) @@ -88,43 +99,53 @@ public class ComplexDescGetter extends DescGetter { String[] split = method.split("(?<=\\)),(?=\\w+)"); - for (int i = 0; i < split.length; i++) { + for (int i = 0; i < split.length; i++) + { String meth = split[i]; - if (meth.endsWith("()")) meth = meth.substring(0, meth.length() - 2); + if (meth.endsWith("()")) + { + meth = meth.substring(0, meth.length() - 2); + } methods.add(meth); } methodNames = new String[methods.size()]; - methodNames = (String[])methods.toArray(methodNames); + methodNames = (String[]) methods.toArray(methodNames); } // create an instance - try { - testClass = (ComplexTestCase)dcl.getInstance(className); + try + { + testClass = (ComplexTestCase) dcl.getInstance(className); } - catch(java.lang.IllegalArgumentException e) { - System.out.println("Error while getting description for test '" +className + "' as a Complex test."); + catch (java.lang.IllegalArgumentException e) + { + System.out.println("Error while getting description for test '" + className + "' as a Complex test."); return null; } - catch(java.lang.ClassCastException e) { - System.out.println("The given class '" +className + "' is not a Complex test."); + catch (java.lang.ClassCastException e) + { + System.out.println("The given class '" + className + "' is not a Complex test."); return null; } - if (debug) { - System.out.println("Got test: "+((Object)testClass).toString()); + if (debug) + { + System.out.println("Got test: " + ((Object) testClass).toString()); } String testObjectName = className; String[] testMethodNames = null; - if (testMethodNames == null){ + if (testMethodNames == null) + { testMethodNames = testClass.getTestMethodNames(); } - if (methodNames != null) { + if (methodNames != null) + { testMethodNames = methodNames; } @@ -141,7 +162,8 @@ public class ComplexDescGetter extends DescGetter { * @param log * @return filled description entry */ - public DescEntry createTestDesc(String testObjectName, String className, String[] testMethodNames, LogWriter log){ + public DescEntry createTestDesc(String testObjectName, String className, String[] testMethodNames, LogWriter log) + { DescEntry dEntry = new DescEntry(); @@ -153,10 +175,11 @@ public class ComplexDescGetter extends DescGetter { dEntry.Logger = log; dEntry.SubEntryCount = testMethodNames.length; dEntry.SubEntries = new DescEntry[dEntry.SubEntryCount]; - for (int i=0; i<dEntry.SubEntryCount; i++) { + for (int i = 0; i < dEntry.SubEntryCount; i++) + { DescEntry aEntry = new DescEntry(); aEntry.entryName = testMethodNames[i]; - aEntry.longName = testObjectName +"::" + aEntry.entryName; + aEntry.longName = testObjectName + "::" + aEntry.entryName; aEntry.isOptional = false; aEntry.EntryType = "method"; aEntry.isToTest = true; @@ -167,8 +190,8 @@ public class ComplexDescGetter extends DescGetter { return dEntry; } - protected String[] createScenario(String descPath, String job, boolean debug) { - return new String[]{}; + protected String[] createScenario(String descPath, String job, boolean debug) + { + return new String[] {}; } - } diff --git a/qadevOOo/runner/helper/CwsDataExchangeImpl.java b/qadevOOo/runner/helper/CwsDataExchangeImpl.java index 782d944e3009..6884d6c27d8e 100644 --- a/qadevOOo/runner/helper/CwsDataExchangeImpl.java +++ b/qadevOOo/runner/helper/CwsDataExchangeImpl.java @@ -1,5 +1,5 @@ /* -************************************************************************* + ************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -43,7 +43,8 @@ import util.utils; * Implementaion of the interface CwsDataExchange * @see share.CwsDataExchange */ -public class CwsDataExchangeImpl implements CwsDataExchange { +public class CwsDataExchangeImpl implements CwsDataExchange +{ private final String cwsName; private final TestParameters param; @@ -51,7 +52,8 @@ public class CwsDataExchangeImpl implements CwsDataExchange { private final BuildEnvTools bet; private final boolean mDebug; - public CwsDataExchangeImpl(String cwsName, TestParameters param, LogWriter log) throws ParameterNotFoundException { + public CwsDataExchangeImpl(String cwsName, TestParameters param, LogWriter log) throws ParameterNotFoundException + { this.cwsName = cwsName; this.param = param; this.log = log; @@ -59,15 +61,22 @@ public class CwsDataExchangeImpl implements CwsDataExchange { mDebug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); } - public ArrayList getModules() { + public ArrayList getModules() + { // the cwstouched command send its version information to StdErr. // A piping from StdErr to SdtOut the tcsh does not support. // To find the output easily the echo command is used - final String[] commands = {"echo cwstouched starts here", "cwstouched", "echo cwstouched ends here"}; + final String[] commands = + { + "echo cwstouched starts here", + "cwstouched", + "echo cwstouched ends here" + }; final ProcessHandler procHdl = bet.runCommandsInEnvironmentShell(commands, null, 20000); - if (mDebug) { + if (mDebug) + { log.println("---> Output of getModules:"); log.println(procHdl.getOutputText()); log.println("<--- Output of getModules"); @@ -79,33 +88,44 @@ public class CwsDataExchangeImpl implements CwsDataExchange { final String[] outs = procHdl.getOutputText().split("\n"); final ArrayList<String> moduleNames = new ArrayList<String>(); - boolean start = false; - for (int i = 0; i < outs.length; i++) { + boolean bStart = false; + for (int i = 0; i < outs.length; i++) + { final String line = outs[i]; - if (line.startsWith("cwstouched ends here")) { - start = false; + if (line.startsWith("cwstouched starts here")) + { + bStart = true; + continue; } - if (start && line.length() > 1) { - moduleNames.add(line); + if (line.startsWith("cwstouched ends here")) + { + bStart = false; + continue; } - if (line.startsWith("cwstouched starts here")) { - start = true; + if (bStart && line.length() > 1) + { + moduleNames.add(line); } } return moduleNames; } - public void setUnoApiCwsStatus(boolean status) { + public void setUnoApiCwsStatus(boolean status) + { FileWriter out = null; String statusFile = null; - try { + try + { final String stat = status ? ".PASSED.OK" : ".PASSED.FAILED"; - statusFile = utils.getUsersTempDir() + System.getProperty("file.separator") + "UnoApiCwsStatus." + - (String) param.get(PropertyName.VERSION) + "_" + param.get(PropertyName.OPERATING_SYSTEM) + stat + ".txt"; + statusFile = utils.getUsersTempDir() + + System.getProperty("file.separator") + + "UnoApiCwsStatus." + + (String) param.get(PropertyName.VERSION) + + "_" + param.get(PropertyName.OPERATING_SYSTEM) + stat + ".txt"; out = new FileWriter(statusFile); @@ -113,16 +133,26 @@ public class CwsDataExchangeImpl implements CwsDataExchange { out.flush(); out.close(); - final String[] commands = {"cwsattach " + statusFile}; + final String[] commands = + { + "cwsattach " + statusFile + }; bet.runCommandsInEnvironmentShell(commands, null, 5000); - } catch (IOException ex) { + } + catch (IOException ex) + { System.out.println("ERROR: could not attach file '" + statusFile + "' to cws\n" + ex.toString()); - } finally { - try { + } + finally + { + try + { out.close(); - } catch (IOException ex) { + } + catch (IOException ex) + { ex.printStackTrace(); } } diff --git a/qadevOOo/runner/helper/OfficeProvider.java b/qadevOOo/runner/helper/OfficeProvider.java index 36350899844d..5653c882a1f3 100644 --- a/qadevOOo/runner/helper/OfficeProvider.java +++ b/qadevOOo/runner/helper/OfficeProvider.java @@ -59,7 +59,8 @@ import util.utils; * This class will connect the office and start it if possible * */ -public class OfficeProvider implements AppProvider { +public class OfficeProvider implements AppProvider +{ protected static boolean debug = false; @@ -68,8 +69,10 @@ public class OfficeProvider implements AppProvider { * @param param * @param msf */ - public void backupUserLayer(TestParameters param, XMultiServiceFactory msf) { - try { + public void backupUserLayer(TestParameters param, XMultiServiceFactory msf) + { + try + { final XStringSubstitution sts = createStringSubstitution(msf); debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); @@ -78,8 +81,8 @@ public class OfficeProvider implements AppProvider { param.put("userLayer", userLayer); final String copyLayer = util.utils.getUsersTempDir() + System.getProperty("file.separator") + - "user_backup" + - System.getProperty("user.name"); + "user_backup" + + System.getProperty("user.name"); param.put("copyLayer", copyLayer); @@ -88,13 +91,21 @@ public class OfficeProvider implements AppProvider { OfficeWatcherPing owp = new OfficeWatcherPing((OfficeWatcher) param.get(PropertyName.OFFICE_WATCHER)); owp.start(); - FileTools.copyDirectory(new File(userLayer), new File(copyLayer), new String[]{"temp"}); + deleteFilesAndDirector (new File(copyLayer)); + FileTools.copyDirectory(new File(userLayer), new File(copyLayer), new String[] + { + "temp" + }); owp.finish(); - } catch (com.sun.star.container.NoSuchElementException e) { + } + catch (com.sun.star.container.NoSuchElementException e) + { System.out.println("User Variable '$(user)' not defined."); - } catch (java.io.IOException e) { + } + catch (java.io.IOException e) + { System.out.println("Couldn't backup user layer"); e.printStackTrace(); } @@ -107,30 +118,40 @@ public class OfficeProvider implements AppProvider { * @param param * @return return true if desktop is terminates, else false */ - public boolean disposeManager(lib.TestParameters param) { + public boolean disposeManager(lib.TestParameters param) + { XMultiServiceFactory msf = (XMultiServiceFactory) param.getMSF(); - if (msf == null) { + if (msf == null) + { return true; - } else { + } + else + { XDesktop desk = null; - try { + try + { desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, - msf.createInstance( - "com.sun.star.frame.Desktop")); - } catch (com.sun.star.uno.Exception ue) { + msf.createInstance( + "com.sun.star.frame.Desktop")); + } + catch (com.sun.star.uno.Exception ue) + { return false; } msf = null; - if (desk != null) { + if (desk != null) + { desk.terminate(); return true; - } else { + } + else + { return false; } } @@ -138,23 +159,29 @@ public class OfficeProvider implements AppProvider { /** * Method to get the ServiceManager of an Office + * @param param + * @return */ - public Object getManager(lib.TestParameters param) { + public Object getManager(lib.TestParameters param) + { String errorMessage = null; boolean bAppExecutionHasWarning = false; debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); String additionalArgs = (String) param.get( - "AdditionalConnectionArguments"); + "AdditionalConnectionArguments"); - if (additionalArgs == null) { + if (additionalArgs == null) + { additionalArgs = ";"; - } else { + } + else + { additionalArgs = "," + additionalArgs + ";"; } final String cncstr = "uno:" + param.get("ConnectionString") + ";urp" + - additionalArgs + "StarOffice.ServiceManager"; + additionalArgs + "StarOffice.ServiceManager"; System.out.println("Connecting the Office with " + cncstr); @@ -165,25 +192,29 @@ public class OfficeProvider implements AppProvider { // Example: The UNO-API-Tests in the projects will be executed by calling // 'damke'. This connects to an existing office. If the office crashes // it is usefull to restart the office and continuing the tests. - if ((param.getBool(util.PropertyName.AUTO_RESTART)) && (msf != null)) { + if ((param.getBool(util.PropertyName.AUTO_RESTART)) && (msf != null)) + { makeAppExecCommand(msf, param); } - if (msf == null) { + if (msf == null) + { String exc = ""; Exception exConnectFailed = null; boolean isExecutable = false; boolean isAppKnown = ((cncstr.indexOf("host=localhost") > 0) || (cncstr.indexOf("pipe,name=") > 0)); isAppKnown &= !((String) param.get("AppExecutionCommand")).equals(""); - if (isAppKnown) { + if (isAppKnown) + { dbg("Local Connection trying to start the Office"); //ensure that a pending officewatcher gets finished before a new //office is started final OfficeWatcher ow_old = (OfficeWatcher) param.get("Watcher"); - if (ow_old != null) { + if (ow_old != null) + { ow_old.finish = true; } @@ -192,8 +223,9 @@ public class OfficeProvider implements AppProvider { // validate the AppExecutionCommand, but try it out anyway. // keep the error message for later. errorMessage = - util.utils.validateAppExecutionCommand(cmd, (String) param.get("OperatingSystem")); - if (errorMessage.startsWith("Error")) { + util.utils.validateAppExecutionCommand(cmd, (String) param.get("OperatingSystem")); + if (errorMessage.startsWith("Error")) + { System.out.println(errorMessage); return null; } @@ -201,7 +233,7 @@ public class OfficeProvider implements AppProvider { final DynamicClassLoader dcl = new DynamicClassLoader(); final LogWriter log = (LogWriter) dcl.getInstance( - (String) param.get("LogWriter")); + (String) param.get("LogWriter")); //create empty entry final DescEntry Entry = new DescEntry(); @@ -220,7 +252,8 @@ public class OfficeProvider implements AppProvider { final ProcessHandler ph = new ProcessHandler(cmd, (PrintWriter) log); isExecutable = ph.executeAsynchronously(); - if (isExecutable) { + if (isExecutable) + { param.put("AppProvider", ph); final OfficeWatcher ow = new OfficeWatcher(param); param.put("Watcher", ow); @@ -253,31 +286,39 @@ public class OfficeProvider implements AppProvider { { Thread.sleep(k * 500); } - catch (InterruptedException ex){ } - } + catch (InterruptedException ex) + { + } + } k++; } - if (msf == null) { + if (msf == null) + { System.out.println("Exception while connecting.\n" + exConnectFailed); - if (exc != null) { + if (exc != null) + { System.out.println(exc); } - if (bAppExecutionHasWarning) { + if (bAppExecutionHasWarning) + { System.out.println(errorMessage); } - } else if (isExecutable) + } + else if (isExecutable) { - if (! param.getBool(util.PropertyName.DONT_BACKUP_USERLAYER)) + if (!param.getBool(util.PropertyName.DONT_BACKUP_USERLAYER)) { backupUserLayer(param, msf); } } - } else { - System.out.println("Could not connect an Office and cannot start one.\n". - concat("please start an office with following parameter:\n"). + } + else + { + System.out.println("Could not connect an Office and cannot start one.\n".concat("please start an office with following parameter:\n"). concat("\nsoffice -accept=").concat((String) param.get("ConnectionString")).concat(";urp;\n")); - if (bAppExecutionHasWarning) { + if (bAppExecutionHasWarning) + { System.out.println(errorMessage); } } @@ -288,16 +329,23 @@ public class OfficeProvider implements AppProvider { /** * Connect an Office + * @param connectStr + * @return + * @throws com.sun.star.uno.Exception + * @throws com.sun.star.uno.RuntimeException + * @throws com.sun.star.connection.NoConnectException + * @throws Exception */ protected static XMultiServiceFactory connect(String connectStr) - throws com.sun.star.uno.Exception, - com.sun.star.uno.RuntimeException, - com.sun.star.connection.NoConnectException, - Exception { + throws com.sun.star.uno.Exception, + com.sun.star.uno.RuntimeException, + com.sun.star.connection.NoConnectException, + Exception + { // Get component context final XComponentContext xcomponentcontext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( - null); + null); // initial serviceManager final XMultiComponentFactory xLocalServiceManager = xcomponentcontext.getServiceManager(); @@ -305,20 +353,21 @@ public class OfficeProvider implements AppProvider { // create a connector, so that it can contact the office // XUnoUrlResolver urlResolver = UnoUrlResolver.create(xcomponentcontext); final Object xUrlResolver = xLocalServiceManager.createInstanceWithContext( - "com.sun.star.bridge.UnoUrlResolver", xcomponentcontext); + "com.sun.star.bridge.UnoUrlResolver", xcomponentcontext); final XUnoUrlResolver urlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface( - XUnoUrlResolver.class, xUrlResolver); + XUnoUrlResolver.class, xUrlResolver); final Object rInitialObject = urlResolver.resolve(connectStr); XMultiServiceFactory xMSF = null; - if (rInitialObject != null) { + if (rInitialObject != null) + { debug = true; dbg("resolved url"); xMSF = (XMultiServiceFactory) UnoRuntime.queryInterface( - XMultiServiceFactory.class, rInitialObject); + XMultiServiceFactory.class, rInitialObject); } return xMSF; @@ -330,18 +379,21 @@ public class OfficeProvider implements AppProvider { * @param closeIfPossible If true, close even if * it was running before the test */ - public boolean closeExistingOffice(lib.TestParameters param, boolean closeIfPossible) { + public boolean closeExistingOffice(lib.TestParameters param, boolean closeIfPossible) + { XMultiServiceFactory msf = (XMultiServiceFactory) param.getMSF(); final boolean alreadyConnected = (msf != null); debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); - if (alreadyConnected) { + if (alreadyConnected) + { dbg("try to get ProcessHandler"); final ProcessHandler ph = (ProcessHandler) param.get("AppProvider"); - if (ph != null) { + if (ph != null) + { dbg("ProcessHandler != null"); disposeOffice(msf, param); @@ -351,26 +403,35 @@ public class OfficeProvider implements AppProvider { final OfficeWatcher ow = (OfficeWatcher) param.get("Watcher"); - if ((ow != null) && ow.isAlive()) { + if ((ow != null) && ow.isAlive()) + { dbg("OfficeWatcher will be finished"); ow.finish = true; - } else { + } + else + { dbg("OfficeWatcher seems to be finished"); } return true; - } else { - if (closeIfPossible) { + } + else + { + if (closeIfPossible) + { return disposeOffice(msf, param); } } - } else { + } + else + { final String cncstr = "uno:" + param.get("ConnectionString") + - ";urp;StarOffice.ServiceManager"; + ";urp;StarOffice.ServiceManager"; dbg("try to connect office"); msf = connectOffice(cncstr); - if (closeIfPossible) { + if (closeIfPossible) + { return disposeOffice(msf, param); } } @@ -378,23 +439,31 @@ public class OfficeProvider implements AppProvider { return true; } - private XMultiServiceFactory connectOffice(String cncstr) { + private XMultiServiceFactory connectOffice(String cncstr) + { XMultiServiceFactory msf = null; String exc = ""; debug = true; dbg("trying to connect to " + cncstr); - try { + try + { msf = connect(cncstr); - } catch (com.sun.star.uno.Exception ue) { + } + catch (com.sun.star.uno.Exception ue) + { exc = ue.getMessage(); - } catch (java.lang.Exception je) { + } + catch (java.lang.Exception je) + { exc = je.getMessage(); } - if (debug && exc != null && exc.length() != 0) { - if (exc == null) { + if (debug && exc != null && exc.length() != 0) + { + if (exc == null) + { exc = ""; } dbg("Could not connect an Office. " + exc); @@ -404,34 +473,42 @@ public class OfficeProvider implements AppProvider { } private synchronized boolean disposeOffice(XMultiServiceFactory msf, - TestParameters param) { + TestParameters param) + { XDesktop desk = null; debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); boolean result = true; - if (msf != null) { + if (msf != null) + { // disable QuickStarter - try { + try + { Object quickStarter = msf.createInstance("com.sun.star.office.Quickstart"); XFastPropertySet fps = (XFastPropertySet) UnoRuntime.queryInterface(XFastPropertySet.class, quickStarter); fps.setFastPropertyValue(0, false); - } catch (com.sun.star.uno.Exception ex) { + } + catch (com.sun.star.uno.Exception ex) + { dbg("ERROR: Could not disable QuickStarter: " + ex.toString()); } - try { + try + { desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, - msf.createInstance( - "com.sun.star.frame.Desktop")); + msf.createInstance( + "com.sun.star.frame.Desktop")); msf = null; - if (desk != null) { + if (desk != null) + { final boolean allClosed = closeAllWindows(desk); - if (!allClosed) { + if (!allClosed) + { dbg("Couldn't close all office windows!"); } @@ -440,16 +517,23 @@ public class OfficeProvider implements AppProvider { desk.terminate(); dbg("Desktop terminated"); - try { + try + { final int closeTime = param.getInt(util.PropertyName.OFFICE_CLOSE_TIME_OUT); dbg("the Office has " + closeTime / 1000 + " seconds for closing..."); Thread.sleep(closeTime); - } catch (java.lang.InterruptedException e) { + } + catch (java.lang.InterruptedException e) + { } } - } catch (com.sun.star.uno.Exception ue) { + } + catch (com.sun.star.uno.Exception ue) + { result = false; - } catch (com.sun.star.lang.DisposedException ue) { + } + catch (com.sun.star.lang.DisposedException ue) + { result = false; } } @@ -473,11 +557,13 @@ public class OfficeProvider implements AppProvider { final ProcessHandler ph = (ProcessHandler) param.get("AppProvider"); - if (ph != null) { + if (ph != null) + { // dispose watcher in case it's still running. final OfficeWatcher ow = (OfficeWatcher) param.get("Watcher"); - if ((ow != null) && ow.isAlive()) { + if ((ow != null) && ow.isAlive()) + { ow.finish = true; } @@ -487,17 +573,22 @@ public class OfficeProvider implements AppProvider { param.remove("AppProvider"); param.remove("ServiceFactory"); - if (! param.getBool(util.PropertyName.DONT_BACKUP_USERLAYER)) + if (!param.getBool(util.PropertyName.DONT_BACKUP_USERLAYER)) { //copy user_backup into user layer - try { + try + { final String userLayer = (String) param.get("userLayer"); final String copyLayer = (String) param.get("copyLayer"); if (userLayer != null && copyLayer != null) { + deleteFilesAndDirector(new File(userLayer)); final File copyFile = new File(copyLayer); dbg("copy '" + copyFile + "' -> '" + userLayer + "'"); - FileTools.copyDirectory(copyFile, new File(userLayer), new String[]{"temp"}); + FileTools.copyDirectory(copyFile, new File(userLayer), new String[] + { + "temp" + }); dbg("copy '" + copyFile + "' -> '" + userLayer + "' finished"); // remove all user_backup folder in temp dir @@ -518,46 +609,63 @@ public class OfficeProvider implements AppProvider { return result; } - protected boolean closeAllWindows(XDesktop desk) { + protected boolean closeAllWindows(XDesktop desk) + { final XEnumerationAccess compEnumAccess = desk.getComponents(); final XEnumeration compEnum = compEnumAccess.createEnumeration(); boolean res = true; - try { - while (compEnum.hasMoreElements()) { + try + { + while (compEnum.hasMoreElements()) + { final XCloseable closer = (XCloseable) UnoRuntime.queryInterface( - XCloseable.class, - compEnum.nextElement()); + XCloseable.class, + compEnum.nextElement()); - if (closer != null) { + if (closer != null) + { closer.close(true); } } - } catch (com.sun.star.util.CloseVetoException cve) { + } + catch (com.sun.star.util.CloseVetoException cve) + { res = false; - } catch (com.sun.star.container.NoSuchElementException nsee) { + } + catch (com.sun.star.container.NoSuchElementException nsee) + { res = false; - } catch (com.sun.star.lang.WrappedTargetException wte) { + } + catch (com.sun.star.lang.WrappedTargetException wte) + { res = false; } return res; } - public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) { + public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) + { Object xPathSubst = null; - try { + try + { xPathSubst = xMSF.createInstance( - "com.sun.star.util.PathSubstitution"); - } catch (com.sun.star.uno.Exception e) { + "com.sun.star.util.PathSubstitution"); + } + catch (com.sun.star.uno.Exception e) + { e.printStackTrace(); } - if (xPathSubst != null) { + if (xPathSubst != null) + { return (XStringSubstitution) UnoRuntime.queryInterface( - XStringSubstitution.class, xPathSubst); - } else { + XStringSubstitution.class, xPathSubst); + } + else + { return null; } } @@ -565,8 +673,11 @@ public class OfficeProvider implements AppProvider { /** * converts directory without 'file:///' prefix. * and System dependend file separator + * @param dir + * @return */ - public static String getDirSys(String dir) { + public static String getDirSys(String dir) + { String sysDir = ""; final int idx = dir.indexOf("file://"); @@ -574,26 +685,34 @@ public class OfficeProvider implements AppProvider { final int idx2 = dir.indexOf("file:///"); // remove leading 'file://' - if (idx < 0) { + if (idx < 0) + { sysDir = dir; - } else { + } + else + { sysDir = dir.substring("file://".length()); } sysDir = utils.replaceAll13(sysDir, "%20", " "); // append '/' if not there (e.g. linux) - if (sysDir.charAt(sysDir.length() - 1) != '/') { + if (sysDir.charAt(sysDir.length() - 1) != '/') + { sysDir += "/"; } // remove leading '/' and replace others with '\' on windows machines final String sep = System.getProperty("file.separator"); - if (sep.equalsIgnoreCase("\\")) { - if (!(idx2 < 0)) { + if (sep.equalsIgnoreCase("\\")) + { + if (!(idx2 < 0)) + { sysDir = sysDir.substring(1); - } else { + } + else + { //network path sysDir = "//" + sysDir; } @@ -611,27 +730,42 @@ public class OfficeProvider implements AppProvider { * @param msf the <CODE>MultiServiceFactory</CODE> * @param param the <CODE>TestParameters</CODE> */ - private static void makeAppExecCommand(XMultiServiceFactory msf, TestParameters param) { + private static void makeAppExecCommand(XMultiServiceFactory msf, TestParameters param) + { debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); // get existing AppExecutionCommand if available, else empty string String command = (String) param.get(util.PropertyName.APP_EXECUTION_COMMAND); - final String connectionString = (String) param.get(util.PropertyName.CONNECTION_STRING); + String connectionString; + if (param.getBool(util.PropertyName.USE_PIPE_CONNECTION) == true) + { + // This is the default behaviour + connectionString = (String) param.get(util.PropertyName.PIPE_CONNECTION_STRING); + } + else + { + // is used if UsePipeConnection=false + connectionString = (String) param.get(util.PropertyName.CONNECTION_STRING); + } String sysBinDir = ""; - try { + try + { sysBinDir = utils.getSystemURL(utils.expandMacro(msf, "$SYSBINDIR")); - } catch (java.lang.Exception e) { + } + catch (java.lang.Exception e) + { dbg("could not get system binary directory"); return; } // does the existing command show to the connected office? - if (command.indexOf(sysBinDir) == -1) { + if (command.indexOf(sysBinDir) == -1) + { command = sysBinDir + System.getProperty("file.separator") + "soffice" + - " -norestore -accept=" + connectionString + ";urp;"; + " -norestore -accept=" + connectionString + ";urp;"; } dbg("update AppExecutionCommand: " + command); @@ -639,45 +773,74 @@ public class OfficeProvider implements AppProvider { param.put(util.PropertyName.APP_EXECUTION_COMMAND, command); } - private static void dbg(String message) { - if (debug) { + private static void dbg(String message) + { + if (debug) + { System.out.println(utils.getDateTime() + "OfficeProvider: " + message); } } - private class OfficeWatcherPing extends Thread { + private class OfficeWatcherPing extends Thread + { private final OfficeWatcher ow; private boolean bStop = false; - public OfficeWatcherPing(OfficeWatcher ow) { + public OfficeWatcherPing(OfficeWatcher ow) + { this.ow = ow; } - public void run() { + public void run() + { System.out.println(utils.getDateTime() + "OfficeProvider:Owp: start "); - while (!bStop) { - System.out.println(utils.getDateTime() + "OfficeProvider:Owp: ping "); - ow.ping(); - try { + while (!bStop) + { + System.out.println(utils.getDateTime() + "OfficeProvider:Owp: ping "); + ow.ping(); + try + { System.out.println(utils.getDateTime() + "OfficeProvider:Owp: sleep "); OfficeWatcherPing.sleep(1000); // 5000 - } catch (InterruptedException ex) { + } + catch (InterruptedException ex) + { ex.printStackTrace(); } } } - public void finish() { - synchronized (this) { + public void finish() + { + synchronized(this) + { bStop = true; - System.out.println(utils.getDateTime() + "OfficeProvider:Owp: stop "); + System.out.println(utils.getDateTime() + "OfficeProvider:Owp: stop "); notify(); } } } + +private void deleteFilesAndDirector(File file) + { + File f = file; + if(f.isDirectory()) + { + File files[] = f.listFiles(); + for(int i = 0; i < files.length; i++) + { + deleteFilesAndDirector(files[i]); + } + f.delete(); + } + else if (f.isFile()) + { + f.delete(); + } + } } diff --git a/qadevOOo/runner/helper/ProcessHandler.java b/qadevOOo/runner/helper/ProcessHandler.java index c1892094d093..6fa842c4ebb8 100644 --- a/qadevOOo/runner/helper/ProcessHandler.java +++ b/qadevOOo/runner/helper/ProcessHandler.java @@ -36,6 +36,9 @@ import java.io.PrintStream; import java.io.LineNumberReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import lib.TestParameters; import util.PropertyName; import util.utils; @@ -51,7 +54,8 @@ import util.utils; * This class is currently used by ProcesHandler * internally only. */ -class Pump extends Thread { +class Pump extends Thread +{ private LineNumberReader reader; private String pref; @@ -69,23 +73,29 @@ class Pump extends Thread { * @param outPrefix A prefix which is printed at the * beginning of each output line. */ - public Pump(InputStream is, PrintWriter log, String outPrefix) { - this.pref = outPrefix == null ? "" : outPrefix; + public Pump(InputStream is, PrintWriter log, String outPrefix) + { + this.pref = (outPrefix == null) ? "" : outPrefix; reader = new LineNumberReader(new InputStreamReader(is)); this.log = log; start(); } - public void run() { - try { + public void run() + { + try + { String line = reader.readLine(); - while (line != null) { + while (line != null) + { log.println(pref + line); log.flush(); buf.append(line).append('\n'); line = reader.readLine(); } - } catch (java.io.IOException e) { + } + catch (java.io.IOException e) + { log.println(pref + "Exception occured: " + e); } } @@ -93,7 +103,8 @@ class Pump extends Thread { /** * Returns the text collected from input stream. */ - public String getStringBuffer() { + public String getStringBuffer() + { return buf.toString(); } } @@ -105,7 +116,8 @@ class Pump extends Thread { * execution. If you need to execute the same command again you * should create a new instance for this. */ -public class ProcessHandler { +public class ProcessHandler +{ private String cmdLine; private String[] cmdLineArray; @@ -121,7 +133,7 @@ public class ProcessHandler { private Pump stdout = null; private Pump stderr = null; private PrintStream stdIn = null; - private Process proc = null; + private Process m_aProcess = null; private TestParameters param = null; private boolean debug = false; @@ -131,7 +143,8 @@ public class ProcessHandler { * of external command is printed to stdout. * @param cmdLine */ - public ProcessHandler(String cmdLine) { + public ProcessHandler(String cmdLine) + { this(cmdLine, null, null, null, 0); } @@ -142,7 +155,8 @@ public class ProcessHandler { * of external command is printed to stdout. * @param cmdLines */ - public ProcessHandler(String[] cmdLines) { + public ProcessHandler(String[] cmdLines) + { this(null, null, null, null, 0); cmdLineArray = cmdLines; } @@ -157,7 +171,8 @@ public class ProcessHandler { * @param envVars * @see java.lang.Runtime exec(String[], String[]) */ - public ProcessHandler(String[] cmdLines, String[] envVars) { + public ProcessHandler(String[] cmdLines, String[] envVars) + { this(null, null, null, envVars, 0); cmdLineArray = cmdLines; } @@ -171,7 +186,8 @@ public class ProcessHandler { * @param cmdLines * @param workDir */ - public ProcessHandler(String[] cmdLines, File workDir) { + public ProcessHandler(String[] cmdLines, File workDir) + { this(null, null, workDir, null, 0); cmdLineArray = cmdLines; @@ -185,7 +201,8 @@ public class ProcessHandler { * @param log * @param workDir */ - public ProcessHandler(String[] cmdLines, PrintWriter log, File workDir) { + public ProcessHandler(String[] cmdLines, PrintWriter log, File workDir) + { this(null, log, workDir, null, 0); cmdLineArray = cmdLines; } @@ -197,7 +214,8 @@ public class ProcessHandler { * @param cmdLine * @param log */ - public ProcessHandler(String cmdLine, PrintWriter log) { + public ProcessHandler(String cmdLine, PrintWriter log) + { this(cmdLine, log, null, null, 0); } @@ -206,7 +224,8 @@ public class ProcessHandler { * @param cmdLine * @param timeOut */ - public ProcessHandler(String cmdLine, int timeOut) { + public ProcessHandler(String cmdLine, int timeOut) + { this(cmdLine, null, null, null, timeOut); } @@ -218,7 +237,8 @@ public class ProcessHandler { * @param cmdLine * @param workDir */ - public ProcessHandler(String cmdLine, File workDir) { + public ProcessHandler(String cmdLine, File workDir) + { this(cmdLine, null, workDir, null, 0); } @@ -230,7 +250,8 @@ public class ProcessHandler { * @param log * @param workDir */ - public ProcessHandler(String cmdLine, PrintWriter log, File workDir) { + public ProcessHandler(String cmdLine, PrintWriter log, File workDir) + { this(cmdLine, log, workDir, null, 0); } @@ -246,7 +267,8 @@ public class ProcessHandler { * @param workDir * @param envVars */ - public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars) { + public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars) + { this(cmdLine, log, workDir, envVars, 0); } @@ -278,15 +300,19 @@ public class ProcessHandler { * * */ - public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars, long timeOut) { + public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars, long timeOut) + { this.cmdLine = cmdLine; this.workDir = workDir; this.log = log; this.cmdLine = cmdLine; this.envVars = envVars; - if (log == null) { + if (log == null) + { this.log = new PrintWriter(new OutputStreamWriter(System.out)); - } else { + } + else + { this.log = log; } this.mTimeOut = timeOut; @@ -307,13 +333,17 @@ public class ProcessHandler { * @see lib.TestParameters * @see helper.OfficeWatcher */ - public ProcessHandler(String[] commands, PrintWriter log, File workDir, int shortWait, TestParameters param) { + public ProcessHandler(String[] commands, PrintWriter log, File workDir, int shortWait, TestParameters param) + { this(null, log, workDir, null, 0); this.cmdLineArray = commands; this.param = param; - if (shortWait != 0) { + if (shortWait != 0) + { this.mTimeOut = shortWait; - } else { + } + else + { this.mTimeOut = (long) (param.getInt(PropertyName.TIME_OUT) / 1.3); } debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE); @@ -325,7 +355,8 @@ public class ProcessHandler { * caused by <CODE>OfficeWatcher</CODE>, the OfficeWatcher get frequently a ping. * @see helper.OfficeWatcher */ - public void runCommand() { + public void runCommand() + { boolean changedText = true; int count = 0; @@ -334,44 +365,61 @@ public class ProcessHandler { this.executeAsynchronously(); OfficeWatcher ow = null; - if (param != null) { + if (param != null) + { ow = (OfficeWatcher) param.get(PropertyName.OFFICE_WATCHER); } + if (ow != null) + { + ow.ping(); + } - while (!this.isFinished() && changedText) { + int hangcheck = 10; + while (!this.isFinished() && changedText) + { count++; - if (ow != null) { - ow.ping(); - } - dbg("runCommand: waiting " + mTimeOut / 1000 + " seconds while command execution is ongoing... " + count); - shortWait(mTimeOut); + // dbg("runCommand: waiting " + mTimeOut / 1000 + " seconds while command execution is ongoing... " + count); + // shortWait(mTimeOut); + // shortWait(2000); // wait 2 seconds. //waitFor(mTimeOut); + waitFor(2000, false); // wait but don't kill - if (ow != null) { + if (ow != null) + { ow.ping(); } // check for changes in the output stream. If there are no changes, the process maybe hangs - if (!this.isFinished()) { - if (this.getOutputText().length() == memText.length()) { - changedText = false; - dbg("runCommand Could not detect changes in output stream!!!"); - + if (!this.isFinished()) + { + hangcheck--; + if (hangcheck < 0) + { + String sOutputText = getOutputText(); + if (sOutputText.length() == memText.length()) + { + changedText = false; + // dbg("runCommand Could not detect changes in output stream!!!"); + } + hangcheck = 10; + memText = this.getOutputText(); } - memText = this.getOutputText(); } } - if (!this.isFinished()) { + if (!this.isFinished()) + { dbg("runCommand Process ist not finished but there are no changes in output stream."); this.kill(); } } - public boolean isTimedOut() { + public boolean isTimedOut() + { return mbTimedOut; } - private void setTimedOut(boolean bTimedOut) { + private void setTimedOut(boolean bTimedOut) + { mbTimedOut = bTimedOut; } @@ -383,7 +431,8 @@ public class ProcessHandler { * started and correcly exits (exit code doesn't affect * to this result). */ - public boolean executeSynchronously() { + public boolean executeSynchronously() + { execute(); return waitFor(mTimeOut); } @@ -396,34 +445,48 @@ public class ProcessHandler { * @return <code>true</code> if process was successfully * started. */ - public boolean executeAsynchronously() { + public boolean executeAsynchronously() + { execute(); return isStarted(); } - public synchronized void kill() { - if (!isStarted()) { + public synchronized void kill() + { + if (!isStarted()) + { return; } boolean exit = false; int counter = 1; - while (counter < 3 && !exit) { - proc.destroy(); + while (counter < 3 && !exit) + { + m_aProcess.destroy(); - try { + try + { Thread.sleep(1000 * counter); // 5000 - } catch (java.lang.InterruptedException e) { } - try { - final int exit_Value = proc.exitValue(); - if (exit_Value < 1) { + catch (java.lang.InterruptedException e) + { + } + try + { + final int exit_Value = m_aProcess.exitValue(); + if (exit_Value < 1) + { exit = true; - } else { + } + else + { counter++; } dbg("kill: process closed with exit code " + exit_Value); - } catch (java.lang.IllegalThreadStateException e) { - if (counter < 3) { + } + catch (java.lang.IllegalThreadStateException e) + { + if (counter < 3) + { dbg("kill: Couldn't close process after " + counter + " attempts, trying again"); } counter++; @@ -432,45 +495,86 @@ public class ProcessHandler { isStarted = false; } - protected void execute() { - if (isStarted()) { + /** + * Returns the time in seconds since 1st January 1970 + * @return + */ + public static long getSystemTime() + { + // Calendar cal = new GregorianCalendar(); + // final long nTime = cal.getTimeInMillis(); + final long nTime = System.currentTimeMillis(); + return nTime; + } + private long m_nExactStartTimeInMillisec; + + private void initialExactStartTime() + { + m_nExactStartTimeInMillisec = getSystemTime(); + } + + public long getProcessStartTime() + { + return m_nExactStartTimeInMillisec; + } + + protected void execute() + { + if (isStarted()) + { throw new RuntimeException( - "The process handler has already been executed."); + "The process handler has already been executed."); } final Runtime runtime = Runtime.getRuntime(); - try { - if (cmdLine == null) { + try + { + if (cmdLine == null) + { log.print(utils.getDateTime() + "execute: Starting command from array: "); - for (int i = 0; i < cmdLineArray.length; i++) { + for (int i = 0; i < cmdLineArray.length; i++) + { log.print(cmdLineArray[i]); log.print(" "); } log.println(""); - - proc = runtime.exec(cmdLineArray, envVars); - } else { - if (workDir != null) { + initialExactStartTime(); + m_aProcess = runtime.exec(cmdLineArray, envVars); + } + else + { + if (workDir != null) + { log.println(utils.getDateTime() + "execute: Starting command: " + cmdLine + " " + - workDir.getAbsolutePath()); - proc = runtime.exec(cmdLine, envVars, workDir); - } else { + workDir.getAbsolutePath()); + m_aProcess = runtime.exec(cmdLine, envVars, workDir); + } + else + { log.println(utils.getDateTime() + "execute: Starting command: " + cmdLine); - proc = runtime.exec(cmdLine, envVars); + m_aProcess = runtime.exec(cmdLine, envVars); } } isStarted = true; - } catch (java.io.IOException e) { - if (cmdLine == null) { + } + catch (java.io.IOException e) + { + if (cmdLine == null) + { log.println(utils.getDateTime() + "execute: The command array can't be started: " + e); - } else { + } + else + { log.println(utils.getDateTime() + "execute: The command " + cmdLine + " can't be started: " + e); } return; } dbg("execute: pump io-streams"); - stdout = new Pump(proc.getInputStream(), log, "out > "); - stderr = new Pump(proc.getErrorStream(), log, "err > "); - stdIn = new PrintStream(proc.getOutputStream()); + stdout = new Pump(m_aProcess.getInputStream(), log, "out > "); + stderr = new Pump(m_aProcess.getErrorStream(), log, "err > "); + stdIn = new PrintStream(m_aProcess.getOutputStream()); + + // int nExitValue = m_aProcess.exitValue(); + // int dummy = 0; dbg("execute: flush io-streams"); @@ -485,7 +589,8 @@ public class ProcessHandler { * @return <code>true</code> if process correctly exited * (exit code doesn't affect to this result). */ - public boolean waitFor() { + public boolean waitFor() + { return waitFor(0); } @@ -507,50 +612,79 @@ public class ProcessHandler { * @return <code>true</code> if process correctly exited * (exit code doesn't affect to this result). */ - public boolean waitFor(long timeout) { - if (isFinished()) { + public boolean waitFor(long timeout) + { + return waitFor(timeout, true); + } + + private boolean waitFor(long timeout, boolean bKillProcessAfterTimeout) + { + if (isFinished()) + { return true; } - if (!isStarted()) { + if (!isStarted()) + { return false; } - if (timeout == 0) { - try { - proc.waitFor(); - } catch (InterruptedException e) { + if (timeout == 0) + { + try + { + m_aProcess.waitFor(); + } + catch (InterruptedException e) + { log.println("The process was interrupted: " + e); } isFinished = true; - try { - exitValue = proc.exitValue(); - } catch (IllegalThreadStateException e) { + try + { + exitValue = m_aProcess.exitValue(); } - } else { - try { - while (!isFinished && timeout > 0) { + catch (IllegalThreadStateException e) + { + } + } + else + { + try + { + while (!isFinished && timeout > 0) + { isFinished = true; Thread.sleep(1000); timeout -= 1000; - try { - exitValue = proc.exitValue(); // throws exception if not finished - } catch (IllegalThreadStateException e) { + try + { + exitValue = m_aProcess.exitValue(); // throws exception if not finished + } + catch (IllegalThreadStateException e) + { isFinished = false; } } - if (timeout < 0) { + if (timeout < 0) + { setTimedOut(true); log.println("The process has timed out!"); } - } catch (InterruptedException ex) { + } + catch (InterruptedException ex) + { log.println("The process was interrupted: " + ex); } } - if (!isFinished) { - log.println("Going to destroy the process!!"); - proc.destroy(); - log.println("Process has been destroyed!"); + if (bKillProcessAfterTimeout == true) + { + if (!isFinished) + { + log.println("Going to destroy the process!!"); + m_aProcess.destroy(); + log.println("Process has been destroyed!"); + } } // Removed as hung up in SDK test 'PathSettings' // try { @@ -561,12 +695,15 @@ public class ProcessHandler { return isFinished(); } - protected void flushInput() { - if (stdIn == null) { + protected void flushInput() + { + if (stdIn == null) + { return; } - synchronized (stdInBuff) { + synchronized(stdInBuff) + { stdIn.print(stdInBuff); stdIn.flush(); stdInBuff = ""; @@ -577,10 +714,14 @@ public class ProcessHandler { * Returns the text output by external command to stdout. * @return the text output by external command to stdout */ - public String getOutputText() { - if (stdout == null) { + public String getOutputText() + { + if (stdout == null) + { return ""; - } else { + } + else + { return stdout.getStringBuffer(); } } @@ -589,10 +730,14 @@ public class ProcessHandler { * Returns the text output by external command to stderr. * @return the text output by external command to stderr */ - public String getErrorText() { - if (stderr == null) { + public String getErrorText() + { + if (stderr == null) + { return ""; - } else { + } + else + { return stderr.getStringBuffer(); } } @@ -607,7 +752,8 @@ public class ProcessHandler { * and transfered to command when it will be started. * @param str */ - public void printInputText(String str) { + public void printInputText(String str) + { stdInBuff += str; flushInput(); } @@ -619,7 +765,8 @@ public class ProcessHandler { * @return <code>true</code> if the external command was * found and successfully started. */ - public boolean isStarted() { + public boolean isStarted() + { return isStarted; } @@ -630,7 +777,8 @@ public class ProcessHandler { * @return <code>true</code> if the command correctly starts, * exits and was not interrupted due to timeout. */ - public boolean isFinished() { + public boolean isFinished() + { return isFinished; } @@ -640,11 +788,15 @@ public class ProcessHandler { * @return exit code of command if it was finished, * -1 if not. */ - public int getExitCode() { - try { - exitValue = proc.exitValue(); - } catch (Exception e) { - //System.out.println("No ExitValue available"); + public int getExitCode() + { + try + { + exitValue = m_aProcess.exitValue(); + } + catch (Exception e) + { + //System.out.println("No ExitValue available"); } return exitValue; @@ -653,16 +805,22 @@ public class ProcessHandler { /** Causes the thread to sleep some time. * @param milliseconds */ - public static void shortWait(long milliseconds) { - try { + public static void shortWait(long milliseconds) + { + try + { Thread.sleep(milliseconds); - } catch (InterruptedException e) { + } + catch (InterruptedException e) + { System.out.println("While waiting :" + e); } } - private void dbg(String message) { - if (debug) { + private void dbg(String message) + { + if (debug) + { log.println(utils.getDateTime() + "PH." + message); } } diff --git a/qadevOOo/runner/lib/MultiMethodTest.java b/qadevOOo/runner/lib/MultiMethodTest.java index 2ebac0b3675d..d6e6833648fb 100644 --- a/qadevOOo/runner/lib/MultiMethodTest.java +++ b/qadevOOo/runner/lib/MultiMethodTest.java @@ -27,7 +27,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package lib; import java.io.PrintWriter; @@ -43,7 +42,6 @@ import share.DescEntry; import lib.TestParameters; import stats.Summarizer; - /** * The class supports method based interface tests development. * @@ -81,38 +79,34 @@ import stats.Summarizer; * * @see TestResult */ -public class MultiMethodTest { +public class MultiMethodTest +{ /** * Contains the TestEnvironment being tested, to allow for tests to access * it. */ protected TestEnvironment tEnv; - /** * Contains the TestParameters for the tests, to allow for tests to access * it. */ protected TestParameters tParam; - /** * Contains the Description for the test * it. */ protected DescEntry entry; - /** * Contains a writer to log an information about the interface testing, to * allows for tests to access it. */ protected PrintWriter log; - /** * Contains the TestResult instance for the interface test to collect * information about methods test. */ protected TestResult tRes; - /** * Contains names of the methods have been alreadycalled */ @@ -123,7 +117,8 @@ public class MultiMethodTest { * * @param tEnv the environment to dispose */ - public void disposeEnvironment( TestEnvironment tEnv ) { + public void disposeEnvironment(TestEnvironment tEnv) + { disposeEnvironment(); } @@ -132,10 +127,11 @@ public class MultiMethodTest { * * @see #disposeEnvironment(TestEnvironment) */ - public void disposeEnvironment() { + public void disposeEnvironment() + { tEnv.dispose(); TestCase tCase = tEnv.getTestCase(); - tCase.disposeTestEnvironment( tEnv, tParam ); + tCase.disposeTestEnvironment(tEnv, tParam); } /** @@ -147,92 +143,113 @@ public class MultiMethodTest { * called. After them, after() method is called, to allow cleaning up the * stuff initialized in before() and test methods. * + * @param entry the interface test state * @param tEnv the environment to test - * @param ifcState the interface test state * @param tParam the parameters of the test * * @see #before * @see #after */ - public TestResult run( DescEntry entry, TestEnvironment tEnv, TestParameters tParam ) { + public TestResult run(DescEntry entry, TestEnvironment tEnv, TestParameters tParam) + { log = (PrintWriter) entry.Logger; this.tEnv = tEnv; this.tParam = tParam; - this.log = log; + // this.log = log; this.entry = entry; this.tRes = new TestResult(); Class testedClass; - String ifcName = getInterfaceName(); - System.out.println("checking : "+ifcName); + // Some fake code for a self test. + // For normal test we must not be a "ifc.qadevooo._SelfTest" + if (! entry.entryName.equals("ifc.qadevooo._SelfTest")) + { + String ifcName = getInterfaceName(); + System.out.println("checking : " + ifcName); - // defining a name of the class corresponding to the tested interface - // or service - String testedClassName; + // defining a name of the class corresponding to the tested interface + // or service + String testedClassName; - testedClassName = getTestedClassName(); - - if (entry.EntryType.equals("service")) { - testedClassName = "com.sun.star.beans.XPropertySet"; - } + testedClassName = getTestedClassName(); - try { - testedClass = Class.forName(testedClassName); - } catch (ClassNotFoundException cnfE) { + if (entry.EntryType.equals("service")) + { + testedClassName = "com.sun.star.beans.XPropertySet"; + } - cnfE.printStackTrace(log); - log.println("could not find a class : " + getTestedClassName()); - return null; + try + { + testedClass = Class.forName(testedClassName); + } + catch (ClassNotFoundException cnfE) + { - } + cnfE.printStackTrace(log); + log.println("could not find a class : " + getTestedClassName()); + return null; - // quering the tested interface from the tested object - XInterface tCase = tEnv.getTestObject(); - Object oObj = UnoRuntime.queryInterface( - testedClass, tEnv.getTestObject()); - - if (oObj == null) { - if (entry.isOptional) { - Summarizer.summarizeDown( - entry,"Not supported but optional.OK"); - } else { - Summarizer.summarizeDown( - entry,"queryInterface returned null.FAILED"); - entry.ErrorMsg="queryInterface returned null"; - entry.hasErrorMsg=true; } - return null; - } + // quering the tested interface from the tested object + XInterface tCase = tEnv.getTestObject(); + Object oObj = UnoRuntime.queryInterface(testedClass, tEnv.getTestObject()); + + if (oObj == null) + { + if (entry.isOptional) + { + Summarizer.summarizeDown(entry, "Not supported but optional.OK"); + } + else + { + Summarizer.summarizeDown(entry, "queryInterface returned null.FAILED"); + entry.ErrorMsg = "queryInterface returned null"; + entry.hasErrorMsg = true; + } - //setting the field oObj - setField("oObj",oObj); + return null; + } + //setting the field oObj + setField("oObj", oObj); + } // to perform some stuff before all method tests - try { + try + { before(); - } catch (Exception e){ + } + catch (Exception e) + { setSubStates(e.toString()); return tRes; } // executing methods tests - for (int i=0;i<entry.SubEntryCount;i++) { - try { - executeMethod( entry.SubEntries[i].entryName ); - } catch (Exception e){ - log.println("Exception while checking: "+ - entry.SubEntries[i].entryName+" : "+e.getMessage()); + for (int i = 0; i < entry.SubEntryCount; i++) + { + DescEntry aSubEntry = entry.SubEntries[i]; + try + { + executeMethod(aSubEntry.entryName); + } + catch (Exception e) + { + log.println("Exception while checking: " + aSubEntry.entryName + " : " + e.getMessage()); } } // to perform some stuff after all method tests - try { + try + { after(); - } catch (Exception e){} + } + catch (Exception e) + { + } return tRes; } @@ -241,21 +258,23 @@ public class MultiMethodTest { * Is called before calling method tests, but after initialization. * Subclasses may override to perform actions before method tests. */ - protected void before() { + protected void before() throws Exception + { } /** * Is called after calling method tests. Subclasses may override * to perform actions after method tests. */ - protected void after() { + protected void after() + { } - /** * @return the name of the interface or the service tested. */ - protected String getTestedClassName() { + protected String getTestedClassName() + { String clsName = this.getClass().getName(); int firstDot = clsName.indexOf("."); @@ -263,13 +282,12 @@ public class MultiMethodTest { String append = "com.sun.star."; - if (entry.longName.indexOf("::drafts::com::")>-1) { + if (entry.longName.indexOf("::drafts::com::") > -1) + { append = "drafts.com.sun.star."; } - return append - + clsName.substring(firstDot + 1, lastDot + 1) - + clsName.substring(lastDot + 2); + return append + clsName.substring(firstDot + 1, lastDot + 1) + clsName.substring(lastDot + 2); } /** @@ -278,18 +296,22 @@ public class MultiMethodTest { * @param methName the method name to set status * @param methStatus the status to set to the method */ - protected void setStatus( String methName, Status methStatus ) { - tRes.tested( methName, methStatus ); + protected void setStatus(String methName, Status methStatus) + { + tRes.tested(methName, methStatus); } /** * sets the substates */ - protected void setSubStates(String msg) { - for (int k=0;k<entry.SubEntryCount;k++) { - entry.SubEntries[k].hasErrorMsg=true; - entry.SubEntries[k].ErrorMsg=msg; - if (entry.SubEntries[k].State.equals("UNKNOWN")) { + protected void setSubStates(String msg) + { + for (int k = 0; k < entry.SubEntryCount; k++) + { + entry.SubEntries[k].hasErrorMsg = true; + entry.SubEntries[k].ErrorMsg = msg; + if (entry.SubEntries[k].State.equals("UNKNOWN")) + { entry.SubEntries[k].State = msg; } } @@ -299,9 +321,12 @@ public class MultiMethodTest { /** * Checks if the <code>method</code> is optional in the service. */ - protected boolean isOptional(String method) { - for (int k=0;k<entry.SubEntryCount;k++) { - if (entry.SubEntries[k].entryName.equals(method)) { + protected boolean isOptional(String method) + { + for (int k = 0; k < entry.SubEntryCount; k++) + { + if (entry.SubEntries[k].entryName.equals(method)) + { return entry.SubEntries[k].isOptional; } } @@ -311,8 +336,9 @@ public class MultiMethodTest { /** * Checks if the <code>method</code> test has been already called. */ - protected boolean isCalled( String method ) { - return methCalled.contains( method ); + protected boolean isCalled(String method) + { + return methCalled.contains(method); } /** @@ -320,15 +346,16 @@ public class MultiMethodTest { * be called. The method checks this and if it is not called, calls it. * If the method is failed or skipped, it throws StatusException. */ - protected void requiredMethod(String method) { + protected void requiredMethod(String method) + { log.println("starting required method: " + method); - executeMethod( method ); - Status mtStatus = tRes.getStatusFor( method ); + executeMethod(method); + Status mtStatus = tRes.getStatusFor(method); - if ( mtStatus != null - && (!mtStatus.isPassed() || mtStatus.isFailed()) ) { - log.println( "! Required method " + method + " failed" ); - throw new StatusException( mtStatus ); + if (mtStatus != null && (!mtStatus.isPassed() || mtStatus.isFailed())) + { + log.println("! Required method " + method + " failed"); + throw new StatusException(mtStatus); } } @@ -336,10 +363,12 @@ public class MultiMethodTest { * Checks if the <code>method</code> was called, and if not, call it. * On contrary to requiredMethod(), he method doesn't check its status. */ - protected void executeMethod( String method ) { - if ( ! isCalled( method ) ) { - log.println("Execute: "+ method); - callMethod( method ); + protected void executeMethod(String method) + { + if (!isCalled(method)) + { + log.println("Execute: " + method); + callMethod(method); log.println(method + ": " + tRes.getStatusFor(method)); } } @@ -347,7 +376,8 @@ public class MultiMethodTest { /** * Just calls the <code>method</code> test. */ - protected void callMethod(String method) { + protected void callMethod(String method) + { methCalled.add(method); invokeTestMethod(getMethodFor(method), method); } @@ -359,31 +389,47 @@ public class MultiMethodTest { * @param meth the subclass' method to invoke * @param methName the name of the method */ - protected void invokeTestMethod(Method meth, String methName) { - if (meth == null) { - setStatus( methName, Status.skipped( false ) ); - } else { + protected void invokeTestMethod(Method meth, String methName) + { + if (meth == null) + { + setStatus(methName, Status.skipped(false)); + } + else + { Status stat; - try { + try + { meth.invoke(this, new Object[0]); return; - } catch (InvocationTargetException itE) { + } + catch (InvocationTargetException itE) + { Throwable t = itE.getTargetException(); - if ( t instanceof StatusException ) { - stat = ((StatusException)t).getStatus(); - } else { + if (t instanceof StatusException) + { + stat = ((StatusException) t).getStatus(); + } + else + { t.printStackTrace(log); stat = Status.exception(t); } - } catch (IllegalAccessException iaE) { + } + catch (IllegalAccessException iaE) + { iaE.printStackTrace(log); stat = Status.exception(iaE); - } catch (IllegalArgumentException iaE) { + } + catch (IllegalArgumentException iaE) + { iaE.printStackTrace(log); stat = Status.exception(iaE); - } catch (ClassCastException ccE) { + } + catch (ClassCastException ccE) + { ccE.printStackTrace(log); stat = Status.exception(ccE); } @@ -397,18 +443,23 @@ public class MultiMethodTest { * * @return the testing method, if found, <tt>null</tt> otherwise */ - protected Method getMethodFor(String method) { + protected Method getMethodFor(String method) + { String mName = "_" + method; - if (mName.endsWith("()")) { + if (mName.endsWith("()")) + { mName = mName.substring(0, mName.length() - 2); } final Class[] paramTypes = new Class[0]; - try { + try + { return this.getClass().getDeclaredMethod(mName, paramTypes); - } catch (NoSuchMethodException nsmE) { + } + catch (NoSuchMethodException nsmE) + { return null; } } @@ -416,38 +467,43 @@ public class MultiMethodTest { /** * @return the name of the interface tested */ - public String getInterfaceName() { + public String getInterfaceName() + { String clName = this.getClass().getName(); - return clName.substring( clName.lastIndexOf('.') + 1 ); + return clName.substring(clName.lastIndexOf('.') + 1); } - /** * Initializes <code>fieldName</code> of the subclass with * <code>value</code>. * * @return Status describing the result of the operation. */ - protected Status setField( String fieldName, Object value) { + protected Status setField(String fieldName, Object value) + { Field objField; - try { - objField = this.getClass().getField( fieldName ); + try + { + objField = this.getClass().getField(fieldName); } - catch( NoSuchFieldException nsfE ){ - return Status.exception( nsfE ); + catch (NoSuchFieldException nsfE) + { + return Status.exception(nsfE); } - try { - objField.set( this, value ); + try + { + objField.set(this, value); return Status.passed(true); } - catch( IllegalArgumentException iaE ){ - return Status.exception( iaE ); + catch (IllegalArgumentException iaE) + { + return Status.exception(iaE); } - catch( IllegalAccessException iaE ){ - return Status.exception( iaE ); + catch (IllegalAccessException iaE) + { + return Status.exception(iaE); } } - } diff --git a/qadevOOo/runner/lib/MultiPropertyTest.java b/qadevOOo/runner/lib/MultiPropertyTest.java index 909640cee6a0..cd6f5ce28218 100644 --- a/qadevOOo/runner/lib/MultiPropertyTest.java +++ b/qadevOOo/runner/lib/MultiPropertyTest.java @@ -27,7 +27,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package lib; import com.sun.star.beans.Property; @@ -71,7 +70,9 @@ import com.sun.star.uno.Type; * @see #compare * @see #toString(Object) */ -public class MultiPropertyTest extends MultiMethodTest { +public class MultiPropertyTest extends MultiMethodTest +{ + /** * Contains a XPropertySet interface of the tested object. Is initialized * in MultiMethodTest code. @@ -82,18 +83,23 @@ public class MultiPropertyTest extends MultiMethodTest { /** * Overrides super.before() to check the service is supported by the object. */ - protected void before() { - XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface( + protected void before() + { + XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface( XServiceInfo.class, oObj); optionalService = entry.isOptional; String theService = getTestedClassName(); - if (xInfo != null && !xInfo.supportsService(theService)) { - log.println("Service "+theService+" not available"); - if (optionalService) { + if (xInfo != null && !xInfo.supportsService(theService)) + { + log.println("Service " + theService + " not available"); + if (optionalService) + { log.println("This is OK since it is optional"); - } else { + } + else + { Status.failed(theService + " is not supported"); } } @@ -107,10 +113,14 @@ public class MultiPropertyTest extends MultiMethodTest { * * @see #MultiMethodTest.invokeTestMethod() */ - protected void invokeTestMethod(Method meth, String methName) { - if (meth != null) { + protected void invokeTestMethod(Method meth, String methName) + { + if (meth != null) + { super.invokeTestMethod(meth, methName); - } else { + } + else + { testProperty(methName); } } @@ -122,7 +132,9 @@ public class MultiPropertyTest extends MultiMethodTest { * each property separately, by providing subclass of PropertyTester * and passing it to testProperty(String, PropertyTester method). */ - public class PropertyTester { + public class PropertyTester + { + /** * The method defines the whole process of testing propName * property. @@ -140,37 +152,46 @@ public class MultiPropertyTest extends MultiMethodTest { * @result - adds the result of testing propName property to * MultiMethodTest.tRes. */ - protected void testProperty(String propName) { + protected void testProperty(String propName) + { XPropertySetInfo info = oObj.getPropertySetInfo(); - if (!info.hasPropertyByName(propName)) { - if (isOptional(propName) || optionalService) { - // skipping optional property test - log.println("Property '" + propName - + "' is optional and not supported"); - tRes.tested(propName,true); - return; - } else { - // cannot test the property - log.println("Tested XPropertySet does not contain'" - + propName + "' property"); - tRes.tested(propName, false); - return; + if (info != null) + { + if (!info.hasPropertyByName(propName)) + { + if (isOptional(propName) || optionalService) + { + // skipping optional property test + log.println("Property '" + propName + "' is optional and not supported"); + tRes.tested(propName, true); + return; + } + else + { + // cannot test the property + log.println("Tested XPropertySet does not contain'" + propName + "' property"); + tRes.tested(propName, false); + return; + } } } - try { + try + { Object oldValue = oObj.getPropertyValue(propName); Object newValue; // trying to create new value - try { + try + { newValue = getNewValue(propName, oldValue); - } catch (java.lang.IllegalArgumentException e) { + } + catch (java.lang.IllegalArgumentException e) + { // skipping test since new value is not available - Status.failed("Cannot create new value for '" - + propName + " : " + e.getMessage()); + Status.failed("Cannot create new value for '" + propName + " : " + e.getMessage()); return; } @@ -178,20 +199,31 @@ public class MultiPropertyTest extends MultiMethodTest { // to pass it to checkResult method Exception exception = null; - try { + try + { log.println("try to set:"); log.println("old = " + toString(oldValue)); log.println("new = " + toString(newValue)); oObj.setPropertyValue(propName, newValue); - } catch(IllegalArgumentException e) { + } + catch (IllegalArgumentException e) + { exception = e; - } catch(PropertyVetoException e) { + } + catch (PropertyVetoException e) + { exception = e; - } catch(WrappedTargetException e) { + } + catch (WrappedTargetException e) + { exception = e; - } catch(UnknownPropertyException e) { + } + catch (UnknownPropertyException e) + { exception = e; - } catch(RuntimeException e) { + } + catch (RuntimeException e) + { exception = e; } @@ -200,7 +232,9 @@ public class MultiPropertyTest extends MultiMethodTest { // checking results checkResult(propName, oldValue, newValue, resValue, exception); - } catch (Exception e) { + } + catch (Exception e) + { log.println("Exception occured while testing property '" + propName + "'"); e.printStackTrace(log); tRes.tested(propName, false); @@ -234,130 +268,175 @@ public class MultiPropertyTest extends MultiMethodTest { */ protected void checkResult(String propName, Object oldValue, Object newValue, Object resValue, Exception exception) - throws Exception { + throws Exception + { XPropertySetInfo info = oObj.getPropertySetInfo(); + if (info == null) + { + log.println("Can't get XPropertySetInfo for property " + propName); + tRes.tested(propName, false); + return; + } Property prop = info.getPropertyByName(propName); short attr = prop.Attributes; - boolean readOnly = (prop.Attributes - & PropertyAttribute.READONLY) != 0; - boolean maybeVoid = (prop.Attributes - & PropertyAttribute.MAYBEVOID) != 0; + boolean readOnly = (prop.Attributes & PropertyAttribute.READONLY) != 0; + boolean maybeVoid = (prop.Attributes & PropertyAttribute.MAYBEVOID) != 0; //check get-set methods - if (maybeVoid) log.println("Property "+propName+" is void"); - if (readOnly) log.println("Property "+propName+" is readOnly"); - if (util.utils.isVoid(oldValue) && !maybeVoid) { - log.println(propName - + " is void, but it's not MAYBEVOID"); + if (maybeVoid) + { + log.println("Property " + propName + " is void"); + } + if (readOnly) + { + log.println("Property " + propName + " is readOnly"); + } + if (util.utils.isVoid(oldValue) && !maybeVoid) + { + log.println(propName + " is void, but it's not MAYBEVOID"); tRes.tested(propName, false); - } else if (oldValue == null ) { - log.println(propName - + " has null value, and therefore can't be changed"); + } + else if (oldValue == null) + { + log.println(propName + " has null value, and therefore can't be changed"); tRes.tested(propName, true); - } else if (readOnly) { + } + else if (readOnly) + { // check if exception was thrown - if (exception != null) { - if (exception instanceof PropertyVetoException) { + if (exception != null) + { + if (exception instanceof PropertyVetoException) + { // the change of read only prohibited - OK log.println("Property is ReadOnly and wasn't changed"); log.println("Property '" + propName + "' OK"); tRes.tested(propName, true); - } else if (exception instanceof IllegalArgumentException) { + } + else if (exception instanceof IllegalArgumentException) + { // the change of read only prohibited - OK log.println("Property is ReadOnly and wasn't changed"); log.println("Property '" + propName + "' OK"); tRes.tested(propName, true); - } else if (exception instanceof UnknownPropertyException) { + } + else if (exception instanceof UnknownPropertyException) + { // the change of read only prohibited - OK log.println("Property is ReadOnly and wasn't changed"); log.println("Property '" + propName + "' OK"); tRes.tested(propName, true); - }else if (exception instanceof RuntimeException) { + } + else if (exception instanceof RuntimeException) + { // the change of read only prohibited - OK log.println("Property is ReadOnly and wasn't changed"); log.println("Property '" + propName + "' OK"); tRes.tested(propName, true); - } else { + } + else + { throw exception; } - } else { + } + else + { // if no exception - check that value // has not changed - if (!compare(resValue, oldValue)) { - log.println("Read only property '" - + propName + "' has changed"); - try { - if (!util.utils.isVoid(oldValue) - && oldValue instanceof Any) { - oldValue = AnyConverter.toObject - (new Type(((Any)oldValue).getClass()),oldValue); + if (!compare(resValue, oldValue)) + { + log.println("Read only property '" + propName + "' has changed"); + try + { + if (!util.utils.isVoid(oldValue) && oldValue instanceof Any) + { + oldValue = AnyConverter.toObject(new Type(((Any) oldValue).getClass()), oldValue); } // log.println("old = " + toString(oldValue)); // log.println("new = " + toString(newValue)); log.println("result = " + toString(resValue)); - } catch(com.sun.star.lang.IllegalArgumentException iae) { + } + catch (com.sun.star.lang.IllegalArgumentException iae) + { log.println("NOTIFY: this property needs further investigations."); log.println("\t The type seems to be an Any with value of NULL."); log.println("\t Maybe the property should get it's own test method."); } tRes.tested(propName, false); - } else { - log.println("Read only property '" - + propName + "' hasn't changed"); + } + else + { + log.println("Read only property '" + propName + "' hasn't changed"); log.println("Property '" + propName + "' OK"); tRes.tested(propName, true); } } - } else { - if (exception == null) { + } + else + { + if (exception == null) + { // if no exception thrown // check that the new value is set - if ((!compare(resValue, newValue)) || (compare(resValue, oldValue))) { - log.println("Value for '" + propName - + "' hasn't changed as expected"); - try { - if (!util.utils.isVoid(oldValue) - && oldValue instanceof Any) { - oldValue = AnyConverter.toObject - (new Type(((Any)oldValue).getClass()),oldValue); + if ((!compare(resValue, newValue)) || (compare(resValue, oldValue))) + { + log.println("Value for '" + propName + "' hasn't changed as expected"); + try + { + if (!util.utils.isVoid(oldValue) && oldValue instanceof Any) + { + oldValue = AnyConverter.toObject(new Type(((Any) oldValue).getClass()), oldValue); } // log.println("old = " + toString(oldValue)); // log.println("new = " + toString(newValue)); log.println("result = " + toString(resValue)); - } catch(com.sun.star.lang.IllegalArgumentException iae) { + } + catch (com.sun.star.lang.IllegalArgumentException iae) + { log.println("NOTIFY: this property needs further investigations."); log.println("\t The type seems to be an Any with value of NULL."); log.println("\t Maybe the property should get it's own test method."); } - if (resValue != null ) { - if ( (!compare(resValue, oldValue)) || (!resValue.equals(oldValue))) { + if (resValue != null) + { + if ((!compare(resValue, oldValue)) || (!resValue.equals(oldValue))) + { log.println("But it has changed."); tRes.tested(propName, true); - } else { + } + else + { tRes.tested(propName, false); } } - else { + else + { tRes.tested(propName, false); } //tRes.tested(propName, false); - } else { + } + else + { log.println("Property '" + propName + "' OK"); - try { - if (!util.utils.isVoid(oldValue) - && oldValue instanceof Any) { - oldValue = AnyConverter.toObject - (new Type(((Any)oldValue).getClass()),oldValue); + try + { + if (!util.utils.isVoid(oldValue) && oldValue instanceof Any) + { + oldValue = AnyConverter.toObject(new Type(((Any) oldValue).getClass()), oldValue); } // log.println("old = " + toString(oldValue)); // log.println("new = " + toString(newValue)); log.println("result = " + toString(resValue)); - } catch(com.sun.star.lang.IllegalArgumentException iae) { + } + catch (com.sun.star.lang.IllegalArgumentException iae) + { } tRes.tested(propName, true); } - } else { + } + else + { throw exception; } } @@ -371,7 +450,8 @@ public class MultiPropertyTest extends MultiMethodTest { * when oldValue is null. */ protected Object getNewValue(String propName, Object oldValue) - throws java.lang.IllegalArgumentException { + throws java.lang.IllegalArgumentException + { return ValueChanger.changePValue(oldValue); } @@ -382,7 +462,8 @@ public class MultiPropertyTest extends MultiMethodTest { * which is not apropriate in some cases(e.g., structs with equals * not overridden). */ - protected boolean compare(Object obj1, Object obj2) { + protected boolean compare(Object obj1, Object obj2) + { return callCompare(obj1, obj2); } @@ -391,7 +472,8 @@ public class MultiPropertyTest extends MultiMethodTest { * MultipropertyTest.toString(Object), but subclasses can override * to change the behaviour. */ - protected String toString(Object obj) { + protected String toString(Object obj) + { return callToString(obj); } } @@ -402,9 +484,11 @@ public class MultiPropertyTest extends MultiMethodTest { * class returns one of these two values depending on the * old value, so new value is not equal to old value. */ - public class PropertyValueSwitcher extends PropertyTester { - Object val1 = null ; - Object val2 = null ; + public class PropertyValueSwitcher extends PropertyTester + { + + Object val1 = null; + Object val2 = null; /** * Constructs a property tester with two different values @@ -415,9 +499,10 @@ public class MultiPropertyTest extends MultiMethodTest { * @param val1 Not <code>null</code> value for the property * tested which differs from the first value. */ - public PropertyValueSwitcher(Object val1, Object val2) { - this.val1 = val1 ; - this.val2 = val2 ; + public PropertyValueSwitcher(Object val1, Object val2) + { + this.val1 = val1; + this.val2 = val2; } /** @@ -427,18 +512,24 @@ public class MultiPropertyTest extends MultiMethodTest { * @return The second value if old value is equal to the first * one, the first value otherwise. */ - protected Object getNewValue(String propName, Object old) { + protected Object getNewValue(String propName, Object old) + { if (ValueComparer.equalValue(val1, old)) - return val2 ; + { + return val2; + } else - return val1 ; + { + return val1; + } } } /** * The method performs testing of propName property using propTester. */ - protected void testProperty(String propName, PropertyTester propTester) { + protected void testProperty(String propName, PropertyTester propTester) + { propTester.testProperty(propName); } @@ -446,7 +537,8 @@ public class MultiPropertyTest extends MultiMethodTest { * The method performs testing of propName property. It uses PropertyTester * instance for testing. */ - protected void testProperty(String propName) { + protected void testProperty(String propName) + { testProperty(propName, new PropertyTester()); } @@ -456,7 +548,8 @@ public class MultiPropertyTest extends MultiMethodTest { * * @see #PropertyValueSwitcher */ - protected void testProperty(String propName, Object val1, Object val2) { + protected void testProperty(String propName, Object val1, Object val2) + { testProperty(propName, new PropertyValueSwitcher(val1, val2)); } @@ -464,14 +557,16 @@ public class MultiPropertyTest extends MultiMethodTest { * The method just calls compare. This is a workaround to CodeWarrior's * compiler bug. */ - private boolean callCompare(Object obj1, Object obj2) { + private boolean callCompare(Object obj1, Object obj2) + { return compare(obj1, obj2); } /** * Compares two object. In the implementation calls obj1.equals(obj2). */ - protected boolean compare(Object obj1, Object obj2) { + protected boolean compare(Object obj1, Object obj2) + { return ValueComparer.equalValue(obj1, obj2); } @@ -479,7 +574,8 @@ public class MultiPropertyTest extends MultiMethodTest { * The method just calls toString. This is a workaround to * CodeWarrior's compiler bug. */ - private String callToString(Object obj) { + private String callToString(Object obj) + { return toString(obj); } @@ -487,7 +583,8 @@ public class MultiPropertyTest extends MultiMethodTest { * Gets string representation of the obj. In the implementation * returns obj.toString(). */ - protected String toString(Object obj) { + protected String toString(Object obj) + { return obj == null ? "null" : obj.toString(); } -}
\ No newline at end of file +} diff --git a/qadevOOo/runner/lib/TestParameters.java b/qadevOOo/runner/lib/TestParameters.java index c87a5b21f263..42f64331e661 100644 --- a/qadevOOo/runner/lib/TestParameters.java +++ b/qadevOOo/runner/lib/TestParameters.java @@ -32,6 +32,8 @@ package lib; import java.util.Hashtable; import util.PropertyName; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.XComponentContext; //import com.sun.star.lang.XMultiServiceFactory; @@ -159,13 +161,13 @@ public class TestParameters extends Hashtable { * This parameter contains the timeout used<br> * by the watcher */ - public Integer TimeOut = new Integer(30000); + public Integer TimeOut = new Integer(3000000); /* * This parameter contains the timeout used<br> * by the complex tests */ - public Integer ThreadTimeOut = new Integer(30000); + public Integer ThreadTimeOut = new Integer(3000000); /* * This parameter contains the time which the office could use to close for @@ -256,8 +258,11 @@ public class TestParameters extends Hashtable { public TestParameters() { //fill the propertyset String user = System.getProperty("user.name"); - if ( user != null) { - ConnectionString = "pipe,name=" + user; + if ( user != null) + { + String PipeConnectionString = "pipe,name=" + user; + put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString); + put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE); } put(PropertyName.CONNECTION_STRING,ConnectionString); put(PropertyName.TEST_BASE,TestBase); @@ -292,6 +297,24 @@ public class TestParameters extends Hashtable { return ret; } + public XComponentContext getComponentContext() { + Object context = get( "ComponentContext" ); + if ( context == null ) + { + XPropertySet factoryProps = (XPropertySet)com.sun.star.uno.UnoRuntime.queryInterface( + XPropertySet.class, getMSF() ); + try + { + context = com.sun.star.uno.UnoRuntime.queryInterface( + XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) ); + put( "ComponentContext", context ); + } + catch( com.sun.star.beans.UnknownPropertyException e ) { } + catch( com.sun.star.lang.WrappedTargetException e ) { } + } + return (XComponentContext)context; + } + /** * Convert the system dependent operating system name to a name according * to OOo rules. diff --git a/qadevOOo/runner/makefile.mk b/qadevOOo/runner/makefile.mk index b3afff1ba9ce..986111bd5bad 100644 --- a/qadevOOo/runner/makefile.mk +++ b/qadevOOo/runner/makefile.mk @@ -44,7 +44,7 @@ JARCOMMANDS_TESTS = $(foreach,i,$(SUBDIRS_TESTS) -C $(CLASSDIR) $i) JARCOMMANDS_RUNNER = $(foreach,i,$(SUBDIRS_RUNNER) -C $(CLASSDIR) $i) # --- Targets ------------------------------------------------------ -.IF "$(SOLAR_JAVA)"=="TRUE" +.IF "$(SOLAR_JAVA)"=="TRUE" && "$(L10N_framework)"=="" OWNJAR: ALLTAR diff --git a/qadevOOo/runner/org/openoffice/Runner.java b/qadevOOo/runner/org/openoffice/Runner.java index 305700b08ff6..473f01a63b97 100644 --- a/qadevOOo/runner/org/openoffice/Runner.java +++ b/qadevOOo/runner/org/openoffice/Runner.java @@ -27,16 +27,17 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package org.openoffice; +import java.util.Enumeration; +import java.util.Properties; +import java.util.StringTokenizer; import lib.TestParameters; import util.DynamicClassLoader; import base.TestBase; import helper.ClParser; import helper.CfgParser; - /** * The main class, will call ClParser and CfgParser to <br> * fill the TestParameters.<br> @@ -44,37 +45,40 @@ import helper.CfgParser; */ public class Runner { + private static long m_nStartTime; - private static long getStartTime() + public static long getRunnerStartTime() { return m_nStartTime; } /* - simple helper functions to start/stop a timer, to know how long a process need in milliseconds + simple helper functions to start/stop a timer, to know how long a process need in milliseconds */ + private static long getTime() - { - return System.currentTimeMillis(); - } + { + return System.currentTimeMillis(); + } + private static void setStartTime(long _nStartTime) - { - m_nStartTime = _nStartTime; - } + { + m_nStartTime = _nStartTime; + } /* - return the time, which is done until last startTime() + return the time, which is done until last startTime() */ - private static long meanTime(long _nCurrentTimer) + public static long meanTime(long _nCurrentTimer) + { + if (_nCurrentTimer == 0) { - if (_nCurrentTimer == 0) - { - System.out.println("Forgotten to initialise a start timer?"); - return 0; - } - long nMeanTime = getTime(); - return nMeanTime - _nCurrentTimer; + System.out.println("Forgotten to initialise a start timer?"); + return 0; } + long nMeanTime = getTime(); + return nMeanTime - _nCurrentTimer; + } private static String beautifyTime(long _nTime) { @@ -82,15 +86,108 @@ public class Runner long min = (_nTime / (60 * 1000)) % 60; long hour = _nTime / (60 * 60 * 1000); StringBuffer aTime = new StringBuffer(); - aTime.append(helper.StringHelper.createValueString((int)hour, 2)). - append(':'). - append(helper.StringHelper.createValueString((int)min, 2)). - append(':'). - append(helper.StringHelper.createValueString((int)sec, 2)); + aTime.append(helper.StringHelper.createValueString((int) hour, 2)). + append(':'). + append(helper.StringHelper.createValueString((int) min, 2)). + append(':'). + append(helper.StringHelper.createValueString((int) sec, 2)); return aTime.toString(); } - public static void main(String[] args) { + /** + Helper to check if there are problems with Cygwin Path variables. + */ + private static boolean checkVariableForCygwin(String _sVariable) + { + if (_sVariable == null) + { + return false; + } + if (_sVariable.startsWith("/cygdrive")) + { + return true; + } + return false; + } + + private static boolean checkPathVariable(String _sPath, String delim) + { + String sPath = System.getProperty(_sPath); + if (sPath != null) + { + StringTokenizer aTokenEnum = new StringTokenizer(sPath, delim); + while (aTokenEnum.hasMoreElements()) + { + String sToken = (String) aTokenEnum.nextElement(); + if (checkVariableForCygwin(sToken)) + { + System.err.println("ERROR: OOoRunner detect cygwin path in '" + _sPath + "'"); + return true; + } + } + } + return false; + } + + private static void checkAllVariablesForCygwinPath(TestParameters _aParams) + { + // ----- check all System.getProperty(key) variables ----- + String sOsName = System.getProperty("os.name"); + if (!sOsName.toLowerCase().startsWith("windows")) + { + // we need to check only on windows + return; + } + + Properties aProps = System.getProperties(); + Enumeration aEnum = aProps.propertyNames(); + // Enumeration aEnum = aProps.elements(); // these are only the values + boolean bEmergencyStop = false; + + while (aEnum.hasMoreElements()) + { + String sKey = (String) aEnum.nextElement(); + String sValue = System.getProperty(sKey); + + if (checkVariableForCygwin(sValue)) + { + System.err.println("ERROR: OOoRunner detect cygwin path in '" + sKey + ":=" + sValue + "'"); + bEmergencyStop = true; + } + } + + // ----- check path variables separatly ----- + String sDelim = System.getProperty("path.separator"); + bEmergencyStop |= checkPathVariable("java.library.path", sDelim); + bEmergencyStop |= checkPathVariable("java.class.path", sDelim); + bEmergencyStop |= checkPathVariable("sun.boot.class.path", sDelim); + + // ----- check all TestParameters ----- + aEnum = _aParams.keys(); + while (aEnum.hasMoreElements()) + { + String sKey = (String) aEnum.nextElement(); + if (_aParams.get(sKey) instanceof String) + { + String sValue = (String) _aParams.get(sKey); + + if (checkVariableForCygwin(sValue)) + { + System.err.println("ERROR: OOoRunner detect cygwin path in '" + sKey + ":=" + sValue + "'"); + bEmergencyStop = true; + } + } + } + + if (bEmergencyStop) + { + System.exit(-1); + } + } + + public static void main(String[] args) + { + System.out.println("OOoRunner Main() version from 20090825 (yyyymmdd)"); setStartTime(getTime()); @@ -122,11 +219,12 @@ public class Runner //parse the commandline arguments // TODO: no right error message, if no parameter given! - cli.getCommandLineParameter(param,args); + cli.getCommandLineParameter(param, args); Object tj = param.get("TestJob"); - if (tj==null) { + if (tj == null) + { System.out.println("=========================================================================="); System.out.println("No TestJob given, please make sure that you "); System.out.println("a.) called the OOoRunner with the paramter -o <job> or -sce <scenarioFile>"); @@ -136,25 +234,26 @@ public class Runner System.exit(-1); } - System.out.println("TestJob: "+tj); + System.out.println("TestJob: " + tj); + String sName = "base." + (String) param.get("TestBase"); + TestBase toExecute = (TestBase) dcl.getInstance(sName); - TestBase toExecute = (TestBase) dcl.getInstance("base."+ - (String)param.get("TestBase")); + checkAllVariablesForCygwinPath(param); boolean worked = toExecute.executeTest(param); - long nTime = meanTime(getStartTime()); + long nTime = meanTime(getRunnerStartTime()); String sBeautifyTime = beautifyTime(nTime); System.out.println("Job run took: " + nTime + "ms " + " [" + sBeautifyTime + "]"); if (!worked) { - System.out.println("Job "+param.get("TestJob")+" failed"); + System.out.println("Job " + param.get("TestJob") + " failed"); System.exit(-1); } else { - System.out.println("Job "+param.get("TestJob")+" done"); + System.out.println("Job " + param.get("TestJob") + " done"); System.exit(0); } } diff --git a/qadevOOo/runner/share/DescGetter.java b/qadevOOo/runner/share/DescGetter.java index 3b038e5ab090..dc6ac351ccb1 100644 --- a/qadevOOo/runner/share/DescGetter.java +++ b/qadevOOo/runner/share/DescGetter.java @@ -36,62 +36,76 @@ import java.util.StringTokenizer; import java.util.Vector; - /** * * Base Interface to get a description for a given TestJob * */ -public abstract class DescGetter { +public abstract class DescGetter +{ + public abstract DescEntry[] getDescriptionFor(String entry, - String DescPath, - boolean debug); + String DescPath, + boolean debug); protected abstract DescEntry getDescriptionForSingleJob(String job, - String descPath, - boolean debug); + String descPath, + boolean debug); protected abstract String[] createScenario(String descPath, String job, - boolean debug); + boolean debug); protected DescEntry[] getScenario(String url, String descPath, - boolean debug) { + boolean debug) + { Vector entryList = new Vector(); String line = ""; BufferedReader scenario = null; DescEntry[] entries = null; - try { + try + { scenario = new BufferedReader(new FileReader(url)); - } catch (java.io.FileNotFoundException fnfe) { + } + catch (java.io.FileNotFoundException fnfe) + { System.out.println("Couldn't find file " + url); return entries; } - while (line != null) { - try { - if (line.startsWith("-o")) { + while (line != null) + { + try + { + if (line.startsWith("-o")) + { String job = line.substring(3, line.length()).trim(); - DescEntry aEntry ; + DescEntry aEntry; // special in case several Interfaces are given comma separated - if (job.indexOf(",") < 0) { + if (job.indexOf(",") < 0) + { aEntry = getDescriptionForSingleJob(job, descPath, - debug); - } else { + debug); + } + else + { ArrayList subs = getSubInterfaces(job); String partjob = job.substring(0, job.indexOf(",")).trim(); aEntry = getDescriptionForSingleJob(partjob, descPath, - debug); + debug); - if (aEntry != null) { - for (int i = 0; i < aEntry.SubEntryCount; i++) { + if (aEntry != null) + { + for (int i = 0; i < aEntry.SubEntryCount; i++) + { String subEntry = aEntry.SubEntries[i].longName; int cpLength = aEntry.longName.length(); subEntry = subEntry.substring(cpLength + 2, - subEntry.length()); + subEntry.length()); - if (subs.contains(subEntry)) { + if (subs.contains(subEntry)) + { aEntry.SubEntries[i].isToTest = true; } } @@ -101,63 +115,82 @@ public abstract class DescGetter { // line.substring(3).trim(), descPath, // debug); if (aEntry != null) + { entryList.add(aEntry); - } else if (line.startsWith("-sce")) { + } + } + else if (line.startsWith("-sce")) + { DescEntry[] subs = getScenario(line.substring(5, - line.length()) - .trim(), descPath, - debug); + line.length()).trim(), descPath, + debug); - for (int i = 0; i < subs.length; i++) { + for (int i = 0; i < subs.length; i++) + { entryList.add(subs[i]); } - } else if (line.startsWith("-p")) { + } + else if (line.startsWith("-p")) + { String[] perModule = createScenario(descPath, - line.substring(3) - .trim(), debug); + line.substring(3).trim(), debug); - for (int i = 0; i < perModule.length; i++) { + for (int i = 0; i < perModule.length; i++) + { DescEntry aEntry = getDescriptionForSingleJob( - perModule[i].substring(3) - .trim(), - descPath, debug); + perModule[i].substring(3).trim(), + descPath, debug); if (aEntry != null) + { entryList.add(aEntry); + } } } line = scenario.readLine(); - } catch (java.io.IOException ioe) { - if (debug) { + } + catch (java.io.IOException ioe) + { + if (debug) + { System.out.println("Exception while reading scenario"); } } } - try { + try + { scenario.close(); - } catch (java.io.IOException ioe) { - if (debug) { + } + catch (java.io.IOException ioe) + { + if (debug) + { System.out.println("Exception while closeing scenario"); } } if (entryList.size() == 0) + { return null; + } entries = new DescEntry[entryList.size()]; entries = (DescEntry[]) entryList.toArray(entries); return entries; } - protected ArrayList getSubInterfaces(String job) { + protected ArrayList getSubInterfaces(String job) + { ArrayList namesList = new ArrayList(); StringTokenizer st = new StringTokenizer(job, ","); - for (int i = 0; st.hasMoreTokens(); i++) { + for (int i = 0; st.hasMoreTokens(); i++) + { String token = st.nextToken(); - if (token.indexOf(".") < 0) { + if (token.indexOf(".") < 0) + { namesList.add(token); } } diff --git a/qadevOOo/runner/util/DesktopTools.java b/qadevOOo/runner/util/DesktopTools.java index 2e34e4de49d3..bee3bc8f9bd1 100644 --- a/qadevOOo/runner/util/DesktopTools.java +++ b/qadevOOo/runner/util/DesktopTools.java @@ -56,23 +56,25 @@ import helper.ConfigHelper; import java.util.Vector; import lib.StatusException; - /** * contains helper methods for the Desktop */ -public class DesktopTools { +public class DesktopTools +{ + /** * Queries the XComponentLoader * * @param xMSF the MultiServiceFactory * @return the gained XComponentLoader - */ - public static XComponentLoader getCLoader(XMultiServiceFactory xMSF) { + */ + public static XComponentLoader getCLoader(XMultiServiceFactory xMSF) + { XDesktop oDesktop = (XDesktop) UnoRuntime.queryInterface( - XDesktop.class, createDesktop(xMSF)); + XDesktop.class, createDesktop(xMSF)); XComponentLoader oCLoader = (XComponentLoader) UnoRuntime.queryInterface( - XComponentLoader.class, oDesktop); + XComponentLoader.class, oDesktop); return oCLoader; } // finish getCLoader @@ -82,13 +84,17 @@ public class DesktopTools { * * @param xMSF the MultiServiceFactory * @return the gained Object - */ - public static Object createDesktop(XMultiServiceFactory xMSF) { + */ + public static Object createDesktop(XMultiServiceFactory xMSF) + { Object oInterface; - try { + try + { oInterface = xMSF.createInstance("com.sun.star.comp.framework.Desktop"); - } catch (com.sun.star.uno.Exception e) { + } + catch (com.sun.star.uno.Exception e) + { throw new IllegalArgumentException("Desktop Service not available"); } @@ -100,9 +106,10 @@ public class DesktopTools { * @param xMSF the XMultiServiceFactory * @return XEnumeration of all components on the desktop */ - public static XEnumeration getAllComponents(XMultiServiceFactory xMSF) { + public static XEnumeration getAllComponents(XMultiServiceFactory xMSF) + { XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface( - XDesktop.class, createDesktop(xMSF)); + XDesktop.class, createDesktop(xMSF)); return xDesktop.getComponents().createEnumeration(); } @@ -111,9 +118,10 @@ public class DesktopTools { * @param xMSF the XMultiServiceFactory * @return XComponent of the current component on the desktop */ - public static XComponent getCurrentComponent(XMultiServiceFactory xMSF) { + public static XComponent getCurrentComponent(XMultiServiceFactory xMSF) + { XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface( - XDesktop.class, createDesktop(xMSF)); + XDesktop.class, createDesktop(xMSF)); return xDesktop.getCurrentComponent(); } @@ -122,9 +130,10 @@ public class DesktopTools { * @param xMSF the XMultiServiceFactory * @return XComponent of the current component on the desktop */ - public static XFrame getCurrentFrame(XMultiServiceFactory xMSF) { + public static XFrame getCurrentFrame(XMultiServiceFactory xMSF) + { XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface( - XDesktop.class, createDesktop(xMSF)); + XDesktop.class, createDesktop(xMSF)); return xDesktop.getCurrentFrame(); } @@ -138,22 +147,33 @@ public class DesktopTools { * @param xMSF the XMultiSerivceFactory * @return returns an array of all open documents */ - public static Object[] getAllOpenDocuments(XMultiServiceFactory xMSF) { + public static Object[] getAllOpenDocuments(XMultiServiceFactory xMSF) + { Vector components = new Vector(); XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface( - XDesktop.class, createDesktop(xMSF)); + XDesktop.class, createDesktop(xMSF)); XEnumeration allComp = getAllComponents(xMSF); - while (allComp.hasMoreElements()){ - try{ + while (allComp.hasMoreElements()) + { + try + { XComponent xComponent = (XComponent) UnoRuntime.queryInterface( - XComponent.class, allComp.nextElement()); + XComponent.class, allComp.nextElement()); - if (getDocumentType(xComponent) != null) components.add(xComponent); + if (getDocumentType(xComponent) != null) + { + components.add(xComponent); + } - } catch (com.sun.star.container.NoSuchElementException e) { - } catch ( com.sun.star.lang.WrappedTargetException e) {} + } + catch (com.sun.star.container.NoSuchElementException e) + { + } + catch (com.sun.star.lang.WrappedTargetException e) + { + } } return components.toArray(); } @@ -170,28 +190,41 @@ public class DesktopTools { * </ul> * or <CODE>null</CODE> */ - public static String getDocumentType(XComponent xComponent) { - XServiceInfo sInfo = (XServiceInfo)UnoRuntime.queryInterface( + public static String getDocumentType(XComponent xComponent) + { + XServiceInfo sInfo = (XServiceInfo) UnoRuntime.queryInterface( XServiceInfo.class, xComponent); - if (sInfo == null) { + if (sInfo == null) + { return ""; - } else if (sInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) { + } + else if (sInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) + { return "scalc"; - } else if (sInfo.supportsService("com.sun.star.text.TextDocument")) { + } + else if (sInfo.supportsService("com.sun.star.text.TextDocument")) + { return "swriter"; - } else if (sInfo.supportsService("com.sun.star.drawing.DrawingDocument")) { + } + else if (sInfo.supportsService("com.sun.star.drawing.DrawingDocument")) + { return "sdraw"; - } else if (sInfo.supportsService("com.sun.star.presentation.PresentationDocument")) { + } + else if (sInfo.supportsService("com.sun.star.presentation.PresentationDocument")) + { return "simpress"; - } else if (sInfo.supportsService("com.sun.star.formula.FormulaProperties")) { + } + else if (sInfo.supportsService("com.sun.star.formula.FormulaProperties")) + { return "smath"; - } else { + } + else + { return null; } } - /** * Opens a new document of a given kind * with arguments @@ -208,14 +241,17 @@ public class DesktopTools { * @param xMSF the MultiServiceFactory */ public static XComponent openNewDoc(XMultiServiceFactory xMSF, String kind, - PropertyValue[] Args) { + PropertyValue[] Args) + { XComponent oDoc = null; - try { - oDoc = getCLoader(xMSF) - .loadComponentFromURL("private:factory/" + kind, - "_blank", 0, Args); - } catch (com.sun.star.uno.Exception e) { + try + { + oDoc = getCLoader(xMSF).loadComponentFromURL("private:factory/" + kind, + "_blank", 0, Args); + } + catch (com.sun.star.uno.Exception e) + { throw new IllegalArgumentException("Document could not be opened"); } @@ -231,7 +267,8 @@ public class DesktopTools { * @param xMSF the MultiServiceFactory */ public static XComponent loadDoc(XMultiServiceFactory xMSF, String url, - PropertyValue[] Args) { + PropertyValue[] Args) + { XComponent oDoc = null; if (Args == null) { @@ -245,6 +282,7 @@ public class DesktopTools { { throw new IllegalArgumentException("Document could not be loaded"); } + bringWindowToFront(oDoc); return oDoc; } //finish openNewDoc @@ -253,29 +291,48 @@ public class DesktopTools { * closes a given document * @param DocumentToClose the document to close */ - public static void closeDoc(XInterface DocumentToClose) { + public static void closeDoc(XInterface DocumentToClose) + { + if (DocumentToClose == null) + { + return; + } + String kd = System.getProperty("KeepDocument"); - if (kd != null ) { + if (kd != null) + { System.out.println("The property 'KeepDocument' is set and so the document won't be disposed"); return; } - XModifiable modified = (XModifiable) UnoRuntime.queryInterface( - XModifiable.class, DocumentToClose); - XCloseable closer = (XCloseable) UnoRuntime.queryInterface( - XCloseable.class, DocumentToClose); + XModifiable modified = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, DocumentToClose); + XCloseable closer = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, DocumentToClose); - try { - if (modified != null){ + try + { + if (modified != null) + { modified.setModified(false); } closer.close(true); - } catch (com.sun.star.util.CloseVetoException e) { + } + catch (com.sun.star.util.CloseVetoException e) + { + // e.printStackTrace(); System.out.println("Couldn't close document"); - } catch (com.sun.star.lang.DisposedException e) { + } + catch (com.sun.star.lang.DisposedException e) + { + // e.printStackTrace(); System.out.println("Couldn't close document"); - } catch (java.lang.NullPointerException e) { + } + catch (java.lang.NullPointerException e) + { + // e.printStackTrace(); System.out.println("Couldn't close document"); - } catch (com.sun.star.beans.PropertyVetoException e) { + } + catch (com.sun.star.beans.PropertyVetoException e) + { + // e.printStackTrace(); System.out.println("Couldn't close document"); } } @@ -287,10 +344,12 @@ public class DesktopTools { * @return a floating XWindow */ public static XWindowPeer createFloatingWindow(XMultiServiceFactory xMSF) - throws StatusException{ - return createFloatingWindow(xMSF, 500, 100, 400, 600); + throws StatusException + { + return createFloatingWindow(xMSF, 500, 100, 400, 600); } - /** + + /** * Creates a floating XWindow on the given position and size. * @return a floating XWindow * @param X the X-Postion of the floating XWindow @@ -301,44 +360,51 @@ public class DesktopTools { * @throws lib.StatusException if it is not possible to create a floating window a lib.StatusException was thrown */ public static XWindowPeer createFloatingWindow(XMultiServiceFactory xMSF, int X, int Y, int width, int height) - throws StatusException{ + throws StatusException + { XInterface oObj = null; - try { + try + { oObj = (XInterface) xMSF.createInstance("com.sun.star.awt.Toolkit"); - } catch (com.sun.star.uno.Exception e) { + } + catch (com.sun.star.uno.Exception e) + { throw new StatusException("Couldn't get toolkit", e); } XToolkit tk = (XToolkit) UnoRuntime.queryInterface( - XToolkit.class, oObj); + XToolkit.class, oObj); - WindowDescriptor descriptor = new com.sun.star.awt.WindowDescriptor(); + WindowDescriptor descriptor = new com.sun.star.awt.WindowDescriptor(); descriptor.Type = com.sun.star.awt.WindowClass.TOP; descriptor.WindowServiceName = "modelessdialog"; - descriptor.ParentIndex = -1; + descriptor.ParentIndex = -1; - Rectangle bounds = new com.sun.star.awt.Rectangle(); - bounds.X = X; - bounds.Y = Y; - bounds.Width = width; - bounds.Height = height; + Rectangle bounds = new com.sun.star.awt.Rectangle(); + bounds.X = X; + bounds.Y = Y; + bounds.Width = width; + bounds.Height = height; descriptor.Bounds = bounds; descriptor.WindowAttributes = (com.sun.star.awt.WindowAttribute.BORDER + - com.sun.star.awt.WindowAttribute.MOVEABLE + - com.sun.star.awt.WindowAttribute.SIZEABLE + - com.sun.star.awt.WindowAttribute.CLOSEABLE + - com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN); + com.sun.star.awt.WindowAttribute.MOVEABLE + + com.sun.star.awt.WindowAttribute.SIZEABLE + + com.sun.star.awt.WindowAttribute.CLOSEABLE + + com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN); XWindowPeer xWindow = null; - try{ - xWindow = tk.createWindow( descriptor ); - }catch ( com.sun.star.lang.IllegalArgumentException e){ - throw new StatusException("Could not create window", e); + try + { + xWindow = tk.createWindow(descriptor); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + throw new StatusException("Could not create window", e); } return xWindow; @@ -349,27 +415,28 @@ public class DesktopTools { * zoom to have a view over the hole page * @param xDoc the document to zoom */ - public static void zoomToEntirePage( XInterface xDoc){ - try { + public static void zoomToEntirePage(XInterface xDoc) + { + try + { XModel xMod = (XModel) UnoRuntime.queryInterface(XModel.class, xDoc); XInterface oCont = xMod.getCurrentController(); - XViewSettingsSupplier oVSSupp = (XViewSettingsSupplier) - UnoRuntime.queryInterface(XViewSettingsSupplier.class, oCont); + XViewSettingsSupplier oVSSupp = (XViewSettingsSupplier) UnoRuntime.queryInterface(XViewSettingsSupplier.class, oCont); XInterface oViewSettings = oVSSupp.getViewSettings(); - XPropertySet oViewProp = (XPropertySet) - UnoRuntime.queryInterface(XPropertySet.class, oViewSettings); + XPropertySet oViewProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oViewSettings); oViewProp.setPropertyValue("ZoomType", - new Short(com.sun.star.view.DocumentZoomType.ENTIRE_PAGE)); + new Short(com.sun.star.view.DocumentZoomType.ENTIRE_PAGE)); utils.shortWait(5000); - } catch (Exception e){ + } + catch (Exception e) + { System.out.println("Could not zoom to entire page: " + e.toString()); } } - /** * This function docks the Stylist onto the right side of the window.</p> * Note:<P> @@ -377,31 +444,35 @@ public class DesktopTools { * the chage of the docking will be effective at a restart. * @param xMSF the XMultiServiceFactory */ - public static void dockStylist(XMultiServiceFactory xMSF){ + public static void dockStylist(XMultiServiceFactory xMSF) + { // prepare Window-Settings - try { + try + { ConfigHelper aConfig = new ConfigHelper(xMSF, - "org.openoffice.Office.Views", false); + "org.openoffice.Office.Views", false); // Is node "5539" (slot-id for navigator) available? If not, insert it XNameReplace x5539 = aConfig.getOrInsertGroup("Windows", "5539"); aConfig.updateGroupProperty( - "Windows", "5539", "WindowState", "952,180,244,349;1;0,0,0,0;"); + "Windows", "5539", "WindowState", "952,180,244,349;1;0,0,0,0;"); aConfig.insertOrUpdateExtensibleGroupProperty( - "Windows", "5539", "UserData", "Data","V2,V,0,AL:(5,16,0/0/244/349,244;610)"); + "Windows", "5539", "UserData", "Data", "V2,V,0,AL:(5,16,0/0/244/349,244;610)"); // Is node "SplitWindow2" available? If not, instert it. aConfig.getOrInsertGroup("Windows", "SplitWindow2"); aConfig.insertOrUpdateExtensibleGroupProperty( - "Windows", "SplitWindow2","UserData", "UserItem","V1,2,1,0,5539"); + "Windows", "SplitWindow2", "UserData", "UserItem", "V1,2,1,0,5539"); aConfig.flush(); aConfig = null; - } catch (com.sun.star.uno.Exception e) { + } + catch (com.sun.star.uno.Exception e) + { e.printStackTrace(); } } @@ -412,7 +483,8 @@ public class DesktopTools { * @deprecated */ @Deprecated - public static void bringWindowToFromt(XModel xModel){ + public static void bringWindowToFromt(XModel xModel) + { bringWindowToFront(xModel); } @@ -422,8 +494,9 @@ public class DesktopTools { * Only the order of Office documents are changeable. * @param xModel the XModel of the document to bring to top */ - public static void bringWindowToFront(XModel xModel){ - System.out.println("DEBUG: bring to front xModel"); + public static void bringWindowToFront(XModel xModel) + { + // System.out.println("DEBUG: bring to front xModel"); XTopWindow xTopWindow = (XTopWindow) UnoRuntime.queryInterface( @@ -433,10 +506,12 @@ public class DesktopTools { xTopWindow.toFront(); } - public static void bringWindowToFront(XComponent xComponent){ - System.out.println("DEBUG: bring to front xCompoent"); + public static void bringWindowToFront(XComponent xComponent) + { + // System.out.println("DEBUG: bring to front xComponent"); XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent); - if (xModel != null){ + if (xModel != null) + { bringWindowToFront(xModel); } } diff --git a/qadevOOo/runner/util/FormTools.java b/qadevOOo/runner/util/FormTools.java index 5d59044adf63..180f4d79da21 100644 --- a/qadevOOo/runner/util/FormTools.java +++ b/qadevOOo/runner/util/FormTools.java @@ -41,6 +41,7 @@ import com.sun.star.awt.Size; import com.sun.star.awt.Point; import com.sun.star.awt.XControlModel; import com.sun.star.container.XNameContainer; +import com.sun.star.container.XIndexContainer; import com.sun.star.form.XFormsSupplier; import com.sun.star.form.XForm; import com.sun.star.form.XLoadable; @@ -192,12 +193,21 @@ public class FormTools { return oControl; } // finish createControl - public static XNameContainer getForms ( XDrawPage oDP ) { + public static XNameContainer getForms ( XDrawPage oDP ) + { XFormsSupplier oFS = (XFormsSupplier) UnoRuntime.queryInterface( XFormsSupplier.class,oDP); return oFS.getForms(); } //finish getForms + public static XIndexContainer getIndexedForms ( XDrawPage oDP ) + { + XFormsSupplier oFS = (XFormsSupplier) UnoRuntime.queryInterface( + XFormsSupplier.class,oDP); + return (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, + oFS.getForms() ); + } //finish getIndexedForms + public static void insertForm ( XComponent aDoc, XNameContainer Forms, String aName ) { try { @@ -222,7 +232,7 @@ public class FormTools { XLoadable formLoader = null; try { - Object aForm = FormTools.getForms(WriterTools.getDrawPage(aDoc)).getByName("Standard"); + Object aForm = FormTools.getIndexedForms(WriterTools.getDrawPage(aDoc)).getByIndex(0); XForm the_form = null; try { the_form = (XForm) AnyConverter.toObject(new Type(XForm.class), aForm); @@ -257,7 +267,7 @@ public class FormTools { throws com.sun.star.uno.Exception { XForm the_form = (XForm) AnyConverter.toObject(new Type(XForm.class), - FormTools.getForms(WriterTools.getDrawPage(aDoc)).getByName("Standard")); + FormTools.getIndexedForms(WriterTools.getDrawPage(aDoc)).getByIndex(0)); XPropertySet formProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, the_form); formProps.setPropertyValue("DataSourceName",sourceName); formProps.setPropertyValue("Command",tableName); diff --git a/qadevOOo/runner/util/PropertyName.java b/qadevOOo/runner/util/PropertyName.java index 3f1b1e44d2c3..c77c07187288 100644 --- a/qadevOOo/runner/util/PropertyName.java +++ b/qadevOOo/runner/util/PropertyName.java @@ -46,6 +46,9 @@ public interface PropertyName { * parameter name: "ConnectionString" */ final public static String CONNECTION_STRING = "ConnectionString"; + final public static String PIPE_CONNECTION_STRING = "PipeConnectionString"; + final public static String USE_PIPE_CONNECTION = "UsePipeConnection"; + /** * parameter name: "TestBase" */ diff --git a/qadevOOo/runner/util/ValueChanger.java b/qadevOOo/runner/util/ValueChanger.java index 70eaf25530a5..45acaa615d1c 100644 --- a/qadevOOo/runner/util/ValueChanger.java +++ b/qadevOOo/runner/util/ValueChanger.java @@ -957,9 +957,9 @@ public class ValueChanger { } } else - { - System.out.println("ValueChanger don't know type " + oldValue.getClass()); - } + { + System.out.println("ValueChanger don't know type " + oldValue.getClass()); + } return newValue; diff --git a/qadevOOo/runner/util/utils.java b/qadevOOo/runner/util/utils.java index f4cf3d1253dd..3ec523e32fec 100644 --- a/qadevOOo/runner/util/utils.java +++ b/qadevOOo/runner/util/utils.java @@ -186,7 +186,13 @@ public class utils { } else { if (fullDocPath.startsWith("/")) { prefix = "file://"; - } else { +// if (helper.OSHelper.isLinuxIntel()) +// { +// prefix = "file:/"; +// } + } + else + { prefix = "file:///"; } } diff --git a/qadevOOo/tests/java/complex/unoapi/CheckModuleAPI.java b/qadevOOo/tests/java/complex/unoapi/CheckModuleAPI.java index 4ca0728de864..20b36a057757 100644 --- a/qadevOOo/tests/java/complex/unoapi/CheckModuleAPI.java +++ b/qadevOOo/tests/java/complex/unoapi/CheckModuleAPI.java @@ -44,7 +44,7 @@ import helper.BuildEnvTools; import helper.ComplexDescGetter; import helper.CwsDataExchangeImpl; import java.io.File; -import java.io.FileFilter; +// import java.io.FileFilter; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -70,7 +70,8 @@ import util.utils; * </ul> * */ -public class CheckModuleAPI extends ComplexTestCase { +public class CheckModuleAPI extends ComplexTestCase +{ private static String mSRC_ROOT = null; private static boolean mIsInitialized = false; @@ -87,16 +88,21 @@ public class CheckModuleAPI extends ComplexTestCase { * but this will take some time. * Note: This funktionality is only reasonable with parameter <CODE>-noOffice true</CODE> */ - public void before() { + public void before() + { - if (!mIsInitialized) { + if (!mIsInitialized) + { mIsInitialized = true; - try { + try + { bet = new BuildEnvTools(param, log); - } catch (ParameterNotFoundException ex) { + } + catch (ParameterNotFoundException ex) + { this.failed(ex.toString(), false); } @@ -111,11 +117,15 @@ public class CheckModuleAPI extends ComplexTestCase { * let API tests run. * @param module */ - public void checkModule(String module) { + public void checkModule(String module) + { log.println(utils.getDateTime() + ": start testing module '" + module + "'"); log.println(utils.getDateTime() + "start new Office instance..."); + + // TODO: is Office started with this program? final OfficeProvider officeProvider = new OfficeProvider(); + log.println(utils.getDateTime() + "Receiving the ServiceManager of the Office "); final XMultiServiceFactory msf = (XMultiServiceFactory) officeProvider.getManager(param); assure("couldnot get ServiceFarcotry", msf != null, mContinue); @@ -128,12 +138,12 @@ public class CheckModuleAPI extends ComplexTestCase { final File fMakeFile = new File(sMakeFile); assure("ERROR: could not find makefile: '" + sMakeFile + "'", fMakeFile.exists(), mContinue); - final String[] commands = getCommands(sUnoapi); + final String[] commands = getDmakeCommands(sUnoapi); final ProcessHandler procHdl = bet.runCommandsInEnvironmentShell(commands, fUnoapi, 0); log.println("exit code of dmake: " + procHdl.getExitCode()); String test = procHdl.getOutputText(); - test = procHdl.getErrorText(); + test += procHdl.getErrorText(); // if (mDebug) { // log.println("---> Output of dmake:"); // log.println(procHdl.getOutputText()); @@ -142,40 +152,93 @@ public class CheckModuleAPI extends ComplexTestCase { // log.println(procHdl.getErrorText()); // log.println("<--- Error output of dmake:"); // } - assure("module '" + module + "' failed", verifyOutput(procHdl.getOutputText()), mContinue); + assure("module '" + module + "' failed", verifyOutput(test), mContinue); log.println(utils.getDateTime() + " module '" + module + "': kill existing office..."); - try { - officeProvider.closeExistingOffice(param, true); - } catch (java.lang.UnsatisfiedLinkError exception) { - log.println("Office seems not to be running"); - } + // TODO: how to check if the office is not started with this process. + boolean bNoOffice = param.getBool("NoOffice"); + if (!bNoOffice) + { + try + { + officeProvider.closeExistingOffice(param, true); + } + catch (java.lang.UnsatisfiedLinkError exception) + { + log.println("Office seems not to be running"); + } + } } - - private void addIfQaUnoApiFolderExist(File srcRoot, ArrayList moduleNames) { - - if (doesQaUnoApiFolderExist(srcRoot)) { - moduleNames.add(srcRoot.getName()); + private String getQaUnoApiPath(String srcRoot, String _sModul) + { + File aFile = new File(srcRoot); + if (!aFile.exists()) + { + System.out.println("ERROR: srcRoot '" + srcRoot + "' does not exist."); + return null; + } + String sModulePath = srcRoot; + sModulePath += File.separator; + sModulePath += _sModul; + + File aModulePath = new File(sModulePath); + if (! aModulePath.exists()) + { + aModulePath = new File(sModulePath + ".lnk"); + if (! aModulePath.exists()) + { + aModulePath = new File(sModulePath + ".link"); + if (! aModulePath.exists()) + { + // module does not exist. + return null; + } + } + } + sModulePath = aModulePath.getAbsolutePath(); + sModulePath += File.separator; + sModulePath += "qa"; + sModulePath += File.separator; + sModulePath += "unoapi"; + File aModulePathQaUnoApi = new File(sModulePath); + if (aModulePathQaUnoApi.exists()) + { + return aModulePathQaUnoApi.getAbsolutePath(); } + return null; } - - private boolean doesQaUnoApiFolderExist(File srcRoot) { + private boolean doesQaUnoApiFolderExist(String srcRoot, String _sModul) + { + if (getQaUnoApiPath(srcRoot, _sModul) != null) + { + return true; + } + return false; + } +/* + private boolean doesQaUnoApiFolderExist(File srcRoot) + { final FolderFilter qaFilter = new FolderFilter("qa"); final File[] qaTree = srcRoot.listFiles(qaFilter); - if (qaTree != null) { - for (int j = 0; j < qaTree.length; j++) { + if (qaTree != null) + { + for (int j = 0; j < qaTree.length; j++) + { final File qaFolder = qaTree[j]; final FolderFilter apiFilter = new FolderFilter("unoapi"); final File[] apiTree = qaFolder.listFiles(apiFilter); - if (apiTree != null && apiTree.length > 0) { + if (apiTree != null && apiTree.length > 0) + { return true; } } } return false; } +*/ - private String[] getAllModuleCommand() { + private String[] getAllModuleCommand() + { String[] checkModules; final String[] names = getModulesFromSourceRoot(); @@ -184,45 +247,75 @@ public class CheckModuleAPI extends ComplexTestCase { return checkModules; } - private String[] getCheckModuleCommand(String[] names) { + private String[] getCheckModuleCommand(String[] names) + { String[] checkModules; checkModules = new String[names.length]; - for (int i = 0; i < names.length; i++) { + for (int i = 0; i < names.length; i++) + { // if a module is not added to a cws it contains a dot in its name (forms.lnk) - if (names[i].indexOf(".") != -1) { + if (names[i].indexOf(".") != -1) + { checkModules[i] = "checkModule(" + names[i].substring(0, names[i].indexOf(".")) + ")"; - } else { + } + else + { checkModules[i] = "checkModule(" + names[i] + ")"; } } return checkModules; } - private String[] getCommands(String sUnoapi) { + private String[] getDmakeCommands(String sUnoapi) + { String[] cmdLines = null; final String platform = (String) param.get(PropertyName.OPERATING_SYSTEM); log.println("prepare command for platform " + platform); - if (platform.equals(PropertyName.WNTMSCI)){ - if (param.getBool(PropertyName.CYGWIN)){ - cmdLines = new String[]{"cd `cygpath '" + sUnoapi.replaceAll("\\\\", "\\\\\\\\")+ "'`", "dmake"}; - } else{ - cmdLines = new String[]{"cdd " + sUnoapi, "dmake"}; + if (platform.equals(PropertyName.WNTMSCI)) + { + if (param.getBool(PropertyName.CYGWIN)) + { + // cygwin stuff + cmdLines = new String[] + { + "cd `cygpath '" + sUnoapi.replaceAll("\\\\", "\\\\\\\\") + "'`", + "dmake" + }; } - } else { - cmdLines = new String[]{"cd " + sUnoapi, "dmake"}; + else + { + // old 4NT + cmdLines = new String[] + { + "cdd " + sUnoapi, + "dmake" + }; } + } + else + { + // unix + cmdLines = new String[] + { + "cd " + sUnoapi, + "dmake" + }; + } return cmdLines; } - private String[] getCwsModuleCommand() { + private String[] getCwsModuleCommand() + { String[] checkModules; final String version = (String) param.get(PropertyName.VERSION); String[] names = null; - if (version.startsWith("cws_")) { - try { + if (version.startsWith("cws_")) + { + try + { // cws version: all added modules must be tested final String cws = version.substring(4, version.length()); final CwsDataExchangeImpl cde = new CwsDataExchangeImpl(cws, param, log); @@ -230,18 +323,27 @@ public class CheckModuleAPI extends ComplexTestCase { final ArrayList moduleNames = new ArrayList(); Iterator iterator = addedModules.iterator(); - while (iterator.hasNext()) { - final File sourceRoot = new File(mSRC_ROOT + File.separator + (String) iterator.next()); - addIfQaUnoApiFolderExist(sourceRoot, moduleNames); - + while (iterator.hasNext()) + { + String sModuleName = (String) iterator.next(); + // String sFilename = mSRC_ROOT; // + File.separator + sModuleName; + // final File sourceRoot = new File(sFilename); + if (doesQaUnoApiFolderExist(mSRC_ROOT, sModuleName)) + { + moduleNames.add(sModuleName); + } } names = (String[]) moduleNames.toArray(new String[0]); - } catch (ParameterNotFoundException ex) { + } + catch (ParameterNotFoundException ex) + { this.failed(ex.toString(), false); } - } else { + } + else + { // major version: all modules must be tested names = getModulesFromSourceRoot(); } @@ -250,53 +352,70 @@ public class CheckModuleAPI extends ComplexTestCase { return checkModules; } - private String[] getDefinedModuleCommand(String module) { + private String[] getDefinedModuleCommand(String module) + { String[] checkModules = null; // list of modules to test: (sw,sc,sd) - if (module.indexOf(",") != -1) { + if (module.indexOf(",") != -1) + { final String[] names = module.split(","); checkModules = new String[names.length]; - for (int i = 0; i < names.length; i++) { + for (int i = 0; i < names.length; i++) + { final String moduleName = names[i].trim(); - File sourceRoot = new File(mSRC_ROOT + File.separator + moduleName); - if (!sourceRoot.exists()) { - sourceRoot = new File(mSRC_ROOT + File.separator + moduleName + ".lnk"); - } +// File sourceRoot = new File(mSRC_ROOT + File.separator + moduleName); +// if (!sourceRoot.exists()) +// { +// sourceRoot = new File(mSRC_ROOT + File.separator + moduleName + ".lnk"); +// } - if (doesQaUnoApiFolderExist(sourceRoot)) { + if (doesQaUnoApiFolderExist(mSRC_ROOT, moduleName)) + { checkModules[i] = "checkModule(" + moduleName + ")"; } } - } else { - File sourceRoot = new File(mSRC_ROOT + File.separator + module); - if (!sourceRoot.exists()) { - sourceRoot = new File(mSRC_ROOT + File.separator + module + ".lnk"); - } - if (doesQaUnoApiFolderExist(sourceRoot)) { - checkModules = new String[]{"checkModule(" + module + ")"}; + } + else + { +// File sourceRoot = new File(mSRC_ROOT + File.separator + module); +// if (!sourceRoot.exists()) +// { +// sourceRoot = new File(mSRC_ROOT + File.separator + module + ".lnk"); +// } + if (doesQaUnoApiFolderExist(mSRC_ROOT, module)) + { + checkModules = new String[] + { + "checkModule(" + module + ")" + }; } } return checkModules; } - private String getModulePath(String module) { - - String sUnoapi = null; - final String sep = System.getProperty("file.separator"); - final File srcRoot = new File(mSRC_ROOT); - - final FolderFilter qaFilter = new FolderFilter(module); - final File[] moduleTree = srcRoot.listFiles(qaFilter); - if (moduleTree != null) { - if (mDebug) { - log.println("moduleTree length:" + moduleTree.length); - log.println("moduleTree: " + moduleTree[0].getAbsolutePath()); - } - if (moduleTree != null) { - sUnoapi = moduleTree[0].getAbsolutePath() + sep + "qa" + sep + "unoapi"; - } - } + private String getModulePath(String module) + { + + // String sUnoapi = null; + // final String sep = System.getProperty("file.separator"); + // final File srcRoot = new File(mSRC_ROOT); + + // final FolderFilter qaFilter = new FolderFilter(module); + // final File[] moduleTree = srcRoot.listFiles(qaFilter); +// if (moduleTree != null) +// { +// if (mDebug) +// { +// log.println("moduleTree length:" + moduleTree.length); +// log.println("moduleTree: " + moduleTree[0].getAbsolutePath()); +// } +// if (moduleTree != null) +// { +// sUnoapi = moduleTree[0].getAbsolutePath() + sep + "qa" + sep + "unoapi"; +// } +// } + String sUnoapi = getQaUnoApiPath(mSRC_ROOT, module); return sUnoapi; } @@ -314,35 +433,39 @@ public class CheckModuleAPI extends ComplexTestCase { * sfx -> sfx2 * sm -> starmath */ - private String getTranslatedNames(String module) { + private String getTranslatedNames(String module) + { - final HashMap modulez = new HashMap(); + final HashMap aModuleHashMap = new HashMap(); - modulez.put("fwk", "framework"); - modulez.put("fwl", "framework"); - modulez.put("sch", "chart2"); - modulez.put("sysmgr1", "configmgr"); - modulez.put("cfgmag2", "configmgr"); - modulez.put("lnn", "lingu"); - modulez.put("lng", "linguistic"); - modulez.put("sfx", "sfx2"); - modulez.put("sm", "starmath"); + aModuleHashMap.put("fwk", "framework"); + aModuleHashMap.put("fwl", "framework"); + aModuleHashMap.put("sch", "chart2"); + aModuleHashMap.put("sysmgr1", "configmgr"); + aModuleHashMap.put("cfgmag2", "configmgr"); + aModuleHashMap.put("lnn", "lingu"); + aModuleHashMap.put("lng", "linguistic"); + aModuleHashMap.put("sfx", "sfx2"); + aModuleHashMap.put("sm", "starmath"); // it could the that the parameter looks like "fwk,fwl". This results in double "famework,framework". // The following loop correct this to only one "framework" - final Set keys = modulez.keySet(); + final Set keys = aModuleHashMap.keySet(); final Iterator iterator = keys.iterator(); - while (iterator.hasNext()) { + while (iterator.hasNext()) + { final String key = (String) iterator.next(); - final String value = (String) modulez.get(key); + final String value = (String) aModuleHashMap.get(key); module = module.replaceAll(key, value); final int count = module.split(value).length; - if (count > 2) { - for (int i = 2; i < count; i++) { + if (count > 2) + { + for (int i = 2; i < count; i++) + { module.replaceFirst("," + value, ""); } @@ -351,33 +474,41 @@ public class CheckModuleAPI extends ComplexTestCase { return module; } - private boolean verifyOutput(String output) { + private boolean verifyOutput(String output) + { log.println("verify output..."); boolean ok = false; final String[] outs = output.split("\n"); - for (int i = 0; i < outs.length; i++) { + for (int i = 0; i < outs.length; i++) + { final String line = outs[i]; - if (line.matches("[0-9]+? of [0-9]+? tests failed")) { + if (line.matches("[0-9]+? of [0-9]+? tests failed")) + { log.println("mached line: " + line); - if (line.matches("0 of [0-9]+? tests failed")) { + if (line.matches("0 of [0-9]+? tests failed")) + { ok = true; log.println("Module passed OK"); - } else { + } + else + { log.println("Module passed FAILED"); } } } - if (!ok) { + if (!ok) + { log.println("ERROR: could not find '0 of [0-9]+? tests failed' in output"); } return ok; } - private String[] getModulesFromSourceRoot() { + private String[] getModulesFromSourceRoot() + { log.println("**** run module tests over all modules ****"); log.println("search for qa/unoapi foldres in all modules based in "); @@ -387,11 +518,17 @@ public class CheckModuleAPI extends ComplexTestCase { final File sourceRoot = new File(mSRC_ROOT); final File[] sourceTree = sourceRoot.listFiles(); - assure("Could not find any files in SOURCE_ROOT=" + mSRC_ROOT, sourceTree != null, false); +// assure("Could not find any files in SOURCE_ROOT=" + mSRC_ROOT, sourceTree != null, false); - for (int i = 0; i < sourceTree.length; i++) { + for (int i = 0; i < sourceTree.length; i++) + { final File moduleName = sourceTree[i]; - addIfQaUnoApiFolderExist(moduleName, moduleNames); + String sModuleName = moduleName.getName(); // (String)moduleNames.get(i); + if (doesQaUnoApiFolderExist(mSRC_ROOT, sModuleName)) + { + // addIfQaUnoApiFolderExist(moduleName, moduleNames); + moduleNames.add(sModuleName); + } } final String[] names = (String[]) moduleNames.toArray(new String[0]); @@ -409,7 +546,8 @@ public class CheckModuleAPI extends ComplexTestCase { * <li>'auto' to check only modules which are added to the ChildWorkSpace</li> * </ul> */ - public void module(String module) { + public void module(String module) + { String[] checkModules; final ComplexDescGetter desc = new ComplexDescGetter(); @@ -420,30 +558,38 @@ public class CheckModuleAPI extends ComplexTestCase { all: check all modules which contains a qa/unoapi folder auto: check all modules which contains a qa/unoapi folder except the module is not added */ - if (module.equals("all")) { + if (module.equals("all")) + { checkModules = getAllModuleCommand(); - } else if (module.equals("auto")) { + } + else if (module.equals("auto")) + { checkModules = getCwsModuleCommand(); - } else { + } + else + { module = getTranslatedNames(module); checkModules = getDefinedModuleCommand(module); } - if (checkModules != null && checkModules.length > 0) { + if (checkModules != null && checkModules.length > 0) + { entry = desc.createTestDesc("complex.unoapi.CheckModuleAPI", "complex.unoapi.CheckModuleAPI", checkModules, - log); + log); final java_complex complex = new java_complex(); log.println("********** start test *************"); - final boolean result = complex.executeTest(param, new DescEntry[]{entry}); + final boolean result = complex.executeTest(param, new DescEntry[] { entry }); log.println("********** end test *************"); assure("CheckModuleAPI.module(" + module + ") PASSED.FAILED", result); - } else { - log.println("No modules containing qa/unoapi foder found => OK"); + } + else + { + log.println("No modules containing qa/unoapi folder found => OK"); state = true; } @@ -451,48 +597,65 @@ public class CheckModuleAPI extends ComplexTestCase { } - private void setUnoApiCwsStatus(boolean status) { + private void setUnoApiCwsStatus(boolean status) + { - if (!param.getBool(PropertyName.NO_CWS_ATTACH)) { + if (!param.getBool(PropertyName.NO_CWS_ATTACH)) + { final String version = (String) param.get(PropertyName.VERSION); - if (version.startsWith("cws_")) { - try { + if (version.startsWith("cws_")) + { + try + { // cws version: all added modules must be tested final String cws = version.substring(4, version.length()); final CwsDataExchangeImpl cde = new CwsDataExchangeImpl(cws, param, log); cde.setUnoApiCwsStatus(status); - } catch (ParameterNotFoundException ex) { + } + catch (ParameterNotFoundException ex) + { log.println("ERROR: could not wirte status to EIS database: " + ex.toString()); } } } } - public String[] getTestMethodNames() { - return new String[]{"module(all)"}; + public String[] getTestMethodNames() + { + return new String[] + { + "module(all)" + }; } - class FolderFilter implements FileFilter { - - private String mFolderName; - - public FolderFilter(String folderName) { - mFolderName = folderName; - } - - public boolean accept(File pathname) { - - boolean found = false; - if (pathname.isDirectory()) { - if (pathname.getName().equals(mFolderName)) { - found = true; - } else if (pathname.getName().equals(mFolderName + ".lnk")) { - found = true; - } - } - return found; - } - } +// class _FolderFilter implements FileFilter +// { +// +// private String mFolderName; +// +// public FolderFilter(String folderName) +// { +// mFolderName = folderName; +// } +// +// public boolean accept_(File pathname) +// { +// +// boolean found = false; +// if (pathname.isDirectory()) +// { +// if (pathname.getName().equals(mFolderName)) +// { +// found = true; +// } +// else if (pathname.getName().equals(mFolderName + ".lnk")) +// { +// found = true; +// } +// } +// return found; +// } +// } } diff --git a/qadevOOo/tests/java/ifc/qadevooo/_SelfTest.java b/qadevOOo/tests/java/ifc/qadevooo/_SelfTest.java new file mode 100755 index 000000000000..e7d215e5bcbb --- /dev/null +++ b/qadevOOo/tests/java/ifc/qadevooo/_SelfTest.java @@ -0,0 +1,86 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: _XActiveDataSource.java,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.qadevooo; + +import lib.MultiMethodTest; + +// import com.sun.star.uno.UnoRuntime; +// import com.sun.star.uno.XInterface; + +/** +* Testing <code>ifc.qadevooo._SelfTest</code> +* interface methods: +* <ul> +* <li><code>testmethod()</code></li> +* </ul> <p> +* +*/ +public class _SelfTest extends MultiMethodTest +{ + + /** + */ + public void before() + { + log.println("_SelfTest.before()"); + } + + /** + * Test calls the method + */ + public void _testmethod() + { + log.println("_SelfTest._testmethod()"); + tRes.tested("testmethod()", true); + } + + public void _testmethod2() + { + log.println("_SelfTest._testmethod2()"); + tRes.tested("testmethod2()", true); + } + + public void _testmethod3() + { + log.println("_SelfTest._testmethod3()"); + tRes.tested("testmethod3()", true); + } + + /** + * Forces object environment recreation. + */ + public void after() + { + log.println("_SelfTest.after()"); + this.disposeEnvironment() ; + } +} + diff --git a/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java b/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java index 5fdd9b0e8db0..03c9a43c918f 100644 --- a/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java +++ b/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java @@ -33,6 +33,7 @@ package ifc.sdb; import com.sun.star.sdb.XSingleSelectQueryComposer; import lib.MultiMethodTest; import com.sun.star.sdb.XSingleSelectQueryAnalyzer; +import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import lib.StatusException; import lib.Status; @@ -80,7 +81,7 @@ public class _XSingleSelectQueryComposer extends MultiMethodTest { * @see om.sun.star.sdb.XSingleSelectQueryAnalyzer * @see com.sun.star.beans.XPropertySet */ - protected void before() { + protected void before() throws Exception { xQueryAna = (XSingleSelectQueryAnalyzer) UnoRuntime.queryInterface(XSingleSelectQueryAnalyzer.class, @@ -102,9 +103,7 @@ public class _XSingleSelectQueryComposer extends MultiMethodTest { } - colName = (String) - UnoRuntime.queryInterface(String.class, - tEnv.getObjRelation("colName")); + colName = AnyConverter.toString(tEnv.getObjRelation("colName")); if (colName == null) { throw new StatusException(Status.failed( diff --git a/qadevOOo/tests/java/ifc/sheet/_FunctionDescription.java b/qadevOOo/tests/java/ifc/sheet/_FunctionDescription.java index 554b6f6d12e3..dd6aebf57268 100644 --- a/qadevOOo/tests/java/ifc/sheet/_FunctionDescription.java +++ b/qadevOOo/tests/java/ifc/sheet/_FunctionDescription.java @@ -37,6 +37,7 @@ import com.sun.star.beans.XPropertySet; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XServiceInfo; import com.sun.star.sheet.FunctionArgument; +import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; @@ -75,7 +76,7 @@ public class _FunctionDescription extends MultiMethodTest { XInterface FA = (XInterface)oDocMSF. createInstance("com.sun.star.sheet.FunctionArgument"); - FunctionArgument arg = (FunctionArgument)UnoRuntime.queryInterface + FunctionArgument arg = (FunctionArgument)AnyConverter.toObject (FunctionArgument.class, FA); arg.Description = "FunctionDescription argument description" ; diff --git a/qadevOOo/tests/java/ifc/text/_XSimpleText.java b/qadevOOo/tests/java/ifc/text/_XSimpleText.java index 785d53fec97a..84f271dae7b5 100644 --- a/qadevOOo/tests/java/ifc/text/_XSimpleText.java +++ b/qadevOOo/tests/java/ifc/text/_XSimpleText.java @@ -77,7 +77,7 @@ public class _XSimpleText extends MultiMethodTest { */ public void _insertString() { requiredMethod("createTextCursor()"); - log.println( "Testing insertString)" ); + log.println( "Testing insertString" ); String sStr = getInterfaceName() ; oObj.insertString( oCursor, sStr, false ); String gStr = oObj.getText().getString() ; diff --git a/qadevOOo/tests/java/mod/_qadevOOo/SelfTest.java b/qadevOOo/tests/java/mod/_qadevOOo/SelfTest.java new file mode 100755 index 000000000000..6d14de54f8e9 --- /dev/null +++ b/qadevOOo/tests/java/mod/_qadevOOo/SelfTest.java @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ScDocumentConfiguration.java,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package mod._qadevOOo; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; + +import java.io.PrintWriter; + +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; + +import util.SOfficeFactory; + +import com.sun.star.text.XSimpleText; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextDocument; + +public class SelfTest extends TestCase +{ + private XTextDocument xTextDoc = null; + + protected void initialize(TestParameters tParam, PrintWriter log) + { + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF()); + + log.println("initialize the selftest"); + try + { + log.println("creating a textdocument"); + xTextDoc = SOF.createTextDoc(null); + } + catch (com.sun.star.uno.Exception e) + { + e.printStackTrace(log); + throw new StatusException("Couldn't create document", e); + } + } + + /** + * Disposes text document. + */ + protected void cleanup(TestParameters tParam, PrintWriter log) + { + log.println(" cleanup selftest"); + util.DesktopTools.closeDoc(xTextDoc); + } + + protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) + { + XInterface oObj = null; + log.println("creating a test environment"); + + // get the bodytext of textdocument here + log.println("getting the TextCursor"); + + final XSimpleText aText = xTextDoc.getText(); + final XTextCursor textCursor = aText.createTextCursor(); + oObj = textCursor; + + TestEnvironment tEnv = new TestEnvironment(oObj); + + return tEnv; + } +} |