summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/qa/unit/ucalc.cxx58
-rw-r--r--sc/source/core/data/cell2.cxx14
-rw-r--r--sc/source/core/data/column3.cxx4
3 files changed, 69 insertions, 7 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 3e9a14d9fe4e..f53089058064 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -33,6 +33,7 @@
#include <osl/file.hxx>
#include "scdll.hxx"
+#include "cell.hxx"
#include "document.hxx"
#include "stringutil.hxx"
#include "scmatrix.hxx"
@@ -266,6 +267,11 @@ public:
void testAnchoredRotatedShape();
void testCellTextWidth();
+ /**
+ * Test formula & formula grouping
+ */
+ void testFormulaGrouping();
+
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testRangeList);
@@ -328,6 +334,7 @@ public:
CPPUNIT_TEST(testDeleteCol);
CPPUNIT_TEST(testAnchoredRotatedShape);
CPPUNIT_TEST(testCellTextWidth);
+ CPPUNIT_TEST(testFormulaGrouping);
CPPUNIT_TEST_SUITE_END();
private:
@@ -6174,6 +6181,57 @@ void Test::testCellTextWidth()
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);
}
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index 4cb4eb8fcae2..db14d580b2af 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -1752,11 +1752,15 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
fprintf( stderr, "Incompatible type, op-code or param counts\n" );
return NULL;
}
- if( pThis[ i ]->GetType() == formula::svMatrix ||
- pOther[ i ]->GetType() == formula::svMatrix )
+ switch( pThis[ i ]->GetType() )
{
- 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;
+ default:
+ break;
}
}
@@ -1765,6 +1769,10 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
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 *pOtherTok = static_cast< ScToken * >( pOther[ i ] );
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index d288625a318a..5ddb3f1287ff 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2036,7 +2036,6 @@ void ScColumn::RebuildFormulaGroups()
ScFormulaCell *pCur = static_cast< ScFormulaCell *>( rCur.pCell );
ScFormulaCell *pPrev = static_cast< ScFormulaCell *>( rPrev.pCell );
-#ifdef BUILD_FORMULA_GROUPS
fprintf( stderr, "column has contiguous formulae\n" );
ScSimilarFormulaDelta *pDelta = pPrev->BuildDeltaTo( pCur );
@@ -2081,9 +2080,6 @@ void ScColumn::RebuildFormulaGroups()
pCur->ReleaseDelta( pDelta );
}
-#else
- (void)pCur; (void) pPrev;
-#endif
}
bDirtyGroups = false;