summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2017-05-02 19:44:57 -0400
committerKohei Yoshida <libreoffice@kohei.us>2017-05-03 04:54:54 +0200
commit5233a2c9009533e454a734ac57c764e15f92a229 (patch)
tree6af53bb71ddade3b8dc175605824217cc60646f3
parent93f5cb55349e6de5003182462bfee434dc51f6ad (diff)
tdf#107255: add test case for the multi-cell query method.
This is the best we can do since the rest of the cell merge code is in ScViewFunc which cannot be unit-tested currently. Change-Id: I639f48d5cd05bff015689b0d223684f6f8d302f8 Reviewed-on: https://gerrit.libreoffice.org/37179 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_column.cxx59
2 files changed, 61 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 486bb1064e89..18ddbd58af60 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -518,6 +518,7 @@ public:
void testUndoDataAnchor();
void testFormulaErrorPropagation();
void testSetFormula();
+ void testMultipleDataCellsInRange();
void testTdf97369();
void testTdf97587();
@@ -786,6 +787,7 @@ public:
CPPUNIT_TEST(testUndoDataAnchor);
CPPUNIT_TEST(testFormulaErrorPropagation);
CPPUNIT_TEST(testSetFormula);
+ CPPUNIT_TEST(testMultipleDataCellsInRange);
CPPUNIT_TEST(testTdf97369);
CPPUNIT_TEST(testTdf97587);
CPPUNIT_TEST(testEmptyCalcDocDefaults);
diff --git a/sc/qa/unit/ucalc_column.cxx b/sc/qa/unit/ucalc_column.cxx
index 6a70aef3923f..8aeb6f2dbf57 100644
--- a/sc/qa/unit/ucalc_column.cxx
+++ b/sc/qa/unit/ucalc_column.cxx
@@ -126,4 +126,63 @@ void Test::testSetFormula()
m_pDoc->DeleteTab(0);
}
+void Test::testMultipleDataCellsInRange()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ ScRange aRange(1,2,0); // B3
+ sc::MultiDataCellState aState = m_pDoc->HasMultipleDataCells(aRange);
+ CPPUNIT_ASSERT_EQUAL(sc::MultiDataCellState::Empty, aState.meState);
+
+ // Set a numeric value to B3.
+ m_pDoc->SetValue(ScAddress(1,2,0), 1.0);
+ aState = m_pDoc->HasMultipleDataCells(aRange);
+ CPPUNIT_ASSERT_EQUAL(sc::MultiDataCellState::HasOneCell, aState.meState);
+ CPPUNIT_ASSERT_EQUAL(SCCOL(1), aState.mnCol1);
+ CPPUNIT_ASSERT_EQUAL(SCROW(2), aState.mnRow1);
+ CPPUNIT_ASSERT_EQUAL(SCTAB(0), aState.mnTab1);
+
+ // Set another numeric value to B4.
+ m_pDoc->SetValue(ScAddress(1,3,0), 2.0);
+ aRange.aEnd.SetRow(3); // B3:B4
+ aState = m_pDoc->HasMultipleDataCells(aRange);
+ CPPUNIT_ASSERT_EQUAL(sc::MultiDataCellState::HasMultipleCells, aState.meState);
+ CPPUNIT_ASSERT_EQUAL(SCCOL(1), aState.mnCol1);
+ CPPUNIT_ASSERT_EQUAL(SCROW(2), aState.mnRow1);
+ CPPUNIT_ASSERT_EQUAL(SCTAB(0), aState.mnTab1);
+
+ // Set the query range to B4:B5. Now it should only report one cell, with
+ // B4 being the first non-empty cell.
+ aRange.aStart.SetRow(3);
+ aRange.aEnd.SetRow(4);
+ aState = m_pDoc->HasMultipleDataCells(aRange);
+ CPPUNIT_ASSERT_EQUAL(sc::MultiDataCellState::HasOneCell, aState.meState);
+ CPPUNIT_ASSERT_EQUAL(SCCOL(1), aState.mnCol1);
+ CPPUNIT_ASSERT_EQUAL(SCROW(3), aState.mnRow1);
+ CPPUNIT_ASSERT_EQUAL(SCTAB(0), aState.mnTab1);
+
+ // Set the query range to A1:C3. The first non-empty cell should be B3.
+ aRange = ScRange(0,0,0,2,2,0);
+ aState = m_pDoc->HasMultipleDataCells(aRange);
+ CPPUNIT_ASSERT_EQUAL(sc::MultiDataCellState::HasOneCell, aState.meState);
+ CPPUNIT_ASSERT_EQUAL(SCCOL(1), aState.mnCol1);
+ CPPUNIT_ASSERT_EQUAL(SCROW(2), aState.mnRow1);
+ CPPUNIT_ASSERT_EQUAL(SCTAB(0), aState.mnTab1);
+
+ // Set string cells to D4 and F5, and query D3:F5. D4 should be the first
+ // non-empty cell.
+ m_pDoc->SetString(ScAddress(3,3,0), "foo");
+ m_pDoc->SetString(ScAddress(5,4,0), "bar");
+ aRange = ScRange(3,2,0,5,4,0);
+ aState = m_pDoc->HasMultipleDataCells(aRange);
+ CPPUNIT_ASSERT_EQUAL(sc::MultiDataCellState::HasMultipleCells, aState.meState);
+ CPPUNIT_ASSERT_EQUAL(SCCOL(3), aState.mnCol1);
+ CPPUNIT_ASSERT_EQUAL(SCROW(3), aState.mnRow1);
+ CPPUNIT_ASSERT_EQUAL(SCTAB(0), aState.mnTab1);
+
+ // TODO : add more test cases as needed.
+
+ m_pDoc->DeleteTab(0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */