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 <xiscofauli@libreoffice.org>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli 2022-11-10 14:18:12 +01:00
parent 6870c0c338
commit a865d042ef
11 changed files with 896 additions and 1081 deletions

View file

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

View file

@ -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, \

View file

@ -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, \

View file

@ -51,6 +51,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_parallelism, \
sb \
sfx \
sot \
subsequenttest \
svl \
svt \
svx \

View file

@ -50,6 +50,7 @@ $(eval $(call gb_Library_use_libraries,scqahelper,\
sc \
sfx \
sot \
subsequenttest \
svl \
svt \
svx \

View file

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

View file

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

File diff suppressed because it is too large Load diff

View file

@ -43,6 +43,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_$(1), \
scqahelper \
sfx \
sot \
subsequenttest \
svl \
svt \
svx \
@ -72,56 +73,7 @@ $(eval $(call gb_CppunitTest_use_api,sc_subsequent_$(1),\
$(eval $(call gb_CppunitTest_use_ure,sc_subsequent_$(1)))
$(eval $(call gb_CppunitTest_use_vcl,sc_subsequent_$(1)))
$(eval $(call gb_CppunitTest_use_components,sc_subsequent_$(1),\
basic/util/sb \
basctl/util/basctl \
chart2/source/chartcore \
chart2/source/controller/chartcontroller \
comphelper/util/comphelp \
configmgr/source/configmgr \
dbaccess/util/dba \
embeddedobj/util/embobj \
eventattacher/source/evtatt \
filter/source/config/cache/filterconfig1 \
filter/source/odfflatxml/odfflatxml \
filter/source/xmlfilteradaptor/xmlfa \
forms/util/frm \
framework/util/fwk \
i18npool/source/search/i18nsearch \
i18npool/util/i18npool \
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
sax/source/expatwrap/expwrap \
scaddins/source/analysis/analysis \
scaddins/source/datefunc/date \
sc/util/sc \
sc/util/scfilt \
sc/util/vbaobj \
sfx2/util/sfx \
sot/util/sot \
svl/util/svl \
svl/source/fsstor/fsstorage \
svtools/util/svt \
svx/util/svxcore \
toolkit/util/tk \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
ucb/source/ucp/tdoc/ucptdoc1 \
unotools/util/utl \
unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
uui/util/uui \
vcl/vcl.common \
xmloff/util/xo \
xmlsecurity/util/xmlsecurity \
emfio/emfio \
))
$(eval $(call gb_CppunitTest_use_components,sc_subsequent_$(1),\
xmlsecurity/util/xsec_xmlsec \
))
$(eval $(call gb_CppunitTest_use_rdb,sc_subsequent_$(1),services))
$(eval $(call gb_CppunitTest_use_custom_headers,sc_subsequent_$(1),\
officecfg/registry \

View file

@ -60,6 +60,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_ucalc$(1), \
sb \
sfx \
sot \
subsequenttest \
svl \
svt \
svx \

View file

@ -57,6 +57,11 @@ OUString UnoApiTest::createFileURL(std::u16string_view aFileBase)
return m_directories.getSrcRootURL() + m_aBaseString + "/" + aFileBase;
}
OUString UnoApiTest::createFilePath(std::u16string_view aFileBase)
{
return m_directories.getSrcRootPath() + "/" + m_aBaseString + "/" + aFileBase;
}
void UnoApiTest::setTestInteractionHandler(const char* pPassword,
std::vector<beans::PropertyValue>& rFilterOptions)
{