diff options
Diffstat (limited to 'Swiften/Queries/Requests')
10 files changed, 267 insertions, 248 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 337375e..0000000 --- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h> diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h index c0488ad..b187fa5 100644 --- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h +++ b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h @@ -1,26 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/InBandRegistrationPayload.h> - +#include <Swiften/Queries/GenericRequest.h> namespace Swift { - class 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 b5fd97f..5fb0de5 100644 --- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h @@ -1,44 +1,45 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <Swiften/Queries/Request.h> -#include <Swiften/Elements/PrivateStorage.h> +#include <boost/signals2.hpp> + +#include <Swiften/Base/API.h> #include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Queries/Request.h> namespace Swift { - template<typename PAYLOAD_TYPE> - class 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 943adef..0a3502f 100644 --- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h +++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h @@ -1,32 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Queries/GenericRequest.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/SecurityLabelsCatalog.h> - +#include <Swiften/Queries/GenericRequest.h> namespace Swift { - class 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 18461bb..5660dd8 100644 --- a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h +++ b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Queries/GenericRequest.h> -#include <Swiften/Elements/SoftwareVersion.h> -#include <boost/smart_ptr/make_shared.hpp> +#include <memory> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/SoftwareVersion.h> +#include <Swiften/Queries/GenericRequest.h> namespace Swift { - class 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 f65f819..f1dc77a 100644 --- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h @@ -1,38 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <Swiften/Queries/Request.h> -#include <Swiften/Elements/PrivateStorage.h> +#include <boost/signals2.hpp> + +#include <Swiften/Base/API.h> #include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Queries/Request.h> namespace Swift { - template<typename PAYLOAD_TYPE> - class 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 f010e96..0000000 --- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h> diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h index 8e0862b..1cf28c5 100644 --- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h +++ b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h @@ -1,36 +1,37 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <Swiften/Queries/Request.h> -#include <Swiften/Elements/InBandRegistrationPayload.h> +#include <boost/signals2.hpp> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> +#include <Swiften/Queries/Request.h> namespace Swift { - class 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 f3ecfb7..ed242f9 100644 --- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp +++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp @@ -1,109 +1,110 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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::make_unique<DummyIQChannel>(); + router = std::make_unique<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); |