Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / test / unoapi_test.hxx
blob4ba209c44d3922c28cbee722dcea782d44fc4682
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_TEST_UNOAPI_TEST_HXX
11 #define INCLUDED_TEST_UNOAPI_TEST_HXX
13 #include <sal/config.h>
15 #include <string_view>
17 #include <rtl/ref.hxx>
18 #include <test/bootstrapfixture.hxx>
19 #include <test/testinteractionhandler.hxx>
20 #include <unotest/macros_test.hxx>
21 #include <com/sun/star/lang/XComponent.hpp>
22 #include <osl/file.hxx>
23 #include <unotools/tempfile.hxx>
24 #include <vcl/filter/PDFiumLibrary.hxx>
26 // basic uno api test class
28 class OOO_DLLPUBLIC_TEST UnoApiTest : public test::BootstrapFixture, public unotest::MacrosTest
30 public:
31 UnoApiTest(OUString path);
33 virtual void setUp() override;
34 virtual void tearDown() override;
36 OUString createFileURL(std::u16string_view aFileBase);
37 OUString createFilePath(std::u16string_view aFileBase);
38 void load(const OUString& rURL, const char* pPassword = nullptr);
39 void loadWithParams(const OUString& rURL,
40 const css::uno::Sequence<css::beans::PropertyValue>& rParams);
41 OUString loadFromURL(std::u16string_view aFileBase, const char* pPassword = nullptr);
43 css::uno::Any executeMacro(const OUString& rScriptURL,
44 const css::uno::Sequence<css::uno::Any>& rParams = {});
46 void save(const OUString& rFilter, const char* pPassword = nullptr);
47 void saveWithParams(const css::uno::Sequence<css::beans::PropertyValue>& rParams);
48 void saveAndReload(const OUString& rFilter, const char* pPassword = nullptr);
50 std::unique_ptr<vcl::pdf::PDFiumDocument> parsePDFExport(const OString& rPassword = OString());
52 void createTempCopy(std::u16string_view fileName);
54 void skipValidation() { mbSkipValidation = true; }
55 void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; }
57 void setImportFilterOptions(const OUString& rFilterOptions)
59 maImportFilterOptions = rFilterOptions;
62 void setImportFilterName(const OUString& rFilterName) { maImportFilterName = rFilterName; }
64 protected:
65 // reference to document component that we are testing
66 css::uno::Reference<css::lang::XComponent> mxComponent;
68 // In case the test needs to work with two documents at the same time
69 css::uno::Reference<css::lang::XComponent> mxComponent2;
71 utl::TempFileNamed maTempFile;
73 SvMemoryStream maMemory; // Underlying memory for parsed PDF files.
75 rtl::Reference<TestInteractionHandler> xInteractionHandler;
77 private:
78 void
79 setTestInteractionHandler(const char* pPassword,
80 std::vector<com::sun::star::beans::PropertyValue>& rFilterOptions);
82 bool mbSkipValidation;
83 OUString m_aBaseString;
84 OUString maFilterOptions;
86 OUString maImportFilterOptions;
87 OUString maImportFilterName;
90 inline void assertRectangleEqual(const tools::Rectangle& rExpected, const tools::Rectangle& rActual,
91 const sal_Int32 nTolerance, const CppUnit::SourceLine& rSourceLine)
93 CPPUNIT_NS::assertDoubleEquals(rExpected.Top(), rActual.Top(), nTolerance, rSourceLine,
94 "different Top");
95 CPPUNIT_NS::assertDoubleEquals(rExpected.Left(), rActual.Left(), nTolerance, rSourceLine,
96 "different Left");
97 CPPUNIT_NS::assertDoubleEquals(rExpected.GetWidth(), rActual.GetWidth(), nTolerance,
98 rSourceLine, "different Width");
99 CPPUNIT_NS::assertDoubleEquals(rExpected.GetHeight(), rActual.GetHeight(), nTolerance,
100 rSourceLine, "different Height");
103 #define CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aExpected, aActual, aTolerance) \
104 assertRectangleEqual(aExpected, aActual, aTolerance, CPPUNIT_SOURCELINE())
106 #endif // INCLUDED_TEST_UNOAPI_TEST_HXX
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */