summaryrefslogtreecommitdiffstats
blob: df79f0df0084dab64909b265fce9933c1d6f8a60 (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
64
65
66
67
68
69
/*
 * Copyright (c) 2015 Tarun Gupta.
 * 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 <memory>

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

#include <Swiften/Base/DateTime.h>
#include <Swiften/Elements/UserTune.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h>

using namespace Swift;

class UserTuneSerializerTest : public CppUnit::TestFixture {
        CPPUNIT_TEST_SUITE(UserTuneSerializerTest);
        CPPUNIT_TEST(testSerialize_withAllVariablesSet);
        CPPUNIT_TEST(testSerialize_withSomeVariablesSet);
        CPPUNIT_TEST_SUITE_END();

    public:
        void testSerialize_withAllVariablesSet() {
            UserTuneSerializer testling(&serializers);
            std::shared_ptr<UserTune> userTune(new UserTune());
            userTune->setRating(5);
            userTune->setTitle(boost::optional<std::string>("Minion"));
            userTune->setTrack(boost::optional<std::string>("Yellow"));
            userTune->setArtist(boost::optional<std::string>("Ice"));
            userTune->setURI(boost::optional<std::string>("Fire"));
            userTune->setSource(boost::optional<std::string>("Origin"));
            userTune->setLength(226);

            std::string expectedResult =
                                "<tune xmlns=\"http://jabber.org/protocol/tune\">"
                                "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><uri>Fire</uri><source>Origin</source><length>226</length></tune>";

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

        void testSerialize_withSomeVariablesSet() {
            UserTuneSerializer testling(&serializers);
            std::shared_ptr<UserTune> userTune(new UserTune());
            userTune->setTitle(boost::optional<std::string>("Minion"));
            userTune->setTrack(boost::optional<std::string>("Yellow"));
            userTune->setArtist(boost::optional<std::string>("Ice"));
            userTune->setSource(boost::optional<std::string>("Origin"));
            userTune->setLength(226);

            std::string expectedResult =
                                "<tune xmlns=\"http://jabber.org/protocol/tune\">"
                                "<title>Minion</title><track>Yellow</track><artist>Ice</artist><source>Origin</source><length>226</length></tune>";

            CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune));
        }
    private:
        FullPayloadSerializerCollection serializers;
};

CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneSerializerTest);