summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-06 16:20:30 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-06 16:21:22 (GMT)
commitebccdadcae24932b299a8612a9c6e0cdc4e00249 (patch)
tree8e56f94c023c9f3b079bcd9fd00d7983f708014d /Swiften/StreamManagement/UnitTest
parent1e2c3461458f4274d539daf51507ce81d845cce0 (diff)
downloadswift-contrib-ebccdadcae24932b299a8612a9c6e0cdc4e00249.zip
swift-contrib-ebccdadcae24932b299a8612a9c6e0cdc4e00249.tar.bz2
Only request acks after a message was sent.
Diffstat (limited to 'Swiften/StreamManagement/UnitTest')
-rw-r--r--Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp b/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp
index 70fe6eb..e53b8c6 100644
--- a/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp
+++ b/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp
@@ -11,6 +11,8 @@
#include "Swiften/StreamManagement/StanzaAckRequester.h"
#include "Swiften/Elements/Message.h"
+#include "Swiften/Elements/Presence.h"
+#include "Swiften/Elements/IQ.h"
using namespace Swift;
@@ -18,8 +20,11 @@ namespace Swift {
class StanzaAckRequesterTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(StanzaAckRequesterTest);
- CPPUNIT_TEST(testHandleStanzaSent_RequestsAck);
+ CPPUNIT_TEST(testHandleStanzaSent_MessageRequestsAck);
+ CPPUNIT_TEST(testHandleStanzaSent_IQDoesNotRequestAck);
+ CPPUNIT_TEST(testHandleStanzaSent_PresenceDoesNotRequestAck);
CPPUNIT_TEST(testHandleAckReceived_AcksStanza);
+ CPPUNIT_TEST(testHandleAckReceived_AcksMultipleMessages);
CPPUNIT_TEST(testHandleAckReceived_AcksMultipleStanzas);
CPPUNIT_TEST(testHandleAckReceived_MultipleAcks);
CPPUNIT_TEST(testHandleAckReceived_WrapAround);
@@ -30,13 +35,27 @@ class StanzaAckRequesterTest : public CppUnit::TestFixture {
acksRequested = 0;
}
- void testHandleStanzaSent_RequestsAck() {
+ void testHandleStanzaSent_MessageRequestsAck() {
std::auto_ptr<StanzaAckRequester> testling(createRequester());
testling->handleStanzaSent(createMessage("m1"));
CPPUNIT_ASSERT_EQUAL(1, acksRequested);
}
+ void testHandleStanzaSent_IQDoesNotRequestAck() {
+ std::auto_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createIQ("iq1"));
+
+ CPPUNIT_ASSERT_EQUAL(0, acksRequested);
+ }
+
+ void testHandleStanzaSent_PresenceDoesNotRequestAck() {
+ std::auto_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createPresence("p1"));
+
+ CPPUNIT_ASSERT_EQUAL(0, acksRequested);
+ }
+
void testHandleAckReceived_AcksStanza() {
std::auto_ptr<StanzaAckRequester> testling(createRequester());
testling->handleStanzaSent(createMessage("m1"));
@@ -47,7 +66,7 @@ class StanzaAckRequesterTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(String("m1"), ackedStanzas[0]->getID());
}
- void testHandleAckReceived_AcksMultipleStanzas() {
+ void testHandleAckReceived_AcksMultipleMessages() {
std::auto_ptr<StanzaAckRequester> testling(createRequester());
testling->handleStanzaSent(createMessage("m1"));
testling->handleStanzaSent(createMessage("m2"));
@@ -59,6 +78,20 @@ class StanzaAckRequesterTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(String("m2"), ackedStanzas[1]->getID());
}
+ void testHandleAckReceived_AcksMultipleStanzas() {
+ std::auto_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createIQ("iq1"));
+ testling->handleStanzaSent(createPresence("p1"));
+ testling->handleStanzaSent(createMessage("m1"));
+
+ testling->handleAckReceived(3);
+
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(ackedStanzas.size()));
+ CPPUNIT_ASSERT_EQUAL(String("iq1"), ackedStanzas[0]->getID());
+ CPPUNIT_ASSERT_EQUAL(String("p1"), ackedStanzas[1]->getID());
+ CPPUNIT_ASSERT_EQUAL(String("m1"), ackedStanzas[2]->getID());
+ }
+
void testHandleAckReceived_MultipleAcks() {
std::auto_ptr<StanzaAckRequester> testling(createRequester());
testling->handleStanzaSent(createMessage("m1"));
@@ -95,6 +128,18 @@ class StanzaAckRequesterTest : public CppUnit::TestFixture {
return result;
}
+ IQ::ref createIQ(const String& id) {
+ IQ::ref result(new IQ());
+ result->setID(id);
+ return result;
+ }
+
+ Presence::ref createPresence(const String& id) {
+ Presence::ref result(new Presence());
+ result->setID(id);
+ return result;
+ }
+
StanzaAckRequester* createRequester() {
StanzaAckRequester* requester = new StanzaAckRequester();
requester->onRequestAck.connect(boost::bind(&StanzaAckRequesterTest::handleRequestAck, this));