From 2e86507010e1f8754049a3bb37ce9041bb19d870 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 22 Mar 2010 21:51:36 +0000 Subject: Fixing up the unit tests again. Oops. diff --git a/Swift/Controllers/MainWindow.h b/Swift/Controllers/MainWindow.h index b15cbb5..07ff703 100644 --- a/Swift/Controllers/MainWindow.h +++ b/Swift/Controllers/MainWindow.h @@ -21,7 +21,6 @@ namespace Swift { virtual void setMyStatusType(StatusShow::Type type) = 0; boost::signal onStartChatRequest; - boost::signal onAddContactRequest; boost::signal onJoinMUCRequest; boost::signal onChangeStatusRequest; boost::signal onShowOfflineToggled; diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index 8d13057..0fc80eb 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -18,6 +18,7 @@ #include "Swiften/Roster/OpenChatRosterAction.h" #include "Swiften/Roster/TreeWidgetFactory.h" #include "Swiften/Roster/XMPPRoster.h" +#include "Swift/Controllers/UIEvents/AddContactUIEvent.h" namespace Swift { @@ -41,6 +42,7 @@ RosterController::RosterController(const JID& jid, boost::shared_ptr xmppRoster_->onJIDRemoved.connect(boost::bind(&RosterController::handleOnJIDRemoved, this, _1)); presenceOracle_->onPresenceSubscriptionRequest.connect(boost::bind(&RosterController::handleSubscriptionRequest, this, _1, _2)); presenceOracle_->onPresenceChange.connect(boost::bind(&RosterController::handleIncomingPresence, this, _1, _2)); + uiEventStream->onUIEvent.connect(boost::bind(&RosterController::handleUIEvent, this, _1)); avatarManager_ = NULL; setAvatarManager(avatarManager); setNickResolver(nickResolver); @@ -137,6 +139,13 @@ void RosterController::handleOnJIDUpdated(const JID& jid, const String& oldName, } +void RosterController::handleUIEvent(boost::shared_ptr event) { + boost::shared_ptr addContactEvent = boost::dynamic_pointer_cast(event); + if (addContactEvent) { + presenceOracle_->requestSubscription(addContactEvent->getJID()); + } +} + void RosterController::handleIncomingPresence(boost::shared_ptr newPresence, boost::shared_ptr /*oldPresence*/) { roster_->applyOnItems(SetPresence(newPresence)); } diff --git a/Swift/Controllers/RosterController.h b/Swift/Controllers/RosterController.h index cef0e48..4f1da1a 100644 --- a/Swift/Controllers/RosterController.h +++ b/Swift/Controllers/RosterController.h @@ -6,6 +6,7 @@ #include "Swiften/Elements/Presence.h" #include "Swiften/Roster/UserRosterAction.h" #include "Swiften/Avatars/AvatarManager.h" +#include "Swift/Controllers/UIEvents/UIEvent.h" #include #include @@ -51,6 +52,7 @@ namespace Swift { void handleSubscriptionRequest(const JID& jid, const String& message); void handleSubscriptionRequestAccepted(SubscriptionRequestEvent* event); void handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event); + void handleUIEvent(boost::shared_ptr event); JID myJID_; boost::shared_ptr xmppRoster_; MainWindowFactory* mainWindowFactory_; diff --git a/Swift/Controllers/UIEvents/AddContactUIEvent.h b/Swift/Controllers/UIEvents/AddContactUIEvent.h new file mode 100644 index 0000000..8ff4d51 --- /dev/null +++ b/Swift/Controllers/UIEvents/AddContactUIEvent.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Swiften/Base/String.h" + +#include "Swift/Controllers/UIEvents/UIEvent.h" + +namespace Swift { + class AddContactUIEvent : public UIEvent { + public: + AddContactUIEvent(const JID& jid, const String& name) : jid_(jid), name_(name) {}; + String getName() {return name_;}; + JID getJID() {return jid_;}; + private: + JID jid_; + String name_; + }; +} diff --git a/Swift/Controllers/UnitTest/NickResolverTest.cpp b/Swift/Controllers/UnitTest/NickResolverTest.cpp index e3123f9..6f509c0 100644 --- a/Swift/Controllers/UnitTest/NickResolverTest.cpp +++ b/Swift/Controllers/UnitTest/NickResolverTest.cpp @@ -33,7 +33,7 @@ class NickResolverTest : public CppUnit::TestFixture boost::shared_ptr xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); JID testJID("foo@bar/baz"); - xmppRoster->addContact(testJID, "", groups_); + xmppRoster->addContact(testJID, "", groups_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID)); } @@ -41,7 +41,7 @@ class NickResolverTest : public CppUnit::TestFixture boost::shared_ptr xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); JID testJID("foo@bar/baz"); - xmppRoster->addContact(testJID, "Test", groups_); + xmppRoster->addContact(testJID, "Test", groups_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testJID)); } @@ -50,8 +50,8 @@ class NickResolverTest : public CppUnit::TestFixture boost::shared_ptr xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); JID testJID("foo@bar/baz"); - xmppRoster->addContact(testJID, "FailTest", groups_); - xmppRoster->addContact(testJID, "Test", groups_); + xmppRoster->addContact(testJID, "FailTest", groups_, RosterItemPayload::Both); + xmppRoster->addContact(testJID, "Test", groups_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testJID)); } @@ -60,7 +60,7 @@ class NickResolverTest : public CppUnit::TestFixture boost::shared_ptr xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); JID testJID("foo@bar/baz"); - xmppRoster->addContact(testJID, "FailTest", groups_); + xmppRoster->addContact(testJID, "FailTest", groups_, RosterItemPayload::Both); xmppRoster->removeContact(testJID); CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID)); } diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp index bfd98ac..80b2284 100644 --- a/Swift/Controllers/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp @@ -64,7 +64,7 @@ class RosterControllerTest : public CppUnit::TestFixture std::vector groups; groups.push_back("testGroup1"); groups.push_back("testGroup2"); - xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups); + xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(2, (int)treeWidgetFactory_->getGroups().size()); //CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com"))); diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index ebafaff..618a887 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -5,6 +5,8 @@ #include "QtSwiftUtil.h" #include "Roster/QtTreeWidgetFactory.h" #include "Roster/QtTreeWidget.h" +#include "Swift/Controllers/UIEvents/AddContactUIEvent.h" + #include #include @@ -89,7 +91,8 @@ void QtMainWindow::handleSignOutAction() { } void QtMainWindow::handleAddContactDialogComplete(const JID& contact, const QString& name) { - onAddContactRequest(contact, Q2PSTRING(name)); + boost::shared_ptr event(new AddContactUIEvent(contact, Q2PSTRING(name))); + uiEventStream_->send(event); } TreeWidget* QtMainWindow::getTreeWidget() { diff --git a/Swiften/Roster/UnitTest/XMPPRosterTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterTest.cpp index 96de30c..d03953e 100644 --- a/Swiften/Roster/UnitTest/XMPPRosterTest.cpp +++ b/Swiften/Roster/UnitTest/XMPPRosterTest.cpp @@ -102,13 +102,13 @@ class XMPPRosterTest : public CppUnit::TestFixture } void testJIDAdded() { - roster_->addContact(jid1_, "NewName", groups1_); + roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID()); CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid1_)); CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_)); handler_->reset(); - roster_->addContact(jid2_, "NameTwo", groups1_); + roster_->addContact(jid2_, "NameTwo", groups1_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID()); CPPUNIT_ASSERT_EQUAL(String("NameTwo"), roster_->getNameForJID(jid2_)); @@ -116,7 +116,7 @@ class XMPPRosterTest : public CppUnit::TestFixture CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid2_)); CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_)); handler_->reset(); - roster_->addContact(jid3_, "NewName", groups2_); + roster_->addContact(jid3_, "NewName", groups2_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID()); CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid3_)); @@ -124,17 +124,17 @@ class XMPPRosterTest : public CppUnit::TestFixture } void testJIDRemoved() { - roster_->addContact(jid1_, "NewName", groups1_); + roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both); handler_->reset(); roster_->removeContact(jid1_); CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID()); handler_->reset(); - roster_->addContact(jid1_, "NewName2", groups1_); + roster_->addContact(jid1_, "NewName2", groups1_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID()); CPPUNIT_ASSERT_EQUAL(String("NewName2"), roster_->getNameForJID(jid1_)); - roster_->addContact(jid2_, "NewName3", groups1_); + roster_->addContact(jid2_, "NewName3", groups1_, RosterItemPayload::Both); handler_->reset(); roster_->removeContact(jid2_); CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent()); @@ -146,13 +146,13 @@ class XMPPRosterTest : public CppUnit::TestFixture } void testJIDUpdated() { - roster_->addContact(jid1_, "NewName", groups1_); + roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID()); CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid1_)); CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_)); handler_->reset(); - roster_->addContact(jid1_, "NameTwo", groups2_); + roster_->addContact(jid1_, "NameTwo", groups2_, RosterItemPayload::Both); CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent()); CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID()); CPPUNIT_ASSERT_EQUAL(String("NameTwo"), roster_->getNameForJID(jid1_)); -- cgit v0.10.2-6-g49f6