summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-09-12 23:22:12 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-09-18 09:38:54 (GMT)
commit4455c20085834098f6d9aa872db3115d466e7004 (patch)
treee5e61ec0880f4001bc76340cd13670cd49628e7c /Swiften/Client/UnitTest
parent909ecaea63618e9b94c9063c94cd51aa69654b00 (diff)
downloadswift-4455c20085834098f6d9aa872db3115d466e7004.zip
swift-4455c20085834098f6d9aa872db3115d466e7004.tar.bz2
Fix notification logic for signals in BlockListImpl
The logic for calling onItemAdded and onItemRemoved signals when setting a new list of block items using BlockListImpl::setItems used to be broken. This commit fixes and documents the correct signal notification behavior Test-Information: Added a unit test which verifies the notification behavior in case of added block list items, removed block list items and a complete change of the block list. Change-Id: I3061545e25ddfc2d9d1a3c987045a58e5c9230ac
Diffstat (limited to 'Swiften/Client/UnitTest')
-rw-r--r--Swiften/Client/UnitTest/BlockListImplTest.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/Swiften/Client/UnitTest/BlockListImplTest.cpp b/Swiften/Client/UnitTest/BlockListImplTest.cpp
new file mode 100644
index 0000000..9e5bc1a
--- /dev/null
+++ b/Swiften/Client/UnitTest/BlockListImplTest.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <vector>
+
+#include <boost/bind.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Client/BlockListImpl.h>
+#include <Swiften/JID/JID.h>
+
+using namespace Swift;
+
+class BlockListImplTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(BlockListImplTest);
+ CPPUNIT_TEST(testSetItemsToSubset);
+ CPPUNIT_TEST(testSetItemsToSuperset);
+ CPPUNIT_TEST(testSetItemsAllDifferent);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ void testSetItemsToSubset() {
+ std::vector<JID> subset;
+ subset.push_back(JID("a@example.com"));
+
+ blockList_->setItems(subset);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), addedJIDs_.size());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), removedJIDs_.size());
+ }
+
+ void testSetItemsToSuperset() {
+ std::vector<JID> superset;
+ superset.push_back(JID("a@example.com"));
+ superset.push_back(JID("b@example.com"));
+ superset.push_back(JID("c@example.com"));
+
+ blockList_->setItems(superset);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), addedJIDs_.size());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), removedJIDs_.size());
+ }
+
+ void testSetItemsAllDifferent() {
+ std::vector<JID> newBlockList;
+ newBlockList.push_back(JID("x@example.com"));
+ newBlockList.push_back(JID("y@example.com"));
+ newBlockList.push_back(JID("z@example.com"));
+
+ blockList_->setItems(newBlockList);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), addedJIDs_.size());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), removedJIDs_.size());
+ }
+
+ void setUp() {
+ blockList_ = boost::make_shared<BlockListImpl>();
+ addedJIDs_.clear();
+ removedJIDs_.clear();
+ blockList_->addItem(JID("a@example.com"));
+ blockList_->addItem(JID("b@example.com"));
+
+ blockList_->onItemAdded.connect(boost::bind(&BlockListImplTest::handleBlockListItemAdded, this, _1));
+ blockList_->onItemRemoved.connect(boost::bind(&BlockListImplTest::handleBlockListItemRemoved, this, _1));
+ }
+
+ void tearDown() {
+ blockList_.reset();
+ }
+
+ void handleBlockListItemAdded(const JID& jid) {
+ addedJIDs_.push_back(jid);
+ }
+
+ void handleBlockListItemRemoved(const JID& jid) {
+ removedJIDs_.push_back(jid);
+ }
+
+ private:
+ boost::shared_ptr<BlockListImpl> blockList_;
+ std::vector<JID> addedJIDs_;
+ std::vector<JID> removedJIDs_;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BlockListImplTest);