aboutsummaryrefslogtreecommitdiff
path: root/tests/qxmpppubsubforms/tst_qxmpppubsubforms.cpp
blob: 725059c380860d4fe82dd89e3c393c93c285c54a (plain) (blame)
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
/*
 * Copyright (C) 2008-2020 The QXmpp developers
 *
 * Author:
 *  Linus Jahn
 *
 * Source:
 *  https://github.com/qxmpp-project/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */

#include "QXmppDataFormBase.h"
#include "QXmppPubSubSubAuthorization.h"

#include "util.h"
#include <QObject>

class tst_QXmppPubSubForms : public QObject
{
    Q_OBJECT

private slots:
    void subAuthorization();

private:
};

void tst_QXmppPubSubForms::subAuthorization()
{
    QByteArray xml(R"(
<x xmlns="jabber:x:data" type="form">
<field type="hidden" var="FORM_TYPE">
<value>http://jabber.org/protocol/pubsub#subscribe_authorization</value>
</field>
<field type="boolean" var="pubsub#allow"><value>0</value></field>
<field type="text-single" var="pubsub#node"><value>princely_musings</value></field>
<field type="text-single" var="pubsub#subid"><value>123-abc</value></field>
<field type="jid-single" var="pubsub#subscriber_jid"><value>horatio@denmark.lit</value></field>
</x>)");

    QXmppDataForm form;
    parsePacket(form, xml);

    auto subAuthForm = QXmppPubSubSubAuthorization::fromDataForm(form);
    QVERIFY(subAuthForm.has_value());
    QCOMPARE(subAuthForm->subid(), QStringLiteral("123-abc"));
    QCOMPARE(subAuthForm->node(), QStringLiteral("princely_musings"));
    QCOMPARE(subAuthForm->subscriberJid(), QStringLiteral("horatio@denmark.lit"));
    QVERIFY(subAuthForm->allowSubscription().has_value());
    QCOMPARE(subAuthForm->allowSubscription().value(), false);

    form = subAuthForm->toDataForm();
    QVERIFY(!form.isNull());
    xml = QString::fromUtf8(xml).remove(QChar('\n')).toUtf8();
    serializePacket(form, xml);
}

QTEST_MAIN(tst_QXmppPubSubForms)
#include "tst_qxmpppubsubforms.moc"