diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-11 16:44:59 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-11 20:09:41 +0100 |
commit | 7986d35eee84fdf391c563602fb348758e1cd254 (patch) | |
tree | 0be65fbf8655c1461f712537ba0130f99b4d8da2 /test | |
parent | 4c9093c95445c154c4ce7db1756ca936ea0752ca (diff) |
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 <xiscofauli@libreoffice.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/source/unoapi_test.cxx | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/test/source/unoapi_test.cxx b/test/source/unoapi_test.cxx index bc9395246c8c..29d4020d5337 100644 --- a/test/source/unoapi_test.cxx +++ b/test/source/unoapi_test.cxx @@ -14,6 +14,7 @@ #include <com/sun/star/frame/XStorable.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/sequence.hxx> #include <sfx2/app.hxx> #include <sfx2/objsh.hxx> @@ -56,7 +57,19 @@ OUString UnoApiTest::createFileURL(std::u16string_view aFileBase) return m_directories.getSrcRootURL() + m_aBaseString + "/" + aFileBase; } -OUString UnoApiTest::loadFromURL(std::u16string_view aFileBase) +void UnoApiTest::setTestInteractionHandler(const char* pPassword, + std::vector<beans::PropertyValue>& rFilterOptions) +{ + OUString sPassword = OUString::createFromAscii(pPassword); + rFilterOptions.emplace_back(); + xInteractionHandler + = rtl::Reference<TestInteractionHandler>(new TestInteractionHandler(sPassword)); + css::uno::Reference<task::XInteractionHandler2> const xInteraction(xInteractionHandler); + rFilterOptions[0].Name = "InteractionHandler"; + rFilterOptions[0].Value <<= xInteraction; +} + +void UnoApiTest::load(OUString const& rURL, const char* pPassword) { if (mxComponent.is()) { @@ -64,8 +77,43 @@ OUString UnoApiTest::loadFromURL(std::u16string_view aFileBase) mxComponent.clear(); } + std::vector<beans::PropertyValue> aFilterOptions; + + if (pPassword) + { + setTestInteractionHandler(pPassword, aFilterOptions); + } + + if (!maImportFilterOptions.isEmpty()) + { + beans::PropertyValue aValue; + aValue.Name = "FilterOptions"; + aValue.Value <<= maImportFilterOptions; + aFilterOptions.push_back(aValue); + } + + if (!maImportFilterName.isEmpty()) + { + beans::PropertyValue aValue; + aValue.Name = "FilterName"; + aValue.Value <<= maImportFilterName; + aFilterOptions.push_back(aValue); + } + + mxComponent + = loadFromDesktop(rURL, OUString(), comphelper::containerToSequence(aFilterOptions)); + + if (pPassword) + { + CPPUNIT_ASSERT_MESSAGE("Password set but not requested", + xInteractionHandler->wasPasswordRequested()); + } +} + +OUString UnoApiTest::loadFromURL(std::u16string_view aFileBase, const char* pPassword) +{ OUString aFileName = createFileURL(aFileBase); - mxComponent = loadFromDesktop(aFileName); + load(aFileName, pPassword); return aFileName; } @@ -139,17 +187,17 @@ void UnoApiTest::save(const OUString& rFilter, const char* pPassword) void UnoApiTest::saveAndClose(const OUString& rFilter) { - save(rFilter); + save(rFilter, nullptr); mxComponent->dispose(); mxComponent.clear(); } -void UnoApiTest::saveAndReload(const OUString& rFilter) +void UnoApiTest::saveAndReload(const OUString& rFilter, const char* pPassword) { - saveAndClose(rFilter); + save(rFilter, pPassword); - mxComponent = loadFromDesktop(maTempFile.GetURL()); + load(maTempFile.GetURL(), pPassword); } std::unique_ptr<vcl::pdf::PDFiumDocument> UnoApiTest::parsePDFExport(const OString& rPassword) |