summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StreamManagement')
-rw-r--r--Swiften/StreamManagement/StanzaAckRequester.cpp32
-rw-r--r--Swiften/StreamManagement/StanzaAckRequester.h32
-rw-r--r--Swiften/StreamManagement/StanzaAckResponder.cpp4
-rw-r--r--Swiften/StreamManagement/StanzaAckResponder.h22
-rw-r--r--Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp278
-rw-r--r--Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp148
6 files changed, 258 insertions, 258 deletions
diff --git a/Swiften/StreamManagement/StanzaAckRequester.cpp b/Swiften/StreamManagement/StanzaAckRequester.cpp
index 07927ac..ceafe28 100644
--- a/Swiften/StreamManagement/StanzaAckRequester.cpp
+++ b/Swiften/StreamManagement/StanzaAckRequester.cpp
@@ -21,25 +21,25 @@ StanzaAckRequester::StanzaAckRequester() : lastHandledStanzasCount(0) {
}
void StanzaAckRequester::handleStanzaSent(boost::shared_ptr<Stanza> stanza) {
- unackedStanzas.push_back(stanza);
- if (boost::dynamic_pointer_cast<Message>(stanza)) {
- onRequestAck();
- }
+ unackedStanzas.push_back(stanza);
+ if (boost::dynamic_pointer_cast<Message>(stanza)) {
+ onRequestAck();
+ }
}
void StanzaAckRequester::handleAckReceived(unsigned int handledStanzasCount) {
- unsigned int i = lastHandledStanzasCount;
- while (i != handledStanzasCount) {
- if (unackedStanzas.empty()) {
- std::cerr << "Warning: Server acked more stanzas than we sent" << std::endl;
- break;
- }
- boost::shared_ptr<Stanza> ackedStanza = unackedStanzas.front();
- unackedStanzas.pop_front();
- onStanzaAcked(ackedStanza);
- i = (i == MAX_HANDLED_STANZA_COUNT ? 0 : i + 1);
- }
- lastHandledStanzasCount = handledStanzasCount;
+ unsigned int i = lastHandledStanzasCount;
+ while (i != handledStanzasCount) {
+ if (unackedStanzas.empty()) {
+ std::cerr << "Warning: Server acked more stanzas than we sent" << std::endl;
+ break;
+ }
+ boost::shared_ptr<Stanza> ackedStanza = unackedStanzas.front();
+ unackedStanzas.pop_front();
+ onStanzaAcked(ackedStanza);
+ i = (i == MAX_HANDLED_STANZA_COUNT ? 0 : i + 1);
+ }
+ lastHandledStanzasCount = handledStanzasCount;
}
}
diff --git a/Swiften/StreamManagement/StanzaAckRequester.h b/Swiften/StreamManagement/StanzaAckRequester.h
index 6b04238..4d913bb 100644
--- a/Swiften/StreamManagement/StanzaAckRequester.h
+++ b/Swiften/StreamManagement/StanzaAckRequester.h
@@ -15,21 +15,21 @@
#include <Swiften/Elements/Stanza.h>
namespace Swift {
- class SWIFTEN_API StanzaAckRequester {
- public:
- StanzaAckRequester();
-
- void handleStanzaSent(boost::shared_ptr<Stanza> stanza);
- void handleAckReceived(unsigned int handledStanzasCount);
-
- public:
- boost::signal<void ()> onRequestAck;
- boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaAcked;
-
- private:
- friend class StanzaAckRequesterTest;
- unsigned int lastHandledStanzasCount;
- std::deque<boost::shared_ptr<Stanza> > unackedStanzas;
- };
+ class SWIFTEN_API StanzaAckRequester {
+ public:
+ StanzaAckRequester();
+
+ void handleStanzaSent(boost::shared_ptr<Stanza> stanza);
+ void handleAckReceived(unsigned int handledStanzasCount);
+
+ public:
+ boost::signal<void ()> onRequestAck;
+ boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaAcked;
+
+ private:
+ friend class StanzaAckRequesterTest;
+ unsigned int lastHandledStanzasCount;
+ std::deque<boost::shared_ptr<Stanza> > unackedStanzas;
+ };
}
diff --git a/Swiften/StreamManagement/StanzaAckResponder.cpp b/Swiften/StreamManagement/StanzaAckResponder.cpp
index ee6f077..b6171d0 100644
--- a/Swiften/StreamManagement/StanzaAckResponder.cpp
+++ b/Swiften/StreamManagement/StanzaAckResponder.cpp
@@ -16,11 +16,11 @@ StanzaAckResponder::StanzaAckResponder() : handledStanzasCount(0) {
}
void StanzaAckResponder::handleStanzaReceived() {
- handledStanzasCount = (handledStanzasCount == MAX_HANDLED_STANZA_COUNT ? 0 : handledStanzasCount + 1);
+ handledStanzasCount = (handledStanzasCount == MAX_HANDLED_STANZA_COUNT ? 0 : handledStanzasCount + 1);
}
void StanzaAckResponder::handleAckRequestReceived() {
- onAck(handledStanzasCount);
+ onAck(handledStanzasCount);
}
}
diff --git a/Swiften/StreamManagement/StanzaAckResponder.h b/Swiften/StreamManagement/StanzaAckResponder.h
index a2e1f42..16c8825 100644
--- a/Swiften/StreamManagement/StanzaAckResponder.h
+++ b/Swiften/StreamManagement/StanzaAckResponder.h
@@ -13,19 +13,19 @@
#include <Swiften/Elements/Stanza.h>
namespace Swift {
- class SWIFTEN_API StanzaAckResponder {
- public:
- StanzaAckResponder();
+ class SWIFTEN_API StanzaAckResponder {
+ public:
+ StanzaAckResponder();
- void handleStanzaReceived();
- void handleAckRequestReceived();
+ void handleStanzaReceived();
+ void handleAckRequestReceived();
- public:
- boost::signal<void (unsigned int /* handledStanzaCount */)> onAck;
+ public:
+ boost::signal<void (unsigned int /* handledStanzaCount */)> onAck;
- private:
- friend class StanzaAckResponderTest;
- unsigned int handledStanzasCount;
- };
+ private:
+ friend class StanzaAckResponderTest;
+ unsigned int handledStanzasCount;
+ };
}
diff --git a/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp b/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp
index 99713a9..55e6012 100644
--- a/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp
+++ b/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp
@@ -20,145 +20,145 @@ using namespace Swift;
namespace Swift {
class StanzaAckRequesterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(StanzaAckRequesterTest);
- 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);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- acksRequested = 0;
- }
-
- void testHandleStanzaSent_MessageRequestsAck() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->handleStanzaSent(createMessage("m1"));
-
- CPPUNIT_ASSERT_EQUAL(1, acksRequested);
- }
-
- void testHandleStanzaSent_IQDoesNotRequestAck() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->handleStanzaSent(createIQ("iq1"));
-
- CPPUNIT_ASSERT_EQUAL(0, acksRequested);
- }
-
- void testHandleStanzaSent_PresenceDoesNotRequestAck() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->handleStanzaSent(createPresence("p1"));
-
- CPPUNIT_ASSERT_EQUAL(0, acksRequested);
- }
-
- void testHandleAckReceived_AcksStanza() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->handleStanzaSent(createMessage("m1"));
-
- testling->handleAckReceived(1);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(ackedStanzas.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
- }
-
- void testHandleAckReceived_AcksMultipleMessages() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->handleStanzaSent(createMessage("m1"));
- testling->handleStanzaSent(createMessage("m2"));
-
- testling->handleAckReceived(2);
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(ackedStanzas.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
- CPPUNIT_ASSERT_EQUAL(std::string("m2"), ackedStanzas[1]->getID());
- }
-
- void testHandleAckReceived_AcksMultipleStanzas() {
- boost::shared_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(std::string("iq1"), ackedStanzas[0]->getID());
- CPPUNIT_ASSERT_EQUAL(std::string("p1"), ackedStanzas[1]->getID());
- CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[2]->getID());
- }
-
- void testHandleAckReceived_MultipleAcks() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->handleStanzaSent(createMessage("m1"));
- testling->handleAckReceived(1);
-
- testling->handleStanzaSent(createMessage("m2"));
- testling->handleStanzaSent(createMessage("m3"));
- testling->handleAckReceived(3);
-
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(ackedStanzas.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
- CPPUNIT_ASSERT_EQUAL(std::string("m2"), ackedStanzas[1]->getID());
- CPPUNIT_ASSERT_EQUAL(std::string("m3"), ackedStanzas[2]->getID());
- }
-
- // Handle stanza ack count wrapping, as per the XEP
- void testHandleAckReceived_WrapAround() {
- boost::shared_ptr<StanzaAckRequester> testling(createRequester());
- testling->lastHandledStanzasCount = boost::numeric_cast<unsigned int>((1ULL<<32) - 1);
- testling->handleStanzaSent(createMessage("m1"));
- testling->handleStanzaSent(createMessage("m2"));
-
- testling->handleAckReceived(1);
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(ackedStanzas.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
- CPPUNIT_ASSERT_EQUAL(std::string("m2"), ackedStanzas[1]->getID());
- }
-
- private:
- Message::ref createMessage(const std::string& id) {
- Message::ref result(new Message());
- result->setID(id);
- return result;
- }
-
- IQ::ref createIQ(const std::string& id) {
- IQ::ref result(new IQ());
- result->setID(id);
- return result;
- }
-
- Presence::ref createPresence(const std::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));
- requester->onStanzaAcked.connect(boost::bind(&StanzaAckRequesterTest::handleStanzaAcked, this, _1));
- return requester;
- }
-
- void handleRequestAck() {
- acksRequested++;
- }
-
- void handleStanzaAcked(boost::shared_ptr<Stanza> stanza) {
- ackedStanzas.push_back(stanza);
- }
-
- private:
- int acksRequested;
- std::vector< boost::shared_ptr<Stanza> > ackedStanzas;
+ CPPUNIT_TEST_SUITE(StanzaAckRequesterTest);
+ 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);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ acksRequested = 0;
+ }
+
+ void testHandleStanzaSent_MessageRequestsAck() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createMessage("m1"));
+
+ CPPUNIT_ASSERT_EQUAL(1, acksRequested);
+ }
+
+ void testHandleStanzaSent_IQDoesNotRequestAck() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createIQ("iq1"));
+
+ CPPUNIT_ASSERT_EQUAL(0, acksRequested);
+ }
+
+ void testHandleStanzaSent_PresenceDoesNotRequestAck() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createPresence("p1"));
+
+ CPPUNIT_ASSERT_EQUAL(0, acksRequested);
+ }
+
+ void testHandleAckReceived_AcksStanza() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createMessage("m1"));
+
+ testling->handleAckReceived(1);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(ackedStanzas.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
+ }
+
+ void testHandleAckReceived_AcksMultipleMessages() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createMessage("m1"));
+ testling->handleStanzaSent(createMessage("m2"));
+
+ testling->handleAckReceived(2);
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(ackedStanzas.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
+ CPPUNIT_ASSERT_EQUAL(std::string("m2"), ackedStanzas[1]->getID());
+ }
+
+ void testHandleAckReceived_AcksMultipleStanzas() {
+ boost::shared_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(std::string("iq1"), ackedStanzas[0]->getID());
+ CPPUNIT_ASSERT_EQUAL(std::string("p1"), ackedStanzas[1]->getID());
+ CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[2]->getID());
+ }
+
+ void testHandleAckReceived_MultipleAcks() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->handleStanzaSent(createMessage("m1"));
+ testling->handleAckReceived(1);
+
+ testling->handleStanzaSent(createMessage("m2"));
+ testling->handleStanzaSent(createMessage("m3"));
+ testling->handleAckReceived(3);
+
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(ackedStanzas.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
+ CPPUNIT_ASSERT_EQUAL(std::string("m2"), ackedStanzas[1]->getID());
+ CPPUNIT_ASSERT_EQUAL(std::string("m3"), ackedStanzas[2]->getID());
+ }
+
+ // Handle stanza ack count wrapping, as per the XEP
+ void testHandleAckReceived_WrapAround() {
+ boost::shared_ptr<StanzaAckRequester> testling(createRequester());
+ testling->lastHandledStanzasCount = boost::numeric_cast<unsigned int>((1ULL<<32) - 1);
+ testling->handleStanzaSent(createMessage("m1"));
+ testling->handleStanzaSent(createMessage("m2"));
+
+ testling->handleAckReceived(1);
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(ackedStanzas.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[0]->getID());
+ CPPUNIT_ASSERT_EQUAL(std::string("m2"), ackedStanzas[1]->getID());
+ }
+
+ private:
+ Message::ref createMessage(const std::string& id) {
+ Message::ref result(new Message());
+ result->setID(id);
+ return result;
+ }
+
+ IQ::ref createIQ(const std::string& id) {
+ IQ::ref result(new IQ());
+ result->setID(id);
+ return result;
+ }
+
+ Presence::ref createPresence(const std::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));
+ requester->onStanzaAcked.connect(boost::bind(&StanzaAckRequesterTest::handleStanzaAcked, this, _1));
+ return requester;
+ }
+
+ void handleRequestAck() {
+ acksRequested++;
+ }
+
+ void handleStanzaAcked(boost::shared_ptr<Stanza> stanza) {
+ ackedStanzas.push_back(stanza);
+ }
+
+ private:
+ int acksRequested;
+ std::vector< boost::shared_ptr<Stanza> > ackedStanzas;
};
}
diff --git a/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp b/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp
index 11d1c57..70cd8fc 100644
--- a/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp
+++ b/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp
@@ -18,80 +18,80 @@ using namespace Swift;
namespace Swift {
class StanzaAckResponderTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(StanzaAckResponderTest);
- CPPUNIT_TEST(testHandleAckRequestReceived_AcksStanza);
- CPPUNIT_TEST(testHandleAckRequestReceived_AcksMultipleStanzas);
- CPPUNIT_TEST(testHandleAckRequestReceived_MultipleAcks);
- CPPUNIT_TEST(testHandleAckRequestReceived_WrapAround);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void testHandleAckRequestReceived_AcksStanza() {
- boost::shared_ptr<StanzaAckResponder> testling(createResponder());
- testling->handleStanzaReceived();
-
- testling->handleAckRequestReceived();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(acks.size()));
- CPPUNIT_ASSERT_EQUAL(1U, acks[0]);
- }
-
- void testHandleAckRequestReceived_AcksMultipleStanzas() {
- boost::shared_ptr<StanzaAckResponder> testling(createResponder());
- testling->handleStanzaReceived();
- testling->handleStanzaReceived();
-
- testling->handleAckRequestReceived();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(acks.size()));
- CPPUNIT_ASSERT_EQUAL(2U, acks[0]);
- }
-
- void testHandleAckRequestReceived_MultipleAcks() {
- boost::shared_ptr<StanzaAckResponder> testling(createResponder());
- testling->handleStanzaReceived();
- testling->handleAckRequestReceived();
-
- testling->handleStanzaReceived();
- testling->handleAckRequestReceived();
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(acks.size()));
- CPPUNIT_ASSERT_EQUAL(1U, acks[0]);
- CPPUNIT_ASSERT_EQUAL(2U, acks[1]);
- }
-
- // Handle stanza ack count wrapping, as per the XEP
- void testHandleAckRequestReceived_WrapAround() {
- boost::shared_ptr<StanzaAckResponder> testling(createResponder());
- testling->handledStanzasCount = boost::numeric_cast<unsigned int>((1ULL<<32) - 1);
- testling->handleStanzaReceived();
- testling->handleStanzaReceived();
-
- testling->handleAckRequestReceived();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(acks.size()));
- CPPUNIT_ASSERT_EQUAL(1U, acks[0]);
- }
-
- private:
- Message::ref createMessage(const std::string& id) {
- Message::ref result(new Message());
- result->setID(id);
- return result;
- }
-
- StanzaAckResponder* createResponder() {
- StanzaAckResponder* responder = new StanzaAckResponder();
- responder->onAck.connect(boost::bind(&StanzaAckResponderTest::handleAck, this, _1));
- return responder;
- }
-
- void handleAck(unsigned int h) {
- acks.push_back(h);
- }
-
- private:
- std::vector<unsigned int> acks;
+ CPPUNIT_TEST_SUITE(StanzaAckResponderTest);
+ CPPUNIT_TEST(testHandleAckRequestReceived_AcksStanza);
+ CPPUNIT_TEST(testHandleAckRequestReceived_AcksMultipleStanzas);
+ CPPUNIT_TEST(testHandleAckRequestReceived_MultipleAcks);
+ CPPUNIT_TEST(testHandleAckRequestReceived_WrapAround);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testHandleAckRequestReceived_AcksStanza() {
+ boost::shared_ptr<StanzaAckResponder> testling(createResponder());
+ testling->handleStanzaReceived();
+
+ testling->handleAckRequestReceived();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(acks.size()));
+ CPPUNIT_ASSERT_EQUAL(1U, acks[0]);
+ }
+
+ void testHandleAckRequestReceived_AcksMultipleStanzas() {
+ boost::shared_ptr<StanzaAckResponder> testling(createResponder());
+ testling->handleStanzaReceived();
+ testling->handleStanzaReceived();
+
+ testling->handleAckRequestReceived();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(acks.size()));
+ CPPUNIT_ASSERT_EQUAL(2U, acks[0]);
+ }
+
+ void testHandleAckRequestReceived_MultipleAcks() {
+ boost::shared_ptr<StanzaAckResponder> testling(createResponder());
+ testling->handleStanzaReceived();
+ testling->handleAckRequestReceived();
+
+ testling->handleStanzaReceived();
+ testling->handleAckRequestReceived();
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(acks.size()));
+ CPPUNIT_ASSERT_EQUAL(1U, acks[0]);
+ CPPUNIT_ASSERT_EQUAL(2U, acks[1]);
+ }
+
+ // Handle stanza ack count wrapping, as per the XEP
+ void testHandleAckRequestReceived_WrapAround() {
+ boost::shared_ptr<StanzaAckResponder> testling(createResponder());
+ testling->handledStanzasCount = boost::numeric_cast<unsigned int>((1ULL<<32) - 1);
+ testling->handleStanzaReceived();
+ testling->handleStanzaReceived();
+
+ testling->handleAckRequestReceived();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(acks.size()));
+ CPPUNIT_ASSERT_EQUAL(1U, acks[0]);
+ }
+
+ private:
+ Message::ref createMessage(const std::string& id) {
+ Message::ref result(new Message());
+ result->setID(id);
+ return result;
+ }
+
+ StanzaAckResponder* createResponder() {
+ StanzaAckResponder* responder = new StanzaAckResponder();
+ responder->onAck.connect(boost::bind(&StanzaAckResponderTest::handleAck, this, _1));
+ return responder;
+ }
+
+ void handleAck(unsigned int h) {
+ acks.push_back(h);
+ }
+
+ private:
+ std::vector<unsigned int> acks;
};
}