Kaydet (Commit) 31292682 authored tarafından Tobias Lippert's avatar Tobias Lippert Kaydeden (comit) Noel Grandin

Add unittests for SfxBroadcaster

Change-Id: I9ecd8fec395eafbdc2675dda9fa25ac32761123c
Reviewed-on: https://gerrit.libreoffice.org/10343Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst f413cb08
......@@ -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
......
# -*- 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:
......@@ -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
......
/* -*- 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();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment