Skip to content

Commit 7986d35

Browse files
author
Xisco Fauli
committed
move password handling from SwModelTestBase to UnoApiTest
so other places inheriting from UnoApiTest can also import/export protected documents Change-Id: I0e2716204dbb171c9e17e3939b266977e1b96dda Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142592 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]>
1 parent 4c9093c commit 7986d35

23 files changed

+97
-74
lines changed

dbaccess/CppunitTest_dbaccess_firebird_test.mk

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_firebird_test, \
1818
$(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \
1919
comphelper \
2020
cppu \
21+
cppuhelper \
2122
dbaxml \
2223
firebird_sdbc \
2324
sal \

embeddedobj/CppunitTest_embeddedobj_general.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,embeddedobj_general, \
2222
$(eval $(call gb_CppunitTest_use_libraries,embeddedobj_general, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
embobj \
2627
sal \
2728
subsequenttest \

include/test/unoapi_test.hxx

+23-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#include <string_view>
1616

17+
#include <rtl/ref.hxx>
1718
#include <test/bootstrapfixture.hxx>
19+
#include <test/testinteractionhandler.hxx>
1820
#include <unotest/macros_test.hxx>
1921
#include <com/sun/star/lang/XComponent.hpp>
2022
#include <osl/file.hxx>
@@ -28,24 +30,32 @@ class OOO_DLLPUBLIC_TEST UnoApiTest : public test::BootstrapFixture, public unot
2830
public:
2931
UnoApiTest(OUString path);
3032

31-
OUString createFileURL(std::u16string_view aFileBase);
32-
OUString loadFromURL(std::u16string_view aFileBase);
33-
3433
virtual void setUp() override;
3534
virtual void tearDown() override;
3635

36+
OUString createFileURL(std::u16string_view aFileBase);
37+
void load(const OUString& rURL, const char* pPassword = nullptr);
38+
OUString loadFromURL(std::u16string_view aFileBase, const char* pPassword = nullptr);
39+
3740
css::uno::Any executeMacro(const OUString& rScriptURL,
3841
const css::uno::Sequence<css::uno::Any>& rParams = {});
3942

4043
void save(const OUString& rFilter, const char* pPassword = nullptr);
4144
void saveAndClose(const OUString& rFilter);
42-
void saveAndReload(const OUString& rFilter);
45+
void saveAndReload(const OUString& rFilter, const char* pPassword = nullptr);
4346

4447
std::unique_ptr<vcl::pdf::PDFiumDocument> parsePDFExport(const OString& rPassword = OString());
4548

4649
void skipValidation() { mbSkipValidation = true; }
4750
void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; }
4851

52+
void setImportFilterOptions(const OUString& rFilterOptions)
53+
{
54+
maImportFilterOptions = rFilterOptions;
55+
}
56+
57+
void setImportFilterName(const OUString& rFilterName) { maImportFilterName = rFilterName; }
58+
4959
protected:
5060
// reference to document component that we are testing
5161
css::uno::Reference<css::lang::XComponent> mxComponent;
@@ -54,10 +64,19 @@ protected:
5464

5565
SvMemoryStream maMemory; // Underlying memory for parsed PDF files.
5666

67+
rtl::Reference<TestInteractionHandler> xInteractionHandler;
68+
5769
private:
70+
void
71+
setTestInteractionHandler(const char* pPassword,
72+
std::vector<com::sun::star::beans::PropertyValue>& rFilterOptions);
73+
5874
bool mbSkipValidation;
5975
OUString m_aBaseString;
6076
OUString maFilterOptions;
77+
78+
OUString maImportFilterOptions;
79+
OUString maImportFilterName;
6180
};
6281

6382
#endif // INCLUDED_TEST_UNOAPI_TEST_HXX

oox/CppunitTest_oox_drawingml.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_drawingml, \
2222
$(eval $(call gb_CppunitTest_use_libraries,oox_drawingml, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
oox \
2627
sal \
2728
subsequenttest \

oox/CppunitTest_oox_export.mk

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_export, \
2323
$(eval $(call gb_CppunitTest_use_libraries,oox_export, \
2424
comphelper \
2525
cppu \
26+
cppuhelper \
2627
oox \
2728
sal \
2829
subsequenttest \

oox/CppunitTest_oox_mathml.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_mathml, \
2222
$(eval $(call gb_CppunitTest_use_libraries,oox_mathml, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
oox \
2627
sal \
2728
subsequenttest \

oox/CppunitTest_oox_shape.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_shape, \
2222
$(eval $(call gb_CppunitTest_use_libraries,oox_shape, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
oox \
2627
sal \
2728
subsequenttest \

oox/CppunitTest_oox_vml.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_vml, \
2222
$(eval $(call gb_CppunitTest_use_libraries,oox_vml, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
oox \
2627
sal \
2728
subsequenttest \

sc/CppunitTest_sc_functionlistobj.mk

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sc_functionlistobj, \
2121

2222
$(eval $(call gb_CppunitTest_use_libraries,sc_functionlistobj, \
2323
cppu \
24+
cppuhelper \
2425
sal \
2526
subsequenttest \
2627
test \

sc/CppunitTest_sc_pdf_export.mk

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ endif
2828
$(eval $(call gb_CppunitTest_use_libraries,sc_pdf_export, \
2929
comphelper \
3030
cppu \
31+
cppuhelper \
3132
editeng \
3233
sal \
3334
sax \

sc/common_unoapi_tests.mk

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sc_$(1), \
2525
$(eval $(call gb_CppunitTest_use_libraries,sc_$(1), \
2626
comphelper \
2727
cppu \
28+
cppuhelper \
2829
sal \
2930
salhelper \
3031
sc \

sd/CppunitTest_sd_filter_eppt.mk

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sd_filter_eppt, \
2323
$(eval $(call gb_CppunitTest_use_libraries,sd_filter_eppt, \
2424
comphelper \
2525
cppu \
26+
cppuhelper \
2627
sd \
2728
sal \
2829
subsequenttest \

sfx2/CppunitTest_sfx2_doc.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sfx2_doc, \
2222
$(eval $(call gb_CppunitTest_use_libraries,sfx2_doc, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
sal \
2627
subsequenttest \
2728
test \

sfx2/CppunitTest_sfx2_view.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sfx2_view, \
2222
$(eval $(call gb_CppunitTest_use_libraries,sfx2_view, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
sal \
2627
subsequenttest \
2728
test \

svx/CppunitTest_svx_styles.mk

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,svx_styles, \
2222
$(eval $(call gb_CppunitTest_use_libraries,svx_styles, \
2323
comphelper \
2424
cppu \
25+
cppuhelper \
2526
svx \
2627
sal \
2728
subsequenttest \

sw/qa/inc/swmodeltestbase.hxx

-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "swqahelperdllapi.h"
2626
#include <test/unoapixml_test.hxx>
27-
#include <test/testinteractionhandler.hxx>
2827
#include <unotools/tempfile.hxx>
2928

3029
#include <doc.hxx>
@@ -94,13 +93,9 @@ class PDFiumDocument;
9493
class SWQAHELPER_DLLPUBLIC SwModelTestBase : public UnoApiXmlTest
9594
{
9695
private:
97-
OUString maImportFilterOptions;
98-
OUString maImportFilterName;
9996
bool mbExported; ///< Does maTempFile already contain something useful?
10097

10198
protected:
102-
rtl::Reference<TestInteractionHandler> xInteractionHandler;
103-
10499
xmlBufferPtr mpXmlBuffer;
105100
const char* mpFilter;
106101

@@ -112,16 +107,6 @@ protected:
112107
void paste(std::u16string_view aFilename, css::uno::Reference<css::text::XTextRange> const& xTextRange);
113108

114109
public:
115-
void setImportFilterOptions(const OUString &rFilterOptions)
116-
{
117-
maImportFilterOptions = rFilterOptions;
118-
}
119-
120-
void setImportFilterName(const OUString &rFilterName)
121-
{
122-
maImportFilterName = rFilterName;
123-
}
124-
125110
SwModelTestBase(const OUString& pTestDocumentPath = OUString(), const char* pFilter = "");
126111

127112
protected:
@@ -361,8 +346,6 @@ protected:
361346
bool isExported(){ return mbExported; }
362347

363348
private:
364-
void setTestInteractionHandler(const char* pPassword, std::vector<beans::PropertyValue>& rFilterOptions);
365-
366349
void loadURL(OUString const& rURL, const char* pName, const char* pPassword);
367350

368351
void load(const char* pName, const char* pPassword = nullptr)

sw/qa/unit/swmodeltestbase.cxx

+1-47
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include <comphelper/processfactory.hxx>
2222
#include <comphelper/propertyvalue.hxx>
23-
#include <comphelper/sequence.hxx>
2423
#include <officecfg/Office/Common.hxx>
2524
#include <rtl/ustrbuf.hxx>
2625
#include <sfx2/app.hxx>
@@ -448,48 +447,10 @@ uno::Reference<drawing::XShape> SwModelTestBase::getTextFrameByName(const OUStri
448447
return xShape;
449448
}
450449

451-
void SwModelTestBase::setTestInteractionHandler(const char* pPassword,
452-
std::vector<beans::PropertyValue>& rFilterOptions)
453-
{
454-
OUString sPassword = OUString::createFromAscii(pPassword);
455-
rFilterOptions.emplace_back();
456-
xInteractionHandler
457-
= rtl::Reference<TestInteractionHandler>(new TestInteractionHandler(sPassword));
458-
uno::Reference<task::XInteractionHandler2> const xInteraction(xInteractionHandler);
459-
rFilterOptions[0].Name = "InteractionHandler";
460-
rFilterOptions[0].Value <<= xInteraction;
461-
}
462-
463450
void SwModelTestBase::header() {}
464451

465452
void SwModelTestBase::loadURL(OUString const& rURL, const char* pName, const char* pPassword)
466453
{
467-
if (mxComponent.is())
468-
mxComponent->dispose();
469-
470-
std::vector<beans::PropertyValue> aFilterOptions;
471-
472-
if (pPassword)
473-
{
474-
setTestInteractionHandler(pPassword, aFilterOptions);
475-
}
476-
477-
if (!maImportFilterOptions.isEmpty())
478-
{
479-
beans::PropertyValue aValue;
480-
aValue.Name = "FilterOptions";
481-
aValue.Value <<= maImportFilterOptions;
482-
aFilterOptions.push_back(aValue);
483-
}
484-
485-
if (!maImportFilterName.isEmpty())
486-
{
487-
beans::PropertyValue aValue;
488-
aValue.Name = "FilterName";
489-
aValue.Value <<= maImportFilterName;
490-
aFilterOptions.push_back(aValue);
491-
}
492-
493454
// Output name at load time, so in the case of a hang, the name of the hanging input file is visible.
494455
if (!isExported())
495456
{
@@ -498,14 +459,7 @@ void SwModelTestBase::loadURL(OUString const& rURL, const char* pName, const cha
498459
mnStartTime = osl_getGlobalTimer();
499460
}
500461

501-
mxComponent
502-
= loadFromDesktop(rURL, OUString(), comphelper::containerToSequence(aFilterOptions));
503-
504-
if (pPassword)
505-
{
506-
CPPUNIT_ASSERT_MESSAGE("Password set but not requested",
507-
xInteractionHandler->wasPasswordRequested());
508-
}
462+
UnoApiXmlTest::load(rURL, pPassword);
509463

510464
discardDumpedLayout();
511465
if (pName && mustCalcLayoutOf(pName))

test/source/unoapi_test.cxx

+54-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <com/sun/star/frame/XStorable.hpp>
1515
#include <comphelper/processfactory.hxx>
1616
#include <comphelper/propertyvalue.hxx>
17+
#include <comphelper/sequence.hxx>
1718

1819
#include <sfx2/app.hxx>
1920
#include <sfx2/objsh.hxx>
@@ -56,16 +57,63 @@ OUString UnoApiTest::createFileURL(std::u16string_view aFileBase)
5657
return m_directories.getSrcRootURL() + m_aBaseString + "/" + aFileBase;
5758
}
5859

59-
OUString UnoApiTest::loadFromURL(std::u16string_view aFileBase)
60+
void UnoApiTest::setTestInteractionHandler(const char* pPassword,
61+
std::vector<beans::PropertyValue>& rFilterOptions)
62+
{
63+
OUString sPassword = OUString::createFromAscii(pPassword);
64+
rFilterOptions.emplace_back();
65+
xInteractionHandler
66+
= rtl::Reference<TestInteractionHandler>(new TestInteractionHandler(sPassword));
67+
css::uno::Reference<task::XInteractionHandler2> const xInteraction(xInteractionHandler);
68+
rFilterOptions[0].Name = "InteractionHandler";
69+
rFilterOptions[0].Value <<= xInteraction;
70+
}
71+
72+
void UnoApiTest::load(OUString const& rURL, const char* pPassword)
6073
{
6174
if (mxComponent.is())
6275
{
6376
mxComponent->dispose();
6477
mxComponent.clear();
6578
}
6679

80+
std::vector<beans::PropertyValue> aFilterOptions;
81+
82+
if (pPassword)
83+
{
84+
setTestInteractionHandler(pPassword, aFilterOptions);
85+
}
86+
87+
if (!maImportFilterOptions.isEmpty())
88+
{
89+
beans::PropertyValue aValue;
90+
aValue.Name = "FilterOptions";
91+
aValue.Value <<= maImportFilterOptions;
92+
aFilterOptions.push_back(aValue);
93+
}
94+
95+
if (!maImportFilterName.isEmpty())
96+
{
97+
beans::PropertyValue aValue;
98+
aValue.Name = "FilterName";
99+
aValue.Value <<= maImportFilterName;
100+
aFilterOptions.push_back(aValue);
101+
}
102+
103+
mxComponent
104+
= loadFromDesktop(rURL, OUString(), comphelper::containerToSequence(aFilterOptions));
105+
106+
if (pPassword)
107+
{
108+
CPPUNIT_ASSERT_MESSAGE("Password set but not requested",
109+
xInteractionHandler->wasPasswordRequested());
110+
}
111+
}
112+
113+
OUString UnoApiTest::loadFromURL(std::u16string_view aFileBase, const char* pPassword)
114+
{
67115
OUString aFileName = createFileURL(aFileBase);
68-
mxComponent = loadFromDesktop(aFileName);
116+
load(aFileName, pPassword);
69117
return aFileName;
70118
}
71119

@@ -139,17 +187,17 @@ void UnoApiTest::save(const OUString& rFilter, const char* pPassword)
139187

140188
void UnoApiTest::saveAndClose(const OUString& rFilter)
141189
{
142-
save(rFilter);
190+
save(rFilter, nullptr);
143191

144192
mxComponent->dispose();
145193
mxComponent.clear();
146194
}
147195

148-
void UnoApiTest::saveAndReload(const OUString& rFilter)
196+
void UnoApiTest::saveAndReload(const OUString& rFilter, const char* pPassword)
149197
{
150-
saveAndClose(rFilter);
198+
save(rFilter, pPassword);
151199

152-
mxComponent = loadFromDesktop(maTempFile.GetURL());
200+
load(maTempFile.GetURL(), pPassword);
153201
}
154202

155203
std::unique_ptr<vcl::pdf::PDFiumDocument> UnoApiTest::parsePDFExport(const OString& rPassword)

0 commit comments

Comments
 (0)