summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2014-05-09 14:25:29 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2014-05-12 08:49:36 (GMT)
commit634555e64572531fece2a955d1168a88c7979d09 (patch)
tree4a7d50488d4adf60b24091e6308e7d4c30b350e7
parentafa4aa4a38991fc219d71604baab4d64a2082629 (diff)
downloadswift-contrib-634555e64572531fece2a955d1168a88c7979d09.zip
swift-contrib-634555e64572531fece2a955d1168a88c7979d09.tar.bz2
Add support for <before/> to ResultSet
Change-Id: I46bd9f24fc887b180cee3c2aa75a6c9e1761473b
-rw-r--r--Sluift/ElementConvertors/ResultSetConvertor.cpp9
-rw-r--r--Swiften/Elements/ResultSet.h4
-rw-r--r--Swiften/Parser/PayloadParsers/ResultSetParser.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp3
-rw-r--r--Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp4
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp18
6 files changed, 40 insertions, 0 deletions
diff --git a/Sluift/ElementConvertors/ResultSetConvertor.cpp b/Sluift/ElementConvertors/ResultSetConvertor.cpp
index a4ebbf1..bd517b3 100644
--- a/Sluift/ElementConvertors/ResultSetConvertor.cpp
+++ b/Sluift/ElementConvertors/ResultSetConvertor.cpp
@@ -55,2 +55,7 @@ boost::shared_ptr<ResultSet> ResultSetConvertor::doConvertFromLua(lua_State* L)
lua_pop(L, 1);
+ lua_getfield(L, -1, "before");
+ if (lua_isstring(L, -1)) {
+ result->setBefore(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
return result;
@@ -84,2 +89,6 @@ void ResultSetConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<ResultSe
}
+ if (payload->getBefore()) {
+ lua_pushstring(L, (*payload->getBefore()).c_str());
+ lua_setfield(L, -2, "before");
+ }
}
diff --git a/Swiften/Elements/ResultSet.h b/Swiften/Elements/ResultSet.h
index 871b699..e84be35 100644
--- a/Swiften/Elements/ResultSet.h
+++ b/Swiften/Elements/ResultSet.h
@@ -32,2 +32,5 @@ namespace Swift {
+ void setBefore(const boost::optional<std::string>& before) { before_ = before; }
+ const boost::optional<std::string>& getBefore() const { return before_; }
+
void setAfter(const boost::optional<std::string>& after) { after_ = after; }
@@ -41,2 +44,3 @@ namespace Swift {
boost::optional<std::string> lastID_;
+ boost::optional<std::string> before_;
boost::optional<std::string> after_;
diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp
index 95960d7..4c8283b 100644
--- a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp
+++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp
@@ -49,2 +49,4 @@ void ResultSetParser::handleEndElement(const std::string& element, const std::st
getPayloadInternal()->setLastID(currentText_);
+ } else if (element == "before") {
+ getPayloadInternal()->setBefore(currentText_);
} else if (element == "after") {
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp
index 68df71b..e345323 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp
@@ -30,2 +30,3 @@ class ResultSetParserTest : public CppUnit::TestFixture
"<last>peterpan@neverland.lit</last>"
+ "<before>decaf-badba-dbad1</before>"
"<after>09af3-cc343-b409f</after>"
@@ -45,2 +46,4 @@ class ResultSetParserTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID());
+ CPPUNIT_ASSERT(payload->getBefore());
+ CPPUNIT_ASSERT_EQUAL(std::string("decaf-badba-dbad1"), *payload->getBefore());
CPPUNIT_ASSERT(payload->getAfter());
diff --git a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp
index 86d8830..0f464a4 100644
--- a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp
@@ -47,2 +47,6 @@ std::string ResultSetSerializer::serializePayload(boost::shared_ptr<ResultSet> p
+ if (payload->getBefore()) {
+ element.addNode(boost::make_shared<XMLElement>("before", "", *payload->getBefore()));
+ }
+
if (payload->getAfter()) {
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp
index 641b856..354db85 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp
@@ -21,2 +21,3 @@ class ResultSetSerializerTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testSerializeMaxItems);
+ CPPUNIT_TEST(testSerializeEmptyBefore);
CPPUNIT_TEST(testSerializeFirst);
@@ -37,2 +38,3 @@ class ResultSetSerializerTest : public CppUnit::TestFixture {
resultSet->setAfter(std::string("09af3-cc343-b409f"));
+ resultSet->setBefore(std::string("decaf-badba-dbad1"));
@@ -44,2 +46,3 @@ class ResultSetSerializerTest : public CppUnit::TestFixture {
"<last>peterpan@neverland.lit</last>"
+ "<before>decaf-badba-dbad1</before>"
"<after>09af3-cc343-b409f</after>"
@@ -65,2 +68,17 @@ class ResultSetSerializerTest : public CppUnit::TestFixture {
+ void testSerializeEmptyBefore() {
+ ResultSetSerializer serializer;
+
+ boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>());
+
+ resultSet->setBefore(std::string());
+
+ std::string expectedResult =
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<before/>"
+ "</set>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet));
+ }
+
void testSerializeFirst() {