summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-02-11 17:19:59 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-02-11 17:19:59 (GMT)
commit7fe127240ecebd163f65a5078f8dc927fe17e47b (patch)
tree6acdea2ca200771365fe27518a28f9dc252fc1c6 /Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h
parentf5e9fb9032bb90ec0ca622f4afb97ba9a479e43d (diff)
downloadswift-7fe127240ecebd163f65a5078f8dc927fe17e47b.zip
swift-7fe127240ecebd163f65a5078f8dc927fe17e47b.tar.bz2
Adding more roster unit tests
Diffstat (limited to 'Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h')
-rw-r--r--Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h
new file mode 100644
index 0000000..5e15e9f
--- /dev/null
+++ b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2010-2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+#pragma once
+#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+
+#include <vector>
+
+
+#include "Swiften/Roster/XMPPRosterImpl.h"
+
+using namespace Swift;
+
+
+enum XMPPRosterEvents {None, Add, Remove, Update};
+
+class XMPPRosterSignalHandler {
+public:
+ XMPPRosterSignalHandler(XMPPRoster* roster) {
+ lastEvent_ = None;
+ roster->onJIDAdded.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDAdded, this, _1));
+ roster->onJIDRemoved.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDRemoved, this, _1));
+ roster->onJIDUpdated.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDUpdated, this, _1, _2, _3));
+ }
+
+ XMPPRosterEvents getLastEvent() {
+ return lastEvent_;
+ }
+
+ JID getLastJID() {
+ return lastJID_;
+ }
+
+ String getLastOldName() {
+ return lastOldName_;
+ }
+
+ std::vector<String> getLastOldGroups() {
+ return lastOldGroups_;
+ }
+
+ void reset() {
+ lastEvent_ = None;
+ }
+
+private:
+ void handleJIDAdded(const JID& jid) {
+ lastJID_ = jid;
+ lastEvent_ = Add;
+ }
+
+ void handleJIDRemoved(const JID& jid) {
+ lastJID_ = jid;
+ lastEvent_ = Remove;
+ }
+
+ void handleJIDUpdated(const JID& jid, const String& oldName, const std::vector<String>& oldGroups) {
+ CPPUNIT_ASSERT_EQUAL(None, lastEvent_);
+ lastJID_ = jid;
+ lastOldName_ = oldName;
+ lastOldGroups_ = oldGroups;
+ lastEvent_ = Update;
+ }
+
+ XMPPRosterEvents lastEvent_;
+ JID lastJID_;
+ String lastOldName_;
+ std::vector<String> lastOldGroups_;
+
+};