sc/qa/unit/helper/qahelper.cxx        |   28 +++++++++++++++++--
 sc/qa/unit/helper/qahelper.hxx        |    3 +-
 sc/qa/unit/subsequent_export-test.cxx |   50 +---------------------------------
 3 files changed, 30 insertions(+), 51 deletions(-)

New commits:
commit b84afd2188d6993c91081885dc24664bd3f1cc73
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Oct 20 17:34:12 2020 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Oct 21 08:01:37 2020 +0200

    CppunitTest_sc_subsequent_export: factor out duplicated code
    
    Change-Id: I87381f243e71e302df92b60c6afde15e78ab7828
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104570
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 1b0d5e3de64b..db5efcea77e7 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -12,6 +12,7 @@
 #include "debughelper.hxx"
 #include <drwlayer.hxx>
 #include <comphelper/sequence.hxx>
+#include <comphelper/storagehelper.hxx>
 #include <compiler.hxx>
 #include <conditio.hxx>
 #include <stlsheet.hxx>
@@ -31,6 +32,7 @@
 #include <svl/gridprinter.hxx>
 #include <sfx2/docfilt.hxx>
 #include <sfx2/docfile.hxx>
+#include <sfx2/frame.hxx>
 #include <unotools/tempfile.hxx>
 #include <scitems.hxx>
 #include <tokenarray.hxx>
@@ -660,7 +662,7 @@ void ScBootstrapFixture::createCSVPath(const OUString& 
aFileBase, OUString& rCSV
 
 ScDocShellRef ScBootstrapFixture::saveAndReload(
     ScDocShell* pShell, const OUString &rFilter,
-    const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags 
nFormatType)
+    const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags 
nFormatType, const OUString* pPassword)
 {
 
     utl::TempFile aTempFile;
@@ -674,6 +676,16 @@ ScDocShellRef ScBootstrapFixture::saveAndReload(
         rUserData, "private:factory/scalc*" );
     pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
     aStoreMedium.SetFilter(pExportFilter);
+
+    if (pPassword)
+    {
+        SfxItemSet* pExportSet = aStoreMedium.GetItemSet();
+        uno::Sequence< beans::NamedValue > aEncryptionData = 
comphelper::OStorageHelper::CreatePackageEncryptionData( *pPassword );
+        pExportSet->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, 
makeAny(aEncryptionData)));
+
+        uno::Reference< embed::XStorage > xMedStorage = 
aStoreMedium.GetStorage();
+        ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( 
xMedStorage, aEncryptionData );
+    }
     pShell->DoSaveAs( aStoreMedium );
     pShell->DoClose();
 
@@ -683,7 +695,7 @@ ScDocShellRef ScBootstrapFixture::saveAndReload(
     if (nFormatType == ODS_FORMAT_TYPE)
         nFormat = SotClipboardFormatId::STARCALC_8;
 
-    ScDocShellRef xDocSh = load(aTempFile.GetURL(), rFilter, rUserData, 
rTypeName, nFormatType, nFormat );
+    ScDocShellRef xDocSh = load(aTempFile.GetURL(), rFilter, rUserData, 
rTypeName, nFormatType, nFormat, SOFFICE_FILEFORMAT_CURRENT, pPassword );
     if(nFormatType == XLSX_FORMAT_TYPE)
         validate(aTempFile.GetFileName(), test::OOXML);
     else if (nFormatType == ODS_FORMAT_TYPE)
@@ -702,6 +714,18 @@ ScDocShellRef ScBootstrapFixture::saveAndReload( 
ScDocShell* pShell, sal_Int32 n
     return xDocSh;
 }
 
+ScDocShellRef ScBootstrapFixture::saveAndReloadPassword( ScDocShell* pShell, 
sal_Int32 nFormat )
+{
+    OUString aFilterName(aFileFormats[nFormat].pFilterName, 
strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
+    OUString aFilterType(aFileFormats[nFormat].pTypeName, 
strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
+    OUString aPass("test");
+
+    ScDocShellRef xDocSh = saveAndReload(pShell, aFilterName, OUString(), 
aFilterType, aFileFormats[nFormat].nFormatType, &aPass);
+
+    CPPUNIT_ASSERT(xDocSh.is());
+    return xDocSh;
+}
+
 std::shared_ptr<utl::TempFile> ScBootstrapFixture::saveAs( ScDocShell* pShell, 
sal_Int32 nFormat )
 {
     OUString aFilterName(aFileFormats[nFormat].pFilterName, 
strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index d8ffa146a6aa..ad518d160f18 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -190,9 +190,10 @@ public:
     void createCSVPath(const OUString& aFileBase, OUString& rCSVPath);
 
     ScDocShellRef saveAndReload(ScDocShell* pShell, const OUString &rFilter,
-    const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags 
nFormatType);
+    const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags 
nFormatType, const OUString* pPassword = nullptr );
 
     ScDocShellRef saveAndReload( ScDocShell* pShell, sal_Int32 nFormat );
+    ScDocShellRef saveAndReloadPassword( ScDocShell* pShell, sal_Int32 nFormat 
);
 
     std::shared_ptr<utl::TempFile> saveAs(ScDocShell* pShell, sal_Int32 
nFormat);
     std::shared_ptr<utl::TempFile> exportTo(ScDocShell* pShell, sal_Int32 
nFormat);
diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index a1a129e1b636..71fa266a191e 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -12,7 +12,6 @@
 #include <config_features.h>
 
 #include <sfx2/docfile.hxx>
-#include <sfx2/frame.hxx>
 #include <sfx2/sfxmodelfactory.hxx>
 #include <sfx2/sfxsids.hrc>
 #include <sfx2/docfilt.hxx>
@@ -75,7 +74,6 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/graphic/GraphicType.hpp>
 #include <com/sun/star/sheet/GlobalSheetSettings.hpp>
-#include <comphelper/storagehelper.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -90,8 +88,6 @@ public:
     virtual void setUp() override;
     virtual void tearDown() override;
 
-    ScDocShellRef saveAndReloadPassword( ScDocShell*, const OUString&, const 
OUString&, const OUString&, SfxFilterFlags );
-
     void test();
     void testTdf90104();
     void testTdf111876();
@@ -488,41 +484,6 @@ void ScExportTest::registerNamespaces(xmlXPathContextPtr& 
pXmlXPathCtx)
     }
 }
 
-ScDocShellRef ScExportTest::saveAndReloadPassword(ScDocShell* pShell, const 
OUString &rFilter,
-    const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags 
nFormatType)
-{
-    utl::TempFile aTempFile;
-    aTempFile.EnableKillingFile();
-    SfxMedium aStoreMedium( aTempFile.GetURL(), StreamMode::STD_WRITE );
-    SotClipboardFormatId nExportFormat = SotClipboardFormatId::NONE;
-    if (nFormatType == ODS_FORMAT_TYPE)
-        nExportFormat = SotClipboardFormatId::STARCHART_8;
-    auto pExportFilter = std::make_shared<SfxFilter>(
-        rFilter,
-        OUString(), nFormatType, nExportFormat, rTypeName, OUString(),
-        rUserData, "private:factory/scalc*" );
-    pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
-    aStoreMedium.SetFilter(pExportFilter);
-    SfxItemSet* pExportSet = aStoreMedium.GetItemSet();
-    uno::Sequence< beans::NamedValue > aEncryptionData = 
comphelper::OStorageHelper::CreatePackageEncryptionData( "test" );
-    pExportSet->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, 
makeAny(aEncryptionData)));
-
-    uno::Reference< embed::XStorage > xMedStorage = aStoreMedium.GetStorage();
-    ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xMedStorage, 
aEncryptionData );
-
-    pShell->DoSaveAs( aStoreMedium );
-    pShell->DoClose();
-
-    //std::cout << "File: " << aTempFile.GetURL() << std::endl;
-
-    SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
-    if (nFormatType == ODS_FORMAT_TYPE)
-        nFormat = SotClipboardFormatId::STARCALC_8;
-
-    OUString aPass("test");
-    return load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, 
nFormatType, nFormat, SOFFICE_FILEFORMAT_CURRENT, &aPass);
-}
-
 void ScExportTest::test()
 {
     ScDocShell* pShell = new ScDocShell(
@@ -597,10 +558,7 @@ void ScExportTest::testPasswordExportODS()
 
     rDoc.SetValue(0, 0, 0, 1.0);
 
-    sal_Int32 nFormat = FORMAT_ODS;
-    OUString aFilterName(getFileFormats()[nFormat].pFilterName, 
strlen(getFileFormats()[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
-    OUString aFilterType(getFileFormats()[nFormat].pTypeName, 
strlen(getFileFormats()[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
-    ScDocShellRef xDocSh = saveAndReloadPassword(pShell, aFilterName, 
OUString(), aFilterType, getFileFormats()[nFormat].nFormatType);
+    ScDocShellRef xDocSh = saveAndReloadPassword(pShell, FORMAT_ODS);
 
     CPPUNIT_ASSERT(xDocSh.is());
     ScDocument& rLoadedDoc = xDocSh->GetDocument();
@@ -621,11 +579,7 @@ void ScExportTest::testTdf134332()
 
     ASSERT_DOUBLES_EQUAL(238.0, rDoc.GetValue(ScAddress(0,10144,0)));
 
-    sal_Int32 nFormat = FORMAT_ODS;
-    OUString aFilterName(getFileFormats()[nFormat].pFilterName, 
strlen(getFileFormats()[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
-    OUString aFilterType(getFileFormats()[nFormat].pTypeName, 
strlen(getFileFormats()[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
-    ScDocShellRef xDocSh = 
saveAndReloadPassword(static_cast<ScDocShell*>(rDoc.GetDocumentShell()), 
aFilterName, OUString(),
-            aFilterType, getFileFormats()[nFormat].nFormatType);
+    ScDocShellRef xDocSh = saveAndReloadPassword(xShell.get(), FORMAT_ODS);
 
     // Without the fixes in place, it would have failed here
     CPPUNIT_ASSERT(xDocSh.is());
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to