summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
committerTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
commitcfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch)
tree18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/MUC/UnitTest
parent1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff)
downloadswift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip
swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines in the process. Changed CheckTabs.py tool to disallow hard tabs in source files. Test-Information: Manually checked 30 random files that the conversion worked as expected. Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/MUC/UnitTest')
-rw-r--r--Swiften/MUC/UnitTest/MUCTest.cpp496
-rw-r--r--Swiften/MUC/UnitTest/MockMUC.cpp32
-rw-r--r--Swiften/MUC/UnitTest/MockMUC.h124
3 files changed, 326 insertions, 326 deletions
diff --git a/Swiften/MUC/UnitTest/MUCTest.cpp b/Swiften/MUC/UnitTest/MUCTest.cpp
index a422c12..548617c 100644
--- a/Swiften/MUC/UnitTest/MUCTest.cpp
+++ b/Swiften/MUC/UnitTest/MUCTest.cpp
@@ -24,254 +24,254 @@
using namespace Swift;
class MUCTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(MUCTest);
- CPPUNIT_TEST(testJoin);
- CPPUNIT_TEST(testJoin_ChangePresenceDuringJoinDoesNotSendPresenceBeforeJoinSuccess);
- CPPUNIT_TEST(testJoin_ChangePresenceDuringJoinResendsPresenceAfterJoinSuccess);
- CPPUNIT_TEST(testJoin_NoPresenceChangeDuringJoinDoesNotResendAfterJoinSuccess);
- CPPUNIT_TEST(testCreateInstant);
- CPPUNIT_TEST(testReplicateBug);
- CPPUNIT_TEST(testNicknameChange);
- /*CPPUNIT_TEST(testJoin_Success);
- CPPUNIT_TEST(testJoin_Fail);*/
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- channel = new DummyStanzaChannel();
- router = new IQRouter(channel);
- mucRegistry = new MUCRegistry();
- stanzaChannelPresenceSender = new StanzaChannelPresenceSender(channel);
- presenceSender = new DirectedPresenceSender(stanzaChannelPresenceSender);
- nickChanges = 0;
- }
-
- void tearDown() {
- delete presenceSender;
- delete stanzaChannelPresenceSender;
- delete mucRegistry;
- delete router;
- delete channel;
- }
-
- void testJoin() {
- MUC::ref testling = createMUC(JID("foo@bar.com"));
- testling->joinAs("Alice");
-
- CPPUNIT_ASSERT(mucRegistry->isMUC(JID("foo@bar.com")));
- Presence::ref p = channel->getStanzaAtIndex<Presence>(0);
- CPPUNIT_ASSERT(p);
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/Alice"), p->getTo());
- }
-
- void testJoin_ChangePresenceDuringJoinDoesNotSendPresenceBeforeJoinSuccess() {
- MUC::ref testling = createMUC(JID("foo@bar.com"));
- testling->joinAs("Alice");
-
- presenceSender->sendPresence(Presence::create("Test"));
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel->sentStanzas.size()));
- }
-
- void testJoin_ChangePresenceDuringJoinResendsPresenceAfterJoinSuccess() {
- MUC::ref testling = createMUC(JID("foo@bar.com"));
- testling->joinAs("Alice");
-
- presenceSender->sendPresence(Presence::create("Test"));
- receivePresence(JID("foo@bar.com/Rabbit"), "Here");
-
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(channel->sentStanzas.size()));
- Presence::ref p = channel->getStanzaAtIndex<Presence>(2);
- CPPUNIT_ASSERT(p);
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/Alice"), p->getTo());
- CPPUNIT_ASSERT_EQUAL(std::string("Test"), p->getStatus());
- }
-
- void testJoin_NoPresenceChangeDuringJoinDoesNotResendAfterJoinSuccess() {
- MUC::ref testling = createMUC(JID("foo@bar.com"));
- testling->joinAs("Alice");
-
- receivePresence(JID("foo@bar.com/Rabbit"), "Here");
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->sentStanzas.size()));
- Presence::ref p = channel->getStanzaAtIndex<Presence>(0);
- CPPUNIT_ASSERT(p);
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/Alice"), p->getTo());
- CPPUNIT_ASSERT_EQUAL(std::string(""), p->getStatus());
- }
-
- void testCreateInstant() {
- MUC::ref testling = createMUC(JID("rabbithole@wonderland.lit"));
- testling->joinAs("Alice");
- Presence::ref serverRespondsLocked = boost::make_shared<Presence>();
- serverRespondsLocked->setFrom(JID("rabbithole@wonderland.lit/Alice"));
- MUCUserPayload::ref mucPayload(new MUCUserPayload());
- MUCItem myItem;
- myItem.affiliation = MUCOccupant::Owner;
- myItem.role = MUCOccupant::Moderator;
- mucPayload->addItem(myItem);
- mucPayload->addStatusCode(MUCUserPayload::StatusCode(110));
- mucPayload->addStatusCode(MUCUserPayload::StatusCode(201));
- serverRespondsLocked->addPayload(mucPayload);
- channel->onPresenceReceived(serverRespondsLocked);
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel->sentStanzas.size()));
- IQ::ref iq = channel->getStanzaAtIndex<IQ>(1);
- CPPUNIT_ASSERT(iq);
- CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>());
- CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>()->getForm());
- CPPUNIT_ASSERT_EQUAL(Form::SubmitType, iq->getPayload<MUCOwnerPayload>()->getForm()->getType());
- }
-
- void testReplicateBug() {
- Presence::ref initialPresence = boost::make_shared<Presence>();
- initialPresence->setStatus("");
- VCard::ref vcard = boost::make_shared<VCard>();
- vcard->setPhoto(createByteArray("15c30080ae98ec48be94bf0e191d43edd06e500a"));
- initialPresence->addPayload(vcard);
- CapsInfo::ref caps = boost::make_shared<CapsInfo>();
- caps->setNode("http://swift.im");
- caps->setVersion("p2UP0DrcVgKM6jJqYN/B92DKK0o=");
- initialPresence->addPayload(caps);
- channel->sendPresence(initialPresence);
-
- MUC::ref testling = createMUC(JID("test@rooms.swift.im"));
- testling->joinAs("Test");
- Presence::ref serverRespondsLocked = boost::make_shared<Presence>();
- serverRespondsLocked->setFrom(JID("test@rooms.swift.im/Test"));
- serverRespondsLocked->setTo(JID("test@swift.im/6913d576d55f0b67"));
- serverRespondsLocked->addPayload(vcard);
- serverRespondsLocked->addPayload(caps);
- serverRespondsLocked->setStatus("");
- MUCUserPayload::ref mucPayload(new MUCUserPayload());
- MUCItem myItem;
- myItem.affiliation = MUCOccupant::Owner;
- myItem.role = MUCOccupant::Moderator;
- mucPayload->addItem(myItem);
- mucPayload->addStatusCode(MUCUserPayload::StatusCode(201));
- serverRespondsLocked->addPayload(mucPayload);
- channel->onPresenceReceived(serverRespondsLocked);
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(channel->sentStanzas.size()));
- IQ::ref iq = channel->getStanzaAtIndex<IQ>(2);
- CPPUNIT_ASSERT(iq);
- CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>());
- CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>()->getForm());
- CPPUNIT_ASSERT_EQUAL(Form::SubmitType, iq->getPayload<MUCOwnerPayload>()->getForm()->getType());
- }
-
- void testNicknameChange() {
- MUC::ref testling = createMUC(JID("foo@bar.com"));
- // Join as Rabbit
- testling->joinAs("Rabbit");
-
- // Rabbit joins
- Presence::ref rabbitJoins = boost::make_shared<Presence>();
- rabbitJoins->setTo("test@swift.im/6913d576d55f0b67");
- rabbitJoins->setFrom(testling->getJID().toString() + "/Rabbit");
- channel->onPresenceReceived(rabbitJoins);
- CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Rabbit"));
-
- // Alice joins
- Presence::ref aliceJoins = boost::make_shared<Presence>();
- aliceJoins->setTo("test@swift.im/6913d576d55f0b67");
- aliceJoins->setFrom(testling->getJID().toString() + "/Alice");
- channel->onPresenceReceived(aliceJoins);
- CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Alice"));
-
- // Change nick to Dodo
- testling->changeNickname("Dodo");
- Presence::ref stanza = channel->getStanzaAtIndex<Presence>(1);
- CPPUNIT_ASSERT(stanza);
- CPPUNIT_ASSERT_EQUAL(std::string("Dodo"), stanza->getTo().getResource());
-
- // Alice changes nick to Alice2
- stanza = boost::make_shared<Presence>();
- stanza->setFrom(JID("foo@bar.com/Alice"));
- stanza->setTo(JID(router->getJID()));
- stanza->setType(Presence::Unavailable);
- MUCUserPayload::ref mucPayload(new MUCUserPayload());
- MUCItem myItem;
- myItem.affiliation = MUCOccupant::Member;
- myItem.nick = "Alice2";
- myItem.role = MUCOccupant::Participant;
- mucPayload->addItem(myItem);
- mucPayload->addStatusCode(303);
- stanza->addPayload(mucPayload);
- channel->onPresenceReceived(stanza);
- CPPUNIT_ASSERT_EQUAL(1, nickChanges);
- CPPUNIT_ASSERT_EQUAL(false, testling->hasOccupant("Alice"));
- CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Alice2"));
-
- // We (Rabbit) change nick to Robot
- stanza = boost::make_shared<Presence>();
- stanza->setFrom(JID("foo@bar.com/Rabbit"));
- stanza->setTo(JID(router->getJID()));
- stanza->setType(Presence::Unavailable);
- mucPayload = MUCUserPayload::ref(new MUCUserPayload());
- myItem.affiliation = MUCOccupant::Member;
- myItem.nick = "Robot";
- myItem.role = MUCOccupant::Participant;
- mucPayload->addItem(myItem);
- mucPayload->addStatusCode(303);
- stanza->addPayload(mucPayload);
- channel->onPresenceReceived(stanza);
- CPPUNIT_ASSERT_EQUAL(2, nickChanges);
- CPPUNIT_ASSERT_EQUAL(false, testling->hasOccupant("Rabbit"));
- CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Robot"));
- }
-
- /*void testJoin_Success() {
- MUC::ref testling = createMUC(JID("foo@bar.com"));
- testling->onJoinFinished.connect(boost::bind(&MUCTest::handleJoinFinished, this, _1, _2));
- testling->joinAs("Alice");
- receivePresence(JID("foo@bar.com/Rabbit"), "Here");
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(joinResults.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("Alice"), joinResults[0].nick);
- CPPUNIT_ASSERT(joinResults[0].error);
- }
-
- void testJoin_Fail() {
- //CPPUNIT_ASSERT(!mucRegistry->isMUC(JID("foo@bar.com")));
- }*/
-
- private:
- MUC::ref createMUC(const JID& jid) {
- MUC::ref muc = boost::make_shared<MUCImpl>(channel, router, presenceSender, jid, mucRegistry);
- muc->onOccupantNicknameChanged.connect(boost::bind(&MUCTest::handleOccupantNicknameChanged, this, _1, _2));
- return muc;
- }
-
- void handleJoinFinished(const std::string& nick, ErrorPayload::ref error) {
- JoinResult r;
- r.nick = nick;
- r.error = error;
- joinResults.push_back(r);
- }
-
- void receivePresence(const JID& jid, const std::string& status) {
- Presence::ref p = Presence::create(status);
- p->setFrom(jid);
- //MUCUserPayload::ref mucUserPayload = boost::make_shared<MUCUserPayload>();
- //mucUserPayload->addItem(item);
- //p->addPayload(mucUserPayload);
- channel->onPresenceReceived(p);
- }
-
- void handleOccupantNicknameChanged(const std::string&, const std::string&) {
- nickChanges++;
- }
-
- private:
- DummyStanzaChannel* channel;
- IQRouter* router;
- MUCRegistry* mucRegistry;
- StanzaChannelPresenceSender* stanzaChannelPresenceSender;
- DirectedPresenceSender* presenceSender;
- struct JoinResult {
- std::string nick;
- ErrorPayload::ref error;
- };
- std::vector<JoinResult> joinResults;
- int nickChanges;
+ CPPUNIT_TEST_SUITE(MUCTest);
+ CPPUNIT_TEST(testJoin);
+ CPPUNIT_TEST(testJoin_ChangePresenceDuringJoinDoesNotSendPresenceBeforeJoinSuccess);
+ CPPUNIT_TEST(testJoin_ChangePresenceDuringJoinResendsPresenceAfterJoinSuccess);
+ CPPUNIT_TEST(testJoin_NoPresenceChangeDuringJoinDoesNotResendAfterJoinSuccess);
+ CPPUNIT_TEST(testCreateInstant);
+ CPPUNIT_TEST(testReplicateBug);
+ CPPUNIT_TEST(testNicknameChange);
+ /*CPPUNIT_TEST(testJoin_Success);
+ CPPUNIT_TEST(testJoin_Fail);*/
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ channel = new DummyStanzaChannel();
+ router = new IQRouter(channel);
+ mucRegistry = new MUCRegistry();
+ stanzaChannelPresenceSender = new StanzaChannelPresenceSender(channel);
+ presenceSender = new DirectedPresenceSender(stanzaChannelPresenceSender);
+ nickChanges = 0;
+ }
+
+ void tearDown() {
+ delete presenceSender;
+ delete stanzaChannelPresenceSender;
+ delete mucRegistry;
+ delete router;
+ delete channel;
+ }
+
+ void testJoin() {
+ MUC::ref testling = createMUC(JID("foo@bar.com"));
+ testling->joinAs("Alice");
+
+ CPPUNIT_ASSERT(mucRegistry->isMUC(JID("foo@bar.com")));
+ Presence::ref p = channel->getStanzaAtIndex<Presence>(0);
+ CPPUNIT_ASSERT(p);
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/Alice"), p->getTo());
+ }
+
+ void testJoin_ChangePresenceDuringJoinDoesNotSendPresenceBeforeJoinSuccess() {
+ MUC::ref testling = createMUC(JID("foo@bar.com"));
+ testling->joinAs("Alice");
+
+ presenceSender->sendPresence(Presence::create("Test"));
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel->sentStanzas.size()));
+ }
+
+ void testJoin_ChangePresenceDuringJoinResendsPresenceAfterJoinSuccess() {
+ MUC::ref testling = createMUC(JID("foo@bar.com"));
+ testling->joinAs("Alice");
+
+ presenceSender->sendPresence(Presence::create("Test"));
+ receivePresence(JID("foo@bar.com/Rabbit"), "Here");
+
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(channel->sentStanzas.size()));
+ Presence::ref p = channel->getStanzaAtIndex<Presence>(2);
+ CPPUNIT_ASSERT(p);
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/Alice"), p->getTo());
+ CPPUNIT_ASSERT_EQUAL(std::string("Test"), p->getStatus());
+ }
+
+ void testJoin_NoPresenceChangeDuringJoinDoesNotResendAfterJoinSuccess() {
+ MUC::ref testling = createMUC(JID("foo@bar.com"));
+ testling->joinAs("Alice");
+
+ receivePresence(JID("foo@bar.com/Rabbit"), "Here");
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->sentStanzas.size()));
+ Presence::ref p = channel->getStanzaAtIndex<Presence>(0);
+ CPPUNIT_ASSERT(p);
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/Alice"), p->getTo());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), p->getStatus());
+ }
+
+ void testCreateInstant() {
+ MUC::ref testling = createMUC(JID("rabbithole@wonderland.lit"));
+ testling->joinAs("Alice");
+ Presence::ref serverRespondsLocked = boost::make_shared<Presence>();
+ serverRespondsLocked->setFrom(JID("rabbithole@wonderland.lit/Alice"));
+ MUCUserPayload::ref mucPayload(new MUCUserPayload());
+ MUCItem myItem;
+ myItem.affiliation = MUCOccupant::Owner;
+ myItem.role = MUCOccupant::Moderator;
+ mucPayload->addItem(myItem);
+ mucPayload->addStatusCode(MUCUserPayload::StatusCode(110));
+ mucPayload->addStatusCode(MUCUserPayload::StatusCode(201));
+ serverRespondsLocked->addPayload(mucPayload);
+ channel->onPresenceReceived(serverRespondsLocked);
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel->sentStanzas.size()));
+ IQ::ref iq = channel->getStanzaAtIndex<IQ>(1);
+ CPPUNIT_ASSERT(iq);
+ CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>());
+ CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>()->getForm());
+ CPPUNIT_ASSERT_EQUAL(Form::SubmitType, iq->getPayload<MUCOwnerPayload>()->getForm()->getType());
+ }
+
+ void testReplicateBug() {
+ Presence::ref initialPresence = boost::make_shared<Presence>();
+ initialPresence->setStatus("");
+ VCard::ref vcard = boost::make_shared<VCard>();
+ vcard->setPhoto(createByteArray("15c30080ae98ec48be94bf0e191d43edd06e500a"));
+ initialPresence->addPayload(vcard);
+ CapsInfo::ref caps = boost::make_shared<CapsInfo>();
+ caps->setNode("http://swift.im");
+ caps->setVersion("p2UP0DrcVgKM6jJqYN/B92DKK0o=");
+ initialPresence->addPayload(caps);
+ channel->sendPresence(initialPresence);
+
+ MUC::ref testling = createMUC(JID("test@rooms.swift.im"));
+ testling->joinAs("Test");
+ Presence::ref serverRespondsLocked = boost::make_shared<Presence>();
+ serverRespondsLocked->setFrom(JID("test@rooms.swift.im/Test"));
+ serverRespondsLocked->setTo(JID("test@swift.im/6913d576d55f0b67"));
+ serverRespondsLocked->addPayload(vcard);
+ serverRespondsLocked->addPayload(caps);
+ serverRespondsLocked->setStatus("");
+ MUCUserPayload::ref mucPayload(new MUCUserPayload());
+ MUCItem myItem;
+ myItem.affiliation = MUCOccupant::Owner;
+ myItem.role = MUCOccupant::Moderator;
+ mucPayload->addItem(myItem);
+ mucPayload->addStatusCode(MUCUserPayload::StatusCode(201));
+ serverRespondsLocked->addPayload(mucPayload);
+ channel->onPresenceReceived(serverRespondsLocked);
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(channel->sentStanzas.size()));
+ IQ::ref iq = channel->getStanzaAtIndex<IQ>(2);
+ CPPUNIT_ASSERT(iq);
+ CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>());
+ CPPUNIT_ASSERT(iq->getPayload<MUCOwnerPayload>()->getForm());
+ CPPUNIT_ASSERT_EQUAL(Form::SubmitType, iq->getPayload<MUCOwnerPayload>()->getForm()->getType());
+ }
+
+ void testNicknameChange() {
+ MUC::ref testling = createMUC(JID("foo@bar.com"));
+ // Join as Rabbit
+ testling->joinAs("Rabbit");
+
+ // Rabbit joins
+ Presence::ref rabbitJoins = boost::make_shared<Presence>();
+ rabbitJoins->setTo("test@swift.im/6913d576d55f0b67");
+ rabbitJoins->setFrom(testling->getJID().toString() + "/Rabbit");
+ channel->onPresenceReceived(rabbitJoins);
+ CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Rabbit"));
+
+ // Alice joins
+ Presence::ref aliceJoins = boost::make_shared<Presence>();
+ aliceJoins->setTo("test@swift.im/6913d576d55f0b67");
+ aliceJoins->setFrom(testling->getJID().toString() + "/Alice");
+ channel->onPresenceReceived(aliceJoins);
+ CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Alice"));
+
+ // Change nick to Dodo
+ testling->changeNickname("Dodo");
+ Presence::ref stanza = channel->getStanzaAtIndex<Presence>(1);
+ CPPUNIT_ASSERT(stanza);
+ CPPUNIT_ASSERT_EQUAL(std::string("Dodo"), stanza->getTo().getResource());
+
+ // Alice changes nick to Alice2
+ stanza = boost::make_shared<Presence>();
+ stanza->setFrom(JID("foo@bar.com/Alice"));
+ stanza->setTo(JID(router->getJID()));
+ stanza->setType(Presence::Unavailable);
+ MUCUserPayload::ref mucPayload(new MUCUserPayload());
+ MUCItem myItem;
+ myItem.affiliation = MUCOccupant::Member;
+ myItem.nick = "Alice2";
+ myItem.role = MUCOccupant::Participant;
+ mucPayload->addItem(myItem);
+ mucPayload->addStatusCode(303);
+ stanza->addPayload(mucPayload);
+ channel->onPresenceReceived(stanza);
+ CPPUNIT_ASSERT_EQUAL(1, nickChanges);
+ CPPUNIT_ASSERT_EQUAL(false, testling->hasOccupant("Alice"));
+ CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Alice2"));
+
+ // We (Rabbit) change nick to Robot
+ stanza = boost::make_shared<Presence>();
+ stanza->setFrom(JID("foo@bar.com/Rabbit"));
+ stanza->setTo(JID(router->getJID()));
+ stanza->setType(Presence::Unavailable);
+ mucPayload = MUCUserPayload::ref(new MUCUserPayload());
+ myItem.affiliation = MUCOccupant::Member;
+ myItem.nick = "Robot";
+ myItem.role = MUCOccupant::Participant;
+ mucPayload->addItem(myItem);
+ mucPayload->addStatusCode(303);
+ stanza->addPayload(mucPayload);
+ channel->onPresenceReceived(stanza);
+ CPPUNIT_ASSERT_EQUAL(2, nickChanges);
+ CPPUNIT_ASSERT_EQUAL(false, testling->hasOccupant("Rabbit"));
+ CPPUNIT_ASSERT_EQUAL(true, testling->hasOccupant("Robot"));
+ }
+
+ /*void testJoin_Success() {
+ MUC::ref testling = createMUC(JID("foo@bar.com"));
+ testling->onJoinFinished.connect(boost::bind(&MUCTest::handleJoinFinished, this, _1, _2));
+ testling->joinAs("Alice");
+ receivePresence(JID("foo@bar.com/Rabbit"), "Here");
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(joinResults.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Alice"), joinResults[0].nick);
+ CPPUNIT_ASSERT(joinResults[0].error);
+ }
+
+ void testJoin_Fail() {
+ //CPPUNIT_ASSERT(!mucRegistry->isMUC(JID("foo@bar.com")));
+ }*/
+
+ private:
+ MUC::ref createMUC(const JID& jid) {
+ MUC::ref muc = boost::make_shared<MUCImpl>(channel, router, presenceSender, jid, mucRegistry);
+ muc->onOccupantNicknameChanged.connect(boost::bind(&MUCTest::handleOccupantNicknameChanged, this, _1, _2));
+ return muc;
+ }
+
+ void handleJoinFinished(const std::string& nick, ErrorPayload::ref error) {
+ JoinResult r;
+ r.nick = nick;
+ r.error = error;
+ joinResults.push_back(r);
+ }
+
+ void receivePresence(const JID& jid, const std::string& status) {
+ Presence::ref p = Presence::create(status);
+ p->setFrom(jid);
+ //MUCUserPayload::ref mucUserPayload = boost::make_shared<MUCUserPayload>();
+ //mucUserPayload->addItem(item);
+ //p->addPayload(mucUserPayload);
+ channel->onPresenceReceived(p);
+ }
+
+ void handleOccupantNicknameChanged(const std::string&, const std::string&) {
+ nickChanges++;
+ }
+
+ private:
+ DummyStanzaChannel* channel;
+ IQRouter* router;
+ MUCRegistry* mucRegistry;
+ StanzaChannelPresenceSender* stanzaChannelPresenceSender;
+ DirectedPresenceSender* presenceSender;
+ struct JoinResult {
+ std::string nick;
+ ErrorPayload::ref error;
+ };
+ std::vector<JoinResult> joinResults;
+ int nickChanges;
};
CPPUNIT_TEST_SUITE_REGISTRATION(MUCTest);
diff --git a/Swiften/MUC/UnitTest/MockMUC.cpp b/Swiften/MUC/UnitTest/MockMUC.cpp
index 6131183..93e7d0b 100644
--- a/Swiften/MUC/UnitTest/MockMUC.cpp
+++ b/Swiften/MUC/UnitTest/MockMUC.cpp
@@ -18,34 +18,34 @@ MockMUC::~MockMUC() {
void MockMUC::insertOccupant(const MUCOccupant& occupant)
{
- occupants_.insert(std::make_pair(occupant.getNick(), occupant));
- onOccupantJoined(occupant);
+ occupants_.insert(std::make_pair(occupant.getNick(), occupant));
+ onOccupantJoined(occupant);
}
const MUCOccupant& MockMUC::getOccupant(const std::string& nick) {
- return occupants_.find(nick)->second;
+ return occupants_.find(nick)->second;
}
bool MockMUC::hasOccupant(const std::string& nick) {
- return occupants_.find(nick) != occupants_.end();
+ return occupants_.find(nick) != occupants_.end();
}
void MockMUC::changeAffiliation(const JID &jid, MUCOccupant::Affiliation newAffilation) {
- std::map<std::string, MUCOccupant>::iterator i = occupants_.find(jid.getResource());
- if (i != occupants_.end()) {
- const MUCOccupant old = i->second;
- i->second = MUCOccupant(old.getNick(), old.getRole(), newAffilation);
- onOccupantAffiliationChanged(i->first, newAffilation, old.getAffiliation());
- }
+ std::map<std::string, MUCOccupant>::iterator i = occupants_.find(jid.getResource());
+ if (i != occupants_.end()) {
+ const MUCOccupant old = i->second;
+ i->second = MUCOccupant(old.getNick(), old.getRole(), newAffilation);
+ onOccupantAffiliationChanged(i->first, newAffilation, old.getAffiliation());
+ }
}
void MockMUC::changeOccupantRole(const JID &jid, MUCOccupant::Role newRole) {
- std::map<std::string, MUCOccupant>::iterator i = occupants_.find(jid.getResource());
- if (i != occupants_.end()) {
- const MUCOccupant old = i->second;
- i->second = MUCOccupant(old.getNick(), newRole, old.getAffiliation());
- onOccupantRoleChanged(i->first, i->second, old.getRole());
- }
+ std::map<std::string, MUCOccupant>::iterator i = occupants_.find(jid.getResource());
+ if (i != occupants_.end()) {
+ const MUCOccupant old = i->second;
+ i->second = MUCOccupant(old.getNick(), newRole, old.getAffiliation());
+ onOccupantRoleChanged(i->first, i->second, old.getRole());
+ }
}
}
diff --git a/Swiften/MUC/UnitTest/MockMUC.h b/Swiften/MUC/UnitTest/MockMUC.h
index c54e738..c61f8a9 100644
--- a/Swiften/MUC/UnitTest/MockMUC.h
+++ b/Swiften/MUC/UnitTest/MockMUC.h
@@ -25,74 +25,74 @@
#include <Swiften/MUC/MUCRegistry.h>
namespace Swift {
- class StanzaChannel;
- class IQRouter;
- class DirectedPresenceSender;
+ class StanzaChannel;
+ class IQRouter;
+ class DirectedPresenceSender;
- class SWIFTEN_API MockMUC : public MUC{
- public:
- typedef boost::shared_ptr<MockMUC> ref;
+ class SWIFTEN_API MockMUC : public MUC{
+ public:
+ typedef boost::shared_ptr<MockMUC> ref;
- public:
- MockMUC(const JID &muc);
- virtual ~MockMUC();
+ public:
+ MockMUC(const JID &muc);
+ virtual ~MockMUC();
- /**
- * Cause a user to appear to have entered the room. For testing only.
- */
- void insertOccupant(const MUCOccupant& occupant);
+ /**
+ * Cause a user to appear to have entered the room. For testing only.
+ */
+ void insertOccupant(const MUCOccupant& occupant);
- /**
- * Returns the (bare) JID of the MUC.
- */
- virtual JID getJID() const {
- return ownMUCJID.toBare();
- }
- /**
- * Returns if the room is unlocked and other people can join the room.
- * @return True if joinable by others; false otherwise.
- */
- virtual bool isUnlocked() const { return true; }
+ /**
+ * Returns the (bare) JID of the MUC.
+ */
+ virtual JID getJID() const {
+ return ownMUCJID.toBare();
+ }
+ /**
+ * Returns if the room is unlocked and other people can join the room.
+ * @return True if joinable by others; false otherwise.
+ */
+ virtual bool isUnlocked() const { return true; }
- virtual void joinAs(const std::string&) {}
- virtual void joinWithContextSince(const std::string&, const boost::posix_time::ptime&) {}
- /*virtual void queryRoomInfo(); */
- /*virtual void queryRoomItems(); */
- /*virtual std::string getCurrentNick() = 0; */
- virtual std::map<std::string, MUCOccupant> getOccupants() const { return occupants_; }
- virtual void changeNickname(const std::string&) { }
- virtual void part() {}
- /*virtual void handleIncomingMessage(Message::ref message) = 0; */
- /** Expose public so it can be called when e.g. user goes offline */
- virtual void handleUserLeft(LeavingType) {}
- /** Get occupant information*/
- virtual const MUCOccupant& getOccupant(const std::string&);
- virtual bool hasOccupant(const std::string&);
- virtual void kickOccupant(const JID&) {}
- virtual void changeOccupantRole(const JID&, MUCOccupant::Role);
- virtual void requestAffiliationList(MUCOccupant::Affiliation) {}
- virtual void changeAffiliation(const JID&, MUCOccupant::Affiliation);
- virtual void changeSubject(const std::string&) {}
- virtual void requestConfigurationForm() {}
- virtual void configureRoom(Form::ref) {}
- virtual void cancelConfigureRoom() {}
- virtual void destroyRoom() {}
- /** Send an invite for the person to join the MUC */
- virtual void invitePerson(const JID&, const std::string&, bool, bool) {}
- virtual void setCreateAsReservedIfNew() {}
- virtual void setPassword(const boost::optional<std::string>&) {}
+ virtual void joinAs(const std::string&) {}
+ virtual void joinWithContextSince(const std::string&, const boost::posix_time::ptime&) {}
+ /*virtual void queryRoomInfo(); */
+ /*virtual void queryRoomItems(); */
+ /*virtual std::string getCurrentNick() = 0; */
+ virtual std::map<std::string, MUCOccupant> getOccupants() const { return occupants_; }
+ virtual void changeNickname(const std::string&) { }
+ virtual void part() {}
+ /*virtual void handleIncomingMessage(Message::ref message) = 0; */
+ /** Expose public so it can be called when e.g. user goes offline */
+ virtual void handleUserLeft(LeavingType) {}
+ /** Get occupant information*/
+ virtual const MUCOccupant& getOccupant(const std::string&);
+ virtual bool hasOccupant(const std::string&);
+ virtual void kickOccupant(const JID&) {}
+ virtual void changeOccupantRole(const JID&, MUCOccupant::Role);
+ virtual void requestAffiliationList(MUCOccupant::Affiliation) {}
+ virtual void changeAffiliation(const JID&, MUCOccupant::Affiliation);
+ virtual void changeSubject(const std::string&) {}
+ virtual void requestConfigurationForm() {}
+ virtual void configureRoom(Form::ref) {}
+ virtual void cancelConfigureRoom() {}
+ virtual void destroyRoom() {}
+ /** Send an invite for the person to join the MUC */
+ virtual void invitePerson(const JID&, const std::string&, bool, bool) {}
+ virtual void setCreateAsReservedIfNew() {}
+ virtual void setPassword(const boost::optional<std::string>&) {}
- protected:
- virtual bool isFromMUC(const JID& j) const {
- return ownMUCJID.equals(j, JID::WithoutResource);
- }
+ protected:
+ virtual bool isFromMUC(const JID& j) const {
+ return ownMUCJID.equals(j, JID::WithoutResource);
+ }
- virtual const std::string& getOwnNick() const {
- return ownMUCJID.getResource();
- }
+ virtual const std::string& getOwnNick() const {
+ return ownMUCJID.getResource();
+ }
- private:
- JID ownMUCJID;
- std::map<std::string, MUCOccupant> occupants_;
- };
+ private:
+ JID ownMUCJID;
+ std::map<std::string, MUCOccupant> occupants_;
+ };
}