summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp')
-rw-r--r--Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp157
1 files changed, 79 insertions, 78 deletions
diff --git a/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp b/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp
index 92115e8..ffdabe9 100644
--- a/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp
+++ b/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp
@@ -1,96 +1,97 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
#include <boost/bind.hpp>
#include <boost/numeric/conversion/cast.hpp>
-#include <Swiften/StreamManagement/StanzaAckResponder.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
#include <Swiften/Elements/Message.h>
+#include <Swiften/StreamManagement/StanzaAckResponder.h>
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() {
+ std::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() {
+ std::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() {
+ std::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() {
+ std::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;
};
}