summaryrefslogtreecommitdiff
path: root/unotest/source/cpp
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2011-09-28 15:48:09 +0100
committerMichael Meeks <michael.meeks@suse.com>2011-09-28 17:55:26 +0100
commitd0edcf0a554828232ab3c8edfbea22d611bfda2b (patch)
tree07b22ac005305e8c27fdec25fcadd65df4eeff48 /unotest/source/cpp
parentf29109cc5bfdfe13922f9ff2ec85bf0bd3f6dce8 (diff)
split 'test' into 'unotest' and 'test' to help dependencies
Diffstat (limited to 'unotest/source/cpp')
-rw-r--r--unotest/source/cpp/getargument.cxx50
-rw-r--r--unotest/source/cpp/getargument.hxx47
-rw-r--r--unotest/source/cpp/gettestargument.cxx46
-rw-r--r--unotest/source/cpp/makefile.mk69
-rw-r--r--unotest/source/cpp/officeconnection.cxx192
-rw-r--r--unotest/source/cpp/toabsolutefileurl.cxx86
-rw-r--r--unotest/source/cpp/uniquepipename.cxx52
-rw-r--r--unotest/source/cpp/unoexceptionprotector/makefile.mk59
-rw-r--r--unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx125
9 files changed, 726 insertions, 0 deletions
diff --git a/unotest/source/cpp/getargument.cxx b/unotest/source/cpp/getargument.cxx
new file mode 100644
index 000000000000..d401bc964094
--- /dev/null
+++ b/unotest/source/cpp/getargument.cxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#include "sal/config.h"
+
+#include "osl/diagnose.h"
+#include "rtl/bootstrap.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.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(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("arg-")) + name, *value);
+}
+
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotest/source/cpp/getargument.hxx b/unotest/source/cpp/getargument.hxx
new file mode 100644
index 000000000000..3380fdd2e5c2
--- /dev/null
+++ b/unotest/source/cpp/getargument.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#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-<name>" bootstrap
+// variable:
+bool getArgument(
+ rtl::OUString const & name, rtl::OUString * value);
+
+}
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotest/source/cpp/gettestargument.cxx b/unotest/source/cpp/gettestargument.cxx
new file mode 100644
index 000000000000..0bc00062e8d3
--- /dev/null
+++ b/unotest/source/cpp/gettestargument.cxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#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);
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotest/source/cpp/makefile.mk b/unotest/source/cpp/makefile.mk
new file mode 100644
index 000000000000..31eafda84da9
--- /dev/null
+++ b/unotest/source/cpp/makefile.mk
@@ -0,0 +1,69 @@
+#*************************************************************************
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#***********************************************************************/
+
+PRJ = ../..
+PRJNAME = unotest
+TARGET = cpp
+
+ENABLE_EXCEPTIONS = TRUE
+VISIBILITY_HIDDEN = TRUE
+
+.INCLUDE: settings.mk
+
+# --- Files --------------------------------------------------------
+CDEFS += -DOOO_DLLIMPLEMENTATION_UNOTEST
+
+CFLAGSCXX += $(CPPUNIT_CFLAGS)
+
+SLOFILES = \
+ $(SLO)/getargument.obj \
+ $(SLO)/gettestargument.obj \
+ $(SLO)/bootstrapfixture.obj \
+ $(SLO)/officeconnection.obj \
+ $(SLO)/toabsolutefileurl.obj \
+ $(SLO)/uniquepipename.obj
+
+.IF "$(CROSS_COMPILING)" == "YES"
+SHL1IMPLIB = $(SHL1TARGET)
+.ELSE
+SHL1IMPLIB = i$(SHL1TARGET)
+.ENDIF
+SHL1OBJS = $(SLOFILES)
+SHL1RPATH = NONE
+SHL1STDLIBS = \
+ $(VCLLIB) \
+ $(TOOLSLIB) \
+ $(UCBHELPERLIB) \
+ $(COMPHELPERLIB) \
+ $(CPPUHELPERLIB) \
+ $(UNOTOOLSLIB) \
+ $(CPPULIB) \
+ $(CPPUNITLIB) \
+ $(SALLIB)
+SHL1TARGET = test
+SHL1USE_EXPORTS = name
+DEF1NAME = $(SHL1TARGET)
+
+.INCLUDE: target.mk
diff --git a/unotest/source/cpp/officeconnection.cxx b/unotest/source/cpp/officeconnection.cxx
new file mode 100644
index 000000000000..9c8d4d549b71
--- /dev/null
+++ b/unotest/source/cpp/officeconnection.cxx
@@ -0,0 +1,192 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#include "sal/config.h"
+#include "sal/precppunit.hxx"
+
+#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/frame/XDesktop.hpp"
+#include "com/sun/star/lang/DisposedException.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"
+#include "osl/time.h"
+#include "sal/macros.h"
+#include "sal/types.h"
+#include "test/officeconnection.hxx"
+#include "test/toabsolutefileurl.hxx"
+#include "test/uniquepipename.hxx"
+
+#include "getargument.hxx"
+
+namespace {
+
+namespace css = com::sun::star;
+
+}
+
+namespace test {
+
+OfficeConnection::OfficeConnection(): process_(0) {}
+
+OfficeConnection::~OfficeConnection() {}
+
+void OfficeConnection::setUp() {
+ rtl::OUString desc;
+ rtl::OUString argSoffice;
+ CPPUNIT_ASSERT(
+ detail::getArgument(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("soffice")),
+ &argSoffice));
+ if (argSoffice.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("path:"))) {
+ 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(
+ RTL_CONSTASCII_USTRINGPARAM("--nofirststartwizard"));
+ rtl::OUString norestoreArg(RTL_CONSTASCII_USTRINGPARAM("--norestore"));
+ rtl::OUString nologoArg(RTL_CONSTASCII_USTRINGPARAM("--nologo"));
+ // disable use of the unix standalone splash screen app for the
+ // tests (probably not needed in combination with --headless?)
+ rtl::OUString headlessArg(RTL_CONSTASCII_USTRINGPARAM("--headless"));
+ rtl::OUString acceptArg(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--accept=")) + desc +
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";urp")));
+ rtl::OUString argUser;
+ CPPUNIT_ASSERT(
+ detail::getArgument(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), &argUser));
+ rtl::OUString userArg(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("-env:UserInstallation=")) +
+ 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,
+ nologoArg.pData, headlessArg.pData, acceptArg.pData, userArg.pData,
+ jreArg.pData, classpathArg.pData };
+ rtl_uString ** envs = 0;
+ rtl::OUString argEnv;
+ if (detail::getArgument(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env")), &argEnv))
+ {
+ envs = &argEnv.pData;
+ }
+ CPPUNIT_ASSERT_EQUAL(
+ osl_Process_E_None,
+ osl_executeProcess(
+ toAbsoluteFileUrl(
+ argSoffice.copy(RTL_CONSTASCII_LENGTH("path:"))).pData,
+ args, SAL_N_ELEMENTS(args), 0, 0, 0, envs, envs == 0 ? 0 : 1,
+ &process_));
+ } else if (argSoffice.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("connect:"))) {
+ desc = argSoffice.copy(RTL_CONSTASCII_LENGTH("connect:"));
+ } else {
+ CPPUNIT_FAIL(
+ "\"soffice\" argument starts with neither \"path:\" nor"
+ " \"connect:\"");
+ }
+ css::uno::Reference< css::bridge::XUnoUrlResolver > resolver(
+ css::bridge::UnoUrlResolver::create(
+ cppu::defaultBootstrap_InitialComponentContext()));
+ for (;;) {
+ try {
+ context_ =
+ css::uno::Reference< css::uno::XComponentContext >(
+ resolver->resolve(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uno:")) +
+ desc +
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ ";urp;StarOffice.ComponentContext"))),
+ css::uno::UNO_QUERY_THROW);
+ break;
+ } catch (css::connection::NoConnectException &) {}
+ if (process_ != 0) {
+ TimeValue delay = { 1, 0 }; // 1 sec
+ CPPUNIT_ASSERT_EQUAL(
+ osl_Process_E_TimedOut,
+ osl_joinProcessWithTimeout(process_, &delay));
+ }
+ }
+}
+
+void OfficeConnection::tearDown() {
+ 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;
+ CPPUNIT_ASSERT_EQUAL(
+ osl_Process_E_None,
+ osl_getProcessInfo(process_, osl_Process_EXITCODE, &info));
+ CPPUNIT_ASSERT_EQUAL(oslProcessExitCode(0), info.Code);
+ osl_freeProcessHandle(process_);
+ process_ = 0; // guard against subsequent calls to isStillAlive
+ }
+}
+
+css::uno::Reference< css::uno::XComponentContext >
+OfficeConnection::getComponentContext() const {
+ return context_;
+}
+
+bool OfficeConnection::isStillAlive() const {
+ OSL_ASSERT(process_ != 0);
+ TimeValue delay = { 0, 0 }; // 0 sec
+ oslProcessError e = osl_joinProcessWithTimeout(process_, &delay);
+ CPPUNIT_ASSERT(e == osl_Process_E_None || e == osl_Process_E_TimedOut);
+ return e == osl_Process_E_TimedOut;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotest/source/cpp/toabsolutefileurl.cxx b/unotest/source/cpp/toabsolutefileurl.cxx
new file mode 100644
index 000000000000..e7c97d2fb85f
--- /dev/null
+++ b/unotest/source/cpp/toabsolutefileurl.cxx
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#include "sal/config.h"
+
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "osl/file.hxx"
+#include "osl/process.h"
+#include "rtl/ustring.hxx"
+#include "test/toabsolutefileurl.hxx"
+
+namespace {
+
+namespace css = com::sun::star;
+
+}
+
+namespace test {
+
+rtl::OUString toAbsoluteFileUrl(rtl::OUString const & relativePathname) {
+ rtl::OUString cwd;
+ oslProcessError e1 = osl_getProcessWorkingDir(&cwd.pData);
+ if (e1 != osl_Process_E_None) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "osl_getProcessWorkingDir failed with ")) +
+ rtl::OUString::valueOf(static_cast< sal_Int32 >(e1))),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ rtl::OUString url;
+ osl::FileBase::RC e2 = osl::FileBase::getFileURLFromSystemPath(
+ relativePathname, url);
+ if (e2 != osl::FileBase::E_None) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "osl::FileBase::getFileURLFromSystemPath(")) +
+ relativePathname +
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(") failed with ")) +
+ rtl::OUString::valueOf(static_cast< sal_Int32 >(e2))),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ rtl::OUString absUrl;
+ e2 = osl::FileBase::getAbsoluteFileURL(cwd, url, absUrl);
+ if (e2 != osl::FileBase::E_None) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "osl::FileBase::getAbsoluteFileURL(")) +
+ cwd + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", ")) + url +
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(") failed with ")) +
+ rtl::OUString::valueOf(static_cast< sal_Int32 >(e2))),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ return absUrl;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotest/source/cpp/uniquepipename.cxx b/unotest/source/cpp/uniquepipename.cxx
new file mode 100644
index 000000000000..1725ca218918
--- /dev/null
+++ b/unotest/source/cpp/uniquepipename.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#include "sal/config.h"
+#include "sal/precppunit.hxx"
+
+#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));
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotest/source/cpp/unoexceptionprotector/makefile.mk b/unotest/source/cpp/unoexceptionprotector/makefile.mk
new file mode 100644
index 000000000000..d3d13e646232
--- /dev/null
+++ b/unotest/source/cpp/unoexceptionprotector/makefile.mk
@@ -0,0 +1,59 @@
+#*************************************************************************
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#***********************************************************************/
+
+PRJ = ../../..
+PRJNAME = test
+TARGET = unoexceptionprotector
+
+ENABLE_EXCEPTIONS = TRUE
+VISIBILITY_HIDDEN = TRUE
+
+.INCLUDE: settings.mk
+
+.IF "$(CROSS_COMPILING)"=="YES"
+all:
+ @echo Nothing done when cross-compiling
+.ENDIF
+
+# --- Files --------------------------------------------------------
+DLLPRE =
+
+CFLAGSCXX += $(CPPUNIT_CFLAGS)
+
+SLOFILES = $(SLO)/unoexceptionprotector.obj
+
+SHL1IMPLIB = i$(SHL1TARGET)
+SHL1OBJS = $(SLOFILES)
+SHL1RPATH = NONE
+SHL1STDLIBS = \
+ $(CPPUHELPERLIB) \
+ $(CPPULIB) \
+ $(CPPUNITLIB) \
+ $(SALLIB)
+SHL1TARGET = unoexceptionprotector
+SHL1USE_EXPORTS = name
+DEF1NAME = $(SHL1TARGET)
+
+.INCLUDE: target.mk
diff --git a/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx b/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx
new file mode 100644
index 000000000000..7e7e0000c49a
--- /dev/null
+++ b/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx
@@ -0,0 +1,125 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2011 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#include "precompiled_test.hxx"
+#include "sal/config.h"
+#include "sal/precppunit.hxx"
+
+#include <limits>
+#include <string>
+#include <iostream>
+
+#include "boost/noncopyable.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Exception.hpp"
+#include "cppuhelper/exc_hlp.hxx"
+#include "cppunit/Message.h"
+#include "osl/thread.h"
+#include "rtl/string.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+#include "protectorfactory.hxx"
+
+namespace {
+
+namespace css = com::sun::star;
+
+// Best effort conversion:
+std::string convert(rtl::OUString const & s16) {
+ rtl::OString s8(rtl::OUStringToOString(s16, osl_getThreadTextEncoding()));
+ return std::string(
+ s8.getStr(),
+ ((static_cast< sal_uInt32 >(s8.getLength())
+ > std::numeric_limits< std::string::size_type >::max())
+ ? std::numeric_limits< std::string::size_type >::max()
+ : static_cast< std::string::size_type >(s8.getLength())));
+}
+
+class Prot : public cppunittester::LibreOfficeProtector, private boost::noncopyable
+{
+public:
+ Prot() {}
+
+ virtual ~Prot() {}
+
+ virtual bool protect(
+ CppUnit::Functor const & functor,
+ CppUnit::ProtectorContext const & context);
+
+ virtual bool protect(CppUnit::Functor const & functor);
+};
+
+bool Prot::protect(
+ CppUnit::Functor const & functor, CppUnit::ProtectorContext const & context)
+{
+ try {
+ return functor();
+ } catch (const css::uno::Exception &e) {
+ css::uno::Any a(cppu::getCaughtException());
+ reportError(
+ context,
+ CppUnit::Message(
+ convert(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "An uncaught exception of type "))
+ + a.getValueTypeName()),
+ convert(e.Message)));
+ }
+ return false;
+}
+
+bool Prot::protect(CppUnit::Functor const & functor)
+{
+ bool bRet = false;
+ try
+ {
+ bRet = functor();
+ } catch (const css::uno::Exception &e)
+ {
+ css::uno::Any a(cppu::getCaughtException());
+ std::cerr
+ << convert(rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "An uncaught exception of type "))
+ + a.getValueTypeName())
+ << std::endl << "Exception Message was: " << convert(e.Message)
+ << std::endl;
+ throw;
+ }
+ return bRet;
+}
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL
+unoexceptionprotector() {
+ return new Prot;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */