summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Queries/Requests')
-rw-r--r--Swiften/Queries/Requests/EnableCarbonsRequest.h28
-rw-r--r--Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp7
-rw-r--r--Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h24
-rw-r--r--Swiften/Queries/Requests/GetPrivateStorageRequest.h64
-rw-r--r--Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h35
-rw-r--r--Swiften/Queries/Requests/GetSoftwareVersionRequest.h36
-rw-r--r--Swiften/Queries/Requests/SetPrivateStorageRequest.h52
-rw-r--r--Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp7
-rw-r--r--Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h40
-rw-r--r--Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp187
10 files changed, 247 insertions, 233 deletions
diff --git a/Swiften/Queries/Requests/EnableCarbonsRequest.h b/Swiften/Queries/Requests/EnableCarbonsRequest.h
new file mode 100644
index 0000000..7762e68
--- /dev/null
+++ b/Swiften/Queries/Requests/EnableCarbonsRequest.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/CarbonsEnable.h>
+#include <Swiften/Queries/GenericRequest.h>
+
+namespace Swift {
+ class SWIFTEN_API EnableCarbonsRequest : public GenericRequest<CarbonsEnable> {
+ public:
+ typedef std::shared_ptr<EnableCarbonsRequest> ref;
+
+ static ref create(IQRouter* router) {
+ return ref(new EnableCarbonsRequest(router));
+ }
+
+ private:
+ EnableCarbonsRequest(IQRouter* router) : GenericRequest<CarbonsEnable>(IQ::Set, JID(), std::make_shared<CarbonsEnable>(), router) {
+ }
+ };
+}
diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp
deleted file mode 100644
index d04e5c7..0000000
--- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * Copyright (c) 2010 Isode Limited.
- * All rights reserved.
- * See the COPYING file for more information.
- */
-
-#include <Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h>
diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h
index b952875..b187fa5 100644
--- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h
+++ b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,20 +7,20 @@
#pragma once
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/InBandRegistrationPayload.h>
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetInBandRegistrationFormRequest : public GenericRequest<InBandRegistrationPayload> {
- public:
- typedef boost::shared_ptr<GetInBandRegistrationFormRequest> ref;
+ class SWIFTEN_API GetInBandRegistrationFormRequest : public GenericRequest<InBandRegistrationPayload> {
+ public:
+ typedef std::shared_ptr<GetInBandRegistrationFormRequest> ref;
- static ref create(const JID& to, IQRouter* router) {
- return ref(new GetInBandRegistrationFormRequest(to, router));
- }
+ static ref create(const JID& to, IQRouter* router) {
+ return ref(new GetInBandRegistrationFormRequest(to, router));
+ }
- private:
- GetInBandRegistrationFormRequest(const JID& to, IQRouter* router) : GenericRequest<InBandRegistrationPayload>(IQ::Get, to, InBandRegistrationPayload::ref(new InBandRegistrationPayload()), router) {
- }
- };
+ private:
+ GetInBandRegistrationFormRequest(const JID& to, IQRouter* router) : GenericRequest<InBandRegistrationPayload>(IQ::Get, to, InBandRegistrationPayload::ref(new InBandRegistrationPayload()), router) {
+ }
+ };
}
diff --git a/Swiften/Queries/Requests/GetPrivateStorageRequest.h b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
index 97711a6..5fb0de5 100644
--- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
@@ -1,45 +1,45 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/Request.h>
-#include <Swiften/Elements/PrivateStorage.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/PrivateStorage.h>
+#include <Swiften/Queries/Request.h>
namespace Swift {
- template<typename PAYLOAD_TYPE>
- class SWIFTEN_API GetPrivateStorageRequest : public Request {
- public:
- typedef boost::shared_ptr<GetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
-
- static ref create(IQRouter* router) {
- return ref(new GetPrivateStorageRequest(router));
- }
-
- private:
- GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), boost::make_shared<PrivateStorage>(boost::shared_ptr<Payload>(new PAYLOAD_TYPE())), router) {
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- boost::shared_ptr<PrivateStorage> storage = boost::dynamic_pointer_cast<PrivateStorage>(payload);
- if (storage) {
- onResponse(boost::dynamic_pointer_cast<PAYLOAD_TYPE>(storage->getPayload()), error);
- }
- else {
- onResponse(boost::shared_ptr<PAYLOAD_TYPE>(), error);
- }
- }
-
- public:
- boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, ErrorPayload::ref)> onResponse;
- };
+ template<typename PAYLOAD_TYPE>
+ class SWIFTEN_API GetPrivateStorageRequest : public Request {
+ public:
+ typedef std::shared_ptr<GetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
+
+ static ref create(IQRouter* router) {
+ return ref(new GetPrivateStorageRequest(router));
+ }
+
+ private:
+ GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), std::make_shared<PrivateStorage>(std::make_shared<PAYLOAD_TYPE>()), router) {
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ std::shared_ptr<PrivateStorage> storage = std::dynamic_pointer_cast<PrivateStorage>(payload);
+ if (storage) {
+ onResponse(std::dynamic_pointer_cast<PAYLOAD_TYPE>(storage->getPayload()), error);
+ }
+ else {
+ onResponse(std::shared_ptr<PAYLOAD_TYPE>(), error);
+ }
+ }
+
+ public:
+ boost::signals2::signal<void (std::shared_ptr<PAYLOAD_TYPE>, ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
index 7a76fcc..0a3502f 100644
--- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
+++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
@@ -1,33 +1,32 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/SecurityLabelsCatalog.h>
-
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetSecurityLabelsCatalogRequest : public GenericRequest<SecurityLabelsCatalog> {
- public:
- typedef boost::shared_ptr<GetSecurityLabelsCatalogRequest> ref;
+ class SWIFTEN_API GetSecurityLabelsCatalogRequest : public GenericRequest<SecurityLabelsCatalog> {
+ public:
+ typedef std::shared_ptr<GetSecurityLabelsCatalogRequest> ref;
- static ref create(const JID& recipient, IQRouter* router) {
- return ref(new GetSecurityLabelsCatalogRequest(recipient, router));
- }
+ static ref create(const JID& recipient, IQRouter* router) {
+ return ref(new GetSecurityLabelsCatalogRequest(recipient, router));
+ }
- private:
- GetSecurityLabelsCatalogRequest(
- const JID& recipient,
- IQRouter* router) :
- GenericRequest<SecurityLabelsCatalog>(
- IQ::Get, JID(), boost::make_shared<SecurityLabelsCatalog>(recipient), router) {
- }
- };
+ private:
+ GetSecurityLabelsCatalogRequest(
+ const JID& recipient,
+ IQRouter* router) :
+ GenericRequest<SecurityLabelsCatalog>(
+ IQ::Get, JID(), std::make_shared<SecurityLabelsCatalog>(recipient), router) {
+ }
+ };
}
diff --git a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h
index 1084a0b..5660dd8 100644
--- a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h
+++ b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h
@@ -1,32 +1,32 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
+#include <memory>
+
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/SoftwareVersion.h>
-#include <boost/smart_ptr/make_shared.hpp>
-
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetSoftwareVersionRequest : public GenericRequest<SoftwareVersion> {
- public:
- typedef boost::shared_ptr<GetSoftwareVersionRequest> ref;
+ class SWIFTEN_API GetSoftwareVersionRequest : public GenericRequest<SoftwareVersion> {
+ public:
+ typedef std::shared_ptr<GetSoftwareVersionRequest> ref;
- static ref create(const JID& recipient, IQRouter* router) {
- return ref(new GetSoftwareVersionRequest(recipient, router));
- }
+ static ref create(const JID& recipient, IQRouter* router) {
+ return ref(new GetSoftwareVersionRequest(recipient, router));
+ }
- private:
- GetSoftwareVersionRequest(
- const JID& recipient,
- IQRouter* router) :
- GenericRequest<SoftwareVersion>(
- IQ::Get, recipient, boost::make_shared<SoftwareVersion>(), router) {
- }
- };
+ private:
+ GetSoftwareVersionRequest(
+ const JID& recipient,
+ IQRouter* router) :
+ GenericRequest<SoftwareVersion>(
+ IQ::Get, recipient, std::make_shared<SoftwareVersion>(), router) {
+ }
+ };
}
diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
index 9ab65f7..f1dc77a 100644
--- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
@@ -1,39 +1,39 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/Request.h>
-#include <Swiften/Elements/PrivateStorage.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/PrivateStorage.h>
+#include <Swiften/Queries/Request.h>
namespace Swift {
- template<typename PAYLOAD_TYPE>
- class SWIFTEN_API SetPrivateStorageRequest : public Request {
- public:
- typedef boost::shared_ptr<SetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
-
- static ref create(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) {
- return ref(new SetPrivateStorageRequest<PAYLOAD_TYPE>(payload, router));
- }
-
- private:
- SetPrivateStorageRequest(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), boost::make_shared<PrivateStorage>(payload), router) {
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload>, ErrorPayload::ref error) {
- onResponse(error);
- }
-
- public:
- boost::signal<void (ErrorPayload::ref)> onResponse;
- };
+ template<typename PAYLOAD_TYPE>
+ class SWIFTEN_API SetPrivateStorageRequest : public Request {
+ public:
+ typedef std::shared_ptr<SetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
+
+ static ref create(std::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) {
+ return ref(new SetPrivateStorageRequest<PAYLOAD_TYPE>(payload, router));
+ }
+
+ private:
+ SetPrivateStorageRequest(std::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), std::make_shared<PrivateStorage>(payload), router) {
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload>, ErrorPayload::ref error) {
+ onResponse(error);
+ }
+
+ public:
+ boost::signals2::signal<void (ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp
deleted file mode 100644
index d99ddca..0000000
--- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * Copyright (c) 2010 Isode Limited.
- * All rights reserved.
- * See the COPYING file for more information.
- */
-
-#include <Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h>
diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h
index e79562a..1cf28c5 100644
--- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h
+++ b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h
@@ -1,37 +1,37 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/Request.h>
#include <Swiften/Elements/InBandRegistrationPayload.h>
-
+#include <Swiften/Queries/Request.h>
namespace Swift {
- class SWIFTEN_API SetInBandRegistrationRequest : public Request {
- public:
- typedef boost::shared_ptr<SetInBandRegistrationRequest> ref;
+ class SWIFTEN_API SetInBandRegistrationRequest : public Request {
+ public:
+ typedef std::shared_ptr<SetInBandRegistrationRequest> ref;
- static ref create(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) {
- return ref(new SetInBandRegistrationRequest(to, payload, router));
- }
+ static ref create(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) {
+ return ref(new SetInBandRegistrationRequest(to, payload, router));
+ }
- private:
- SetInBandRegistrationRequest(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) : Request(IQ::Set, to, InBandRegistrationPayload::ref(payload), router) {
- }
+ private:
+ SetInBandRegistrationRequest(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) : Request(IQ::Set, to, InBandRegistrationPayload::ref(payload), router) {
+ }
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- onResponse(payload, error);
- }
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ onResponse(payload, error);
+ }
- public:
- boost::signal<void (boost::shared_ptr<Payload>, ErrorPayload::ref)> onResponse;
- };
+ public:
+ boost::signals2::signal<void (std::shared_ptr<Payload>, ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
index 5b0a704..8a4b9fc 100644
--- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
+++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
@@ -1,109 +1,110 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <memory>
+
+#include <boost/bind.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/bind.hpp>
-#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h>
-#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Elements/Payload.h>
+#include <Swiften/Queries/DummyIQChannel.h>
+#include <Swiften/Queries/IQRouter.h>
+#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h>
using namespace Swift;
class GetPrivateStorageRequestTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(GetPrivateStorageRequestTest);
- CPPUNIT_TEST(testSend);
- CPPUNIT_TEST(testHandleResponse);
- CPPUNIT_TEST(testHandleResponse_Error);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- class MyPayload : public Payload {
- public:
- MyPayload(const std::string& text = "") : text(text) {}
- std::string text;
- };
-
- public:
- void setUp() {
- channel = new DummyIQChannel();
- router = new IQRouter(channel);
- }
-
- void tearDown() {
- delete router;
- delete channel;
- }
-
- void testSend() {
- GetPrivateStorageRequest<MyPayload>::ref request = GetPrivateStorageRequest<MyPayload>::create(router);
- request->send();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->iqs_.size()));
- CPPUNIT_ASSERT_EQUAL(JID(), channel->iqs_[0]->getTo());
- CPPUNIT_ASSERT_EQUAL(IQ::Get, channel->iqs_[0]->getType());
- boost::shared_ptr<PrivateStorage> storage = channel->iqs_[0]->getPayload<PrivateStorage>();
- CPPUNIT_ASSERT(storage);
- boost::shared_ptr<MyPayload> payload = boost::dynamic_pointer_cast<MyPayload>(storage->getPayload());
- CPPUNIT_ASSERT(payload);
- }
-
- void testHandleResponse() {
- GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router);
- testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
- testling->send();
- channel->onIQReceived(createResponse("test-id", "foo"));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(responses.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), boost::dynamic_pointer_cast<MyPayload>(responses[0])->text);
- }
-
- void testHandleResponse_Error() {
- GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router);
- testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
- testling->send();
- channel->onIQReceived(createError("test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(responses.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(errors.size()));
- }
-
- private:
- void handleResponse(boost::shared_ptr<Payload> p, ErrorPayload::ref e) {
- if (e) {
- errors.push_back(*e);
- }
- else {
- responses.push_back(p);
- }
- }
-
- boost::shared_ptr<IQ> createResponse(const std::string& id, const std::string& text) {
- boost::shared_ptr<IQ> iq(new IQ(IQ::Result));
- boost::shared_ptr<PrivateStorage> storage(new PrivateStorage());
- storage->setPayload(boost::shared_ptr<Payload>(new MyPayload(text)));
- iq->addPayload(storage);
- iq->setID(id);
- return iq;
- }
-
- boost::shared_ptr<IQ> createError(const std::string& id) {
- boost::shared_ptr<IQ> iq(new IQ(IQ::Error));
- iq->setID(id);
- return iq;
- }
-
- private:
- IQRouter* router;
- DummyIQChannel* channel;
- std::vector< ErrorPayload > errors;
- std::vector< boost::shared_ptr<Payload> > responses;
+ CPPUNIT_TEST_SUITE(GetPrivateStorageRequestTest);
+ CPPUNIT_TEST(testSend);
+ CPPUNIT_TEST(testHandleResponse);
+ CPPUNIT_TEST(testHandleResponse_Error);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ class MyPayload : public Payload {
+ public:
+ MyPayload(const std::string& text = "") : text(text) {}
+ std::string text;
+ };
+
+ public:
+ void setUp() {
+ channel = std::unique_ptr<DummyIQChannel>(new DummyIQChannel());
+ router = std::unique_ptr<IQRouter>(new IQRouter(channel.get()));
+ }
+
+ void tearDown() {
+ router.reset();
+ }
+
+ void testSend() {
+ GetPrivateStorageRequest<MyPayload>::ref request = GetPrivateStorageRequest<MyPayload>::create(router.get());
+ request->send();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(JID(), channel->iqs_[0]->getTo());
+ CPPUNIT_ASSERT_EQUAL(IQ::Get, channel->iqs_[0]->getType());
+ std::shared_ptr<PrivateStorage> storage = channel->iqs_[0]->getPayload<PrivateStorage>();
+ CPPUNIT_ASSERT(storage);
+ std::shared_ptr<MyPayload> payload = std::dynamic_pointer_cast<MyPayload>(storage->getPayload());
+ CPPUNIT_ASSERT(payload);
+ }
+
+ void testHandleResponse() {
+ GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router.get());
+ testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
+ testling->send();
+ channel->onIQReceived(createResponse("test-id", "foo"));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(responses.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::dynamic_pointer_cast<MyPayload>(responses[0])->text);
+ }
+
+ void testHandleResponse_Error() {
+ GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router.get());
+ testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
+ testling->send();
+ channel->onIQReceived(createError("test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(responses.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(errors.size()));
+ }
+
+ private:
+ void handleResponse(std::shared_ptr<Payload> p, ErrorPayload::ref e) {
+ if (e) {
+ errors.push_back(*e);
+ }
+ else {
+ responses.push_back(p);
+ }
+ }
+
+ std::shared_ptr<IQ> createResponse(const std::string& id, const std::string& text) {
+ std::shared_ptr<IQ> iq(new IQ(IQ::Result));
+ std::shared_ptr<PrivateStorage> storage(new PrivateStorage());
+ storage->setPayload(std::make_shared<MyPayload>(text));
+ iq->addPayload(storage);
+ iq->setID(id);
+ return iq;
+ }
+
+ std::shared_ptr<IQ> createError(const std::string& id) {
+ std::shared_ptr<IQ> iq(new IQ(IQ::Error));
+ iq->setID(id);
+ return iq;
+ }
+
+ private:
+ std::unique_ptr<IQRouter> router;
+ std::unique_ptr<DummyIQChannel> channel;
+ std::vector< ErrorPayload > errors;
+ std::vector< std::shared_ptr<Payload> > responses;
};
CPPUNIT_TEST_SUITE_REGISTRATION(GetPrivateStorageRequestTest);