summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2021-05-12 22:16:34 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-05-14 12:44:03 +0200
commit1f23231c56cf33deacab3083f1ed771f10f91b00 (patch)
tree6938479fea4e2ed5024b34903c2c9674b6c68aa0 /sc/qa/unit
parent5449a798d1e676ce8bef876270226eaea602f258 (diff)
sc_ucalc: move sort tests to their own module
in order to split sc_ucalc monster into smaller modules Change-Id: Ib041d1fbce51230dcc46320939257771eac0faea Change-Id: Iae19af01de63346b2bf951ed935fccbd6bfb9d15 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115558 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/helper/qahelper.cxx92
-rw-r--r--sc/qa/unit/helper/qahelper.hxx19
-rw-r--r--sc/qa/unit/ucalc.cxx93
-rw-r--r--sc/qa/unit/ucalc.hxx59
-rw-r--r--sc/qa/unit/ucalc_formula.cxx20
-rw-r--r--sc/qa/unit/ucalc_pivottable.cxx2
-rw-r--r--sc/qa/unit/ucalc_sort.cxx174
7 files changed, 256 insertions, 203 deletions
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 3774f6b5a27c..6802e27c960b 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -36,6 +36,7 @@
#include <sfx2/frame.hxx>
#include <unotools/tempfile.hxx>
#include <scitems.hxx>
+#include <stringutil.hxx>
#include <tokenarray.hxx>
#include <orcus/csv_parser.hpp>
@@ -50,6 +51,17 @@
using namespace com::sun::star;
using namespace ::com::sun::star::uno;
+FormulaGrammarSwitch::FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar) :
+ mpDoc(pDoc), meOldGrammar(pDoc->GetGrammar())
+{
+ mpDoc->SetGrammar(eGrammar);
+}
+
+FormulaGrammarSwitch::~FormulaGrammarSwitch()
+{
+ mpDoc->SetGrammar(meOldGrammar);
+}
+
// calc data structure pretty printer
std::ostream& operator<<(std::ostream& rStrm, const ScAddress& rAddr)
{
@@ -844,4 +856,84 @@ void checkFormula(ScDocument& rDoc, const ScAddress& rPos, const char* expected,
}
}
+ScRange insertRangeData(
+ ScDocument* pDoc, const ScAddress& rPos, const std::vector<std::vector<const char*>>& rData )
+{
+ if (rData.empty())
+ return ScRange(ScAddress::INITIALIZE_INVALID);
+
+ ScAddress aPos = rPos;
+
+ SCCOL nColWidth = 1;
+ for (const std::vector<const char*>& rRow : rData)
+ nColWidth = std::max<SCCOL>(nColWidth, rRow.size());
+
+ ScRange aRange(aPos);
+ aRange.aEnd.IncCol(nColWidth-1);
+ aRange.aEnd.IncRow(rData.size()-1);
+
+ clearRange(pDoc, aRange);
+
+ for (const std::vector<const char*>& rRow : rData)
+ {
+ aPos.SetCol(rPos.Col());
+
+ for (const char* pStr : rRow)
+ {
+ if (!pStr)
+ {
+ aPos.IncCol();
+ continue;
+ }
+
+ OUString aStr(pStr, strlen(pStr), RTL_TEXTENCODING_UTF8);
+
+ ScSetStringParam aParam; // Leave default.
+ aParam.meStartListening = sc::NoListening;
+ pDoc->SetString(aPos, aStr, &aParam);
+
+ aPos.IncCol();
+ }
+
+ aPos.IncRow();
+ }
+
+ pDoc->StartAllListeners(aRange);
+ printRange(pDoc, aRange, "Range data content");
+ return aRange;
+}
+
+void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption)
+{
+ SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
+ SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
+ svl::GridPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1, CALC_DEBUG_OUTPUT != 0);
+ for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
+ {
+ for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+ {
+ ScAddress aPos(nCol, nRow, rRange.aStart.Tab());
+ ScRefCellValue aCell(*pDoc, aPos);
+ OUString aVal = ScCellFormat::GetOutputString(*pDoc, aPos, aCell);
+ printer.set(nRow-nRow1, nCol-nCol1, aVal);
+ }
+ }
+ printer.print(pCaption);
+}
+
+void clearRange(ScDocument* pDoc, const ScRange& rRange)
+{
+ ScMarkData aMarkData(pDoc->GetSheetLimits());
+ aMarkData.SetMarkArea(rRange);
+ pDoc->DeleteArea(
+ rRange.aStart.Col(), rRange.aStart.Row(),
+ rRange.aEnd.Col(), rRange.aEnd.Row(), aMarkData, InsertDeleteFlags::CONTENTS);
+}
+
+void clearSheet(ScDocument* pDoc, SCTAB nTab)
+{
+ ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
+ clearRange(pDoc, aRange);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index 3533cf82cfa0..49ff66d5bc94 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -161,6 +161,19 @@ inline std::string print(const ScAddress& rAddr)
return str.str();
}
+/**
+ * Temporarily set formula grammar.
+ */
+class FormulaGrammarSwitch
+{
+ ScDocument* mpDoc;
+ formula::FormulaGrammar::Grammar meOldGrammar;
+
+public:
+ FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar);
+ ~FormulaGrammarSwitch();
+};
+
class SCQAHELPER_DLLPUBLIC ScBootstrapFixture : public test::BootstrapFixture
{
static const FileFormat aFileFormats[];
@@ -220,4 +233,10 @@ SCQAHELPER_DLLPUBLIC ScTokenArray* getTokens(ScDocument& rDoc, const ScAddress&
SCQAHELPER_DLLPUBLIC std::string to_std_string(const OUString& rStr);
+SCQAHELPER_DLLPUBLIC ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos,
+ const std::vector<std::vector<const char*>>& rData);
+SCQAHELPER_DLLPUBLIC void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption);
+SCQAHELPER_DLLPUBLIC void clearRange(ScDocument* pDoc, const ScRange& rRange);
+SCQAHELPER_DLLPUBLIC void clearSheet(ScDocument* pDoc, SCTAB nTab);
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 32db14e20be2..b13bd77592c1 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -100,17 +100,6 @@ struct TestImpl
ScDocShellRef m_xDocShell;
};
-FormulaGrammarSwitch::FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar) :
- mpDoc(pDoc), meOldGrammar(pDoc->GetGrammar())
-{
- mpDoc->SetGrammar(eGrammar);
-}
-
-FormulaGrammarSwitch::~FormulaGrammarSwitch()
-{
- mpDoc->SetGrammar(meOldGrammar);
-}
-
Test::Test() :
m_pImpl(new TestImpl),
m_pDoc(nullptr)
@@ -940,7 +929,7 @@ struct HoriIterCheck
bool checkHorizontalIterator(ScDocument& rDoc, const std::vector<std::vector<const char*>>& rData, const HoriIterCheck* pChecks, size_t nCheckCount)
{
ScAddress aPos(0,0,0);
- Test::insertRangeData(&rDoc, aPos, rData);
+ insertRangeData(&rDoc, aPos, rData);
ScHorizontalCellIterator aIter(rDoc, 0, 0, 0, 1, rData.size() - 1);
SCCOL nCol;
@@ -12413,39 +12402,6 @@ bool Test::insertRangeNames(
return true;
}
-void Test::printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption)
-{
- SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
- SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
- svl::GridPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1, CALC_DEBUG_OUTPUT != 0);
- for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
- {
- for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
- {
- ScAddress aPos(nCol, nRow, rRange.aStart.Tab());
- ScRefCellValue aCell(*pDoc, aPos);
- OUString aVal = ScCellFormat::GetOutputString(*pDoc, aPos, aCell);
- printer.set(nRow-nRow1, nCol-nCol1, aVal);
- }
- }
- printer.print(pCaption);
-}
-
-void Test::clearRange(ScDocument* pDoc, const ScRange& rRange)
-{
- ScMarkData aMarkData(pDoc->GetSheetLimits());
- aMarkData.SetMarkArea(rRange);
- pDoc->DeleteArea(
- rRange.aStart.Col(), rRange.aStart.Row(),
- rRange.aEnd.Col(), rRange.aEnd.Row(), aMarkData, InsertDeleteFlags::CONTENTS);
-}
-
-void Test::clearSheet(ScDocument* pDoc, SCTAB nTab)
-{
- ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
- clearRange(pDoc, aRange);
-}
-
ScUndoCut* Test::cutToClip(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pClipDoc, bool bCreateUndo)
{
ScDocument* pSrcDoc = &rDocSh.GetDocument();
@@ -12551,53 +12507,6 @@ void Test::checkPrecisionAsShown( OUString& rCode, double fValue, double fExpect
CPPUNIT_ASSERT_EQUAL_MESSAGE( aMessage.getStr(), fExpectedRoundVal, fRoundValue );
}
-ScRange Test::insertRangeData(
- ScDocument* pDoc, const ScAddress& rPos, const std::vector<std::vector<const char*>>& rData )
-{
- if (rData.empty())
- return ScRange(ScAddress::INITIALIZE_INVALID);
-
- ScAddress aPos = rPos;
-
- SCCOL nColWidth = 1;
- for (const std::vector<const char*>& rRow : rData)
- nColWidth = std::max<SCCOL>(nColWidth, rRow.size());
-
- ScRange aRange(aPos);
- aRange.aEnd.IncCol(nColWidth-1);
- aRange.aEnd.IncRow(rData.size()-1);
-
- clearRange(pDoc, aRange);
-
- for (const std::vector<const char*>& rRow : rData)
- {
- aPos.SetCol(rPos.Col());
-
- for (const char* pStr : rRow)
- {
- if (!pStr)
- {
- aPos.IncCol();
- continue;
- }
-
- OUString aStr(pStr, strlen(pStr), RTL_TEXTENCODING_UTF8);
-
- ScSetStringParam aParam; // Leave default.
- aParam.meStartListening = sc::NoListening;
- pDoc->SetString(aPos, aStr, &aParam);
-
- aPos.IncCol();
- }
-
- aPos.IncRow();
- }
-
- pDoc->StartAllListeners(aRange);
- printRange(pDoc, aRange, "Range data content");
- return aRange;
-}
-
void Test::testPrecisionAsShown()
{
m_pDoc->InsertTab(0, "Test");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index c265ca13db67..9fb3d4c4b8e3 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -20,19 +20,6 @@ struct TestImpl;
class ScUndoPaste;
class ScUndoCut;
-/**
- * Temporarily set formula grammar.
- */
-class FormulaGrammarSwitch
-{
- ScDocument* mpDoc;
- formula::FormulaGrammar::Grammar meOldGrammar;
-
-public:
- FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar);
- ~FormulaGrammarSwitch();
-};
-
class Test : public test::BootstrapFixture
{
public:
@@ -46,9 +33,6 @@ public:
static ScDocShell* findLoadedDocShellByName(std::u16string_view rName);
static bool insertRangeNames(ScDocument* pDoc, ScRangeName* pNames, const RangeNameDef* p,
const RangeNameDef* pEnd);
- static void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption);
- static void clearRange(ScDocument* pDoc, const ScRange& rRange);
- static void clearSheet(ScDocument* pDoc, SCTAB nTab);
static ScUndoCut* cutToClip(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pClipDoc,
bool bCreateUndo);
static void copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc);
@@ -70,9 +54,6 @@ public:
void checkPrecisionAsShown(OUString& rCode, double fValue, double fExpectedRoundVal);
- static ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos,
- const std::vector<std::vector<const char*>>& rData);
-
Test();
virtual ~Test() override;
@@ -494,27 +475,6 @@ public:
void testFindAreaPosColRight();
void testShiftCells();
- void testSort();
- void testSortHorizontal();
- void testSortHorizontalWholeColumn();
- void testSortSingleRow();
- void testSortWithFormulaRefs();
- void testSortWithStrings();
- void testSortInFormulaGroup();
- void testSortWithCellFormats();
- void testSortRefUpdate();
- void testSortRefUpdate2();
- void testSortRefUpdate3();
- void testSortRefUpdate4();
- void testSortRefUpdate4_Impl();
- void testSortRefUpdate5();
- void testSortRefUpdate6();
- void testSortBroadcaster();
- void testSortBroadcastBroadcaster();
- void testSortOutOfPlaceResult();
- void testSortPartialFormulaGroup();
- void testSortImages();
-
void testNoteBasic();
void testNoteDeleteRow();
void testNoteDeleteCol();
@@ -882,25 +842,6 @@ public:
CPPUNIT_TEST(testCopyPasteReferencesExternalDoc);
CPPUNIT_TEST(testFindAreaPosVertical);
CPPUNIT_TEST(testFindAreaPosColRight);
- CPPUNIT_TEST(testSort);
- CPPUNIT_TEST(testSortHorizontal);
- CPPUNIT_TEST(testSortHorizontalWholeColumn);
- CPPUNIT_TEST(testSortSingleRow);
- CPPUNIT_TEST(testSortWithFormulaRefs);
- CPPUNIT_TEST(testSortWithStrings);
- CPPUNIT_TEST(testSortInFormulaGroup);
- CPPUNIT_TEST(testSortWithCellFormats);
- CPPUNIT_TEST(testSortRefUpdate);
- CPPUNIT_TEST(testSortRefUpdate2);
- CPPUNIT_TEST(testSortRefUpdate3);
- CPPUNIT_TEST(testSortRefUpdate4);
- CPPUNIT_TEST(testSortRefUpdate5);
- CPPUNIT_TEST(testSortRefUpdate6);
- CPPUNIT_TEST(testSortBroadcaster);
- CPPUNIT_TEST(testSortBroadcastBroadcaster);
- CPPUNIT_TEST(testSortOutOfPlaceResult);
- CPPUNIT_TEST(testSortPartialFormulaGroup);
- CPPUNIT_TEST(testSortImages);
CPPUNIT_TEST(testShiftCells);
CPPUNIT_TEST(testNoteBasic);
CPPUNIT_TEST(testNoteDeleteRow);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 65876d57a520..aee414898d8f 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -5781,7 +5781,7 @@ static void runTestMATCH(ScDocument* pDoc, const char* aData[DataSize], const St
}
pDoc->CalcAll();
- Test::printRange(pDoc, ScRange(0, 0, 0, 2, FormulaSize-1, 0), "MATCH");
+ printRange(pDoc, ScRange(0, 0, 0, 2, FormulaSize-1, 0), "MATCH");
// verify the results.
for (size_t i = 0; i < FormulaSize; ++i)
@@ -5815,7 +5815,7 @@ static void runTestHorizontalMATCH(ScDocument* pDoc, const char* aData[DataSize]
}
pDoc->CalcAll();
- Test::printRange(pDoc, ScRange(0, 0, 0, FormulaSize-1, 2, 0), "MATCH");
+ printRange(pDoc, ScRange(0, 0, 0, FormulaSize-1, 2, 0), "MATCH");
// verify the results.
for (size_t i = 0; i < FormulaSize; ++i)
@@ -6806,8 +6806,8 @@ void Test::testExternalRangeName()
static void testExtRefFuncT(ScDocument* pDoc, ScDocument& rExtDoc)
{
- Test::clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
- Test::clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
rExtDoc.SetString(0, 0, 0, "'1.2");
rExtDoc.SetString(0, 1, 0, "Foo");
@@ -6827,8 +6827,8 @@ static void testExtRefFuncT(ScDocument* pDoc, ScDocument& rExtDoc)
static void testExtRefFuncOFFSET(ScDocument* pDoc, ScDocument& rExtDoc)
{
- Test::clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
- Test::clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
sc::AutoCalcSwitch aACSwitch(*pDoc, true);
@@ -6840,8 +6840,8 @@ static void testExtRefFuncOFFSET(ScDocument* pDoc, ScDocument& rExtDoc)
static void testExtRefFuncVLOOKUP(ScDocument* pDoc, ScDocument& rExtDoc)
{
- Test::clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
- Test::clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
// Populate the external document.
rExtDoc.SetString(ScAddress(0,0,0), "A1");
@@ -6871,8 +6871,8 @@ static void testExtRefFuncVLOOKUP(ScDocument* pDoc, ScDocument& rExtDoc)
static void testExtRefConcat(ScDocument* pDoc, ScDocument& rExtDoc)
{
- Test::clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
- Test::clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
+ clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
sc::AutoCalcSwitch aACSwitch(*pDoc, true);
diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 027074cc4e2e..c787385def94 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -84,7 +84,7 @@ ScRange insertDPSourceData(ScDocument* pDoc, DPFieldDef const aFields[], size_t
static_cast<SCROW>(nDataCount), nRow2);
ScRange aSrcRange(nCol1, nRow1, 0, nCol2, nRow2, 0);
- Test::printRange(pDoc, aSrcRange, "Data sheet content");
+ printRange(pDoc, aSrcRange, "Data sheet content");
return aSrcRange;
}
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index 58b6e5016674..ab2322cfef8a 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -7,11 +7,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include "ucalc.hxx"
+#include <test/bootstrapfixture.hxx>
#include "helper/sorthelper.hxx"
#include "helper/debughelper.hxx"
#include "helper/qahelper.hxx"
+#include <scdll.hxx>
#include <postit.hxx>
#include <sortparam.hxx>
#include <dbdata.hxx>
@@ -33,12 +34,99 @@
#include <svx/svdpage.hxx>
#include <rtl/math.hxx>
-void Test::testSort()
+class TestSort : public test::BootstrapFixture
+{
+public:
+ TestSort();
+
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ void testSort();
+ void testSortHorizontal();
+ void testSortHorizontalWholeColumn();
+ void testSortSingleRow();
+ void testSortWithFormulaRefs();
+ void testSortWithStrings();
+ void testSortInFormulaGroup();
+ void testSortWithCellFormats();
+ void testSortRefUpdate();
+ void testSortRefUpdate2();
+ void testSortRefUpdate3();
+ void testSortRefUpdate4();
+ void testSortRefUpdate4_Impl();
+ void testSortRefUpdate5();
+ void testSortRefUpdate6();
+ void testSortBroadcaster();
+ void testSortBroadcastBroadcaster();
+ void testSortOutOfPlaceResult();
+ void testSortPartialFormulaGroup();
+ void testSortImages();
+
+ CPPUNIT_TEST_SUITE(TestSort);
+
+ CPPUNIT_TEST(testSort);
+ CPPUNIT_TEST(testSortHorizontal);
+ CPPUNIT_TEST(testSortHorizontalWholeColumn);
+ CPPUNIT_TEST(testSortSingleRow);
+ CPPUNIT_TEST(testSortWithFormulaRefs);
+ CPPUNIT_TEST(testSortWithStrings);
+ CPPUNIT_TEST(testSortInFormulaGroup);
+ CPPUNIT_TEST(testSortWithCellFormats);
+ CPPUNIT_TEST(testSortRefUpdate);
+ CPPUNIT_TEST(testSortRefUpdate2);
+ CPPUNIT_TEST(testSortRefUpdate3);
+ CPPUNIT_TEST(testSortRefUpdate4);
+ CPPUNIT_TEST(testSortRefUpdate5);
+ CPPUNIT_TEST(testSortRefUpdate6);
+ CPPUNIT_TEST(testSortBroadcaster);
+ CPPUNIT_TEST(testSortBroadcastBroadcaster);
+ CPPUNIT_TEST(testSortOutOfPlaceResult);
+ CPPUNIT_TEST(testSortPartialFormulaGroup);
+ CPPUNIT_TEST(testSortImages);
+
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ ScDocShellRef m_xDocShell;
+ ScDocument* m_pDoc;
+};
+
+
+TestSort::TestSort()
+{
+}
+
+void TestSort::setUp()
+{
+ BootstrapFixture::setUp();
+
+ ScDLL::Init();
+
+ m_xDocShell = new ScDocShell(
+ SfxModelFlags::EMBEDDED_OBJECT |
+ SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
+ SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+ m_xDocShell->SetIsInUcalc();
+ m_xDocShell->DoInitUnitTest();
+
+ m_pDoc = &m_xDocShell->GetDocument();
+}
+
+void TestSort::tearDown()
+{
+ m_xDocShell->DoClose();
+ m_xDocShell.clear();
+
+ test::BootstrapFixture::tearDown();
+}
+
+void TestSort::testSort()
{
m_pDoc->InsertTab(0, "test1");
// We need a drawing layer in order to create caption objects.
- m_pDoc->InitDrawLayer(&getDocShell());
+ m_pDoc->InitDrawLayer(m_xDocShell.get());
ScAddress aPos(0,0,0);
{
@@ -125,7 +213,7 @@ void Test::testSort()
m_pDoc->DeleteTab(0);
}
-void Test::testSortHorizontal()
+void TestSort::testSortHorizontal()
{
SortRefUpdateSetter aUpdateSet;
@@ -134,7 +222,7 @@ void Test::testSortHorizontal()
aNewOptions.SetFormulaSepArg(";");
aNewOptions.SetFormulaSepArrayCol(";");
aNewOptions.SetFormulaSepArrayRow("|");
- getDocShell().SetFormulaOptions(aNewOptions);
+ m_xDocShell->SetFormulaOptions(aNewOptions);
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true);
m_pDoc->InsertTab(0, "Sort");
@@ -163,7 +251,7 @@ void Test::testSortHorizontal()
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 3, 3)));
// Sort A1:D4 horizontally, ascending by row 1.
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
ScSortParam aSortData;
aSortData.nCol1 = 0;
@@ -197,12 +285,12 @@ void Test::testSortHorizontal()
ASSERT_FORMULA_EQUAL(*m_pDoc, ScAddress(1,3,0), "CONCATENATE(C4;\"-\";D4)", "Wrong formula!");
// restore formula options back to default
- getDocShell().SetFormulaOptions(aOldOptions);
+ m_xDocShell->SetFormulaOptions(aOldOptions);
m_pDoc->DeleteTab(0);
}
-void Test::testSortHorizontalWholeColumn()
+void TestSort::testSortHorizontalWholeColumn()
{
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true);
m_pDoc->InsertTab(0, "Sort");
@@ -233,7 +321,7 @@ void Test::testSortHorizontalWholeColumn()
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, nCol1, nRow1, nCol2, nRow2, false, false)));
// Sort C:G horizontally ascending by row 1.
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
ScSortParam aSortData;
aSortData.nCol1 = nCol1;
@@ -279,7 +367,7 @@ void Test::testSortHorizontalWholeColumn()
m_pDoc->DeleteTab(0);
}
-void Test::testSortSingleRow()
+void TestSort::testSortSingleRow()
{
// This test case is from fdo#80462.
@@ -294,7 +382,7 @@ void Test::testSortSingleRow()
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 0)));
// Sort A1:B1 horizontally, ascending by row 1.
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
ScSortParam aSortData;
aSortData.nCol1 = 0;
@@ -372,7 +460,7 @@ void Test::testSortSingleRow()
// regression test of fdo#53814, sorting doesn't work as expected
// if cells in the sort are referenced by formulas
-void Test::testSortWithFormulaRefs()
+void TestSort::testSortWithFormulaRefs()
{
SortRefUpdateSetter aUpdateSet;
@@ -432,7 +520,7 @@ void Test::testSortWithFormulaRefs()
m_pDoc->DeleteTab(0);
}
-void Test::testSortWithStrings()
+void TestSort::testSortWithStrings()
{
m_pDoc->InsertTab(0, "Test");
@@ -473,7 +561,7 @@ void Test::testSortWithStrings()
m_pDoc->DeleteTab(0);
}
-void Test::testSortInFormulaGroup()
+void TestSort::testSortInFormulaGroup()
{
SortRefUpdateSetter aUpdateSet;
@@ -534,7 +622,7 @@ void Test::testSortInFormulaGroup()
m_pDoc->DeleteTab( 0 );
}
-void Test::testSortWithCellFormats()
+void TestSort::testSortWithCellFormats()
{
struct
{
@@ -663,7 +751,7 @@ void Test::testSortWithCellFormats()
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 3)));
// Sort A1:A4 ascending with cell formats.
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
ScSortParam aSortData;
aSortData.nCol1 = 0;
@@ -699,7 +787,7 @@ void Test::testSortWithCellFormats()
m_pDoc->DeleteTab(0);
}
-void Test::testSortRefUpdate()
+void TestSort::testSortRefUpdate()
{
SortTypeSetter aSortTypeSet(true);
@@ -728,7 +816,7 @@ void Test::testSortRefUpdate()
CPPUNIT_ASSERT_EQUAL(fCheck, m_pDoc->GetValue(ScAddress(2,i+1,0)));
}
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Define A1:A10 as sheet-local anonymous database range, else sort wouldn't run.
m_pDoc->SetAnonymousDBData(
@@ -848,7 +936,7 @@ void Test::testSortRefUpdate()
m_pDoc->DeleteTab(0);
}
-void Test::testSortRefUpdate2()
+void TestSort::testSortRefUpdate2()
{
SortRefUpdateSetter aUpdateSet;
@@ -879,7 +967,7 @@ void Test::testSortRefUpdate2()
CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(1,3,0)));
CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(ScAddress(1,4,0)));
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Define A1:B5 as sheet-local anonymous database range, else sort wouldn't run.
m_pDoc->SetAnonymousDBData(
@@ -936,7 +1024,7 @@ void Test::testSortRefUpdate2()
m_pDoc->DeleteTab(0);
}
-void Test::testSortRefUpdate3()
+void TestSort::testSortRefUpdate3()
{
SortRefUpdateSetter aUpdateSet;
@@ -964,7 +1052,7 @@ void Test::testSortRefUpdate3()
CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(0,4,0)));
CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(0,5,0)));
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:A6.
m_pDoc->SetAnonymousDBData(
@@ -1023,7 +1111,7 @@ void Test::testSortRefUpdate3()
// Derived from fdo#79441 https://bugs.freedesktop.org/attachment.cgi?id=100144
// testRefInterne.ods
-void Test::testSortRefUpdate4()
+void TestSort::testSortRefUpdate4()
{
// This test has to work in both update reference modes.
{
@@ -1036,7 +1124,7 @@ void Test::testSortRefUpdate4()
}
}
-void Test::testSortRefUpdate4_Impl()
+void TestSort::testSortRefUpdate4_Impl()
{
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
m_pDoc->InsertTab(0, "Sort");
@@ -1095,7 +1183,7 @@ void Test::testSortRefUpdate4_Impl()
CPPUNIT_ASSERT_EQUAL_MESSAGE("failed to insert range data at correct position", aPos, aSortRange.aStart);
}
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:D6 by column D (Average, with a row header).
{
@@ -1229,7 +1317,7 @@ void Test::testSortRefUpdate4_Impl()
* functions it's not that easy to come up with something reproducible staying
* stable over sorts... ;-) Check for time and don't run test a few seconds
* before midnight, ermm... */
-void Test::testSortRefUpdate5()
+void TestSort::testSortRefUpdate5()
{
SortRefUpdateSetter aUpdateSet;
@@ -1268,7 +1356,7 @@ void Test::testSortRefUpdate5()
}
}
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:B5.
m_pDoc->SetAnonymousDBData( 0, std::unique_ptr<ScDBData>(new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(),
@@ -1332,7 +1420,7 @@ void Test::testSortRefUpdate5()
m_pDoc->DeleteTab(0);
}
-void Test::testSortRefUpdate6()
+void TestSort::testSortRefUpdate6()
{
SortRefNoUpdateSetter aUpdateSet;
@@ -1363,7 +1451,7 @@ void Test::testSortRefUpdate6()
CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
}
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:C4.
m_pDoc->SetAnonymousDBData(
@@ -1435,7 +1523,7 @@ void Test::testSortRefUpdate6()
}
// Change the value of C1 and make sure the formula broadcasting chain still works.
- ScDocFunc& rFunc = getDocShell().GetDocFunc();
+ ScDocFunc& rFunc = m_xDocShell->GetDocFunc();
rFunc.SetValueCell(ScAddress(2,0,0), 11.0, false);
{
// Expected output table content. 0 = empty cell
@@ -1470,7 +1558,7 @@ void Test::testSortRefUpdate6()
// fdo#86762 check that broadcasters are sorted correctly and empty cell is
// broadcasted.
-void Test::testSortBroadcaster()
+void TestSort::testSortBroadcaster()
{
SortRefNoUpdateSetter aUpdateSet;
@@ -1502,7 +1590,7 @@ void Test::testSortBroadcaster()
m_pDoc->SetAnonymousDBData(
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 1)));
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:B2 by column A descending.
ScSortParam aSortData;
@@ -1599,7 +1687,7 @@ void Test::testSortBroadcaster()
m_pDoc->SetAnonymousDBData(
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 4, 1, 5)));
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A5:B6 by row 5 descending.
ScSortParam aSortData;
@@ -1670,7 +1758,7 @@ void Test::testSortBroadcaster()
// tdf#99417 check that formulas are tracked that *only* indirectly depend on
// sorted data and no other broadcasting than BroadcastBroadcasters is
// involved (for which this test can not be included in testSortBroadcaster()).
-void Test::testSortBroadcastBroadcaster()
+void TestSort::testSortBroadcastBroadcaster()
{
SortRefNoUpdateSetter aUpdateSet;
@@ -1702,7 +1790,7 @@ void Test::testSortBroadcastBroadcaster()
m_pDoc->SetAnonymousDBData(
0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 1)));
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:A2 by column A descending.
ScSortParam aSortData;
@@ -1739,7 +1827,7 @@ void Test::testSortBroadcastBroadcaster()
m_pDoc->DeleteTab(0);
}
-void Test::testSortOutOfPlaceResult()
+void TestSort::testSortOutOfPlaceResult()
{
m_pDoc->InsertTab(0, "Sort");
m_pDoc->InsertTab(1, "Result");
@@ -1766,7 +1854,7 @@ void Test::testSortOutOfPlaceResult()
CPPUNIT_ASSERT_EQUAL( 9.0, m_pDoc->GetValue(ScAddress(0,4,0)));
CPPUNIT_ASSERT_EQUAL(-2.0, m_pDoc->GetValue(ScAddress(0,5,0)));
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort A1:A6, and set the result to C2:C7
m_pDoc->SetAnonymousDBData(
@@ -1808,7 +1896,7 @@ void Test::testSortOutOfPlaceResult()
m_pDoc->DeleteTab(0);
}
-void Test::testSortPartialFormulaGroup()
+void TestSort::testSortPartialFormulaGroup()
{
SortRefUpdateSetter aUpdateSet;
@@ -1845,7 +1933,7 @@ void Test::testSortPartialFormulaGroup()
CPPUNIT_ASSERT_MESSAGE("This formula cell should be the first in a group.", pFC->IsSharedTop());
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect formula group length.", static_cast<SCROW>(5), pFC->GetSharedLength());
- ScDBDocFunc aFunc(getDocShell());
+ ScDBDocFunc aFunc(*m_xDocShell);
// Sort only B2:B4. This caused crash at one point (c.f. fdo#81617).
@@ -1885,12 +1973,12 @@ void Test::testSortPartialFormulaGroup()
m_pDoc->DeleteTab(0);
}
-void Test::testSortImages()
+void TestSort::testSortImages()
{
m_pDoc->InsertTab(0, "testSortImages");
// We need a drawing layer in order to create caption objects.
- m_pDoc->InitDrawLayer(&getDocShell());
+ m_pDoc->InitDrawLayer(m_xDocShell.get());
ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
CPPUNIT_ASSERT(pDrawLayer);
@@ -1945,4 +2033,8 @@ void Test::testSortImages()
m_pDoc->DeleteTab(0);
}
+CPPUNIT_TEST_SUITE_REGISTRATION(TestSort);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */