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

#include <gtest/gtest.h>

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

#include <Swiften/Elements/Body.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>

using namespace Swift;

static FullPayloadSerializerCollection serializers;

TEST(ReferencePayloadSerializerTest, testSerialize) {
    ReferencePayloadSerializer testling(&serializers);
    auto reference = std::make_shared<ReferencePayload>();
    reference->setType(ReferencePayload::Type::Data);
    reference->setUri(boost::optional<std::string>("https://www.example.com/mindBlowingImage.jpeg"));
    reference->setBegin(boost::optional<std::string>("11"));
    reference->setEnd(boost::optional<std::string>("22"));
    reference->setAnchor(boost::optional<std::string>("xmpp:data@localhost.example.test"));

    std::string expectedResult =
        "<reference "
            "anchor=\"xmpp:data@localhost.example.test\" "
            "begin=\"11\" "
            "end=\"22\" "
            "type=\"data\" "
            "uri=\"https://www.example.com/mindBlowingImage.jpeg\" "
            "xmlns=\"urn:xmpp:reference:0\"/>";

    ASSERT_EQ(expectedResult, testling.serialize(reference));
}

TEST(ReferencePayloadSerializerTest, testSerializeNoType) {
    ReferencePayloadSerializer testling(&serializers);
    auto reference = std::make_shared<ReferencePayload>();
    reference->setUri(boost::optional<std::string>("https://www.example.com/mindBlowingImage.jpeg"));
    reference->setBegin(boost::optional<std::string>("11"));
    reference->setEnd(boost::optional<std::string>("22"));
    reference->setAnchor(boost::optional<std::string>("xmpp:data@localhost.example.test"));

    std::string expectedResult =
        "<reference "
            "anchor=\"xmpp:data@localhost.example.test\" "
            "begin=\"11\" "
            "end=\"22\" "
            "type=\"data\" "
            "uri=\"https://www.example.com/mindBlowingImage.jpeg\" "
            "xmlns=\"urn:xmpp:reference:0\"/>";

    ASSERT_EQ(expectedResult, testling.serialize(reference));
}

TEST(ReferencePayloadSerializerTest, testSerializeWithEmbeddedPayload) {
    ReferencePayloadSerializer testling(&serializers);
    auto reference = std::make_shared<ReferencePayload>();
    reference->setUri(boost::optional<std::string>("https://www.example.com/mindBlowingImage.jpeg"));
    reference->setBegin(boost::optional<std::string>("11"));
    reference->setEnd(boost::optional<std::string>("22"));
    reference->setAnchor(boost::optional<std::string>("xmpp:data@localhost.example.test"));
    auto payload = std::make_shared<Body>(std::string("Look, I'm in a reference"));
    reference->addPayload(payload);

    std::string expectedResult =
        "<reference "
            "anchor=\"xmpp:data@localhost.example.test\" "
            "begin=\"11\" "
            "end=\"22\" "
            "type=\"data\" "
            "uri=\"https://www.example.com/mindBlowingImage.jpeg\" "
            "xmlns=\"urn:xmpp:reference:0\">"
            "<body>Look, I'm in a reference</body>"
        "</reference>";

    ASSERT_EQ(expectedResult, testling.serialize(reference));
}