[Libreoffice-commits] core.git: sc/qa

Markus Mohrhard markus.mohrhard at googlemail.com
Wed Feb 3 19:59:40 UTC 2016


 sc/qa/unit/helper/qahelper.cxx |   29 +++++++++++++++++++++++++++++
 sc/qa/unit/helper/qahelper.hxx |    8 ++++++++
 sc/qa/unit/ucalc_formula.cxx   |    3 +--
 3 files changed, 38 insertions(+), 2 deletions(-)

New commits:
commit aaa7b7c87dc0d685e2a0edf2763aaeacd2d6e579
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Feb 3 14:59:47 2016 +0100

    tdf#90290, add custom asserter for formula
    
    Change-Id: Id584b9ba5955e56f9ee0dacb2534b7365cdce380
    Reviewed-on: https://gerrit.libreoffice.org/22080
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 1e34890..cd9aae6 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -19,6 +19,9 @@
 #include <editeng/brushitem.hxx>
 #include <editeng/justifyitem.hxx>
 
+#include <cppunit/Asserter.h>
+#include <cppunit/AdditionalMessage.h>
+
 #include <config_orcus.h>
 
 #if ENABLE_ORCUS
@@ -734,4 +737,30 @@ void ScBootstrapFixture::miscRowHeightsTest( TestParam* aTestValues, unsigned in
     }
 }
 
+namespace {
+
+std::string to_std_string(const OUString& rStr)
+{
+    return std::string(rStr.toUtf8().getStr());
+}
+
+}
+
+void checkFormula(ScDocument& rDoc, const ScAddress& rPos, const char* expected, const char* msg, CppUnit::SourceLine sourceLine)
+{
+    ScTokenArray* pCode = getTokens(rDoc, rPos);
+    if (!pCode)
+    {
+        CppUnit::Asserter::fail("empty token array", sourceLine);
+    }
+
+    OUString aFormula = toString(rDoc, rPos, *pCode, rDoc.GetGrammar());
+    OUString aExpectedFormula = OUString::createFromAscii(expected);
+    if (aFormula != aExpectedFormula)
+    {
+        CppUnit::Asserter::failNotEqual(to_std_string(aExpectedFormula),
+                to_std_string(aFormula), sourceLine, CppUnit::AdditionalMessage(msg));
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index cce409c..083e2d1 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -15,6 +15,8 @@
 #include "docsh.hxx"
 #include "address.hxx"
 
+#include <cppunit/SourceLine.h>
+
 #include <test/bootstrapfixture.hxx>
 #include <comphelper/documentconstants.hxx>
 
@@ -244,6 +246,12 @@ public:
 #define ASSERT_EQUAL_TYPE( type, expected, result ) \
     CPPUNIT_ASSERT_EQUAL( static_cast<type>(expected), static_cast<type>(result) );
 
+SCQAHELPER_DLLPUBLIC void checkFormula(ScDocument& rDoc, const ScAddress& rPos,
+        const char* expected, const char* msg, CppUnit::SourceLine sourceLine);
+
+#define ASSERT_FORMULA_EQUAL(doc, pos, expected, msg) \
+    checkFormula(doc, pos, expected, msg, CPPUNIT_SOURCELINE())
+
 SCQAHELPER_DLLPUBLIC void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat);
 
 #endif
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 4b41261..d8ba5ce 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1295,8 +1295,7 @@ void Test::testFormulaRefUpdateRange()
     m_pDoc->SetString(ScAddress(0,6,0), "=SUM(B2:C5)");
     m_pDoc->SetString(ScAddress(0,7,0), "=SUM($B$2:$C$5)");
 
-    if (!checkFormula(*m_pDoc, ScAddress(0,6,0), "SUM(B2:C5)"))
-        CPPUNIT_FAIL("Wrong formula in A7.");
+    ASSERT_FORMULA_EQUAL(*m_pDoc, ScAddress(0,6,0), "SUM(B2:C5)", "Wrong formula in A7.");
 
     if (!checkFormula(*m_pDoc, ScAddress(0,7,0), "SUM($B$2:$C$5)"))
         CPPUNIT_FAIL("Wrong formula in A8.");


More information about the Libreoffice-commits mailing list