summaryrefslogtreecommitdiffstats
blob: b8ceac33526a5de8b8efb34ee2ffc199c79949fc (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
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

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

#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h"

using namespace Swift;

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

	public:
		RosterSerializerTest() {}

		void testSerialize() {
			RosterSerializer testling;
			boost::shared_ptr<RosterPayload> roster(new RosterPayload());

			RosterItemPayload item1;
			item1.setJID(JID("foo@bar.com"));
			item1.setName("Foo @ Bar");
			item1.setSubscription(RosterItemPayload::From);
			item1.addGroup("Group 1");
			item1.addGroup("Group 2");
			item1.setSubscriptionRequested();
			roster->addItem(item1);

			RosterItemPayload item2;
			item2.setJID(JID("baz@blo.com"));
			item2.setName("Baz");
			roster->addItem(item2);

			std::string expectedResult = 
				"<query xmlns=\"jabber:iq:roster\">"
					"<item ask=\"subscribe\" jid=\"foo@bar.com\" name=\"Foo @ Bar\" subscription=\"from\">"
						"<group>Group 1</group>"
						"<group>Group 2</group>"
					"</item>"
					"<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\"/>"
				"</query>";

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

		void testSerialize_ItemWithUnknownContent() {
			RosterSerializer testling;
			boost::shared_ptr<RosterPayload> roster(new RosterPayload());

			RosterItemPayload item;
			item.setJID(JID("baz@blo.com"));
			item.setName("Baz");
			item.addGroup("Group 1");
			item.addGroup("Group 2");
			item.addUnknownContent(std::string(
				"<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>"
				"<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>"));
			roster->addItem(item);

			std::string expectedResult = 
				"<query xmlns=\"jabber:iq:roster\">"
					"<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\">"
						"<group>Group 1</group>"
						"<group>Group 2</group>"
						"<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>"
						"<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>"
					"</item>"
				"</query>";

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

CPPUNIT_TEST_SUITE_REGISTRATION(RosterSerializerTest);