summaryrefslogtreecommitdiffstats
blob: 7cbce3542ba656d3df89257b6387a4c17029a609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * 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>

using namespace Swift;

class InBandRegistrationPayloadSerializerTest : public CppUnit::TestFixture {
		CPPUNIT_TEST_SUITE(InBandRegistrationPayloadSerializerTest);
		CPPUNIT_TEST(testSerialize);
		CPPUNIT_TEST(testSerialize_Form);
		CPPUNIT_TEST_SUITE_END();

	public:
		void testSerialize() {
			InBandRegistrationPayloadSerializer testling;
			boost::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload());
			registration->setRegistered(true);

			std::string expectedResult = 
				"<query xmlns=\"jabber:iq:register\">"
					"<registered/>"
				"</query>";

			CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration));
		}
		void testSerialize_Form() {
			InBandRegistrationPayloadSerializer testling;
			boost::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload());
			registration->setInstructions("Use the enclosed form to register.");

			boost::shared_ptr<Form> form(new Form(Form::FormType));
			form->setTitle("Contest Registration");

			FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:register");
			field->setName("FORM_TYPE");
			form->addField(field);
			registration->setForm(form);

			std::string expectedResult = 
				"<query xmlns=\"jabber:iq:register\">"
					"<instructions>Use the enclosed form to register.</instructions>"
					"<x type=\"form\" xmlns=\"jabber:x:data\">"
						"<title>Contest Registration</title>"
						"<field type=\"hidden\" var=\"FORM_TYPE\">"
							"<value>jabber:iq:register</value>"
						"</field>"
					"</x>"
				"</query>";

			CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration));
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadSerializerTest);