summaryrefslogtreecommitdiffstats
blob: 44ac7a1930ac85c7b98f19b9e0af8b396c11bbeb (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
63
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <memory>

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#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;
            std::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;
            std::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload());
            registration->setInstructions("Use the enclosed form to register.");

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

            FormField::ref field = std::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);