[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/qa sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Mon Jul 15 16:46:39 PDT 2013
sc/inc/compiler.hxx | 4 ++--
sc/qa/unit/ucalc.hxx | 2 ++
sc/qa/unit/ucalc_formula.cxx | 36 ++++++++++++++++++++++++++++++++++++
sc/source/core/tool/compiler.cxx | 10 +++++-----
4 files changed, 45 insertions(+), 7 deletions(-)
New commits:
commit 5ebd1e7c8746f5060dbc7896bd2074fb1f9d8c71
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Jul 15 19:46:16 2013 -0400
Add test for formula tokenization and back.
Change-Id: I770ba842bc7dd0095d1be75cbd9132affb46ed5f
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 4f4a58c..0ab4c68 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -432,8 +432,8 @@ public:
const String& GetCorrectedFormula() { return aCorrectedFormula; }
// Use convention from this->aPos by default
- ScTokenArray* CompileString( const String& rFormula );
- ScTokenArray* CompileString( const String& rFormula, const String& rFormulaNmsp );
+ ScTokenArray* CompileString( const OUString& rFormula );
+ ScTokenArray* CompileString( const OUString& rFormula, const OUString& rFormulaNmsp );
const ScDocument* GetDoc() const { return pDoc; }
const ScAddress& GetPos() const { return aPos; }
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 43b10a9..0f0198c 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -83,6 +83,7 @@ public:
void testRangeList();
void testInput();
void testFormulaHashAndTag();
+ void testFormulaCompiler();
void testFuncSUM();
void testFuncPRODUCT();
void testFuncN();
@@ -267,6 +268,7 @@ public:
CPPUNIT_TEST(testRangeList);
CPPUNIT_TEST(testInput);
CPPUNIT_TEST(testFormulaHashAndTag);
+ CPPUNIT_TEST(testFormulaCompiler);
CPPUNIT_TEST(testFuncSUM);
CPPUNIT_TEST(testFuncPRODUCT);
CPPUNIT_TEST(testFuncN);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 249a5a7..5d1d082 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -11,6 +11,12 @@
#include "markdata.hxx"
#include "calcconfig.hxx"
#include "interpre.hxx"
+#include "compiler.hxx"
+#include "tokenarray.hxx"
+
+#include <boost/scoped_ptr.hpp>
+
+using namespace formula;
void Test::testFormulaHashAndTag()
{
@@ -103,6 +109,36 @@ void Test::testFormulaHashAndTag()
m_pDoc->DeleteTab(0);
}
+void Test::testFormulaCompiler()
+{
+ struct {
+ const char* pInput; FormulaGrammar::Grammar eInputGram;
+ const char* pOutput; FormulaGrammar::Grammar eOutputGram;
+ } aTests[] = {
+ { "=B1-$C2+D$3-$E$4", FormulaGrammar::GRAM_NATIVE, "[.B1]-[.$C2]+[.D$3]-[.$E$4]", FormulaGrammar::GRAM_ODFF },
+ };
+
+ for (size_t i = 0, n = SAL_N_ELEMENTS(aTests); i < n; ++i)
+ {
+ boost::scoped_ptr<ScTokenArray> pArray;
+ {
+ ScCompiler aComp(m_pDoc, ScAddress());
+ aComp.SetGrammar(aTests[i].eInputGram);
+ pArray.reset(aComp.CompileString(OUString::createFromAscii(aTests[i].pInput)));
+ CPPUNIT_ASSERT_MESSAGE("Token array shouldn't be NULL!", pArray.get());
+ }
+
+ {
+ ScCompiler aComp(m_pDoc, ScAddress(), *pArray);
+ aComp.SetGrammar(aTests[i].eOutputGram);
+ OUStringBuffer aBuf;
+ aComp.CreateStringFromTokenArray(aBuf);
+ OUString aFormula = aBuf.makeStringAndClear();
+ CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(aTests[i].pOutput), aFormula);
+ }
+ }
+}
+
void Test::testFuncSUM()
{
OUString aTabName("foo");
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 3c64b81..1fd1cf6 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3714,7 +3714,7 @@ public:
}
-ScTokenArray* ScCompiler::CompileString( const String& rFormula )
+ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
{
OSL_ENSURE( meGrammar != FormulaGrammar::GRAM_EXTERNAL, "ScCompiler::CompileString - unexpected grammar GRAM_EXTERNAL" );
if( meGrammar == FormulaGrammar::GRAM_EXTERNAL )
@@ -3755,8 +3755,8 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula )
bool bPODF = FormulaGrammar::isPODF( meGrammar);
const size_t nAlloc = 512;
FunctionStack aFuncs[ nAlloc ];
- FunctionStack* pFunctionStack = (bPODF && rFormula.Len() > nAlloc ?
- new FunctionStack[ rFormula.Len() ] : &aFuncs[0]);
+ FunctionStack* pFunctionStack =
+ (bPODF && static_cast<size_t>(rFormula.getLength()) > nAlloc ? new FunctionStack[rFormula.getLength()] : &aFuncs[0]);
pFunctionStack[0].eOp = ocNone;
pFunctionStack[0].nPar = 0;
size_t nFunction = 0;
@@ -3935,9 +3935,9 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula )
}
-ScTokenArray* ScCompiler::CompileString( const String& rFormula, const String& rFormulaNmsp )
+ScTokenArray* ScCompiler::CompileString( const OUString& rFormula, const OUString& rFormulaNmsp )
{
- OSL_ENSURE( (GetGrammar() == FormulaGrammar::GRAM_EXTERNAL) || (rFormulaNmsp.Len() == 0),
+ OSL_ENSURE( (GetGrammar() == FormulaGrammar::GRAM_EXTERNAL) || rFormulaNmsp.isEmpty(),
"ScCompiler::CompileString - unexpected formula namespace for internal grammar" );
if( GetGrammar() == FormulaGrammar::GRAM_EXTERNAL ) try
{
More information about the Libreoffice-commits
mailing list