summaryrefslogtreecommitdiffstats
blob: 652becb1dc42a071b8281ce7b6f4e310113df6fc (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
/*
 * Copyright (c) 2011 Jan Kaluza
 * Licensed under the Simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 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/RosterItemExchangeSerializer.h>

using namespace Swift;

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

    public:
        RosterItemExchangeSerializerTest() {}

        void testSerialize() {
            RosterItemExchangeSerializer testling;
            std::shared_ptr<RosterItemExchangePayload> roster(new RosterItemExchangePayload());

            RosterItemExchangePayload::Item item1;
            item1.setJID("foo@bar.com");
            item1.setName("Foo @ Bar");
            item1.setAction(RosterItemExchangePayload::Item::Add);
            item1.addGroup("Group 1");
            item1.addGroup("Group 2");
            roster->addItem(item1);

            RosterItemExchangePayload::Item item2;
            item2.setJID("baz@blo.com");
            item2.setName("Baz");
            item2.setAction(RosterItemExchangePayload::Item::Modify);
            roster->addItem(item2);

            std::string expectedResult =
                "<x xmlns=\"http://jabber.org/protocol/rosterx\">"
                    "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">"
                        "<group>Group 1</group>"
                        "<group>Group 2</group>"
                    "</item>"
                    "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>"
                "</x>";

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

CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeSerializerTest);