From cc1f3ccc6d8e60ce57f7bcb1340563d63f2f06a0 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Thu, 27 Sep 2012 21:12:51 +0200 Subject: split pubsub tests --- tests/all/all.pro | 3 - tests/all/tests.cpp | 232 ++++-------------------------- tests/all/tests.h | 65 --------- tests/qxmpppubsubiq/qxmpppubsubiq.pro | 3 + tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp | 218 ++++++++++++++++++++++++++++ tests/tests.pro | 1 + 6 files changed, 250 insertions(+), 272 deletions(-) delete mode 100644 tests/all/tests.h create mode 100644 tests/qxmpppubsubiq/qxmpppubsubiq.pro create mode 100644 tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp (limited to 'tests') diff --git a/tests/all/all.pro b/tests/all/all.pro index 13afe30f..ba6fd763 100644 --- a/tests/all/all.pro +++ b/tests/all/all.pro @@ -1,6 +1,3 @@ include(../tests.pri) - TARGET = tst_all - SOURCES += tests.cpp -HEADERS += tests.h diff --git a/tests/all/tests.cpp b/tests/all/tests.cpp index 322085e5..230fbf6f 100644 --- a/tests/all/tests.cpp +++ b/tests/all/tests.cpp @@ -22,11 +22,6 @@ * */ -#include - -#include -#include - #include "QXmppArchiveIq.h" #include "QXmppBindIq.h" #include "QXmppDiscoveryIq.h" @@ -37,10 +32,34 @@ #include "QXmppUtils.h" #include "QXmppVersionIq.h" #include "QXmppEntityTimeIq.h" - -#include "tests.h" #include "util.h" +class TestPackets : public QObject +{ + Q_OBJECT + +private slots: + void testArchiveList_data(); + void testArchiveList(); + void testArchiveChat_data(); + void testArchiveChat(); + void testArchiveRemove(); + void testArchiveRetrieve_data(); + void testArchiveRetrieve(); + void testBindNoResource(); + void testBindResource(); + void testBindResult(); + void testDiscovery(); + void testDiscoveryWithForm(); + void testNonSaslAuth(); + void testSession(); + void testStreamFeatures(); + void testVersionGet(); + void testVersionResult(); + void testEntityTimeGet(); + void testEntityTimeResult(); +}; + void TestPackets::testArchiveList_data() { QTest::addColumn("xml"); @@ -485,200 +504,5 @@ void TestPackets::testEntityTimeResult() serializePacket(entityTime, xml); } -void TestPubSub::testItems() -{ - const QByteArray xml( - "" - "" - "" - "" - ""); - - QXmppPubSubIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.id(), QLatin1String("items1")); - QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); - QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); - QCOMPARE(iq.type(), QXmppIq::Get); - QCOMPARE(iq.queryType(), QXmppPubSubIq::ItemsQuery); - QCOMPARE(iq.queryJid(), QString()); - QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); - serializePacket(iq, xml); -} - -void TestPubSub::testItemsResponse() -{ - const QByteArray xml( - "" - "" - "" - "" - "" - "" - "JC" - "" - "" - "" - "" - "" - ""); - - QXmppPubSubIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.id(), QLatin1String("items1")); - QCOMPARE(iq.to(), QLatin1String("francisco@denmark.lit/barracks")); - QCOMPARE(iq.from(), QLatin1String("pubsub.shakespeare.lit")); - QCOMPARE(iq.type(), QXmppIq::Result); - QCOMPARE(iq.queryType(), QXmppPubSubIq::ItemsQuery); - QCOMPARE(iq.queryJid(), QString()); - QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); - serializePacket(iq, xml); -} - -void TestPubSub::testPublish() -{ - const QByteArray xml( - "" - "" - "" - "" - "" - "" - "JC" - "" - "" - "" - "" - "" - ""); - - QXmppPubSubIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.id(), QLatin1String("items1")); - QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); - QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); - QCOMPARE(iq.type(), QXmppIq::Result); - QCOMPARE(iq.queryType(), QXmppPubSubIq::PublishQuery); - QCOMPARE(iq.queryJid(), QString()); - QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); - serializePacket(iq, xml); -} - -void TestPubSub::testSubscribe() -{ - const QByteArray xml( - "" - "" - "" - "" - ""); - - QXmppPubSubIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.id(), QLatin1String("sub1")); - QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); - QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); - QCOMPARE(iq.type(), QXmppIq::Set); - QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscribeQuery); - QCOMPARE(iq.queryJid(), QLatin1String("francisco@denmark.lit")); - QCOMPARE(iq.queryNode(), QLatin1String("princely_musings")); - serializePacket(iq, xml); -} - -void TestPubSub::testSubscription() -{ - const QByteArray xml( - "" - "" - "" - "" - ""); - - QXmppPubSubIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.id(), QLatin1String("sub1")); - QCOMPARE(iq.to(), QLatin1String("francisco@denmark.lit/barracks")); - QCOMPARE(iq.from(), QLatin1String("pubsub.shakespeare.lit")); - QCOMPARE(iq.type(), QXmppIq::Result); - QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscriptionQuery); - QCOMPARE(iq.queryJid(), QLatin1String("francisco@denmark.lit")); - QCOMPARE(iq.queryNode(), QLatin1String("princely_musings")); - QCOMPARE(iq.subscriptionId(), QLatin1String("ba49252aaa4f5d320c24d3766f0bdcade78c78d3")); - serializePacket(iq, xml); -} - -void TestPubSub::testSubscriptions() -{ - const QByteArray xml( - "" - "" - "" - "" - ""); - - QXmppPubSubIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.id(), QLatin1String("subscriptions1")); - QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); - QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); - QCOMPARE(iq.type(), QXmppIq::Get); - QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscriptionsQuery); - QCOMPARE(iq.queryJid(), QString()); - QCOMPARE(iq.queryNode(), QString()); - serializePacket(iq, xml); -} - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - // run tests - int errors = 0; - - TestPackets testPackets; - errors += QTest::qExec(&testPackets); - - TestPubSub testPubSub; - errors += QTest::qExec(&testPubSub); - - if (errors) - { - qWarning() << "Total failed tests:" << errors; - return EXIT_FAILURE; - } - return EXIT_SUCCESS; -}; - +QTEST_MAIN(TestPackets) +#include "tests.moc" diff --git a/tests/all/tests.h b/tests/all/tests.h deleted file mode 100644 index 3bc8ad1e..00000000 --- a/tests/all/tests.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2008-2012 The QXmpp developers - * - * Authors: - * Jeremy Lainé - * Manjeet Dahiya - * - * 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 - -class TestPackets : public QObject -{ - Q_OBJECT - -private slots: - void testArchiveList_data(); - void testArchiveList(); - void testArchiveChat_data(); - void testArchiveChat(); - void testArchiveRemove(); - void testArchiveRetrieve_data(); - void testArchiveRetrieve(); - void testBindNoResource(); - void testBindResource(); - void testBindResult(); - void testDiscovery(); - void testDiscoveryWithForm(); - void testNonSaslAuth(); - void testSession(); - void testStreamFeatures(); - void testVersionGet(); - void testVersionResult(); - void testEntityTimeGet(); - void testEntityTimeResult(); -}; - -class TestPubSub : public QObject -{ - Q_OBJECT - -private slots: - void testItems(); - void testItemsResponse(); - void testPublish(); - void testSubscribe(); - void testSubscription(); - void testSubscriptions(); -}; - diff --git a/tests/qxmpppubsubiq/qxmpppubsubiq.pro b/tests/qxmpppubsubiq/qxmpppubsubiq.pro new file mode 100644 index 00000000..0847c919 --- /dev/null +++ b/tests/qxmpppubsubiq/qxmpppubsubiq.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +TARGET = tst_qxmpppubsubiq +SOURCES += tst_qxmpppubsubiq.cpp diff --git a/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp b/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp new file mode 100644 index 00000000..e3ae8541 --- /dev/null +++ b/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Author: + * 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 +#include "QXmppPubSubIq.h" +#include "util.h" + +class tst_QXmppPubSubIq : public QObject +{ + Q_OBJECT + +private slots: + void testItems(); + void testItemsResponse(); + void testPublish(); + void testSubscribe(); + void testSubscription(); + void testSubscriptions(); +}; + +void tst_QXmppPubSubIq::testItems() +{ + const QByteArray xml( + "" + "" + "" + "" + ""); + + QXmppPubSubIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("items1")); + QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); + QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); + QCOMPARE(iq.type(), QXmppIq::Get); + QCOMPARE(iq.queryType(), QXmppPubSubIq::ItemsQuery); + QCOMPARE(iq.queryJid(), QString()); + QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); + serializePacket(iq, xml); +} + +void tst_QXmppPubSubIq::testItemsResponse() +{ + const QByteArray xml( + "" + "" + "" + "" + "" + "" + "JC" + "" + "" + "" + "" + "" + ""); + + QXmppPubSubIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("items1")); + QCOMPARE(iq.to(), QLatin1String("francisco@denmark.lit/barracks")); + QCOMPARE(iq.from(), QLatin1String("pubsub.shakespeare.lit")); + QCOMPARE(iq.type(), QXmppIq::Result); + QCOMPARE(iq.queryType(), QXmppPubSubIq::ItemsQuery); + QCOMPARE(iq.queryJid(), QString()); + QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); + serializePacket(iq, xml); +} + +void tst_QXmppPubSubIq::testPublish() +{ + const QByteArray xml( + "" + "" + "" + "" + "" + "" + "JC" + "" + "" + "" + "" + "" + ""); + + QXmppPubSubIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("items1")); + QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); + QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); + QCOMPARE(iq.type(), QXmppIq::Result); + QCOMPARE(iq.queryType(), QXmppPubSubIq::PublishQuery); + QCOMPARE(iq.queryJid(), QString()); + QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); + serializePacket(iq, xml); +} + +void tst_QXmppPubSubIq::testSubscribe() +{ + const QByteArray xml( + "" + "" + "" + "" + ""); + + QXmppPubSubIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("sub1")); + QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); + QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); + QCOMPARE(iq.type(), QXmppIq::Set); + QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscribeQuery); + QCOMPARE(iq.queryJid(), QLatin1String("francisco@denmark.lit")); + QCOMPARE(iq.queryNode(), QLatin1String("princely_musings")); + serializePacket(iq, xml); +} + +void tst_QXmppPubSubIq::testSubscription() +{ + const QByteArray xml( + "" + "" + "" + "" + ""); + + QXmppPubSubIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("sub1")); + QCOMPARE(iq.to(), QLatin1String("francisco@denmark.lit/barracks")); + QCOMPARE(iq.from(), QLatin1String("pubsub.shakespeare.lit")); + QCOMPARE(iq.type(), QXmppIq::Result); + QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscriptionQuery); + QCOMPARE(iq.queryJid(), QLatin1String("francisco@denmark.lit")); + QCOMPARE(iq.queryNode(), QLatin1String("princely_musings")); + QCOMPARE(iq.subscriptionId(), QLatin1String("ba49252aaa4f5d320c24d3766f0bdcade78c78d3")); + serializePacket(iq, xml); +} + +void tst_QXmppPubSubIq::testSubscriptions() +{ + const QByteArray xml( + "" + "" + "" + "" + ""); + + QXmppPubSubIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("subscriptions1")); + QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); + QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); + QCOMPARE(iq.type(), QXmppIq::Get); + QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscriptionsQuery); + QCOMPARE(iq.queryJid(), QString()); + QCOMPARE(iq.queryNode(), QString()); + serializePacket(iq, xml); +} + +QTEST_MAIN(tst_QXmppPubSubIq) +#include "tst_qxmpppubsubiq.moc" diff --git a/tests/tests.pro b/tests/tests.pro index d356fbcf..56276fc5 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -6,6 +6,7 @@ SUBDIRS = \ qxmppjingleiq \ qxmppmessage \ qxmpppresence \ + qxmpppubsubiq \ qxmppregisteriq \ qxmppresultset \ qxmpprosteriq \ -- cgit v1.2.3