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

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

#include <Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h>

using namespace Swift;

class ResourceBindSerializerTest : public CppUnit::TestFixture
{
        CPPUNIT_TEST_SUITE(ResourceBindSerializerTest);
        CPPUNIT_TEST(testSerialize_JID);
        CPPUNIT_TEST(testSerialize_Resource);
        CPPUNIT_TEST(testSerialize_Empty);
        CPPUNIT_TEST_SUITE_END();

    public:
        ResourceBindSerializerTest() {}

        void testSerialize_JID() {
            ResourceBindSerializer testling;
            std::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
            resourceBind->setJID(JID("somenode@example.com/someresource"));

            CPPUNIT_ASSERT_EQUAL(std::string(
                "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"
                    "<jid>somenode@example.com/someresource</jid>"
                "</bind>"), testling.serialize(resourceBind));
        }

        void testSerialize_Resource() {
            ResourceBindSerializer testling;
            std::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
            resourceBind->setResource("someresource");

            CPPUNIT_ASSERT_EQUAL(std::string(
                "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"
                    "<resource>someresource</resource>"
                "</bind>"), testling.serialize(resourceBind));
        }

        void testSerialize_Empty() {
            ResourceBindSerializer testling;
            std::shared_ptr<ResourceBind> resourceBind(new ResourceBind());

            CPPUNIT_ASSERT_EQUAL(std::string("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"), testling.serialize(resourceBind));
        }
};

CPPUNIT_TEST_SUITE_REGISTRATION(ResourceBindSerializerTest);