sc/qa/unit/ucalc.cxx | 45 ++++++++++++++++++++++++++++++++++++++- sc/source/core/tool/scmatrix.cxx | 4 +++ 2 files changed, 48 insertions(+), 1 deletion(-)
New commits: commit 3c59183f5bfa22194f0287b449aaa6d882be8827 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Thu Jul 11 13:26:04 2013 -0400 Add test case for matrix's double array handling & fix one bug. Change-Id: I6cb2ff8bf536ccb53ae9f146baf6aa582f9fbcfe diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 6d2d0fc..5c3ec7b 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -2145,7 +2145,7 @@ struct PartiallyFilledEmptyMatrix void Test::testMatrix() { - ScMatrixRef pMat; + ScMatrixRef pMat, pMat2; // First, test the zero matrix type. pMat = new ScMatrix(0, 0, 0.0); @@ -2226,6 +2226,49 @@ void Test::testMatrix() pMat->PutDouble(12.5, 1, 1); CPPUNIT_ASSERT_EQUAL(0.0, pMat->GetMinValue(false)); CPPUNIT_ASSERT_EQUAL(12.5, pMat->GetMaxValue(false)); + + // Convert matrix into a linear double array. String elements become NaN + // and empty elements become 0. + pMat = new ScMatrix(3, 3); + pMat->PutDouble(2.5, 0, 0); + pMat->PutDouble(1.2, 0, 1); + pMat->PutString("A", 1, 1); + pMat->PutDouble(2.3, 2, 1); + pMat->PutDouble(-20, 2, 2); + + double fNaN; + rtl::math::setNan(&fNaN); + + std::vector<double> aDoubles; + pMat->GetDoubleArray(aDoubles); + + { + const double pChecks[] = { 2.5, 1.2, 0, 0, fNaN, 0, 0, 2.3, -20 }; + CPPUNIT_ASSERT_EQUAL(SAL_N_ELEMENTS(pChecks), aDoubles.size()); + for (size_t i = 0, n = aDoubles.size(); i < n; ++i) + { + if (rtl::math::isNan(pChecks[i])) + CPPUNIT_ASSERT_MESSAGE("NaN is expected, but it's not.", rtl::math::isNan(aDoubles[i])); + else + CPPUNIT_ASSERT_EQUAL(pChecks[i], aDoubles[i]); + } + } + + pMat2 = new ScMatrix(3, 3, 10.0); + pMat2->PutString("B", 1, 0); + pMat2->MergeDoubleArray(aDoubles, ScMatrix::Mul); + + { + const double pChecks[] = { 25, 12, 0, fNaN, fNaN, 0, 0, 23, -200 }; + CPPUNIT_ASSERT_EQUAL(SAL_N_ELEMENTS(pChecks), aDoubles.size()); + for (size_t i = 0, n = aDoubles.size(); i < n; ++i) + { + if (rtl::math::isNan(pChecks[i])) + CPPUNIT_ASSERT_MESSAGE("NaN is expected, but it's not.", rtl::math::isNan(aDoubles[i])); + else + CPPUNIT_ASSERT_EQUAL(pChecks[i], aDoubles[i]); + } + } } void Test::testEnterMixedMatrix() diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index c692238..73ed2e2 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -1063,6 +1063,8 @@ public: *miPos = mfNaN; } break; + case mdds::mtm::element_empty: + std::advance(miPos, node.size); default: ; } @@ -1133,6 +1135,8 @@ public: *miPos = mfNaN; } break; + case mdds::mtm::element_empty: + std::advance(miPos, node.size); default: ; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits