diff options
author | László Németh <laszlo.nemeth@collabora.com> | 2015-02-19 15:16:43 +0100 |
---|---|---|
committer | László Németh <laszlo.nemeth@collabora.com> | 2015-02-19 15:24:18 +0100 |
commit | d619d23a1f641fc910723cc32c4d8c8d9a8f3681 (patch) | |
tree | 43135f9341307631b3b339a315fb18e38ee1f0e4 | |
parent | bdd4e1957fcdef591acac4ce3a7f6fd4f83380c4 (diff) |
tdf#89436 add unit test for ScHorizontalAttrIterator
+ OSL_ENSURE to check row-level buffering of the horizontal
cell ranges with the same cell attributes
Change-Id: If265e1c5a389d4c63bfda4017173d8fe41badb6b
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 34 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/dociter.cxx | 4 |
3 files changed, 40 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 5883bf983aef..b200c1e09eab 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1224,6 +1224,40 @@ void Test::testValueIterator() m_pDoc->DeleteTab(0); } +void Test::testHorizontalAttrIterator() +{ + m_pDoc->InsertTab(0, "Test"); + + // Set the background color of B2:C3 to blue + ScPatternAttr aCellBackColor(m_pDoc->GetPool()); + aCellBackColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND)); + m_pDoc->ApplyPatternAreaTab(1, 1, 2, 2, 0, aCellBackColor); + + // some numeric data + for (SCCOL i = 1; i <= 4; ++i) + for (SCCOL j = 1; j <= 4; ++j) + m_pDoc->SetValue(ScAddress(i,j,0), i*10+j); + + { + const int aChecks[][3] = { {1, 2, 1}, {1, 2, 2} }; + size_t nCheckLen = SAL_N_ELEMENTS(aChecks); + + ScHorizontalAttrIterator aIter(m_pDoc, 0, 0, 0, 3, 3); + SCCOL rCol1, rCol2; + SCROW rRow; + size_t nCheckPos = 0; + for (const ScPatternAttr* pAttr = aIter.GetNext(rCol1, rCol2, rRow); pAttr; pAttr = aIter.GetNext(rCol1, rCol2, rRow), ++nCheckPos) + { + CPPUNIT_ASSERT_MESSAGE("Iteration longer than expected.", nCheckPos < nCheckLen); + CPPUNIT_ASSERT_EQUAL(aChecks[nCheckPos][0], static_cast<int>(rCol1)); + CPPUNIT_ASSERT_EQUAL(aChecks[nCheckPos][1], static_cast<int>(rCol2)); + CPPUNIT_ASSERT_EQUAL(aChecks[nCheckPos][2], static_cast<int>(rRow)); + } + } + + m_pDoc->DeleteTab(0); +} + namespace { bool broadcasterShifted(const ScDocument& rDoc, const ScAddress& rFrom, const ScAddress& rTo) diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 9edafa0b669c..1937e4a25004 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -187,6 +187,7 @@ public: void testHorizontalIterator(); void testValueIterator(); + void testHorizontalAttrIterator(); /** * Basic test for formula dependency tracking. @@ -496,6 +497,7 @@ public: CPPUNIT_TEST(testFuncNOW); CPPUNIT_TEST(testHorizontalIterator); CPPUNIT_TEST(testValueIterator); + CPPUNIT_TEST(testHorizontalAttrIterator); CPPUNIT_TEST(testFormulaDepTracking); CPPUNIT_TEST(testFormulaDepTracking2); CPPUNIT_TEST(testFormulaDepTracking3); diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index cf8cbe25358c..168f9294c223 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -2266,6 +2266,7 @@ ScHorizontalAttrIterator::ScHorizontalAttrIterator( ScDocument* pDocument, SCTAB pIndices[nPos] = nIndex; pNextEnd[nPos] = nThisEnd; + pPrevColEnd[nPos] = MAXCOL+1; // only for OSL_ENSURE ppPatterns[nPos] = pPattern; } @@ -2301,7 +2302,10 @@ const ScPatternAttr* ScHorizontalAttrIterator::GetNext( SCCOL& rCol1, SCCOL& rCo rRow = nRow; rCol1 = nCol; if ( bRepeatedRow ) + { + OSL_ENSURE( pPrevColEnd[nCol-nStartCol] < MAXCOL+1, "missing stored data" ); nCol = pPrevColEnd[nCol-nStartCol]; // use the result stored before + } else { while ( nCol < nEndCol && ( ppPatterns[nCol+1-nStartCol] == pPat) ) |