summaryrefslogtreecommitdiff
path: root/svl/qa
diff options
context:
space:
mode:
authorTobias Lippert <drtl@fastmail.fm>2014-06-20 11:01:30 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-07-22 06:25:22 +0000
commit312926823dc6da7e87eb60c98ba084f14f0aa676 (patch)
treedb1185fbe2ffc98430faff9a56bafbf78844e163 /svl/qa
parentf413cb08b8c0f67b9bf7278dd654dac9001cf490 (diff)
Add unittests for SfxBroadcaster
Change-Id: I9ecd8fec395eafbdc2675dda9fa25ac32761123c Reviewed-on: https://gerrit.libreoffice.org/10343 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svl/qa')
-rw-r--r--svl/qa/unit/notify/test_SfxBroadcaster.cxx98
1 files changed, 98 insertions, 0 deletions
diff --git a/svl/qa/unit/notify/test_SfxBroadcaster.cxx b/svl/qa/unit/notify/test_SfxBroadcaster.cxx
new file mode 100644
index 000000000000..8139ed1eba2d
--- /dev/null
+++ b/svl/qa/unit/notify/test_SfxBroadcaster.cxx
@@ -0,0 +1,98 @@
+/* -*- 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 <svl/SfxBroadcaster.hxx>
+
+#include <svl/lstner.hxx>
+#include <svl/hint.hxx>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+class SfxBroadcasterTest : public CppUnit::TestFixture
+{
+ void AddingListenersIncreasesCount();
+ void RemovingListenersDecreasesCount();
+ void HintsAreNotForwardedToRemovedListeners();
+
+ // Adds code needed to register the test suite
+ CPPUNIT_TEST_SUITE(SfxBroadcasterTest);
+ CPPUNIT_TEST(AddingListenersIncreasesCount);
+ //CPPUNIT_TEST(RemovingListenersDecreasesCount);
+ CPPUNIT_TEST(HintsAreNotForwardedToRemovedListeners);
+
+ CPPUNIT_TEST_SUITE_END();
+};
+
+class MockedSfxListener : public SfxListener
+{
+public:
+ MockedSfxListener()
+ : mNotifyWasCalled(false) {}
+
+ void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) SAL_OVERRIDE {
+ (void)(rBC); (void)(rHint); // avoid warnings about unused parameters
+ mNotifyWasCalled = true;
+ }
+
+ bool NotifyWasCalled() const {
+ return mNotifyWasCalled;
+ }
+
+private:
+ bool mNotifyWasCalled;
+};
+
+void
+SfxBroadcasterTest::AddingListenersIncreasesCount()
+{
+ SfxBroadcaster sb;
+ MockedSfxListener sl;
+
+ CPPUNIT_ASSERT_EQUAL((size_t)0, sb.GetListenerCount());
+
+ sl.StartListening(sb, true);
+ CPPUNIT_ASSERT_EQUAL((size_t)1, sb.GetListenerCount());
+}
+
+void
+SfxBroadcasterTest::RemovingListenersDecreasesCount()
+{
+ SfxBroadcaster sb;
+ MockedSfxListener sl;
+
+ CPPUNIT_ASSERT_EQUAL((size_t)0, sb.GetListenerCount());
+ sl.StartListening(sb, true);
+ CPPUNIT_ASSERT_EQUAL((size_t)1, sb.GetListenerCount());
+ sl.EndListening(sb, true);
+ CPPUNIT_ASSERT_EQUAL((size_t)0, sb.GetListenerCount());
+}
+
+void
+SfxBroadcasterTest::HintsAreNotForwardedToRemovedListeners()
+{
+ SfxBroadcaster sb;
+ MockedSfxListener sl1;
+ MockedSfxListener sl2;
+ SfxHint hint;
+
+ sl1.StartListening(sb, true);
+ sl2.StartListening(sb, true);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("All listeners were added.", (size_t)2, sb.GetListenerCount());
+ sl1.EndListening(sb, true);
+ sb.Forward(sb, hint);
+ CPPUNIT_ASSERT_EQUAL(true, sl2.NotifyWasCalled());
+ CPPUNIT_ASSERT_EQUAL(false, sl1.NotifyWasCalled());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SfxBroadcasterTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();