summaryrefslogtreecommitdiffstats
blob: 2306e9ef8e7ae05377abf4add02285c39893af9d (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
/*
 * Copyright (c) 2015 Tarun Gupta.
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <boost/smart_ptr/make_shared.hpp>

#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> 
#include <Swiften/Elements/UserTune.h>
#include <Swiften/Base/DateTime.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);
			boost::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);
			boost::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);