From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- include/test/unoapi_test.hxx | 108 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 include/test/unoapi_test.hxx (limited to 'include/test/unoapi_test.hxx') diff --git a/include/test/unoapi_test.hxx b/include/test/unoapi_test.hxx new file mode 100644 index 0000000000..2594583296 --- /dev/null +++ b/include/test/unoapi_test.hxx @@ -0,0 +1,108 @@ +/* -*- 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_TEST_UNOAPI_TEST_HXX +#define INCLUDED_TEST_UNOAPI_TEST_HXX + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +// basic uno api test class + +class OOO_DLLPUBLIC_TEST UnoApiTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +public: + UnoApiTest(OUString path); + + virtual void setUp() override; + virtual void tearDown() override; + + OUString createFileURL(std::u16string_view aFileBase); + OUString createFilePath(std::u16string_view aFileBase); + void load(const OUString& rURL, const char* pPassword = nullptr); + void loadWithParams(const OUString& rURL, + const css::uno::Sequence& rParams); + OUString loadFromFile(std::u16string_view aFileBase, const char* pPassword = nullptr); + + css::uno::Any executeMacro(const OUString& rScriptURL, + const css::uno::Sequence& rParams = {}); + + void save(const OUString& rFilter, const char* pPassword = nullptr); + void saveWithParams(const css::uno::Sequence& rParams); + void saveAndReload(const OUString& rFilter, const char* pPassword = nullptr); + + std::unique_ptr parsePDFExport(const OString& rPassword = OString()); + + void createTempCopy(std::u16string_view fileName); + + void skipValidation() { mbSkipValidation = true; } + void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; } + + void setImportFilterOptions(const OUString& rFilterOptions) + { + maImportFilterOptions = rFilterOptions; + } + + void setImportFilterName(const OUString& rFilterName) { maImportFilterName = rFilterName; } + +protected: + // reference to document component that we are testing + css::uno::Reference mxComponent; + + // In case the test needs to work with two documents at the same time + css::uno::Reference mxComponent2; + + utl::TempFileNamed maTempFile; + + SvMemoryStream maMemory; // Underlying memory for parsed PDF files. + + rtl::Reference xInteractionHandler; + +private: + void + setTestInteractionHandler(const char* pPassword, + std::vector& rFilterOptions); + + bool mbSkipValidation; + OUString m_aBaseString; + OUString maFilterOptions; + + OUString maImportFilterOptions; + OUString maImportFilterName; +}; + +inline void assertRectangleEqual(const tools::Rectangle& rExpected, const tools::Rectangle& rActual, + const sal_Int32 nTolerance, const CppUnit::SourceLine& rSourceLine) +{ + CPPUNIT_NS::assertDoubleEquals(rExpected.Top(), rActual.Top(), nTolerance, rSourceLine, + "different Top"); + CPPUNIT_NS::assertDoubleEquals(rExpected.Left(), rActual.Left(), nTolerance, rSourceLine, + "different Left"); + CPPUNIT_NS::assertDoubleEquals(rExpected.GetWidth(), rActual.GetWidth(), nTolerance, + rSourceLine, "different Width"); + CPPUNIT_NS::assertDoubleEquals(rExpected.GetHeight(), rActual.GetHeight(), nTolerance, + rSourceLine, "different Height"); +} + +#define CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aExpected, aActual, aTolerance) \ + assertRectangleEqual(aExpected, aActual, aTolerance, CPPUNIT_SOURCELINE()) + +#endif // INCLUDED_TEST_UNOAPI_TEST_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3