[Libreoffice-commits] core.git: sc/qa sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Tue Nov 8 14:25:31 UTC 2016
sc/qa/unit/ucalc_formula.cxx | 37 +++++++++++++++++++++++++++++++++++++
sc/source/core/data/column2.cxx | 21 ++++++++++++++-------
2 files changed, 51 insertions(+), 7 deletions(-)
New commits:
commit 2573f6bba6b3033143b776650f03fd4813669e5b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Nov 7 22:43:10 2016 -0500
Ensure that the string array is null when no strings present.
It was intended this way from day one, but the implementation
didn't live up to that promise...
Change-Id: I231ddc8923fdd8a205127c6a3214dd93f13378b9
Reviewed-on: https://gerrit.libreoffice.org/30678
Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>
Tested-by: Kohei Yoshida <libreoffice at kohei.us>
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index b572c54..cb4b3f4 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -736,6 +736,43 @@ void Test::testFetchVectorRefArray()
CPPUNIT_ASSERT(rtl::math::isNan(aArray.mpNumericArray[1]));
CPPUNIT_ASSERT(rtl::math::isNan(aArray.mpNumericArray[2]));
+ // The column begins with a string header at row 1 (Column C).
+ m_pDoc->SetString(ScAddress(2,0,0), "MyHeader");
+ for (SCROW i = 1; i <= 9; ++i) // rows 2-10 are numeric.
+ m_pDoc->SetValue(ScAddress(2,i,0), i);
+
+ aArray = m_pDoc->FetchVectorRefArray(ScAddress(2,1,0), 9); // C2:C10
+ CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray);
+ CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray);
+ for (size_t i = 0; i < 9; ++i)
+ CPPUNIT_ASSERT_EQUAL(double(i+1), aArray.mpNumericArray[i]);
+
+ // The column begins with a number, followed by a string then followed by
+ // a block of numbers (Column D).
+ m_pDoc->SetValue(ScAddress(3,0,0), 0.0);
+ m_pDoc->SetString(ScAddress(3,1,0), "Some string");
+ for (SCROW i = 2; i <= 9; ++i) // rows 3-10 are numeric.
+ m_pDoc->SetValue(ScAddress(3,i,0), i);
+
+ aArray = m_pDoc->FetchVectorRefArray(ScAddress(3,2,0), 8); // D3:D10
+ CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray);
+ CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray);
+ for (size_t i = 0; i < 8; ++i)
+ CPPUNIT_ASSERT_EQUAL(double(i+2), aArray.mpNumericArray[i]);
+
+ // The column begins with a formula, followed by a string then followed by
+ // a block of numbers (Column E).
+ m_pDoc->SetString(ScAddress(4,0,0), "=1*2");
+ m_pDoc->SetString(ScAddress(4,1,0), "Some string");
+ for (SCROW i = 2; i <= 9; ++i) // rows 3-10 are numeric.
+ m_pDoc->SetValue(ScAddress(4,i,0), i*2);
+
+ aArray = m_pDoc->FetchVectorRefArray(ScAddress(4,2,0), 8); // E3:E10
+ CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray);
+ CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray);
+ for (size_t i = 0; i < 8; ++i)
+ CPPUNIT_ASSERT_EQUAL(double((i+2)*2), aArray.mpNumericArray[i]);
+
m_pDoc->DeleteTab(0);
}
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index c5e136b..581607e 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2628,10 +2628,11 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
if (!appendToBlock(pDocument, rCxt, *pColArray, nPos, nRow2+1, itBlk, maCells.end()))
return formula::VectorRefArray(formula::VectorRefArray::Invalid);
- if (pColArray->mpStrArray)
- return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], &(*pColArray->mpStrArray)[nRow1]);
- else
- return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1]);
+ rtl_uString** pStr = nullptr;
+ if (pColArray->mpStrArray && hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2))
+ pStr = &(*pColArray->mpStrArray)[nRow1];
+
+ return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], pStr);
}
break;
case sc::element_type_string:
@@ -2660,10 +2661,16 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
if (!appendToBlock(pDocument, rCxt, *pColArray, nPos, nRow2+1, itBlk, maCells.end()))
return formula::VectorRefArray(formula::VectorRefArray::Invalid);
+ assert(pColArray->mpStrArray);
+
+ rtl_uString** pStr = nullptr;
+ if (hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2))
+ pStr = &(*pColArray->mpStrArray)[nRow1];
+
if (pColArray->mpNumArray)
- return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], &(*pColArray->mpStrArray)[nRow1]);
+ return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], pStr);
else
- return formula::VectorRefArray(&(*pColArray->mpStrArray)[nRow1]);
+ return formula::VectorRefArray(pStr);
}
break;
case sc::element_type_formula:
@@ -2701,7 +2708,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
rtl_uString** pStr = nullptr;
if (pColArray->mpNumArray)
pNum = &(*pColArray->mpNumArray)[nRow1];
- if (pColArray->mpStrArray)
+ if (pColArray->mpStrArray && hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2))
pStr = &(*pColArray->mpStrArray)[nRow1];
return formula::VectorRefArray(pNum, pStr);
More information about the Libreoffice-commits
mailing list