summaryrefslogtreecommitdiffstats
blob: 641b856133ac924298c6e702e759b87548da8340 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (c) 2014 Kevin Smith and Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <boost/smart_ptr/make_shared.hpp>

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

#include <Swiften/Serializer/PayloadSerializers/ResultSetSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
#include <Swiften/Elements/ResultSet.h>

using namespace Swift;

class ResultSetSerializerTest : public CppUnit::TestFixture {
		CPPUNIT_TEST_SUITE(ResultSetSerializerTest);
		CPPUNIT_TEST(testSerializeFull);
		CPPUNIT_TEST(testSerializeMaxItems);
		CPPUNIT_TEST(testSerializeFirst);
		CPPUNIT_TEST(testSerializeFirstWithIndex);
		CPPUNIT_TEST_SUITE_END();

	public:
		void testSerializeFull() {
			ResultSetSerializer serializer;

			boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>());

			resultSet->setMaxItems(100);
			resultSet->setCount(800);
			resultSet->setFirstIDIndex(123);
			resultSet->setFirstID(std::string("stpeter@jabber.org"));
			resultSet->setLastID(std::string("peterpan@neverland.lit"));
			resultSet->setAfter(std::string("09af3-cc343-b409f"));

			std::string expectedResult = 
				"<set xmlns=\"http://jabber.org/protocol/rsm\">"
					"<max>100</max>"
					"<count>800</count>"
					"<first index=\"123\">stpeter@jabber.org</first>"
					"<last>peterpan@neverland.lit</last>"
					"<after>09af3-cc343-b409f</after>"
				"</set>";

			CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet));
		}

		void testSerializeMaxItems() {
			ResultSetSerializer serializer;

			boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>());

			resultSet->setMaxItems(100);

			std::string expectedResult = 
				"<set xmlns=\"http://jabber.org/protocol/rsm\">"
					"<max>100</max>"
				"</set>";

			CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet));
		}

		void testSerializeFirst() {
			ResultSetSerializer serializer;

			boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>());

			resultSet->setFirstID(std::string("stpeter@jabber.org"));

			std::string expectedResult = 
				"<set xmlns=\"http://jabber.org/protocol/rsm\">"
					"<first>stpeter@jabber.org</first>"
				"</set>";

			CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet));
		}

		void testSerializeFirstWithIndex() {
			ResultSetSerializer serializer;

			boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>());

			resultSet->setFirstID(std::string("stpeter@jabber.org"));
			resultSet->setFirstIDIndex(123);

			std::string expectedResult = 
				"<set xmlns=\"http://jabber.org/protocol/rsm\">"
					"<first index=\"123\">stpeter@jabber.org</first>"
				"</set>";

			CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet));
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetSerializerTest);