summaryrefslogtreecommitdiffstats
blob: 88d8fc1eff7aff84455ec624cdc58a82fc598b3e (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * Copyright (c) 2017 Tarun Gupta
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <gtest/gtest.h>

#include <Swiften/Elements/MIXJoin.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>

using namespace Swift;

TEST(MIXJoinParserTest, XEP0369_Example22) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<join xmlns=\"urn:xmpp:mix:0\" channel=\"coven@mix.shakespeare.example\">"
                    "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
                "</join>"
                ));

    MIXJoin::ref payload = parser.getPayload<MIXJoin>();
    ASSERT_TRUE(payload);

    ASSERT_TRUE(payload->getChannel());
    ASSERT_EQ(JID("coven@mix.shakespeare.example"), *payload->getChannel());
    ASSERT_FALSE(payload->getJID());
    ASSERT_FALSE(payload->getForm());

    const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
    ASSERT_EQ(static_cast<size_t>(4), items.size());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:participants"), items[2]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:config"), items[3]->getNode());
}

TEST(MIXJoinParserTest, XEP0369_Example23) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<join xmlns=\"urn:xmpp:mix:0\">"
                    "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
                "</join>"
                ));

    MIXJoin::ref payload = parser.getPayload<MIXJoin>();
    ASSERT_TRUE(payload);

    ASSERT_FALSE(payload->getChannel());
    ASSERT_FALSE(payload->getJID());
    ASSERT_FALSE(payload->getForm());

    const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
    ASSERT_EQ(static_cast<size_t>(4), items.size());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:participants"), items[2]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:config"), items[3]->getNode());
}

TEST(MIXJoinParserTest, XEP0369_Example24) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<join xmlns=\"urn:xmpp:mix:0\" jid=\"123456#coven@mix.shakespeare.example\">"
                    "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
                "</join>"
                ));

    MIXJoin::ref payload = parser.getPayload<MIXJoin>();
    ASSERT_TRUE(payload);

    ASSERT_FALSE(payload->getChannel());
    ASSERT_TRUE(payload->getJID());
    ASSERT_EQ(JID("123456#coven@mix.shakespeare.example"), *payload->getJID());
    ASSERT_FALSE(payload->getForm());

    const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
    ASSERT_EQ(static_cast<size_t>(4), items.size());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:participants"), items[2]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:config"), items[3]->getNode());
}

TEST(MIXJoinParserTest, XEP0369_Example29) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<join xmlns=\"urn:xmpp:mix:0\">"
                    "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
                    "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
                    "<x xmlns=\"jabber:x:data\" type=\"submit\">"
                        "<field var=\"FORM_TYPE\" type=\"hidden\">"
                             "<value>urn:xmpp:mix:0</value>"
                        "</field>"
                        "<field var=\"JID Visibility\">"
                            "<value>never</value>"
                        "</field>"
                    "</x>"
                "</join>"));

    MIXJoin::ref payload = parser.getPayload<MIXJoin>();
    ASSERT_TRUE(payload);

    ASSERT_FALSE(payload->getChannel());
    ASSERT_FALSE(payload->getJID());
    const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
    ASSERT_EQ(static_cast<size_t>(2), items.size());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());

    ASSERT_TRUE(payload->getForm());
    ASSERT_EQ(Form::Type::SubmitType, payload->getForm()->getType());
    std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE");
    ASSERT_TRUE(fieldType);

    std::shared_ptr<FormField> fieldJIDVisibility = payload->getForm()->getField("JID Visibility");
    ASSERT_TRUE(fieldJIDVisibility);
    ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue());
}

TEST(MIXJoinParserTest, XEP0369_Example30) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
        "<join xmlns=\"urn:xmpp:mix:0\" jid=\"hag66@shakespeare.example\">"
            "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
            "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
            "<x xmlns=\"jabber:x:data\" type=\"result\">"
                "<field var=\"FORM_TYPE\" type=\"hidden\">"
                    "<value>urn:xmpp:mix:0</value>"
                "</field>"
                "<field var=\"JID Visibility\">"
                    "<value>never</value>"
                "</field>"
                "<field var=\"Private Messages\">"
                    "<value>allow</value>"
                "</field>"
                "<field var=\"vCard\">"
                    "<value>block</value>"
                "</field>"
            "</x>"
        "</join>"));

    MIXJoin::ref payload = parser.getPayload<MIXJoin>();
    ASSERT_TRUE(payload);

    ASSERT_FALSE(payload->getChannel());
    ASSERT_TRUE(payload->getJID());
    ASSERT_EQ(JID("hag66@shakespeare.example"), *payload->getJID());

    const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
    ASSERT_EQ(static_cast<size_t>(2), items.size());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
    ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());

    ASSERT_TRUE(payload->getForm());
    ASSERT_EQ(Form::Type::ResultType, payload->getForm()->getType());
    std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE");
    ASSERT_TRUE(fieldType);

    std::shared_ptr<FormField> fieldJIDVisibility = payload->getForm()->getField("JID Visibility");
    ASSERT_TRUE(fieldJIDVisibility);
    ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue());

    std::shared_ptr<FormField> fieldprivateMessages = payload->getForm()->getField("Private Messages");
    ASSERT_TRUE(fieldprivateMessages);
    ASSERT_EQ(std::string("allow"), fieldprivateMessages->getTextSingleValue());

    std::shared_ptr<FormField> vCard = payload->getForm()->getField("vCard");
    ASSERT_TRUE(vCard);
    ASSERT_EQ(std::string("block"), vCard->getTextSingleValue());
}