diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-02 14:40:06 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-02 14:41:12 -0500 |
commit | 4d881d03e5e7156a434719c689af05717bc58913 (patch) | |
tree | 66a64c0965b31458797fc1380d0bfde4ff55e323 /sc/qa | |
parent | 32b8c5c4a9fd03b4e05dff2a77ec186973c126b3 (diff) |
fdo#74077: Write unit test for this.
Change-Id: Ieacad6dc1909ed5647d8a6f4839c9e9d47cb655c
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 55 |
2 files changed, 57 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 8ddd6f00f449..0944f5a90f59 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -101,6 +101,7 @@ public: void testFormulaParseReference(); void testFetchVectorRefArray(); void testFormulaHashAndTag(); + void testFormulaTokenEquality(); void testFormulaRefData(); void testFormulaCompiler(); void testFormulaRefUpdate(); @@ -324,6 +325,7 @@ public: CPPUNIT_TEST(testFormulaParseReference); CPPUNIT_TEST(testFetchVectorRefArray); CPPUNIT_TEST(testFormulaHashAndTag); + CPPUNIT_TEST(testFormulaTokenEquality); CPPUNIT_TEST(testFormulaRefData); CPPUNIT_TEST(testFormulaCompiler); CPPUNIT_TEST(testFormulaRefUpdate); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index b19afdceb03f..df3e4c120ca6 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -564,6 +564,61 @@ void Test::testFormulaHashAndTag() m_pDoc->DeleteTab(0); } +void Test::testFormulaTokenEquality() +{ + struct Test + { + const char* mpFormula1; + const char* mpFormula2; + bool mbEqual; + }; + + Test aTests[] = { + { "R1C2", "R1C2", true }, + { "R1C2", "R1C3", false }, + { "R1C2", "R2C2", false }, + { "RC2", "RC[1]", false }, + { "R1C2:R10C2", "R1C2:R10C2", true }, + { "R1C2:R10C2", "R1C2:R11C2", false }, + { "1", "2", false }, + { "RC[1]+1.2", "RC[1]+1.2", true }, + { "RC[1]*0.2", "RC[1]*0.5", false }, + { "\"Test1\"", "\"Test2\"", false }, + { "\"Test\"", "\"Test\"", true }, + { "CONCATENATE(\"Test1\")", "CONCATENATE(\"Test1\")", true }, + { "CONCATENATE(\"Test1\")", "CONCATENATE(\"Test2\")", false }, + }; + + formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1; + for (size_t i = 0; i < SAL_N_ELEMENTS(aTests); ++i) + { + ScFormulaCell aCell1(m_pDoc, ScAddress(), OUString::createFromAscii(aTests[i].mpFormula1), eGram); + ScFormulaCell aCell2(m_pDoc, ScAddress(), OUString::createFromAscii(aTests[i].mpFormula2), eGram); + + ScFormulaCell::CompareState eComp = aCell1.CompareByTokenArray(aCell2); + if (aTests[i].mbEqual) + { + if (eComp == ScFormulaCell::NotEqual) + { + std::ostringstream os; + os << "These two formulas should be evaluated equal: '" + << aTests[i].mpFormula1 << "' vs '" << aTests[i].mpFormula2 << "'" << endl; + CPPUNIT_FAIL(os.str().c_str()); + } + } + else + { + if (eComp != ScFormulaCell::NotEqual) + { + std::ostringstream os; + os << "These two formulas should be evaluated non-equal: '" + << aTests[i].mpFormula1 << "' vs '" << aTests[i].mpFormula2 << "'" << endl; + CPPUNIT_FAIL(os.str().c_str()); + } + } + } +} + void Test::testFormulaRefData() { ScAddress aAddr(4,5,3), aPos(2,2,2); |