diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2017-02-11 15:58:23 -0500 |
---|---|---|
committer | Kohei Yoshida <libreoffice@kohei.us> | 2017-02-11 22:02:08 +0000 |
commit | 5fea81e4bfc2372563c0612f95406ca34fdd2c96 (patch) | |
tree | 6362b4917071678f77da8cfdf7afefa913b2f2d9 /sc | |
parent | bcdde13996e3e33f9d4c41be25d062560c72636b (diff) |
tdf#86470: add unit test for this.
Change-Id: Ib93703d10fe1fff0898bc935222df7a0cfe20486
Reviewed-on: https://gerrit.libreoffice.org/34160
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 52 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 3 |
2 files changed, 55 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 86f04c4b8f5b..884ae3f2793d 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -710,6 +710,58 @@ void Test::testSelectionFunction() m_pDoc->DeleteTab(0); } +void Test::testMarkedCellIteration() +{ + m_pDoc->InsertTab(0, "Test"); + + // Insert cells to A1, A5, B2 and C3. + m_pDoc->SetString(ScAddress(0,0,0), "California"); + m_pDoc->SetValue(ScAddress(0,4,0), 1.2); + m_pDoc->SetEditText(ScAddress(1,1,0), "Boston"); + m_pDoc->SetFormula(ScAddress(2,2,0), "=SUM(1,2,3)", m_pDoc->GetGrammar()); + + // Select A1:C5. + ScMarkData aMarkData; + aMarkData.SetMarkArea(ScRange(0,0,0,2,4,0)); + aMarkData.MarkToMulti(); // TODO : we shouldn't have to do this. + + struct Check + { + SCCOL mnCol; + SCROW mnRow; + }; + + const std::vector<Check> aChecks = { + { 0, 0 }, // A1 + { 0, 4 }, // A5 + { 1, 1 }, // B2 + { 2, 2 }, // C3 + }; + + SCROW nRow = -1; // Start from the imaginary row before A1. + SCCOL nCol = 0; + + for (const Check& rCheck : aChecks) + { + bool bFound = m_pDoc->GetNextMarkedCell(nCol, nRow, 0, aMarkData); + if (!bFound) + { + std::ostringstream os; + os << ScAddress(rCheck.mnCol, rCheck.mnRow, 0).GetColRowString() << " was expected, but not found."; + CPPUNIT_FAIL(os.str().data()); + } + + CPPUNIT_ASSERT_EQUAL(rCheck.mnRow, nRow); + CPPUNIT_ASSERT_EQUAL(rCheck.mnCol, nCol); + } + + // No more marked cells on this sheet. + bool bFound = m_pDoc->GetNextMarkedCell(nCol, nRow, 0, aMarkData); + CPPUNIT_ASSERT(!bFound); + + m_pDoc->DeleteTab(0); +} + void Test::testCopyToDocument() { CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet", m_pDoc->InsertTab (0, "src")); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index fc956db49113..17154478da0d 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -123,6 +123,8 @@ public: */ void testSelectionFunction(); + void testMarkedCellIteration(); + void testFormulaCreateStringFromTokens(); void testFormulaParseReference(); void testFetchVectorRefArray(); @@ -502,6 +504,7 @@ public: CPPUNIT_TEST(testRowForHeight); CPPUNIT_TEST(testDataEntries); CPPUNIT_TEST(testSelectionFunction); + CPPUNIT_TEST(testMarkedCellIteration); CPPUNIT_TEST(testFormulaCreateStringFromTokens); CPPUNIT_TEST(testFormulaParseReference); CPPUNIT_TEST(testFetchVectorRefArray); |