diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-07-18 14:07:51 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-07-18 14:07:51 +0200 |
| commit | 088c9cdd984a08d044064a24a4f898d290297b02 (patch) | |
| tree | 404342ce3aaa02bda09bf919a081a920772cc6b0 | |
| parent | 2da1035a984946d2920773de6b32abc46aef6288 (diff) | |
| download | qxmpp-088c9cdd984a08d044064a24a4f898d290297b02.tar.gz | |
split result-set tests
| -rw-r--r-- | tests/rsm.cpp | 155 | ||||
| -rw-r--r-- | tests/rsm.h | 37 | ||||
| -rw-r--r-- | tests/tests.cpp | 129 | ||||
| -rw-r--r-- | tests/tests.h | 11 | ||||
| -rw-r--r-- | tests/tests.pro | 2 |
5 files changed, 196 insertions, 138 deletions
diff --git a/tests/rsm.cpp b/tests/rsm.cpp new file mode 100644 index 00000000..fde8711f --- /dev/null +++ b/tests/rsm.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * Olivier Goffart + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/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 "QXmppResultSet.h" + +#include "rsm.h" +#include "tests.h" + +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); +} + diff --git a/tests/rsm.h b/tests/rsm.h new file mode 100644 index 00000000..120ea625 --- /dev/null +++ b/tests/rsm.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * Olivier Goffart + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/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 <QObject> + +class tst_QXmppResultSet : public QObject +{ + Q_OBJECT + +private slots: + void testQuery_data(); + void testQuery(); + void testReply_data(); + void testReply(); +}; + diff --git a/tests/tests.cpp b/tests/tests.cpp index c9cd03f1..bc66a25a 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -55,6 +55,7 @@ #include "dataform.h" #include "register.h" +#include "rsm.h" #include "rtp.h" #include "tests.h" @@ -1267,132 +1268,6 @@ private: QString m_password; }; -void TestRsm::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 TestRsm::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 TestRsm::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 TestRsm::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); -} - void TestServer::testConnect() { const QString testDomain("localhost"); @@ -1747,7 +1622,7 @@ int main(int argc, char *argv[]) tst_QXmppRegisterIq testRegister; errors += QTest::qExec(&testRegister); - TestRsm testRsm; + tst_QXmppResultSet testRsm; errors += QTest::qExec(&testRsm); tst_QXmppRtpPacket testRtp; diff --git a/tests/tests.h b/tests/tests.h index b3db0cf7..1be52a2c 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -134,17 +134,6 @@ private slots: void testSubscriptions(); }; -class TestRsm : public QObject -{ - Q_OBJECT - -private slots: - void testQuery_data(); - void testQuery(); - void testReply_data(); - void testReply(); -}; - class TestServer : public QObject { Q_OBJECT diff --git a/tests/tests.pro b/tests/tests.pro index 47961519..6e34661c 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -8,11 +8,13 @@ RESOURCES += tests.qrc SOURCES += \ dataform.cpp \ register.cpp \ + rsm.cpp \ rtp.cpp \ tests.cpp HEADERS += \ dataform.h \ register.h \ + rsm.h \ rtp.h \ tests.h |
