summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-18 14:19:52 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-19 13:40:22 -0400
commit6433ab29afa4d19000c14bdc0b64c0062972427e (patch)
treefb70ea164f36e9935ed05a682e4a1f6b1893a268 /sc/qa
parent6000c8d15510b77a02d517afb81e3d2e164b318c (diff)
Implement (partially?) and test formula token array hash function.
For now, we don't factor in any differences in reference tokens in the generated hash values. Change-Id: Ie9836228eaad9c74edd884c3e8c4b273979760fd
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/ucalc.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ec9465228ee5..4d93eb1e24be 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -116,6 +116,7 @@ public:
void testCollator();
void testRangeList();
void testInput();
+ void testFormulaGrouping();
void testCellFunctions();
void testCopyToDocument();
/**
@@ -269,6 +270,7 @@ public:
CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testRangeList);
CPPUNIT_TEST(testInput);
+ CPPUNIT_TEST(testFormulaGrouping);
CPPUNIT_TEST(testCellFunctions);
CPPUNIT_TEST(testCopyToDocument);
CPPUNIT_TEST(testSheetsFunc);
@@ -1188,6 +1190,56 @@ void testFuncINDIRECT(ScDocument* pDoc)
}
}
+void Test::testFormulaGrouping()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ ScAddress aPos1(0,0,0), aPos2(1,0,0);
+
+ // simplest cases.
+ m_pDoc->SetString(aPos1, "=1");
+ size_t nHashVal1 = m_pDoc->GetFormulaHash(aPos1);
+ m_pDoc->SetString(aPos2, "=2");
+ size_t nHashVal2 = m_pDoc->GetFormulaHash(aPos2);
+ CPPUNIT_ASSERT_MESSAGE("These hashes should differ.", nHashVal1 != nHashVal2);
+
+ // different cell functions.
+ aPos1.IncRow();
+ aPos2.IncRow();
+ m_pDoc->SetString(aPos1, "=SUM(1,2,3,4,5)");
+ m_pDoc->SetString(aPos2, "=AVERAGE(1,2,3,4,5)");
+ nHashVal1 = m_pDoc->GetFormulaHash(aPos1);
+ nHashVal2 = m_pDoc->GetFormulaHash(aPos2);
+ CPPUNIT_ASSERT_MESSAGE("These hashes should differ.", nHashVal1 != nHashVal2);
+
+ // same relative references.
+ aPos1.IncRow();
+ aPos2.IncRow();
+ m_pDoc->SetString(aPos1, "=A2*3");
+ m_pDoc->SetString(aPos2, "=B2*3");
+ nHashVal1 = m_pDoc->GetFormulaHash(aPos1);
+ nHashVal2 = m_pDoc->GetFormulaHash(aPos2);
+ CPPUNIT_ASSERT_MESSAGE("These hashes should be equal.", nHashVal1 == nHashVal2);
+
+ m_pDoc->SetString(aPos2, "=B2*4"); // Change the constant.
+ nHashVal2 = m_pDoc->GetFormulaHash(aPos2);
+ CPPUNIT_ASSERT_MESSAGE("These hashes should differ.", nHashVal1 != nHashVal2);
+
+ m_pDoc->SetString(aPos1, "=A2*4"); // Change the constant again to make it "equal".
+ nHashVal1 = m_pDoc->GetFormulaHash(aPos1);
+ CPPUNIT_ASSERT_MESSAGE("These hashes should be equal.", nHashVal1 == nHashVal2);
+
+ aPos1.IncRow();
+ aPos2.IncRow();
+ m_pDoc->SetString(aPos1, "=3*4*5");
+ m_pDoc->SetString(aPos2, "=3*4*\"foo\"");
+ nHashVal1 = m_pDoc->GetFormulaHash(aPos1);
+ nHashVal2 = m_pDoc->GetFormulaHash(aPos2);
+ CPPUNIT_ASSERT_MESSAGE("These hashes should differ.", nHashVal1 != nHashVal2);
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testCellFunctions()
{
OUString aTabName("foo");