summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-08-22 21:07:51 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-08-23 08:02:12 (GMT)
commit00284e5f4445a7bbab482196901c5927ea7d5488 (patch)
treef2ca6e0c51632a8aa5a7a884f3b312bacc3a2fb0 /Swiften/Serializer/PayloadSerializers/UnitTest
parent54da0a4c0cceae947afbde586a97d1cc60c50ed8 (diff)
downloadswift-00284e5f4445a7bbab482196901c5927ea7d5488.zip
swift-00284e5f4445a7bbab482196901c5927ea7d5488.tar.bz2
FormField element refactoring.
This should make FormField easier to use. Change-Id: Ia5eeedcdb673e2fe5e38fd23d5ab00970178bc44
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UnitTest')
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp57
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp5
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp29
3 files changed, 47 insertions, 44 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp
index 4608522..e4ce2c8 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 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 <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h>
using namespace Swift;
@@ -36,37 +37,37 @@ class FormSerializerTest : public CppUnit::TestFixture {
FormSerializer testling;
boost::shared_ptr<Form> form(new Form(Form::FormType));
- FormField::ref field = HiddenFormField::create("jabber:bot");
+ FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:bot");
field->setName("FORM_TYPE");
form->addField(field);
- form->addField(FixedFormField::create("Section 1: Bot Info"));
+ form->addField(boost::make_shared<FormField>(FormField::FixedType, "Section 1: Bot Info"));
- field = TextSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::TextSingleType);
field->setName("botname");
field->setLabel("The name of your bot");
form->addField(field);
- field = TextMultiFormField::create("This is a bot.\nA quite good one actually");
+ field = boost::make_shared<FormField>(FormField::TextMultiType);
+ field->setTextMultiValue("This is a bot.\nA quite good one actually");
field->setName("description");
field->setLabel("Helpful description of your bot");
form->addField(field);
- field = BooleanFormField::create(true);
+ field = boost::make_shared<FormField>(FormField::BooleanType, "1");
field->setName("public");
field->setLabel("Public bot?");
field->setRequired(true);
form->addField(field);
- field = TextPrivateFormField::create();
+ field = boost::make_shared<FormField>(FormField::TextPrivateType);
field->setName("password");
field->setLabel("Password for special access");
form->addField(field);
- std::vector<std::string> values;
- values.push_back("news");
- values.push_back("search");
- field = ListMultiFormField::create(values);
+ field = boost::make_shared<FormField>(FormField::ListMultiType);
+ field->addValue("news");
+ field->addValue("search");
field->setName("features");
field->setLabel("What features will the bot support?");
field->addOption(FormField::Option("Contests", "contests"));
@@ -76,7 +77,7 @@ class FormSerializerTest : public CppUnit::TestFixture {
field->addOption(FormField::Option("Search", "search"));
form->addField(field);
- field = ListSingleFormField::create("20");
+ field = boost::make_shared<FormField>(FormField::ListSingleType, "20");
field->setName("maxsubs");
field->setLabel("Maximum number of subscribers");
field->addOption(FormField::Option("10", "10"));
@@ -88,9 +89,9 @@ class FormSerializerTest : public CppUnit::TestFixture {
form->addField(field);
std::vector<JID> jids;
- jids.push_back(JID("foo@bar.com"));
- jids.push_back(JID("baz@fum.org"));
- field = JIDMultiFormField::create(jids);
+ field = boost::make_shared<FormField>(FormField::JIDMultiType);
+ field->addValue("foo@bar.com");
+ field->addValue("baz@fum.org");
field->setName("invitelist");
field->setLabel("People to invite");
field->setDescription("Tell all your friends about your new bot!");
@@ -140,62 +141,62 @@ class FormSerializerTest : public CppUnit::TestFixture {
boost::shared_ptr<Form> form(new Form(Form::ResultType));
- FormField::ref field = HiddenFormField::create("jabber:iq:search");
+ FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search");
field->setName("FORM_TYPE");
form->addField(field);
// reported fields
- field = TextSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::TextSingleType);
field->setName("first");
field->setLabel("Given Name");
form->addReportedField(field);
- field = TextSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::TextSingleType);
field->setName("last");
field->setLabel("Family Name");
form->addReportedField(field);
- field = JIDSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::JIDSingleType);
field->setName("jid");
field->setLabel("Jabber ID");
form->addReportedField(field);
- field = ListSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::ListSingleType);
field->setName("x-gender");
field->setLabel("Gender");
form->addReportedField(field);
Form::FormItem firstItem;
- field = TextSingleFormField::create("Benvolio");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio");
field->setName("first");
firstItem.push_back(field);
- field = TextSingleFormField::create("Montague");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague");
field->setName("last");
firstItem.push_back(field);
- field = JIDSingleFormField::create(JID("benvolio@montague.net"));
+ field = boost::make_shared<FormField>(FormField::JIDSingleType, JID("benvolio@montague.net"));
field->setName("jid");
firstItem.push_back(field);
- field = ListSingleFormField::create("male");
+ field = boost::make_shared<FormField>(FormField::ListSingleType, "male");
field->setName("x-gender");
firstItem.push_back(field);
Form::FormItem secondItem;
- field = TextSingleFormField::create("Romeo");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo");
field->setName("first");
secondItem.push_back(field);
- field = TextSingleFormField::create("Montague");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague");
field->setName("last");
secondItem.push_back(field);
- field = JIDSingleFormField::create(JID("romeo@montague.net"));
+ field = boost::make_shared<FormField>(FormField::JIDSingleType, JID("romeo@montague.net"));
field->setName("jid");
secondItem.push_back(field);
- field = ListSingleFormField::create("male");
+ field = boost::make_shared<FormField>(FormField::ListSingleType, "male");
field->setName("x-gender");
secondItem.push_back(field);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp
index df43e69..7cbce35 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 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 <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h>
@@ -38,7 +39,7 @@ class InBandRegistrationPayloadSerializerTest : public CppUnit::TestFixture {
boost::shared_ptr<Form> form(new Form(Form::FormType));
form->setTitle("Contest Registration");
- FormField::ref field = HiddenFormField::create("jabber:iq:register");
+ FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:register");
field->setName("FORM_TYPE");
form->addField(field);
registration->setForm(form);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp
index 42bff72..29e20c9 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 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 <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h>
@@ -78,62 +79,62 @@ class SearchPayloadSerializerTest : public CppUnit::TestFixture {
SearchPayload::ref payload(new SearchPayload());
boost::shared_ptr<Form> form(new Form(Form::ResultType));
- FormField::ref field = HiddenFormField::create("jabber:iq:search");
+ FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search");
field->setName("FORM_TYPE");
form->addField(field);
// reported fields
- field = TextSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::TextSingleType);
field->setName("first");
field->setLabel("Given Name");
form->addReportedField(field);
- field = TextSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::TextSingleType);
field->setName("last");
field->setLabel("Family Name");
form->addReportedField(field);
- field = JIDSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::JIDSingleType);
field->setName("jid");
field->setLabel("Jabber ID");
form->addReportedField(field);
- field = ListSingleFormField::create();
+ field = boost::make_shared<FormField>(FormField::ListSingleType);
field->setName("x-gender");
field->setLabel("Gender");
form->addReportedField(field);
Form::FormItem firstItem;
- field = TextSingleFormField::create("Benvolio");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio");
field->setName("first");
firstItem.push_back(field);
- field = TextSingleFormField::create("Montague");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague");
field->setName("last");
firstItem.push_back(field);
- field = TextSingleFormField::create("benvolio@montague.net");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "benvolio@montague.net");
field->setName("jid");
firstItem.push_back(field);
- field = ListSingleFormField::create("male");
+ field = boost::make_shared<FormField>(FormField::ListSingleType, "male");
field->setName("x-gender");
firstItem.push_back(field);
Form::FormItem secondItem;
- field = TextSingleFormField::create("Romeo");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo");
field->setName("first");
secondItem.push_back(field);
- field = TextSingleFormField::create("Montague");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague");
field->setName("last");
secondItem.push_back(field);
- field = TextSingleFormField::create("romeo@montague.net");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "romeo@montague.net");
field->setName("jid");
secondItem.push_back(field);
- field = ListSingleFormField::create("male");
+ field = boost::make_shared<FormField>(FormField::ListSingleType, "male");
field->setName("x-gender");
secondItem.push_back(field);