diff options
Diffstat (limited to 'Swiften/Queries/Requests')
7 files changed, 186 insertions, 186 deletions
diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h index faea191..ad4caf7 100644 --- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h +++ b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h @@ -11,16 +11,16 @@ #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 boost::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 a2e7bde..eecd4d4 100644 --- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h @@ -16,30 +16,30 @@ #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 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; + }; } diff --git a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h index 34e2cfb..a474be5 100644 --- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h +++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h @@ -13,20 +13,20 @@ #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 boost::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(), boost::make_shared<SecurityLabelsCatalog>(recipient), router) { + } + }; } diff --git a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h index b8e568a..9533651 100644 --- a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h +++ b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h @@ -13,20 +13,20 @@ #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 boost::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, boost::make_shared<SoftwareVersion>(), router) { + } + }; } diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h index 46620c3..703b749 100644 --- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h @@ -16,24 +16,24 @@ #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 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; + }; } diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h index 220e2ba..94a497b 100644 --- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h +++ b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h @@ -14,23 +14,23 @@ #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 boost::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(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) { + onResponse(payload, error); + } - public: - boost::signal<void (boost::shared_ptr<Payload>, ErrorPayload::ref)> onResponse; - }; + public: + boost::signal<void (boost::shared_ptr<Payload>, ErrorPayload::ref)> onResponse; + }; } diff --git a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp index 4e3be50..1efe523 100644 --- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp +++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp @@ -18,93 +18,93 @@ 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 = 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_REGISTRATION(GetPrivateStorageRequestTest); |