summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2013-03-18 21:29:58 +0000
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-19 13:40:23 -0400
commitfedb28e84614ac6c0f6076cca56b6c2c8b832198 (patch)
tree5aea102733f56bf2c25a173ff9f6fa8c0c160e01 /sc/qa
parentaed58c04a8483881e4592565587aaf08e6239672 (diff)
add initial formula group unit tests.
Change-Id: Id4dd3cc0d3d8a4db641e316d2eda44a5b94105c7
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/ucalc.cxx58
1 files changed, 58 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 3e9a14d9fe4e..f53089058064 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -33,6 +33,7 @@
#include <osl/file.hxx>
#include "scdll.hxx"
+#include "cell.hxx"
#include "document.hxx"
#include "stringutil.hxx"
#include "scmatrix.hxx"
@@ -266,6 +267,11 @@ public:
void testAnchoredRotatedShape();
void testCellTextWidth();
+ /**
+ * Test formula & formula grouping
+ */
+ void testFormulaGrouping();
+
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testRangeList);
@@ -328,6 +334,7 @@ public:
CPPUNIT_TEST(testDeleteCol);
CPPUNIT_TEST(testAnchoredRotatedShape);
CPPUNIT_TEST(testCellTextWidth);
+ CPPUNIT_TEST(testFormulaGrouping);
CPPUNIT_TEST_SUITE_END();
private:
@@ -6174,6 +6181,57 @@ void Test::testCellTextWidth()
m_pDoc->DeleteTab(0);
}
+void Test::testFormulaGrouping()
+{
+ static const struct {
+ const char *pFormula[3];
+ const bool bGroup[3];
+ } aGroupTests[] = {
+ { { "=B1", "=C1", "" }, // single increments
+ { true, true, false } },
+ { { "=B1", "=D1", "=F1" }, // tripple increments
+ { true, true, true } },
+ { { "=B1", "", "=C1" }, // a gap
+ { false, false, false } },
+ { { "=B1", "=C1+3", "=C1+D1" }, // confusion: FIXME: =C1+7
+ { false, false, false } },
+ };
+
+ m_pDoc->InsertTab( 0, "sheet" );
+
+ for (size_t i = 0; i < SAL_N_ELEMENTS( aGroupTests ); i++)
+ {
+ for (size_t j = 0; j < SAL_N_ELEMENTS( aGroupTests[0].pFormula ); j++)
+ {
+ OUString aFormula = OUString::createFromAscii(aGroupTests[i].pFormula[j]);
+ m_pDoc->SetString(0, (SCROW)j, 0, aFormula);
+ }
+ m_pDoc->RebuildFormulaGroups();
+
+ for (size_t j = 0; j < SAL_N_ELEMENTS( aGroupTests[0].pFormula ); j++)
+ {
+ ScBaseCell *pCell = NULL;
+ m_pDoc->GetCell( 0, (SCROW)j, 0, pCell );
+ if( !pCell )
+ {
+ CPPUNIT_ASSERT_MESSAGE("invalid empty cell", !aGroupTests[i].bGroup[j]);
+ continue;
+ }
+ CPPUNIT_ASSERT_MESSAGE("Cell expected, but not there.", pCell != NULL);
+ CPPUNIT_ASSERT_MESSAGE("Cell wrong type.",
+ pCell->GetCellType() == CELLTYPE_FORMULA);
+ ScFormulaCell *pCur = static_cast< ScFormulaCell *>( pCell );
+
+ if( !!pCur->GetCellGroup().get() ^ aGroupTests[i].bGroup[j] )
+ {
+ printf("expected group test %d at row %d to be %d but is %d\n",
+ i, j, !!pCur->GetCellGroup().get(), aGroupTests[i].bGroup[j]);
+ CPPUNIT_ASSERT_MESSAGE("Failed", false);
+ }
+ }
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}