[Libreoffice-commits] core.git: 2 commits - sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Sun Feb 9 08:31:37 PST 2014


 sc/qa/unit/ucalc.hxx             |    2 ++
 sc/qa/unit/ucalc_formula.cxx     |   25 +++++++++++++++++++++++++
 sc/source/core/tool/scmatrix.cxx |   11 ++++++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)

New commits:
commit 295869ce95c00a0e0b192ea6bf62753f91badaf2
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Feb 9 11:34:11 2014 -0500

    fdo#74479: Treat empty cells as if they have a value of 0.
    
    Change-Id: I3701848016c230138e8791f683a2c8b97219198d

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 74f7fa3..090cada 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1612,7 +1612,16 @@ public:
             }
             break;
             case mdds::mtm::element_empty:
-                std::advance(miPos, node.size);
+            {
+                // Empty element is equivalent of having a numeric value of 0.0.
+                for (size_t i = 0; i < node.size; ++i, ++miPos)
+                {
+                    if (rtl::math::isNan(*miPos))
+                        continue;
+
+                    *miPos = op(*miPos, 0.0);
+                }
+            }
             default:
                 ;
         }
commit 71fe47cfe652829ff7dc09ae49b1c6c22d9b6a6d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Feb 9 11:10:34 2014 -0500

    fdo#74479: Test case for SUMPRODUCT.
    
    Change-Id: I2e8669c1cd6c824751d557c7c9ee735d580f17e9

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 053e607..a32b048 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -115,6 +115,7 @@ public:
     void testFuncROW();
     void testFuncSUM();
     void testFuncPRODUCT();
+    void testFuncSUMPRODUCT();
     void testFuncN();
     void testFuncCOUNTIF();
     void testFuncNUMBERVALUE();
@@ -347,6 +348,7 @@ public:
     CPPUNIT_TEST(testFuncROW);
     CPPUNIT_TEST(testFuncSUM);
     CPPUNIT_TEST(testFuncPRODUCT);
+    CPPUNIT_TEST(testFuncSUMPRODUCT);
     CPPUNIT_TEST(testFuncN);
     CPPUNIT_TEST(testFuncCOUNTIF);
     CPPUNIT_TEST(testFuncNUMBERVALUE);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 05ff6b6..a4b6289 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1790,6 +1790,31 @@ void Test::testFuncPRODUCT()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testFuncSUMPRODUCT()
+{
+    m_pDoc->InsertTab(0, "Test");
+
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto recalc.
+
+    ScAddress aPos(0,0,0);
+    m_pDoc->SetString(aPos, "=SUMPRODUCT(B1:B3;C1:C3)");
+    CPPUNIT_ASSERT_EQUAL(0.0,  m_pDoc->GetValue(aPos));
+    m_pDoc->SetValue(ScAddress(2,0,0),  1.0); // C1
+    CPPUNIT_ASSERT_EQUAL(0.0,  m_pDoc->GetValue(aPos));
+    m_pDoc->SetValue(ScAddress(1,0,0),  1.0); // B1
+    CPPUNIT_ASSERT_EQUAL(1.0,  m_pDoc->GetValue(aPos));
+    m_pDoc->SetValue(ScAddress(1,1,0),  2.0); // B2
+    CPPUNIT_ASSERT_EQUAL(1.0,  m_pDoc->GetValue(aPos));
+    m_pDoc->SetValue(ScAddress(2,1,0),  3.0); // C2
+    CPPUNIT_ASSERT_EQUAL(7.0,  m_pDoc->GetValue(aPos));
+    m_pDoc->SetValue(ScAddress(2,2,0), -2.0); // C3
+    CPPUNIT_ASSERT_EQUAL(7.0,  m_pDoc->GetValue(aPos));
+    m_pDoc->SetValue(ScAddress(1,2,0),  5.0); // B3
+    CPPUNIT_ASSERT_EQUAL(-3.0, m_pDoc->GetValue(aPos));
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testFuncN()
 {
     OUString aTabName("foo");


More information about the Libreoffice-commits mailing list