From 88d1e25d5c61d1d4ef12f0ac397db3c8b399564c Mon Sep 17 00:00:00 2001 From: sb Date: Fri, 14 May 2010 13:50:22 +0200 Subject: sb123: #i111598# OfficeConnection getFactory -> getComponentContext --- test/inc/test/officeconnection.hxx | 12 ++++++------ test/source/cpp/officeconnection.cxx | 23 ++++++++++++----------- test/source/java/OfficeConnection.java | 23 ++++++++++++----------- 3 files changed, 30 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/inc/test/officeconnection.hxx b/test/inc/test/officeconnection.hxx index 99a319d51a7e..45c0a370d3c4 100644 --- a/test/inc/test/officeconnection.hxx +++ b/test/inc/test/officeconnection.hxx @@ -33,8 +33,8 @@ #include "osl/process.h" #include "test/detail/testdllapi.hxx" -namespace com { namespace sun { namespace star { namespace lang { - class XMultiServiceFactory; +namespace com { namespace sun { namespace star { namespace uno { + class XComponentContext; } } } } namespace test { @@ -51,13 +51,13 @@ public: void tearDown(); - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > - getFactory() const; + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + getComponentContext() const; private: oslProcess process_; - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > - factory_; + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + context_; }; } diff --git a/test/source/cpp/officeconnection.cxx b/test/source/cpp/officeconnection.cxx index ccfd2cd0a069..c8c42873c4a8 100644 --- a/test/source/cpp/officeconnection.cxx +++ b/test/source/cpp/officeconnection.cxx @@ -30,8 +30,8 @@ #include "com/sun/star/connection/NoConnectException.hpp" #include "com/sun/star/frame/XDesktop.hpp" #include "com/sun/star/lang/DisposedException.hpp" -#include "com/sun/star/lang/XMultiServiceFactory.hpp" #include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" #include "cppuhelper/bootstrap.hxx" #include "cppunit/TestAssert.h" #include "osl/process.h" @@ -118,14 +118,14 @@ void OfficeConnection::setUp() { cppu::defaultBootstrap_InitialComponentContext())); for (;;) { try { - factory_ = - css::uno::Reference< css::lang::XMultiServiceFactory >( + context_ = + css::uno::Reference< css::uno::XComponentContext >( resolver->resolve( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uno:")) + desc + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - ";urp;StarOffice.ServiceManager"))), + ";urp;StarOffice.ComponentContext"))), css::uno::UNO_QUERY_THROW); break; } catch (css::connection::NoConnectException &) {} @@ -139,13 +139,14 @@ void OfficeConnection::setUp() { } void OfficeConnection::tearDown() { - if (factory_.is()) { + if (context_.is()) { css::uno::Reference< css::frame::XDesktop > desktop( - factory_->createInstance( + context_->getServiceManager()->createInstanceWithContext( rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")), + context_), css::uno::UNO_QUERY_THROW); - factory_.clear(); + context_.clear(); try { CPPUNIT_ASSERT(desktop->terminate()); desktop.clear(); @@ -165,9 +166,9 @@ void OfficeConnection::tearDown() { } } -css::uno::Reference< css::lang::XMultiServiceFactory > -OfficeConnection::getFactory() const { - return factory_; +css::uno::Reference< css::uno::XComponentContext > +OfficeConnection::getComponentContext() const { + return context_; } } diff --git a/test/source/java/OfficeConnection.java b/test/source/java/OfficeConnection.java index 6887c3bfa3cd..b0b08c1643fd 100644 --- a/test/source/java/OfficeConnection.java +++ b/test/source/java/OfficeConnection.java @@ -31,8 +31,8 @@ import com.sun.star.comp.helper.Bootstrap; import com.sun.star.connection.NoConnectException; import com.sun.star.frame.XDesktop; import com.sun.star.lang.DisposedException; -import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; @@ -85,11 +85,11 @@ public final class OfficeConnection { Bootstrap.createInitialComponentContext(null)); for (;;) { try { - factory = UnoRuntime.queryInterface( - XMultiServiceFactory.class, + context = UnoRuntime.queryInterface( + XComponentContext.class, resolver.resolve( "uno:" + description + - ";urp;StarOffice.ServiceManager")); + ";urp;StarOffice.ComponentContext")); break; } catch (NoConnectException e) {} if (process != null) { @@ -104,11 +104,12 @@ public final class OfficeConnection { throws InterruptedException, com.sun.star.uno.Exception { boolean desktopTerminated = true; - if (factory != null) { + if (context != null) { XDesktop desktop = UnoRuntime.queryInterface( XDesktop.class, - factory.createInstance("com.sun.star.frame.Desktop")); - factory = null; + context.getServiceManager().createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + context = null; try { desktopTerminated = desktop.terminate(); } catch (DisposedException e) {} @@ -130,10 +131,10 @@ public final class OfficeConnection { assertTrue(errTerminated); } - /** Obtain the service factory of the running OOo instance. + /** Obtain the component context of the running OOo instance. */ - public XMultiServiceFactory getFactory() { - return factory; + public XComponentContext getComponentContext() { + return context; } //TODO: get rid of this hack for legacy qa/unoapi tests @@ -217,5 +218,5 @@ public final class OfficeConnection { private Process process = null; private Forward outForward = null; private Forward errForward = null; - private XMultiServiceFactory factory = null; + private XComponentContext context = null; } -- cgit From af5cef5b1e2f3d76f52340bbd2ea8bd93cb5185d Mon Sep 17 00:00:00 2001 From: sb Date: Fri, 14 May 2010 16:22:06 +0200 Subject: sb123: #i111601# various additional test helper functionality --- test/inc/test/getargument.hxx | 44 -------------------------------- test/inc/test/gettestargument.hxx | 46 ++++++++++++++++++++++++++++++++++ test/prj/d.lst | 2 +- test/source/cpp/getargument.cxx | 7 +++++- test/source/cpp/getargument.hxx | 44 ++++++++++++++++++++++++++++++++ test/source/cpp/gettestargument.cxx | 43 +++++++++++++++++++++++++++++++ test/source/cpp/makefile.mk | 1 + test/source/cpp/officeconnection.cxx | 9 ++++--- test/source/java/Argument.java | 36 ++++++++++++++++++++++++++ test/source/java/OfficeConnection.java | 10 +++----- test/source/java/OfficeFileUrl.java | 42 +++++++++++++++++++++++++++++++ test/source/java/TestArgument.java | 39 ++++++++++++++++++++++++++++ test/source/java/makefile.mk | 6 ++++- 13 files changed, 271 insertions(+), 58 deletions(-) delete mode 100644 test/inc/test/getargument.hxx create mode 100644 test/inc/test/gettestargument.hxx create mode 100644 test/source/cpp/getargument.hxx create mode 100644 test/source/cpp/gettestargument.cxx create mode 100644 test/source/java/Argument.java create mode 100644 test/source/java/OfficeFileUrl.java create mode 100644 test/source/java/TestArgument.java (limited to 'test') diff --git a/test/inc/test/getargument.hxx b/test/inc/test/getargument.hxx deleted file mode 100644 index 1b4df29d2115..000000000000 --- a/test/inc/test/getargument.hxx +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************* -* 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 -* -* for a copy of the LGPLv3 License. -************************************************************************/ - -#ifndef INCLUDED_TEST_GETARGUMENT_HXX -#define INCLUDED_TEST_GETARGUMENT_HXX - -#include "sal/config.h" - -#include "test/detail/testdllapi.hxx" - -namespace rtl { class OUString; } - -namespace test { - -// Obtain the value of an argument tunneled in via an "arg-" bootstrap -// variable: -OOO_DLLPUBLIC_TEST bool getArgument( - rtl::OUString const & name, rtl::OUString * value); - -} - -#endif diff --git a/test/inc/test/gettestargument.hxx b/test/inc/test/gettestargument.hxx new file mode 100644 index 000000000000..21b9df7a097e --- /dev/null +++ b/test/inc/test/gettestargument.hxx @@ -0,0 +1,46 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +#ifndef INCLUDED_TEST_GETTESTARGUMENT_HXX +#define INCLUDED_TEST_GETTESTARGUMENT_HXX + +#include "sal/config.h" + +#include "test/detail/testdllapi.hxx" + +namespace rtl { class OUString; } + +namespace test { + +// Obtain the value of a test argument (tunneled in via an "arg-testarg." +// bootstrap variable): +OOO_DLLPUBLIC_TEST bool getTestArgument( + rtl::OUString const & name, rtl::OUString * value); + +} + +#endif diff --git a/test/prj/d.lst b/test/prj/d.lst index bcea8bee46fe..34218f54e974 100644 --- a/test/prj/d.lst +++ b/test/prj/d.lst @@ -5,7 +5,7 @@ mkdir: %_DEST%\inc%_EXT%\test\detail ..\%__SRC%\lib\libtest.dylib %_DEST%\lib%_EXT%\libtest.dylib ..\%__SRC%\lib\libtest.so %_DEST%\lib%_EXT%\libtest.so ..\inc\test\detail\testdllapi.hxx %_DEST%\inc%_EXT%\test\detail\testdllapi.hxx -..\inc\test\getargument.hxx %_DEST%\inc%_EXT%\test\getargument.hxx +..\inc\test\gettestargument.hxx %_DEST%\inc%_EXT%\test\gettestargument.hxx ..\inc\test\officeconnection.hxx %_DEST%\inc%_EXT%\test\officeconnection.hxx ..\inc\test\oustringostreaminserter.hxx %_DEST%\inc%_EXT%\test\oustringostreaminserter.hxx ..\inc\test\toabsolutefileurl.hxx %_DEST%\inc%_EXT%\test\toabsolutefileurl.hxx diff --git a/test/source/cpp/getargument.cxx b/test/source/cpp/getargument.cxx index 339c5c9c797d..0db144679d92 100644 --- a/test/source/cpp/getargument.cxx +++ b/test/source/cpp/getargument.cxx @@ -29,10 +29,13 @@ #include "rtl/bootstrap.hxx" #include "rtl/ustring.h" #include "rtl/ustring.hxx" -#include "test/getargument.hxx" + +#include "getargument.hxx" namespace test { +namespace detail { + bool getArgument(rtl::OUString const & name, rtl::OUString * value) { OSL_ASSERT(value != 0); return rtl::Bootstrap::get( @@ -40,3 +43,5 @@ bool getArgument(rtl::OUString const & name, rtl::OUString * value) { } } + +} diff --git a/test/source/cpp/getargument.hxx b/test/source/cpp/getargument.hxx new file mode 100644 index 000000000000..4ba7e0f47827 --- /dev/null +++ b/test/source/cpp/getargument.hxx @@ -0,0 +1,44 @@ +/************************************************************************* +* 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 +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef INCLUDED_TEST_SOURCE_CPP_GETARGUMENT_HXX +#define INCLUDED_TEST_SOURCE_CPP_GETARGUMENT_HXX + +#include "sal/config.h" + +namespace test { + +namespace detail { + +// Obtain the value of an argument tunneled in via an "arg-" bootstrap +// variable: +bool getArgument( + rtl::OUString const & name, rtl::OUString * value); + +} + +} + +#endif diff --git a/test/source/cpp/gettestargument.cxx b/test/source/cpp/gettestargument.cxx new file mode 100644 index 000000000000..757faa751d37 --- /dev/null +++ b/test/source/cpp/gettestargument.cxx @@ -0,0 +1,43 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +#include "sal/config.h" + +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "test/gettestargument.hxx" + +#include "getargument.hxx" + +namespace test { + +bool getTestArgument(rtl::OUString const & name, rtl::OUString * value) { + return detail::getArgument( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("testarg.")) + name, value); +} + +} diff --git a/test/source/cpp/makefile.mk b/test/source/cpp/makefile.mk index 8494bd4aaa05..1c2d5a8ca2ff 100644 --- a/test/source/cpp/makefile.mk +++ b/test/source/cpp/makefile.mk @@ -37,6 +37,7 @@ CFLAGSCXX += $(CPPUNIT_CFLAGS) SLOFILES = \ $(SLO)/getargument.obj \ + $(SLO)/gettestargument.obj \ $(SLO)/officeconnection.obj \ $(SLO)/toabsolutefileurl.obj diff --git a/test/source/cpp/officeconnection.cxx b/test/source/cpp/officeconnection.cxx index c8c42873c4a8..5ea493f0bd0d 100644 --- a/test/source/cpp/officeconnection.cxx +++ b/test/source/cpp/officeconnection.cxx @@ -37,10 +37,11 @@ #include "osl/process.h" #include "osl/time.h" #include "sal/types.h" -#include "test/getargument.hxx" #include "test/officeconnection.hxx" #include "test/toabsolutefileurl.hxx" +#include "getargument.hxx" + namespace { namespace css = com::sun::star; @@ -57,7 +58,7 @@ void OfficeConnection::setUp() { rtl::OUString desc; rtl::OUString argSoffice; CPPUNIT_ASSERT( - getArgument( + detail::getArgument( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("soffice")), &argSoffice)); if (argSoffice.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("path:"))) { @@ -78,7 +79,7 @@ void OfficeConnection::setUp() { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";urp"))); rtl::OUString argUser; CPPUNIT_ASSERT( - getArgument( + detail::getArgument( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), &argUser)); rtl::OUString userArg( rtl::OUString( @@ -94,7 +95,7 @@ void OfficeConnection::setUp() { acceptArg.pData, userArg.pData, jreArg.pData, classpathArg.pData }; rtl_uString ** envs = 0; rtl::OUString argEnv; - if (getArgument( + if (detail::getArgument( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env")), &argEnv)) { envs = &argEnv.pData; diff --git a/test/source/java/Argument.java b/test/source/java/Argument.java new file mode 100644 index 000000000000..4e2a781531a8 --- /dev/null +++ b/test/source/java/Argument.java @@ -0,0 +1,36 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package org.openoffice.test; + +final class Argument { + public static String get(String name) { + return System.getProperty("org.openoffice.test.arg." + name); + } + + private Argument() {} +} diff --git a/test/source/java/OfficeConnection.java b/test/source/java/OfficeConnection.java index b0b08c1643fd..fc6e78f5f108 100644 --- a/test/source/java/OfficeConnection.java +++ b/test/source/java/OfficeConnection.java @@ -49,17 +49,17 @@ public final class OfficeConnection { /** Start up an OOo instance. */ public void setUp() throws Exception { - String sofficeArg = getArgument("soffice"); + String sofficeArg = Argument.get("soffice"); if (sofficeArg.startsWith("path:")) { description = "pipe,name=oootest" + UUID.randomUUID(); ProcessBuilder pb = new ProcessBuilder( sofficeArg.substring("path:".length()), "-quickstart=no", "-nofirststartwizard", "-norestore", "-accept=" + description + ";urp", - "-env:UserInstallation=" + getArgument("user"), + "-env:UserInstallation=" + Argument.get("user"), "-env:UNO_JAVA_JFW_ENV_JREHOME=true", "-env:UNO_JAVA_JFW_ENV_CLASSPATH=true"); - String envArg = getArgument("env"); + String envArg = Argument.get("env"); if (envArg != null) { Map env = pb.environment(); int i = envArg.indexOf("="); @@ -142,10 +142,6 @@ public final class OfficeConnection { return description; } - private static String getArgument(String name) { - return System.getProperty("org.openoffice.test.arg." + name); - } - private static Integer waitForProcess(Process process, final long millis) throws InterruptedException { diff --git a/test/source/java/OfficeFileUrl.java b/test/source/java/OfficeFileUrl.java new file mode 100644 index 000000000000..1ab62e283e6a --- /dev/null +++ b/test/source/java/OfficeFileUrl.java @@ -0,0 +1,42 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package org.openoffice.test; + +import java.io.File; + +/** Obtain the office-internal absolute file URL of a given file. + */ +public final class OfficeFileUrl { + public static String getAbsolute(File file) { + return file.getAbsoluteFile().toURI().toString().replaceFirst( + "\\A[Ff][Ii][Ll][Ee]:/(?=[^/]|\\z)", "file:///"); + // file:/path -> file:///path + } + + private OfficeFileUrl() {} +} diff --git a/test/source/java/TestArgument.java b/test/source/java/TestArgument.java new file mode 100644 index 000000000000..1303d09e1ba2 --- /dev/null +++ b/test/source/java/TestArgument.java @@ -0,0 +1,39 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package org.openoffice.test; + +/** Obtain the value of a test argument (tunneled in via an + "org.openoffice.test.arg.testarg." system property). + */ +public final class TestArgument { + public static String get(String name) { + return Argument.get("testarg." + name); + } + + private TestArgument() {} +} diff --git a/test/source/java/makefile.mk b/test/source/java/makefile.mk index a541d532f158..86506f11cc0f 100644 --- a/test/source/java/makefile.mk +++ b/test/source/java/makefile.mk @@ -30,7 +30,11 @@ TARGET = java .IF "$(OOO_JUNIT_JAR)" != "" PACKAGE = org/openoffice/test -JAVAFILES = OfficeConnection.java +JAVAFILES = \ + Argument.java \ + OfficeConnection.java \ + OfficeFileUrl.java \ + TestArgument.java JARFILES = juh.jar ridl.jar unoil.jar EXTRAJARFILES = $(OOO_JUNIT_JAR) -- cgit From d4b1d9b75572fdcc55a925254943a3cf29354f98 Mon Sep 17 00:00:00 2001 From: sb Date: Mon, 17 May 2010 17:34:10 +0200 Subject: sb123: #i111655# when, within build env, calling javaldx within OOo installation sets, set UNO_JAVA_JFW_ENV_JREHOME, but not UNO_JAVA_JFW_ENV_CLASSPATH --- test/source/cpp/officeconnection.cxx | 5 +---- test/source/java/OfficeConnection.java | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/source/cpp/officeconnection.cxx b/test/source/cpp/officeconnection.cxx index 5ea493f0bd0d..d18f266ecb7d 100644 --- a/test/source/cpp/officeconnection.cxx +++ b/test/source/cpp/officeconnection.cxx @@ -87,12 +87,9 @@ void OfficeConnection::setUp() { toAbsoluteFileUrl(argUser)); rtl::OUString jreArg( RTL_CONSTASCII_USTRINGPARAM("-env:UNO_JAVA_JFW_ENV_JREHOME=true")); - rtl::OUString classpathArg( - RTL_CONSTASCII_USTRINGPARAM( - "-env:UNO_JAVA_JFW_ENV_CLASSPATH=true")); rtl_uString * args[] = { noquickArg.pData, nofirstArg.pData, norestoreArg.pData, - acceptArg.pData, userArg.pData, jreArg.pData, classpathArg.pData }; + acceptArg.pData, userArg.pData, jreArg.pData }; rtl_uString ** envs = 0; rtl::OUString argEnv; if (detail::getArgument( diff --git a/test/source/java/OfficeConnection.java b/test/source/java/OfficeConnection.java index fc6e78f5f108..f87947137167 100644 --- a/test/source/java/OfficeConnection.java +++ b/test/source/java/OfficeConnection.java @@ -57,8 +57,7 @@ public final class OfficeConnection { "-nofirststartwizard", "-norestore", "-accept=" + description + ";urp", "-env:UserInstallation=" + Argument.get("user"), - "-env:UNO_JAVA_JFW_ENV_JREHOME=true", - "-env:UNO_JAVA_JFW_ENV_CLASSPATH=true"); + "-env:UNO_JAVA_JFW_ENV_JREHOME=true"); String envArg = Argument.get("env"); if (envArg != null) { Map env = pb.environment(); -- cgit From 7bf6134dbcd5846782cbe91e5f6763da1953bdd2 Mon Sep 17 00:00:00 2001 From: Lars Langhans Date: Mon, 14 Jun 2010 13:39:43 +0200 Subject: sb123:#i111449# cleanups in module test --- test/prj/build.lst | 2 +- test/source/java/Argument.java | 36 ---- test/source/java/OfficeConnection.java | 217 --------------------- test/source/java/OfficeFileUrl.java | 42 ---- test/source/java/TestArgument.java | 39 ---- test/source/java/makefile.mk | 53 ----- test/source/java/org/openoffice/test/Argument.java | 36 ++++ .../java/org/openoffice/test/OfficeConnection.java | 217 +++++++++++++++++++++ .../java/org/openoffice/test/OfficeFileUrl.java | 42 ++++ .../java/org/openoffice/test/TestArgument.java | 39 ++++ test/source/java/org/openoffice/test/makefile.mk | 53 +++++ 11 files changed, 388 insertions(+), 388 deletions(-) delete mode 100644 test/source/java/Argument.java delete mode 100644 test/source/java/OfficeConnection.java delete mode 100644 test/source/java/OfficeFileUrl.java delete mode 100644 test/source/java/TestArgument.java delete mode 100644 test/source/java/makefile.mk create mode 100644 test/source/java/org/openoffice/test/Argument.java create mode 100644 test/source/java/org/openoffice/test/OfficeConnection.java create mode 100644 test/source/java/org/openoffice/test/OfficeFileUrl.java create mode 100644 test/source/java/org/openoffice/test/TestArgument.java create mode 100644 test/source/java/org/openoffice/test/makefile.mk (limited to 'test') diff --git a/test/prj/build.lst b/test/prj/build.lst index 1bf76d664a7a..5ef6353a1dc3 100644 --- a/test/prj/build.lst +++ b/test/prj/build.lst @@ -1,4 +1,4 @@ te test : BOOST:boost cppu cppuhelper CPPUNIT:cppunit javaunohelper offuh ridljar sal solenv unoil NULL te test\inc nmake - all inc NULL te test\source\cpp nmake - all source_cpp inc NULL -te test\source\java nmake - all source_java NULL +te test\source\java\org\openoffice\test nmake - all source_java NULL diff --git a/test/source/java/Argument.java b/test/source/java/Argument.java deleted file mode 100644 index 4e2a781531a8..000000000000 --- a/test/source/java/Argument.java +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************* -* -* 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 -* -* for a copy of the LGPLv3 License. -* -************************************************************************/ - -package org.openoffice.test; - -final class Argument { - public static String get(String name) { - return System.getProperty("org.openoffice.test.arg." + name); - } - - private Argument() {} -} diff --git a/test/source/java/OfficeConnection.java b/test/source/java/OfficeConnection.java deleted file mode 100644 index f87947137167..000000000000 --- a/test/source/java/OfficeConnection.java +++ /dev/null @@ -1,217 +0,0 @@ -/************************************************************************* -* 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 -* -* for a copy of the LGPLv3 License. -************************************************************************/ - -package org.openoffice.test; - -import com.sun.star.bridge.UnoUrlResolver; -import com.sun.star.bridge.XUnoUrlResolver; -import com.sun.star.comp.helper.Bootstrap; -import com.sun.star.connection.NoConnectException; -import com.sun.star.frame.XDesktop; -import com.sun.star.lang.DisposedException; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.util.Map; -import java.util.UUID; -import static org.junit.Assert.*; - -/** Start up and shut down an OOo instance. - - Details about the OOo instance are tunneled in via - org.openoffice.test.arg.... system properties. -*/ -public final class OfficeConnection { - /** Start up an OOo instance. - */ - public void setUp() throws Exception { - String sofficeArg = Argument.get("soffice"); - if (sofficeArg.startsWith("path:")) { - description = "pipe,name=oootest" + UUID.randomUUID(); - ProcessBuilder pb = new ProcessBuilder( - sofficeArg.substring("path:".length()), "-quickstart=no", - "-nofirststartwizard", "-norestore", - "-accept=" + description + ";urp", - "-env:UserInstallation=" + Argument.get("user"), - "-env:UNO_JAVA_JFW_ENV_JREHOME=true"); - String envArg = Argument.get("env"); - if (envArg != null) { - Map env = pb.environment(); - int i = envArg.indexOf("="); - if (i == -1) { - env.remove(envArg); - } else { - env.put(envArg.substring(0, i), envArg.substring(i + 1)); - } - } - process = pb.start(); - outForward = new Forward(process.getInputStream(), System.out); - outForward.start(); - errForward = new Forward(process.getErrorStream(), System.err); - errForward.start(); - } else if (sofficeArg.startsWith("connect:")) { - description = sofficeArg.substring("connect:".length()); - } else { - fail( - "\"soffice\" argument \"" + sofficeArg + - " starts with neither \"path:\" nor \"connect:\""); - } - XUnoUrlResolver resolver = UnoUrlResolver.create( - Bootstrap.createInitialComponentContext(null)); - for (;;) { - try { - context = UnoRuntime.queryInterface( - XComponentContext.class, - resolver.resolve( - "uno:" + description + - ";urp;StarOffice.ComponentContext")); - break; - } catch (NoConnectException e) {} - if (process != null) { - assertNull(waitForProcess(process, 1000)); // 1 sec - } - } - } - - /** Shut down the OOo instance. - */ - public void tearDown() - throws InterruptedException, com.sun.star.uno.Exception - { - boolean desktopTerminated = true; - if (context != null) { - XDesktop desktop = UnoRuntime.queryInterface( - XDesktop.class, - context.getServiceManager().createInstanceWithContext( - "com.sun.star.frame.Desktop", context)); - context = null; - try { - desktopTerminated = desktop.terminate(); - } catch (DisposedException e) {} - // it appears that DisposedExceptions can already happen while - // receiving the response of the terminate call - desktop = null; - } else if (process != null) { - process.destroy(); - } - int code = 0; - if (process != null) { - code = process.waitFor(); - } - boolean outTerminated = outForward == null || outForward.terminated(); - boolean errTerminated = errForward == null || errForward.terminated(); - assertTrue(desktopTerminated); - assertEquals(0, code); - assertTrue(outTerminated); - assertTrue(errTerminated); - } - - /** Obtain the component context of the running OOo instance. - */ - public XComponentContext getComponentContext() { - return context; - } - - //TODO: get rid of this hack for legacy qa/unoapi tests - public String getDescription() { - return description; - } - - private static Integer waitForProcess(Process process, final long millis) - throws InterruptedException - { - final Thread t1 = Thread.currentThread(); - Thread t2 = new Thread("waitForProcess") { - public void run() { - try { - Thread.currentThread().sleep(millis); - } catch (InterruptedException e) {} - t1.interrupt(); - } - }; - boolean old = Thread.interrupted(); - // clear interrupted status, get old status - t2.start(); - int n = 0; - boolean done = false; - try { - n = process.waitFor(); - done = true; - } catch (InterruptedException e) {} - t2.interrupt(); - try { - t2.join(); - } catch (InterruptedException e) { - t2.join(); - } - Thread.interrupted(); // clear interrupted status - if (old) { - t1.interrupt(); // reset old status - } - return done ? new Integer(n) : null; - } - - private static final class Forward extends Thread { - public Forward(InputStream in, PrintStream out) { - super("process output forwarder"); - this.in = in; - this.out = out; - } - - public void run() { - for (;;) { - byte[] buf = new byte[1024]; - int n; - try { - n = in.read(buf); - } catch (IOException e) { - throw new RuntimeException("wrapping", e); - } - if (n == -1) { - break; - } - out.write(buf, 0, n); - } - done = true; - } - - public boolean terminated() throws InterruptedException { - join(); - return done; - } - - private final InputStream in; - private final PrintStream out; - private boolean done = false; - } - - private String description; - private Process process = null; - private Forward outForward = null; - private Forward errForward = null; - private XComponentContext context = null; -} diff --git a/test/source/java/OfficeFileUrl.java b/test/source/java/OfficeFileUrl.java deleted file mode 100644 index 1ab62e283e6a..000000000000 --- a/test/source/java/OfficeFileUrl.java +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************* -* -* 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 -* -* for a copy of the LGPLv3 License. -* -************************************************************************/ - -package org.openoffice.test; - -import java.io.File; - -/** Obtain the office-internal absolute file URL of a given file. - */ -public final class OfficeFileUrl { - public static String getAbsolute(File file) { - return file.getAbsoluteFile().toURI().toString().replaceFirst( - "\\A[Ff][Ii][Ll][Ee]:/(?=[^/]|\\z)", "file:///"); - // file:/path -> file:///path - } - - private OfficeFileUrl() {} -} diff --git a/test/source/java/TestArgument.java b/test/source/java/TestArgument.java deleted file mode 100644 index 1303d09e1ba2..000000000000 --- a/test/source/java/TestArgument.java +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************* -* -* 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 -* -* for a copy of the LGPLv3 License. -* -************************************************************************/ - -package org.openoffice.test; - -/** Obtain the value of a test argument (tunneled in via an - "org.openoffice.test.arg.testarg." system property). - */ -public final class TestArgument { - public static String get(String name) { - return Argument.get("testarg." + name); - } - - private TestArgument() {} -} diff --git a/test/source/java/makefile.mk b/test/source/java/makefile.mk deleted file mode 100644 index 86506f11cc0f..000000000000 --- a/test/source/java/makefile.mk +++ /dev/null @@ -1,53 +0,0 @@ -#************************************************************************* -# 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 -# -# for a copy of the LGPLv3 License. -#***********************************************************************/ - -PRJ = ../.. -PRJNAME = test -TARGET = java - -.IF "$(OOO_JUNIT_JAR)" != "" - -PACKAGE = org/openoffice/test -JAVAFILES = \ - Argument.java \ - OfficeConnection.java \ - OfficeFileUrl.java \ - TestArgument.java -JARFILES = juh.jar ridl.jar unoil.jar -EXTRAJARFILES = $(OOO_JUNIT_JAR) - -JARTARGET = test.jar -JARCLASSDIRS = $(PACKAGE) -JARCLASSPATH = $(JARFILES) - # expect $(OOO_JUNIT_JAR) to be on CLASSPATH wherever test.jar is used (also, - # on Windows, $(OOO_JUNIT_JAR) could be an absolute pathname with drive letter - # like X:/path and some JVMs would refuse to load test.jar if its MANIFEST.MF - # Class-Path contained such a pathname that looks like an unknown URL with - # scheme X) - -.END - -.INCLUDE: settings.mk -.INCLUDE: target.mk diff --git a/test/source/java/org/openoffice/test/Argument.java b/test/source/java/org/openoffice/test/Argument.java new file mode 100644 index 000000000000..83c3f2417416 --- /dev/null +++ b/test/source/java/org/openoffice/test/Argument.java @@ -0,0 +1,36 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package org.openoffice.test; + +final public class Argument { + public static String get(String name) { + return System.getProperty("org.openoffice.test.arg." + name); + } + + private Argument() {} +} diff --git a/test/source/java/org/openoffice/test/OfficeConnection.java b/test/source/java/org/openoffice/test/OfficeConnection.java new file mode 100644 index 000000000000..f87947137167 --- /dev/null +++ b/test/source/java/org/openoffice/test/OfficeConnection.java @@ -0,0 +1,217 @@ +/************************************************************************* +* 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 +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +package org.openoffice.test; + +import com.sun.star.bridge.UnoUrlResolver; +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.connection.NoConnectException; +import com.sun.star.frame.XDesktop; +import com.sun.star.lang.DisposedException; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Map; +import java.util.UUID; +import static org.junit.Assert.*; + +/** Start up and shut down an OOo instance. + + Details about the OOo instance are tunneled in via + org.openoffice.test.arg.... system properties. +*/ +public final class OfficeConnection { + /** Start up an OOo instance. + */ + public void setUp() throws Exception { + String sofficeArg = Argument.get("soffice"); + if (sofficeArg.startsWith("path:")) { + description = "pipe,name=oootest" + UUID.randomUUID(); + ProcessBuilder pb = new ProcessBuilder( + sofficeArg.substring("path:".length()), "-quickstart=no", + "-nofirststartwizard", "-norestore", + "-accept=" + description + ";urp", + "-env:UserInstallation=" + Argument.get("user"), + "-env:UNO_JAVA_JFW_ENV_JREHOME=true"); + String envArg = Argument.get("env"); + if (envArg != null) { + Map env = pb.environment(); + int i = envArg.indexOf("="); + if (i == -1) { + env.remove(envArg); + } else { + env.put(envArg.substring(0, i), envArg.substring(i + 1)); + } + } + process = pb.start(); + outForward = new Forward(process.getInputStream(), System.out); + outForward.start(); + errForward = new Forward(process.getErrorStream(), System.err); + errForward.start(); + } else if (sofficeArg.startsWith("connect:")) { + description = sofficeArg.substring("connect:".length()); + } else { + fail( + "\"soffice\" argument \"" + sofficeArg + + " starts with neither \"path:\" nor \"connect:\""); + } + XUnoUrlResolver resolver = UnoUrlResolver.create( + Bootstrap.createInitialComponentContext(null)); + for (;;) { + try { + context = UnoRuntime.queryInterface( + XComponentContext.class, + resolver.resolve( + "uno:" + description + + ";urp;StarOffice.ComponentContext")); + break; + } catch (NoConnectException e) {} + if (process != null) { + assertNull(waitForProcess(process, 1000)); // 1 sec + } + } + } + + /** Shut down the OOo instance. + */ + public void tearDown() + throws InterruptedException, com.sun.star.uno.Exception + { + boolean desktopTerminated = true; + if (context != null) { + XDesktop desktop = UnoRuntime.queryInterface( + XDesktop.class, + context.getServiceManager().createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + context = null; + try { + desktopTerminated = desktop.terminate(); + } catch (DisposedException e) {} + // it appears that DisposedExceptions can already happen while + // receiving the response of the terminate call + desktop = null; + } else if (process != null) { + process.destroy(); + } + int code = 0; + if (process != null) { + code = process.waitFor(); + } + boolean outTerminated = outForward == null || outForward.terminated(); + boolean errTerminated = errForward == null || errForward.terminated(); + assertTrue(desktopTerminated); + assertEquals(0, code); + assertTrue(outTerminated); + assertTrue(errTerminated); + } + + /** Obtain the component context of the running OOo instance. + */ + public XComponentContext getComponentContext() { + return context; + } + + //TODO: get rid of this hack for legacy qa/unoapi tests + public String getDescription() { + return description; + } + + private static Integer waitForProcess(Process process, final long millis) + throws InterruptedException + { + final Thread t1 = Thread.currentThread(); + Thread t2 = new Thread("waitForProcess") { + public void run() { + try { + Thread.currentThread().sleep(millis); + } catch (InterruptedException e) {} + t1.interrupt(); + } + }; + boolean old = Thread.interrupted(); + // clear interrupted status, get old status + t2.start(); + int n = 0; + boolean done = false; + try { + n = process.waitFor(); + done = true; + } catch (InterruptedException e) {} + t2.interrupt(); + try { + t2.join(); + } catch (InterruptedException e) { + t2.join(); + } + Thread.interrupted(); // clear interrupted status + if (old) { + t1.interrupt(); // reset old status + } + return done ? new Integer(n) : null; + } + + private static final class Forward extends Thread { + public Forward(InputStream in, PrintStream out) { + super("process output forwarder"); + this.in = in; + this.out = out; + } + + public void run() { + for (;;) { + byte[] buf = new byte[1024]; + int n; + try { + n = in.read(buf); + } catch (IOException e) { + throw new RuntimeException("wrapping", e); + } + if (n == -1) { + break; + } + out.write(buf, 0, n); + } + done = true; + } + + public boolean terminated() throws InterruptedException { + join(); + return done; + } + + private final InputStream in; + private final PrintStream out; + private boolean done = false; + } + + private String description; + private Process process = null; + private Forward outForward = null; + private Forward errForward = null; + private XComponentContext context = null; +} diff --git a/test/source/java/org/openoffice/test/OfficeFileUrl.java b/test/source/java/org/openoffice/test/OfficeFileUrl.java new file mode 100644 index 000000000000..1ab62e283e6a --- /dev/null +++ b/test/source/java/org/openoffice/test/OfficeFileUrl.java @@ -0,0 +1,42 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package org.openoffice.test; + +import java.io.File; + +/** Obtain the office-internal absolute file URL of a given file. + */ +public final class OfficeFileUrl { + public static String getAbsolute(File file) { + return file.getAbsoluteFile().toURI().toString().replaceFirst( + "\\A[Ff][Ii][Ll][Ee]:/(?=[^/]|\\z)", "file:///"); + // file:/path -> file:///path + } + + private OfficeFileUrl() {} +} diff --git a/test/source/java/org/openoffice/test/TestArgument.java b/test/source/java/org/openoffice/test/TestArgument.java new file mode 100644 index 000000000000..1303d09e1ba2 --- /dev/null +++ b/test/source/java/org/openoffice/test/TestArgument.java @@ -0,0 +1,39 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package org.openoffice.test; + +/** Obtain the value of a test argument (tunneled in via an + "org.openoffice.test.arg.testarg." system property). + */ +public final class TestArgument { + public static String get(String name) { + return Argument.get("testarg." + name); + } + + private TestArgument() {} +} diff --git a/test/source/java/org/openoffice/test/makefile.mk b/test/source/java/org/openoffice/test/makefile.mk new file mode 100644 index 000000000000..94b629a69ed0 --- /dev/null +++ b/test/source/java/org/openoffice/test/makefile.mk @@ -0,0 +1,53 @@ +#************************************************************************* +# 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 +# +# for a copy of the LGPLv3 License. +#***********************************************************************/ + +PRJ = ../../../../.. +PRJNAME = test +TARGET = java + +.IF "$(OOO_JUNIT_JAR)" != "" + +PACKAGE = org/openoffice/test +JAVAFILES = \ + Argument.java \ + OfficeConnection.java \ + OfficeFileUrl.java \ + TestArgument.java +JARFILES = juh.jar ridl.jar unoil.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) + +JARTARGET = test.jar +JARCLASSDIRS = $(PACKAGE) +JARCLASSPATH = $(JARFILES) + # expect $(OOO_JUNIT_JAR) to be on CLASSPATH wherever test.jar is used (also, + # on Windows, $(OOO_JUNIT_JAR) could be an absolute pathname with drive letter + # like X:/path and some JVMs would refuse to load test.jar if its MANIFEST.MF + # Class-Path contained such a pathname that looks like an unknown URL with + # scheme X) + +.END + +.INCLUDE: settings.mk +.INCLUDE: target.mk -- cgit From 38f22192a435ce2df6dbb2a266df8feb97e0bd47 Mon Sep 17 00:00:00 2001 From: Lars Langhans Date: Tue, 29 Jun 2010 13:43:01 +0200 Subject: sb123:#i111449# cleanups in test environment --- .../java/org/openoffice/test/FileHelper.java | 63 ++++++++++++++++++++++ .../java/org/openoffice/test/OfficeConnection.java | 37 ++++++++----- test/source/java/org/openoffice/test/makefile.mk | 1 + 3 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 test/source/java/org/openoffice/test/FileHelper.java (limited to 'test') diff --git a/test/source/java/org/openoffice/test/FileHelper.java b/test/source/java/org/openoffice/test/FileHelper.java new file mode 100644 index 000000000000..bd1a00370479 --- /dev/null +++ b/test/source/java/org/openoffice/test/FileHelper.java @@ -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 + * + * for a copy of the LGPLv3 License. + * + * ************************************************************************ + */ + +package org.openoffice.test; + +/** + * + * @author ll93751 + */ +public class FileHelper +{ + public FileHelper() + { + } + /** + * Concat a _sRelativePathToAdd to a _sPath and append a '/' to the _sPath only if need. + * + * @param _sPath + * @param _sRelativePathToAdd + * @return a right concated path + */ + public static String appendPath(String _sPath, String _sRelativePathToAdd) + { + String sNewPath = _sPath; + String fs = System.getProperty("file.separator"); + if (_sPath.startsWith("file:")) + { + fs = "/"; // we use a file URL so only '/' is allowed. + } + if (! (sNewPath.endsWith("/") || sNewPath.endsWith("\\") ) ) + { + sNewPath += fs; + } + sNewPath += _sRelativePathToAdd; + return sNewPath; + } +} diff --git a/test/source/java/org/openoffice/test/OfficeConnection.java b/test/source/java/org/openoffice/test/OfficeConnection.java index f87947137167..a7c75557b217 100644 --- a/test/source/java/org/openoffice/test/OfficeConnection.java +++ b/test/source/java/org/openoffice/test/OfficeConnection.java @@ -31,6 +31,7 @@ import com.sun.star.comp.helper.Bootstrap; import com.sun.star.connection.NoConnectException; import com.sun.star.frame.XDesktop; import com.sun.star.lang.DisposedException; +import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import java.io.IOException; @@ -103,23 +104,31 @@ public final class OfficeConnection { throws InterruptedException, com.sun.star.uno.Exception { boolean desktopTerminated = true; - if (context != null) { - XDesktop desktop = UnoRuntime.queryInterface( - XDesktop.class, - context.getServiceManager().createInstanceWithContext( - "com.sun.star.frame.Desktop", context)); - context = null; - try { - desktopTerminated = desktop.terminate(); - } catch (DisposedException e) {} - // it appears that DisposedExceptions can already happen while - // receiving the response of the terminate call - desktop = null; - } else if (process != null) { + if (context != null) + { + XMultiComponentFactory xMSF = context.getServiceManager(); + if (xMSF != null) + { + XDesktop desktop = UnoRuntime.queryInterface( + XDesktop.class, + xMSF.createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + context = null; + try { + desktopTerminated = desktop.terminate(); + } catch (DisposedException e) {} + // it appears that DisposedExceptions can already happen while + // receiving the response of the terminate call + desktop = null; + } + } + else if (process != null) + { process.destroy(); } int code = 0; - if (process != null) { + if (process != null) + { code = process.waitFor(); } boolean outTerminated = outForward == null || outForward.terminated(); diff --git a/test/source/java/org/openoffice/test/makefile.mk b/test/source/java/org/openoffice/test/makefile.mk index 94b629a69ed0..9314ea6a1506 100644 --- a/test/source/java/org/openoffice/test/makefile.mk +++ b/test/source/java/org/openoffice/test/makefile.mk @@ -32,6 +32,7 @@ TARGET = java PACKAGE = org/openoffice/test JAVAFILES = \ Argument.java \ + FileHelper.java \ OfficeConnection.java \ OfficeFileUrl.java \ TestArgument.java -- cgit From 897c48e18e269a315eea6d9e465b12acbe7e6295 Mon Sep 17 00:00:00 2001 From: Lars Langhans Date: Fri, 2 Jul 2010 13:14:28 +0200 Subject: sb123:#i111449# cleanups --- test/source/java/org/openoffice/test/Argument.java | 2 +- .../java/org/openoffice/test/FileHelper.java | 3 +-- .../java/org/openoffice/test/OfficeConnection.java | 28 ++++++++++------------ 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/Argument.java b/test/source/java/org/openoffice/test/Argument.java index 83c3f2417416..0380375d8519 100644 --- a/test/source/java/org/openoffice/test/Argument.java +++ b/test/source/java/org/openoffice/test/Argument.java @@ -27,7 +27,7 @@ package org.openoffice.test; -final public class Argument { +public final class Argument { public static String get(String name) { return System.getProperty("org.openoffice.test.arg." + name); } diff --git a/test/source/java/org/openoffice/test/FileHelper.java b/test/source/java/org/openoffice/test/FileHelper.java index bd1a00370479..722b31124d43 100644 --- a/test/source/java/org/openoffice/test/FileHelper.java +++ b/test/source/java/org/openoffice/test/FileHelper.java @@ -30,8 +30,7 @@ package org.openoffice.test; /** - * - * @author ll93751 + * Helper Functions for File handling */ public class FileHelper { diff --git a/test/source/java/org/openoffice/test/OfficeConnection.java b/test/source/java/org/openoffice/test/OfficeConnection.java index a7c75557b217..26756ecd05c6 100644 --- a/test/source/java/org/openoffice/test/OfficeConnection.java +++ b/test/source/java/org/openoffice/test/OfficeConnection.java @@ -106,21 +106,19 @@ public final class OfficeConnection { boolean desktopTerminated = true; if (context != null) { - XMultiComponentFactory xMSF = context.getServiceManager(); - if (xMSF != null) - { - XDesktop desktop = UnoRuntime.queryInterface( - XDesktop.class, - xMSF.createInstanceWithContext( - "com.sun.star.frame.Desktop", context)); - context = null; - try { - desktopTerminated = desktop.terminate(); - } catch (DisposedException e) {} - // it appears that DisposedExceptions can already happen while - // receiving the response of the terminate call - desktop = null; - } + final XMultiComponentFactory xMSF = context.getServiceManager(); + assertNotNull("Can't get ServiceManager.", xMSF); + XDesktop desktop = UnoRuntime.queryInterface( + XDesktop.class, + xMSF.createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + context = null; + try { + desktopTerminated = desktop.terminate(); + } catch (DisposedException e) {} + // it appears that DisposedExceptions can already happen while + // receiving the response of the terminate call + desktop = null; } else if (process != null) { -- cgit From af970845ba8b95a84a45fc84f646c5e5c938f8cb Mon Sep 17 00:00:00 2001 From: sb Date: Tue, 6 Jul 2010 15:12:23 +0200 Subject: sb123: cleaned up the previous cleanup --- .../java/org/openoffice/test/OfficeConnection.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/OfficeConnection.java b/test/source/java/org/openoffice/test/OfficeConnection.java index 26756ecd05c6..e87efb210f62 100644 --- a/test/source/java/org/openoffice/test/OfficeConnection.java +++ b/test/source/java/org/openoffice/test/OfficeConnection.java @@ -104,13 +104,12 @@ public final class OfficeConnection { throws InterruptedException, com.sun.star.uno.Exception { boolean desktopTerminated = true; - if (context != null) - { - final XMultiComponentFactory xMSF = context.getServiceManager(); - assertNotNull("Can't get ServiceManager.", xMSF); + if (context != null) { + XMultiComponentFactory factory = context.getServiceManager(); + assertNotNull(factory); XDesktop desktop = UnoRuntime.queryInterface( XDesktop.class, - xMSF.createInstanceWithContext( + factory.createInstanceWithContext( "com.sun.star.frame.Desktop", context)); context = null; try { @@ -119,14 +118,11 @@ public final class OfficeConnection { // it appears that DisposedExceptions can already happen while // receiving the response of the terminate call desktop = null; - } - else if (process != null) - { + } else if (process != null) { process.destroy(); } int code = 0; - if (process != null) - { + if (process != null) { code = process.waitFor(); } boolean outTerminated = outForward == null || outForward.terminated(); -- cgit From e8d3f4cc2cc59fefcd2fb44165cc1a37eb9d5e1d Mon Sep 17 00:00:00 2001 From: sb Date: Tue, 6 Jul 2010 15:23:32 +0200 Subject: sb123: #i112519# do not terminate OOo accessed via OOO_TEST_SOFFICE=connect:... --- test/source/cpp/officeconnection.cxx | 31 ++++++++++---------- .../java/org/openoffice/test/OfficeConnection.java | 34 ++++++++++++---------- 2 files changed, 34 insertions(+), 31 deletions(-) (limited to 'test') diff --git a/test/source/cpp/officeconnection.cxx b/test/source/cpp/officeconnection.cxx index d18f266ecb7d..4baa18081379 100644 --- a/test/source/cpp/officeconnection.cxx +++ b/test/source/cpp/officeconnection.cxx @@ -137,22 +137,23 @@ void OfficeConnection::setUp() { } void OfficeConnection::tearDown() { - if (context_.is()) { - css::uno::Reference< css::frame::XDesktop > desktop( - context_->getServiceManager()->createInstanceWithContext( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")), - context_), - css::uno::UNO_QUERY_THROW); - context_.clear(); - try { - CPPUNIT_ASSERT(desktop->terminate()); - desktop.clear(); - } catch (css::lang::DisposedException &) {} - // it appears that DisposedExceptions can already happen while - // receiving the response of the terminate call - } if (process_ != 0) { + if (context_.is()) { + css::uno::Reference< css::frame::XDesktop > desktop( + context_->getServiceManager()->createInstanceWithContext( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.frame.Desktop")), + context_), + css::uno::UNO_QUERY_THROW); + context_.clear(); + try { + CPPUNIT_ASSERT(desktop->terminate()); + desktop.clear(); + } catch (css::lang::DisposedException &) {} + // it appears that DisposedExceptions can already happen while + // receiving the response of the terminate call + } CPPUNIT_ASSERT_EQUAL(osl_Process_E_None, osl_joinProcess(process_)); oslProcessInfo info; info.Size = sizeof info; diff --git a/test/source/java/org/openoffice/test/OfficeConnection.java b/test/source/java/org/openoffice/test/OfficeConnection.java index e87efb210f62..60978717a993 100644 --- a/test/source/java/org/openoffice/test/OfficeConnection.java +++ b/test/source/java/org/openoffice/test/OfficeConnection.java @@ -104,22 +104,24 @@ public final class OfficeConnection { throws InterruptedException, com.sun.star.uno.Exception { boolean desktopTerminated = true; - if (context != null) { - XMultiComponentFactory factory = context.getServiceManager(); - assertNotNull(factory); - XDesktop desktop = UnoRuntime.queryInterface( - XDesktop.class, - factory.createInstanceWithContext( - "com.sun.star.frame.Desktop", context)); - context = null; - try { - desktopTerminated = desktop.terminate(); - } catch (DisposedException e) {} - // it appears that DisposedExceptions can already happen while - // receiving the response of the terminate call - desktop = null; - } else if (process != null) { - process.destroy(); + if (process != null) { + if (context != null) { + XMultiComponentFactory factory = context.getServiceManager(); + assertNotNull(factory); + XDesktop desktop = UnoRuntime.queryInterface( + XDesktop.class, + factory.createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + context = null; + try { + desktopTerminated = desktop.terminate(); + } catch (DisposedException e) {} + // it appears that DisposedExceptions can already happen + // while receiving the response of the terminate call + desktop = null; + } else { + process.destroy(); + } } int code = 0; if (process != null) { -- cgit From 4699a135a27314e126ddbaa6d7d8e010d39c8aa5 Mon Sep 17 00:00:00 2001 From: sb Date: Wed, 7 Jul 2010 16:25:37 +0200 Subject: sb126: #i111184# introduced test::uniquePipeName --- test/inc/test/uniquepipename.hxx | 44 +++++++++++++++++++++++++++++++++ test/prj/d.lst | 1 + test/source/cpp/makefile.mk | 3 ++- test/source/cpp/officeconnection.cxx | 11 +++------ test/source/cpp/uniquepipename.cxx | 48 ++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 test/inc/test/uniquepipename.hxx create mode 100644 test/source/cpp/uniquepipename.cxx (limited to 'test') diff --git a/test/inc/test/uniquepipename.hxx b/test/inc/test/uniquepipename.hxx new file mode 100644 index 000000000000..4b96586a0299 --- /dev/null +++ b/test/inc/test/uniquepipename.hxx @@ -0,0 +1,44 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +#ifndef INCLUDED_TEST_UNIQUEPIPENAME_HXX +#define INCLUDED_TEST_UNIQUEPIPENAME_HXX + +#include "sal/config.h" + +#include "test/detail/testdllapi.hxx" + +namespace rtl { class OUString; } + +namespace test { + +// Create a system-wide unique name (for use with osl::Pipe): +OOO_DLLPUBLIC_TEST rtl::OUString uniquePipeName(rtl::OUString const & name); + +} + +#endif diff --git a/test/prj/d.lst b/test/prj/d.lst index bcea8bee46fe..6a3827d90309 100644 --- a/test/prj/d.lst +++ b/test/prj/d.lst @@ -9,4 +9,5 @@ mkdir: %_DEST%\inc%_EXT%\test\detail ..\inc\test\officeconnection.hxx %_DEST%\inc%_EXT%\test\officeconnection.hxx ..\inc\test\oustringostreaminserter.hxx %_DEST%\inc%_EXT%\test\oustringostreaminserter.hxx ..\inc\test\toabsolutefileurl.hxx %_DEST%\inc%_EXT%\test\toabsolutefileurl.hxx +..\inc\test\uniquepipename.hxx %_DEST%\inc%_EXT%\test\uniquepipename.hxx ..\%__SRC%\class\test.jar %_DEST%\bin%_EXT%\test.jar diff --git a/test/source/cpp/makefile.mk b/test/source/cpp/makefile.mk index 8494bd4aaa05..bb570cd2cc97 100644 --- a/test/source/cpp/makefile.mk +++ b/test/source/cpp/makefile.mk @@ -38,7 +38,8 @@ CFLAGSCXX += $(CPPUNIT_CFLAGS) SLOFILES = \ $(SLO)/getargument.obj \ $(SLO)/officeconnection.obj \ - $(SLO)/toabsolutefileurl.obj + $(SLO)/toabsolutefileurl.obj \ + $(SLO)/uniquepipename.obj SHL1IMPLIB = i$(SHL1TARGET) SHL1OBJS = $(SLOFILES) diff --git a/test/source/cpp/officeconnection.cxx b/test/source/cpp/officeconnection.cxx index ccfd2cd0a069..abf1d88fedb9 100644 --- a/test/source/cpp/officeconnection.cxx +++ b/test/source/cpp/officeconnection.cxx @@ -40,6 +40,7 @@ #include "test/getargument.hxx" #include "test/officeconnection.hxx" #include "test/toabsolutefileurl.hxx" +#include "test/uniquepipename.hxx" namespace { @@ -61,13 +62,9 @@ void OfficeConnection::setUp() { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("soffice")), &argSoffice)); if (argSoffice.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("path:"))) { - oslProcessInfo info; - info.Size = sizeof info; - CPPUNIT_ASSERT_EQUAL( - osl_Process_E_None, - osl_getProcessInfo(0, osl_Process_IDENTIFIER, &info)); - desc = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("pipe,name=oootest")) + - rtl::OUString::valueOf(static_cast< sal_Int64 >(info.Ident)); + desc = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("pipe,name=")) + + uniquePipeName( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("oootest"))); rtl::OUString noquickArg( RTL_CONSTASCII_USTRINGPARAM("-quickstart=no")); rtl::OUString nofirstArg( diff --git a/test/source/cpp/uniquepipename.cxx b/test/source/cpp/uniquepipename.cxx new file mode 100644 index 000000000000..c7614f4f3216 --- /dev/null +++ b/test/source/cpp/uniquepipename.cxx @@ -0,0 +1,48 @@ +/************************************************************************* +* +* 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 +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +#include "sal/config.h" + +#include "cppunit/TestAssert.h" +#include "osl/process.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "test/uniquepipename.hxx" + +namespace test { + +rtl::OUString uniquePipeName(rtl::OUString const & name) { + oslProcessInfo info; + info.Size = sizeof info; + CPPUNIT_ASSERT_EQUAL( + osl_Process_E_None, + osl_getProcessInfo(0, osl_Process_IDENTIFIER, &info)); + return name + rtl::OUString::valueOf(static_cast< sal_Int64 >(info.Ident)); +} + +} -- cgit From fab0859824dfdf60de2c5f0d9c7c41efe3364c31 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 3 Aug 2010 10:01:07 +0100 Subject: cmcfixes77: #i113503# system non-stlport cppunit with OOo stlport --- test/source/cpp/makefile.mk | 7 +++++++ test/source/cpp/officeconnection.cxx | 2 ++ 2 files changed, 9 insertions(+) (limited to 'test') diff --git a/test/source/cpp/makefile.mk b/test/source/cpp/makefile.mk index 8494bd4aaa05..04eedea3c670 100644 --- a/test/source/cpp/makefile.mk +++ b/test/source/cpp/makefile.mk @@ -35,6 +35,13 @@ VISIBILITY_HIDDEN = TRUE CDEFS += -DOOO_DLLIMPLEMENTATION_TEST CFLAGSCXX += $(CPPUNIT_CFLAGS) +#building with stlport, but cppunit was not built with stlport +.IF "$(USE_SYSTEM_STL)"!="YES" +.IF "$(SYSTEM_CPPUNIT)"=="YES" +CFLAGSCXX+=-DADAPT_EXT_STL +.ENDIF +.ENDIF + SLOFILES = \ $(SLO)/getargument.obj \ $(SLO)/officeconnection.obj \ diff --git a/test/source/cpp/officeconnection.cxx b/test/source/cpp/officeconnection.cxx index ccfd2cd0a069..b77fb59e4fff 100644 --- a/test/source/cpp/officeconnection.cxx +++ b/test/source/cpp/officeconnection.cxx @@ -33,7 +33,9 @@ #include "com/sun/star/lang/XMultiServiceFactory.hpp" #include "com/sun/star/uno/Reference.hxx" #include "cppuhelper/bootstrap.hxx" +#include #include "cppunit/TestAssert.h" +#include #include "osl/process.h" #include "osl/time.h" #include "sal/types.h" -- cgit From 5588b80f74960ba3e6c2cad18532564cf558b443 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 14 Oct 2010 16:40:31 +0200 Subject: undoapi: added tools (in test-tools.jar) for writing Java unit tests which operate on a live OOo --- test/prj/build.lst | 1 + test/prj/d.lst | 1 + test/source/java/org/openoffice/test/makefile.mk | 7 +- .../org/openoffice/test/tools/DocumentType.java | 60 ++++ .../org/openoffice/test/tools/OfficeDocument.java | 312 +++++++++++++++++++++ .../openoffice/test/tools/OfficeDocumentView.java | 125 +++++++++ .../openoffice/test/tools/SpreadsheetDocument.java | 73 +++++ .../org/openoffice/test/tools/SpreadsheetView.java | 72 +++++ .../java/org/openoffice/test/tools/makefile.mk | 41 +++ 9 files changed, 689 insertions(+), 3 deletions(-) create mode 100644 test/source/java/org/openoffice/test/tools/DocumentType.java create mode 100644 test/source/java/org/openoffice/test/tools/OfficeDocument.java create mode 100644 test/source/java/org/openoffice/test/tools/OfficeDocumentView.java create mode 100644 test/source/java/org/openoffice/test/tools/SpreadsheetDocument.java create mode 100644 test/source/java/org/openoffice/test/tools/SpreadsheetView.java create mode 100644 test/source/java/org/openoffice/test/tools/makefile.mk (limited to 'test') diff --git a/test/prj/build.lst b/test/prj/build.lst index 5ef6353a1dc3..7adea0c0727b 100644 --- a/test/prj/build.lst +++ b/test/prj/build.lst @@ -2,3 +2,4 @@ te test : BOOST:boost cppu cppuhelper CPPUNIT:cppunit javaunohelper offuh ridlja te test\inc nmake - all inc NULL te test\source\cpp nmake - all source_cpp inc NULL te test\source\java\org\openoffice\test nmake - all source_java NULL +te test\source\java\org\openoffice\test\tools nmake - all source_java_tools NULL diff --git a/test/prj/d.lst b/test/prj/d.lst index 48f9d8edba0c..54da2062a511 100644 --- a/test/prj/d.lst +++ b/test/prj/d.lst @@ -11,3 +11,4 @@ mkdir: %_DEST%\inc%_EXT%\test\detail ..\inc\test\toabsolutefileurl.hxx %_DEST%\inc%_EXT%\test\toabsolutefileurl.hxx ..\inc\test\uniquepipename.hxx %_DEST%\inc%_EXT%\test\uniquepipename.hxx ..\%__SRC%\class\test.jar %_DEST%\bin%_EXT%\test.jar +..\%__SRC%\class\test-tools.jar %_DEST%\bin%_EXT%\test-tools.jar diff --git a/test/source/java/org/openoffice/test/makefile.mk b/test/source/java/org/openoffice/test/makefile.mk index 9314ea6a1506..76e2ffe0bcda 100644 --- a/test/source/java/org/openoffice/test/makefile.mk +++ b/test/source/java/org/openoffice/test/makefile.mk @@ -39,9 +39,10 @@ JAVAFILES = \ JARFILES = juh.jar ridl.jar unoil.jar EXTRAJARFILES = $(OOO_JUNIT_JAR) -JARTARGET = test.jar -JARCLASSDIRS = $(PACKAGE) -JARCLASSPATH = $(JARFILES) +JARTARGET = test.jar +JARCLASSDIRS = $(PACKAGE) +JARCLASSEXCLUDES = $(PACKAGE)/tools/* FOOBAR +JARCLASSPATH = $(JARFILES) # expect $(OOO_JUNIT_JAR) to be on CLASSPATH wherever test.jar is used (also, # on Windows, $(OOO_JUNIT_JAR) could be an absolute pathname with drive letter # like X:/path and some JVMs would refuse to load test.jar if its MANIFEST.MF diff --git a/test/source/java/org/openoffice/test/tools/DocumentType.java b/test/source/java/org/openoffice/test/tools/DocumentType.java new file mode 100644 index 000000000000..cccf803cec81 --- /dev/null +++ b/test/source/java/org/openoffice/test/tools/DocumentType.java @@ -0,0 +1,60 @@ +/************************************************************************* + * + * 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 + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.test.tools; + +/** a helper "enumeration class" for classifying a document type +*/ +public class DocumentType extends com.sun.star.uno.Enum +{ + private DocumentType( int value ) + { + super( value ); + } + + public static DocumentType getDefault() + { + return WRITER; + } + + public static final DocumentType WRITER = new DocumentType(0); + public static final DocumentType CALC = new DocumentType(1); + public static final DocumentType DRAWING = new DocumentType(2); + public static final DocumentType XMLFORM = new DocumentType(3); + public static final DocumentType UNKNOWN = new DocumentType(-1); + + public static DocumentType fromInt(int value) + { + switch(value) + { + case 0: return WRITER; + case 1: return CALC; + case 2: return DRAWING; + case 3: return XMLFORM; + default: return UNKNOWN; + } + } +}; diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocument.java b/test/source/java/org/openoffice/test/tools/OfficeDocument.java new file mode 100644 index 000000000000..96db51138d67 --- /dev/null +++ b/test/source/java/org/openoffice/test/tools/OfficeDocument.java @@ -0,0 +1,312 @@ +/************************************************************************* + * + * 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 + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.test.tools; + +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.PropertyValue; +import com.sun.star.document.MacroExecMode; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPageSupplier; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.frame.XController; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.util.CloseVetoException; +import com.sun.star.util.XCloseable; +import com.sun.star.util.XModifiable; +import java.util.logging.Level; +import java.util.logging.Logger; + +/**************************************************************************/ + +/**************************************************************************/ +/** provides a small wrapper around a document +*/ +public class OfficeDocument +{ + /* ================================================================== */ + /* ------------------------------------------------------------------ */ + public OfficeDocument( XMultiServiceFactory orb, XComponent document ) + { + m_orb = orb; + m_documentComponent = document; + } + + /* ------------------------------------------------------------------ */ + protected static XComponent implLoadAsComponent( XMultiServiceFactory orb, String documentOrFactoryURL ) throws com.sun.star.uno.Exception + { + return implLoadAsComponent( orb, documentOrFactoryURL, new PropertyValue[0] ); + } + + /* ------------------------------------------------------------------ */ + protected static XComponent implLoadAsComponent( XMultiServiceFactory orb, String documentOrFactoryURL, final PropertyValue[] i_args ) throws com.sun.star.uno.Exception + { + XComponentLoader aLoader = UnoRuntime.queryInterface( XComponentLoader.class, + orb.createInstance( "com.sun.star.frame.Desktop" ) ); + + XComponent document = UnoRuntime.queryInterface( XComponent.class, + aLoader.loadComponentFromURL( documentOrFactoryURL, "_blank", 0, i_args ) + ); + return document; + } + + /* ------------------------------------------------------------------ */ + private static OfficeDocument implLoadDocument( XMultiServiceFactory orb, String documentOrFactoryURL ) throws com.sun.star.uno.Exception + { + return implLoadDocument( orb, documentOrFactoryURL, new PropertyValue[0] ); + } + + /* ------------------------------------------------------------------ */ + private static OfficeDocument implLoadDocument( XMultiServiceFactory orb, String documentOrFactoryURL, final PropertyValue[] i_args ) throws com.sun.star.uno.Exception + { + XComponent document = implLoadAsComponent( orb, documentOrFactoryURL, i_args ); + + XServiceInfo xSI = UnoRuntime.queryInterface( XServiceInfo.class, document ); + if ( xSI.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) ) + return new SpreadsheetDocument( orb, document ); + return new OfficeDocument( orb, document ); + } + + /* ------------------------------------------------------------------ */ + public static OfficeDocument loadDocument( XMultiServiceFactory orb, String documentURL ) throws com.sun.star.uno.Exception + { + return implLoadDocument( orb, documentURL ); + } + + /* ------------------------------------------------------------------ */ + public static OfficeDocument blankTextDocument( XMultiServiceFactory orb ) throws com.sun.star.uno.Exception + { + return blankDocument( orb, DocumentType.WRITER ); + } + + /* ------------------------------------------------------------------ */ + public static OfficeDocument blankXMLForm( XMultiServiceFactory orb ) throws com.sun.star.uno.Exception + { + return blankDocument( orb, DocumentType.XMLFORM ); + } + + /* ------------------------------------------------------------------ */ + public static OfficeDocument blankDocument( XMultiServiceFactory orb, DocumentType eType ) throws com.sun.star.uno.Exception + { + final PropertyValue[] args = new PropertyValue[] { + new PropertyValue( "MacroExecutionMode", -1, MacroExecMode.ALWAYS_EXECUTE, PropertyState.DIRECT_VALUE ) + }; + return implLoadDocument( orb, getDocumentFactoryURL( eType ), args ); + } + + /* ------------------------------------------------------------------ */ + public boolean close() + { + try + { + XCloseable closeDoc = UnoRuntime.queryInterface( XCloseable.class, m_documentComponent ); + closeDoc.close( true ); + return true; + } + catch ( CloseVetoException e ) + { + Logger.getLogger( OfficeDocument.class.getName() ).log( Level.SEVERE, "closing the document was vetoed", e ); + } + return false; + } + + /* ================================================================== */ + /* ------------------------------------------------------------------ */ + public XComponent getDocument( ) + { + return m_documentComponent; + } + + /* ------------------------------------------------------------------ */ + public boolean isModified() + { + XModifiable modify = (XModifiable)query( XModifiable.class ); + return modify.isModified(); + } + + /* ------------------------------------------------------------------ */ + public Object query( Class aInterfaceClass ) + { + return UnoRuntime.queryInterface( aInterfaceClass, m_documentComponent ); + } + + /* ------------------------------------------------------------------ */ + public XMultiServiceFactory getOrb( ) + { + return m_orb; + } + + /* ------------------------------------------------------------------ */ + /** retrieves the current view of the document + @return + the view component, queried for the interface described by aInterfaceClass + */ + public OfficeDocumentView getCurrentView( ) + { + // get the model interface for the document + XModel xDocModel = UnoRuntime.queryInterface( XModel.class, m_documentComponent ); + // get the current controller for the document - as a controller is tied to a view, + // this gives us the currently active view for the document. + XController xController = xDocModel.getCurrentController(); + + if ( classify() == DocumentType.CALC ) + return new SpreadsheetView( m_orb, this, xController ); + + return new OfficeDocumentView( m_orb, this, xController ); + } + + /* ------------------------------------------------------------------ */ + /** reloads the document + * + * The reload is done by dispatching the respective URL at a frame of the document. + * As a consequence, if you have references to a view of the document, or any interface + * of the document, they will become invalid. + * The Model instance itself, at which you called reload, will still be valid, it will + * automatically update its internal state after the reload. + * + * Another consequence is that if the document does not have a view at all, it cannot + * be reloaded. + */ + public void reload() throws Exception + { + OfficeDocumentView view = getCurrentView(); + XFrame frame = view.getController().getFrame(); + XModel oldModel = frame.getController().getModel(); + + getCurrentView().dispatch( ".uno:Reload" ); + + m_documentComponent = UnoRuntime.queryInterface( XComponent.class, frame.getController().getModel() ); + + XModel newModel = getCurrentView().getController().getModel(); + if ( UnoRuntime.areSame( oldModel, newModel ) ) + throw new java.lang.IllegalStateException( "reload failed" ); + } + + /* ------------------------------------------------------------------ */ + /** returns a URL which can be used to create a document of a certain type + */ + public static String getDocumentFactoryURL( DocumentType eType ) + { + if ( eType == DocumentType.WRITER ) + return "private:factory/swriter"; + if ( eType == DocumentType.CALC ) + return "private:factory/scalc"; + if ( eType == DocumentType.DRAWING ) + return "private:factory/sdraw"; + if ( eType == DocumentType.XMLFORM ) + return "private:factory/swriter?slot=21053"; + return "private:factory/swriter"; + } + + /* ------------------------------------------------------------------ */ + /** classifies a document + */ + public DocumentType classify( ) + { + XServiceInfo xSI = UnoRuntime.queryInterface( XServiceInfo.class, m_documentComponent ); + + if ( xSI.supportsService( "com.sun.star.text.TextDocument" ) ) + return DocumentType.WRITER; + else if ( xSI.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) ) + return DocumentType.CALC; + else if ( xSI.supportsService( "com.sun.star.drawing.DrawingDocument" ) ) + return DocumentType.DRAWING; + + return DocumentType.UNKNOWN; + } + + /* ------------------------------------------------------------------ */ + /** retrieves a com.sun.star.drawing.DrawPage of the document, denoted by index + * @param index + * the index of the draw page + * @throws + * com.sun.star.lang.IndexOutOfBoundsException + * com.sun.star.lang.WrappedTargetException + */ + protected XDrawPage getDrawPage( int index ) throws com.sun.star.lang.IndexOutOfBoundsException, com.sun.star.lang.WrappedTargetException + { + XDrawPagesSupplier xSuppPages = UnoRuntime.queryInterface( XDrawPagesSupplier.class, getDocument() ); + XDrawPages xPages = xSuppPages.getDrawPages(); + + return UnoRuntime.queryInterface( XDrawPage.class, xPages.getByIndex( index ) ); + } + + /* ------------------------------------------------------------------ */ + /** retrieves the DrawPage of the document + */ + protected XDrawPage getMainDrawPage( ) throws com.sun.star.uno.Exception + { + XDrawPage xReturn; + + // in case of a Writer document, this is rather easy: simply ask the XDrawPageSupplier + XDrawPageSupplier xSuppPage = UnoRuntime.queryInterface( XDrawPageSupplier.class, getDocument() ); + if ( null != xSuppPage ) + xReturn = xSuppPage.getDrawPage(); + else + { // the model itself is no draw page supplier - okay, it may be a Writer or Calc document + // (or any other multi-page document) + XDrawPagesSupplier xSuppPages = UnoRuntime.queryInterface( XDrawPagesSupplier.class, getDocument() ); + XDrawPages xPages = xSuppPages.getDrawPages(); + + xReturn = UnoRuntime.queryInterface( XDrawPage.class, xPages.getByIndex( 0 ) ); + + // Note that this is no really error-proof code: If the document model does not support the + // XDrawPagesSupplier interface, or if the pages collection returned is empty, this will break. + } + + return xReturn; + } + + /* ------------------------------------------------------------------ */ + /** creates a component at the service factory provided by the document + */ + public XInterface createInstance( String serviceSpecifier ) throws com.sun.star.uno.Exception + { + XMultiServiceFactory xORB = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_documentComponent ); + return (XInterface)xORB.createInstance( serviceSpecifier ); + } + + /* ------------------------------------------------------------------ */ + /** creates a component at the service factory provided by the document + */ + public XInterface createInstanceWithArguments( String serviceSpecifier, Object[] arguments ) throws com.sun.star.uno.Exception + { + XMultiServiceFactory xORB = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_documentComponent ); + return (XInterface) xORB.createInstanceWithArguments( serviceSpecifier, arguments ); + } + + private XMultiServiceFactory m_orb; + private XComponent m_documentComponent; +}; + diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java new file mode 100644 index 000000000000..beba6b3b3a38 --- /dev/null +++ b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java @@ -0,0 +1,125 @@ +/************************************************************************* + * + * 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 + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.test.tools; + +/**************************************************************************/ + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XController; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.URL; +import com.sun.star.util.XURLTransformer; + +/**************************************************************************/ +/** provides a small wrapper around a document view +*/ +public class OfficeDocumentView +{ + private XMultiServiceFactory m_orb; + private XController m_controller; + private OfficeDocument m_document; + + /* ------------------------------------------------------------------ */ + final protected XController getController() + { + return m_controller; + } + + /* ------------------------------------------------------------------ */ + final protected OfficeDocument getDocument() + { + return m_document; + } + + /* ------------------------------------------------------------------ */ + public OfficeDocumentView( XMultiServiceFactory orb, OfficeDocument document, XController controller ) + { + m_orb = orb; + m_document = document; + m_controller = controller; + } + + /* ------------------------------------------------------------------ */ + /** retrieves a dispatcher for the given URL, obtained at the current view of the document + @param aURL + a one-element array. The first element must contain a valid + URL::Complete value. Upon return, the URL is correctly + parsed. + @return + the dispatcher for the URL in question + */ + public XDispatch getDispatcher( URL[] aURL ) throws java.lang.Exception + { + XDispatch xReturn = null; + + // go get the dispatch provider of it's frame + XDispatchProvider xProvider = UnoRuntime.queryInterface( XDispatchProvider.class, m_controller.getFrame() ); + if ( null != xProvider ) + { + // need an URLTransformer + XURLTransformer xTransformer = UnoRuntime.queryInterface( XURLTransformer.class, + m_orb.createInstance( "com.sun.star.util.URLTransformer" ) ); + xTransformer.parseStrict( aURL ); + + xReturn = xProvider.queryDispatch( aURL[0], new String( ), 0 ); + } + return xReturn; + } + + /* ------------------------------------------------------------------ */ + /** retrieves a dispatcher for the given URL, obtained at the current view of the document + */ + public XDispatch getDispatcher( String url ) throws java.lang.Exception + { + URL[] aURL = new URL[] { new URL() }; + aURL[0].Complete = url; + return getDispatcher( aURL ); + } + + /* ------------------------------------------------------------------ */ + /** dispatches the given URL into the view, if there's a dispatcher for it + + @return + if the URL was successfully dispatched + */ + public boolean dispatch( String url ) throws java.lang.Exception + { + URL[] completeURL = new URL[] { new URL() }; + completeURL[0].Complete = url; + XDispatch dispatcher = getDispatcher( completeURL ); + if ( dispatcher == null ) + return false; + + PropertyValue[] aDummyArgs = new PropertyValue[] { }; + dispatcher.dispatch( completeURL[0], aDummyArgs ); + return true; + } +}; + diff --git a/test/source/java/org/openoffice/test/tools/SpreadsheetDocument.java b/test/source/java/org/openoffice/test/tools/SpreadsheetDocument.java new file mode 100644 index 000000000000..83b4028eec32 --- /dev/null +++ b/test/source/java/org/openoffice/test/tools/SpreadsheetDocument.java @@ -0,0 +1,73 @@ +/************************************************************************* + * + * 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 + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.test.tools; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XComponent; +import com.sun.star.table.XCellRange; +import com.sun.star.container.XIndexAccess; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.sheet.XSpreadsheets; +import com.sun.star.uno.UnoRuntime; + +/** + * @author frank.schoenheit@oracle.com + */ +public class SpreadsheetDocument extends OfficeDocument +{ + /** Creates a new blank spreadsheet document */ + /* ------------------------------------------------------------------ */ + public SpreadsheetDocument( XMultiServiceFactory orb ) throws com.sun.star.uno.Exception + { + super( orb, implLoadAsComponent( orb, "private:factory/scalc" ) ); + } + + /* ------------------------------------------------------------------ */ + public SpreadsheetDocument( XMultiServiceFactory orb, XComponent document ) throws com.sun.star.uno.Exception + { + super( orb, document ); + } + + /* ------------------------------------------------------------------ */ + /** returns the sheets collection + */ + public XSpreadsheets getSheets() throws com.sun.star.uno.Exception + { + XSpreadsheetDocument spreadsheetDoc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, getDocument() ); + return spreadsheetDoc.getSheets(); + } + + /* ------------------------------------------------------------------ */ + /** returns the sheet with the given index + */ + public XCellRange getSheet( int index ) throws com.sun.star.uno.Exception + { + XIndexAccess sheets = UnoRuntime.queryInterface( XIndexAccess.class, getSheets() ); + return UnoRuntime.queryInterface( XCellRange.class, sheets.getByIndex( index ) ); + } +} diff --git a/test/source/java/org/openoffice/test/tools/SpreadsheetView.java b/test/source/java/org/openoffice/test/tools/SpreadsheetView.java new file mode 100644 index 000000000000..34cb8b0813e4 --- /dev/null +++ b/test/source/java/org/openoffice/test/tools/SpreadsheetView.java @@ -0,0 +1,72 @@ +/************************************************************************* + * + * 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 + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.test.tools; + +import com.sun.star.container.XIndexAccess; +import com.sun.star.frame.XController; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sheet.XSpreadsheet; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.sheet.XSpreadsheetView; +import com.sun.star.uno.UnoRuntime; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author frank.schoenheit@oracle.com + */ +public class SpreadsheetView extends OfficeDocumentView +{ + + /** Creates a new instance of SpreadsheetView */ + public SpreadsheetView( XMultiServiceFactory orb, OfficeDocument document, XController controller ) + { + super( orb, document, controller ); + } + + /** activates the sheet with the given index + */ + void activateSheet( int sheetIndex ) + { + try + { + // get the sheet to activate + XSpreadsheetDocument doc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, getDocument().getDocument() ); + XIndexAccess sheets = UnoRuntime.queryInterface( XIndexAccess.class, doc.getSheets() ); + + XSpreadsheet sheet = UnoRuntime.queryInterface( XSpreadsheet.class, sheets.getByIndex( sheetIndex ) ); + + // activate + XSpreadsheetView view = UnoRuntime.queryInterface( XSpreadsheetView.class, getController() ); + view.setActiveSheet( sheet ); + } + catch( com.sun.star.uno.Exception e ) + { + Logger.getLogger( SpreadsheetView.class.getName() ).log( Level.SEVERE, "unable to activate the given sheet", e ); + } + } +} diff --git a/test/source/java/org/openoffice/test/tools/makefile.mk b/test/source/java/org/openoffice/test/tools/makefile.mk new file mode 100644 index 000000000000..ec7d191e6b10 --- /dev/null +++ b/test/source/java/org/openoffice/test/tools/makefile.mk @@ -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 +# +# for a copy of the LGPLv3 License. +#***********************************************************************/ + +PRJ = ../../../../../.. +PRJNAME = test +TARGET = java + +PACKAGE = org/openoffice/test/tools + +JARFILES = juh.jar ridl.jar unoil.jar +JAVAFILES = $(shell @$(FIND) . -name "*.java") + +JARTARGET = test-tools.jar +JARCLASSDIRS = $(PACKAGE) +JARCLASSPATH = $(JARFILES) + +.INCLUDE: settings.mk +.INCLUDE: target.mk + -- cgit From 192aeb2871ac755cdd4fbb18ea521fda77ae921d Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 15 Oct 2010 13:32:00 +0200 Subject: undoapi: fixed makefiles --- test/source/java/org/openoffice/test/makefile.mk | 6 +++--- test/source/java/org/openoffice/test/tools/makefile.mk | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/makefile.mk b/test/source/java/org/openoffice/test/makefile.mk index 76e2ffe0bcda..8340f144aed3 100644 --- a/test/source/java/org/openoffice/test/makefile.mk +++ b/test/source/java/org/openoffice/test/makefile.mk @@ -25,7 +25,7 @@ PRJ = ../../../../.. PRJNAME = test -TARGET = java +TARGET = test .IF "$(OOO_JUNIT_JAR)" != "" @@ -39,9 +39,9 @@ JAVAFILES = \ JARFILES = juh.jar ridl.jar unoil.jar EXTRAJARFILES = $(OOO_JUNIT_JAR) -JARTARGET = test.jar +JARTARGET = $(TARGET).jar JARCLASSDIRS = $(PACKAGE) -JARCLASSEXCLUDES = $(PACKAGE)/tools/* FOOBAR +JARCLASSEXCLUDES = $(PACKAGE)/tools/* JARCLASSPATH = $(JARFILES) # expect $(OOO_JUNIT_JAR) to be on CLASSPATH wherever test.jar is used (also, # on Windows, $(OOO_JUNIT_JAR) could be an absolute pathname with drive letter diff --git a/test/source/java/org/openoffice/test/tools/makefile.mk b/test/source/java/org/openoffice/test/tools/makefile.mk index ec7d191e6b10..1464bb958d49 100644 --- a/test/source/java/org/openoffice/test/tools/makefile.mk +++ b/test/source/java/org/openoffice/test/tools/makefile.mk @@ -25,17 +25,25 @@ PRJ = ../../../../../.. PRJNAME = test -TARGET = java +TARGET = test-tools PACKAGE = org/openoffice/test/tools +.INCLUDE: settings.mk + JARFILES = juh.jar ridl.jar unoil.jar -JAVAFILES = $(shell @$(FIND) . -name "*.java") +JAVAFILES = \ + OfficeDocument.java \ + OfficeDocumentView.java \ + DocumentType.java \ + SpreadsheetDocument.java \ + SpreadsheetView.java \ -JARTARGET = test-tools.jar +JARTARGET = $(TARGET).jar JARCLASSDIRS = $(PACKAGE) JARCLASSPATH = $(JARFILES) -.INCLUDE: settings.mk .INCLUDE: target.mk +test: + echo $(JAVACLASSFILES) -- cgit From 4a8b1355d87b3e3457b61c050192557f742f6eb6 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 15 Oct 2010 23:39:06 +0200 Subject: undoapi: tests for Draw docs' Undo --- test/source/java/org/openoffice/test/tools/OfficeDocument.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocument.java b/test/source/java/org/openoffice/test/tools/OfficeDocument.java index 96db51138d67..2a051fddad46 100644 --- a/test/source/java/org/openoffice/test/tools/OfficeDocument.java +++ b/test/source/java/org/openoffice/test/tools/OfficeDocument.java @@ -297,6 +297,14 @@ public class OfficeDocument return (XInterface)xORB.createInstance( serviceSpecifier ); } + /* ------------------------------------------------------------------ */ + /** creates a component at the service factory provided by the document, queried for a given interface type + */ + public T createInstance( String i_serviceSpecifier, Class i_interfaceClass ) throws com.sun.star.uno.Exception + { + return UnoRuntime.queryInterface( i_interfaceClass, createInstance( i_serviceSpecifier ) ); + } + /* ------------------------------------------------------------------ */ /** creates a component at the service factory provided by the document */ -- cgit From 80b680882f93882ed5016921cfab23fad666b7ba Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 19 Oct 2010 13:02:51 +0200 Subject: undoapi: added PRESENTATION/FORMULAR doc types --- test/source/java/org/openoffice/test/tools/DocumentType.java | 4 ++++ test/source/java/org/openoffice/test/tools/OfficeDocument.java | 8 ++++++++ 2 files changed, 12 insertions(+) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/tools/DocumentType.java b/test/source/java/org/openoffice/test/tools/DocumentType.java index cccf803cec81..bf310c5ed0fa 100644 --- a/test/source/java/org/openoffice/test/tools/DocumentType.java +++ b/test/source/java/org/openoffice/test/tools/DocumentType.java @@ -44,6 +44,8 @@ public class DocumentType extends com.sun.star.uno.Enum public static final DocumentType CALC = new DocumentType(1); public static final DocumentType DRAWING = new DocumentType(2); public static final DocumentType XMLFORM = new DocumentType(3); + public static final DocumentType PRESENTATION = new DocumentType(4); + public static final DocumentType FORMULA = new DocumentType(5); public static final DocumentType UNKNOWN = new DocumentType(-1); public static DocumentType fromInt(int value) @@ -54,6 +56,8 @@ public class DocumentType extends com.sun.star.uno.Enum case 1: return CALC; case 2: return DRAWING; case 3: return XMLFORM; + case 4: return PRESENTATION; + case 5: return FORMULA; default: return UNKNOWN; } } diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocument.java b/test/source/java/org/openoffice/test/tools/OfficeDocument.java index 2a051fddad46..bfb76a347e1c 100644 --- a/test/source/java/org/openoffice/test/tools/OfficeDocument.java +++ b/test/source/java/org/openoffice/test/tools/OfficeDocument.java @@ -226,6 +226,10 @@ public class OfficeDocument return "private:factory/sdraw"; if ( eType == DocumentType.XMLFORM ) return "private:factory/swriter?slot=21053"; + if ( eType == DocumentType.PRESENTATION ) + return "private:factory/simpress"; + if ( eType == DocumentType.FORMULA ) + return "private:factory/smath"; return "private:factory/swriter"; } @@ -242,6 +246,10 @@ public class OfficeDocument return DocumentType.CALC; else if ( xSI.supportsService( "com.sun.star.drawing.DrawingDocument" ) ) return DocumentType.DRAWING; + else if ( xSI.supportsService( "com.sun.star.presentation.PresentationDocument" ) ) + return DocumentType.PRESENTATION; + else if ( xSI.supportsService( "com.sun.star.formula.FormulaProperties" ) ) + return DocumentType.FORMULA; return DocumentType.UNKNOWN; } -- cgit From 555e27b5a04b35fa039f802567b4b21199e14894 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 22 Oct 2010 15:58:29 +0200 Subject: undoapi: don't throw too generously --- test/source/java/org/openoffice/test/tools/OfficeDocumentView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java index beba6b3b3a38..da22ade339f6 100644 --- a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java +++ b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java @@ -75,7 +75,7 @@ public class OfficeDocumentView @return the dispatcher for the URL in question */ - public XDispatch getDispatcher( URL[] aURL ) throws java.lang.Exception + public XDispatch getDispatcher( URL[] aURL ) throws com.sun.star.uno.Exception { XDispatch xReturn = null; @@ -96,7 +96,7 @@ public class OfficeDocumentView /* ------------------------------------------------------------------ */ /** retrieves a dispatcher for the given URL, obtained at the current view of the document */ - public XDispatch getDispatcher( String url ) throws java.lang.Exception + public XDispatch getDispatcher( String url ) throws com.sun.star.uno.Exception { URL[] aURL = new URL[] { new URL() }; aURL[0].Complete = url; @@ -109,7 +109,7 @@ public class OfficeDocumentView @return if the URL was successfully dispatched */ - public boolean dispatch( String url ) throws java.lang.Exception + public boolean dispatch( String url ) throws com.sun.star.uno.Exception { URL[] completeURL = new URL[] { new URL() }; completeURL[0].Complete = url; -- cgit From 49230835a7da7e7da394e7202c21c4e5c5b084b6 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 4 Nov 2010 10:51:04 +0100 Subject: undoapi: added tests for OOo's auto-closing of Undo contexts after executing scripts which do not properly do this themselves --- test/source/java/org/openoffice/test/tools/OfficeDocumentView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java index da22ade339f6..841607d9a377 100644 --- a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java +++ b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java @@ -47,7 +47,7 @@ public class OfficeDocumentView private OfficeDocument m_document; /* ------------------------------------------------------------------ */ - final protected XController getController() + final public XController getController() { return m_controller; } -- cgit From ed89443a2c555a1f3d605c6d605c1f7a730fc632 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 15 Nov 2010 22:12:20 +0100 Subject: undoapi: step 2.1 of the migration of css.chart2.XUndoManager to css.document.XUndoManager: implement an XUndoManager/Supplier for chart documents --- .../openoffice/test/tools/OfficeDocumentView.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java index 841607d9a377..9d5db59ac009 100644 --- a/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java +++ b/test/source/java/org/openoffice/test/tools/OfficeDocumentView.java @@ -28,6 +28,8 @@ package org.openoffice.test.tools; /**************************************************************************/ +import com.sun.star.beans.NamedValue; +import com.sun.star.beans.PropertyState; import com.sun.star.beans.PropertyValue; import com.sun.star.frame.XController; import com.sun.star.frame.XDispatch; @@ -93,6 +95,7 @@ public class OfficeDocumentView return xReturn; } + /* ------------------------------------------------------------------ */ /** retrieves a dispatcher for the given URL, obtained at the current view of the document */ @@ -109,17 +112,33 @@ public class OfficeDocumentView @return if the URL was successfully dispatched */ - public boolean dispatch( String url ) throws com.sun.star.uno.Exception + public boolean dispatch( String i_url ) throws com.sun.star.uno.Exception + { + return dispatch( i_url, new PropertyValue[0] ); + } + + /* ------------------------------------------------------------------ */ + public boolean dispatch( final String i_url, final PropertyValue[] i_arguments ) throws com.sun.star.uno.Exception { URL[] completeURL = new URL[] { new URL() }; - completeURL[0].Complete = url; + completeURL[0].Complete = i_url; XDispatch dispatcher = getDispatcher( completeURL ); if ( dispatcher == null ) return false; - PropertyValue[] aDummyArgs = new PropertyValue[] { }; - dispatcher.dispatch( completeURL[0], aDummyArgs ); + dispatcher.dispatch( completeURL[0], i_arguments ); return true; } + + /* ------------------------------------------------------------------ */ + public boolean dispatch( final String i_url, final NamedValue[] i_arguments ) throws com.sun.star.uno.Exception + { + final PropertyValue[] dispatchArgs = new PropertyValue[ i_arguments.length ]; + for ( int i=0; i