summaryrefslogtreecommitdiffstats
blob: 2750c9f8ad6b331b9801262c0c79c3407765c0e2 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Copyright (c) 2014 Isode Limited.
 * All rights reserved.
 * See the COPYING file 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(testSerializeEmptyBefore);
		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->setIndex(0);
			resultSet->setFirstIDIndex(123);
			resultSet->setFirstID(std::string("stpeter@jabber.org"));
			resultSet->setLastID(std::string("peterpan@neverland.lit"));
			resultSet->setAfter(std::string("09af3-cc343-b409f"));
			resultSet->setBefore(std::string("decaf-badba-dbad1"));

			std::string expectedResult = 
				"<set xmlns=\"http://jabber.org/protocol/rsm\">"
					"<max>100</max>"
					"<count>800</count>"
					"<index>0</index>"
					"<first index=\"123\">stpeter@jabber.org</first>"
					"<last>peterpan@neverland.lit</last>"
					"<before>decaf-badba-dbad1</before>"
					"<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 testSerializeEmptyBefore() {
			ResultSetSerializer serializer;

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

			resultSet->setBefore(std::string());

			std::string expectedResult =
				"<set xmlns=\"http://jabber.org/protocol/rsm\">"
					"<before/>"
				"</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);