summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-02-25 13:19:11 (GMT)
committerSwift Review <review@swift.im>2014-04-24 13:06:33 (GMT)
commite4704555946626980014d936dcfe6ede2710501b (patch)
tree59d0db1bad3d4a0f74c89da8834b2002369c3b4b /Swiften/Parser/PayloadParsers/UnitTest
parent09e9713028b728fad9050c4e20180cc96c4572ce (diff)
downloadswift-e4704555946626980014d936dcfe6ede2710501b.zip
swift-e4704555946626980014d936dcfe6ede2710501b.tar.bz2
Added MAM parsers, serializers and tests.
Change-Id: I589a7c65664bfecfd0ac34240600dcccb4cbd40e
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest')
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp118
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp35
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp76
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp58
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp65
5 files changed, 352 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp
new file mode 100644
index 0000000..a950fa4
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/PayloadParsers/ForwardedParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+#include <Swiften/Elements/Delay.h>
+#include <Swiften/Elements/IQ.h>
+#include <Swiften/Elements/Message.h>
+#include <Swiften/Elements/Presence.h>
+
+using namespace Swift;
+
+class ForwardedParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ForwardedParserTest);
+ CPPUNIT_TEST(testParseIQ);
+ CPPUNIT_TEST(testParseMessage);
+ CPPUNIT_TEST(testParseMessageNoDelay);
+ CPPUNIT_TEST(testParsePresence);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParseIQ() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>"
+ "<iq xmlns=\"jabber:client\" type=\"get\" from=\"kindanormal@example.com/IM\" to=\"stupidnewbie@example.com\" id=\"id0\"/>"
+ "</forwarded>"));
+
+ boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getDelay());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp()));
+
+ boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(payload->getStanza());
+ CPPUNIT_ASSERT(!!iq);
+ CPPUNIT_ASSERT_EQUAL(JID("stupidnewbie@example.com"), iq->getTo());
+ CPPUNIT_ASSERT_EQUAL(JID("kindanormal@example.com/IM"), iq->getFrom());
+ CPPUNIT_ASSERT_EQUAL(std::string("id0"), iq->getID());
+ CPPUNIT_ASSERT_EQUAL(IQ::Get, iq->getType());
+ }
+
+ void testParseMessage() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>"
+ "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">"
+ "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>"
+ "</message>"
+ "</forwarded>"));
+
+ boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getDelay());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp()));
+
+ boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza());
+ CPPUNIT_ASSERT(!!message);
+ const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.";
+ CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody());
+ CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType());
+ CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom());
+ }
+
+ void testParseMessageNoDelay() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">"
+ "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>"
+ "</message>"
+ "</forwarded>"));
+
+ boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(!payload->getDelay());
+
+ boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza());
+ CPPUNIT_ASSERT(!!message);
+ const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.";
+ CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody());
+ CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType());
+ CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom());
+ }
+
+ void testParsePresence() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>"
+ "<presence xmlns=\"jabber:client\" from=\"alice@wonderland.lit/rabbithole\" to=\"madhatter@wonderland.lit\" type=\"unavailable\"/>"
+ "</forwarded>"));
+
+ boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getDelay());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp()));
+
+ boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(payload->getStanza());
+ CPPUNIT_ASSERT(!!presence);
+ CPPUNIT_ASSERT_EQUAL(JID("madhatter@wonderland.lit"), presence->getTo());
+ CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/rabbithole"), presence->getFrom());
+ CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presence->getType());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp
new file mode 100644
index 0000000..3e65cc6
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class MAMArchivedParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(MAMArchivedParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>"));
+
+ boost::shared_ptr<MAMArchived> payload = parser.getPayload<MAMArchived>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit"), payload->getBy());
+ CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MAMArchivedParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp
new file mode 100644
index 0000000..ddcd7c4
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class MAMQueryParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(MAMQueryParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST(testParseEmpty);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">"
+ "<x type=\"form\" xmlns=\"jabber:x:data\">"
+ "<field type=\"text-single\" var=\"FORM_TYPE\">"
+ "<value>urn:xmpp:mam:0</value>"
+ "</field>"
+ "<field type=\"text-single\" var=\"start\">"
+ "<value>2010-08-07T00:00:00Z</value>"
+ "</field>"
+ "</x>"
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<max>10</max>"
+ "</set>"
+ "</query>"));
+
+
+ boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getQueryID());
+ CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID());
+
+ CPPUNIT_ASSERT(payload->getForm());
+ boost::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE");
+ CPPUNIT_ASSERT(fieldType);
+ CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue());
+ boost::shared_ptr<FormField> fieldStart = payload->getForm()->getField("start");
+ CPPUNIT_ASSERT(fieldStart);
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-08-07T00:00:00Z"), fieldStart->getTextSingleValue());
+
+ CPPUNIT_ASSERT(payload->getResultSet());
+ boost::shared_ptr<ResultSet> resultSet = payload->getResultSet();
+ CPPUNIT_ASSERT(resultSet->getMaxItems());
+ CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10);
+ }
+
+ void testParseEmpty() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">"
+ "</query>"));
+
+ boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getQueryID());
+ CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID());
+ CPPUNIT_ASSERT(!payload->getForm());
+ CPPUNIT_ASSERT(!payload->getResultSet());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MAMQueryParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp
new file mode 100644
index 0000000..e62db9b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+#include <Swiften/Elements/Delay.h>
+#include <Swiften/Elements/Forwarded.h>
+#include <Swiften/Elements/Message.h>
+
+using namespace Swift;
+
+class MAMResultParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(MAMResultParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">"
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>"
+ "<message xmlns=\"jabber:client\" from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\">"
+ "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>"
+ "</message>"
+ "</forwarded>"
+ "</result>"));
+
+ boost::shared_ptr<MAMResult> payload = parser.getPayload<MAMResult>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID());
+ CPPUNIT_ASSERT(payload->getQueryID());
+ CPPUNIT_ASSERT_EQUAL(std::string("f27"), *payload->getQueryID());
+
+ boost::shared_ptr<Forwarded> forwarded = payload->getPayload();
+ CPPUNIT_ASSERT(forwarded->getDelay());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp()));
+
+ boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza());
+ CPPUNIT_ASSERT(!!message);
+ const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.";
+ CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody());
+ CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType());
+ CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MAMResultParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp
new file mode 100644
index 0000000..68df71b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PayloadParsers/ResultSetParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class ResultSetParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ResultSetParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST(testParseFirstNoIndex);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<max>100</max>"
+ "<count>800</count>"
+ "<first index=\"123\">stpeter@jabber.org</first>"
+ "<last>peterpan@neverland.lit</last>"
+ "<after>09af3-cc343-b409f</after>"
+ "</set>"));
+
+ boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getMaxItems());
+ CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems());
+ CPPUNIT_ASSERT(payload->getCount());
+ CPPUNIT_ASSERT_EQUAL(800, *payload->getCount());
+ CPPUNIT_ASSERT(payload->getFirstID());
+ CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID());
+ CPPUNIT_ASSERT(payload->getFirstIDIndex());
+ CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex());
+ CPPUNIT_ASSERT(payload->getLastID());
+ CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID());
+ CPPUNIT_ASSERT(payload->getAfter());
+ CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter());
+ }
+
+ void testParseFirstNoIndex() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<first>stpeter@jabber.org</first>"
+ "</set>"));
+
+ boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT(payload->getFirstID());
+ CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID());
+ CPPUNIT_ASSERT(!payload->getFirstIDIndex());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetParserTest);