include/test/unoapi_test.hxx | 1 sc/CppunitTest_sc_filters_test.mk | 1 sc/CppunitTest_sc_opencl_test.mk | 1 sc/CppunitTest_sc_parallelism.mk | 1 sc/Library_scqahelper.mk | 1 sc/qa/unit/helper/qahelper.cxx | 190 +++ sc/qa/unit/helper/qahelper.hxx | 36 sc/qa/unit/subsequent_export_test.cxx | 1694 +++++++++++++--------------------- sc/subsequent_setup.mk | 52 - sc/ucalc_setup.mk | 1 test/source/unoapi_test.cxx | 5 11 files changed, 899 insertions(+), 1084 deletions(-)
New commits: commit a865d042eff3cdd4d78badcc55c9d8fdf9ef52aa Author: Xisco Fauli <[email protected]> AuthorDate: Thu Nov 10 14:18:12 2022 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Nov 15 11:56:34 2022 +0100 CppunitTest_sc_subsequent_export_test: inherit from UnoApiXmlTest Some notes: * testLinkedGraphicRT needed to be adapted. Saving to Calc Office Open XML doesn't keep IsLinkedGraphic. Reported in tdf#152036. No idea why it didn't fail before * Some tests used "generic_HTML" as export filter format, which is wrong. Instead, "HTML (StarCalc)" should have been used. But then, the test would have failed with - unsatisfied query for interface of type com.sun.star.sheet.XSpreadsheetDocument! So trying to export to html in those tests is not expected. No idea why it didn't fail before * testTdf90299 fails now with - Expected: 'file:///tmp/lu23738863wthph.tmp/dummy.xls'#$Sheet1.A1 - Actual : 'file:///tmp/lu23738863wthph.tmp/lu23738863wthpg.tmp/dummy.xls'#$Sheet1.A1 I added a TODO to check it later * testNamedRangeBugfdo62729 fails on mac with an infinite loop Change-Id: I63168583a47f510d1ac22971a274e28d085de61b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142576 Tested-by: Xisco Fauli <[email protected]> Reviewed-by: Xisco Fauli <[email protected]> diff --git a/include/test/unoapi_test.hxx b/include/test/unoapi_test.hxx index 0277131e31f7..461b52dcad93 100644 --- a/include/test/unoapi_test.hxx +++ b/include/test/unoapi_test.hxx @@ -34,6 +34,7 @@ public: virtual void tearDown() override; OUString createFileURL(std::u16string_view aFileBase); + OUString createFilePath(std::u16string_view aFileBase); void load(const OUString& rURL, const char* pPassword = nullptr); OUString loadFromURL(std::u16string_view aFileBase, const char* pPassword = nullptr); diff --git a/sc/CppunitTest_sc_filters_test.mk b/sc/CppunitTest_sc_filters_test.mk index 67ef60664081..ca12691c73a4 100644 --- a/sc/CppunitTest_sc_filters_test.mk +++ b/sc/CppunitTest_sc_filters_test.mk @@ -24,6 +24,7 @@ endif $(eval $(call gb_CppunitTest_use_externals,sc_filters_test, \ boost_headers \ mdds_headers \ + libxml2 \ )) $(eval $(call gb_CppunitTest_use_libraries,sc_filters_test, \ diff --git a/sc/CppunitTest_sc_opencl_test.mk b/sc/CppunitTest_sc_opencl_test.mk index 9320d6757408..0807e14c08e1 100644 --- a/sc/CppunitTest_sc_opencl_test.mk +++ b/sc/CppunitTest_sc_opencl_test.mk @@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_use_externals,sc_opencl_test, \ boost_headers \ $(call gb_Helper_optional,OPENCL,clew) \ mdds_headers \ + libxml2 \ )) $(eval $(call gb_CppunitTest_use_libraries,sc_opencl_test, \ diff --git a/sc/CppunitTest_sc_parallelism.mk b/sc/CppunitTest_sc_parallelism.mk index 8511d209f3d6..74b88f3b7d80 100644 --- a/sc/CppunitTest_sc_parallelism.mk +++ b/sc/CppunitTest_sc_parallelism.mk @@ -51,6 +51,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_parallelism, \ sb \ sfx \ sot \ + subsequenttest \ svl \ svt \ svx \ diff --git a/sc/Library_scqahelper.mk b/sc/Library_scqahelper.mk index 78bbae5cd9ec..15289fea87af 100644 --- a/sc/Library_scqahelper.mk +++ b/sc/Library_scqahelper.mk @@ -50,6 +50,7 @@ $(eval $(call gb_Library_use_libraries,scqahelper,\ sc \ sfx \ sot \ + subsequenttest \ svl \ svt \ svx \ diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index 45816c8f6fd4..59d4177ef19c 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -313,6 +313,120 @@ void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat) CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(1,1,2,3,1,2)), rRange3); } +void testFormats(ScModelTestBase* pTest, ScDocument* pDoc,std::u16string_view sFormat) +{ + //test Sheet1 with csv file + OUString aCSVFileName = pTest->createFilePath(u"contentCSV/numberFormat.csv"); + testFile(aCSVFileName, *pDoc, 0, StringType::PureString); + //need to test the color of B3 + //it's not a font color! + //formatting for B5: # ??/100 gets lost during import + + //test Sheet2 + const ScPatternAttr* pPattern = pDoc->GetPattern(0, 0, 1); + vcl::Font aFont; + pPattern->GetFont(aFont,SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 10", tools::Long(200), aFont.GetFontSize().getHeight()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font color should be black", COL_AUTO, aFont.GetColor()); + pPattern = pDoc->GetPattern(0,1,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 12", tools::Long(240), aFont.GetFontSize().getHeight()); + pPattern = pDoc->GetPattern(0,2,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be italic", ITALIC_NORMAL, aFont.GetItalic()); + pPattern = pDoc->GetPattern(0,4,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight()); + pPattern = pDoc->GetPattern(1,0,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be blue", COL_BLUE, aFont.GetColor()); + pPattern = pDoc->GetPattern(1,1,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a single line", STRIKEOUT_SINGLE, aFont.GetStrikeout()); + //some tests on sheet2 only for ods + if (sFormat == u"calc8") + { + pPattern = pDoc->GetPattern(1,2,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a double line", STRIKEOUT_DOUBLE, aFont.GetStrikeout()); + pPattern = pDoc->GetPattern(1,3,1); + pPattern->GetFont(aFont, SC_AUTOCOL_RAW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be underlined with a dotted line", LINESTYLE_DOTTED, aFont.GetUnderline()); + //check row height import + //disable for now until we figure out cause of win tinderboxes test failures + //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(256), pDoc->GetRowHeight(0,1) ); //0.178in + //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(304), pDoc->GetRowHeight(1,1) ); //0.211in + //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(477), pDoc->GetRowHeight(5,1) ); //0.3311in + //check column width import + CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(555), pDoc->GetColWidth(4,1) ); //0.3854in + CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1280), pDoc->GetColWidth(5,1) ); //0.889in + CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(4153), pDoc->GetColWidth(6,1) ); //2.8839in + //test case for i53253 where a cell has text with different styles and space between the text. + OUString aTestStr = pDoc->GetString(3,0,1); + OUString aKnownGoodStr("text14 space"); + CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr ); + //test case for cell text with line breaks. + aTestStr = pDoc->GetString(3,5,1); + aKnownGoodStr = "Hello,\nCalc!"; + CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr ); + } + pPattern = pDoc->GetPattern(1,4,1); + Color aColor = pPattern->GetItem(ATTR_BACKGROUND).GetColor(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("background color should be green", COL_LIGHTGREEN, aColor); + pPattern = pDoc->GetPattern(2,0,1); + SvxCellHorJustify eHorJustify = pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned centre horizontally", SvxCellHorJustify::Center, eHorJustify); + //test alignment + pPattern = pDoc->GetPattern(2,1,1); + eHorJustify = pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned right horizontally", SvxCellHorJustify::Right, eHorJustify); + pPattern = pDoc->GetPattern(2,2,1); + eHorJustify = pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned block horizontally", SvxCellHorJustify::Block, eHorJustify); + + //test Sheet3 only for ods and xlsx + if ( sFormat == u"calc8" || sFormat == u"Calc Office Open XML" ) + { + aCSVFileName = pTest->createFilePath(u"contentCSV/conditionalFormatting.csv"); + testCondFile(aCSVFileName, pDoc, 2); + // test parent cell style import ( fdo#55198 ) + if ( sFormat == u"Calc Office Open XML" ) + { + pPattern = pDoc->GetPattern(1,1,3); + ScStyleSheet* pStyleSheet = const_cast<ScStyleSheet*>(pPattern->GetStyleSheet()); + // check parent style name + OUString sExpected("Excel Built-in Date"); + OUString sResult = pStyleSheet->GetName(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("parent style for Sheet4.B2 is 'Excel Built-in Date'", sExpected, sResult); + // check align of style + SfxItemSet& rItemSet = pStyleSheet->GetItemSet(); + eHorJustify = rItemSet.Get( ATTR_HOR_JUSTIFY ).GetValue(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should be aligned centre horizontally", SvxCellHorJustify::Center, eHorJustify); + // check date format ( should be just month e.g. 29 ) + sResult =pDoc->GetString( 1,1,3 ); + sExpected = "29"; + CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should just display month", sExpected, sResult ); + + // check actual align applied to cell, should be the same as + // the style + eHorJustify = pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("cell with 'Excel Built-in Date' style should be aligned centre horizontally", SvxCellHorJustify::Center, eHorJustify); + } + } + + ScConditionalFormat* pCondFormat = pDoc->GetCondFormat(0,0,2); + const ScRangeList& rRange = pCondFormat->GetRange(); + CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(0,0,2,3,0,2)), rRange); + + pCondFormat = pDoc->GetCondFormat(0,1,2); + const ScRangeList& rRange2 = pCondFormat->GetRange(); + CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(0,1,2,0,1,2)), rRange2); + + pCondFormat = pDoc->GetCondFormat(1,1,2); + const ScRangeList& rRange3 = pCondFormat->GetRange(); + CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(1,1,2,3,1,2)), rRange3); +} + const SdrOle2Obj* getSingleOleObject(ScDocument& rDoc, sal_uInt16 nPage) { // Retrieve the chart object instance from the 2nd page (for the 2nd sheet). @@ -787,18 +901,6 @@ ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell& rShell, sal_Int32 n return xDocSh; } -ScDocShellRef ScBootstrapFixture::saveAndReloadPassword( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFileNamed>* 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, pTempFile, &aPass); - - CPPUNIT_ASSERT(xDocSh.is()); - return xDocSh; -} - std::shared_ptr<utl::TempFileNamed> ScBootstrapFixture::exportTo( ScDocShell& rShell, sal_Int32 nFormat, bool bValidate ) { OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ; @@ -912,6 +1014,70 @@ void ScSimpleBootstrapFixture::tearDown() test::BootstrapFixture::tearDown(); } +void ScModelTestBase::createScDoc(const char* pName, const char* pPassword) +{ + if (!pName) + load("private:factory/scalc"); + else + loadFromURL(OUString::createFromAscii(pName), pPassword); + + uno::Reference<lang::XServiceInfo> xServiceInfo(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.sheet.SpreadsheetDocument")); +} + +ScDocument* ScModelTestBase::getScDoc() +{ + ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get()); + CPPUNIT_ASSERT(pModelObj); + return pModelObj->GetDocument(); +} + +ScDocShell* ScModelTestBase::getScDocShell() +{ + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + return pDocSh; +} + +void ScModelTestBase::miscRowHeightsTest( TestParam2 const * aTestValues, unsigned int numElems) +{ + for ( unsigned int index=0; index<numElems; ++index ) + { + const std::u16string_view sFileName = aTestValues[ index ].sTestDoc; + const OUString sExportType = aTestValues[ index ].sExportType; + loadFromURL(sFileName); + + if ( !sExportType.isEmpty() ) + saveAndReload(sExportType); + + ScDocument* pDoc = getScDoc(); + + for (int i=0; i<aTestValues[ index ].nRowData; ++i) + { + SCROW nRow = aTestValues[ index ].pData[ i].nStartRow; + SCROW nEndRow = aTestValues[ index ].pData[ i ].nEndRow; + SCTAB nTab = aTestValues[ index ].pData[ i ].nTab; + int nExpectedHeight = aTestValues[ index ].pData[ i ].nExpectedHeight; + if ( nExpectedHeight == -1 ) + nExpectedHeight = convertTwipToMm100(ScGlobal::GetStandardRowHeight()); + bool bCheckOpt = ( ( aTestValues[ index ].pData[ i ].nCheck & CHECK_OPTIMAL ) == CHECK_OPTIMAL ); + for ( ; nRow <= nEndRow; ++nRow ) + { + SAL_INFO( "sc.qa", " checking row " << nRow << " for height " << nExpectedHeight ); + int nHeight = convertTwipToMm100(pDoc->GetRowHeight(nRow, nTab, false)); + if ( bCheckOpt ) + { + bool bOpt = !(pDoc->GetRowFlags( nRow, nTab ) & CRFlags::ManualSize); + CPPUNIT_ASSERT_EQUAL(aTestValues[ index ].pData[ i ].bOptimal, bOpt); + } + CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight); + } + } + } +} + std::string to_std_string(const OUString& rStr) { return std::string(rStr.toUtf8().getStr()); diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx index 5105bbdc73ba..f2dc6fae94e2 100644 --- a/sc/qa/unit/helper/qahelper.hxx +++ b/sc/qa/unit/helper/qahelper.hxx @@ -14,6 +14,7 @@ #include <cppunit/SourceLine.h> +#include <test/unoapixml_test.hxx> #include <test/bootstrapfixture.hxx> #include <comphelper/documentconstants.hxx> @@ -70,7 +71,6 @@ class SdrOle2Obj; class ScRangeList; class ScTokenArray; - // data format for row height tests struct TestParam { @@ -90,6 +90,23 @@ struct TestParam RowData const * pData; }; +struct TestParam2 +{ + struct RowData + { + SCROW nStartRow; + SCROW nEndRow; + SCTAB nTab; + int nExpectedHeight; // -1 for default height + int nCheck; // currently only CHECK_OPTIMAL ( we could add CHECK_MANUAL etc.) + bool bOptimal; + }; + const std::u16string_view sTestDoc; + const OUString sExportType; // empty for import test, otherwise this is an export test + int nRowData; + RowData const * pData; +}; + struct RangeNameDef { const char* mpName; @@ -224,7 +241,6 @@ public: std::shared_ptr<utl::TempFileNamed>* pTempFile = nullptr, const OUString* pPassword = nullptr, bool bClose = true ); ScDocShellRef saveAndReload( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFileNamed>* pTempFile = nullptr ); - ScDocShellRef saveAndReloadPassword( ScDocShell& rShell, sal_Int32 nFormat, std::shared_ptr<utl::TempFileNamed>* pTempFile = nullptr ); std::shared_ptr<utl::TempFileNamed> exportTo(ScDocShell& rShell, sal_Int32 nFormat, bool bValidate = true); @@ -245,6 +261,20 @@ protected: ScDocument* m_pDoc; }; +class SCQAHELPER_DLLPUBLIC ScModelTestBase : public UnoApiXmlTest +{ +public: + ScModelTestBase(OUString path) + : UnoApiXmlTest(path) + { + } + + void createScDoc(const char* pName = nullptr, const char* pPassword = nullptr); + ScDocument* getScDoc(); + ScDocShell* getScDocShell(); + void miscRowHeightsTest( TestParam2 const * aTestValues, unsigned int numElems); +}; + #define ASSERT_DOUBLES_EQUAL( expected, result ) \ CPPUNIT_ASSERT_DOUBLES_EQUAL( (expected), (result), 1e-14 ) @@ -259,6 +289,8 @@ SCQAHELPER_DLLPUBLIC void checkFormula(ScDocument& rDoc, const ScAddress& rPos, SCQAHELPER_DLLPUBLIC void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat); +SCQAHELPER_DLLPUBLIC void testFormats(ScModelTestBase* pTest, ScDocument* pDoc,std::u16string_view sFormat); + SCQAHELPER_DLLPUBLIC ScTokenArray* getTokens(ScDocument& rDoc, const ScAddress& rPos); SCQAHELPER_DLLPUBLIC std::string to_std_string(const OUString& rStr); diff --git a/sc/qa/unit/subsequent_export_test.cxx b/sc/qa/unit/subsequent_export_test.cxx index d4f80f1ed103..8533400c36a8 100644 --- a/sc/qa/unit/subsequent_export_test.cxx +++ b/sc/qa/unit/subsequent_export_test.cxx @@ -14,7 +14,7 @@ #include <sfx2/sfxmodelfactory.hxx> #include "helper/qahelper.hxx" -#include "helper/xpath.hxx" +#include <test/unoapixml_test.hxx> #include "helper/shared_test_impl.hxx" #include <userdat.hxx> @@ -58,13 +58,16 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::uno; -class ScExportTest : public ScBootstrapFixture, public XmlTestTools +class ScExportTest : public ScModelTestBase { protected: virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override; public: - ScExportTest(); + ScExportTest() + : ScModelTestBase("sc/qa/unit/data") + { + } void test(); void testDefaultFontHeight(); @@ -143,12 +146,12 @@ public: void testSharedFormulaExportXLSX(); void testSharedFormulaStringResultExportXLSX(); - void testFunctionsExcel2010(sal_uLong nFormatType); + void testFunctionsExcel2010(const OUString& sFormatType); void testFunctionsExcel2010XLSX(); void testFunctionsExcel2010XLS(); void testFunctionsExcel2010ODS(); - void testCeilingFloor(sal_uLong nFormatType); + void testCeilingFloor(const OUString& sFormatType); void testCeilingFloorXLSX(); void testCeilingFloorODSToXLSX(); void testCeilingFloorXLS(); @@ -293,7 +296,7 @@ public: CPPUNIT_TEST_SUITE_END(); private: - void testExcelCellBorders(sal_uLong nFormatType); + void testExcelCellBorders(const OUString& sFormatType); }; void ScExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) @@ -304,76 +307,64 @@ void ScExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) void ScExportTest::test() { - ScDocShell* pShell - = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS - | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); - pShell->DoInitNew(); + createScDoc(); - ScDocument& rDoc = pShell->GetDocument(); + ScDocument* pDoc = getScDoc(); - rDoc.SetValue(0, 0, 0, 1.0); + pDoc->SetValue(0, 0, 0, 1.0); - ScDocShellRef xDocSh = saveAndReload(*pShell, FORMAT_ODS); + saveAndReload("calc8"); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rLoadedDoc = xDocSh->GetDocument(); - double aVal = rLoadedDoc.GetValue(0, 0, 0); + pDoc = getScDoc(); + double aVal = pDoc->GetValue(0, 0, 0); ASSERT_DOUBLES_EQUAL(aVal, 1.0); - xDocSh->DoClose(); } void ScExportTest::testDefaultFontHeight() { - ScDocShellRef xDocSh = new ScDocShell; - xDocSh->DoInitNew(); + createScDoc(); - ScDocumentPool* pPool = xDocSh->GetDocument().GetPool(); + ScDocument* pDoc = getScDoc(); + ScDocumentPool* pPool = pDoc->GetPool(); pPool->SetPoolDefaultItem(SvxFontHeightItem(400, 100, ATTR_FONT_HEIGHT)); pPool->SetPoolDefaultItem(SvxFontHeightItem(400, 100, ATTR_CJK_FONT_HEIGHT)); pPool->SetPoolDefaultItem(SvxFontHeightItem(400, 100, ATTR_CTL_FONT_HEIGHT)); - xDocSh = saveAndReload(*xDocSh, FORMAT_ODS); + saveAndReload("calc8"); - pPool = xDocSh->GetDocument().GetPool(); + pDoc = getScDoc(); + pPool = pDoc->GetPool(); const SvxFontHeightItem& rItem = pPool->GetDefaultItem(ATTR_FONT_HEIGHT); CPPUNIT_ASSERT_EQUAL(sal_uInt32(400), rItem.GetHeight()); const SvxFontHeightItem& rCJKItem = pPool->GetDefaultItem(ATTR_CJK_FONT_HEIGHT); CPPUNIT_ASSERT_EQUAL(sal_uInt32(400), rCJKItem.GetHeight()); const SvxFontHeightItem& rCTLItem = pPool->GetDefaultItem(ATTR_CTL_FONT_HEIGHT); CPPUNIT_ASSERT_EQUAL(sal_uInt32(400), rCTLItem.GetHeight()); - - xDocSh->DoClose(); } void ScExportTest::testTdf139167() { - ScDocShellRef xShell = loadDoc(u"tdf139167.", FORMAT_XLSX); + createScDoc("xlsx/tdf139167.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/styles.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/styles.xml"); CPPUNIT_ASSERT(pDoc); assertXPath(pDoc, "/x:styleSheet/x:cellStyles", "count", "6"); assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:fill/x:patternFill/x:bgColor", "rgb", "FFFFFF00"); - - xDocSh->DoClose(); } void ScExportTest::testTdf113271() { - ScDocShellRef xShell = loadDoc(u"tdf113271.", FORMAT_XLSX); + createScDoc("xlsx/tdf113271.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/styles.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/styles.xml"); CPPUNIT_ASSERT(pDoc); assertXPath(pDoc, "/x:styleSheet/x:fonts", "count", "6"); @@ -383,21 +374,16 @@ void ScExportTest::testTdf113271() // - Actual : FFFFFFFF assertXPath(pDoc, "/x:styleSheet/x:fonts/x:font[1]/x:color", "rgb", "FF000000"); assertXPath(pDoc, "/x:styleSheet/x:fonts/x:font[1]/x:name", "val", "Calibri"); - - xDocSh->DoClose(); } void ScExportTest::testTdf139394() { - ScDocShellRef xShell = loadDoc(u"tdf139394.", FORMAT_XLSX); + createScDoc("xlsx/tdf139394.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); - xmlDocUniquePtr pDoc - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pDoc); assertXPathContent( @@ -415,21 +401,16 @@ void ScExportTest::testTdf139394() "/x:worksheet/x:extLst/x:ext/x14:conditionalFormattings/x14:conditionalFormatting[3]/" "x14:cfRule/xm:f", "LEFT(A3,LEN($B$3))=$B$3"); - - xDocSh->DoClose(); } void ScExportTest::testExtCondFormatXLSX() { - ScDocShellRef xShell = loadDoc(u"tdf139021.", FORMAT_XLSX); + createScDoc("xlsx/tdf139021.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); - xmlDocUniquePtr pDoc - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pDoc); assertXPath( @@ -462,22 +443,17 @@ void ScExportTest::testExtCondFormatXLSX() "/x:worksheet/x:extLst/x:ext/x14:conditionalFormattings/x14:conditionalFormatting[2]/" "x14:cfRule/xm:f[2]", "$B$2"); - - xDocSh->DoClose(); } void ScExportTest::testTdf90104() { - ScDocShellRef xShell = loadDoc(u"tdf90104.", FORMAT_XLSX); + createScDoc("xlsx/tdf90104.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); + save("Calc Office Open XML"); - xmlDocUniquePtr pDoc - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pDoc); assertXPathContent(pDoc, @@ -494,89 +470,72 @@ void ScExportTest::testTdf111876() { // Document with relative path hyperlink - ScDocShellRef xShell = loadDoc(u"tdf111876.", FORMAT_XLSX); + createScDoc("xlsx/tdf111876.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - xmlDocUniquePtr pDoc = XPathHelper::parseExport2( - *this, *xDocSh, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels", FORMAT_XLSX); + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/worksheets/_rels/sheet1.xml.rels"); CPPUNIT_ASSERT(pDoc); OUString sTarget = getXPath(pDoc, "/rels:Relationships/rels:Relationship", "Target"); // Document is saved to the temporary directory, relative path should be different than original one CPPUNIT_ASSERT(sTarget != "../xls/bug-fixes.xls"); - - xDocSh->DoClose(); } void ScExportTest::testPasswordExportODS() { - ScDocShell* pShell - = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS - | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); - pShell->DoInitNew(); + createScDoc(); - ScDocument& rDoc = pShell->GetDocument(); + ScDocument* pDoc = getScDoc(); - rDoc.SetValue(0, 0, 0, 1.0); + pDoc->SetValue(0, 0, 0, 1.0); - ScDocShellRef xDocSh = saveAndReloadPassword(*pShell, FORMAT_ODS); + saveAndReload("calc8", /*pPassword*/ "test"); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rLoadedDoc = xDocSh->GetDocument(); - double aVal = rLoadedDoc.GetValue(0, 0, 0); + pDoc = getScDoc(); + double aVal = pDoc->GetValue(0, 0, 0); ASSERT_DOUBLES_EQUAL(aVal, 1.0); - - xDocSh->DoClose(); } void ScExportTest::testTdf134332() { - ScDocShellRef xShell = loadDoc(u"tdf134332.", FORMAT_ODS); + createScDoc("ods/tdf134332.ods"); - ScDocument& rDoc = xShell->GetDocument(); + ScDocument* pDoc = getScDoc(); - ASSERT_DOUBLES_EQUAL(190.0, rDoc.GetValue(ScAddress(0, 0, 0))); + ASSERT_DOUBLES_EQUAL(190.0, pDoc->GetValue(ScAddress(0, 0, 0))); - ASSERT_DOUBLES_EQUAL(238.0, rDoc.GetValue(ScAddress(0, 10144, 0))); + ASSERT_DOUBLES_EQUAL(238.0, pDoc->GetValue(ScAddress(0, 10144, 0))); - ScDocShellRef xDocSh = saveAndReloadPassword(*xShell, FORMAT_ODS); + saveAndReload("calc8", /*pPassword*/ "test"); // Without the fixes in place, it would have failed here - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rLoadedDoc = xDocSh->GetDocument(); - ASSERT_DOUBLES_EQUAL(190.0, rLoadedDoc.GetValue(ScAddress(0, 0, 0))); + pDoc = getScDoc(); + ASSERT_DOUBLES_EQUAL(190.0, pDoc->GetValue(ScAddress(0, 0, 0))); - ASSERT_DOUBLES_EQUAL(238.0, rLoadedDoc.GetValue(ScAddress(0, 10144, 0))); - - xDocSh->DoClose(); + ASSERT_DOUBLES_EQUAL(238.0, pDoc->GetValue(ScAddress(0, 10144, 0))); } void ScExportTest::testConditionalFormatExportODS() { - ScDocShellRef xShell = loadDoc(u"new_cond_format_test_export.", FORMAT_ODS); - - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - OUString aCSVPath; - createCSVPath("new_cond_format_test_export.", aCSVPath); - testCondFile(aCSVPath, &rDoc, 0); + createScDoc("ods/new_cond_format_test_export.ods"); - xDocSh->DoClose(); + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); + OUString aCSVPath = createFilePath(u"contentCSV/new_cond_format_test_export.csv"); + testCondFile(aCSVPath, &*pDoc, 0); } void ScExportTest::testCondFormatExportCellIs() { - ScDocShellRef xShell = loadDoc(u"condFormat_cellis.", FORMAT_XLSX); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + createScDoc("xlsx/condFormat_cellis.xlsx"); + saveAndReload("Calc Office Open XML"); - ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT_EQUAL(size_t(1), rDoc.GetCondFormList(0)->size()); + ScDocument* pDoc = getScDoc(); + CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetCondFormList(0)->size()); - ScConditionalFormat* pFormat = rDoc.GetCondFormat(0, 0, 0); + ScConditionalFormat* pFormat = pDoc->GetCondFormat(0, 0, 0); CPPUNIT_ASSERT(pFormat); const ScFormatEntry* pEntry = pFormat->GetEntry(0); @@ -598,40 +557,32 @@ void ScExportTest::testCondFormatExportCellIs() aStr = pCondition->GetExpression(ScAddress(0, 0, 0), 0); CPPUNIT_ASSERT_EQUAL(OUString("$Sheet2.$A$1"), aStr); - - xDocSh->DoClose(); } void ScExportTest::testConditionalFormatExportXLSX() { - ScDocShellRef xShell = loadDoc(u"new_cond_format_test_export.", FORMAT_XLSX); + createScDoc("xlsx/new_cond_format_test_export.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); + saveAndReload("Calc Office Open XML"); + ScDocument* pDoc = getScDoc(); { - OUString aCSVPath; - createCSVPath("new_cond_format_test_export.", aCSVPath); - testCondFile(aCSVPath, &rDoc, 0); + OUString aCSVPath = createFilePath(u"contentCSV/new_cond_format_test_export.csv"); + testCondFile(aCSVPath, &*pDoc, 0); } { - OUString aCSVPath; - createCSVPath("new_cond_format_test_sheet2.", aCSVPath); - testCondFile(aCSVPath, &rDoc, 1); + OUString aCSVPath = createFilePath(u"contentCSV/new_cond_format_test_sheet2.csv"); + testCondFile(aCSVPath, &*pDoc, 1); } - - xDocSh->DoClose(); } void ScExportTest::testTdf99856_dataValidationTest() { - ScDocShellRef xShell = loadDoc(u"tdf99856_dataValidationTest.", FORMAT_ODS); + createScDoc("ods/tdf99856_dataValidationTest.ods"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); + saveAndReload("Calc Office Open XML"); - ScDocument& rDoc = xDocSh->GetDocument(); - const ScValidationData* pData = rDoc.GetValidationEntry(2); + ScDocument* pDoc = getScDoc(); + const ScValidationData* pData = pDoc->GetValidationEntry(2); CPPUNIT_ASSERT(pData); // Excel can't open corrupt file if the list is longer than 255 characters @@ -639,27 +590,24 @@ void ScExportTest::testTdf99856_dataValidationTest() pData->FillSelectionList(aList, ScAddress(0, 1, 1)); CPPUNIT_ASSERT_EQUAL(size_t(18), aList.size()); CPPUNIT_ASSERT_EQUAL(OUString("18 Missis"), aList[17].GetString()); - - xDocSh->DoClose(); } void ScExportTest::testProtectionKeyODS_UTF16LErtlSHA1() { OUString const password("1012345678901234567890123456789012345678901234567890"); - ScDocShellRef xShell = loadDoc(u"protection-key1.", FORMAT_FODS); + createScDoc("fods/protection-key1.fods"); - ScDocument& rDoc = xShell->GetDocument(); - ScDocProtection* const pDocProt(rDoc.GetDocProtection()); + ScDocument* pDoc = getScDoc(); + ScDocProtection* const pDocProt(pDoc->GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - const ScTableProtection* const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection* const pTabProt(pDoc->GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we // round-trip the password as-is - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS); - xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + save("calc8"); + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); assertXPath(pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='vbnhxyBKtPHCA1wB21zG1Oha8ZA=' and " @@ -668,27 +616,24 @@ void ScExportTest::testProtectionKeyODS_UTF16LErtlSHA1() "//table:table[@table:protected='true' and " "@table:protection-key='vbnhxyBKtPHCA1wB21zG1Oha8ZA=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha1']"); - - xShell->DoClose(); } void ScExportTest::testProtectionKeyODS_UTF8SHA1() { OUString const password("1012345678901234567890123456789012345678901234567890"); - ScDocShellRef xShell = loadDoc(u"protection-key2.", FORMAT_FODS); + createScDoc("fods/protection-key2.fods"); - ScDocument& rDoc = xShell->GetDocument(); - ScDocProtection* const pDocProt(rDoc.GetDocProtection()); + ScDocument* pDoc = getScDoc(); + ScDocProtection* const pDocProt(pDoc->GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - const ScTableProtection* const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection* const pTabProt(pDoc->GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we // round-trip the password as-is - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS); - xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + save("calc8"); + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); assertXPath(pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='nLHas0RIwepGDaH4c2hpyIUvIS8=' and " @@ -697,27 +642,24 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA1() "//table:table[@table:protected='true' and " "@table:protection-key='nLHas0RIwepGDaH4c2hpyIUvIS8=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha1']"); - - xShell->DoClose(); } void ScExportTest::testProtectionKeyODS_UTF8SHA256ODF12() { OUString const password("1012345678901234567890123456789012345678901234567890"); - ScDocShellRef xShell = loadDoc(u"protection-key3.", FORMAT_FODS); + createScDoc("fods/protection-key3.fods"); - ScDocument& rDoc = xShell->GetDocument(); - ScDocProtection* const pDocProt(rDoc.GetDocProtection()); + ScDocument* pDoc = getScDoc(); + ScDocProtection* const pDocProt(pDoc->GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - const ScTableProtection* const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection* const pTabProt(pDoc->GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we // round-trip the password as-is - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS); - xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + save("calc8"); + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); assertXPath( pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " @@ -728,27 +670,24 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA256ODF12() "//table:table[@table:protected='true' and " "@table:protection-key='1tnJohagR2T0yF/v69hLPuumSTsj32CumW97nkKGuSQ=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha256']"); - - xShell->DoClose(); } void ScExportTest::testProtectionKeyODS_UTF8SHA256W3C() { OUString const password("1012345678901234567890123456789012345678901234567890"); - ScDocShellRef xShell = loadDoc(u"protection-key4.", FORMAT_FODS); + createScDoc("fods/protection-key4.fods"); - ScDocument& rDoc = xShell->GetDocument(); - ScDocProtection* const pDocProt(rDoc.GetDocProtection()); + ScDocument* pDoc = getScDoc(); + ScDocProtection* const pDocProt(pDoc->GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - const ScTableProtection* const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection* const pTabProt(pDoc->GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we // round-trip the password as-is - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS); - xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + save("calc8"); + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); assertXPath( pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " @@ -759,27 +698,24 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA256W3C() "//table:table[@table:protected='true' and " "@table:protection-key='1tnJohagR2T0yF/v69hLPuumSTsj32CumW97nkKGuSQ=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha256']"); - - xShell->DoClose(); } void ScExportTest::testProtectionKeyODS_XL_SHA1() { OUString const password("1012345678901234567890123456789012345678901234567890"); - ScDocShellRef xShell = loadDoc(u"protection-key5.", FORMAT_FODS); + createScDoc("fods/protection-key5.fods"); - ScDocument& rDoc = xShell->GetDocument(); - ScDocProtection* const pDocProt(rDoc.GetDocProtection()); + ScDocument* pDoc = getScDoc(); + ScDocProtection* const pDocProt(pDoc->GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - const ScTableProtection* const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection* const pTabProt(pDoc->GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we // round-trip the password as-is - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS); - xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + save("calc8"); + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); assertXPath( pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " @@ -794,77 +730,61 @@ void ScExportTest::testProtectionKeyODS_XL_SHA1() "@table:protection-key-digest-algorithm='http://docs.oasis-open.org/office/ns/table/" "legacy-hash-excel' and " "@loext:protection-key-digest-algorithm-2='http://www.w3.org/2000/09/xmldsig#sha1']"); - - xShell->DoClose(); } void ScExportTest::testColorScaleExportODS() { - ScDocShellRef xShell = loadDoc(u"colorscale.", FORMAT_ODS); + createScDoc("ods/colorscale.ods"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("calc8"); - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); - testColorScale2Entry_Impl(rDoc); - testColorScale3Entry_Impl(rDoc); - - xDocSh->DoClose(); + testColorScale2Entry_Impl(*pDoc); + testColorScale3Entry_Impl(*pDoc); } void ScExportTest::testColorScaleExportXLSX() { - ScDocShellRef xShell = loadDoc(u"colorscale.", FORMAT_XLSX); - - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + createScDoc("xlsx/colorscale.xlsx"); - ScDocument& rDoc = xDocSh->GetDocument(); + saveAndReload("Calc Office Open XML"); - testColorScale2Entry_Impl(rDoc); - testColorScale3Entry_Impl(rDoc); + ScDocument* pDoc = getScDoc(); - xDocSh->DoClose(); + testColorScale2Entry_Impl(*pDoc); + testColorScale3Entry_Impl(*pDoc); } void ScExportTest::testDataBarExportODS() { - ScDocShellRef xShell = loadDoc(u"databar.", FORMAT_ODS); + createScDoc("ods/databar.ods"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("calc8"); - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); - testDataBar_Impl(rDoc); - - xDocSh->DoClose(); + testDataBar_Impl(*pDoc); } void ScExportTest::testFormatExportODS() { - ScDocShellRef xShell = loadDoc(u"formats.", FORMAT_ODS); - - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); + createScDoc("ods/formats.ods"); - ScDocument& rDoc = xDocSh->GetDocument(); + saveAndReload("calc8"); - testFormats(this, &rDoc, FORMAT_ODS); + ScDocument* pDoc = getScDoc(); - xDocSh->DoClose(); + testFormats(this, &*pDoc, u"calc8"); } void ScExportTest::testCommentExportXLSX() { //tdf#104729 FILESAVE OpenOffice do not save author of the comment during export to .xlsx - ScDocShellRef xShell = loadDoc(u"comment.", FORMAT_ODS); + createScDoc("ods/comment.ods"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pComments - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/comments1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pComments = parseExport("xl/comments1.xml"); CPPUNIT_ASSERT(pComments); assertXPathContent(pComments, "/x:comments/x:authors/x:author[1]", "BAKO"); @@ -873,8 +793,7 @@ void ScExportTest::testCommentExportXLSX() assertXPathContent(pComments, "/x:comments/x:commentList/x:comment/x:text/x:r/x:t", "Komentarz"); - xmlDocUniquePtr pVmlDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); + xmlDocUniquePtr pVmlDrawing = parseExport("xl/drawings/vmlDrawing1.vml"); CPPUNIT_ASSERT(pVmlDrawing); //assertXPath(pVmlDrawing, "/xml/v:shapetype", "coordsize", "21600,21600"); @@ -889,52 +808,43 @@ void ScExportTest::testCommentExportXLSX() //tdf#117274 fix MSO interoperability with the secret VML shape type id assertXPath(pVmlDrawing, "/xml/v:shapetype", "id", "_x0000_t202"); assertXPath(pVmlDrawing, "/xml/v:shape", "type", "#_x0000_t202"); - - xShell->DoClose(); } void ScExportTest::testCommentExportXLSX_2_XLSX() { //tdf#117287 FILESAVE XLSX: Comments always disappear after opening the exported XLSX file with Excel - ScDocShellRef xShell = loadDoc(u"tdf117287_comment.", FORMAT_XLSX); + createScDoc("xlsx/tdf117287_comment.xlsx"); - ScDocument& rDoc = xShell->GetDocument(); + ScDocument* pDoc = getScDoc(); ScAddress aPosC9(2, 8, 0); - ScPostIt* pNote = rDoc.GetNote(aPosC9); + ScPostIt* pNote = pDoc->GetNote(aPosC9); CPPUNIT_ASSERT(pNote); CPPUNIT_ASSERT(!pNote->IsCaptionShown()); pNote->ShowCaption(aPosC9, true); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pComments - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/comments1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pComments = parseExport("xl/comments1.xml"); CPPUNIT_ASSERT(pComments); assertXPathContent(pComments, "/x:comments/x:commentList/x:comment/x:text/x:r/x:t", "visible comment"); - xmlDocUniquePtr pVmlDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); + xmlDocUniquePtr pVmlDrawing = parseExport("xl/drawings/vmlDrawing1.vml"); CPPUNIT_ASSERT(pVmlDrawing); assertXPath(pVmlDrawing, "/xml/v:shape/x:ClientData/x:Visible", 0); - - xShell->DoClose(); } #if HAVE_MORE_FONTS void ScExportTest::testCustomColumnWidthExportXLSX() { //tdf#100946 FILESAVE Excel on macOS ignored column widths in XLSX last saved by LO - ScDocShellRef xShell = loadDoc(u"custom_column_width.", FORMAT_ODS); + createScDoc("ods/custom_column_width.ods"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); // tdf#124741: check that we export default width, otherwise the skipped columns would have @@ -997,19 +907,16 @@ void ScExportTest::testCustomColumnWidthExportXLSX() assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "collapsed", "false"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "customFormat", "false"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "customHeight", "false"); - - xShell->DoClose(); } #endif void ScExportTest::testXfDefaultValuesXLSX() { //tdf#70565 FORMATTING: User Defined Custom Formatting is not applied during importing XLSX documents - ScDocShellRef xShell = loadDoc(u"xf_default_values.", FORMAT_XLSX); + createScDoc("xlsx/xf_default_values.xlsx"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/styles.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/styles.xml"); CPPUNIT_ASSERT(pSheet); // cellStyleXfs don't need xfId, so we need to make sure it is not saved @@ -1024,42 +931,10 @@ void ScExportTest::testXfDefaultValuesXLSX() // We expected that exactly 15 cellXfs:xf Nodes will be produced assertXPath(pSheet, "/x:styleSheet/x:cellXfs/x:xf", 14); - - xShell->DoClose(); } -namespace -{ -// TODO where to put this? -class Resetter -{ -private: - std::function<void()> m_Func; - -public: - Resetter(std::function<void()> const& rFunc) - : m_Func(rFunc) - { - } - ~Resetter() - { - try - { - m_Func(); - } - catch (...) // has to be reliable - { - fprintf(stderr, "resetter failed with exception\n"); - abort(); - } - } -}; - -} // namespace - -static auto verifySpreadsheet13(char const* const pTestName, ScDocShellRef& pShell) -> void +static auto verifySpreadsheet13(char const* const pTestName, ScDocument& rDoc) -> void { - ScDocument const& rDoc(pShell->GetDocument()); // OFFICE-2173 table:tab-color CPPUNIT_ASSERT_EQUAL_MESSAGE(pTestName, Color(0xff3838), rDoc.GetTabBgColor(0)); // OFFICE-3857 table:scale-to-X/table:scale-to-Y @@ -1077,10 +952,11 @@ static auto verifySpreadsheet13(char const* const pTestName, ScDocShellRef& pShe void ScExportTest::testODF13() { // import - ScDocShellRef pShell = loadDoc(u"spreadsheet13e.", FORMAT_ODS); + createScDoc("ods/spreadsheet13e.ods"); + ScDocument* pDoc = getScDoc(); // check model - verifySpreadsheet13("import", pShell); + verifySpreadsheet13("import", *pDoc); Resetter _([]() { std::shared_ptr<comphelper::ConfigurationChanges> pBatch( @@ -1096,27 +972,24 @@ void ScExportTest::testODF13() officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); pBatch->commit(); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*pShell, FORMAT_ODS); + // FIXME: Error: unexpected attribute "loext:scale-to-X" + skipValidation(); + + saveAndReload("calc8"); + pDoc = getScDoc(); // check XML - xmlDocUniquePtr pContentXml - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + xmlDocUniquePtr pContentXml = parseExport("content.xml"); assertXPath(pContentXml, "/office:document-content/office:automatic-styles/style:style/" "style:table-properties[@table:tab-color='#ff3838']"); - xmlDocUniquePtr pStylesXml - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "styles.xml"); + xmlDocUniquePtr pStylesXml = parseExport("styles.xml"); assertXPath(pStylesXml, "/office:document-styles/office:automatic-styles/style:page-layout/" "style:page-layout-properties[@style:scale-to-X='2']"); assertXPath(pStylesXml, "/office:document-styles/office:automatic-styles/style:page-layout/" "style:page-layout-properties[@style:scale-to-Y='3']"); - // reload - pShell = load(pXPathFile->GetURL(), "calc8", OUString(), OUString(), ODS_FORMAT_TYPE, - SotClipboardFormatId::STARCALC_8); - // check model - verifySpreadsheet13("1.3 reload", pShell); + verifySpreadsheet13("1.3 reload", *pDoc); } { // export ODF 1.2 Extended @@ -1125,28 +998,21 @@ void ScExportTest::testODF13() officecfg::Office::Common::Save::ODF::DefaultVersion::set(9, pBatch); pBatch->commit(); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = exportTo(*pShell, FORMAT_ODS, /*bValidate*/ false); - pShell->DoClose(); + saveAndReload("calc8"); + pDoc = getScDoc(); // check XML - xmlDocUniquePtr pContentXml - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + xmlDocUniquePtr pContentXml = parseExport("content.xml"); assertXPath(pContentXml, "/office:document-content/office:automatic-styles/style:style/" "style:table-properties[@tableooo:tab-color='#ff3838']"); - xmlDocUniquePtr pStylesXml - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "styles.xml"); + xmlDocUniquePtr pStylesXml = parseExport("styles.xml"); assertXPath(pStylesXml, "/office:document-styles/office:automatic-styles/style:page-layout/" "style:page-layout-properties[@loext:scale-to-X='2']"); assertXPath(pStylesXml, "/office:document-styles/office:automatic-styles/style:page-layout/" "style:page-layout-properties[@loext:scale-to-Y='3']"); - // reload - pShell = load(pXPathFile->GetURL(), "calc8", OUString(), OUString(), ODS_FORMAT_TYPE, - SotClipboardFormatId::STARCALC_8); - // check model - verifySpreadsheet13("1.2 Extended reload", pShell); + verifySpreadsheet13("1.2 Extended reload", *pDoc); } { // export ODF 1.2 @@ -1155,18 +1021,15 @@ void ScExportTest::testODF13() officecfg::Office::Common::Save::ODF::DefaultVersion::set(4, pBatch); pBatch->commit(); - std::shared_ptr<utl::TempFileNamed> pXPathFile = exportTo(*pShell, FORMAT_ODS); - pShell->DoClose(); + save("calc8"); // check XML - xmlDocUniquePtr pContentXml - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + xmlDocUniquePtr pContentXml = parseExport("content.xml"); assertXPathNoAttribute( pContentXml, "/office:document-content/office:automatic-styles/style:style/style:table-properties", "tab-color"); - xmlDocUniquePtr pStylesXml - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "styles.xml"); + xmlDocUniquePtr pStylesXml = parseExport("styles.xml"); assertXPathNoAttribute(pStylesXml, "/office:document-styles/office:automatic-styles/" "style:page-layout[1]/style:page-layout-properties", @@ -1184,12 +1047,10 @@ void ScExportTest::testColumnWidthResaveXLSX() { // tdf#91475 FILESAVE: Column width is not preserved in XLSX / after round trip. // Test if after resave .xlsx file, columns width is identical with previous one - ScDocShellRef xShell = loadDoc(u"different-column-width-excel2010.", FORMAT_XLSX); + createScDoc("xlsx/different-column-width-excel2010.xlsx"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); // In original Excel document the width is "24" @@ -1213,8 +1074,6 @@ void ScExportTest::testColumnWidthResaveXLSX() assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "customWidth", "true"); assertXPath(pSheet, "/x:worksheet/x:cols/x:col", 5); - - xShell->DoClose(); } #if HAVE_MORE_FONTS @@ -1224,65 +1083,62 @@ void ScExportTest::testColumnWidthExportFromODStoXLSX() // Test if after export .ods to .xlsx format, displayed columns width // is identical with previous (.ods) one - ScDocShellRef xShell = loadDoc(u"different-column-width.", FORMAT_ODS); + createScDoc("ods/different-column-width.ods"); - ScDocument& rOdsDoc = xShell->GetDocument(); + ScDocument* pDoc = getScDoc(); // Col 1, Tab 0 (Column width 2.00 in) sal_uInt16 nExpectedColumn0Width - = rOdsDoc.GetColWidth(static_cast<SCCOL>(0), static_cast<SCTAB>(0), false); + = pDoc->GetColWidth(static_cast<SCCOL>(0), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2880), nExpectedColumn0Width); // Col 2, Tab 0 (Column width 1.00 in) sal_uInt16 nExpectedColumn1Width - = rOdsDoc.GetColWidth(static_cast<SCCOL>(1), static_cast<SCTAB>(0), false); + = pDoc->GetColWidth(static_cast<SCCOL>(1), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1440), nExpectedColumn1Width); // Col 3, Tab 0 (Column width 0.50 in) sal_uInt16 nExpectedColumn2Width - = rOdsDoc.GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false); + = pDoc->GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(720), nExpectedColumn2Width); // Col 4, Tab 0 (Column width 0.25 in) sal_uInt16 nExpectedColumn3Width - = rOdsDoc.GetColWidth(static_cast<SCCOL>(3), static_cast<SCTAB>(0), false); + = pDoc->GetColWidth(static_cast<SCCOL>(3), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(360), nExpectedColumn3Width); // Col 5, Tab 0 (Column width 13.57 in) sal_uInt16 nExpectedColumn4Width - = rOdsDoc.GetColWidth(static_cast<SCCOL>(4), static_cast<SCTAB>(0), false); + = pDoc->GetColWidth(static_cast<SCCOL>(4), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(19539), nExpectedColumn4Width); // Export to .xlsx and compare column width with the .ods // We expect that column width from .ods will be exactly the same as imported from .xlsx - ScDocShellRef xXlsxDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xXlsxDocSh.is()); + saveAndReload("Calc Office Open XML"); - ScDocument& rDoc = xXlsxDocSh->GetDocument(); + pDoc = getScDoc(); // Col 1, Tab 0 sal_uInt16 nCalcWidth; - nCalcWidth = rDoc.GetColWidth(static_cast<SCCOL>(0), static_cast<SCTAB>(0), false); + nCalcWidth = pDoc->GetColWidth(static_cast<SCCOL>(0), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(nExpectedColumn0Width, nCalcWidth); // Col 2, Tab 0 - nCalcWidth = rDoc.GetColWidth(static_cast<SCCOL>(1), static_cast<SCTAB>(0), false); + nCalcWidth = pDoc->GetColWidth(static_cast<SCCOL>(1), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(nExpectedColumn1Width, nCalcWidth); // Col 3, Tab 0 - nCalcWidth = rDoc.GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false); + nCalcWidth = pDoc->GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(nExpectedColumn2Width, nCalcWidth); // Col 4, Tab 0 - nCalcWidth = rDoc.GetColWidth(static_cast<SCCOL>(3), static_cast<SCTAB>(0), false); + nCalcWidth = pDoc->GetColWidth(static_cast<SCCOL>(3), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(nExpectedColumn3Width, nCalcWidth); // Col 5, Tab 0 - nCalcWidth = rDoc.GetColWidth(static_cast<SCCOL>(4), static_cast<SCTAB>(0), false); + nCalcWidth = pDoc->GetColWidth(static_cast<SCCOL>(4), static_cast<SCTAB>(0), false); CPPUNIT_ASSERT_EQUAL(nExpectedColumn4Width, nCalcWidth); - - xXlsxDocSh->DoClose(); } #endif @@ -1290,12 +1146,10 @@ void ScExportTest::testOutlineExportXLSX() { //tdf#100347 FILESAVE FILEOPEN after exporting to .xlsx format grouping are lost //tdf#51524 FILESAVE .xlsx and.xls looses width information for hidden/collapsed grouped columns - ScDocShellRef xShell = loadDoc(u"outline.", FORMAT_ODS); + createScDoc("ods/outline.ods"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); // Maximum Outline Row is 4 for this document @@ -1432,34 +1286,26 @@ void ScExportTest::testOutlineExportXLSX() // We expected that exactly 29 Row Nodes will be produced assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row", 29); - - xShell->DoClose(); } void ScExportTest::testAllRowsHiddenXLSX() { - ScDocShellRef xOrigDocSh = loadDoc(u"tdf105840_allRowsHidden.", FORMAT_XLSX); + createScDoc("xlsx/tdf105840_allRowsHidden.xlsx"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xOrigDocSh, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); assertXPath(pSheet, "/x:worksheet/x:sheetFormatPr", "zeroHeight", "true"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row", 0); - - xOrigDocSh->DoClose(); } void ScExportTest::testHiddenEmptyRowsXLSX() { //tdf#98106 FILESAVE: Hidden and empty rows became visible when export to .XLSX - ScDocShellRef xShell = loadDoc(u"hidden-empty-rows.", FORMAT_ODS); + createScDoc("ods/hidden-empty-rows.ods"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); assertXPath(pSheet, "/x:worksheet/x:sheetFormatPr", "zeroHeight", "false"); @@ -1467,60 +1313,48 @@ void ScExportTest::testHiddenEmptyRowsXLSX() assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "hidden", "true"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[3]", "hidden", "true"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "hidden", "false"); - - xShell->DoClose(); } void ScExportTest::testHiddenEmptyColsODS() { //tdf#98106 FILESAVE: Hidden and empty rows became visible when export to .XLSX - ScDocShellRef xShell = loadDoc(u"tdf128895_emptyHiddenCols.", FORMAT_ODS); + createScDoc("ods/tdf128895_emptyHiddenCols.ods"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS); - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "content.xml"); + save("calc8"); + xmlDocUniquePtr pSheet = parseExport("content.xml"); CPPUNIT_ASSERT(pSheet); assertXPath(pSheet, "//table:table/table:table-column[2]"); assertXPath(pSheet, "//table:table/table:table-column[2]", "number-columns-repeated", "1017"); - - xShell->DoClose(); } void ScExportTest::testLandscapeOrientationXLSX() { //tdf#48767 - Landscape page orientation is not loaded from .xlsx format with MS Excel, after export with Libre Office - ScDocShellRef xShell = loadDoc(u"hidden-empty-rows.", FORMAT_ODS); + createScDoc("ods/hidden-empty-rows.ods"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); // the usePrinterDefaults cannot be saved to allow opening sheets in Landscape mode via MS Excel assertXPathNoAttribute(pSheet, "/x:worksheet/x:pageSetup", "usePrinterDefaults"); assertXPath(pSheet, "/x:worksheet/x:pageSetup", "orientation", "landscape"); - - xShell->DoClose(); } void ScExportTest::testDataBarExportXLSX() { - ScDocShellRef xShell = loadDoc(u"databar.", FORMAT_XLSX); + createScDoc("xlsx/databar.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); - testDataBar_Impl(rDoc); - - xDocSh->DoClose(); + testDataBar_Impl(*pDoc); } void ScExportTest::testMiscRowHeightExport() { - static const TestParam::RowData DfltRowData[] = { + static const TestParam2::RowData DfltRowData[] = { { 0, 4, 0, 529, 0, false }, { 5, 10, 0, 1058, 0, false }, { 17, 20, 0, 1746, 0, false }, @@ -1529,7 +1363,7 @@ void ScExportTest::testMiscRowHeightExport() { 1048573, 1048575, 0, 529, 0, false }, }; - static const TestParam::RowData EmptyRepeatRowData[] = { + static const TestParam2::RowData EmptyRepeatRowData[] = { // rows 0-4, 5-10, 17-20 are all set at various // heights, there is no content in the rows, there // was a bug where only the first row ( of repeated rows ) @@ -1539,20 +1373,21 @@ void ScExportTest::testMiscRowHeightExport() { 17, 20, 0, 1767, 0, false }, }; - TestParam aTestValues[] = { + TestParam2 aTestValues[] = { // Checks that some distributed ( non-empty ) heights remain set after export (roundtrip) // additionally there is effectively a default row height ( 5.29 mm ). So we test the // unset rows at the end of the document to ensure the effective xlsx default height // is set there too. - { "miscrowheights.", FORMAT_XLSX, FORMAT_XLSX, SAL_N_ELEMENTS(DfltRowData), DfltRowData }, + { u"xlsx/miscrowheights.xlsx", "Calc Office Open XML", SAL_N_ELEMENTS(DfltRowData), + DfltRowData }, // Checks that some distributed ( non-empty ) heights remain set after export (to xls) - { "miscrowheights.", FORMAT_XLSX, FORMAT_XLS, SAL_N_ELEMENTS(DfltRowData), DfltRowData }, + { u"xlsx/miscrowheights.xlsx", "MS Excel 97", SAL_N_ELEMENTS(DfltRowData), DfltRowData }, // Checks that repreated rows ( of various heights ) remain set after export ( to xlsx ) - { "miscemptyrepeatedrowheights.", FORMAT_ODS, FORMAT_XLSX, + { u"ods/miscemptyrepeatedrowheights.ods", "Calc Office Open XML", SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData }, // Checks that repreated rows ( of various heights ) remain set after export ( to xls ) - { "miscemptyrepeatedrowheights.", FORMAT_ODS, FORMAT_XLS, - SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData }, + { u"ods/miscemptyrepeatedrowheights.ods", "MS Excel 97", SAL_N_ELEMENTS(EmptyRepeatRowData), + EmptyRepeatRowData }, }; miscRowHeightsTest(aTestValues, SAL_N_ELEMENTS(aTestValues)); } @@ -1648,37 +1483,33 @@ void setEscapement(ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sa void ScExportTest::testNamedRangeBugfdo62729() { - ScDocShellRef xShell = loadDoc(u"fdo62729.", FORMAT_ODS); - ScDocument& rDoc = xShell->GetDocument(); +#if !defined(MACOSX) // FIXME: infinite loop on jenkins' mac + createScDoc("ods/fdo62729.ods"); + ScDocument* pDoc = getScDoc(); - ScRangeName* pNames = rDoc.GetRangeName(); + ScRangeName* pNames = pDoc->GetRangeName(); //should be just a single named range CPPUNIT_ASSERT_EQUAL(size_t(1), pNames->size()); - rDoc.DeleteTab(0); + pDoc->DeleteTab(0); //should be still a single named range CPPUNIT_ASSERT_EQUAL(size_t(1), pNames->size()); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_ODS); - xShell->DoClose(); + saveAndReload("calc8"); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc2 = xDocSh->GetDocument(); + pDoc = getScDoc(); - pNames = rDoc2.GetRangeName(); + pNames = pDoc->GetRangeName(); //after reload should still have a named range CPPUNIT_ASSERT_EQUAL(size_t(1), pNames->size()); - - xDocSh->DoClose(); +#endif } void ScExportTest::testBuiltinRangesXLSX() { - ScDocShellRef xShell = loadDoc(u"built-in_ranges.", FORMAT_XLSX); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - xShell->DoClose(); + createScDoc("xlsx/built-in_ranges.xlsx"); + saveAndReload("Calc Office Open XML"); - xmlDocUniquePtr pDoc - = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/workbook.xml"); CPPUNIT_ASSERT(pDoc); //assert the existing OOXML built-in names are still there @@ -1716,8 +1547,6 @@ void ScExportTest::testBuiltinRangesXLSX() pDoc, "/x:workbook/x:definedNames/x:definedName[@name='_xlnm.Print_Area_0'][@localSheetId='1']", 0); - - xDocSh->DoClose(); } void ScExportTest::testRichTextExportODS() @@ -2062,16 +1891,15 @@ void ScExportTest::testRichTextExportODS() // Start with an empty document, put one edit text cell, and make sure it // survives the save and reload. - ScDocShellRef xOrigDocSh = loadEmptyDocument(); - CPPUNIT_ASSERT(xOrigDocSh); + createScDoc(); const EditTextObject* pEditText; { - ScDocument& rDoc = xOrigDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.", - rDoc.GetTableCount() > 0); + pDoc->GetTableCount() > 0); // Insert an edit text cell. - ScFieldEditEngine* pEE = &rDoc.GetEditEngine(); + ScFieldEditEngine* pEE = &pDoc->GetEditEngine(); pEE->SetTextCurrentDefaults("Bold and Italic"); // Set the 'Bold' part bold. setAttribute(*pEE, 0, 0, 4, EE_CHAR_WEIGHT); @@ -2081,20 +1909,19 @@ void ScExportTest::testRichTextExportODS() aSel.nStartPara = aSel.nEndPara = 0; // Set this edit text to cell B2. - rDoc.SetEditText(ScAddress(1, 1, 0), pEE->CreateTextObject()); - pEditText = rDoc.GetEditText(ScAddress(1, 1, 0)); + pDoc->SetEditText(ScAddress(1, 1, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 1, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B2 value.", aCheckFunc.checkB2(pEditText)); } // Now, save and reload this document. - ScDocShellRef xNewDocSh = saveAndReload(*xOrigDocSh, FORMAT_ODS); + saveAndReload("calc8"); { - xOrigDocSh->DoClose(); - CPPUNIT_ASSERT(xNewDocSh.is()); - ScDocument& rDoc2 = xNewDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.", - rDoc2.GetTableCount() > 0); - ScFieldEditEngine* pEE = &rDoc2.GetEditEngine(); + pDoc->GetTableCount() > 0); + ScFieldEditEngine* pEE = &pDoc->GetEditEngine(); + pEditText = pDoc->GetEditText(ScAddress(1, 1, 0)); // Make sure the content of B2 is still intact. CPPUNIT_ASSERT_MESSAGE("Incorrect B2 value.", aCheckFunc.checkB2(pEditText)); @@ -2102,28 +1929,27 @@ void ScExportTest::testRichTextExportODS() // Insert a multi-line content to B4. pEE->Clear(); pEE->SetTextCurrentDefaults("One\nTwo\nThree"); - rDoc2.SetEditText(ScAddress(1, 3, 0), pEE->CreateTextObject()); - pEditText = rDoc2.GetEditText(ScAddress(1, 3, 0)); + pDoc->SetEditText(ScAddress(1, 3, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 3, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B4 value.", aCheckFunc.checkB4(pEditText)); } // Reload the doc again, and check the content of B2 and B4. - ScDocShellRef xNewDocSh2 = saveAndReload(*xNewDocSh, FORMAT_ODS); + saveAndReload("calc8"); { - ScDocument& rDoc3 = xNewDocSh2->GetDocument(); - ScFieldEditEngine* pEE = &rDoc3.GetEditEngine(); - xNewDocSh->DoClose(); + ScDocument* pDoc = getScDoc(); + ScFieldEditEngine* pEE = &pDoc->GetEditEngine(); - pEditText = rDoc3.GetEditText(ScAddress(1, 1, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 1, 0)); CPPUNIT_ASSERT_MESSAGE("B2 should be an edit text.", pEditText); - pEditText = rDoc3.GetEditText(ScAddress(1, 3, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 3, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B4 value.", aCheckFunc.checkB4(pEditText)); // Insert a multi-line content to B5, but this time, set some empty paragraphs. pEE->Clear(); pEE->SetTextCurrentDefaults("\nTwo\nThree\n\nFive\n"); - rDoc3.SetEditText(ScAddress(1, 4, 0), pEE->CreateTextObject()); - pEditText = rDoc3.GetEditText(ScAddress(1, 4, 0)); + pDoc->SetEditText(ScAddress(1, 4, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 4, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B5 value.", aCheckFunc.checkB5(pEditText)); // Insert a text with strikethrough in B6. @@ -2131,8 +1957,8 @@ void ScExportTest::testRichTextExportODS() pEE->SetTextCurrentDefaults("Strike Me"); // Set the 'Strike' part strikethrough. setAttribute(*pEE, 0, 0, 6, EE_CHAR_STRIKEOUT); - rDoc3.SetEditText(ScAddress(1, 5, 0), pEE->CreateTextObject()); - pEditText = rDoc3.GetEditText(ScAddress(1, 5, 0)); + pDoc->SetEditText(ScAddress(1, 5, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 5, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B6 value.", aCheckFunc.checkB6(pEditText)); // Insert a text with different font segments in B7. @@ -2140,8 +1966,8 @@ void ScExportTest::testRichTextExportODS() pEE->SetTextCurrentDefaults("Font1 and Font2"); setFont(*pEE, 0, 0, 5, "Courier"); setFont(*pEE, 0, 10, 15, "Luxi Mono"); - rDoc3.SetEditText(ScAddress(1, 6, 0), pEE->CreateTextObject()); - pEditText = rDoc3.GetEditText(ScAddress(1, 6, 0)); + pDoc->SetEditText(ScAddress(1, 6, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 6, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B7 value.", aCheckFunc.checkB7(pEditText)); // Insert a text with overline and underline in B8. @@ -2149,76 +1975,71 @@ void ScExportTest::testRichTextExportODS() pEE->SetTextCurrentDefaults("Over and Under"); setAttribute(*pEE, 0, 0, 4, EE_CHAR_OVERLINE); setAttribute(*pEE, 0, 9, 14, EE_CHAR_UNDERLINE); - rDoc3.SetEditText(ScAddress(1, 7, 0), pEE->CreateTextObject()); - pEditText = rDoc3.GetEditText(ScAddress(1, 7, 0)); + pDoc->SetEditText(ScAddress(1, 7, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 7, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B8 value.", aCheckFunc.checkB8(pEditText)); pEE->Clear(); pEE->SetTextCurrentDefaults("Sub and Super"); setEscapement(*pEE, 0, 0, 3, 32, 64); setEscapement(*pEE, 0, 8, 13, -32, 66); - rDoc3.SetEditText(ScAddress(1, 8, 0), pEE->CreateTextObject()); - pEditText = rDoc3.GetEditText(ScAddress(1, 8, 0)); + pDoc->SetEditText(ScAddress(1, 8, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 8, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B9 value.", aCheckFunc.checkB9(pEditText)); - ScPatternAttr aCellFontColor(rDoc3.GetPool()); + ScPatternAttr aCellFontColor(pDoc->GetPool()); aCellFontColor.GetItemSet().Put(SvxColorItem(COL_BLUE, ATTR_FONT_COLOR)); // Set font color of B10 to blue. - rDoc3.ApplyPattern(1, 9, 0, aCellFontColor); + pDoc->ApplyPattern(1, 9, 0, aCellFontColor); pEE->Clear(); pEE->SetTextCurrentDefaults("BLUE AUTO"); // Set the color of the string "AUTO" to automatic color. setAttribute(*pEE, 0, 5, 9, EE_CHAR_COLOR, COL_AUTO); - rDoc3.SetEditText(ScAddress(1, 9, 0), pEE->CreateTextObject()); - pEditText = rDoc3.GetEditText(ScAddress(1, 9, 0)); + pDoc->SetEditText(ScAddress(1, 9, 0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(1, 9, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B10 value.", aCheckFunc.checkB10(pEditText)); } // Reload the doc again, and check the content of B2, B4, B6 and B7. - ScDocShellRef xNewDocSh3 = saveAndReload(*xNewDocSh2, FORMAT_ODS); - ScDocument& rDoc4 = xNewDocSh3->GetDocument(); - xNewDocSh2->DoClose(); + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); - pEditText = rDoc4.GetEditText(ScAddress(1, 1, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 1, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B2 value after save and reload.", aCheckFunc.checkB2(pEditText)); - pEditText = rDoc4.GetEditText(ScAddress(1, 3, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 3, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B4 value after save and reload.", aCheckFunc.checkB4(pEditText)); - pEditText = rDoc4.GetEditText(ScAddress(1, 4, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 4, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B5 value after save and reload.", aCheckFunc.checkB5(pEditText)); - pEditText = rDoc4.GetEditText(ScAddress(1, 5, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 5, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B6 value after save and reload.", aCheckFunc.checkB6(pEditText)); - pEditText = rDoc4.GetEditText(ScAddress(1, 6, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 6, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B7 value after save and reload.", aCheckFunc.checkB7(pEditText)); - pEditText = rDoc4.GetEditText(ScAddress(1, 7, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 7, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B8 value after save and reload.", aCheckFunc.checkB8(pEditText)); - pEditText = rDoc4.GetEditText(ScAddress(1, 9, 0)); + pEditText = pDoc->GetEditText(ScAddress(1, 9, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B10 value after save and reload.", aCheckFunc.checkB10(pEditText)); - - xNewDocSh3->DoClose(); } void ScExportTest::testRichTextCellFormatXLSX() { - ScDocShellRef xDocSh = loadDoc(u"cellformat.", FORMAT_XLS); + createScDoc("xls/cellformat.xls"); - std::shared_ptr<utl::TempFileNamed> pXPathFile - = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); - xmlDocUniquePtr pSheet - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + save("Calc Office Open XML"); + xmlDocUniquePtr pSheet = parseExport("xl/worksheets/sheet1.xml"); CPPUNIT_ASSERT(pSheet); // make sure the only cell in this doc is assigned some formatting record OUString aCellFormat = getXPath(pSheet, "/x:worksheet/x:sheetData/x:row/x:c", "s"); CPPUNIT_ASSERT_MESSAGE("Cell format is missing", !aCellFormat.isEmpty()); - xmlDocUniquePtr pStyles = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/styles.xml"); + xmlDocUniquePtr pStyles = parseExport("xl/styles.xml"); CPPUNIT_ASSERT(pStyles); OString nFormatIdx = OString::number(aCellFormat.toInt32() + 1); @@ -2234,181 +2055,163 @@ void ScExportTest::testRichTextCellFormatXLSX() // that font should be bold const OString aXPath3("/x:styleSheet/x:fonts/x:font[" + nFontIdx + "]/x:b"); assertXPath(pStyles, aXPath3, "val", "true"); - - xDocSh->DoClose(); } void ScExportTest::testFormulaRefSheetNameODS() { - ScDocShellRef xDocSh = loadDoc(u"formula-quote-in-sheet-name.", FORMAT_ODS, true); + createScDoc("ods/formula-quote-in-sheet-name.ods"); { - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); - sc::AutoCalcSwitch aACSwitch(rDoc, true); // turn on auto calc. - rDoc.SetString(ScAddress(1, 1, 0), "='90''s Data'.B2"); - CPPUNIT_ASSERT_EQUAL(1.1, rDoc.GetValue(ScAddress(1, 1, 0))); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(1, 1, 0), "'90''s Data'.B2", "Wrong formula"); + sc::AutoCalcSwitch aACSwitch(*pDoc, true); // turn on auto calc. + pDoc->SetString(ScAddress(1, 1, 0), "='90''s Data'.B2"); + CPPUNIT_ASSERT_EQUAL(1.1, pDoc->GetValue(ScAddress(1, 1, 0))); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(1, 1, 0), "'90''s Data'.B2", "Wrong formula"); } // Now, save and reload this document. - ScDocShellRef xNewDocSh = saveAndReload(*xDocSh, FORMAT_ODS); - xDocSh->DoClose(); - - ScDocument& rDoc = xNewDocSh->GetDocument(); - rDoc.CalcAll(); - CPPUNIT_ASSERT_EQUAL(1.1, rDoc.GetValue(ScAddress(1, 1, 0))); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(1, 1, 0), "'90''s Data'.B2", "Wrong formula"); + saveAndReload("calc8"); - xNewDocSh->DoClose(); + ScDocument* pDoc = getScDoc(); + pDoc->CalcAll(); + CPPUNIT_ASSERT_EQUAL(1.1, pDoc->GetValue(ScAddress(1, 1, 0))); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(1, 1, 0), "'90''s Data'.B2", "Wrong formula"); } void ScExportTest::testCellValuesExportODS() { // Start with an empty document - ScDocShellRef xOrigDocSh = loadEmptyDocument(); - CPPUNIT_ASSERT(xOrigDocSh); + createScDoc(); { - ScDocument& rDoc = xOrigDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.", - rDoc.GetTableCount() > 0); + pDoc->GetTableCount() > 0); // set a value double - rDoc.SetValue(ScAddress(0, 0, 0), 2.0); // A1 + pDoc->SetValue(ScAddress(0, 0, 0), 2.0); // A1 // set a formula - rDoc.SetValue(ScAddress(2, 0, 0), 3.0); // C1 - rDoc.SetValue(ScAddress(3, 0, 0), 3); // D1 - rDoc.SetString(ScAddress(4, 0, 0), "=10*C1/4"); // E1 - rDoc.SetValue(ScAddress(5, 0, 0), 3.0); // F1 - rDoc.SetString(ScAddress(7, 0, 0), "=SUM(C1:F1)"); //H1 + pDoc->SetValue(ScAddress(2, 0, 0), 3.0); // C1 + pDoc->SetValue(ScAddress(3, 0, 0), 3); // D1 + pDoc->SetString(ScAddress(4, 0, 0), "=10*C1/4"); // E1 + pDoc->SetValue(ScAddress(5, 0, 0), 3.0); // F1 + pDoc->SetString(ScAddress(7, 0, 0), "=SUM(C1:F1)"); //H1 // set a string - rDoc.SetString(ScAddress(0, 2, 0), "a simple line"); //A3 + pDoc->SetString(ScAddress(0, 2, 0), "a simple line"); //A3 // set a digit string - rDoc.SetString(ScAddress(0, 4, 0), "'12"); //A5 + pDoc->SetString(ScAddress(0, 4, 0), "'12"); //A5 // set a contiguous value - rDoc.SetValue(ScAddress(0, 5, 0), 12.0); //A6 + pDoc->SetValue(ScAddress(0, 5, 0), 12.0); //A6 // set a contiguous string - rDoc.SetString(ScAddress(0, 6, 0), "a string"); //A7 + pDoc->SetString(ScAddress(0, 6, 0), "a string"); //A7 // set a contiguous formula - rDoc.SetString(ScAddress(0, 7, 0), "=$A$6"); //A8 + pDoc->SetString(ScAddress(0, 7, 0), "=$A$6"); //A8 } // save and reload - ScDocShellRef xNewDocSh = saveAndReload(*xOrigDocSh, FORMAT_ODS); - xOrigDocSh->DoClose(); - CPPUNIT_ASSERT(xNewDocSh.is()); - ScDocument& rDoc = xNewDocSh->GetDocument(); + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.", - rDoc.GetTableCount() > 0); + pDoc->GetTableCount() > 0); // check value - CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(0, 0, 0)); - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(2, 0, 0)); - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(3, 0, 0)); - CPPUNIT_ASSERT_EQUAL(7.5, rDoc.GetValue(4, 0, 0)); - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(5, 0, 0)); + CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(0, 0, 0)); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(2, 0, 0)); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(3, 0, 0)); + CPPUNIT_ASSERT_EQUAL(7.5, pDoc->GetValue(4, 0, 0)); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(5, 0, 0)); // check formula - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(4, 0, 0), "10*C1/4", "Wrong formula =10*C1/4"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(7, 0, 0), "SUM(C1:F1)", "Wrong formula =SUM(C1:F1)"); - CPPUNIT_ASSERT_EQUAL(16.5, rDoc.GetValue(7, 0, 0)); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(4, 0, 0), "10*C1/4", "Wrong formula =10*C1/4"); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(7, 0, 0), "SUM(C1:F1)", "Wrong formula =SUM(C1:F1)"); + CPPUNIT_ASSERT_EQUAL(16.5, pDoc->GetValue(7, 0, 0)); // check string ScRefCellValue aCell; - aCell.assign(rDoc, ScAddress(0, 2, 0)); + aCell.assign(*pDoc, ScAddress(0, 2, 0)); CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, aCell.getType()); // check for an empty cell - aCell.assign(rDoc, ScAddress(0, 3, 0)); + aCell.assign(*pDoc, ScAddress(0, 3, 0)); CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, aCell.getType()); // check a digit string - aCell.assign(rDoc, ScAddress(0, 4, 0)); + aCell.assign(*pDoc, ScAddress(0, 4, 0)); CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, aCell.getType()); //check contiguous values - CPPUNIT_ASSERT_EQUAL(12.0, rDoc.GetValue(0, 5, 0)); - CPPUNIT_ASSERT_EQUAL(OUString("a string"), rDoc.GetString(0, 6, 0)); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 7, 0), "$A$6", "Wrong formula =$A$6"); - CPPUNIT_ASSERT_EQUAL(rDoc.GetValue(0, 5, 0), rDoc.GetValue(0, 7, 0)); - - xNewDocSh->DoClose(); + CPPUNIT_ASSERT_EQUAL(12.0, pDoc->GetValue(0, 5, 0)); + CPPUNIT_ASSERT_EQUAL(OUString("a string"), pDoc->GetString(0, 6, 0)); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(0, 7, 0), "$A$6", "Wrong formula =$A$6"); + CPPUNIT_ASSERT_EQUAL(pDoc->GetValue(0, 5, 0), pDoc->GetValue(0, 7, 0)); } void ScExportTest::testCellNoteExportODS() { - ScDocShellRef xOrigDocSh = loadDoc(u"single-note.", FORMAT_ODS); + createScDoc("ods/single-note.ods"); ScAddress aPos(0, 0, 0); // Start with A1. { - ScDocument& rDoc = xOrigDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); - CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", rDoc.HasNote(aPos)); + CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", pDoc->HasNote(aPos)); aPos.IncRow(); // Move to A2. - ScPostIt* pNote = rDoc.GetOrCreateNote(aPos); + ScPostIt* pNote = pDoc->GetOrCreateNote(aPos); pNote->SetText(aPos, "Note One"); pNote->SetAuthor("Author One"); - CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", rDoc.HasNote(aPos)); + CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", pDoc->HasNote(aPos)); } // save and reload - ScDocShellRef xNewDocSh = saveAndReload(*xOrigDocSh, FORMAT_ODS); - xOrigDocSh->DoClose(); - CPPUNIT_ASSERT(xNewDocSh.is()); - ScDocument& rDoc = xNewDocSh->GetDocument(); + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); aPos.SetRow(0); // Move back to A1. - CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", rDoc.HasNote(aPos)); + CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", pDoc->HasNote(aPos)); aPos.IncRow(); // Move to A2. - CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", rDoc.HasNote(aPos)); - - xNewDocSh->DoClose(); + CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", pDoc->HasNote(aPos)); } void ScExportTest::testCellNoteExportXLS() { // Start with an empty document.s - ScDocShellRef xOrigDocSh = loadDoc(u"notes-on-3-sheets.", FORMAT_ODS); + createScDoc("ods/notes-on-3-sheets.ods"); { - ScDocument& rDoc = xOrigDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL_MESSAGE("This document should have 3 sheets.", SCTAB(3), - rDoc.GetTableCount()); + pDoc->GetTableCount()); // Check note's presence. - CPPUNIT_ASSERT(rDoc.HasNote(ScAddress(0, 0, 0))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 1, 0))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 2, 0))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 0, 1))); - CPPUNIT_ASSERT(rDoc.HasNote(ScAddress(0, 1, 1))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 2, 1))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 0, 1))); + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(0, 1, 1))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 2, 1))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 0, 2))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 1, 2))); - CPPUNIT_ASSERT(rDoc.HasNote(ScAddress(0, 2, 2))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 0, 2))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 1, 2))); + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(0, 2, 2))); } // save and reload as XLS. - ScDocShellRef xNewDocSh = saveAndReload(*xOrigDocSh, FORMAT_XLS); + saveAndReload("MS Excel 97"); { - xOrigDocSh->DoClose(); - CPPUNIT_ASSERT(xNewDocSh.is()); - ScDocument& rDoc = xNewDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL_MESSAGE("This document should have 3 sheets.", SCTAB(3), - rDoc.GetTableCount()); + pDoc->GetTableCount()); // Check note's presence again. - CPPUNIT_ASSERT(rDoc.HasNote(ScAddress(0, 0, 0))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 1, 0))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 2, 0))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 0, 1))); - CPPUNIT_ASSERT(rDoc.HasNote(ScAddress(0, 1, 1))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 2, 1))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 0, 1))); + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(0, 1, 1))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 2, 1))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 0, 2))); - CPPUNIT_ASSERT(!rDoc.HasNote(ScAddress(0, 1, 2))); - CPPUNIT_ASSERT(rDoc.HasNote(ScAddress(0, 2, 2))); - - xNewDocSh->DoClose(); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 0, 2))); + CPPUNIT_ASSERT(!pDoc->HasNote(ScAddress(0, 1, 2))); + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(0, 2, 2))); } } @@ -2439,83 +2242,71 @@ void checkMatrixRange(ScDocument& rDoc, const ScRange& rRange) void ScExportTest::testInlineArrayXLS() { - ScDocShellRef xShell = loadDoc(u"inline-array.", FORMAT_XLS); + createScDoc("xls/inline-array.xls"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLS); - xShell->DoClose(); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("MS Excel 97"); - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); // B2:C3 contains a matrix. - checkMatrixRange(rDoc, ScRange(1, 1, 0, 2, 2, 0)); + checkMatrixRange(*pDoc, ScRange(1, 1, 0, 2, 2, 0)); // B5:D6 contains a matrix. - checkMatrixRange(rDoc, ScRange(1, 4, 0, 3, 5, 0)); + checkMatrixRange(*pDoc, ScRange(1, 4, 0, 3, 5, 0)); // B8:C10 as well. - checkMatrixRange(rDoc, ScRange(1, 7, 0, 2, 9, 0)); - - xDocSh->DoClose(); + checkMatrixRange(*pDoc, ScRange(1, 7, 0, 2, 9, 0)); } void ScExportTest::testEmbeddedChartODS() { - ScDocShellRef xShell = loadDoc(u"embedded-chart.", FORMAT_XLS); + createScDoc("xls/embedded-chart.xls"); - std::shared_ptr<utl::TempFileNamed> pTempFile( - ScBootstrapFixture::exportTo(*xShell, FORMAT_ODS)); + save("calc8"); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pTempFile, m_xSFactory, "content.xml"); + xmlDocUniquePtr pDoc = parseExport("content.xml"); CPPUNIT_ASSERT(pDoc); assertXPath(pDoc, "/office:document-content/office:body/office:spreadsheet/table:table[2]/" "table:table-row[7]/table:table-cell[2]/draw:frame/draw:object", "notify-on-update-of-ranges", "Chart1.B3:Chart1.B5 Chart1.C2:Chart1.C2 Chart1.C3:Chart1.C5"); - - xShell->DoClose(); } void ScExportTest::testEmbeddedChartXLS() { - ScDocShellRef xShell = loadDoc(u"embedded-chart.", FORMAT_XLS); + createScDoc("xls/embedded-chart.xls"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLS); - xShell->DoClose(); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("MS Excel 97"); - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); // Make sure the 2nd sheet is named 'Chart1'. OUString aName; - rDoc.GetName(1, aName); + pDoc->GetName(1, aName); CPPUNIT_ASSERT_EQUAL(OUString("Chart1"), aName); - const SdrOle2Obj* pOleObj = getSingleChartObject(rDoc, 1); + const SdrOle2Obj* pOleObj = getSingleChartObject(*pDoc, 1); CPPUNIT_ASSERT_MESSAGE("Failed to retrieve a chart object from the 2nd sheet.", pOleObj); - ScRangeList aRanges = getChartRanges(rDoc, *pOleObj); + ScRangeList aRanges = getChartRanges(*pDoc, *pOleObj); CPPUNIT_ASSERT_MESSAGE("Label range (B3:B5) not found.", aRanges.Contains(ScRange(1, 2, 1, 1, 4, 1))); CPPUNIT_ASSERT_MESSAGE("Data label (C2) not found.", aRanges.Contains(ScAddress(2, 1, 1))); CPPUNIT_ASSERT_MESSAGE("Data range (C3:C5) not found.", aRanges.Contains(ScRange(2, 2, 1, 2, 4, 1))); - - xDocSh->DoClose(); } void ScExportTest::testCellAnchoredGroupXLS() { - ScDocShellRef xDocSh_in = loadDoc(u"cell-anchored-group.", FORMAT_XLS); + createScDoc("xls/cell-anchored-group.xls"); - ScDocShellRef xDocSh = saveAndReload(*xDocSh_in, FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to save and reload cell-anchored-group.ods", xDocSh.is()); + saveAndReload("calc8"); // the document contains a group anchored on the first cell, make sure it's there in the right place - ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", rDoc.GetTableCount() > 0); - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + ScDocument* pDoc = getScDoc(); + CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); SdrPage* pPage = pDrawLayer->GetPage(0); CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); const size_t nCount = pPage->GetObjCount(); @@ -2527,42 +2318,36 @@ void ScExportTest::testCellAnchoredGroupXLS() CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData); CPPUNIT_ASSERT_MESSAGE("Upper left of bounding rectangle should be nonnegative.", pData->getShapeRect().Left() >= 0 || pData->getShapeRect().Top() >= 0); - xDocSh->DoClose(); } void ScExportTest::testFormulaReferenceXLS() { - ScDocShellRef xShell = loadDoc(u"formula-reference.", FORMAT_XLS); + createScDoc("xls/formula-reference.xls"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLS); - xShell->DoClose(); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("MS Excel 97"); - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 1, 0), "$A$2+$B$2+$C$2", "Wrong formula in D2"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 2, 0), "A3+B3+C3", "Wrong formula in D3"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 5, 0), "SUM($A$6:$C$6)", "Wrong formula in D6"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 6, 0), "SUM(A7:C7)", "Wrong formula in D7"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 9, 0), "$Two.$A$2+$Two.$B$2+$Two.$C$2", + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 1, 0), "$A$2+$B$2+$C$2", "Wrong formula in D2"); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 2, 0), "A3+B3+C3", "Wrong formula in D3"); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 5, 0), "SUM($A$6:$C$6)", "Wrong formula in D6"); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 6, 0), "SUM(A7:C7)", "Wrong formula in D7"); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 9, 0), "$Two.$A$2+$Two.$B$2+$Two.$C$2", "Wrong formula in D10"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 10, 0), "$Two.A3+$Two.B3+$Two.C3", + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 10, 0), "$Two.A3+$Two.B3+$Two.C3", "Wrong formula in D11"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 13, 0), "MIN($Two.$A$2:$C$2)", "Wrong formula in D14"); - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(3, 14, 0), "MAX($Two.A3:C3)", "Wrong formula in D15"); - - xDocSh->DoClose(); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 13, 0), "MIN($Two.$A$2:$C$2)", "Wrong formula in D14"); + ASSERT_FORMULA_EQUAL(*pDoc, ScAddress(3, 14, 0), "MAX($Two.A3:C3)", "Wrong formula in D15"); } void ScExportTest::testSheetProtectionXLSX() { - ScDocShellRef xShell = loadDoc(u"ProtecteSheet1234Pass.", FORMAT_XLSX); + createScDoc("xlsx/ProtecteSheet1234Pass.xlsx"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - ScDocument& rDoc = xDocSh->GetDocument(); - const ScTableProtection* pTabProtect = rDoc.GetTabProtection(0); + ScDocument* pDoc = getScDoc(); + const ScTableProtection* pTabProtect = pDoc->GetTabProtection(0); CPPUNIT_ASSERT(pTabProtect); Sequence<sal_Int8> aHash = pTabProtect->getPasswordHash(PASSHASH_XL); // check has @@ -2574,22 +2359,19 @@ void ScExportTest::testSheetProtectionXLSX() // we could flesh out this check I guess CPPUNIT_ASSERT(!pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)); CPPUNIT_ASSERT(!pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)); - xDocSh->DoClose(); } void ScExportTest::testSheetProtectionXLSB() { - ScDocShellRef xShell = loadDoc(u"tdf108017_calcProtection.", FORMAT_XLSB); + createScDoc("xlsb/tdf108017_calcProtection.xlsb"); - ScDocShellRef xDocSh = saveAndReload(*xShell, FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); + saveAndReload("Calc Office Open XML"); - ScDocument& rDoc = xDocSh->GetDocument(); - const ScTableProtection* pTabProtect = rDoc.GetTabProtection(0); + ScDocument* pDoc = getScDoc(); + const ScTableProtection* pTabProtect = pDoc->GetTabProtection(0); CPPUNIT_ASSERT(pTabProtect); CPPUNIT_ASSERT(pTabProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS)); CPPUNIT_ASSERT(!pTabProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS)); - xDocSh->DoClose(); } namespace @@ -2619,7 +2401,7 @@ const char* toBorderName(SvxBorderLineStyle eStyle) } } -void ScExportTest::testExcelCellBorders(sal_uLong nFormatType) +void ScExportTest::testExcelCellBorders(const OUString& sFormatType) { static const struct { @@ -2641,14 +2423,13 @@ void ScExportTest::testExcelCellBorders(sal_uLong nFormatType) { 25, SvxBorderLineStyle::DOUBLE_THIN, -1 }, // double (don't check width) }; - ScDocShellRef xDocSh = loadDoc(u"cell-borders.", nFormatType); { - ScDocument& rDoc = xDocSh->GetDocument(); + ScDocument* pDoc = getScDoc(); for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i) { const editeng::SvxBorderLine* pLine = nullptr; - rDoc.GetBorderLines(2, aChecks[i].mnRow, 0, nullptr, &pLine, nullptr, nullptr); + pDoc->GetBorderLines(2, aChecks[i].mnRow, 0, nullptr, &pLine, nullptr, nullptr); CPPUNIT_ASSERT(pLine); CPPUNIT_ASSERT_EQUAL(toBorderName(aChecks[i].mnStyle), toBorderName(pLine->GetBorderLineStyle())); @@ -2657,26 +2438,31 @@ void ScExportTest::testExcelCellBorders(sal_uLong nFormatType) } } - ScDocShellRef xNewDocSh = saveAndReload(*xDocSh, nFormatType); - xDocSh->DoClose(); - ScDocument& rDoc = xNewDocSh->GetDocument(); + saveAndReload(sFormatType); + ScDocument* pDoc = getScDoc(); for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i) { const editeng::SvxBorderLine* pLine = nullptr; - rDoc.GetBorderLines(2, aChecks[i].mnRow, 0, nullptr, &pLine, nullptr, nullptr); ... etc. - the rest is truncated
