diff options
-rw-r--r-- | sc/CppunitTest_sc_core.mk | 38 | ||||
-rw-r--r-- | sc/Module_sc.mk | 1 | ||||
-rw-r--r-- | sc/inc/chartlis.hxx | 8 | ||||
-rw-r--r-- | sc/qa/unit/test_ScChartListenerCollection.cxx | 124 |
4 files changed, 167 insertions, 4 deletions
diff --git a/sc/CppunitTest_sc_core.mk b/sc/CppunitTest_sc_core.mk new file mode 100644 index 000000000000..1247e94f6289 --- /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 5c8986e2c879..21794b9f975c 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 0f74e869852c..8b29b9933d26 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 000000000000..427dc4d2145b --- /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: */ |