blob: f9a9efd7e999f9745fc7b17e6916170942f5e39e (
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
|
/*
* Copyright (c) 2015 Tarun Gupta.
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
#include <Swiften/Elements/Form.h>
#include <Swiften/Elements/InBandRegistrationPayload.h>
using namespace Swift;
class InBandRegistrationPayloadParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParse_Form);
CPPUNIT_TEST_SUITE_END();
public:
InBandRegistrationPayloadParserTest() {}
void testParse() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<query xmlns=\"jabber:iq:register\">"
"<registered/>"
"</query>"));
InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get());
CPPUNIT_ASSERT(payload);
CPPUNIT_ASSERT(payload->isRegistered());
}
void testParse_Form() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<query xmlns=\"jabber:iq:register\">"
"<instructions>Use the enclosed form to register.</instructions>"
"<x type=\"form\" xmlns=\"jabber:x:data\">"
"<title>Contest Registration</title>"
"<field type=\"hidden\" var=\"FORM_TYPE\">"
"<value>jabber:iq:register</value>"
"</field>"
"</x>"
"</query>"));
InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get());
CPPUNIT_ASSERT(payload);
boost::optional<std::string> instruction = payload->getInstructions();
CPPUNIT_ASSERT(instruction);
CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get());
Form::ref form = payload->getForm();
CPPUNIT_ASSERT(form);
CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle());
CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType());
CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadParserTest);
|