summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-12-20 09:51:03 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-12-20 11:09:05 (GMT)
commit241bbe1c1a5755972f3ec0532befa9329631934e (patch)
tree740b4d6d4e8f010260b3cf05857379072d605341 /Swiften/Presence/UnitTest
parentee8e00ba6abb5a61ba51c0c75806b67242364dc6 (diff)
downloadswift-contrib-241bbe1c1a5755972f3ec0532befa9329631934e.zip
swift-contrib-241bbe1c1a5755972f3ec0532befa9329631934e.tar.bz2
Don't immediately send presence unneccesarily when registering directed presence senders.
Hopefully Resolves: #691 Release-Notes: We hope to have fixed the bug where a MUC room would go into loop of parting and joining continually.
Diffstat (limited to 'Swiften/Presence/UnitTest')
-rw-r--r--Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp b/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp
index a60c429..80f5ebd 100644
--- a/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp
+++ b/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp
@@ -19,8 +19,10 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testSendPresence_UndirectedPresenceWithDirectedPresenceReceivers);
CPPUNIT_TEST(testSendPresence_DirectedPresenceWithDirectedPresenceReceivers);
CPPUNIT_TEST(testAddDirectedPresenceReceiver);
+ CPPUNIT_TEST(testAddDirectedPresenceReceiver_WithoutSendingPresence);
CPPUNIT_TEST(testAddDirectedPresenceReceiver_AfterSendingDirectedPresence);
CPPUNIT_TEST(testRemoveDirectedPresenceReceiver);
+ CPPUNIT_TEST(testRemoveDirectedPresenceReceiver_WithoutSendingPresence);
CPPUNIT_TEST_SUITE_END();
public:
@@ -49,7 +51,7 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
void testSendPresence_UndirectedPresenceWithDirectedPresenceReceivers() {
std::auto_ptr<DirectedPresenceSender> testling(createPresenceSender());
- testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"));
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::AndSendPresence);
testling->sendPresence(testPresence);
@@ -63,7 +65,7 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
void testSendPresence_DirectedPresenceWithDirectedPresenceReceivers() {
std::auto_ptr<DirectedPresenceSender> testling(createPresenceSender());
- testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"));
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::AndSendPresence);
channel->sentStanzas.clear();
testPresence->setTo(JID("foo@bar.com"));
@@ -79,7 +81,7 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
testling->sendPresence(testPresence);
channel->sentStanzas.clear();
- testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"));
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::AndSendPresence);
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->sentStanzas.size()));
boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(channel->sentStanzas[0]);
@@ -87,6 +89,16 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/teaparty"), presence->getTo());
}
+ void testAddDirectedPresenceReceiver_WithoutSendingPresence() {
+ std::auto_ptr<DirectedPresenceSender> testling(createPresenceSender());
+ testling->sendPresence(testPresence);
+ channel->sentStanzas.clear();
+
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::DontSendPresence);
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel->sentStanzas.size()));
+ }
+
void testAddDirectedPresenceReceiver_AfterSendingDirectedPresence() {
std::auto_ptr<DirectedPresenceSender> testling(createPresenceSender());
testling->sendPresence(testPresence);
@@ -94,7 +106,7 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
testling->sendPresence(secondTestPresence);
channel->sentStanzas.clear();
- testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"));
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::AndSendPresence);
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->sentStanzas.size()));
boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(channel->sentStanzas[0]);
@@ -104,10 +116,9 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
void testRemoveDirectedPresenceReceiver() {
std::auto_ptr<DirectedPresenceSender> testling(createPresenceSender());
- testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"));
- channel->sentStanzas.clear();
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::DontSendPresence);
- testling->removeDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"));
+ testling->removeDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::AndSendPresence);
testling->sendPresence(testPresence);
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel->sentStanzas.size()));
@@ -115,6 +126,18 @@ class DirectedPresenceSenderTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(channel->sentStanzas[1] == testPresence);
}
+ void testRemoveDirectedPresenceReceiver_WithoutSendingPresence() {
+ std::auto_ptr<DirectedPresenceSender> testling(createPresenceSender());
+ testling->addDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::AndSendPresence);
+ channel->sentStanzas.clear();
+
+ testling->removeDirectedPresenceReceiver(JID("alice@wonderland.lit/teaparty"), DirectedPresenceSender::DontSendPresence);
+ testling->sendPresence(testPresence);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->sentStanzas.size()));
+ CPPUNIT_ASSERT(channel->sentStanzas[0] == testPresence);
+ }
+
private:
DirectedPresenceSender* createPresenceSender() {
return new DirectedPresenceSender(stanzaChannelPresenceSender);