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

Kohei Yoshida kohei.yoshida at collabora.com
Fri May 9 19:20:15 PDT 2014


 sc/qa/unit/ucalc.cxx            |   44 +++++++++++++++++++++++++++++++++-------
 sc/source/core/data/column3.cxx |   43 +++++++++++++++++++++++----------------
 2 files changed, 63 insertions(+), 24 deletions(-)

New commits:
commit 83a88b942134314e86ac612d0ef70a8e4919e4af
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri May 9 22:19:15 2014 -0400

    fdo#77056: Treat empty cells as if they have a value of 0.0.
    
    Change-Id: Ibe64cf7177a5298c1878e0014c049dc9c82b1344

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 8bb8223..5db4625 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1158,6 +1158,23 @@ class MixDataHandler
 
     bool mbSkipEmpty;
 
+    void doFunction( size_t nDestRow, double fVal1, double fVal2 )
+    {
+        bool bOk = lcl_DoFunction(fVal1, fVal2, mnFunction);
+
+        if (bOk)
+            miNewCellsPos = maNewCells.set(miNewCellsPos, nDestRow-mnRowOffset, fVal1);
+        else
+        {
+            ScAddress aPos(mrDestColumn.GetCol(), nDestRow, mrDestColumn.GetTab());
+
+            ScFormulaCell* pFC = new ScFormulaCell(&mrDestColumn.GetDoc(), aPos);
+            pFC->SetErrCode(errNoValue);
+
+            miNewCellsPos = maNewCells.set(miNewCellsPos, nDestRow-mnRowOffset, pFC);
+        }
+    }
+
 public:
     MixDataHandler(
         sc::ColumnBlockPosition& rBlockPos,
@@ -1180,22 +1197,15 @@ public:
         mrBlockPos.miCellPos = aPos.first;
         switch (aPos.first->type)
         {
+            case sc::element_type_empty:
             case sc::element_type_numeric:
             {
-                // Both src and dest are of numeric type.
-                bool bOk = lcl_DoFunction(f, sc::numeric_block::at(*aPos.first->data, aPos.second), mnFunction);
-
-                if (bOk)
-                    miNewCellsPos = maNewCells.set(miNewCellsPos, nRow-mnRowOffset, f);
-                else
-                {
-                    ScFormulaCell* pFC =
-                        new ScFormulaCell(
-                            &mrDestColumn.GetDoc(), ScAddress(mrDestColumn.GetCol(), nRow, mrDestColumn.GetTab()));
+                double fSrcVal = 0.0;
+                if (aPos.first->type == sc::element_type_numeric)
+                    fSrcVal = sc::numeric_block::at(*aPos.first->data, aPos.second);
 
-                    pFC->SetErrCode(errNoValue);
-                    miNewCellsPos = maNewCells.set(miNewCellsPos, nRow-mnRowOffset, pFC);
-                }
+                // Both src and dest are of numeric type.
+                doFunction(nRow, f, fSrcVal);
             }
             break;
             case sc::element_type_formula:
@@ -1229,7 +1239,6 @@ public:
             break;
             case sc::element_type_string:
             case sc::element_type_edittext:
-            case sc::element_type_empty:
             {
                 // Destination cell is not a number. Just take the source cell.
                 miNewCellsPos = maNewCells.set(miNewCellsPos, nRow-mnRowOffset, f);
@@ -1346,9 +1355,9 @@ public:
             {
                 case sc::element_type_numeric:
                 {
-                    double fVal = sc::numeric_block::at(*aPos.first->data, aPos.second);
-                    miNewCellsPos = maNewCells.set(
-                            miNewCellsPos, nDestRow-mnRowOffset, fVal);
+                    double fVal1 = 0.0;
+                    double fVal2 = sc::numeric_block::at(*aPos.first->data, aPos.second);
+                    doFunction(nDestRow, fVal1, fVal2);
                 }
                 break;
                 case sc::element_type_string:
commit b44f8185398ff6835a71fe237089746fca7f999d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri May 9 22:18:14 2014 -0400

    fdo#77056: Modify existing test to cover the reported scenario.
    
    Change-Id: I6d0fe13e6756d8b6c3e7ac9ffba828e3f9c2a7b5

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 4cf444f..4a9fb2f 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6089,19 +6089,49 @@ void Test::testMixData()
 {
     m_pDoc->InsertTab(0, "Test");
 
-    m_pDoc->SetValue(1,0,0,2);
-    m_pDoc->SetValue(0,1,0,3);
+    m_pDoc->SetValue(ScAddress(1,0,0), 2.0); // B1
+    m_pDoc->SetValue(ScAddress(0,1,0), 3.0); // A2
+
+    // Copy A1:B1 to the clip document.
     ScDocument aClipDoc(SCDOCMODE_CLIP);
-    copyToClip(m_pDoc, ScRange(0,0,0,1,0,0), &aClipDoc);
+    copyToClip(m_pDoc, ScRange(0,0,0,1,0,0), &aClipDoc); // A1:B1
 
+    // Copy A2:B2 to the mix document (for arithemetic paste).
     ScDocument aMixDoc(SCDOCMODE_CLIP);
-    copyToClip(m_pDoc, ScRange(0,1,0,1,1,0), &aMixDoc);
+    copyToClip(m_pDoc, ScRange(0,1,0,1,1,0), &aMixDoc); // A2:B2
 
+    // Paste A1:B1 to A2:B2 and perform addition.
     pasteFromClip(m_pDoc, ScRange(0,1,0,1,1,0), &aClipDoc);
-    m_pDoc->MixDocument(ScRange(0,1,0,1,1,0), 1, false, &aMixDoc);
+    m_pDoc->MixDocument(ScRange(0,1,0,1,1,0), PASTE_ADD, false, &aMixDoc);
+
+    CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(0,1,0)); // A2
+    CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(1,1,0)); // B2
+
+    // Clear everything and start over.
+    clearSheet(m_pDoc, 0);
+    clearSheet(&aClipDoc, 0);
+    clearSheet(&aMixDoc, 0);
+
+    // Set values to A1, A2, and B1.  B2 will remain empty.
+    m_pDoc->SetValue(ScAddress(0,0,0), 15.0);
+    m_pDoc->SetValue(ScAddress(0,1,0), 16.0);
+    m_pDoc->SetValue(ScAddress(1,0,0), 12.0);
+    CPPUNIT_ASSERT_MESSAGE("B2 should be empty.", m_pDoc->GetCellType(ScAddress(1,1,0)) == CELLTYPE_NONE);
+
+    // Copy A1:A2 and paste it onto B1:B2 with subtraction operation.
+    copyToClip(m_pDoc, ScRange(0,0,0,0,1,0), &aClipDoc);
+    CPPUNIT_ASSERT_EQUAL(m_pDoc->GetValue(ScAddress(0,0,0)), aClipDoc.GetValue(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL(m_pDoc->GetValue(ScAddress(0,1,0)), aClipDoc.GetValue(ScAddress(0,1,0)));
+
+    copyToClip(m_pDoc, ScRange(1,0,0,1,1,0), &aMixDoc);
+    CPPUNIT_ASSERT_EQUAL(m_pDoc->GetValue(ScAddress(1,0,0)), aMixDoc.GetValue(ScAddress(1,0,0)));
+    CPPUNIT_ASSERT_EQUAL(m_pDoc->GetValue(ScAddress(1,1,0)), aMixDoc.GetValue(ScAddress(1,1,0)));
+
+    pasteFromClip(m_pDoc, ScRange(1,0,0,1,1,0), &aClipDoc);
+    m_pDoc->MixDocument(ScRange(1,0,0,1,1,0), PASTE_SUB, false, &aMixDoc);
 
-    CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(1,1,0));
-    CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(0,1,0));
+    CPPUNIT_ASSERT_EQUAL( -3.0, m_pDoc->GetValue(ScAddress(1,0,0))); // 12 - 15
+    CPPUNIT_ASSERT_EQUAL(-16.0, m_pDoc->GetValue(ScAddress(1,1,0))); //  0 - 16
 
     m_pDoc->DeleteTab(0);
 }


More information about the Libreoffice-commits mailing list