aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-07-18 16:22:28 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-07-18 16:22:28 +0200
commitc0ddf372e5ccfdda3265bdf33bfc1276d9af6885 (patch)
tree39b9f55e97d5b0d2e5b21737d5a0e3dae6e9c527
parentef9f9a57f1dd2e70d29afa26fa0d1ab38a5e3aca (diff)
downloadqxmpp-c0ddf372e5ccfdda3265bdf33bfc1276d9af6885.tar.gz
improve QXmppPresence coverage
-rw-r--r--tests/presence.cpp141
-rw-r--r--tests/presence.h37
-rw-r--r--tests/tests.cpp122
-rw-r--r--tests/tests.h5
-rw-r--r--tests/tests.pro2
5 files changed, 184 insertions, 123 deletions
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<QByteArray>("xml");
+ QTest::addColumn<int>("type");
+ QTest::addColumn<int>("priority");
+ QTest::addColumn<int>("statusType");
+ QTest::addColumn<QString>("statusText");
+ QTest::addColumn<int>("vcardUpdate");
+ QTest::addColumn<QByteArray>("photoHash");
+
+ QTest::newRow("empty") << QByteArray("<presence/>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+ QTest::newRow("unavailable") << QByteArray("<presence type=\"unavailable\"/>") << int(QXmppPresence::Unavailable) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+ QTest::newRow("error") << QByteArray("<presence type=\"error\"/>") << int(QXmppPresence::Error) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+
+ QTest::newRow("away") << QByteArray("<presence><show>away</show><status>In a meeting</status><priority>5</priority></presence>") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::Away) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+ QTest::newRow("dnd") << QByteArray("<presence><show>dnd</show><status>In a meeting</status><priority>5</priority></presence>") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::DND) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+ QTest::newRow("chat") << QByteArray("<presence><show>chat</show><status>In a meeting</status><priority>5</priority></presence>") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::Chat) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+ QTest::newRow("xa") << QByteArray("<presence><show>xa</show><status>In a meeting</status><priority>5</priority></presence>") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::XA) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray();
+
+ QTest::newRow("vcard-photo") << QByteArray(
+ "<presence>"
+ "<x xmlns=\"vcard-temp:x:update\">"
+ "<photo>73b908bc</photo>"
+ "</x>"
+ "</presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateValidPhoto) << QByteArray::fromHex("73b908bc");
+
+ QTest::newRow("vard-not-ready") << QByteArray(
+ "<presence>"
+ "<x xmlns=\"vcard-temp:x:update\"/>"
+ "</presence>") << 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(
+ "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\">"
+ "<show>away</show>"
+ "<status>In a meeting</status>"
+ "<priority>5</priority>"
+ "<x xmlns=\"vcard-temp:x:update\">"
+ "<photo>73b908bc</photo>"
+ "</x>"
+ "<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://code.google.com/p/qxmpp\" ver=\"QgayPKawpkPSDYmwT/WM94uAlu0=\"/>"
+ "</presence>");
+
+ 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(
+ "<presence "
+ "to=\"pistol@shakespeare.lit/harfleur\" "
+ "from=\"harfleur@henryv.shakespeare.lit/pistol\" "
+ "type=\"unavailable\">"
+ "<x xmlns=\"http://jabber.org/protocol/muc#user\">"
+ "<item affiliation=\"none\" role=\"none\">"
+ "<actor jid=\"fluellen@shakespeare.lit\"/>"
+ "<reason>Avaunt, you cullion!</reason>"
+ "</item>"
+ "<status code=\"307\"/>"
+ "</x>"
+ "</presence>");
+
+ 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<int>() << 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 <QObject>
+
+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(
- "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\">"
- "<x xmlns=\"vcard-temp:x:update\"/></presence>");
-
- 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(
- "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\">"
- "<show>away</show>"
- "<status>In a meeting</status>"
- "<priority>5</priority>"
- "</presence>");
-
- 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(
- "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\">"
- "<show>away</show>"
- "<status>In a meeting</status>"
- "<priority>5</priority>"
- "<x xmlns=\"vcard-temp:x:update\">"
- "<photo>73b908bc</photo>"
- "</x>"
- "</presence>");
-
- 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(
- "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\">"
- "<show>away</show>"
- "<status>In a meeting</status>"
- "<priority>5</priority>"
- "<x xmlns=\"vcard-temp:x:update\">"
- "<photo>73b908bc</photo>"
- "</x>"
- "<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://code.google.com/p/qxmpp\" ver=\"QgayPKawpkPSDYmwT/WM94uAlu0=\"/>"
- "</presence>");
-
- 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(
- "<presence "
- "to=\"pistol@shakespeare.lit/harfleur\" "
- "from=\"harfleur@henryv.shakespeare.lit/pistol\" "
- "type=\"unavailable\">"
- "<x xmlns=\"http://jabber.org/protocol/muc#user\">"
- "<item affiliation=\"none\" role=\"none\">"
- "<actor jid=\"fluellen@shakespeare.lit\"/>"
- "<reason>Avaunt, you cullion!</reason>"
- "</item>"
- "<status code=\"307\"/>"
- "</x>"
- "</presence>");
-
- 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<int>() << 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 \