summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-17 20:04:40 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-21 11:50:43 (GMT)
commit76d967cf7cef073501d152cb4863af418e74cdbe (patch)
tree437674039510ceba139f7c02fbebe95e5186ea94 /Swiften/Parser/PayloadParsers/UnitTest
parent94d7b0822e041740232f9d4b0f1e0f9f3dee1dd4 (diff)
downloadswift-contrib-76d967cf7cef073501d152cb4863af418e74cdbe.zip
swift-contrib-76d967cf7cef073501d152cb4863af418e74cdbe.tar.bz2
Added search parserialement.
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest')
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp
new file mode 100644
index 0000000..1d94c15
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 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/UnitTest/PayloadsParserTester.h"
+#include "Swiften/Elements/SearchPayload.h"
+
+using namespace Swift;
+
+class SearchPayloadParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(SearchPayloadParserTest);
+ CPPUNIT_TEST(testParse_FormRequestResponse);
+ CPPUNIT_TEST(testParse_Results);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse_FormRequestResponse() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns=\"jabber:iq:search\">"
+ "<instructions>Foo</instructions>"
+ "<first/>"
+ "<last/>"
+ "</query>"
+ ));
+
+ SearchPayload::ref payload = parser.getPayload<SearchPayload>();
+ CPPUNIT_ASSERT_EQUAL(String("Foo"), *payload->getInstructions());
+ CPPUNIT_ASSERT(payload->getFirst());
+ CPPUNIT_ASSERT(payload->getLast());
+ CPPUNIT_ASSERT(!payload->getNick());
+ }
+
+ void testParse_Results() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns=\"jabber:iq:search\">"
+ "<item jid=\"juliet@capulet.com\">"
+ "<first>Juliet</first>"
+ "<last>Capulet</last>"
+ "<nick>JuliC</nick>"
+ "<email>juliet@shakespeare.lit</email>"
+ "</item>"
+ "<item jid=\"tybalt@shakespeare.lit\">"
+ "<first>Tybalt</first>"
+ "<last>Capulet</last>"
+ "<nick>ty</nick>"
+ "<email>tybalt@shakespeare.lit</email>"
+ "</item>"
+ "</query>"
+ ));
+
+ SearchPayload::ref payload = parser.getPayload<SearchPayload>();
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size()));
+ CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.com"), payload->getItems()[0].jid);
+ CPPUNIT_ASSERT_EQUAL(String("Juliet"), payload->getItems()[0].first);
+ CPPUNIT_ASSERT_EQUAL(String("Capulet"), payload->getItems()[0].last);
+ CPPUNIT_ASSERT_EQUAL(String("JuliC"), payload->getItems()[0].nick);
+ CPPUNIT_ASSERT_EQUAL(String("juliet@shakespeare.lit"), payload->getItems()[0].email);
+ CPPUNIT_ASSERT_EQUAL(JID("tybalt@shakespeare.lit"), payload->getItems()[1].jid);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SearchPayloadParserTest);