blob: f68db408fb0b2e018cb68c880580ab71cb44afd0 (
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
|
/*
* 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/PresenceParser.h"
#include "Swiften/Parser/PayloadParserFactoryCollection.h"
#include "Swiften/Parser/UnitTest/StanzaParserTester.h"
using namespace Swift;
class PresenceParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(PresenceParserTest);
CPPUNIT_TEST(testParse_Available);
CPPUNIT_TEST(testParse_Unavailable);
CPPUNIT_TEST(testParse_Subscribe);
CPPUNIT_TEST(testParse_Subscribed);
CPPUNIT_TEST(testParse_Unsubscribe);
CPPUNIT_TEST(testParse_Unsubscribed);
CPPUNIT_TEST(testParse_Probe);
CPPUNIT_TEST(testParse_Error);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
factoryCollection_ = new PayloadParserFactoryCollection();
}
void tearDown() {
delete factoryCollection_;
}
void testParse_Available() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Available, testling.getStanzaGeneric()->getType());
}
void testParse_Unavailable() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"unavailable\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, testling.getStanzaGeneric()->getType());
}
void testParse_Probe() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"probe\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Probe, testling.getStanzaGeneric()->getType());
}
void testParse_Subscribe() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribe\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Subscribe, testling.getStanzaGeneric()->getType());
}
void testParse_Subscribed() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribed\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Subscribed, testling.getStanzaGeneric()->getType());
}
void testParse_Unsubscribe() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribe\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribe, testling.getStanzaGeneric()->getType());
}
void testParse_Unsubscribed() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribed\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribed, testling.getStanzaGeneric()->getType());
}
void testParse_Error() {
PresenceParser testling(factoryCollection_);
StanzaParserTester parser(&testling);
CPPUNIT_ASSERT(parser.parse("<presence type=\"error\"/>"));
CPPUNIT_ASSERT_EQUAL(Presence::Error, testling.getStanzaGeneric()->getType());
}
private:
PayloadParserFactoryCollection* factoryCollection_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(PresenceParserTest);
|