summaryrefslogtreecommitdiffstats
blob: c728bde8ec10941414ee08773422e21b1cb397c7 (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
/*
 * 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/Elements/Form.h>

using namespace Swift;

class FormTest : public CppUnit::TestFixture {
        CPPUNIT_TEST_SUITE(FormTest);
        CPPUNIT_TEST(testGetFormType);
        CPPUNIT_TEST(testGetFormType_InvalidFormType);
        CPPUNIT_TEST(testGetFormType_NoFormType);
        CPPUNIT_TEST_SUITE_END();

    public:
        void testGetFormType() {
            Form form;

            form.addField(std::make_shared<FormField>(FormField::FixedType, "Foo"));

            FormField::ref field = std::make_shared<FormField>(FormField::HiddenType, "jabber:bot");
            field->setName("FORM_TYPE");
            form.addField(field);

            form.addField(std::make_shared<FormField>(FormField::FixedType, "Bar"));

            CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), form.getFormType());
        }

        void testGetFormType_InvalidFormType() {
            Form form;

            FormField::ref field = std::make_shared<FormField>(FormField::FixedType, "jabber:bot");
            field->setName("FORM_TYPE");
            form.addField(field);

            CPPUNIT_ASSERT_EQUAL(std::string(""), form.getFormType());
        }

        void testGetFormType_NoFormType() {
            Form form;

            form.addField(std::make_shared<FormField>(FormField::FixedType, "Foo"));

            CPPUNIT_ASSERT_EQUAL(std::string(""), form.getFormType());
        }
};

CPPUNIT_TEST_SUITE_REGISTRATION(FormTest);