diff options
author | Tobias Lippert <drtl@fastmail.fm> | 2015-06-09 21:25:40 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2015-06-29 15:55:12 +0000 |
commit | b014150e64cdc23dfd999061bc210f0ad701f0a2 (patch) | |
tree | 78f852588bf002983beda79d81d89e4fce9443bd /svl | |
parent | e03a5f5e8303668cb68844b6df9ec53a561792bc (diff) |
tdf#68016 Write fixture for current behaviour of SfxListener
Also: Make destructor of SfxListener more robust, so that it can be used
in tests.
Change-Id: I02b273ca8e527705c2d3ea3295ed0dec1c4f83ae
Reviewed-on: https://gerrit.libreoffice.org/16483
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/qa/unit/notify/test_SfxBroadcaster.cxx | 25 | ||||
-rw-r--r-- | svl/source/notify/lstner.cxx | 5 |
2 files changed, 29 insertions, 1 deletions
diff --git a/svl/qa/unit/notify/test_SfxBroadcaster.cxx b/svl/qa/unit/notify/test_SfxBroadcaster.cxx index 60960295ccc7..292cd9dcbe93 100644 --- a/svl/qa/unit/notify/test_SfxBroadcaster.cxx +++ b/svl/qa/unit/notify/test_SfxBroadcaster.cxx @@ -22,12 +22,16 @@ class SfxBroadcasterTest : public CppUnit::TestFixture void AddingListenersIncreasesCount(); void RemovingListenersDecreasesCount(); void HintsAreNotForwardedToRemovedListeners(); + void SameListenerCanBeAddedMoreThanOnce(); + void StoppingListeningAffectsOnlyFirstOfIdenticalListeners(); // Adds code needed to register the test suite CPPUNIT_TEST_SUITE(SfxBroadcasterTest); CPPUNIT_TEST(AddingListenersIncreasesCount); CPPUNIT_TEST(RemovingListenersDecreasesCount); CPPUNIT_TEST(HintsAreNotForwardedToRemovedListeners); + CPPUNIT_TEST(SameListenerCanBeAddedMoreThanOnce); + CPPUNIT_TEST(StoppingListeningAffectsOnlyFirstOfIdenticalListeners); CPPUNIT_TEST_SUITE_END(); }; @@ -93,6 +97,27 @@ SfxBroadcasterTest::HintsAreNotForwardedToRemovedListeners() CPPUNIT_ASSERT_EQUAL(false, sl1.NotifyWasCalled()); } +void +SfxBroadcasterTest::SameListenerCanBeAddedMoreThanOnce() +{ + MockedSfxListener sl; + SfxBroadcaster sb; + sb.AddListener(sl); + sb.AddListener(sl); + CPPUNIT_ASSERT_EQUAL((size_t)2, sb.GetListenerCount()); +} + +void +SfxBroadcasterTest::StoppingListeningAffectsOnlyFirstOfIdenticalListeners() +{ + MockedSfxListener sl; + SfxBroadcaster sb; + sb.AddListener(sl); + sb.AddListener(sl); + sb.RemoveListener(sl); + CPPUNIT_ASSERT_EQUAL((size_t)1, sb.GetListenerCount()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SfxBroadcasterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/svl/source/notify/lstner.cxx b/svl/source/notify/lstner.cxx index ee0809cd0db7..4fc3426b8bd4 100644 --- a/svl/source/notify/lstner.cxx +++ b/svl/source/notify/lstner.cxx @@ -68,7 +68,10 @@ SfxListener::~SfxListener() void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster ) { - mpImpl->maBCs.erase( std::find( mpImpl->maBCs.begin(), mpImpl->maBCs.end(), &rBroadcaster ) ); + auto it = std::find( mpImpl->maBCs.begin(), mpImpl->maBCs.end(), &rBroadcaster ); + if (it != mpImpl->maBCs.end()) { + mpImpl->maBCs.erase( it ); + } } |