blob: 80014870f9bd45bf1eab71144f46c115278aeaab (
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
|
/*
* 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/PayloadParsers/UnitTest/PayloadsParserTester.h"
#include "Swiften/Elements/StreamInitiation.h"
using namespace Swift;
class StreamInitiationParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(StreamInitiationParserTest);
CPPUNIT_TEST(testParse_Request);
CPPUNIT_TEST(testParse_Response);
CPPUNIT_TEST_SUITE_END();
public:
void testParse_Request() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<si xmlns='http://jabber.org/protocol/si' id='a0' mime-type='text/plain' profile='http://jabber.org/protocol/si/profile/file-transfer'>"
"<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='test.txt' size='1022'>"
"<desc>This is info about the file.</desc>"
"</file>"
"<feature xmlns='http://jabber.org/protocol/feature-neg'>"
"<x xmlns='jabber:x:data' type='form'>"
"<field var='stream-method' type='list-single'>"
"<option><value>http://jabber.org/protocol/bytestreams</value></option>"
"<option><value>jabber:iq:oob</value></option>"
"<option><value>http://jabber.org/protocol/ibb</value></option>"
"</field>"
"</x>"
"</feature>"
"</si>"
));
StreamInitiation::ref si = parser.getPayload<StreamInitiation>();
CPPUNIT_ASSERT(si->getIsFileTransfer());
CPPUNIT_ASSERT(si->getFileInfo());
CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), si->getFileInfo()->name);
CPPUNIT_ASSERT_EQUAL(1022, si->getFileInfo()->size);
CPPUNIT_ASSERT_EQUAL(std::string("This is info about the file."), si->getFileInfo()->description);
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(si->getProvidedMethods().size()));
CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getProvidedMethods()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:oob"), si->getProvidedMethods()[1]);
CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/ibb"), si->getProvidedMethods()[2]);
}
void testParse_Response() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<si xmlns='http://jabber.org/protocol/si'>"
"<feature xmlns='http://jabber.org/protocol/feature-neg'>"
"<x xmlns='jabber:x:data' type='submit'>"
"<field var='stream-method'>"
"<value>http://jabber.org/protocol/bytestreams</value>"
"</field>"
"</x>"
"</feature>"
"</si>"
));
StreamInitiation::ref si = parser.getPayload<StreamInitiation>();
CPPUNIT_ASSERT(si->getIsFileTransfer());
CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getRequestedMethod());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(StreamInitiationParserTest);
|