include/svl/SfxBroadcaster.hxx | 7 +- svl/CppunitTest_svl_notify.mk | 36 ++++++++++ svl/Module_svl.mk | 1 svl/qa/unit/notify/test_SfxBroadcaster.cxx | 98 +++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 3 deletions(-)
New commits: commit 312926823dc6da7e87eb60c98ba084f14f0aa676 Author: Tobias Lippert <d...@fastmail.fm> Date: Fri Jun 20 11:01:30 2014 +0200 Add unittests for SfxBroadcaster Change-Id: I9ecd8fec395eafbdc2675dda9fa25ac32761123c Reviewed-on: https://gerrit.libreoffice.org/10343 Reviewed-by: Noel Grandin <noelgran...@gmail.com> Tested-by: Noel Grandin <noelgran...@gmail.com> diff --git a/include/svl/SfxBroadcaster.hxx b/include/svl/SfxBroadcaster.hxx index 8fd62b9..5c135b5 100644 --- a/include/svl/SfxBroadcaster.hxx +++ b/include/svl/SfxBroadcaster.hxx @@ -25,12 +25,10 @@ class SfxListener; class SfxHint; - - +class SfxBroadcasterTest; class SVL_DLLPUBLIC SfxBroadcaster { - friend class SfxListener; typedef std::vector<SfxListener*> SfxListenerArr_Impl; SfxListenerArr_Impl m_Listeners; @@ -61,6 +59,9 @@ public: { return m_Listeners[nNo]; } + + friend class SfxListener; + friend class ::SfxBroadcasterTest; }; #endif diff --git a/svl/CppunitTest_svl_notify.mk b/svl/CppunitTest_svl_notify.mk new file mode 100644 index 0000000..ff1dbe7 --- /dev/null +++ b/svl/CppunitTest_svl_notify.mk @@ -0,0 +1,36 @@ +# -*- 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,svl_notify)) + +$(eval $(call gb_CppunitTest_use_external,svl_notify,boost_headers)) + +$(eval $(call gb_CppunitTest_use_api,svl_notify, \ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,svl_notify, \ + svl/qa/unit/notify/test_SfxBroadcaster \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,svl_notify, \ + svl \ + comphelper \ + sal \ + cppu \ + cppuhelper \ +)) + +$(eval $(call gb_CppunitTest_set_include,svl_notify,\ + -I$(SRCDIR)/svl/source/inc \ + $$(INCLUDE) \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/svl/Module_svl.mk b/svl/Module_svl.mk index 7589030..54f6b6c 100644 --- a/svl/Module_svl.mk +++ b/svl/Module_svl.mk @@ -35,6 +35,7 @@ $(eval $(call gb_Module_add_check_targets,svl,\ CppunitTest_svl_inetcontenttype \ CppunitTest_svl_items \ CppunitTest_svl_itempool \ + CppunitTest_svl_notify \ )) #TODO: CppunitTest_svl_urihelper depends on ucb, can only be added once svl is diff --git a/svl/qa/unit/notify/test_SfxBroadcaster.cxx b/svl/qa/unit/notify/test_SfxBroadcaster.cxx new file mode 100644 index 0000000..8139ed1 --- /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(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits