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

Eike Rathke erack at redhat.com
Thu Jan 15 08:28:12 PST 2015


 sc/inc/sharedformula.hxx              |    5 ++++
 sc/qa/unit/ucalc.cxx                  |   13 ++++++++++
 sc/qa/unit/ucalc.hxx                  |    2 +
 sc/qa/unit/ucalc_sharedformula.cxx    |   41 ++++++++++++++++++++++++++++++++++
 sc/source/core/tool/sharedformula.cxx |    2 -
 5 files changed, 61 insertions(+), 2 deletions(-)

New commits:
commit 1a2b8b2358fe5954a5c3960c9a48467de3dc5ba8
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Jan 14 23:37:43 2015 +0100

    add unit test for fdo#88398
    
    Check that grouped area listeners aren't discarded when unsharing a
    grouped formula.
    
    Change-Id: Ic3d3e9acb5b97d927a85ca433de127dd3b74a30c

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 6f6af6b..867b275 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -329,6 +329,7 @@ public:
     void testSharedFormulaUpdateOnNamedRangeChange();
     void testSharedFormulaUpdateOnDBChange();
     void testSharedFormulaAbsCellListener();
+    void testSharedFormulaUnshareAreaListeners();
     void testFormulaPosition();
 
     void testMixData();
@@ -568,6 +569,7 @@ public:
     CPPUNIT_TEST(testSharedFormulaUpdateOnNamedRangeChange);
     CPPUNIT_TEST(testSharedFormulaUpdateOnDBChange);
     CPPUNIT_TEST(testSharedFormulaAbsCellListener);
+    CPPUNIT_TEST(testSharedFormulaUnshareAreaListeners);
     CPPUNIT_TEST(testFormulaPosition);
     CPPUNIT_TEST(testMixData);
     CPPUNIT_TEST(testJumpToPrecedentsDependents);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 36fb824..0cc63e5 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -1702,4 +1702,35 @@ void Test::testSharedFormulaAbsCellListener()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testSharedFormulaUnshareAreaListeners()
+{
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+
+    m_pDoc->InsertTab(0, "Test");
+
+    const char* pData[][2] = {
+        { "=SUM(B1:B2)", "1" },
+        { "=SUM(B2:B3)", "2" },
+        { "=SUM(B3:B4)", "4" },
+        {             0, "8" }
+    };
+
+    insertRangeData(m_pDoc, ScAddress(0,0,0), pData, SAL_N_ELEMENTS(pData));
+
+    // Check that A1:A3 is a formula group.
+    const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(0,0,0));
+    CPPUNIT_ASSERT(pFC);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength());
+
+    m_pDoc->SetValue(ScAddress(0,1,0), 23.0);   // unshare at A2
+    m_pDoc->SetValue(ScAddress(1,1,0), 16.0);   // change value of B2
+    m_pDoc->SetValue(ScAddress(1,2,0), 32.0);   // change value of B3
+    // A1 and A3 should be recalculated.
+    CPPUNIT_ASSERT_EQUAL(17.0, m_pDoc->GetValue(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL(40.0, m_pDoc->GetValue(ScAddress(0,2,0)));
+
+    m_pDoc->DeleteTab(0);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 98a940b60c666792127c58aee989a87820fb7294
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Jan 15 17:21:41 2015 +0100

    fdo#88398 disable grouped listeners for now
    
    Further implementation is needed to re-establish grouped listeners after
    unshare and split.
    
    Change-Id: I861b3f9d63a611ab0e32918ce1b272121bf12988

diff --git a/sc/inc/sharedformula.hxx b/sc/inc/sharedformula.hxx
index d94d8fe..9101402 100644
--- a/sc/inc/sharedformula.hxx
+++ b/sc/inc/sharedformula.hxx
@@ -15,6 +15,11 @@
 
 #include <vector>
 
+/* TODO: before this can be activated further implementation is needed to
+ * re-establish the area listeners in case of unshare/split/join that currently
+ * would get discarded. */
+#define USE_FORMULA_GROUP_LISTENER 0
+
 namespace sc {
 
 class StartListeningContext;
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index cb9dda9..fe01944 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -66,6 +66,7 @@
 
 #include <editable.hxx>
 #include <bcaslot.hxx>
+#include <sharedformula.hxx>
 
 #include <formula/IFunctionDescription.hxx>
 
@@ -3992,6 +3993,8 @@ void Test::testCopyPasteRepeatOneFormula()
     m_pDoc->SetString(aPos, "=SUM(A1:B1)");
     CPPUNIT_ASSERT_EQUAL(11.0, m_pDoc->GetValue(aPos));
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     // At this point, there should be only one normal area listener listening
     // on A1:B1.
     ScRange aWholeSheet(0,0,0,MAXCOL,MAXROW,0);
@@ -4002,6 +4005,7 @@ void Test::testCopyPasteRepeatOneFormula()
     const sc::AreaListener* pListener = &aListeners[0];
     CPPUNIT_ASSERT_EQUAL(ScRange(0,0,0,1,0,0), pListener->maArea);
     CPPUNIT_ASSERT_MESSAGE("This listener shouldn't be a group listener.", !pListener->mbGroupListening);
+#endif
 
     // Copy C1 to clipboard.
     ScClipParam aClipParam(aPos, false);
@@ -4026,6 +4030,8 @@ void Test::testCopyPasteRepeatOneFormula()
         CPPUNIT_ASSERT_EQUAL(fExpected, m_pDoc->GetValue(ScAddress(2,i,0)));
     }
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     // At this point, there should only be one area listener and it should be
     // a group listener listening on A1:B10.
     aListeners = pBASM->GetAllListeners(aWholeSheet, sc::AreaInside);
@@ -4033,6 +4039,7 @@ void Test::testCopyPasteRepeatOneFormula()
     pListener = &aListeners[0];
     CPPUNIT_ASSERT_EQUAL(ScRange(0,0,0,1,9,0), pListener->maArea);
     CPPUNIT_ASSERT_MESSAGE("This listener should be a group listener.", pListener->mbGroupListening);
+#endif
 
     // Insert a new row at row 1.
     ScRange aRowOne(0,0,0,MAXCOL,0,0);
@@ -4042,12 +4049,15 @@ void Test::testCopyPasteRepeatOneFormula()
 
     CPPUNIT_ASSERT_MESSAGE("C1 should be empty.", m_pDoc->GetCellType(ScAddress(2,0,0)) == CELLTYPE_NONE);
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     // Make there we only have one group area listener listening on A2:B11.
     aListeners = pBASM->GetAllListeners(aWholeSheet, sc::AreaInside);
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aListeners.size());
     pListener = &aListeners[0];
     CPPUNIT_ASSERT_EQUAL(ScRange(0,1,0,1,10,0), pListener->maArea);
     CPPUNIT_ASSERT_MESSAGE("This listener should be a group listener.", pListener->mbGroupListening);
+#endif
 
     // Check the formula results.
     for (SCROW i = 0; i < 10; ++i)
@@ -4066,12 +4076,15 @@ void Test::testCopyPasteRepeatOneFormula()
         CPPUNIT_ASSERT_EQUAL(fExpected, m_pDoc->GetValue(ScAddress(2,i,0)));
     }
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     // Check the group area listener again to make sure it's listening on A1:B10 once again.
     aListeners = pBASM->GetAllListeners(aWholeSheet, sc::AreaInside);
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aListeners.size());
     pListener = &aListeners[0];
     CPPUNIT_ASSERT_EQUAL(ScRange(0,0,0,1,9,0), pListener->maArea);
     CPPUNIT_ASSERT_MESSAGE("This listener should be a group listener.", pListener->mbGroupListening);
+#endif
 
     m_pDoc->DeleteTab(0);
 }
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index aa1d778..36fb824 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -22,6 +22,7 @@
 #include <globalnames.hxx>
 #include <dbdata.hxx>
 #include <bcaslot.hxx>
+#include <sharedformula.hxx>
 
 #include <svl/sharedstring.hxx>
 
@@ -631,6 +632,8 @@ void Test::testSharedFormulasRefUpdateRangeDeleteRow()
     std::vector<sc::AreaListener> aListeners = pBASM->GetAllListeners(aWholeArea, sc::AreaInside);
     std::sort(aListeners.begin(), aListeners.end(), sc::AreaListener::SortByArea());
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     CPPUNIT_ASSERT_MESSAGE("There should only be 2 area listeners.", aListeners.size() == 2);
     // First one should be group-listening on A1:B2.
     CPPUNIT_ASSERT_MESSAGE("This listener should be listening on A1:B2.", aListeners[0].maArea == ScRange(0,0,0,1,1,0));
@@ -638,6 +641,7 @@ void Test::testSharedFormulasRefUpdateRangeDeleteRow()
     // Second one should be group-listening on A4:B5.
     CPPUNIT_ASSERT_MESSAGE("This listener should be listening on A1:B2.", aListeners[0].maArea == ScRange(0,0,0,1,1,0));
     CPPUNIT_ASSERT_MESSAGE("This listener should be group-listening.", aListeners[0].mbGroupListening);
+#endif
 
     // Make sure that C1:C2 and C4:C5 are formula groups.
     const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(2,0,0));
@@ -662,11 +666,14 @@ void Test::testSharedFormulasRefUpdateRangeDeleteRow()
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow());
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength());
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     // We should only have one listener group-listening on A1:B4.
     aListeners = pBASM->GetAllListeners(aWholeArea, sc::AreaInside);
     CPPUNIT_ASSERT_MESSAGE("There should only be 1 area listener.", aListeners.size() == 1);
     CPPUNIT_ASSERT_MESSAGE("This listener should be listening on A1:B4.", aListeners[0].maArea == ScRange(0,0,0,1,3,0));
     CPPUNIT_ASSERT_MESSAGE("This listener should be group-listening.", aListeners[0].mbGroupListening);
+#endif
 
     // Change the value of B4 and make sure the value of C4 changes.
     rFunc.SetValueCell(ScAddress(1,3,0), 100.0, false);
@@ -691,6 +698,8 @@ void Test::testSharedFormulasRefUpdateRangeDeleteRow()
     aListeners = pBASM->GetAllListeners(aWholeArea, sc::AreaInside);
     std::sort(aListeners.begin(), aListeners.end(), sc::AreaListener::SortByArea());
 
+    // This check makes only sense if group listeners are activated.
+#if !defined(USE_FORMULA_GROUP_LISTENER) || USE_FORMULA_GROUP_LISTENER
     CPPUNIT_ASSERT_MESSAGE("There should only be 2 area listeners.", aListeners.size() == 2);
     // First one should be group-listening on A1:B2.
     CPPUNIT_ASSERT_MESSAGE("This listener should be listening on A1:B2.", aListeners[0].maArea == ScRange(0,0,0,1,1,0));
@@ -698,6 +707,7 @@ void Test::testSharedFormulasRefUpdateRangeDeleteRow()
     // Second one should be group-listening on A4:B5.
     CPPUNIT_ASSERT_MESSAGE("This listener should be listening on A1:B2.", aListeners[0].maArea == ScRange(0,0,0,1,1,0));
     CPPUNIT_ASSERT_MESSAGE("This listener should be group-listening.", aListeners[0].mbGroupListening);
+#endif
 
     m_pDoc->DeleteTab(0);
 }
diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx
index b1cd80d..844e0a7 100644
--- a/sc/source/core/tool/sharedformula.cxx
+++ b/sc/source/core/tool/sharedformula.cxx
@@ -14,8 +14,6 @@
 #include <document.hxx>
 #include <grouparealistener.hxx>
 
-#define USE_FORMULA_GROUP_LISTENER 1
-
 namespace sc {
 
 void SharedFormulaUtil::splitFormulaCellGroup(const CellStoreType::position_type& aPos)


More information about the Libreoffice-commits mailing list