|
14 | 14 | #include <com/sun/star/frame/XStorable.hpp>
|
15 | 15 | #include <comphelper/processfactory.hxx>
|
16 | 16 | #include <comphelper/propertyvalue.hxx>
|
| 17 | +#include <comphelper/sequence.hxx> |
17 | 18 |
|
18 | 19 | #include <sfx2/app.hxx>
|
19 | 20 | #include <sfx2/objsh.hxx>
|
@@ -56,16 +57,63 @@ OUString UnoApiTest::createFileURL(std::u16string_view aFileBase)
|
56 | 57 | return m_directories.getSrcRootURL() + m_aBaseString + "/" + aFileBase;
|
57 | 58 | }
|
58 | 59 |
|
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) |
60 | 73 | {
|
61 | 74 | if (mxComponent.is())
|
62 | 75 | {
|
63 | 76 | mxComponent->dispose();
|
64 | 77 | mxComponent.clear();
|
65 | 78 | }
|
66 | 79 |
|
| 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 | +{ |
67 | 115 | OUString aFileName = createFileURL(aFileBase);
|
68 |
| - mxComponent = loadFromDesktop(aFileName); |
| 116 | + load(aFileName, pPassword); |
69 | 117 | return aFileName;
|
70 | 118 | }
|
71 | 119 |
|
@@ -139,17 +187,17 @@ void UnoApiTest::save(const OUString& rFilter, const char* pPassword)
|
139 | 187 |
|
140 | 188 | void UnoApiTest::saveAndClose(const OUString& rFilter)
|
141 | 189 | {
|
142 |
| - save(rFilter); |
| 190 | + save(rFilter, nullptr); |
143 | 191 |
|
144 | 192 | mxComponent->dispose();
|
145 | 193 | mxComponent.clear();
|
146 | 194 | }
|
147 | 195 |
|
148 |
| -void UnoApiTest::saveAndReload(const OUString& rFilter) |
| 196 | +void UnoApiTest::saveAndReload(const OUString& rFilter, const char* pPassword) |
149 | 197 | {
|
150 |
| - saveAndClose(rFilter); |
| 198 | + save(rFilter, pPassword); |
151 | 199 |
|
152 |
| - mxComponent = loadFromDesktop(maTempFile.GetURL()); |
| 200 | + load(maTempFile.GetURL(), pPassword); |
153 | 201 | }
|
154 | 202 |
|
155 | 203 | std::unique_ptr<vcl::pdf::PDFiumDocument> UnoApiTest::parsePDFExport(const OString& rPassword)
|
|
0 commit comments