Kaydet (Commit) fedb28e8 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Kohei Yoshida

add initial formula group unit tests.

Change-Id: Id4dd3cc0d3d8a4db641e316d2eda44a5b94105c7
üst aed58c04
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <osl/file.hxx> #include <osl/file.hxx>
#include "scdll.hxx" #include "scdll.hxx"
#include "cell.hxx"
#include "document.hxx" #include "document.hxx"
#include "stringutil.hxx" #include "stringutil.hxx"
#include "scmatrix.hxx" #include "scmatrix.hxx"
...@@ -266,6 +267,11 @@ public: ...@@ -266,6 +267,11 @@ public:
void testAnchoredRotatedShape(); void testAnchoredRotatedShape();
void testCellTextWidth(); void testCellTextWidth();
/**
* Test formula & formula grouping
*/
void testFormulaGrouping();
CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testCollator); CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testRangeList); CPPUNIT_TEST(testRangeList);
...@@ -328,6 +334,7 @@ public: ...@@ -328,6 +334,7 @@ public:
CPPUNIT_TEST(testDeleteCol); CPPUNIT_TEST(testDeleteCol);
CPPUNIT_TEST(testAnchoredRotatedShape); CPPUNIT_TEST(testAnchoredRotatedShape);
CPPUNIT_TEST(testCellTextWidth); CPPUNIT_TEST(testCellTextWidth);
CPPUNIT_TEST(testFormulaGrouping);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
...@@ -6174,6 +6181,57 @@ void Test::testCellTextWidth() ...@@ -6174,6 +6181,57 @@ void Test::testCellTextWidth()
m_pDoc->DeleteTab(0); m_pDoc->DeleteTab(0);
} }
void Test::testFormulaGrouping()
{
static const struct {
const char *pFormula[3];
const bool bGroup[3];
} aGroupTests[] = {
{ { "=B1", "=C1", "" }, // single increments
{ true, true, false } },
{ { "=B1", "=D1", "=F1" }, // tripple increments
{ true, true, true } },
{ { "=B1", "", "=C1" }, // a gap
{ false, false, false } },
{ { "=B1", "=C1+3", "=C1+D1" }, // confusion: FIXME: =C1+7
{ false, false, false } },
};
m_pDoc->InsertTab( 0, "sheet" );
for (size_t i = 0; i < SAL_N_ELEMENTS( aGroupTests ); i++)
{
for (size_t j = 0; j < SAL_N_ELEMENTS( aGroupTests[0].pFormula ); j++)
{
OUString aFormula = OUString::createFromAscii(aGroupTests[i].pFormula[j]);
m_pDoc->SetString(0, (SCROW)j, 0, aFormula);
}
m_pDoc->RebuildFormulaGroups();
for (size_t j = 0; j < SAL_N_ELEMENTS( aGroupTests[0].pFormula ); j++)
{
ScBaseCell *pCell = NULL;
m_pDoc->GetCell( 0, (SCROW)j, 0, pCell );
if( !pCell )
{
CPPUNIT_ASSERT_MESSAGE("invalid empty cell", !aGroupTests[i].bGroup[j]);
continue;
}
CPPUNIT_ASSERT_MESSAGE("Cell expected, but not there.", pCell != NULL);
CPPUNIT_ASSERT_MESSAGE("Cell wrong type.",
pCell->GetCellType() == CELLTYPE_FORMULA);
ScFormulaCell *pCur = static_cast< ScFormulaCell *>( pCell );
if( !!pCur->GetCellGroup().get() ^ aGroupTests[i].bGroup[j] )
{
printf("expected group test %d at row %d to be %d but is %d\n",
i, j, !!pCur->GetCellGroup().get(), aGroupTests[i].bGroup[j]);
CPPUNIT_ASSERT_MESSAGE("Failed", false);
}
}
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_TEST_SUITE_REGISTRATION(Test);
} }
......
...@@ -1752,11 +1752,15 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell ) ...@@ -1752,11 +1752,15 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
fprintf( stderr, "Incompatible type, op-code or param counts\n" ); fprintf( stderr, "Incompatible type, op-code or param counts\n" );
return NULL; return NULL;
} }
if( pThis[ i ]->GetType() == formula::svMatrix || switch( pThis[ i ]->GetType() )
pOther[ i ]->GetType() == formula::svMatrix )
{ {
fprintf( stderr, "Ignoring matrix formulae for now\n" ); case formula::svMatrix:
case formula::svExternalSingleRef:
case formula::svExternalDoubleRef:
fprintf( stderr, "Ignoring matrix and external references for now\n" );
return NULL; return NULL;
default:
break;
} }
} }
...@@ -1765,6 +1769,10 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell ) ...@@ -1765,6 +1769,10 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
for ( sal_uInt16 i = 0; i < pThisLen; i++ ) for ( sal_uInt16 i = 0; i < pThisLen; i++ )
{ {
if ( pThis[i]->GetType() != formula::svSingleRef &&
pThis[i]->GetType() != formula::svDoubleRef )
continue;
ScToken *pThisTok = static_cast< ScToken * >( pThis[ i ] ); ScToken *pThisTok = static_cast< ScToken * >( pThis[ i ] );
ScToken *pOtherTok = static_cast< ScToken * >( pOther[ i ] ); ScToken *pOtherTok = static_cast< ScToken * >( pOther[ i ] );
......
...@@ -2036,7 +2036,6 @@ void ScColumn::RebuildFormulaGroups() ...@@ -2036,7 +2036,6 @@ void ScColumn::RebuildFormulaGroups()
ScFormulaCell *pCur = static_cast< ScFormulaCell *>( rCur.pCell ); ScFormulaCell *pCur = static_cast< ScFormulaCell *>( rCur.pCell );
ScFormulaCell *pPrev = static_cast< ScFormulaCell *>( rPrev.pCell ); ScFormulaCell *pPrev = static_cast< ScFormulaCell *>( rPrev.pCell );
#ifdef BUILD_FORMULA_GROUPS
fprintf( stderr, "column has contiguous formulae\n" ); fprintf( stderr, "column has contiguous formulae\n" );
ScSimilarFormulaDelta *pDelta = pPrev->BuildDeltaTo( pCur ); ScSimilarFormulaDelta *pDelta = pPrev->BuildDeltaTo( pCur );
...@@ -2081,9 +2080,6 @@ void ScColumn::RebuildFormulaGroups() ...@@ -2081,9 +2080,6 @@ void ScColumn::RebuildFormulaGroups()
pCur->ReleaseDelta( pDelta ); pCur->ReleaseDelta( pDelta );
} }
#else
(void)pCur; (void) pPrev;
#endif
} }
bDirtyGroups = false; bDirtyGroups = false;
......
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