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>
This commit is contained in:
Xisco Fauli 2022-11-11 16:44:59 +01:00
parent 4c9093c954
commit 7986d35eee
23 changed files with 97 additions and 74 deletions

View file

@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_firebird_test, \
$(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \
comphelper \
cppu \
cppuhelper \
dbaxml \
firebird_sdbc \
sal \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,embeddedobj_general, \
$(eval $(call gb_CppunitTest_use_libraries,embeddedobj_general, \
comphelper \
cppu \
cppuhelper \
embobj \
sal \
subsequenttest \

View file

@ -14,7 +14,9 @@
#include <string_view>
#include <rtl/ref.hxx>
#include <test/bootstrapfixture.hxx>
#include <test/testinteractionhandler.hxx>
#include <unotest/macros_test.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <osl/file.hxx>
@ -28,24 +30,32 @@ class OOO_DLLPUBLIC_TEST UnoApiTest : public test::BootstrapFixture, public unot
public:
UnoApiTest(OUString path);
OUString createFileURL(std::u16string_view aFileBase);
OUString loadFromURL(std::u16string_view aFileBase);
virtual void setUp() override;
virtual void tearDown() override;
OUString createFileURL(std::u16string_view aFileBase);
void load(const OUString& rURL, const char* pPassword = nullptr);
OUString loadFromURL(std::u16string_view aFileBase, const char* pPassword = nullptr);
css::uno::Any executeMacro(const OUString& rScriptURL,
const css::uno::Sequence<css::uno::Any>& rParams = {});
void save(const OUString& rFilter, const char* pPassword = nullptr);
void saveAndClose(const OUString& rFilter);
void saveAndReload(const OUString& rFilter);
void saveAndReload(const OUString& rFilter, const char* pPassword = nullptr);
std::unique_ptr<vcl::pdf::PDFiumDocument> parsePDFExport(const OString& rPassword = OString());
void skipValidation() { mbSkipValidation = true; }
void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; }
void setImportFilterOptions(const OUString& rFilterOptions)
{
maImportFilterOptions = rFilterOptions;
}
void setImportFilterName(const OUString& rFilterName) { maImportFilterName = rFilterName; }
protected:
// reference to document component that we are testing
css::uno::Reference<css::lang::XComponent> mxComponent;
@ -54,10 +64,19 @@ protected:
SvMemoryStream maMemory; // Underlying memory for parsed PDF files.
rtl::Reference<TestInteractionHandler> xInteractionHandler;
private:
void
setTestInteractionHandler(const char* pPassword,
std::vector<com::sun::star::beans::PropertyValue>& rFilterOptions);
bool mbSkipValidation;
OUString m_aBaseString;
OUString maFilterOptions;
OUString maImportFilterOptions;
OUString maImportFilterName;
};
#endif // INCLUDED_TEST_UNOAPI_TEST_HXX

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_drawingml, \
$(eval $(call gb_CppunitTest_use_libraries,oox_drawingml, \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_export, \
$(eval $(call gb_CppunitTest_use_libraries,oox_export, \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_mathml, \
$(eval $(call gb_CppunitTest_use_libraries,oox_mathml, \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_shape, \
$(eval $(call gb_CppunitTest_use_libraries,oox_shape, \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,oox_vml, \
$(eval $(call gb_CppunitTest_use_libraries,oox_vml, \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sc_functionlistobj, \
$(eval $(call gb_CppunitTest_use_libraries,sc_functionlistobj, \
cppu \
cppuhelper \
sal \
subsequenttest \
test \

View file

@ -28,6 +28,7 @@ endif
$(eval $(call gb_CppunitTest_use_libraries,sc_pdf_export, \
comphelper \
cppu \
cppuhelper \
editeng \
sal \
sax \

View file

@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sc_$(1), \
$(eval $(call gb_CppunitTest_use_libraries,sc_$(1), \
comphelper \
cppu \
cppuhelper \
sal \
salhelper \
sc \

View file

@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sd_filter_eppt, \
$(eval $(call gb_CppunitTest_use_libraries,sd_filter_eppt, \
comphelper \
cppu \
cppuhelper \
sd \
sal \
subsequenttest \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sfx2_doc, \
$(eval $(call gb_CppunitTest_use_libraries,sfx2_doc, \
comphelper \
cppu \
cppuhelper \
sal \
subsequenttest \
test \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sfx2_view, \
$(eval $(call gb_CppunitTest_use_libraries,sfx2_view, \
comphelper \
cppu \
cppuhelper \
sal \
subsequenttest \
test \

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,svx_styles, \
$(eval $(call gb_CppunitTest_use_libraries,svx_styles, \
comphelper \
cppu \
cppuhelper \
svx \
sal \
subsequenttest \

View file

@ -24,7 +24,6 @@
#include "swqahelperdllapi.h"
#include <test/unoapixml_test.hxx>
#include <test/testinteractionhandler.hxx>
#include <unotools/tempfile.hxx>
#include <doc.hxx>
@ -94,13 +93,9 @@ class PDFiumDocument;
class SWQAHELPER_DLLPUBLIC SwModelTestBase : public UnoApiXmlTest
{
private:
OUString maImportFilterOptions;
OUString maImportFilterName;
bool mbExported; ///< Does maTempFile already contain something useful?
protected:
rtl::Reference<TestInteractionHandler> xInteractionHandler;
xmlBufferPtr mpXmlBuffer;
const char* mpFilter;
@ -112,16 +107,6 @@ protected:
void paste(std::u16string_view aFilename, css::uno::Reference<css::text::XTextRange> const& xTextRange);
public:
void setImportFilterOptions(const OUString &rFilterOptions)
{
maImportFilterOptions = rFilterOptions;
}
void setImportFilterName(const OUString &rFilterName)
{
maImportFilterName = rFilterName;
}
SwModelTestBase(const OUString& pTestDocumentPath = OUString(), const char* pFilter = "");
protected:
@ -361,8 +346,6 @@ protected:
bool isExported(){ return mbExported; }
private:
void setTestInteractionHandler(const char* pPassword, std::vector<beans::PropertyValue>& rFilterOptions);
void loadURL(OUString const& rURL, const char* pName, const char* pPassword);
void load(const char* pName, const char* pPassword = nullptr)

View file

@ -20,7 +20,6 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/sequence.hxx>
#include <officecfg/Office/Common.hxx>
#include <rtl/ustrbuf.hxx>
#include <sfx2/app.hxx>
@ -448,48 +447,10 @@ uno::Reference<drawing::XShape> SwModelTestBase::getTextFrameByName(const OUStri
return xShape;
}
void SwModelTestBase::setTestInteractionHandler(const char* pPassword,
std::vector<beans::PropertyValue>& rFilterOptions)
{
OUString sPassword = OUString::createFromAscii(pPassword);
rFilterOptions.emplace_back();
xInteractionHandler
= rtl::Reference<TestInteractionHandler>(new TestInteractionHandler(sPassword));
uno::Reference<task::XInteractionHandler2> const xInteraction(xInteractionHandler);
rFilterOptions[0].Name = "InteractionHandler";
rFilterOptions[0].Value <<= xInteraction;
}
void SwModelTestBase::header() {}
void SwModelTestBase::loadURL(OUString const& rURL, const char* pName, const char* pPassword)
{
if (mxComponent.is())
mxComponent->dispose();
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);
}
// Output name at load time, so in the case of a hang, the name of the hanging input file is visible.
if (!isExported())
{
@ -498,14 +459,7 @@ void SwModelTestBase::loadURL(OUString const& rURL, const char* pName, const cha
mnStartTime = osl_getGlobalTimer();
}
mxComponent
= loadFromDesktop(rURL, OUString(), comphelper::containerToSequence(aFilterOptions));
if (pPassword)
{
CPPUNIT_ASSERT_MESSAGE("Password set but not requested",
xInteractionHandler->wasPasswordRequested());
}
UnoApiXmlTest::load(rURL, pPassword);
discardDumpedLayout();
if (pName && mustCalcLayoutOf(pName))

View file

@ -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)

View file

@ -30,6 +30,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \
basegfx \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_rtftok, \
basegfx \
comphelper \
cppu \
cppuhelper \
oox \
sal \
subsequenttest \

View file

@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,xmloff_draw, \
$(eval $(call gb_CppunitTest_use_libraries,xmloff_draw, \
comphelper \
cppu \
cppuhelper \
embobj \
sal \
subsequenttest \

View file

@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,xmloff_style, \
$(eval $(call gb_CppunitTest_use_libraries,xmloff_style, \
comphelper \
cppu \
cppuhelper \
subsequenttest \
embobj \
sal \

View file

@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,xmloff_text, \
$(eval $(call gb_CppunitTest_use_libraries,xmloff_text, \
comphelper \
cppu \
cppuhelper \
embobj \
sal \
subsequenttest \