Kaydet (Commit) aaa7b7c8 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

tdf#90290, add custom asserter for formula

Change-Id: Id584b9ba5955e56f9ee0dacb2534b7365cdce380
Reviewed-on: https://gerrit.libreoffice.org/22080Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 1487b9dd
......@@ -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: */
......@@ -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
......
......@@ -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.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment