diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-02-11 23:14:18 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-02-15 08:18:39 +0100 |
commit | 3c24fe20ec6cb450abc4a822d323874ebbaecb10 (patch) | |
tree | eca31da310686d2eeb273ffada795c00c62d168c /sc/qa/unit | |
parent | 7714bee48caafc80135f3df78e00b5e407e7ee22 (diff) |
don't export a document twice in a test when not needed
XPathHelper::parseExport2() exports the document, which duplicates
what saveAndReload() does, it's enough to use the first export.
Change-Id: I36d740765d9267a45e37bd72c7b68e8dbd1a405c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129855
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc/qa/unit')
-rw-r--r-- | sc/qa/unit/helper/qahelper.cxx | 32 | ||||
-rw-r--r-- | sc/qa/unit/helper/qahelper.hxx | 10 | ||||
-rw-r--r-- | sc/qa/unit/jumbosheets-test.cxx | 12 |
3 files changed, 28 insertions, 26 deletions
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index 6bef6d0823f4..5f0ae6389df9 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -700,11 +700,11 @@ void ScBootstrapFixture::createCSVPath(std::u16string_view aFileBase, OUString& ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell& rShell, const OUString &rFilter, - const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags nFormatType, const OUString* pPassword, bool bClose) + const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags nFormatType, + std::shared_ptr<utl::TempFile>* pTempFileOut, const OUString* pPassword, bool bClose) { - - utl::TempFile aTempFile; - SfxMedium aStoreMedium( aTempFile.GetURL(), StreamMode::STD_WRITE ); + auto pTempFile = std::make_shared<utl::TempFile>(); + SfxMedium aStoreMedium( pTempFile->GetURL(), StreamMode::STD_WRITE ); SotClipboardFormatId nExportFormat = SotClipboardFormatId::NONE; if (nFormatType == ODS_FORMAT_TYPE) nExportFormat = SotClipboardFormatId::STARCHART_8; @@ -728,49 +728,51 @@ ScDocShellRef ScBootstrapFixture::saveAndReload( if (bClose) rShell.DoClose(); - //std::cout << "File: " << aTempFile.GetURL() << std::endl; + //std::cout << "File: " << pTempFile->GetURL() << std::endl; SotClipboardFormatId nFormat = SotClipboardFormatId::NONE; if (nFormatType == ODS_FORMAT_TYPE) nFormat = SotClipboardFormatId::STARCALC_8; - ScDocShellRef xDocSh = load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat, SOFFICE_FILEFORMAT_CURRENT, pPassword ); + ScDocShellRef xDocSh = load(pTempFile->GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat, SOFFICE_FILEFORMAT_CURRENT, pPassword ); if(nFormatType == XLSX_FORMAT_TYPE) - validate(aTempFile.GetFileName(), test::OOXML); + validate(pTempFile->GetFileName(), test::OOXML); else if (nFormatType == ODS_FORMAT_TYPE) - validate(aTempFile.GetFileName(), test::ODF); - aTempFile.EnableKillingFile(); + validate(pTempFile->GetFileName(), test::ODF); + pTempFile->EnableKillingFile(); + if(pTempFileOut) + *pTempFileOut = pTempFile; return xDocSh; } -ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell& rShell, sal_Int32 nFormat ) +ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFile>* pTempFile ) { OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ; OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8); - ScDocShellRef xDocSh = saveAndReload(rShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType); + ScDocShellRef xDocSh = saveAndReload(rShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType, pTempFile); CPPUNIT_ASSERT(xDocSh.is()); return xDocSh; } -ScDocShellRef ScBootstrapFixture::saveAndReloadPassword( ScDocShell& rShell, sal_Int32 nFormat ) +ScDocShellRef ScBootstrapFixture::saveAndReloadPassword( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFile>* pTempFile ) { 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(rShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType, &aPass); + ScDocShellRef xDocSh = saveAndReload(rShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType, pTempFile, &aPass); CPPUNIT_ASSERT(xDocSh.is()); return xDocSh; } -ScDocShellRef ScBootstrapFixture::saveAndReloadNoClose( ScDocShell& rShell, sal_Int32 nFormat ) +ScDocShellRef ScBootstrapFixture::saveAndReloadNoClose( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFile>* pTempFile ) { OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ; OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8); - ScDocShellRef xDocSh = saveAndReload(rShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType, nullptr, false); + ScDocShellRef xDocSh = saveAndReload(rShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType, pTempFile, nullptr, false); CPPUNIT_ASSERT(xDocSh.is()); return xDocSh; diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx index b61734fd1da1..130875371bcb 100644 --- a/sc/qa/unit/helper/qahelper.hxx +++ b/sc/qa/unit/helper/qahelper.hxx @@ -215,12 +215,12 @@ public: void createCSVPath(std::u16string_view aFileBase, OUString& rCSVPath); ScDocShellRef saveAndReload(ScDocShell& rShell, const OUString &rFilter, - const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags nFormatType, const OUString* pPassword = nullptr, - bool bClose = true ); + const OUString &rUserData, const OUString& rTypeName, SfxFilterFlags nFormatType, + std::shared_ptr<utl::TempFile>* pTempFile = nullptr, const OUString* pPassword = nullptr, bool bClose = true ); - ScDocShellRef saveAndReload( ScDocShell& rShell, sal_Int32 nFormat ); - ScDocShellRef saveAndReloadPassword( ScDocShell& rShell, sal_Int32 nFormat ); - ScDocShellRef saveAndReloadNoClose( ScDocShell& rShell, sal_Int32 nFormat ); + ScDocShellRef saveAndReload( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFile>* pTempFile = nullptr ); + ScDocShellRef saveAndReloadPassword( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFile>* pTempFile = nullptr ); + ScDocShellRef saveAndReloadNoClose( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFile>* pTempFile = nullptr ); std::shared_ptr<utl::TempFile> saveAs(ScDocShell& rShell, sal_Int32 nFormat); std::shared_ptr<utl::TempFile> exportTo(ScDocShell& rShell, sal_Int32 nFormat); diff --git a/sc/qa/unit/jumbosheets-test.cxx b/sc/qa/unit/jumbosheets-test.cxx index 74ad1cffb61a..091fc2438c19 100644 --- a/sc/qa/unit/jumbosheets-test.cxx +++ b/sc/qa/unit/jumbosheets-test.cxx @@ -137,15 +137,15 @@ void ScJumboSheetsTest::testRoundtripColumnRange() CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C:C)"), rDoc.GetFormula(1, 0, 0)); } - ScDocShellRef xDocSh2 = saveAndReloadNoClose(*xDocSh1, FORMAT_ODS); + std::shared_ptr<utl::TempFile> exportedFile; + ScDocShellRef xDocSh2 = saveAndReloadNoClose(*xDocSh1, FORMAT_ODS, &exportedFile); CPPUNIT_ASSERT(xDocSh2.is()); { ScDocument& rDoc = xDocSh2->GetDocument(); CPPUNIT_ASSERT_EQUAL(OUString("=SUM(2:2)"), rDoc.GetFormula(0, 0, 0)); CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C:C)"), rDoc.GetFormula(1, 0, 0)); - xmlDocUniquePtr pDoc - = XPathHelper::parseExport2(*this, *xDocSh2, m_xSFactory, "content.xml", FORMAT_ODS); + xmlDocUniquePtr pDoc = XPathHelper::parseExport(exportedFile, m_xSFactory, "content.xml"); CPPUNIT_ASSERT(pDoc); assertXPath(pDoc, "/office:document-content/office:body/office:spreadsheet/table:table/" @@ -157,15 +157,15 @@ void ScJumboSheetsTest::testRoundtripColumnRange() "formula", "of:=SUM([.C:.C])"); } - ScDocShellRef xDocSh3 = saveAndReloadNoClose(*xDocSh1, FORMAT_XLSX); + ScDocShellRef xDocSh3 = saveAndReloadNoClose(*xDocSh1, FORMAT_XLSX, &exportedFile); CPPUNIT_ASSERT(xDocSh3.is()); { ScDocument& rDoc = xDocSh3->GetDocument(); CPPUNIT_ASSERT_EQUAL(OUString("=SUM(2:2)"), rDoc.GetFormula(0, 0, 0)); CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C:C)"), rDoc.GetFormula(1, 0, 0)); - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh3, m_xSFactory, - "xl/worksheets/sheet1.xml", FORMAT_XLSX); + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(exportedFile, m_xSFactory, "xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pDoc); assertXPathContent(pDoc, "/x:worksheet/x:sheetData/x:row[1]/x:c[1]/x:f", "SUM(2:2)"); assertXPathContent(pDoc, "/x:worksheet/x:sheetData/x:row[1]/x:c[2]/x:f", "SUM(C:C)"); |