From 57532909b5970645ca9fdd5f9a69bd3258d8a914 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Thu, 27 Sep 2012 15:12:16 +0200 Subject: split QXmppPresence tests out --- tests/all/all.pro | 2 - tests/all/presence.cpp | 223 --------------------------- tests/all/presence.h | 40 ----- tests/all/tests.cpp | 4 - tests/qxmpppresence/tst_qxmpppresence.cpp | 240 ++++++++++++++++++++++++++++++ 5 files changed, 240 insertions(+), 269 deletions(-) delete mode 100644 tests/all/presence.cpp delete mode 100644 tests/all/presence.h create mode 100644 tests/qxmpppresence/tst_qxmpppresence.cpp (limited to 'tests') diff --git a/tests/all/all.pro b/tests/all/all.pro index 32a8251a..9141de58 100644 --- a/tests/all/all.pro +++ b/tests/all/all.pro @@ -7,7 +7,6 @@ SOURCES += \ dataform.cpp \ jingle.cpp \ message.cpp \ - presence.cpp \ register.cpp \ roster.cpp \ rpc.cpp \ @@ -21,7 +20,6 @@ HEADERS += \ dataform.h \ jingle.h \ message.h \ - presence.h \ register.h \ roster.h \ rpc.h \ diff --git a/tests/all/presence.cpp b/tests/all/presence.cpp deleted file mode 100644 index c2762622..00000000 --- a/tests/all/presence.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * 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 "QXmppPresence.h" - -#include "presence.h" -#include "util.h" - -void tst_QXmppPresence::testPresence_data() -{ - QXmppPresence foo; - - QTest::addColumn("xml"); - QTest::addColumn("type"); - QTest::addColumn("priority"); - QTest::addColumn("statusType"); - QTest::addColumn("statusText"); - QTest::addColumn("vcardUpdate"); - QTest::addColumn("photoHash"); - - // presence type - QTest::newRow("available") << QByteArray("") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("unavailable") << QByteArray("") << int(QXmppPresence::Unavailable) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("error") << QByteArray("") << int(QXmppPresence::Error) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("subscribe") << QByteArray("") << int(QXmppPresence::Subscribe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("unsubscribe") << QByteArray("") << int(QXmppPresence::Unsubscribe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("subscribed") << QByteArray("") << int(QXmppPresence::Subscribed) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("unsubscribed") << QByteArray("") << int(QXmppPresence::Unsubscribed) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("probe") << QByteArray("") << int(QXmppPresence::Probe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - - // status text + priority - QTest::newRow("full") << QByteArray("awayIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Away) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - - // status type - QTest::newRow("away") << QByteArray("away") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Away) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("dnd") << QByteArray("dnd") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::DND) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("chat") << QByteArray("chat") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Chat) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("xa") << QByteArray("xa") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::XA) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - QTest::newRow("invisible") << QByteArray("invisible") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Invisible) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); - - // photo - QTest::newRow("vcard-photo") << QByteArray( - "" - "" - "73b908bc" - "" - "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateValidPhoto) << QByteArray::fromHex("73b908bc"); - - QTest::newRow("vard-not-ready") << QByteArray( - "" - "" - "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNotReady) << QByteArray(); -} - -void tst_QXmppPresence::testPresence() -{ - QFETCH(QByteArray, xml); - QFETCH(int, type); - QFETCH(int, priority); - QFETCH(int, statusType); - QFETCH(QString, statusText); - QFETCH(int, vcardUpdate); - QFETCH(QByteArray, photoHash); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(int(presence.type()), type); - QCOMPARE(presence.priority(), priority); - QCOMPARE(int(presence.availableStatusType()), statusType); - QCOMPARE(presence.statusText(), statusText); - QCOMPARE(int(presence.vCardUpdateType()), vcardUpdate); - QCOMPARE(presence.photoHash(), photoHash); - - // legacy - QCOMPARE(presence.status().priority(), priority); - QCOMPARE(int(presence.status().type()), statusType); - QCOMPARE(presence.status().statusText(), statusText); - - serializePacket(presence, xml); -} - -void tst_QXmppPresence::testPresenceWithCapability() -{ - const QByteArray xml( - "" - "away" - "In a meeting" - "5" - "" - "73b908bc" - "" - "" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); - QCOMPARE(presence.availableStatusType(), QXmppPresence::Away); - QCOMPARE(presence.statusText(), QString("In a meeting")); - QCOMPARE(presence.priority(), 5); - QCOMPARE(presence.photoHash(), QByteArray::fromHex("73b908bc")); - QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateValidPhoto); - QCOMPARE(presence.capabilityHash(), QString("sha-1")); - QCOMPARE(presence.capabilityNode(), QString("http://code.google.com/p/qxmpp")); - QCOMPARE(presence.capabilityVer(), QByteArray::fromBase64("QgayPKawpkPSDYmwT/WM94uAlu0=")); - - serializePacket(presence, xml); -} - -void tst_QXmppPresence::testPresenceWithExtendedAddresses() -{ - const QByteArray xml( - "" - "" - "
" - "
" - "" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.extendedAddresses().size(), 2); - QCOMPARE(presence.extendedAddresses()[0].description(), QString()); - QCOMPARE(presence.extendedAddresses()[0].jid(), QLatin1String("temas@jabber.org")); - QCOMPARE(presence.extendedAddresses()[0].type(), QLatin1String("bcc")); - QCOMPARE(presence.extendedAddresses()[1].description(), QString()); - QCOMPARE(presence.extendedAddresses()[1].jid(), QLatin1String("jer@jabber.org")); - QCOMPARE(presence.extendedAddresses()[1].type(), QLatin1String("bcc")); - serializePacket(presence, xml); -} - -void tst_QXmppPresence::testPresenceWithMucItem() -{ - const QByteArray xml( - "" - "" - "" - "" - "Avaunt, you cullion!" - "" - "" - "" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QLatin1String("pistol@shakespeare.lit/harfleur")); - QCOMPARE(presence.from(), QLatin1String("harfleur@henryv.shakespeare.lit/pistol")); - QCOMPARE(presence.type(), QXmppPresence::Unavailable); - QCOMPARE(presence.mucItem().actor(), QLatin1String("fluellen@shakespeare.lit")); - QCOMPARE(presence.mucItem().affiliation(), QXmppMucItem::NoAffiliation); - QCOMPARE(presence.mucItem().jid(), QString()); - QCOMPARE(presence.mucItem().reason(), QLatin1String("Avaunt, you cullion!")); - QCOMPARE(presence.mucItem().role(), QXmppMucItem::NoRole); - QCOMPARE(presence.mucStatusCodes(), QList() << 307); - serializePacket(presence, xml); -} - -void tst_QXmppPresence::testPresenceWithMucPassword() -{ - const QByteArray xml( - "" - "" - "pass" - "" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QLatin1String("coven@chat.shakespeare.lit/thirdwitch")); - QCOMPARE(presence.from(), QLatin1String("hag66@shakespeare.lit/pda")); - QCOMPARE(presence.type(), QXmppPresence::Available); - QCOMPARE(presence.isMucSupported(), true); - QCOMPARE(presence.mucPassword(), QLatin1String("pass")); - serializePacket(presence, xml); -} - -void tst_QXmppPresence::testPresenceWithMucSupport() -{ - const QByteArray xml( - "" - "" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QLatin1String("coven@chat.shakespeare.lit/thirdwitch")); - QCOMPARE(presence.from(), QLatin1String("hag66@shakespeare.lit/pda")); - QCOMPARE(presence.type(), QXmppPresence::Available); - QCOMPARE(presence.isMucSupported(), true); - QVERIFY(presence.mucPassword().isEmpty()); - serializePacket(presence, xml); -} - diff --git a/tests/all/presence.h b/tests/all/presence.h deleted file mode 100644 index 74bd7ee8..00000000 --- a/tests/all/presence.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - -class tst_QXmppPresence : public QObject -{ - Q_OBJECT - -private slots: - void testPresence(); - void testPresence_data(); - void testPresenceWithCapability(); - void testPresenceWithExtendedAddresses(); - void testPresenceWithMucItem(); - void testPresenceWithMucPassword(); - void testPresenceWithMucSupport(); -}; - diff --git a/tests/all/tests.cpp b/tests/all/tests.cpp index 0741c84e..82f007f5 100644 --- a/tests/all/tests.cpp +++ b/tests/all/tests.cpp @@ -48,7 +48,6 @@ #include "dataform.h" #include "jingle.h" #include "message.h" -#include "presence.h" #include "register.h" #include "roster.h" #include "rpc.h" @@ -904,9 +903,6 @@ int main(int argc, char *argv[]) tst_QXmppMessage testMessage; errors += QTest::qExec(&testMessage); - tst_QXmppPresence testPresence; - errors += QTest::qExec(&testPresence); - TestPubSub testPubSub; errors += QTest::qExec(&testPubSub); diff --git a/tests/qxmpppresence/tst_qxmpppresence.cpp b/tests/qxmpppresence/tst_qxmpppresence.cpp new file mode 100644 index 00000000..4cbe8caa --- /dev/null +++ b/tests/qxmpppresence/tst_qxmpppresence.cpp @@ -0,0 +1,240 @@ +/* + * 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 + +#include "QXmppPresence.h" + +#include "util.h" + +class tst_QXmppPresence : public QObject +{ + Q_OBJECT + +private slots: + void testPresence(); + void testPresence_data(); + void testPresenceWithCapability(); + void testPresenceWithExtendedAddresses(); + void testPresenceWithMucItem(); + void testPresenceWithMucPassword(); + void testPresenceWithMucSupport(); +}; + +void tst_QXmppPresence::testPresence_data() +{ + QXmppPresence foo; + + QTest::addColumn("xml"); + QTest::addColumn("type"); + QTest::addColumn("priority"); + QTest::addColumn("statusType"); + QTest::addColumn("statusText"); + QTest::addColumn("vcardUpdate"); + QTest::addColumn("photoHash"); + + // presence type + QTest::newRow("available") << QByteArray("") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unavailable") << QByteArray("") << int(QXmppPresence::Unavailable) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("error") << QByteArray("") << int(QXmppPresence::Error) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("subscribe") << QByteArray("") << int(QXmppPresence::Subscribe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unsubscribe") << QByteArray("") << int(QXmppPresence::Unsubscribe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("subscribed") << QByteArray("") << int(QXmppPresence::Subscribed) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unsubscribed") << QByteArray("") << int(QXmppPresence::Unsubscribed) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("probe") << QByteArray("") << int(QXmppPresence::Probe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + // status text + priority + QTest::newRow("full") << QByteArray("awayIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Away) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + // status type + QTest::newRow("away") << QByteArray("away") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Away) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("dnd") << QByteArray("dnd") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::DND) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("chat") << QByteArray("chat") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Chat) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("xa") << QByteArray("xa") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::XA) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("invisible") << QByteArray("invisible") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Invisible) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + // photo + QTest::newRow("vcard-photo") << QByteArray( + "" + "" + "73b908bc" + "" + "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateValidPhoto) << QByteArray::fromHex("73b908bc"); + + QTest::newRow("vard-not-ready") << QByteArray( + "" + "" + "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNotReady) << QByteArray(); +} + +void tst_QXmppPresence::testPresence() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + QFETCH(int, priority); + QFETCH(int, statusType); + QFETCH(QString, statusText); + QFETCH(int, vcardUpdate); + QFETCH(QByteArray, photoHash); + + QXmppPresence presence; + parsePacket(presence, xml); + QCOMPARE(int(presence.type()), type); + QCOMPARE(presence.priority(), priority); + QCOMPARE(int(presence.availableStatusType()), statusType); + QCOMPARE(presence.statusText(), statusText); + QCOMPARE(int(presence.vCardUpdateType()), vcardUpdate); + QCOMPARE(presence.photoHash(), photoHash); + + // legacy + QCOMPARE(presence.status().priority(), priority); + QCOMPARE(int(presence.status().type()), statusType); + QCOMPARE(presence.status().statusText(), statusText); + + serializePacket(presence, xml); +} + +void tst_QXmppPresence::testPresenceWithCapability() +{ + const QByteArray xml( + "" + "away" + "In a meeting" + "5" + "" + "73b908bc" + "" + "" + ""); + + QXmppPresence presence; + parsePacket(presence, xml); + QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); + QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); + QCOMPARE(presence.availableStatusType(), QXmppPresence::Away); + QCOMPARE(presence.statusText(), QString("In a meeting")); + QCOMPARE(presence.priority(), 5); + QCOMPARE(presence.photoHash(), QByteArray::fromHex("73b908bc")); + QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateValidPhoto); + QCOMPARE(presence.capabilityHash(), QString("sha-1")); + QCOMPARE(presence.capabilityNode(), QString("http://code.google.com/p/qxmpp")); + QCOMPARE(presence.capabilityVer(), QByteArray::fromBase64("QgayPKawpkPSDYmwT/WM94uAlu0=")); + + serializePacket(presence, xml); +} + +void tst_QXmppPresence::testPresenceWithExtendedAddresses() +{ + const QByteArray xml( + "" + "" + "
" + "
" + "" + ""); + + QXmppPresence presence; + parsePacket(presence, xml); + QCOMPARE(presence.extendedAddresses().size(), 2); + QCOMPARE(presence.extendedAddresses()[0].description(), QString()); + QCOMPARE(presence.extendedAddresses()[0].jid(), QLatin1String("temas@jabber.org")); + QCOMPARE(presence.extendedAddresses()[0].type(), QLatin1String("bcc")); + QCOMPARE(presence.extendedAddresses()[1].description(), QString()); + QCOMPARE(presence.extendedAddresses()[1].jid(), QLatin1String("jer@jabber.org")); + QCOMPARE(presence.extendedAddresses()[1].type(), QLatin1String("bcc")); + serializePacket(presence, xml); +} + +void tst_QXmppPresence::testPresenceWithMucItem() +{ + const QByteArray xml( + "" + "" + "" + "" + "Avaunt, you cullion!" + "" + "" + "" + ""); + + QXmppPresence presence; + parsePacket(presence, xml); + QCOMPARE(presence.to(), QLatin1String("pistol@shakespeare.lit/harfleur")); + QCOMPARE(presence.from(), QLatin1String("harfleur@henryv.shakespeare.lit/pistol")); + QCOMPARE(presence.type(), QXmppPresence::Unavailable); + QCOMPARE(presence.mucItem().actor(), QLatin1String("fluellen@shakespeare.lit")); + QCOMPARE(presence.mucItem().affiliation(), QXmppMucItem::NoAffiliation); + QCOMPARE(presence.mucItem().jid(), QString()); + QCOMPARE(presence.mucItem().reason(), QLatin1String("Avaunt, you cullion!")); + QCOMPARE(presence.mucItem().role(), QXmppMucItem::NoRole); + QCOMPARE(presence.mucStatusCodes(), QList() << 307); + serializePacket(presence, xml); +} + +void tst_QXmppPresence::testPresenceWithMucPassword() +{ + const QByteArray xml( + "" + "" + "pass" + "" + ""); + + QXmppPresence presence; + parsePacket(presence, xml); + QCOMPARE(presence.to(), QLatin1String("coven@chat.shakespeare.lit/thirdwitch")); + QCOMPARE(presence.from(), QLatin1String("hag66@shakespeare.lit/pda")); + QCOMPARE(presence.type(), QXmppPresence::Available); + QCOMPARE(presence.isMucSupported(), true); + QCOMPARE(presence.mucPassword(), QLatin1String("pass")); + serializePacket(presence, xml); +} + +void tst_QXmppPresence::testPresenceWithMucSupport() +{ + const QByteArray xml( + "" + "" + ""); + + QXmppPresence presence; + parsePacket(presence, xml); + QCOMPARE(presence.to(), QLatin1String("coven@chat.shakespeare.lit/thirdwitch")); + QCOMPARE(presence.from(), QLatin1String("hag66@shakespeare.lit/pda")); + QCOMPARE(presence.type(), QXmppPresence::Available); + QCOMPARE(presence.isMucSupported(), true); + QVERIFY(presence.mucPassword().isEmpty()); + serializePacket(presence, xml); +} + +QTEST_MAIN(tst_QXmppPresence) +#include "tst_qxmpppresence.moc" -- cgit v1.2.3