summaryrefslogtreecommitdiffstats
blob: de9e8582ff3ed474aa4050c34bdfd0e3ee94f048 (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
/*
 * 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/Parser/MessageParser.h"
#include "Swiften/Parser/PayloadParserFactoryCollection.h"
#include "Swiften/Parser/UnitTest/StanzaParserTester.h"

using namespace Swift;

class MessageParserTest : public CppUnit::TestFixture
{
		CPPUNIT_TEST_SUITE(MessageParserTest);
		CPPUNIT_TEST(testParse_Normal);
		CPPUNIT_TEST(testParse_Chat);
		CPPUNIT_TEST(testParse_Error);
		CPPUNIT_TEST(testParse_Groupchat);
		CPPUNIT_TEST(testParse_Headline);
		CPPUNIT_TEST_SUITE_END();

	public:
		MessageParserTest() {}

		void setUp() {
			factoryCollection_ = new PayloadParserFactoryCollection();
		}

		void tearDown() {
			delete factoryCollection_;
		}

		void testParse_Chat() {
			MessageParser testling(factoryCollection_);
			StanzaParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse("<message type=\"chat\"/>"));

			CPPUNIT_ASSERT_EQUAL(Message::Chat, testling.getStanzaGeneric()->getType());
		}

		void testParse_Groupchat() {
			MessageParser testling(factoryCollection_);
			StanzaParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse("<message type=\"groupchat\"/>"));

			CPPUNIT_ASSERT_EQUAL(Message::Groupchat, testling.getStanzaGeneric()->getType());
		}

		void testParse_Error() {
			MessageParser testling(factoryCollection_);
			StanzaParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse("<message type=\"error\"/>"));

			CPPUNIT_ASSERT_EQUAL(Message::Error, testling.getStanzaGeneric()->getType());
		}

		void testParse_Headline() {
			MessageParser testling(factoryCollection_);
			StanzaParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse("<message type=\"headline\"/>"));

			CPPUNIT_ASSERT_EQUAL(Message::Headline, testling.getStanzaGeneric()->getType());
		}

		void testParse_Normal() {
			MessageParser testling(factoryCollection_);
			StanzaParserTester parser(&testling);

			CPPUNIT_ASSERT(parser.parse("<message/>"));

			CPPUNIT_ASSERT_EQUAL(Message::Normal, testling.getStanzaGeneric()->getType());
		}

		private:
			PayloadParserFactoryCollection* factoryCollection_;
};

CPPUNIT_TEST_SUITE_REGISTRATION(MessageParserTest);