From 931c6a095c5f26dc78c531b127aed2ebc86af98d Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sat, 26 Mar 2016 13:12:16 +0100 Subject: add a few unit tests for ScFormulaListener Change-Id: Ie6c26967167a2dffa0e2047a78eb2b44b6c502f3 --- sc/qa/unit/ucalc.hxx | 8 +++++ sc/qa/unit/ucalc_condformat.cxx | 78 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) (limited to 'sc/qa') diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 848521d299ac..59a445b5e233 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -444,6 +444,10 @@ public: void testIconSet(); void testDataBarLengthAutomaticAxis(); void testDataBarLengthMiddleAxis(); + void testFormulaListenerSingleCellToSingleCell(); + void testFormulaListenerMultipleCellsToSingleCell(); + void testFormulaListenerSingleCellToMultipleCells(); + void testFormulaListenerMultipleCellsToMultipleCells(); void testCondFormatEndsWithStr(); void testCondFormatEndsWithVal(); @@ -691,6 +695,10 @@ public: CPPUNIT_TEST(testIconSet); CPPUNIT_TEST(testDataBarLengthAutomaticAxis); CPPUNIT_TEST(testDataBarLengthMiddleAxis); + CPPUNIT_TEST(testFormulaListenerSingleCellToSingleCell); + CPPUNIT_TEST(testFormulaListenerSingleCellToMultipleCells); + CPPUNIT_TEST(testFormulaListenerMultipleCellsToSingleCell); + CPPUNIT_TEST(testFormulaListenerMultipleCellsToMultipleCells); CPPUNIT_TEST(testImportStream); CPPUNIT_TEST(testDeleteContents); CPPUNIT_TEST(testTransliterateText); diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx index 7af25cf66969..aa21471cf511 100644 --- a/sc/qa/unit/ucalc_condformat.cxx +++ b/sc/qa/unit/ucalc_condformat.cxx @@ -18,6 +18,8 @@ #include "scitems.hxx" #include "attrib.hxx" #include "fillinfo.hxx" +#include "compiler.hxx" +#include "tokenarray.hxx" #include #include @@ -665,4 +667,80 @@ void Test::testCondFormatEndsWithVal() m_pDoc->DeleteTab(0); } +void Test::testFormulaListenerSingleCellToSingleCell() +{ + m_pDoc->InsertTab(0, "test"); + + ScCompiler aCompiler(m_pDoc, ScAddress(10, 10, 0)); + aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH); + + std::unique_ptr pTokenArray(aCompiler.CompileString("A1")); + + ScFormulaListener aListener(m_pDoc); + + aListener.addTokenArray(pTokenArray.get(), ScAddress(10, 10, 0)); + + m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0); + CPPUNIT_ASSERT(aListener.NeedsRepaint()); + + m_pDoc->DeleteTab(0); +} + +void Test::testFormulaListenerSingleCellToMultipleCells() +{ + m_pDoc->InsertTab(0, "test"); + + ScCompiler aCompiler(m_pDoc, ScAddress(10, 10, 0)); + aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH); + + std::unique_ptr pTokenArray(aCompiler.CompileString("A1")); + + ScFormulaListener aListener(m_pDoc); + + aListener.addTokenArray(pTokenArray.get(), ScAddress(10, 10, 0)); + + m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0); + CPPUNIT_ASSERT(aListener.NeedsRepaint()); + + m_pDoc->DeleteTab(0); +} + +void Test::testFormulaListenerMultipleCellsToSingleCell() +{ + m_pDoc->InsertTab(0, "test"); + + ScCompiler aCompiler(m_pDoc, ScAddress(10, 10, 0)); + aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH); + + std::unique_ptr pTokenArray(aCompiler.CompileString("A1")); + + ScFormulaListener aListener(m_pDoc); + + aListener.addTokenArray(pTokenArray.get(), ScAddress(10, 10, 0)); + + m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0); + CPPUNIT_ASSERT(aListener.NeedsRepaint()); + + m_pDoc->DeleteTab(0); +} + +void Test::testFormulaListenerMultipleCellsToMultipleCells() +{ + m_pDoc->InsertTab(0, "test"); + + ScCompiler aCompiler(m_pDoc, ScAddress(10, 10, 0)); + aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH); + + std::unique_ptr pTokenArray(aCompiler.CompileString("A1")); + + ScFormulaListener aListener(m_pDoc); + + aListener.addTokenArray(pTokenArray.get(), ScAddress(10, 10, 0)); + + m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0); + CPPUNIT_ASSERT(aListener.NeedsRepaint()); + + m_pDoc->DeleteTab(0); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit