summaryrefslogtreecommitdiffstats
blob: a38295cc43a99d88dcbf7f2996c3fe3c4744db59 (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
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include <Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h>

using namespace Swift;

class StreamInitiationSerializerTest : public CppUnit::TestFixture{
        CPPUNIT_TEST_SUITE(StreamInitiationSerializerTest);
        CPPUNIT_TEST(testSerialize_Request);
        CPPUNIT_TEST(testSerialize_Response);
        CPPUNIT_TEST_SUITE_END();

    public:
        void testSerialize_Request() {
            StreamInitiationSerializer testling;
            std::shared_ptr<StreamInitiation> streamInitiation(new StreamInitiation());
            StreamInitiationFileInfo fileInfo("test.txt", "This is info about the file.", 1022);
            streamInitiation->setID("a0");
            streamInitiation->setFileInfo(fileInfo);
            streamInitiation->addProvidedMethod("http://jabber.org/protocol/bytestreams");
            streamInitiation->addProvidedMethod("jabber:iq:oob");
            streamInitiation->addProvidedMethod("http://jabber.org/protocol/ibb");

            CPPUNIT_ASSERT_EQUAL(std::string(
                    "<si id=\"a0\" profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">"
                        "<file name=\"test.txt\" size=\"1022\" xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">"
                            "<desc>This is info about the file.</desc>"
                        "</file>"
                        "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">"
                            "<x type=\"form\" xmlns=\"jabber:x:data\">"
                                "<field type=\"list-single\" var=\"stream-method\">"
                                    "<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>"
                    ), testling.serialize(streamInitiation));
        }

        void testSerialize_Response() {
            StreamInitiationSerializer testling;
            std::shared_ptr<StreamInitiation> streamInitiation(new StreamInitiation());
            streamInitiation->setRequestedMethod("http://jabber.org/protocol/bytestreams");

            CPPUNIT_ASSERT_EQUAL(std::string(
                    "<si profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">"
                        "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">"
                            "<x type=\"submit\" xmlns=\"jabber:x:data\">"
                                "<field type=\"list-single\" var=\"stream-method\">"
                                    "<value>http://jabber.org/protocol/bytestreams</value>"
                                "</field>"
                            "</x>"
                        "</feature>"
                    "</si>"
                    ), testling.serialize(streamInitiation));
        }

};

CPPUNIT_TEST_SUITE_REGISTRATION(StreamInitiationSerializerTest);