LibreOffice Module test (master) 1
unoapi_test.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#ifndef INCLUDED_TEST_UNOAPI_TEST_HXX
11#define INCLUDED_TEST_UNOAPI_TEST_HXX
12
13#include <sal/config.h>
14
15#include <string_view>
16
17#include <rtl/ref.hxx>
21#include <com/sun/star/lang/XComponent.hpp>
22#include <osl/file.hxx>
23#include <unotools/tempfile.hxx>
25
26// basic uno api test class
27
29{
30public:
31 UnoApiTest(OUString path);
32
33 virtual void setUp() override;
34 virtual void tearDown() override;
35
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 OUString loadFromURL(std::u16string_view aFileBase, const char* pPassword = nullptr);
40
41 css::uno::Any executeMacro(const OUString& rScriptURL,
42 const css::uno::Sequence<css::uno::Any>& rParams = {});
43
44 void save(const OUString& rFilter, const char* pPassword = nullptr);
45 void saveAndReload(const OUString& rFilter, const char* pPassword = nullptr);
46
47 std::unique_ptr<vcl::pdf::PDFiumDocument> parsePDFExport(const OString& rPassword = OString());
48
49 void createTempCopy(std::u16string_view fileName);
50
51 void skipValidation() { mbSkipValidation = true; }
52 void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; }
53
54 void setImportFilterOptions(const OUString& rFilterOptions)
55 {
56 maImportFilterOptions = rFilterOptions;
57 }
58
59 void setImportFilterName(const OUString& rFilterName) { maImportFilterName = rFilterName; }
60
61protected:
62 // reference to document component that we are testing
63 css::uno::Reference<css::lang::XComponent> mxComponent;
64
65 // In case the test needs to work with two documents at the same time
66 css::uno::Reference<css::lang::XComponent> mxComponent2;
67
69
70 SvMemoryStream maMemory; // Underlying memory for parsed PDF files.
71
73
74private:
75 void
76 setTestInteractionHandler(const char* pPassword,
77 std::vector<com::sun::star::beans::PropertyValue>& rFilterOptions);
78
80 OUString m_aBaseString;
82
85};
86
87inline void assertRectangleEqual(const tools::Rectangle& rExpected, const tools::Rectangle& rActual,
88 const sal_Int32 nTolerance, const CppUnit::SourceLine& rSourceLine)
89{
90 CPPUNIT_NS::assertDoubleEquals(rExpected.Top(), rActual.Top(), nTolerance, rSourceLine,
91 "different Top");
92 CPPUNIT_NS::assertDoubleEquals(rExpected.Left(), rActual.Left(), nTolerance, rSourceLine,
93 "different Left");
94 CPPUNIT_NS::assertDoubleEquals(rExpected.GetWidth(), rActual.GetWidth(), nTolerance,
95 rSourceLine, "different Width");
96 CPPUNIT_NS::assertDoubleEquals(rExpected.GetHeight(), rActual.GetHeight(), nTolerance,
97 rSourceLine, "different Height");
98}
99
100#define CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aExpected, aActual, aTolerance) \
101 assertRectangleEqual(aExpected, aActual, aTolerance, CPPUNIT_SOURCELINE())
102
103#endif // INCLUDED_TEST_UNOAPI_TEST_HXX
104
105/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbSkipValidation
Definition: unoapi_test.hxx:79
void setFilterOptions(const OUString &rFilterOptions)
Definition: unoapi_test.hxx:52
css::uno::Reference< css::lang::XComponent > mxComponent2
Definition: unoapi_test.hxx:66
OUString maFilterOptions
Definition: unoapi_test.hxx:81
rtl::Reference< TestInteractionHandler > xInteractionHandler
Definition: unoapi_test.hxx:72
void setImportFilterName(const OUString &rFilterName)
Definition: unoapi_test.hxx:59
OUString maImportFilterName
Definition: unoapi_test.hxx:84
OUString m_aBaseString
Definition: unoapi_test.hxx:80
void skipValidation()
Definition: unoapi_test.hxx:51
utl::TempFileNamed maTempFile
Definition: unoapi_test.hxx:68
css::uno::Reference< css::lang::XComponent > mxComponent
Definition: unoapi_test.hxx:63
OUString maImportFilterOptions
Definition: unoapi_test.hxx:83
SvMemoryStream maMemory
Definition: unoapi_test.hxx:70
void setImportFilterOptions(const OUString &rFilterOptions)
Definition: unoapi_test.hxx:54
virtual void tearDown() override
virtual void setUp() override
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
bool executeMacro(SfxObjectShell *pShell, const OUString &sMacroName, uno::Sequence< uno::Any > &aArgs, uno::Any &aRet, const uno::Any &)
Graphic loadFromURL(OUString const &rURL, weld::Window *pParentWin)
#define OOO_DLLPUBLIC_TEST
Definition: testdllapi.hxx:28
void assertRectangleEqual(const tools::Rectangle &rExpected, const tools::Rectangle &rActual, const sal_Int32 nTolerance, const CppUnit::SourceLine &rSourceLine)
Definition: unoapi_test.hxx:87