diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-06-29 13:39:11 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-06-29 13:39:11 +0000 |
| commit | 782b7f3e1199d867d7262ae3e6cf08aea9ad0624 (patch) | |
| tree | bc17d571e833d752577d1e835d87224756d817e5 /source/tests.cpp | |
| parent | 7bc846598f17eea663b265e682a016acdac6beca (diff) | |
| download | qxmpp-782b7f3e1199d867d7262ae3e6cf08aea9ad0624.tar.gz | |
cleanup & test more IQ handling
Diffstat (limited to 'source/tests.cpp')
| -rw-r--r-- | source/tests.cpp | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/source/tests.cpp b/source/tests.cpp index 4a54a691..3d99bf99 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -28,8 +28,10 @@ #include <QVariant> #include <QtTest/QtTest> +#include "QXmppBind.h" #include "QXmppMessage.h" #include "QXmppPresence.h" +#include "QXmppSession.h" #include "tests.h" static void parsePacket(QXmppPacket &packet, const QByteArray &xml) @@ -51,6 +53,58 @@ static void serializePacket(QXmppPacket &packet, const QByteArray &xml) QCOMPARE(buffer.data(), xml); } +void TestPackets::testBindNoResource() +{ + const QByteArray xml( + "<iq id=\"bind_1\" type=\"set\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" + "</iq>"); + + QXmppBind bind; + parsePacket(bind, xml); + QCOMPARE(bind.type(), QXmppIq::Set); + QCOMPARE(bind.id(), QString("bind_1")); + QCOMPARE(bind.jid(), QString()); + QCOMPARE(bind.resource(), QString()); + serializePacket(bind, xml); +} + +void TestPackets::testBindResource() +{ + const QByteArray xml( + "<iq id=\"bind_2\" type=\"set\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<resource>someresource</resource>" + "</bind>" + "</iq>"); + + QXmppBind bind; + parsePacket(bind, xml); + QCOMPARE(bind.type(), QXmppIq::Set); + QCOMPARE(bind.id(), QString("bind_2")); + QCOMPARE(bind.jid(), QString()); + QCOMPARE(bind.resource(), QString("someresource")); + serializePacket(bind, xml); +} + +void TestPackets::testBindResult() +{ + const QByteArray xml( + "<iq id=\"bind_2\" type=\"result\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<jid>somenode@example.com/someresource</jid>" + "</bind>" + "</iq>"); + + QXmppBind bind; + parsePacket(bind, xml); + QCOMPARE(bind.type(), QXmppIq::Result); + QCOMPARE(bind.id(), QString("bind_2")); + QCOMPARE(bind.jid(), QString("somenode@example.com/someresource")); + QCOMPARE(bind.resource(), QString()); + serializePacket(bind, xml); +} + void TestPackets::testMessage() { const QByteArray xml( @@ -130,8 +184,7 @@ void TestPackets::testPresenceFull() "<show>away</show>" "<status>In a meeting</status>" "<priority>5</priority>" - "</presence>" - ); + "</presence>"); QXmppPresence presence; parsePacket(presence, xml); @@ -143,6 +196,21 @@ void TestPackets::testPresenceFull() serializePacket(presence, xml); } +void TestPackets::testSession() +{ + const QByteArray xml( + "<iq id=\"session_1\" to=\"example.com\" type=\"set\">" + "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" + "</iq>"); + + QXmppSession session; + parsePacket(session, xml); + QCOMPARE(session.id(), QString("session_1")); + QCOMPARE(session.to(), QString("example.com")); + QCOMPARE(session.type(), QXmppIq::Set); + serializePacket(session, xml); +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); |
