[Libreoffice-commits] core.git: sc/CppunitTest_sc_core.mk sc/inc sc/Module_sc.mk sc/qa

Tobias Lippert drtl at fastmail.fm
Mon Aug 3 23:44:10 PDT 2015


 sc/CppunitTest_sc_core.mk                     |   38 +++++++
 sc/Module_sc.mk                               |    1 
 sc/inc/chartlis.hxx                           |    8 -
 sc/qa/unit/test_ScChartListenerCollection.cxx |  124 ++++++++++++++++++++++++++
 4 files changed, 167 insertions(+), 4 deletions(-)

New commits:
commit e355661fe6352c93305406330349b630735fd4cd
Author: Tobias Lippert <drtl at fastmail.fm>
Date:   Sun Aug 2 21:43:22 2015 +0200

    fdo#68016 Add unittests for ScChartListenerCollection
    
    Change-Id: Ie9d0f43783fbdd922c089607ad67fdd1686334c9
    Reviewed-on: https://gerrit.libreoffice.org/17478
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/sc/CppunitTest_sc_core.mk b/sc/CppunitTest_sc_core.mk
new file mode 100644
index 0000000..1247e94
--- /dev/null
+++ b/sc/CppunitTest_sc_core.mk
@@ -0,0 +1,38 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,sc_core))
+
+$(eval $(call gb_CppunitTest_use_externals,sc_core, \
+	boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sc_core, \
+	offapi \
+	udkapi \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sc_core, \
+	sc/qa/unit/test_ScChartListenerCollection \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sc_core, \
+	cppu \
+	cppuhelper \
+	sal \
+	salhelper \
+	sc \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sc_core,\
+	-I$(SRCDIR)/sc/inc \
+	$$(INCLUDE) \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index 5c8986e..21794b9 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -49,6 +49,7 @@ $(eval $(call gb_Module_add_check_targets,sc,\
 		CppunitTest_sc_ucalc) \
     CppunitTest_sc_filters_test \
     CppunitTest_sc_rangelst_test \
+    CppunitTest_sc_core \
 ))
 
 $(eval $(call gb_Module_add_slowcheck_targets,sc, \
diff --git a/sc/inc/chartlis.hxx b/sc/inc/chartlis.hxx
index 0f74e86..8b29b99 100644
--- a/sc/inc/chartlis.hxx
+++ b/sc/inc/chartlis.hxx
@@ -117,7 +117,7 @@ public:
     bool operator!=( const ScChartListener& r ) const;
 };
 
-class ScChartHiddenRangeListener
+class SC_DLLPUBLIC ScChartHiddenRangeListener
 {
 public:
     ScChartHiddenRangeListener();
@@ -125,7 +125,7 @@ public:
     virtual void notify() = 0;
 };
 
-class ScChartListenerCollection
+class SC_DLLPUBLIC ScChartListenerCollection
 {
 public:
     typedef boost::ptr_map<OUString, ScChartListener> ListenersType;
@@ -158,7 +158,7 @@ public:
                     // only needed after copy-ctor, if newly added to doc
     void            StartAllListeners();
 
-    SC_DLLPUBLIC void insert(ScChartListener* pListener);
+    void insert(ScChartListener* pListener);
     ScChartListener* findByName(const OUString& rName);
     const ScChartListener* findByName(const OUString& rName) const;
     bool hasListeners() const;
@@ -184,7 +184,7 @@ public:
                              const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
     void            StartTimer();
     void            UpdateDirtyCharts();
-    SC_DLLPUBLIC void SetDirty();
+    void            SetDirty();
     void            SetDiffDirty( const ScChartListenerCollection&,
                         bool bSetChartRangeLists = false );
 
diff --git a/sc/qa/unit/test_ScChartListenerCollection.cxx b/sc/qa/unit/test_ScChartListenerCollection.cxx
new file mode 100644
index 0000000..427dc4d
--- /dev/null
+++ b/sc/qa/unit/test_ScChartListenerCollection.cxx
@@ -0,0 +1,124 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include "address.hxx"
+#include "chartlis.hxx"
+
+namespace {
+
+const ScRange RANGE_1(10, 10, 0, 19, 10, 0);
+const ScRange RANGE_2(20, 10, 0, 29, 10, 0);
+
+const ScRange RANGE_INTERSECTING_1_AND_2(10, 10, 0, 29, 10, 0);
+
+
+class ChartListenerCollectionTest : public CppUnit::TestFixture {
+
+    void ListenerGetsNotifiedWhenItsRangeIsSetDirty();
+    void ListenerGetsNotifiedTwiceWhenRegisteredTwoTimes();
+    void ListenerDoesNotGetNotifiedWhenListeningStops();
+    void ListenerStopsListeningForAllRanges();
+    void ListenersStopListeningIdependently();
+
+    CPPUNIT_TEST_SUITE(ChartListenerCollectionTest);
+
+    CPPUNIT_TEST(ListenerGetsNotifiedWhenItsRangeIsSetDirty);
+    CPPUNIT_TEST(ListenerGetsNotifiedTwiceWhenRegisteredTwoTimes);
+    CPPUNIT_TEST(ListenerDoesNotGetNotifiedWhenListeningStops);
+    CPPUNIT_TEST(ListenerStopsListeningForAllRanges);
+    CPPUNIT_TEST(ListenersStopListeningIdependently);
+
+    CPPUNIT_TEST_SUITE_END();
+
+};
+
+struct MockedHiddenRangeListener : public ScChartHiddenRangeListener {
+    unsigned mNotifyCount;
+    MockedHiddenRangeListener()
+    : mNotifyCount(0) {
+    }
+
+    void notify() SAL_OVERRIDE {
+        mNotifyCount++;
+    }
+};
+
+void ChartListenerCollectionTest::ListenerGetsNotifiedWhenItsRangeIsSetDirty() {
+    MockedHiddenRangeListener listener;
+    ScChartListenerCollection sut(NULL);
+
+    sut.StartListeningHiddenRange(RANGE_1, &listener);
+    sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
+
+    CPPUNIT_ASSERT_EQUAL(1u, listener.mNotifyCount);
+}
+
+void ChartListenerCollectionTest::ListenerGetsNotifiedTwiceWhenRegisteredTwoTimes() {
+    MockedHiddenRangeListener listener;
+    ScChartListenerCollection sut(NULL);
+
+    sut.StartListeningHiddenRange(RANGE_1, &listener);
+    sut.StartListeningHiddenRange(RANGE_2, &listener);
+    sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
+
+    CPPUNIT_ASSERT_EQUAL(2u, listener.mNotifyCount);
+}
+
+void ChartListenerCollectionTest::ListenerDoesNotGetNotifiedWhenListeningStops() {
+    MockedHiddenRangeListener listener;
+    ScChartListenerCollection sut(NULL);
+    sut.StartListeningHiddenRange(RANGE_1, &listener);
+
+    sut.EndListeningHiddenRange(&listener);
+    sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
+
+    CPPUNIT_ASSERT_EQUAL(0u, listener.mNotifyCount);
+
+}
+
+void ChartListenerCollectionTest::ListenerStopsListeningForAllRanges() {
+    MockedHiddenRangeListener listener;
+    ScChartListenerCollection sut(NULL);
+    sut.StartListeningHiddenRange(RANGE_1, &listener);
+    sut.StartListeningHiddenRange(RANGE_2, &listener);
+
+    sut.EndListeningHiddenRange(&listener);
+    sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
+
+    CPPUNIT_ASSERT_EQUAL(0u, listener.mNotifyCount);
+}
+
+void ChartListenerCollectionTest::ListenersStopListeningIdependently() {
+    MockedHiddenRangeListener listener1;
+    MockedHiddenRangeListener listener2;
+
+    ScChartListenerCollection sut(NULL);
+    sut.StartListeningHiddenRange(RANGE_1, &listener1);
+    sut.StartListeningHiddenRange(RANGE_2, &listener2);
+
+    sut.EndListeningHiddenRange(&listener1);
+    sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
+
+    CPPUNIT_ASSERT_EQUAL(0u, listener1.mNotifyCount);
+    CPPUNIT_ASSERT_EQUAL(1u, listener2.mNotifyCount);
+}
+
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ChartListenerCollectionTest);
+
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list