summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-12 19:02:41 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-12 19:02:41 (GMT)
commitee57df7619725e93efa5a6475282e7dc5a7fb6e7 (patch)
tree1dc1b5bfd4ca8a4ea1c02a06599275c245fd1a3f
parentfdd8755e2363e8d706a3d0bdc2e71f234abdf829 (diff)
downloadswift-ee57df7619725e93efa5a6475282e7dc5a7fb6e7.zip
swift-ee57df7619725e93efa5a6475282e7dc5a7fb6e7.tar.bz2
Retrieve correct error in Request.
-rw-r--r--Swiften/Queries/Request.cpp9
-rw-r--r--Swiften/Queries/UnitTest/RequestTest.cpp31
2 files changed, 31 insertions, 9 deletions
diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp
index 18446ae..ce9f763 100644
--- a/Swiften/Queries/Request.cpp
+++ b/Swiften/Queries/Request.cpp
@@ -35,14 +35,19 @@ bool Request::handleIQ(boost::shared_ptr<IQ> iq) {
bool handled = false;
if (sent_ && iq->getID() == id_) {
if (iq->getType() == IQ::Result) {
handleResponse(iq->getPayloadOfSameType(payload_), boost::optional<ErrorPayload>());
}
else {
- // FIXME: Get proper error
- handleResponse(boost::shared_ptr<Payload>(), boost::optional<ErrorPayload>(ErrorPayload::UndefinedCondition));
+ boost::shared_ptr<ErrorPayload> errorPayload = iq->getPayload<ErrorPayload>();
+ if (errorPayload) {
+ handleResponse(boost::shared_ptr<Payload>(), boost::optional<ErrorPayload>(*errorPayload));
+ }
+ else {
+ handleResponse(boost::shared_ptr<Payload>(), boost::optional<ErrorPayload>(ErrorPayload::UndefinedCondition));
+ }
}
router_->removeHandler(this);
handled = true;
}
return handled;
}
diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp
index 51d5a51..c569bb5 100644
--- a/Swiften/Queries/UnitTest/RequestTest.cpp
+++ b/Swiften/Queries/UnitTest/RequestTest.cpp
@@ -15,12 +15,13 @@ class RequestTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(RequestTest);
CPPUNIT_TEST(testSendGet);
CPPUNIT_TEST(testSendSet);
CPPUNIT_TEST(testHandleIQ);
CPPUNIT_TEST(testHandleIQ_InvalidID);
CPPUNIT_TEST(testHandleIQ_Error);
+ CPPUNIT_TEST(testHandleIQ_ErrorWithoutPayload);
CPPUNIT_TEST(testHandleIQ_BeforeSend);
CPPUNIT_TEST_SUITE_END();
public:
class MyPayload : public Payload {
public:
@@ -36,13 +37,12 @@ class RequestTest : public CppUnit::TestFixture
void setUp() {
channel_ = new DummyIQChannel();
router_ = new IQRouter(channel_);
payload_ = boost::shared_ptr<Payload>(new MyPayload("foo"));
responsePayload_ = boost::shared_ptr<Payload>(new MyPayload("bar"));
responsesReceived_ = 0;
- errorsReceived_ = 0;
}
void tearDown() {
delete router_;
delete channel_;
}
@@ -70,55 +70,72 @@ class RequestTest : public CppUnit::TestFixture
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
channel_->onIQReceived(createResponse("test-id"));
CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, errorsReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
}
// FIXME: Doesn't test that it didn't handle the payload
void testHandleIQ_InvalidID() {
MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
channel_->onIQReceived(createResponse("different-id"));
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, errorsReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
}
void testHandleIQ_Error() {
MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
+ boost::shared_ptr<IQ> error = createError("test-id");
+ boost::shared_ptr<Payload> errorPayload = boost::shared_ptr<ErrorPayload>(new ErrorPayload(ErrorPayload::FeatureNotImplemented));
+ error->addPayload(errorPayload);
+ channel_->onIQReceived(error);
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::FeatureNotImplemented, receivedErrors[0].getCondition());
+ }
+
+ void testHandleIQ_ErrorWithoutPayload() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
channel_->onIQReceived(createError("test-id"));
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(1, errorsReceived_);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::UndefinedCondition, receivedErrors[0].getCondition());
}
void testHandleIQ_BeforeSend() {
MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
channel_->onIQReceived(createResponse("test-id"));
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, errorsReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
}
private:
void handleResponse(boost::shared_ptr<Payload> p, const boost::optional<ErrorPayload>& e) {
if (e) {
- ++errorsReceived_;
+ receivedErrors.push_back(*e);
}
else {
boost::shared_ptr<MyPayload> payload(boost::dynamic_pointer_cast<MyPayload>(p));
CPPUNIT_ASSERT(payload);
CPPUNIT_ASSERT_EQUAL(String("bar"), payload->text_);
++responsesReceived_;
@@ -141,10 +158,10 @@ class RequestTest : public CppUnit::TestFixture
private:
IQRouter* router_;
DummyIQChannel* channel_;
boost::shared_ptr<Payload> payload_;
boost::shared_ptr<Payload> responsePayload_;
int responsesReceived_;
- int errorsReceived_;
+ std::vector<ErrorPayload> receivedErrors;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RequestTest);