[Libreoffice-commits] core.git: svl/qa svl/source
Tobias Lippert
drtl at fastmail.fm
Mon Jun 29 08:55:42 PDT 2015
svl/qa/unit/notify/test_SfxBroadcaster.cxx | 25 +++++++++++++++++++++++++
svl/source/notify/lstner.cxx | 5 ++++-
2 files changed, 29 insertions(+), 1 deletion(-)
New commits:
commit b014150e64cdc23dfd999061bc210f0ad701f0a2
Author: Tobias Lippert <drtl at fastmail.fm>
Date: Tue Jun 9 21:25:40 2015 +0200
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 at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/svl/qa/unit/notify/test_SfxBroadcaster.cxx b/svl/qa/unit/notify/test_SfxBroadcaster.cxx
index 6096029..292cd9d 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 ee0809c..4fc3426 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 );
+ }
}
More information about the Libreoffice-commits
mailing list