aboutsummaryrefslogtreecommitdiff
path: root/tests/qxmppresultset/tst_qxmppresultset.cpp
blob: 8238b5e6a2ac8c4076bb8723c4eff7292be7f93c (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
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
// SPDX-FileCopyrightText: 2012 Oliver Goffart <ogoffart@woboq.com>
// SPDX-FileCopyrightText: 2012 Jeremy Lainé <jeremy.laine@m4x.org>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "QXmppResultSet.h"

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

class tst_QXmppResultSet : public QObject
{
    Q_OBJECT

private:
    Q_SLOT void testQuery_data();
    Q_SLOT void testQuery();
    Q_SLOT void testReply_data();
    Q_SLOT void testReply();
};

void tst_QXmppResultSet::testQuery_data()
{
    QTest::addColumn<QByteArray>("xml");
    QTest::addColumn<int>("max");
    QTest::addColumn<int>("index");
    QTest::addColumn<QString>("before");
    QTest::addColumn<QString>("after");

    QTest::newRow("Example 3") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<max>10</max>"
                                             "</set>")
                               << 10 << -1 << QString() << QString();

    QTest::newRow("Example 5") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<max>10</max>"
                                             "<after>peterpan@neverland.lit</after>"
                                             "</set>")
                               << 10 << -1 << QString() << QString("peterpan@neverland.lit");

    QTest::newRow("Example 5") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<max>10</max>"
                                             "<before>peter@pixyland.org</before>"
                                             "</set>")
                               << 10 << -1 << QString("peter@pixyland.org") << QString();

    QTest::newRow("Example 11") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                              "<max>10</max>"
                                              "<before/>"
                                              "</set>")
                                << 10 << -1 << QString("") << QString();

    QTest::newRow("Example 12") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                              "<max>10</max>"
                                              "<index>371</index>"
                                              "</set>")
                                << 10 << 371 << QString() << QString();

    QTest::newRow("Example 15") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                              "<max>0</max>"
                                              "</set>")
                                << 0 << -1 << QString() << QString();
}

void tst_QXmppResultSet::testQuery()
{
    QFETCH(QByteArray, xml);
    QFETCH(int, max);
    QFETCH(int, index);
    QFETCH(QString, before);
    QFETCH(QString, after);

    QXmppResultSetQuery iq;
    parsePacket(iq, xml);
    QCOMPARE(iq.max(), max);
    QCOMPARE(iq.index(), index);
    QCOMPARE(iq.before(), before);
    QCOMPARE(iq.before().isNull(), before.isNull());
    QCOMPARE(iq.after(), after);
    QCOMPARE(iq.after().isNull(), after.isNull());
    serializePacket(iq, xml);
}

void tst_QXmppResultSet::testReply_data()
{
    QTest::addColumn<QByteArray>("xml");
    QTest::addColumn<int>("count");
    QTest::addColumn<int>("index");
    QTest::addColumn<QString>("first");
    QTest::addColumn<QString>("last");

    QTest::newRow("Example 4") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<first index=\"0\">stpeter@jabber.org</first>"
                                             "<last>peterpan@neverland.lit</last>"
                                             "<count>800</count>"
                                             "</set>")
                               << 800 << 0 << QString("stpeter@jabber.org") << QString("peterpan@neverland.lit");

    QTest::newRow("Example 6") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<first index=\"0\">stpeter@jabber.org</first>"
                                             "<last>peterpan@neverland.lit</last>"
                                             "<count>800</count>"
                                             "</set>")
                               << 800 << 0 << QString("stpeter@jabber.org") << QString("peterpan@neverland.lit");
    QTest::newRow("Example 4") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<first index=\"10\">peter@pixyland.org</first>"
                                             "<last>peter@rabbit.lit</last>"
                                             "<count>800</count>"
                                             "</set>")
                               << 800 << 10 << QString("peter@pixyland.org") << QString("peter@rabbit.lit");

    QTest::newRow("Example 7") << QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">"
                                             "<count>790</count>"
                                             "</set>")
                               << 790 << -1 << QString() << QString();
}

void tst_QXmppResultSet::testReply()
{
    QFETCH(QByteArray, xml);
    QFETCH(int, count);
    QFETCH(int, index);
    QFETCH(QString, first);
    QFETCH(QString, last);

    QXmppResultSetReply iq;
    parsePacket(iq, xml);
    QCOMPARE(iq.count(), count);
    QCOMPARE(iq.index(), index);
    QCOMPARE(iq.first(), first);
    QCOMPARE(iq.first().isNull(), first.isNull());
    QCOMPARE(iq.last(), last);
    QCOMPARE(iq.last().isNull(), last.isNull());
    serializePacket(iq, xml);
}

QTEST_MAIN(tst_QXmppResultSet)
#include "tst_qxmppresultset.moc"