summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/qa/unit/ucalc.cxx19
-rw-r--r--sc/source/core/data/column3.cxx28
2 files changed, 36 insertions, 11 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 72e25f2f5b91..32db14e20be2 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -613,14 +613,22 @@ void Test::testDataEntries()
m_pDoc->SetString(ScAddress(0,5,0), "Andy");
m_pDoc->SetString(ScAddress(0,6,0), "Bruce");
m_pDoc->SetString(ScAddress(0,7,0), "Charlie");
+ m_pDoc->SetValue(ScAddress(0,8,0), 100);
+ m_pDoc->SetValue(ScAddress(0,9,0), 200);
m_pDoc->SetString(ScAddress(0,10,0), "Andy");
+ m_pDoc->SetValue(ScAddress(0,11,0), 1000);
std::vector<ScTypedStrData> aEntries;
- m_pDoc->GetDataEntries(0, 0, 0, aEntries); // Try at the very top.
+ m_pDoc->GetDataEntries(0, 0, 0, aEntries); // Try at the top.
+ std::vector<ScTypedStrData>::const_iterator it = aEntries.begin();
+ CPPUNIT_ASSERT_MESSAGE("The entries should be empty.", bool(it == aEntries.end()));
+
+ aEntries.clear();
+ m_pDoc->GetDataEntries(0, 4, 0, aEntries); // Try at A5.
// Entries are supposed to be sorted in ascending order, and are all unique.
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aEntries.size());
- std::vector<ScTypedStrData>::const_iterator it = aEntries.begin();
+ it = aEntries.begin();
CPPUNIT_ASSERT_EQUAL(OUString("Andy"), it->GetString());
++it;
CPPUNIT_ASSERT_EQUAL(OUString("Bruce"), it->GetString());
@@ -630,7 +638,7 @@ void Test::testDataEntries()
CPPUNIT_ASSERT_MESSAGE("The entries should have ended here.", bool(it == aEntries.end()));
aEntries.clear();
- m_pDoc->GetDataEntries(0, MAXROW, 0, aEntries); // Try at the very bottom.
+ m_pDoc->GetDataEntries(0, 12, 0, aEntries); // Try at A13.
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aEntries.size());
// Make sure we get the same set of suggestions.
@@ -643,6 +651,11 @@ void Test::testDataEntries()
++it;
CPPUNIT_ASSERT_MESSAGE("The entries should have ended here.", bool(it == aEntries.end()));
+ aEntries.clear();
+ m_pDoc->GetDataEntries(0, MAXROW, 0, aEntries); // Try at the bottom.
+ it = aEntries.begin();
+ CPPUNIT_ASSERT_MESSAGE("The entries should be empty.", bool(it == aEntries.end()));
+
m_pDoc->DeleteTab(0);
}
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index eef630c6f297..51bc475d135f 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2585,6 +2585,11 @@ public:
return (maPos.first->type == sc::element_type_string || maPos.first->type == sc::element_type_edittext);
}
+ bool isEmpty() const
+ {
+ return maPos.first->type == sc::element_type_empty;
+ }
+
bool prev()
{
if (!has())
@@ -2592,7 +2597,7 @@ public:
// Not in a string block. Move back until we hit a string block.
while (!has())
{
- if (maPos.first == miBeg)
+ if (isEmpty() || maPos.first == miBeg)
return false;
--maPos.first; // move to the preceding block.
@@ -2618,6 +2623,10 @@ public:
// Move to the last cell of the previous block.
--maPos.first;
maPos.second = maPos.first->size - 1;
+
+ if (isEmpty())
+ return false;
+
if (has())
break;
}
@@ -2632,6 +2641,9 @@ public:
// Not in a string block. Move forward until we hit a string block.
while (!has())
{
+ if (isEmpty())
+ return false;
+
++maPos.first;
if (maPos.first == miEnd)
return false;
@@ -2653,6 +2665,10 @@ public:
return false;
maPos.second = 0;
+
+ if (isEmpty())
+ return false;
+
if (has())
break;
}
@@ -2694,16 +2710,12 @@ bool ScColumn::GetDataEntries(
// going upward and downward directions in parallel. The start position
// cell must be skipped.
- StrCellIterator aItrUp(maCells, nStartRow, &GetDoc());
+ StrCellIterator aItrUp(maCells, nStartRow-1, &GetDoc());
StrCellIterator aItrDown(maCells, nStartRow+1, &GetDoc());
bool bMoveUp = aItrUp.valid();
- if (!bMoveUp)
- // Current cell is invalid.
- return false;
-
- // Skip the start position cell.
- bMoveUp = aItrUp.prev(); // Find the previous string cell position.
+ if (bMoveUp && !aItrUp.has())
+ bMoveUp = aItrUp.prev(); // Find the previous string cell position.
bool bMoveDown = aItrDown.valid();
if (bMoveDown && !aItrDown.has())