From 634555e64572531fece2a955d1168a88c7979d09 Mon Sep 17 00:00:00 2001 From: Edwin Mons Date: Fri, 9 May 2014 16:25:29 +0200 Subject: Add support for to ResultSet Change-Id: I46bd9f24fc887b180cee3c2aa75a6c9e1761473b 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 @@ -53,6 +53,11 @@ boost::shared_ptr ResultSetConvertor::doConvertFromLua(lua_State* L) result->setAfter(std::string(lua_tostring(L, -1))); } 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; } @@ -82,6 +87,10 @@ void ResultSetConvertor::doConvertToLua(lua_State* L, boost::shared_ptrgetAfter()).c_str()); lua_setfield(L, -2, "after"); } + if (payload->getBefore()) { + lua_pushstring(L, (*payload->getBefore()).c_str()); + lua_setfield(L, -2, "before"); + } } boost::optional ResultSetConvertor::getDocumentation() const { 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 @@ -30,6 +30,9 @@ namespace Swift { void setLastID(const boost::optional& lastID) { lastID_ = lastID; } const boost::optional& getLastID() const { return lastID_; } + void setBefore(const boost::optional& before) { before_ = before; } + const boost::optional& getBefore() const { return before_; } + void setAfter(const boost::optional& after) { after_ = after; } const boost::optional& getAfter() const { return after_; } @@ -39,6 +42,7 @@ namespace Swift { boost::optional firstIndex_; boost::optional firstID_; boost::optional lastID_; + boost::optional before_; boost::optional 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 @@ -47,6 +47,8 @@ void ResultSetParser::handleEndElement(const std::string& element, const std::st getPayloadInternal()->setFirstID(currentText_); } else if (element == "last") { getPayloadInternal()->setLastID(currentText_); + } else if (element == "before") { + getPayloadInternal()->setBefore(currentText_); } else if (element == "after") { getPayloadInternal()->setAfter(currentText_); } 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 @@ -28,6 +28,7 @@ class ResultSetParserTest : public CppUnit::TestFixture "800" "stpeter@jabber.org" "peterpan@neverland.lit" + "decaf-badba-dbad1" "09af3-cc343-b409f" "")); @@ -43,6 +44,8 @@ class ResultSetParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex()); CPPUNIT_ASSERT(payload->getLastID()); 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()); CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *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 @@ -45,6 +45,10 @@ std::string ResultSetSerializer::serializePayload(boost::shared_ptr p element.addNode(boost::make_shared("last", "", *payload->getLastID())); } + if (payload->getBefore()) { + element.addNode(boost::make_shared("before", "", *payload->getBefore())); + } + if (payload->getAfter()) { element.addNode(boost::make_shared("after", "", *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 @@ -19,6 +19,7 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ResultSetSerializerTest); CPPUNIT_TEST(testSerializeFull); CPPUNIT_TEST(testSerializeMaxItems); + CPPUNIT_TEST(testSerializeEmptyBefore); CPPUNIT_TEST(testSerializeFirst); CPPUNIT_TEST(testSerializeFirstWithIndex); CPPUNIT_TEST_SUITE_END(); @@ -35,6 +36,7 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { resultSet->setFirstID(std::string("stpeter@jabber.org")); resultSet->setLastID(std::string("peterpan@neverland.lit")); resultSet->setAfter(std::string("09af3-cc343-b409f")); + resultSet->setBefore(std::string("decaf-badba-dbad1")); std::string expectedResult = "" @@ -42,6 +44,7 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { "800" "stpeter@jabber.org" "peterpan@neverland.lit" + "decaf-badba-dbad1" "09af3-cc343-b409f" ""; @@ -63,6 +66,21 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); } + void testSerializeEmptyBefore() { + ResultSetSerializer serializer; + + boost::shared_ptr resultSet(boost::make_shared()); + + resultSet->setBefore(std::string()); + + std::string expectedResult = + "" + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } + void testSerializeFirst() { ResultSetSerializer serializer; -- cgit v0.10.2-6-g49f6