diff options
author | sb <sb@openoffice.org> | 2009-12-18 16:08:08 +0100 |
---|---|---|
committer | sb <sb@openoffice.org> | 2009-12-18 16:08:08 +0100 |
commit | 8db4921431e7db75c86697a224cf29be672c77ce (patch) | |
tree | 3c527b1c1b87762907cc41d77ad08f749a7b66b2 /smoketestoo_native/smoketest.cxx | |
parent | 542dde90f6126e9725e145cc654a83d3ea2fd6ed (diff) |
sb118: work in progress of a simplified smoketestoo_native
Diffstat (limited to 'smoketestoo_native/smoketest.cxx')
-rw-r--r-- | smoketestoo_native/smoketest.cxx | 313 |
1 files changed, 313 insertions, 0 deletions
diff --git a/smoketestoo_native/smoketest.cxx b/smoketestoo_native/smoketest.cxx new file mode 100644 index 000000000000..13970cc2d233 --- /dev/null +++ b/smoketestoo_native/smoketest.cxx @@ -0,0 +1,313 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2008 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* $RCSfile: code,v $ +* +* $Revision: 1.4 $ +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "sal/config.h" + +#include "string" + +#include "boost/noncopyable.hpp" +#include "com/sun/star/beans/PropertyState.hpp" +#include "com/sun/star/beans/PropertyValue.hpp" +#include "com/sun/star/bridge/UnoUrlResolver.hpp" +#include "com/sun/star/bridge/XUnoUrlResolver.hpp" +#include "com/sun/star/connection/NoConnectException.hpp" +#include "com/sun/star/document/MacroExecMode.hpp" +#include "com/sun/star/frame/DispatchResultEvent.hpp" +#include "com/sun/star/frame/DispatchResultState.hpp" +#include "com/sun/star/frame/XComponentLoader.hpp" +#include "com/sun/star/frame/XController.hpp" +#include "com/sun/star/frame/XDesktop.hpp" +#include "com/sun/star/frame/XDispatchProvider.hpp" +#include "com/sun/star/frame/XDispatchResultListener.hpp" +#include "com/sun/star/frame/XModel.hpp" +#include "com/sun/star/frame/XNotifyingDispatch.hpp" +#include "com/sun/star/lang/DisposedException.hpp" +#include "com/sun/star/lang/EventObject.hpp" +#include "com/sun/star/lang/XMultiServiceFactory.hpp" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/util/URL.hpp" +#include "cppuhelper/bootstrap.hxx" +#include "cppuhelper/implbase1.hxx" +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "cppunit/plugin/TestPlugIn.h" +#include "osl/conditn.hxx" +#include "osl/diagnose.h" +#include "osl/file.hxx" +#include "osl/process.h" +#include "osl/thread.hxx" +#include "osl/time.h" +#include "rtl/bootstrap.hxx" +#include "rtl/string.hxx" +#include "rtl/textenc.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/main.h" +#include "sal/types.h" + +namespace CppUnit { + +template<> struct assertion_traits< rtl::OUString > { + static bool equal(rtl::OUString const & x, rtl::OUString const & y) { + return x == y; + } + + static std::string toString(rtl::OUString const & x) { + return rtl::OUStringToOString(x, RTL_TEXTENCODING_UTF8).getStr(); + } +}; + +} + +namespace { + +namespace css = com::sun::star; + +rtl::OUString argumentName(rtl::OUString const & name) { + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("arg-")) + name; +} + +rtl::OUString getArgument(rtl::OUString const & name) { + rtl::OUString val; + CPPUNIT_ASSERT(rtl::Bootstrap::get(argumentName(name), val)); + return val; +} + +bool getOptionalArgument(rtl::OUString const & name, rtl::OUString * value) { + OSL_ASSERT(value != 0); + return rtl::Bootstrap::get(argumentName(name), *value); +} + +rtl::OUString toUrl(rtl::OUString const & pathname) { + rtl::OUString cwd; + CPPUNIT_ASSERT_EQUAL( + osl_Process_E_None, osl_getProcessWorkingDir(&cwd.pData)); + rtl::OUString url; + CPPUNIT_ASSERT_EQUAL( + osl::FileBase::E_None, + osl::FileBase::getFileURLFromSystemPath(pathname, url)); + rtl::OUString absUrl; + CPPUNIT_ASSERT_EQUAL( + osl::FileBase::E_None, + osl::FileBase::getAbsoluteFileURL(cwd, url, absUrl)); + return absUrl; +} + +struct Result: private boost::noncopyable { + osl::Condition condition; + bool success; + rtl::OUString result; +}; + +class Listener: + public cppu::WeakImplHelper1< css::frame::XDispatchResultListener > +{ +public: + Listener(Result * result): result_(result) { OSL_ASSERT(result != 0); } + +private: + virtual void SAL_CALL disposing(css::lang::EventObject const &) + throw (css::uno::RuntimeException) {} + + virtual void SAL_CALL dispatchFinished( + css::frame::DispatchResultEvent const & Result) + throw (css::uno::RuntimeException); + + Result * result_; +}; + +void Listener::dispatchFinished(css::frame::DispatchResultEvent const & Result) + throw (css::uno::RuntimeException) +{ + result_->success = + (Result.State == css::frame::DispatchResultState::SUCCESS) && + (Result.Result >>= result_->result); + result_->condition.set(); +} + +class Test: public CppUnit::TestFixture { +public: + virtual void setUp(); + + virtual void tearDown(); + +private: + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + + void test(); + + oslProcess process_; + css::uno::Reference< css::lang::XMultiServiceFactory > factory_; +}; + +void Test::setUp() { + oslProcessInfo info; + info.Size = sizeof info; + CPPUNIT_ASSERT_EQUAL( + osl_Process_E_None, + osl_getProcessInfo(0, osl_Process_IDENTIFIER, &info)); + rtl::OUString desc( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("pipe,name=oootest")) + + rtl::OUString::valueOf(static_cast< sal_Int64 >(info.Ident)) + + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";urp"))); + rtl::OUString userArg( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-env:UserInstallation=")) + + toUrl(getArgument(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user"))))); + rtl::OUString nofirstArg( + RTL_CONSTASCII_USTRINGPARAM("-nofirststartwizard")); + rtl::OUString acceptArg( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-accept=")) + desc); + rtl_uString * args[] = { nofirstArg.pData, userArg.pData, acceptArg.pData }; + rtl_uString ** envs = 0; + rtl::OUString argEnv; + if (getOptionalArgument( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env")), &argEnv)) + { + envs = &argEnv.pData; + } + CPPUNIT_ASSERT_EQUAL( + osl_Process_E_None, + osl_executeProcess( + (toUrl( + getArgument( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("path")))). + pData), + args, sizeof args / sizeof args[0], 0, 0, 0, envs, + envs == 0 ? 0 : 1, &process_)); + try { + css::uno::Reference< css::uno::XComponentContext > context( + cppu::defaultBootstrap_InitialComponentContext()); + css::uno::Reference< css::bridge::XUnoUrlResolver > resolver( + css::bridge::UnoUrlResolver::create(context)); + for (int i = 0;; ++i) { + try { + factory_ = + css::uno::Reference< css::lang::XMultiServiceFactory >( + resolver->resolve( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uno:")) + + desc + + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + ";StarOffice.ServiceManager"))), + css::uno::UNO_QUERY_THROW); + break; + } catch (css::connection::NoConnectException &) { + if (i == 600) { // 600 sec + throw; + } + } + TimeValue delay = { 1, 0 }; // 1 sec + osl::Thread::wait(delay); + } + } catch (...) { + CPPUNIT_ASSERT_EQUAL( + osl_Process_E_None, osl_terminateProcess(process_)); + osl_freeProcessHandle(process_); + throw; + } +} + +void Test::tearDown() { + css::uno::Reference< css::frame::XDesktop > desktop( + factory_->createInstance( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), + css::uno::UNO_QUERY_THROW); + factory_.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; + CPPUNIT_ASSERT_EQUAL( + osl_Process_E_None, + osl_getProcessInfo(process_, osl_Process_EXITCODE, &info)); + CPPUNIT_ASSERT_EQUAL(oslProcessExitCode(0), info.Code); + osl_freeProcessHandle(process_); +} + +void Test::test() { + css::uno::Sequence< css::beans::PropertyValue > args(1); + args[0].Name = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode")); + args[0].Handle = -1; + args[0].Value <<= + com::sun::star::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN; + args[0].State = css::beans::PropertyState_DIRECT_VALUE; + css::util::URL url; + url.Complete = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "vnd.sun.star.script:Standard.Global.StartTestWithDefaultOptions?" + "language=Basic&location=document")); + Result result; + css::uno::Reference< css::frame::XNotifyingDispatch >( + css::uno::Reference< css::frame::XDispatchProvider >( + css::uno::Reference< css::frame::XController >( + css::uno::Reference< css::frame::XModel >( + css::uno::Reference< css::frame::XComponentLoader >( + factory_->createInstance( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.frame.Desktop"))), + css::uno::UNO_QUERY_THROW)->loadComponentFromURL( + toUrl( + getArgument( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("doc")))), + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("_default")), + 0, args), + css::uno::UNO_QUERY_THROW)->getCurrentController(), + css::uno::UNO_SET_THROW)->getFrame(), + css::uno::UNO_QUERY_THROW)->queryDispatch( + url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")), 0), + css::uno::UNO_QUERY_THROW)->dispatchWithNotification( + url, css::uno::Sequence< css::beans::PropertyValue >(), + new Listener(&result)); + result.condition.wait(); + CPPUNIT_ASSERT(result.success); + CPPUNIT_ASSERT_EQUAL(rtl::OUString(), result.result); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); |