summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Elements/Presence.h4
-rw-r--r--Swiften/StreamManagement/StanzaAckRequester.cpp6
-rw-r--r--Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp51
3 files changed, 55 insertions, 6 deletions
diff --git a/Swiften/Elements/Presence.h b/Swiften/Elements/Presence.h
index 311c2cf..0789b18 100644
--- a/Swiften/Elements/Presence.h
+++ b/Swiften/Elements/Presence.h
@@ -6,14 +6,14 @@
#pragma once
+#include "Swiften/Base/Shared.h"
#include "Swiften/Elements/Stanza.h"
#include "Swiften/Elements/Status.h"
#include "Swiften/Elements/StatusShow.h"
#include "Swiften/Elements/Priority.h"
namespace Swift {
- class Presence : public Stanza
- {
+ class Presence : public Stanza, public Shared<Presence> {
public:
enum Type { Available, Error, Probe, Subscribe, Subscribed, Unavailable, Unsubscribe, Unsubscribed };
diff --git a/Swiften/StreamManagement/StanzaAckRequester.cpp b/Swiften/StreamManagement/StanzaAckRequester.cpp
index b007675..f7d603b 100644
--- a/Swiften/StreamManagement/StanzaAckRequester.cpp
+++ b/Swiften/StreamManagement/StanzaAckRequester.cpp
@@ -8,6 +8,8 @@
#include <boost/numeric/conversion/cast.hpp>
+#include "Swiften/Elements/Message.h"
+
namespace Swift {
static const unsigned int MAX_HANDLED_STANZA_COUNT = boost::numeric_cast<unsigned int>((1ULL<<32) - 1);
@@ -18,7 +20,9 @@ StanzaAckRequester::StanzaAckRequester() : lastHandledStanzasCount(0) {
void StanzaAckRequester::handleStanzaSent(boost::shared_ptr<Stanza> stanza) {
unackedStanzas.push_back(stanza);
- onRequestAck();
+ if (boost::dynamic_pointer_cast<Message>(stanza)) {
+ onRequestAck();
+ }
}
void StanzaAckRequester::handleAckReceived(unsigned int handledStanzasCount) {
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));