summaryrefslogtreecommitdiff
path: root/sc/qa/unit/helper
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2022-11-10 14:18:12 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2022-11-15 11:56:34 +0100
commita865d042eff3cdd4d78badcc55c9d8fdf9ef52aa (patch)
tree038f020d2c3bd05537a9d08fa7f2c2400d14b03b /sc/qa/unit/helper
parent6870c0c3385bf5d19e9c80bf973fca255ae38c08 (diff)
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>
Diffstat (limited to 'sc/qa/unit/helper')
-rw-r--r--sc/qa/unit/helper/qahelper.cxx190
-rw-r--r--sc/qa/unit/helper/qahelper.hxx36
2 files changed, 212 insertions, 14 deletions
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);