summaryrefslogtreecommitdiffstats
path: root/include/unotest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /include/unotest
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/unotest')
-rw-r--r--include/unotest/bootstrapfixturebase.hxx74
-rw-r--r--include/unotest/detail/unotestdllapi.hxx34
-rw-r--r--include/unotest/directories.hxx52
-rw-r--r--include/unotest/filters-test.hxx95
-rw-r--r--include/unotest/getargument.hxx38
-rw-r--r--include/unotest/gettestargument.hxx42
-rw-r--r--include/unotest/macros_test.hxx122
-rw-r--r--include/unotest/officeconnection.hxx65
-rw-r--r--include/unotest/toabsolutefileurl.hxx39
9 files changed, 561 insertions, 0 deletions
diff --git a/include/unotest/bootstrapfixturebase.hxx b/include/unotest/bootstrapfixturebase.hxx
new file mode 100644
index 0000000000..1a25e25d4c
--- /dev/null
+++ b/include/unotest/bootstrapfixturebase.hxx
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef INCLUDED_UNOTEST_BOOTSTRAPFIXTUREBASE_HXX
+#define INCLUDED_UNOTEST_BOOTSTRAPFIXTUREBASE_HXX
+
+#include <sal/config.h>
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <unotest/detail/unotestdllapi.hxx>
+#include <unotest/directories.hxx>
+
+// For cppunit < 1.15.0.
+#ifndef CPPUNIT_TEST_FIXTURE
+#define CPPUNIT_TEST_FIXTURE(TestClass, TestName) \
+ class TestName : public TestClass \
+ { \
+ public: \
+ void TestBody(); \
+ CPPUNIT_TEST_SUITE(TestName); \
+ CPPUNIT_TEST(TestBody); \
+ CPPUNIT_TEST_SUITE_END(); \
+ }; \
+ CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
+ void TestName::TestBody()
+#endif
+
+namespace test {
+
+// Class to do lots of heavy-lifting UNO & environment
+// bootstrapping for unit tests, such that we can use
+// almost an entire LibreOffice during compile - so
+// that we can get pieces of code alone to beat them up.
+
+// NB. this class is instantiated multiple times during a
+// run of unit tests ...
+class OOO_DLLPUBLIC_UNOTEST BootstrapFixtureBase : public CppUnit::TestFixture
+{
+protected:
+ Directories m_directories;
+ css::uno::Reference<css::uno::XComponentContext> m_xContext;
+ css::uno::Reference<css::lang::XMultiServiceFactory> m_xSFactory;
+ css::uno::Reference<css::lang::XMultiComponentFactory> m_xFactory;
+
+public:
+ BootstrapFixtureBase();
+ virtual ~BootstrapFixtureBase() override;
+
+ const css::uno::Reference<css::uno::XComponentContext>&
+ getComponentContext() const { return m_xContext; }
+ const css::uno::Reference<css::lang::XMultiServiceFactory>&
+ getMultiServiceFactory() const { return m_xSFactory; }
+
+ virtual void setUp() override;
+ virtual void tearDown() override;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/detail/unotestdllapi.hxx b/include/unotest/detail/unotestdllapi.hxx
new file mode 100644
index 0000000000..b890139126
--- /dev/null
+++ b/include/unotest/detail/unotestdllapi.hxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_UNOTEST_DETAIL_UNOTESTDLLAPI_HXX
+#define INCLUDED_UNOTEST_DETAIL_UNOTESTDLLAPI_HXX
+
+#include <sal/config.h>
+#include <sal/types.h>
+
+#if defined OOO_DLLIMPLEMENTATION_UNOTEST
+#define OOO_DLLPUBLIC_UNOTEST SAL_DLLPUBLIC_EXPORT
+#else
+#define OOO_DLLPUBLIC_UNOTEST SAL_DLLPUBLIC_IMPORT
+#endif
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/directories.hxx b/include/unotest/directories.hxx
new file mode 100644
index 0000000000..efdcd93a6a
--- /dev/null
+++ b/include/unotest/directories.hxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_UNOTEST_DIRECTORIES_HXX
+#define INCLUDED_UNOTEST_DIRECTORIES_HXX
+
+#include <sal/config.h>
+
+#include <string_view>
+
+#include <rtl/ustring.hxx>
+#include <unotest/detail/unotestdllapi.hxx>
+
+namespace test
+{
+class OOO_DLLPUBLIC_UNOTEST Directories
+{
+private:
+ OUString m_aSrcRootURL;
+ OUString m_aSrcRootPath;
+ OUString m_aWorkdirRootURL;
+ OUString m_aWorkdirRootPath;
+
+public:
+ Directories();
+
+ const OUString& getSrcRootURL() const { return m_aSrcRootURL; }
+ const OUString& getSrcRootPath() const { return m_aSrcRootPath; }
+
+ // return a URL to a given path from the source directory
+ OUString getURLFromSrc(std::u16string_view rPath) const;
+
+ // return a Path to a given path from the source directory
+ OUString getPathFromSrc(std::u16string_view rPath) const;
+
+ // return a URL to a given path from the workdir directory
+ OUString getURLFromWorkdir(std::u16string_view rPath) const;
+
+ // return a Path to a given path from the workdir directory
+ OUString getPathFromWorkdir(std::u16string_view rPath) const;
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/filters-test.hxx b/include/unotest/filters-test.hxx
new file mode 100644
index 0000000000..01570b7863
--- /dev/null
+++ b/include/unotest/filters-test.hxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_UNOTEST_FILTERS_TEST_HXX
+#define INCLUDED_UNOTEST_FILTERS_TEST_HXX
+
+#include <sal/config.h>
+
+#include <string_view>
+
+#include <comphelper/documentconstants.hxx>
+#include <rtl/ustring.hxx>
+#include <unotest/detail/unotestdllapi.hxx>
+#include <sot/formats.hxx>
+
+namespace test {
+
+enum filterStatus
+{
+ fail = 0,
+ pass = 1,
+ indeterminate = 2
+};
+
+/*
+ * NOTE, any files beginning with CVE-, BID- or EDB- will be assumed to be
+ * encrypted using arcfour with key 0x435645, this is to silence panicky
+ * virus/malware-checkers
+ *
+ * e.g. m[de]crypt --bare -a arcfour -o hex -k 435645 -s 3
+ */
+/* Implementation of Filters test */
+class OOO_DLLPUBLIC_UNOTEST FiltersTest
+{
+public:
+ void testDir(
+ //filter name
+ const OUString &rFilter,
+ //root dir of test files, must contain pass, fail, indeterminate
+ std::u16string_view rURL,
+ //additional filter data for SfxFilter
+ const OUString &rUserData = OUString(),
+ //SfxFilterFlags for SfxFilter
+ SfxFilterFlags nFilterFlags = SfxFilterFlags::IMPORT,
+ //Clipboard id for SfxFilter
+ SotClipboardFormatId nClipboardID = SotClipboardFormatId::NONE,
+ //additional filter version for SfxFilter
+ unsigned int nFilterVersion = 0,
+ //export or import?
+ bool bExport = false);
+
+ virtual bool load(
+ const OUString &rFilter,
+ const OUString &rURL,
+ const OUString &rUserData,
+ SfxFilterFlags nFilterFlags,
+ SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion) = 0;
+
+ virtual bool save(
+ const OUString &/*rFilter*/,
+ const OUString &/*rURL*/,
+ const OUString &/*rUserData*/,
+ SfxFilterFlags /*nFilterFlags*/,
+ SotClipboardFormatId /*nClipboardID*/,
+ unsigned int /*nFilterVersion*/)
+ {
+ return true;
+ }
+
+protected:
+ ~FiltersTest() {}
+
+ void recursiveScan(
+ filterStatus nExpected,
+ const OUString &rFilter,
+ const OUString &rURL,
+ const OUString &rUserData,
+ SfxFilterFlags nFilterFlags,
+ SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion,
+ bool bExport);
+};
+
+}
+
+#endif // INCLUDED_UNOTEST_FILTERS_TEST_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/getargument.hxx b/include/unotest/getargument.hxx
new file mode 100644
index 0000000000..08eee217a3
--- /dev/null
+++ b/include/unotest/getargument.hxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <string_view>
+
+#include <rtl/ustring.hxx>
+#include <unotest/detail/unotestdllapi.hxx>
+
+namespace test {
+
+// Obtain the value of an argument tunneled in via an "arg-<name>" bootstrap
+// variable:
+OOO_DLLPUBLIC_UNOTEST bool getArgument(
+ std::u16string_view name, OUString * value);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/gettestargument.hxx b/include/unotest/gettestargument.hxx
new file mode 100644
index 0000000000..3b62917253
--- /dev/null
+++ b/include/unotest/gettestargument.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_UNOTEST_GETTESTARGUMENT_HXX
+#define INCLUDED_UNOTEST_GETTESTARGUMENT_HXX
+
+#include <sal/config.h>
+
+#include <string_view>
+
+#include <rtl/ustring.hxx>
+#include <unotest/detail/unotestdllapi.hxx>
+
+
+namespace test {
+
+// Obtain the value of a test argument (tunneled in via an "arg-testarg.<name>"
+// bootstrap variable):
+OOO_DLLPUBLIC_UNOTEST bool getTestArgument(
+ std::u16string_view name, OUString * value);
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx
new file mode 100644
index 0000000000..c960ff76ea
--- /dev/null
+++ b/include/unotest/macros_test.hxx
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_UNOTEST_MACROS_TEST_HXX
+#define INCLUDED_UNOTEST_MACROS_TEST_HXX
+
+#include <sal/config.h>
+
+#include <memory>
+#include <functional>
+#include <config_gpgme.h>
+#include <rtl/ustring.hxx>
+#include <unotest/detail/unotestdllapi.hxx>
+
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/frame/XDesktop2.hpp>
+#include <com/sun/star/uno/Any.h>
+#include <utility>
+
+struct TestMacroInfo
+{
+ OUString sFileBaseName;
+ OUString sMacroUrl;
+};
+
+class BasicDLL;
+class SvStream;
+
+namespace test
+{
+class Directories;
+}
+namespace utl
+{
+class TempFileNamed;
+}
+
+namespace com::sun::star::security
+{
+class XCertificate;
+}
+namespace com::sun::star::xml::crypto
+{
+class XSecurityEnvironment;
+}
+
+namespace unotest
+{
+class OOO_DLLPUBLIC_UNOTEST MacrosTest
+{
+public:
+ class Resetter
+ {
+ private:
+ std::function<void()> m_Func;
+
+ public:
+ Resetter(std::function<void()> aFunc)
+ : m_Func(std::move(aFunc))
+ {
+ }
+ ~Resetter()
+ {
+ try
+ {
+ m_Func();
+ }
+ catch (...) // has to be reliable
+ {
+ fprintf(stderr, "resetter failed with exception\n");
+ abort();
+ }
+ }
+ };
+
+ MacrosTest();
+ ~MacrosTest();
+
+ css::uno::Reference<css::lang::XComponent>
+ loadFromDesktop(const OUString& rURL, const OUString& rDocService = OUString(),
+ const css::uno::Sequence<css::beans::PropertyValue>& rExtra_args
+ = css::uno::Sequence<css::beans::PropertyValue>());
+
+ static css::uno::Any
+ dispatchCommand(const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const OUString& rCommand,
+ const css::uno::Sequence<css::beans::PropertyValue>& rPropertyValues);
+
+ /// Opens rStreamName from rTempFile, assuming it's a ZIP storage.
+ static std::unique_ptr<SvStream> parseExportStream(const OUString& url,
+ const OUString& rStreamName);
+
+ void setUpNssGpg(const test::Directories& rDirectories, const OUString& rTestName);
+ void tearDownNssGpg();
+
+ static bool IsValid(const css::uno::Reference<css::security::XCertificate>& cert,
+ const css::uno::Reference<css::xml::crypto::XSecurityEnvironment>& env);
+ static css::uno::Reference<css::security::XCertificate> GetValidCertificate(
+ const css::uno::Sequence<css::uno::Reference<css::security::XCertificate>>& certs,
+ const css::uno::Reference<css::xml::crypto::XSecurityEnvironment>& env,
+ const css::uno::Sequence<css::beans::PropertyValue>& rFilterData = {});
+
+protected:
+ css::uno::Reference<css::frame::XDesktop2> mxDesktop;
+
+private:
+ std::unique_ptr<BasicDLL> mpDll;
+#if HAVE_GPGCONF_SOCKETDIR
+ OString m_gpgconfCommandPrefix;
+#endif
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/officeconnection.hxx b/include/unotest/officeconnection.hxx
new file mode 100644
index 0000000000..553f24b3cc
--- /dev/null
+++ b/include/unotest/officeconnection.hxx
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_UNOTEST_OFFICECONNECTION_HXX
+#define INCLUDED_UNOTEST_OFFICECONNECTION_HXX
+
+#include <sal/config.h>
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <osl/process.h>
+#include <unotest/detail/unotestdllapi.hxx>
+
+namespace com::sun::star::uno {
+ class XComponentContext;
+}
+
+namespace test {
+
+// Start up and shut down an OOo instance (details about the OOo instance are
+// tunneled in via "arg-..." bootstrap variables):
+class OOO_DLLPUBLIC_UNOTEST OfficeConnection
+{
+ OfficeConnection(const OfficeConnection&) = delete;
+ OfficeConnection& operator=( const OfficeConnection& ) = delete;
+public:
+ OfficeConnection();
+ ~OfficeConnection();
+
+ void setUp();
+
+ void tearDown();
+
+ const css::uno::Reference< css::uno::XComponentContext >&
+ getComponentContext() const { return context_;}
+
+ // Must not be called before setUp or after tearDown:
+ bool isStillAlive() const;
+
+private:
+ oslProcess process_;
+ css::uno::Reference< css::uno::XComponentContext >
+ context_;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/unotest/toabsolutefileurl.hxx b/include/unotest/toabsolutefileurl.hxx
new file mode 100644
index 0000000000..5bdb7b05ef
--- /dev/null
+++ b/include/unotest/toabsolutefileurl.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_UNOTEST_TOABSOLUTEFILEURL_HXX
+#define INCLUDED_UNOTEST_TOABSOLUTEFILEURL_HXX
+
+#include <rtl/ustring.hxx>
+
+#include <unotest/detail/unotestdllapi.hxx>
+
+
+namespace test {
+
+// Convert a pathname in system notation, potentially relative to the process's
+// current working directory, to an absolute file URL:
+OOO_DLLPUBLIC_UNOTEST OUString toAbsoluteFileUrl(
+ OUString const & relativePathname);
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */