diff options
Diffstat (limited to 'qadevOOo')
20 files changed, 622 insertions, 50 deletions
diff --git a/qadevOOo/prj/build.lst b/qadevOOo/prj/build.lst index 1594d5c59f57..50d60a563c64 100644 --- a/qadevOOo/prj/build.lst +++ b/qadevOOo/prj/build.lst @@ -2,4 +2,5 @@ qa qadevOOo : javaunohelper jurt ridljar unoil NULL qa qadevOOo usr1 - all qa_mkout NULL qa qadevOOo nmake - all qa_runner_ant_build NULL qa qadevOOo\runner nmake - all qa_make_package qa_runner_ant_build NULL -qa qadevOOo\qa\unoapi nmake - all qa_qa_unoapi NULL + +qa qadevOOo\qa\unoapi nmake - all qa_qa_unoapi qa_make_package NULL diff --git a/qadevOOo/qa/complex/junitskeleton/Skeleton.java b/qadevOOo/qa/complex/junitskeleton/Skeleton.java new file mode 100644 index 000000000000..3ae5d3dad120 --- /dev/null +++ b/qadevOOo/qa/complex/junitskeleton/Skeleton.java @@ -0,0 +1,194 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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 complex.junitskeleton; + +import com.sun.star.io.IOException; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.XCloseable; +import java.io.File; +import java.io.RandomAccessFile; + +import lib.TestParameters; + +import util.SOfficeFactory; + +// ---------- junit imports ----------------- +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; +// ------------------------------------------ + +public class Skeleton +{ + /** + * The test parameters + */ + private static TestParameters param = null; + + @Test public void check() { + assertTrue("Couldn't open document", open()); + System.out.println("check"); + assertTrue("Couldn't close document", close()); + String tempDirURL = util.utils.getOfficeTemp/*Dir*/(getMSF()); + System.out.println("temp dir URL is: " + tempDirURL); + String tempDir = graphical.FileHelper.getSystemPathFromFileURL(tempDirURL); + assertTrue("Temp directory doesn't exist.", new File(tempDir).exists()); + } + + private boolean open() + { + System.out.println("open()"); + // get multiservicefactory ----------------------------------------- + final XMultiServiceFactory xMsf = getMSF(); + + SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf); + + // some Tests need the qadevOOo TestParameters, it is like a Hashmap for Properties. + param = new TestParameters(); + param.put("ServiceFactory", xMsf); // some qadevOOo functions need the ServiceFactory + + return true; + } + + private boolean close() + { + System.out.println("close()"); + return true; + } + + // marked as test + @Test public void checkDocument() + { + System.out.println("checkDocument()"); + final String sREADME = TestDocument.getUrl("README.txt"); + System.out.println("README is in:" + sREADME); + File aFile = new File(sREADME); + if (! aFile.exists()) + { + // It is a little bit stupid that office urls not compatible to java file urls + System.out.println("java.io.File can't access Office file urls."); + String sREADMESystemPath = graphical.FileHelper.getSystemPathFromFileURL(sREADME); + aFile = new File(sREADMESystemPath); + assertTrue("File '" + sREADMESystemPath + "' doesn't exists.", aFile.exists()); + } + + try + { + RandomAccessFile aAccess = new RandomAccessFile(aFile, "r"); + long nLength = aAccess.length(); + System.out.println("File length: " + nLength); + assertTrue("File length wrong", nLength > 0); + String sLine = aAccess.readLine(); + assertTrue("Line must not be empty", sLine.length() > 0); + System.out.println(" Line: '" + sLine + "'"); + System.out.println(" length: " + sLine.length()); + assertTrue("File length not near equal to string length", sLine.length() + 2 >= nLength); + aAccess.close(); + } + catch (java.io.FileNotFoundException e) + { + fail("Can't find file: " + sREADME + " - " + e.getMessage()); + } + catch (java.io.IOException e) + { + fail("IO Exception: " + e.getMessage()); + } + + } + + @Test public void checkOpenDocumentWithOffice() + { + // SOfficeFactory aFactory = new SOfficeFactory(getMSF()); + SOfficeFactory SOF = SOfficeFactory.getFactory(getMSF()); + final String sREADME = TestDocument.getUrl("README.txt"); + try + { + XComponent aDocument = SOF.loadDocument(sREADME); + complex.junitskeleton.justatest.shortWait(); + XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, aDocument); + xClose.close(true); + } + catch (com.sun.star.lang.IllegalArgumentException ex) + { + fail("Illegal argument exception caught: " + ex.getMessage()); + } + catch (com.sun.star.io.IOException ex) + { + fail("IOException caught: " + ex.getMessage()); + } + catch (com.sun.star.uno.Exception ex) + { + fail("Exception caught: " + ex.getMessage()); + } + } + + // marked as prepare for test, will call before every test + @Before public void before() + { + System.out.println("before()"); + System.setProperty("THIS IS A TEST", "Hallo"); + } + + + // marked as post for test, will call after every test + @After public void after() + { + System.out.println("after()"); + String sValue = System.getProperty("THIS IS A TEST"); + assertEquals(sValue, "Hallo"); + } + + + private XMultiServiceFactory getMSF() + { + final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + return xMSF1; + } + + // setup and close connections + @BeforeClass public static void setUpConnection() throws Exception { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); + +} diff --git a/qadevOOo/qa/complex/junitskeleton/TestDocument.java b/qadevOOo/qa/complex/junitskeleton/TestDocument.java new file mode 100644 index 000000000000..ff140a9991f6 --- /dev/null +++ b/qadevOOo/qa/complex/junitskeleton/TestDocument.java @@ -0,0 +1,41 @@ +/************************************************************************* +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* 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 complex.junitskeleton; + +import java.io.File; +import org.openoffice.test.OfficeFileUrl; + +final class TestDocument +{ + public static String getUrl(String name) + { + return OfficeFileUrl.getAbsolute(new File("test_documents", name)); + } + + private TestDocument() {} +} diff --git a/qadevOOo/qa/complex/junitskeleton/justatest.java b/qadevOOo/qa/complex/junitskeleton/justatest.java new file mode 100644 index 000000000000..5c11360b0717 --- /dev/null +++ b/qadevOOo/qa/complex/junitskeleton/justatest.java @@ -0,0 +1,38 @@ +/** + * @author: ll93751 + * @copyright: Sun Microsystems Inc. 2010 + */ + +package complex.junitskeleton; + +public class justatest /* extends *//* implements */ { + //public static void main( String[] argv ) { + // + // } + public void justatest() + { + System.out.println("justatest CTor."); + } + + public void testfkt() + { + System.out.println("Test called."); + } + + /** + * Sleeps for 0.5 sec. to allow StarOffice to react on <code> + * reset</code> call. + */ + public static void shortWait() + { + try + { + Thread.sleep(500) ; + } + catch (InterruptedException e) + { + System.out.println("While waiting :" + e) ; + } + } + +} diff --git a/qadevOOo/qa/complex/junitskeleton/makefile.mk b/qadevOOo/qa/complex/junitskeleton/makefile.mk new file mode 100644 index 000000000000..301b8cf88fd7 --- /dev/null +++ b/qadevOOo/qa/complex/junitskeleton/makefile.mk @@ -0,0 +1,63 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# 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. +# +#************************************************************************* + +.IF "$(OOO_SUBSEQUENT_TESTS)" == "" +nothing .PHONY: + @echo "OOO_SUBSEQUENT_TESTS not set, do nothing." +.ELSE + +PRJ = ../../.. +PRJNAME = sc +TARGET = qa_complex_junitskeleton + +.IF "$(OOO_JUNIT_JAR)" != "" +PACKAGE = complex/junitskeleton + +# here store only Files which contain a @Test +JAVATESTFILES = \ + Skeleton.java + +# put here all other files +JAVAFILES = $(JAVATESTFILES) \ + justatest.java \ + TestDocument.java + +JARFILES = OOoRunner.jar ridl.jar test.jar unoil.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) + +# Sample how to debug +# JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y + +.END + +.INCLUDE: settings.mk +.INCLUDE: target.mk +.INCLUDE: installationtest.mk + +ALLTAR : javatest + +.END diff --git a/qadevOOo/qa/complex/junitskeleton/test_documents/README.txt b/qadevOOo/qa/complex/junitskeleton/test_documents/README.txt new file mode 100644 index 000000000000..775f01c4924d --- /dev/null +++ b/qadevOOo/qa/complex/junitskeleton/test_documents/README.txt @@ -0,0 +1 @@ +Here you can store documents. diff --git a/qadevOOo/runner/complexlib/Assurance.java b/qadevOOo/runner/complexlib/Assurance.java index 665980d792ab..980ede95f052 100644 --- a/qadevOOo/runner/complexlib/Assurance.java +++ b/qadevOOo/runner/complexlib/Assurance.java @@ -75,7 +75,7 @@ public class Assurance * @param actual specifies the actual boolean value */ protected void assureEquals( boolean expected, boolean actual ) { - assureEquals( "Equality test failed", new Boolean( expected ), new Boolean( actual ), false ); + assureEquals( "Equality test failed", expected, new Boolean( actual ), false ); } /** @@ -85,7 +85,7 @@ public class Assurance * @param actual specifies the actual boolean value */ protected void assureEquals( String message, boolean expected, boolean actual ) { - assureEquals( message, new Boolean( expected ), new Boolean( actual ), false ); + assureEquals( message, expected, actual, false ); } /** @@ -240,6 +240,27 @@ public class Assurance assureEquals( message, expected, actual, false ); } + /** + * assures the two given sequences are of equal length, and have equal content + */ + public <T> void assureEquals( String i_message, T[] i_expected, T[] i_actual, boolean i_continue ) + { + if ( i_expected.length != i_actual.length ) + failed( i_message + ": expected element count: " + i_expected.length + ", actual element count: " + i_actual.length ); + for ( int i=0; i<i_expected.length; ++i ) + { + assureEquals( i_message + ": mismatch at element pos " + i, i_expected[i], i_actual[i], i_continue ); + } + } + + /** + * assures the two given sequences are of equal length, and have equal content + */ + public <T> void assureEquals( String i_message, T[] i_expected, T[] i_actual ) + { + assureEquals( i_message, i_expected, i_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 diff --git a/qadevOOo/runner/graphical/EnhancedComplexTestCase.java b/qadevOOo/runner/graphical/EnhancedComplexTestCase.java index c3ec2b3e8336..3d496826f5f2 100644 --- a/qadevOOo/runner/graphical/EnhancedComplexTestCase.java +++ b/qadevOOo/runner/graphical/EnhancedComplexTestCase.java @@ -45,7 +45,7 @@ abstract public class EnhancedComplexTestCase extends ComplexTestCase implements private void callEntry(String _sEntry, ParameterHelper _aParam) { // log.println("- next file is: ------------------------------"); - log.println("File: " + _sEntry); + log.println(" File: " + _sEntry); // TODO: check if 'sEntry' is a guilty document. File aFile = new File(_aParam.getInputPath()); String sPath = _aParam.getInputPath(); @@ -254,8 +254,15 @@ private void callEntry(String _sEntry, ParameterHelper _aParam) for (int i=0;i<aList.size();i++) { String sEntry = aList.get(i); - callEntry(sEntry, _aParam); - + try + { + callEntry(sEntry, _aParam); + } + catch (AssureException e) + { + // we only need to catch the assure() + // nOkStatus += 2; + } // we want to know the current status of the run through // if the status is greater (more bad) then the current, // we will remember this. Only the very bad status will @@ -469,9 +476,13 @@ private void callEntry(String _sEntry, ParameterHelper _aParam) { String sPSFile = aList.get(i); - // TODO: this information has to come out of the ini files - String sStatusRunThrough = ""; - String sStatusMessage = ""; + // Read information out of the ini files + String sIndexFile2 = FileHelper.appendPath(sPath, sPSFile + ".ini"); + IniFile aIniFile2 = new IniFile(sIndexFile2); + String sStatusRunThrough = aIniFile2.getValue("global", "state"); + String sStatusMessage = ""; // aIniFile2.getValue("global", "info"); + aIniFile2.close(); + String sHTMLFile = sPSFile + ".html"; aOutputter.indexLine(sHTMLFile, sPSFile, sStatusRunThrough, sStatusMessage); diff --git a/qadevOOo/runner/graphical/JPEGCreator.java b/qadevOOo/runner/graphical/JPEGCreator.java index a4336229e448..7deee0d0d8f6 100644 --- a/qadevOOo/runner/graphical/JPEGCreator.java +++ b/qadevOOo/runner/graphical/JPEGCreator.java @@ -61,7 +61,8 @@ public class JPEGCreator extends EnhancedComplexTestCase public void checkOneFile(String _sDocumentName, String _sResult, ParameterHelper _aParams) throws OfficeException { - GlobalLogWriter.println("Document: " + _sDocumentName + " results: " + _sResult); + GlobalLogWriter.println(" Document: " + _sDocumentName); + GlobalLogWriter.println(" results: " + _sResult); // IOffice aOffice = new Office(_aParams, _sResult); // aOffice.start(); // aOffice.load(_sDocumentName); diff --git a/qadevOOo/runner/graphical/JPEGEvaluator.java b/qadevOOo/runner/graphical/JPEGEvaluator.java index 07b265b62355..049e96b15999 100644 --- a/qadevOOo/runner/graphical/JPEGEvaluator.java +++ b/qadevOOo/runner/graphical/JPEGEvaluator.java @@ -51,6 +51,8 @@ public class JPEGEvaluator extends EnhancedComplexTestCase GlobalLogWriter.set(log); ParameterHelper aParam = new ParameterHelper(param); + // aParam.getTestParameters().put("current_ok_status", -1); + // run through all documents found in Inputpath foreachResultCreateHTML(aParam); } diff --git a/qadevOOo/runner/graphical/Office.java b/qadevOOo/runner/graphical/Office.java index 8ecee36cc742..59eeb160f2d9 100644 --- a/qadevOOo/runner/graphical/Office.java +++ b/qadevOOo/runner/graphical/Office.java @@ -48,6 +48,7 @@ public class Office implements IOffice m_sResult = _sResult; if (_aParam.getReferenceType().toLowerCase().equals("ooo") || + _aParam.getReferenceType().toLowerCase().equals("o3") || _aParam.getReferenceType().toLowerCase().equals("ps") || _aParam.getReferenceType().toLowerCase().equals("pdf")) { diff --git a/qadevOOo/runner/graphical/OpenOfficeDatabaseReportExtractor.java b/qadevOOo/runner/graphical/OpenOfficeDatabaseReportExtractor.java index 69083df762c2..930efd31d4cb 100644 --- a/qadevOOo/runner/graphical/OpenOfficeDatabaseReportExtractor.java +++ b/qadevOOo/runner/graphical/OpenOfficeDatabaseReportExtractor.java @@ -373,13 +373,20 @@ public class OpenOfficeDatabaseReportExtractor extends Assurance { String sReportName = sElementNames[i]; XComponent xDoc = loadComponent(sReportName, _xNameAccess, _aPropertyList); -// util.utils.shortWait(1000); - // print? or store? - String sDocumentPathName = storeComponent(sReportName, xDoc /*, _nType*/); - aList.add(sDocumentPathName); -// util.utils.shortWait(1000); - closeComponent(xDoc); -// util.utils.shortWait(1000); + if (xDoc != null) + { + // util.utils.shortWait(1000); + // print? or store? + String sDocumentPathName = storeComponent(sReportName, xDoc /*, _nType*/); + aList.add(sDocumentPathName); + // util.utils.shortWait(1000); + closeComponent(xDoc); + // util.utils.shortWait(1000); + } + else + { + System.out.println("Leave out maybe due to errors."); + } // sBackPath contains the path where to find the extracted ODB Document } } diff --git a/qadevOOo/runner/graphical/OpenOfficePostscriptCreator.java b/qadevOOo/runner/graphical/OpenOfficePostscriptCreator.java index d918634f8d30..7111d5e0f794 100644 --- a/qadevOOo/runner/graphical/OpenOfficePostscriptCreator.java +++ b/qadevOOo/runner/graphical/OpenOfficePostscriptCreator.java @@ -102,6 +102,7 @@ public class OpenOfficePostscriptCreator implements IOffice { String sDocumentName = FileHelper.appendPath(m_sOutputURL, m_sBasename); if (m_aParameterHelper.getReferenceType().toLowerCase().equals("ooo") || + m_aParameterHelper.getReferenceType().toLowerCase().equals("o3") || m_aParameterHelper.getReferenceType().toLowerCase().equals("ps") ) { String sPrintURL = sDocumentName + ".ps"; @@ -1380,9 +1381,9 @@ public class OpenOfficePostscriptCreator implements IOffice // Watcher Object is need in log object to give a simple way to say if a running office is alive. // As long as a log comes, it pings the Watcher and says the office is alive, if not an // internal counter increase and at a given point (300 seconds) the office is killed. - GlobalLogWriter.println("Set office watcher"); if (GlobalLogWriter.get().getWatcher() == null) { + GlobalLogWriter.println("Set office watcher"); OfficeWatcher aWatcher = (OfficeWatcher)m_aParameterHelper.getTestParameters().get("Watcher"); GlobalLogWriter.get().setWatcher(aWatcher); } diff --git a/qadevOOo/runner/graphical/ParameterHelper.java b/qadevOOo/runner/graphical/ParameterHelper.java index 598ee6c53007..a3608b191f63 100644 --- a/qadevOOo/runner/graphical/ParameterHelper.java +++ b/qadevOOo/runner/graphical/ParameterHelper.java @@ -267,7 +267,8 @@ public class ParameterHelper // check if MultiServiceFactory is given if (getReferenceType().toLowerCase().equals("pdf") || getReferenceType().toLowerCase().equals("ps") || - getReferenceType().toLowerCase().equals("ooo")) + getReferenceType().toLowerCase().equals("ooo") || + getReferenceType().toLowerCase().equals("o3") ) { if (xMSF == null) { diff --git a/qadevOOo/runner/graphical/PostscriptCreator.java b/qadevOOo/runner/graphical/PostscriptCreator.java index ab7ad4536fa6..7109b4851b1b 100644 --- a/qadevOOo/runner/graphical/PostscriptCreator.java +++ b/qadevOOo/runner/graphical/PostscriptCreator.java @@ -59,7 +59,8 @@ public class PostscriptCreator extends EnhancedComplexTestCase public void checkOneFile(String _sDocumentName, String _sResult, ParameterHelper _aParams) throws OfficeException { - GlobalLogWriter.println("Document: " + _sDocumentName + " results: " + _sResult); + GlobalLogWriter.println(" Document: " + _sDocumentName); + GlobalLogWriter.println(" results: " + _sResult); IOffice aOffice = new Office(_aParams, _sResult); PerformanceContainer a = new PerformanceContainer(); diff --git a/qadevOOo/runner/helper/OfficeProvider.java b/qadevOOo/runner/helper/OfficeProvider.java index 8589de47ea82..1d4950ee5404 100644 --- a/qadevOOo/runner/helper/OfficeProvider.java +++ b/qadevOOo/runner/helper/OfficeProvider.java @@ -59,7 +59,7 @@ import util.utils; public class OfficeProvider implements AppProvider { - protected static boolean debug = false; + private static boolean debug = false; /** * copy the user layer to a safe place, usualy to $TMP/user_backup$USER @@ -355,7 +355,7 @@ public class OfficeProvider implements AppProvider if (rInitialObject != null) { - debug = true; + // debug = true; dbg("resolved url"); xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, rInitialObject); @@ -434,7 +434,7 @@ public class OfficeProvider implements AppProvider { XMultiServiceFactory msf = null; String exc = ""; - debug = true; + // debug = true; dbg("trying to connect to " + cncstr); diff --git a/qadevOOo/runner/helper/ProcessHandler.java b/qadevOOo/runner/helper/ProcessHandler.java index f1d7685ce3df..c30a501e191c 100644 --- a/qadevOOo/runner/helper/ProcessHandler.java +++ b/qadevOOo/runner/helper/ProcessHandler.java @@ -26,6 +26,7 @@ ************************************************************************/ package helper; +import java.io.BufferedReader; import java.io.InputStream; import java.io.File; import java.io.PrintWriter; @@ -33,10 +34,12 @@ import java.io.PrintStream; import java.io.LineNumberReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.io.Writer; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import lib.TestParameters; +import share.LogWriter; import util.PropertyName; import util.utils; @@ -58,6 +61,7 @@ class Pump extends Thread private String pref; private StringBuffer buf = new StringBuffer(256); private PrintWriter log; + private boolean bOutput; /** * Creates Pump for specified <code>InputStream</code>. @@ -70,11 +74,12 @@ 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) + public Pump(InputStream is, PrintWriter log, String outPrefix, boolean _bOutput) { this.pref = (outPrefix == null) ? "" : outPrefix; reader = new LineNumberReader(new InputStreamReader(is)); this.log = log; + this.bOutput = _bOutput; start(); } @@ -85,8 +90,11 @@ class Pump extends Thread String line = reader.readLine(); while (line != null) { - log.println(pref + line); - log.flush(); + if (bOutput) + { + log.println(pref + line); + log.flush(); + } buf.append(line).append('\n'); line = reader.readLine(); } @@ -133,6 +141,11 @@ public class ProcessHandler private Process m_aProcess = null; private TestParameters param = null; private boolean debug = false; + private boolean bUseOutput = true; + + private int m_nProcessTimeout = 0; + private String m_sProcessKiller; + private ProcessWatcher m_aWatcher; /** * Creates instance with specified external command. @@ -348,6 +361,24 @@ public class ProcessHandler } /** + * If not equal 0, the time to maximal wait. + * @param _n + */ + public void setProcessTimeout(int _n) + { + m_nProcessTimeout = _n; + } + + /** + * This command will call after ProcessTimeout is arrived. + * @param _s + */ + public void setProcessKiller(String _s) + { + m_sProcessKiller = _s; + } + + /** * This method do an asynchronous execution of the commands. To avoid a interruption on long running processes * caused by <CODE>OfficeWatcher</CODE>, the OfficeWatcher get frequently a ping. * @see helper.OfficeWatcher @@ -395,7 +426,7 @@ public class ProcessHandler if (sOutputText.length() == memText.length()) { changedText = false; - // dbg("runCommand Could not detect changes in output stream!!!"); + // dbg("runCommand Could not detect changes in output stream!!!"); } hangcheck = 10; memText = this.getOutputText(); @@ -515,6 +546,21 @@ public class ProcessHandler return m_nExactStartTimeInMillisec; } + private void showEnvVars() + { + if (envVars != null) + { + for (int i = 0; i < envVars.length; i++) + { + log.println("env: " + envVars[i]); + } + } + else + { + log.println("env: null"); + } + } + protected void execute() { if (isStarted()) @@ -527,27 +573,32 @@ public class ProcessHandler { if (cmdLine == null) { - log.print(utils.getDateTime() + "execute: Starting command from array: "); + log.println(utils.getDateTime() + "execute: Starting command from array: "); for (int i = 0; i < cmdLineArray.length; i++) { - log.print(cmdLineArray[i]); - log.print(" "); + log.println(cmdLineArray[i]); + // log.print(" "); } + showEnvVars(); log.println(""); initialExactStartTime(); + initializeProcessKiller(); m_aProcess = runtime.exec(cmdLineArray, envVars); } else { if (workDir != null) { - log.println(utils.getDateTime() + "execute: Starting command: " + cmdLine + " " + - workDir.getAbsolutePath()); + log.println(utils.getDateTime() + "execute: Starting command: "); + log.println(cmdLine + " path=" + workDir.getAbsolutePath()); + showEnvVars(); m_aProcess = runtime.exec(cmdLine, envVars, workDir); } else { - log.println(utils.getDateTime() + "execute: Starting command: " + cmdLine); + log.println(utils.getDateTime() + "execute: Starting command: "); + log.println(cmdLine); + showEnvVars(); m_aProcess = runtime.exec(cmdLine, envVars); } } @@ -566,8 +617,8 @@ public class ProcessHandler return; } dbg("execute: pump io-streams"); - stdout = new Pump(m_aProcess.getInputStream(), log, "out > "); - stderr = new Pump(m_aProcess.getErrorStream(), log, "err > "); + stdout = new Pump(m_aProcess.getInputStream(), log, "out > ", bUseOutput); + stderr = new Pump(m_aProcess.getErrorStream(), log, "err > ", bUseOutput); stdIn = new PrintStream(m_aProcess.getOutputStream()); // int nExitValue = m_aProcess.exitValue(); @@ -821,4 +872,139 @@ public class ProcessHandler log.println(utils.getDateTime() + "PH." + message); } } + + public void noOutput() + { + bUseOutput = false; + } + // ------------------------------------------------------------------------- + class ProcessWatcher extends Thread + { + + private int m_nTimeoutInSec; + private String m_sProcessToStart; + private boolean m_bInterrupt; + + public ProcessWatcher(int _nTimeOut, String _sProcess) + { + m_nTimeoutInSec = _nTimeOut; + m_sProcessToStart = _sProcess; + m_bInterrupt = false; + } + + /** + * returns true, if the thread should hold on + * @return + */ + public synchronized boolean isInHoldOn() + { + return m_bInterrupt; + } + /** + * Marks the thread to hold on, next time + * STUPID: The thread must poll this flag itself. + * + * Reason: interrupt() seems not to work as expected. + */ + public synchronized void holdOn() + { + m_bInterrupt = true; + interrupt(); + } + + public void run() + { + while (m_nTimeoutInSec > 0) + { + m_nTimeoutInSec--; + try + { + sleep(1000); + } + catch(java.lang.InterruptedException e) + { + // interrupt flag is set back to 'not interrupted' :-( + } + if (isInHoldOn()) + { + break; + } + } + if (m_nTimeoutInSec <= 0 && !isInHoldOn()) // not zero, so we are interrupted. + { + system(m_sProcessToStart); + } + } + + /** + * Start an external Process + * @param _sProcess + */ + private void system(String _sProcess) + { + if (_sProcess == null) + { + return; + } + + try + { + + // run a _sProcess command + // using the Runtime exec method: + Process p = Runtime.getRuntime().exec(_sProcess); + + BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); + + BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); + + // read the output from the command + String s; + while ((s = stdInput.readLine()) != null) + { + System.out.println("out:" + s); + } + + // read any errors from the attempted command + while ((s = stdError.readLine()) != null) + { + System.out.println("err:" + s); + } + + } + catch (java.io.IOException e) + { + System.out.println("exception caught: "); + e.printStackTrace(); + } + + } + } + + /** + * If the timeout only given by setProcessTimeout(int seconds) function is != 0, + * a extra thread is created and after time has run out, the ProcessKiller string + * given by function setProcessKiller(string) will execute. + * So it is possible to kill a running office after a given time of seconds. + */ + private void initializeProcessKiller() + { + if (m_nProcessTimeout != 0) + { + m_aWatcher = new ProcessWatcher(m_nProcessTimeout, m_sProcessKiller); + m_aWatcher.start(); + } + } + + /** + * to stop the extra thread, before he will kill a running office. This will stop the thread. + */ + public void stopWatcher() + { + if (m_aWatcher != null) + { + m_aWatcher.holdOn(); + shortWait(5000); + } + } } diff --git a/qadevOOo/runner/org/openoffice/Runner.java b/qadevOOo/runner/org/openoffice/Runner.java index a3741774917e..ca995bc9b4f4 100644 --- a/qadevOOo/runner/org/openoffice/Runner.java +++ b/qadevOOo/runner/org/openoffice/Runner.java @@ -184,7 +184,7 @@ public class Runner public static boolean run(String... args) { - System.out.println("OOoRunner Main() version from 20100323 (yyyymmdd)"); + System.out.println("OOoRunner Main() version from 20101118 (yyyymmdd)"); setStartTime(getTime()); diff --git a/qadevOOo/runner/stats/Summarizer.java b/qadevOOo/runner/stats/Summarizer.java index b1fe5fe61dd3..5f4a58cc31f8 100644 --- a/qadevOOo/runner/stats/Summarizer.java +++ b/qadevOOo/runner/stats/Summarizer.java @@ -78,7 +78,7 @@ public class Summarizer { if (states.elementAt(j).equals("not part of the job")) { - state = "Not possible since not all Interfaces/Services have been checked"; + state = "PASSED(some interfaces/services not tested).OK"; } else { diff --git a/qadevOOo/tests/java/mod/_forms/GenericModelTest.java b/qadevOOo/tests/java/mod/_forms/GenericModelTest.java index dce88234885f..5ac071c38eb5 100644 --- a/qadevOOo/tests/java/mod/_forms/GenericModelTest.java +++ b/qadevOOo/tests/java/mod/_forms/GenericModelTest.java @@ -27,6 +27,7 @@ package mod._forms; import com.sun.star.beans.NamedValue; import com.sun.star.beans.PropertyValue; +import com.sun.star.container.XIndexAccess; import java.io.PrintWriter; import lib.StatusException; @@ -251,11 +252,10 @@ public class GenericModelTest extends TestCase { if (m_ConnectionColsed) return; try { + XIndexAccess forms = UnoRuntime.queryInterface( XIndexAccess.class, + FormTools.getForms( WriterTools.getDrawPage( m_xTextDoc ) ) ); XForm myForm = (XForm) AnyConverter.toObject(new Type(XForm.class), - (FormTools.getForms( - WriterTools.getDrawPage( - m_xTextDoc))) - .getByName("Standard")); + forms.getByIndex(0)); if (debug){ if (myForm == null){ @@ -269,18 +269,20 @@ public class GenericModelTest extends TestCase { } - XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, myForm); - XConnection connection = (XConnection) AnyConverter.toObject( - new Type(XConnection.class), - xSetProp.getPropertyValue("ActiveConnection")); - if (debug && connection == null){ - log.println("ERROR: could not get property 'ActiveConnection' from the XForm"); + XPropertySet xSetProp = UnoRuntime.queryInterface( XPropertySet.class, myForm ); + XConnection connection = UnoRuntime.queryInterface( XConnection.class, xSetProp.getPropertyValue( "ActiveConnection" ) ); + if ( connection == null ) + { + if ( debug ) + log.println("ERROR: could not get property 'ActiveConnection' from the XForm"); + } + else + { + connection.close(); } - - connection.close(); } catch (Exception e) { log.println("ERROR: Can't close the connection: " + e.toString()); + e.printStackTrace( log ); } log.println("closing data source..."); |