From c0ddf372e5ccfdda3265bdf33bfc1276d9af6885 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Wed, 18 Jul 2012 16:22:28 +0200 Subject: improve QXmppPresence coverage --- tests/presence.cpp | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/presence.h | 37 ++++++++++++++ tests/tests.cpp | 122 ++------------------------------------------- tests/tests.h | 5 -- tests/tests.pro | 2 + 5 files changed, 184 insertions(+), 123 deletions(-) create mode 100644 tests/presence.cpp create mode 100644 tests/presence.h (limited to 'tests') diff --git a/tests/presence.cpp b/tests/presence.cpp new file mode 100644 index 00000000..9c65566b --- /dev/null +++ b/tests/presence.cpp @@ -0,0 +1,141 @@ +/* + * 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 "tests.h" + +void tst_QXmppPresence::testPresence_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("type"); + QTest::addColumn("priority"); + QTest::addColumn("statusType"); + QTest::addColumn("statusText"); + QTest::addColumn("vcardUpdate"); + QTest::addColumn("photoHash"); + + QTest::newRow("empty") << QByteArray("") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unavailable") << QByteArray("") << int(QXmppPresence::Unavailable) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("error") << QByteArray("") << int(QXmppPresence::Error) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + QTest::newRow("away") << QByteArray("awayIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::Away) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("dnd") << QByteArray("dndIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::DND) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("chat") << QByteArray("chatIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::Chat) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("xa") << QByteArray("xaIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::XA) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + QTest::newRow("vcard-photo") << QByteArray( + "" + "" + "73b908bc" + "" + "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateValidPhoto) << QByteArray::fromHex("73b908bc"); + + QTest::newRow("vard-not-ready") << QByteArray( + "" + "" + "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::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.status().priority(), priority); + QCOMPARE(int(presence.status().type()), statusType); + QCOMPARE(presence.status().statusText(), statusText); + QCOMPARE(int(presence.vCardUpdateType()), vcardUpdate); + QCOMPARE(presence.photoHash(), photoHash); + 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.status().type(), QXmppPresence::Status::Away); + QCOMPARE(presence.status().statusText(), QString("In a meeting")); + QCOMPARE(presence.status().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::testPresenceWithMuc() +{ + 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); +} + diff --git a/tests/presence.h b/tests/presence.h new file mode 100644 index 00000000..1b6b1e50 --- /dev/null +++ b/tests/presence.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 + +class tst_QXmppPresence : public QObject +{ + Q_OBJECT + +private slots: + void testPresence(); + void testPresence_data(); + void testPresenceWithCapability(); + void testPresenceWithMuc(); +}; + diff --git a/tests/tests.cpp b/tests/tests.cpp index 0c0c31d1..c4178e94 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -54,6 +54,7 @@ #include "QXmppEntityTimeIq.h" #include "dataform.h" +#include "presence.h" #include "register.h" #include "rsm.h" #include "rtp.h" @@ -631,124 +632,6 @@ void TestPackets::testNonSaslAuth() serializePacket(iq4, xml4); } -void TestPackets::testPresence() -{ - const QByteArray xml( - "" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); - QCOMPARE(presence.photoHash(), QByteArray("")); - QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateNotReady); - serializePacket(presence, xml); -} - -void TestPackets::testPresenceFull() -{ - const QByteArray xml( - "" - "away" - "In a meeting" - "5" - ""); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); - QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); - QCOMPARE(presence.status().statusText(), QString("In a meeting")); - QCOMPARE(presence.status().priority(), 5); - QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateNone); - serializePacket(presence, xml); -} - -void TestPackets::testPresenceWithVCardUpdate() -{ - 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.status().type(), QXmppPresence::Status::Away); - QCOMPARE(presence.status().statusText(), QString("In a meeting")); - QCOMPARE(presence.status().priority(), 5); - QCOMPARE(presence.photoHash(), QByteArray::fromHex("73b908bc")); - QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateValidPhoto); - serializePacket(presence, xml); -} - -void TestPackets::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.status().type(), QXmppPresence::Status::Away); - QCOMPARE(presence.status().statusText(), QString("In a meeting")); - QCOMPARE(presence.status().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 TestPackets::testPresenceWithMuc() -{ - 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 TestPackets::testSession() { const QByteArray xml( @@ -1616,6 +1499,9 @@ int main(int argc, char *argv[]) TestJingle testJingle; errors += QTest::qExec(&testJingle); + tst_QXmppPresence testPresence; + errors += QTest::qExec(&testPresence); + TestPubSub testPubSub; errors += QTest::qExec(&testPubSub); diff --git a/tests/tests.h b/tests/tests.h index 1be52a2c..4ee5671c 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -86,11 +86,6 @@ private slots: void testMessageDelay(); void testMessageLegacyDelay(); void testNonSaslAuth(); - void testPresence(); - void testPresenceFull(); - void testPresenceWithVCardUpdate(); - void testPresenceWithCapability(); - void testPresenceWithMuc(); void testSession(); void testStreamFeatures(); void testVCard(); diff --git a/tests/tests.pro b/tests/tests.pro index 6e34661c..e68b81d6 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -7,12 +7,14 @@ TARGET = qxmpp-tests RESOURCES += tests.qrc SOURCES += \ dataform.cpp \ + presence.cpp \ register.cpp \ rsm.cpp \ rtp.cpp \ tests.cpp HEADERS += \ dataform.h \ + presence.h \ register.h \ rsm.h \ rtp.h \ -- cgit v1.2.3