summaryrefslogtreecommitdiffstats
blob: 27c02e71137770e9581bc951724ba78709c4cf66 (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
/*
 * 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/MIXParticipant.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>

using namespace Swift;

TEST(MIXParticipantParserTest, XEP0369_Example1_ParticipantWithNick) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<participant xmlns='urn:xmpp:mix:0'> <nick>thirdwitch</nick> </participant>"
                ));

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

    ASSERT_TRUE(payload->getNick());
    std::string nick = *payload->getNick();
    ASSERT_EQ("thirdwitch", nick);

    ASSERT_FALSE(payload->getJID());
}

TEST(MIXParticipantParserTest, XEP0369_Example2_ParticipantWithJID) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<participant xmlns='urn:xmpp:mix:0'> <jid>hecate@mix.shakespeare.example</jid> </participant>"
                ));

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

    ASSERT_TRUE(payload->getJID());
    JID jid = *payload->getJID();
    ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString());

    ASSERT_FALSE(payload->getNick());
}

TEST(MIXParticipantParserTest, XEP0369_Example27_ParticipantEmpty) {
    PayloadsParserTester parser;
    ASSERT_TRUE(parser.parse(
                "<participant xmlns='urn:xmpp:mix:0'/>"
                ));

    MIXParticipant::ref payload = parser.getPayload<MIXParticipant>();
    ASSERT_TRUE(payload);
    ASSERT_FALSE(payload->getNick());
    ASSERT_FALSE(payload->getJID());
}