diff options
author | Tobias Markmann <tm@ayena.de> | 2012-01-06 22:18:25 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-01-23 14:51:26 (GMT) |
commit | 83afa3d4bf18e4feb8a33d084ed181508084fc64 (patch) | |
tree | b81a0c6eaaedbad3f3e607ea52a69acf98f95eff /Swiften/Serializer/PayloadSerializers/UnitTest | |
parent | 093d499945d779cfed92b45e413644834004b0d9 (diff) | |
download | swift-contrib-83afa3d4bf18e4feb8a33d084ed181508084fc64.zip swift-contrib-83afa3d4bf18e4feb8a33d084ed181508084fc64.tar.bz2 |
XEP-0004 form support for user search.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UnitTest')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp | 95 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp | 100 |
2 files changed, 194 insertions, 1 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp index 29e7e59..4608522 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp @@ -8,13 +8,13 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> - using namespace Swift; class FormSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(FormSerializerTest); CPPUNIT_TEST(testSerializeFormInformation); CPPUNIT_TEST(testSerializeFields); + CPPUNIT_TEST(testSerializeFormItems); CPPUNIT_TEST_SUITE_END(); public: @@ -134,6 +134,99 @@ class FormSerializerTest : public CppUnit::TestFixture { "</field>" "</x>"), testling.serialize(form)); } + + void testSerializeFormItems() { + FormSerializer testling; + boost::shared_ptr<Form> form(new Form(Form::ResultType)); + + + FormField::ref field = HiddenFormField::create("jabber:iq:search"); + field->setName("FORM_TYPE"); + form->addField(field); + + // reported fields + field = TextSingleFormField::create(); + field->setName("first"); + field->setLabel("Given Name"); + form->addReportedField(field); + + field = TextSingleFormField::create(); + field->setName("last"); + field->setLabel("Family Name"); + form->addReportedField(field); + + field = JIDSingleFormField::create(); + field->setName("jid"); + field->setLabel("Jabber ID"); + form->addReportedField(field); + + field = ListSingleFormField::create(); + field->setName("x-gender"); + field->setLabel("Gender"); + form->addReportedField(field); + + Form::FormItem firstItem; + field = TextSingleFormField::create("Benvolio"); + field->setName("first"); + firstItem.push_back(field); + + field = TextSingleFormField::create("Montague"); + field->setName("last"); + firstItem.push_back(field); + + field = JIDSingleFormField::create(JID("benvolio@montague.net")); + field->setName("jid"); + firstItem.push_back(field); + + field = ListSingleFormField::create("male"); + field->setName("x-gender"); + firstItem.push_back(field); + + Form::FormItem secondItem; + field = TextSingleFormField::create("Romeo"); + field->setName("first"); + secondItem.push_back(field); + + field = TextSingleFormField::create("Montague"); + field->setName("last"); + secondItem.push_back(field); + + field = JIDSingleFormField::create(JID("romeo@montague.net")); + field->setName("jid"); + secondItem.push_back(field); + + field = ListSingleFormField::create("male"); + field->setName("x-gender"); + secondItem.push_back(field); + + form->addItem(firstItem); + form->addItem(secondItem); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<x type=\"result\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:search</value>" + "</field>" + "<reported>" + "<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>" + "<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>" + "<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>" + "<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>" + "</reported>" + "<item>" + "<field var=\"first\"><value>Benvolio</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>benvolio@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "<item>" + "<field var=\"first\"><value>Romeo</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>romeo@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "</x>"), testling.serialize(form)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(FormSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp index d0dcbef..42bff72 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp @@ -15,6 +15,7 @@ class SearchPayloadSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(SearchPayloadSerializerTest); CPPUNIT_TEST(testSerialize_Request); CPPUNIT_TEST(testSerialize_Items); + CPPUNIT_TEST(testSerialize_DataForm); CPPUNIT_TEST_SUITE_END(); public: @@ -70,6 +71,105 @@ class SearchPayloadSerializerTest : public CppUnit::TestFixture { "</query>" ), testling.serialize(payload)); } + + void testSerialize_DataForm() { + SearchPayloadSerializer testling; + + SearchPayload::ref payload(new SearchPayload()); + boost::shared_ptr<Form> form(new Form(Form::ResultType)); + + FormField::ref field = HiddenFormField::create("jabber:iq:search"); + field->setName("FORM_TYPE"); + form->addField(field); + + // reported fields + field = TextSingleFormField::create(); + field->setName("first"); + field->setLabel("Given Name"); + form->addReportedField(field); + + field = TextSingleFormField::create(); + field->setName("last"); + field->setLabel("Family Name"); + form->addReportedField(field); + + field = JIDSingleFormField::create(); + field->setName("jid"); + field->setLabel("Jabber ID"); + form->addReportedField(field); + + field = ListSingleFormField::create(); + field->setName("x-gender"); + field->setLabel("Gender"); + form->addReportedField(field); + + Form::FormItem firstItem; + field = TextSingleFormField::create("Benvolio"); + field->setName("first"); + firstItem.push_back(field); + + field = TextSingleFormField::create("Montague"); + field->setName("last"); + firstItem.push_back(field); + + field = TextSingleFormField::create("benvolio@montague.net"); + field->setName("jid"); + firstItem.push_back(field); + + field = ListSingleFormField::create("male"); + field->setName("x-gender"); + firstItem.push_back(field); + + Form::FormItem secondItem; + field = TextSingleFormField::create("Romeo"); + field->setName("first"); + secondItem.push_back(field); + + field = TextSingleFormField::create("Montague"); + field->setName("last"); + secondItem.push_back(field); + + field = TextSingleFormField::create("romeo@montague.net"); + field->setName("jid"); + secondItem.push_back(field); + + field = ListSingleFormField::create("male"); + field->setName("x-gender"); + secondItem.push_back(field); + + form->addItem(firstItem); + form->addItem(secondItem); + + payload->setForm(form); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<query xmlns=\"jabber:iq:search\">" + "<x type=\"result\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:search</value>" + "</field>" + "<reported>" + "<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>" + "<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>" + "<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>" + "<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>" + "</reported>" + "<item>" + "<field var=\"first\"><value>Benvolio</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>benvolio@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "<item>" + "<field var=\"first\"><value>Romeo</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>romeo@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "</x>" + "</query>"), testling.serialize(payload)); + + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SearchPayloadSerializerTest); |