blob: 68df71b2b4fd82ef9762bc7e2a28e2be6e2353c2 (
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
|
/*
* Copyright (c) 2014 Kevin Smith and 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/PayloadParsers/ResultSetParser.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
using namespace Swift;
class ResultSetParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(ResultSetParserTest);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParseFirstNoIndex);
CPPUNIT_TEST_SUITE_END();
public:
void testParse() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<set xmlns=\"http://jabber.org/protocol/rsm\">"
"<max>100</max>"
"<count>800</count>"
"<first index=\"123\">stpeter@jabber.org</first>"
"<last>peterpan@neverland.lit</last>"
"<after>09af3-cc343-b409f</after>"
"</set>"));
boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>();
CPPUNIT_ASSERT(!!payload);
CPPUNIT_ASSERT(payload->getMaxItems());
CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems());
CPPUNIT_ASSERT(payload->getCount());
CPPUNIT_ASSERT_EQUAL(800, *payload->getCount());
CPPUNIT_ASSERT(payload->getFirstID());
CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID());
CPPUNIT_ASSERT(payload->getFirstIDIndex());
CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex());
CPPUNIT_ASSERT(payload->getLastID());
CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID());
CPPUNIT_ASSERT(payload->getAfter());
CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter());
}
void testParseFirstNoIndex() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<set xmlns=\"http://jabber.org/protocol/rsm\">"
"<first>stpeter@jabber.org</first>"
"</set>"));
boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>();
CPPUNIT_ASSERT(!!payload);
CPPUNIT_ASSERT(payload->getFirstID());
CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID());
CPPUNIT_ASSERT(!payload->getFirstIDIndex());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetParserTest);
|