summaryrefslogtreecommitdiffstats
blob: fa188b7ad49dd0d1b699d2039aaed16930fd0b56 (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
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include "Swiften/Parser/PayloadParsers/StorageParser.h"
#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h"

using namespace Swift;

class StorageParserTest : public CppUnit::TestFixture
{
		CPPUNIT_TEST_SUITE(StorageParserTest);
		CPPUNIT_TEST(testParse_Conference);
		CPPUNIT_TEST(testParse_MultipleConferences);
		CPPUNIT_TEST_SUITE_END();

	public:
		StorageParserTest() {}

		void testParse_Conference() {
			StorageParser testling;
			PayloadParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse(
				"<storage xmlns='storage:bookmarks'>"
					"<conference "
							"name='Council of Oberon' "
							"autojoin='true' jid='council@conference.underhill.org'>"
						"<nick>Puck</nick>"
						"<password>MyPass</password>"
					"</conference>"
				"</storage>"));

			Storage* payload = dynamic_cast<Storage*>(testling.getPayload().get());
			std::vector<Storage::Conference> conferences = payload->getConferences();
			CPPUNIT_ASSERT_EQUAL(1U, conferences.size());
			CPPUNIT_ASSERT_EQUAL(String("Council of Oberon"), conferences[0].name);
			CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), conferences[0].jid);
			CPPUNIT_ASSERT(conferences[0].autoJoin);
			CPPUNIT_ASSERT_EQUAL(String("Puck"), conferences[0].nick);
			CPPUNIT_ASSERT_EQUAL(String("MyPass"), conferences[0].password);
		}

		void testParse_MultipleConferences() {
			StorageParser testling;
			PayloadParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse(
				"<storage xmlns='storage:bookmarks'>"
					"<conference "
							"name='Council of Oberon' "
							"jid='council@conference.underhill.org' />"
					"<conference "
							"name='Tea party' "
							"jid='teaparty@wonderland.lit' />"
				"</storage>"));

			Storage* payload = dynamic_cast<Storage*>(testling.getPayload().get());
			std::vector<Storage::Conference> conferences = payload->getConferences();
			CPPUNIT_ASSERT_EQUAL(2U, conferences.size());
			CPPUNIT_ASSERT_EQUAL(String("Council of Oberon"), conferences[0].name);
			CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), conferences[0].jid);
			CPPUNIT_ASSERT_EQUAL(String("Tea party"), conferences[1].name);
			CPPUNIT_ASSERT_EQUAL(JID("teaparty@wonderland.lit"), conferences[1].jid);
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(StorageParserTest);