diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-27 15:06:55 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-27 15:06:55 +0200 |
| commit | db2f84e966682c1072cd579baa9511906a276ab0 (patch) | |
| tree | 6554c194b2cf52e19e7940ed31f9c64c9d540569 /tests/all | |
| parent | 40c1ce264991447522e8296ad86a55ca5c3b81d1 (diff) | |
| download | qxmpp-db2f84e966682c1072cd579baa9511906a276ab0.tar.gz | |
start splitting tests
Diffstat (limited to 'tests/all')
43 files changed, 4317 insertions, 0 deletions
diff --git a/tests/all/all.pro b/tests/all/all.pro new file mode 100644 index 00000000..1e821b03 --- /dev/null +++ b/tests/all/all.pro @@ -0,0 +1,40 @@ +include(../tests.pri) + +TARGET = tst_all + +RESOURCES += tests.qrc +SOURCES += \ + dataform.cpp \ + iq.cpp \ + jingle.cpp \ + message.cpp \ + presence.cpp \ + register.cpp \ + roster.cpp \ + rpc.cpp \ + rsm.cpp \ + rtp.cpp \ + stanza.cpp \ + stun.cpp \ + tests.cpp \ + vcard.cpp +HEADERS += \ + dataform.h \ + iq.h \ + jingle.h \ + message.h \ + presence.h \ + register.h \ + roster.h \ + rpc.h \ + rsm.h \ + rtp.h \ + stanza.h \ + stun.h \ + tests.h \ + vcard.h + +!isEmpty(QXMPP_AUTOTEST_INTERNAL) { + HEADERS += codec.h sasl.h si.h + SOURCES += codec.cpp sasl.cpp si.cpp +} diff --git a/tests/all/codec.cpp b/tests/all/codec.cpp new file mode 100644 index 00000000..cc76297e --- /dev/null +++ b/tests/all/codec.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * 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 "QXmppCodec_p.h" + +#include "codec.h" + +void TestCodec::testTheoraDecoder() +{ +#ifdef QXMPP_USE_THEORA + QMap<QString, QString> params; + params.insert("delivery-method", "inline"); + params.insert("configuration", "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"); + + QXmppTheoraDecoder decoder; + QCOMPARE(decoder.setParameters(params), true); + + QXmppVideoFormat format = decoder.format(); + QCOMPARE(format.frameSize(), QSize(320, 240)); + QCOMPARE(format.pixelFormat(), QXmppVideoFrame::Format_YUV420P); +#endif +} + +void TestCodec::testTheoraEncoder() +{ +#ifdef QXMPP_USE_THEORA + QXmppVideoFormat format; + format.setFrameSize(QSize(320, 240)); + format.setPixelFormat(QXmppVideoFrame::Format_YUV420P); + + QXmppTheoraEncoder encoder; + encoder.setFormat(format); + + QMap<QString, QString> params = encoder.parameters(); + QCOMPARE(params.value("delivery-method"), QLatin1String("inline")); + QCOMPARE(params.value("configuration"), QLatin1String("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")); +#endif +} diff --git a/tests/all/codec.h b/tests/all/codec.h new file mode 100644 index 00000000..035e5098 --- /dev/null +++ b/tests/all/codec.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * 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 TestCodec : public QObject +{ + Q_OBJECT + +private slots: + void testTheoraDecoder(); + void testTheoraEncoder(); +}; + diff --git a/tests/all/dataform.cpp b/tests/all/dataform.cpp new file mode 100644 index 00000000..da9f62b6 --- /dev/null +++ b/tests/all/dataform.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * Andrey Batyiev + * 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 "QXmppDataForm.h" + +#include "dataform.h" +#include "util.h" + +void tst_QXmppDataForm::testSimple() +{ + const QByteArray xml( + "<x xmlns=\"jabber:x:data\" type=\"form\">" + "<title>Joggle Search</title>" + "<instructions>Fill out this form to search for information!</instructions>" + "<field type=\"text-single\" var=\"search_request\">" + "<required/>" + "</field>" + "</x>"); + + QXmppDataForm form; + parsePacket(form, xml); + + QCOMPARE(form.isNull(), false); + QCOMPARE(form.title(), QLatin1String("Joggle Search")); + QCOMPARE(form.instructions(), QLatin1String("Fill out this form to search for information!")); + QCOMPARE(form.fields().size(), 1); + QCOMPARE(form.fields().at(0).type(), QXmppDataForm::Field::TextSingleField); + QCOMPARE(form.fields().at(0).isRequired(), true); + QCOMPARE(form.fields().at(0).key(), QString("search_request")); + + serializePacket(form, xml); +} + +void tst_QXmppDataForm::testSubmit() +{ + const QByteArray xml( + "<x xmlns=\"jabber:x:data\" type=\"submit\">" + "<field type=\"text-single\" var=\"search_request\">" + "<value>verona</value>" + "</field>" + "</x>"); + + QXmppDataForm form; + parsePacket(form, xml); + QCOMPARE(form.isNull(), false); + serializePacket(form, xml); +} + +void tst_QXmppDataForm::testMedia() +{ + const QByteArray xml( + "<x xmlns=\"jabber:x:data\" type=\"form\">" + "<field type=\"text-single\" label=\"Enter the text you see\" var=\"ocr\">" + "<value/>" + "<media xmlns=\"urn:xmpp:media-element\" height=\"80\" width=\"290\">" + "<uri type=\"image/jpeg\">" + "http://www.victim.com/challenges/ocr.jpeg?F3A6292C" + "</uri>" + "<uri type=\"image/png\">" + "cid:sha1+f24030b8d91d233bac14777be5ab531ca3b9f102@bob.xmpp.org" + "</uri>" + "</media>" + "</field>" + "</x>"); + + QXmppDataForm form; + parsePacket(form, xml); + + QCOMPARE(form.isNull(), false); + QCOMPARE(form.fields().size(), 1); + QCOMPARE(form.fields().at(0).type(), QXmppDataForm::Field::TextSingleField); + QCOMPARE(form.fields().at(0).isRequired(), false); + QCOMPARE(form.fields().at(0).media().uris().size(), 2); + QCOMPARE(form.fields().at(0).media().isNull(), false); + QCOMPARE(form.fields().at(0).media().height(), 80); + QCOMPARE(form.fields().at(0).media().width(), 290); + QCOMPARE(form.fields().at(0).media().uris().at(0).first, QString("image/jpeg")); + QCOMPARE(form.fields().at(0).media().uris().at(0).second, QString("http://www.victim.com/challenges/ocr.jpeg?F3A6292C")); + QCOMPARE(form.fields().at(0).media().uris().at(1).first, QString("image/png")); + QCOMPARE(form.fields().at(0).media().uris().at(1).second, QString("cid:sha1+f24030b8d91d233bac14777be5ab531ca3b9f102@bob.xmpp.org")); + + serializePacket(form, xml); +} + diff --git a/tests/all/dataform.h b/tests/all/dataform.h new file mode 100644 index 00000000..d5461237 --- /dev/null +++ b/tests/all/dataform.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * Andrey Batyiev + * 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_QXmppDataForm : public QObject +{ + Q_OBJECT + +private slots: + void testSimple(); + void testSubmit(); + void testMedia(); +}; + diff --git a/tests/all/iq.cpp b/tests/all/iq.cpp new file mode 100644 index 00000000..fa46c149 --- /dev/null +++ b/tests/all/iq.cpp @@ -0,0 +1,61 @@ +/* + * 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 "QXmppIq.h" +#include "iq.h" +#include "util.h" + +void tst_QXmppIq::testBasic_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("type"); + + QTest::newRow("get") + << QByteArray("<iq to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"get\"/>") + << int(QXmppIq::Get); + + QTest::newRow("set") + << QByteArray("<iq to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"set\"/>") + << int(QXmppIq::Set); + + QTest::newRow("result") + << QByteArray("<iq to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"result\"/>") + << int(QXmppIq::Result); + + QTest::newRow("error") + << QByteArray("<iq to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"error\"/>") + << int(QXmppIq::Error); +} + +void tst_QXmppIq::testBasic() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + + QXmppIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.to(), QString("foo@example.com/QXmpp")); + QCOMPARE(iq.from(), QString("bar@example.com/QXmpp")); + QCOMPARE(int(iq.type()), type); + serializePacket(iq, xml); +} diff --git a/tests/all/iq.h b/tests/all/iq.h new file mode 100644 index 00000000..5d382b31 --- /dev/null +++ b/tests/all/iq.h @@ -0,0 +1,34 @@ +/* + * 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 <QObject> + +class tst_QXmppIq : public QObject +{ + Q_OBJECT + +private slots: + void testBasic_data(); + void testBasic(); +}; + diff --git a/tests/all/jingle.cpp b/tests/all/jingle.cpp new file mode 100644 index 00000000..90aa3797 --- /dev/null +++ b/tests/all/jingle.cpp @@ -0,0 +1,137 @@ +/* + * 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 "QXmppJingleIq.h" + +#include "jingle.h" +#include "util.h" + +void TestJingle::testSession() +{ + const QByteArray xml( + "<iq" + " id=\"zid615d9\"" + " to=\"juliet@capulet.lit/balcony\"" + " from=\"romeo@montague.lit/orchard\"" + " type=\"set\">" + "<jingle xmlns=\"urn:xmpp:jingle:1\"" + " action=\"session-initiate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\">" + "<content creator=\"initiator\" name=\"this-is-a-stub\">" + "<description xmlns=\"urn:xmpp:jingle:apps:stub:0\"/>" + "<transport xmlns=\"urn:xmpp:jingle:transports:stub:0\"/>" + "</content>" + "</jingle>" + "</iq>"); + + QXmppJingleIq session; + parsePacket(session, xml); + QCOMPARE(session.action(), QXmppJingleIq::SessionInitiate); + QCOMPARE(session.initiator(), QLatin1String("romeo@montague.lit/orchard")); + QCOMPARE(session.sid(), QLatin1String("a73sjjvkla37jfea")); + QCOMPARE(session.content().creator(), QLatin1String("initiator")); + QCOMPARE(session.content().name(), QLatin1String("this-is-a-stub")); + QCOMPARE(session.reason().text(), QString()); + QCOMPARE(session.reason().type(), QXmppJingleIq::Reason::None); + serializePacket(session, xml); +} + +void TestJingle::testTerminate() +{ + const QByteArray xml( + "<iq" + " id=\"le71fa63\"" + " to=\"romeo@montague.lit/orchard\"" + " from=\"juliet@capulet.lit/balcony\"" + " type=\"set\">" + "<jingle xmlns=\"urn:xmpp:jingle:1\"" + " action=\"session-terminate\"" + " sid=\"a73sjjvkla37jfea\">" + "<reason>" + "<success/>" + "</reason>" + "</jingle>" + "</iq>"); + + QXmppJingleIq session; + parsePacket(session, xml); + QCOMPARE(session.action(), QXmppJingleIq::SessionTerminate); + QCOMPARE(session.initiator(), QString()); + QCOMPARE(session.sid(), QLatin1String("a73sjjvkla37jfea")); + QCOMPARE(session.reason().text(), QString()); + QCOMPARE(session.reason().type(), QXmppJingleIq::Reason::Success); + serializePacket(session, xml); +} + +void TestJingle::testAudioPayloadType() +{ + const QByteArray xml("<payload-type id=\"103\" name=\"L16\" channels=\"2\" clockrate=\"16000\"/>"); + QXmppJinglePayloadType payload; + parsePacket(payload, xml); + QCOMPARE(payload.id(), static_cast<unsigned char>(103)); + QCOMPARE(payload.name(), QLatin1String("L16")); + QCOMPARE(payload.channels(), static_cast<unsigned char>(2)); + QCOMPARE(payload.clockrate(), 16000u); + serializePacket(payload, xml); +} + +void TestJingle::testVideoPayloadType() +{ + const QByteArray xml( + "<payload-type id=\"98\" name=\"theora\" clockrate=\"90000\">" + "<parameter name=\"height\" value=\"768\"/>" + "<parameter name=\"width\" value=\"1024\"/>" + "</payload-type>"); + QXmppJinglePayloadType payload; + parsePacket(payload, xml); + QCOMPARE(payload.id(), static_cast<unsigned char>(98)); + QCOMPARE(payload.name(), QLatin1String("theora")); + QCOMPARE(payload.clockrate(), 90000u); + QCOMPARE(payload.parameters().size(), 2); + QCOMPARE(payload.parameters().value("height"), QLatin1String("768")); + QCOMPARE(payload.parameters().value("width"), QLatin1String("1024")); + serializePacket(payload, xml); +} + +void TestJingle::testRinging() +{ + const QByteArray xml( + "<iq" + " id=\"tgr515bt\"" + " to=\"romeo@montague.lit/orchard\"" + " from=\"juliet@capulet.lit/balcony\"" + " type=\"set\">" + "<jingle xmlns=\"urn:xmpp:jingle:1\"" + " action=\"session-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\">" + "<ringing xmlns=\"urn:xmpp:jingle:apps:rtp:info:1\"/>" + "</jingle>" + "</iq>"); + + QXmppJingleIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.ringing(), true); + serializePacket(iq, xml); +} diff --git a/tests/all/jingle.h b/tests/all/jingle.h new file mode 100644 index 00000000..9098e8da --- /dev/null +++ b/tests/all/jingle.h @@ -0,0 +1,37 @@ +/* + * 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 <QObject> + +class TestJingle : public QObject +{ + Q_OBJECT + +private slots: + void testSession(); + void testTerminate(); + void testAudioPayloadType(); + void testVideoPayloadType(); + void testRinging(); +}; + diff --git a/tests/all/message.cpp b/tests/all/message.cpp new file mode 100644 index 00000000..fbdb5234 --- /dev/null +++ b/tests/all/message.cpp @@ -0,0 +1,292 @@ +/* + * 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 "QXmppMessage.h" +#include "message.h" +#include "util.h" + +void tst_QXmppMessage::testBasic_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("type"); + QTest::addColumn<QString>("body"); + QTest::addColumn<QString>("subject"); + QTest::addColumn<QString>("thread"); + + QTest::newRow("error") + << QByteArray("<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"error\"/>") + << int(QXmppMessage::Error) + << QString() << QString() << QString(); + QTest::newRow("normal") + << QByteArray("<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\"/>") + << int(QXmppMessage::Normal) + << QString() << QString() << QString(); + QTest::newRow("chat") + << QByteArray("<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"chat\"/>") + << int(QXmppMessage::Chat) + << QString() << QString() << QString(); + QTest::newRow("groupchat") + << QByteArray("<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"groupchat\"/>") + << int(QXmppMessage::GroupChat) + << QString() << QString() << QString(); + QTest::newRow("headline") + << QByteArray("<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"headline\"/>") + << int(QXmppMessage::Headline) + << QString() << QString() << QString(); + + QTest::newRow("full") + << QByteArray("<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">" + "<subject>test subject</subject>" + "<body>test body & stuff</body>" + "<thread>test thread</thread>" + "</message>") + << int(QXmppMessage::Normal) + << "test body & stuff" << "test subject" << "test thread"; +} + +void tst_QXmppMessage::testBasic() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + QFETCH(QString, body); + QFETCH(QString, subject); + QFETCH(QString, thread); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.to(), QString("foo@example.com/QXmpp")); + QCOMPARE(message.from(), QString("bar@example.com/QXmpp")); + QVERIFY(message.extendedAddresses().isEmpty()); + QCOMPARE(int(message.type()), type); + QCOMPARE(message.body(), body); + QCOMPARE(message.subject(), subject); + QCOMPARE(message.thread(), thread); + QCOMPARE(message.state(), QXmppMessage::None); + QCOMPARE(message.isAttentionRequested(), false); + QCOMPARE(message.isReceiptRequested(), false); + QCOMPARE(message.receiptId(), QString()); + QCOMPARE(message.xhtml(), QString()); + serializePacket(message, xml); +} + +void tst_QXmppMessage::testMessageAttention() +{ + const QByteArray xml( + "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">" + "<attention xmlns=\"urn:xmpp:attention:0\"/>" + "</message>"); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.to(), QString("foo@example.com/QXmpp")); + QCOMPARE(message.from(), QString("bar@example.com/QXmpp")); + QVERIFY(message.extendedAddresses().isEmpty()); + QCOMPARE(message.type(), QXmppMessage::Normal); + QCOMPARE(message.body(), QString()); + QCOMPARE(message.isAttentionRequested(), true); + QCOMPARE(message.isReceiptRequested(), false); + QCOMPARE(message.receiptId(), QString()); + serializePacket(message, xml); +} + +void tst_QXmppMessage::testMessageReceipt() +{ + const QByteArray xml( + "<message id=\"richard2-4.1.247\" to=\"kingrichard@royalty.england.lit/throne\" from=\"northumberland@shakespeare.lit/westminster\" type=\"normal\">" + "<body>My lord, dispatch; read o'er these articles.</body>" + "<request xmlns=\"urn:xmpp:receipts\"/>" + "</message>"); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.id(), QString("richard2-4.1.247")); + QCOMPARE(message.to(), QString("kingrichard@royalty.england.lit/throne")); + QCOMPARE(message.from(), QString("northumberland@shakespeare.lit/westminster")); + QVERIFY(message.extendedAddresses().isEmpty()); + QCOMPARE(message.type(), QXmppMessage::Normal); + QCOMPARE(message.body(), QString("My lord, dispatch; read o'er these articles.")); + QCOMPARE(message.isAttentionRequested(), false); + QCOMPARE(message.isReceiptRequested(), true); + QCOMPARE(message.receiptId(), QString()); + serializePacket(message, xml); + + const QByteArray receiptXml( + "<message id=\"bi29sg183b4v\" to=\"northumberland@shakespeare.lit/westminster\" from=\"kingrichard@royalty.england.lit/throne\" type=\"normal\">" + "<received xmlns=\"urn:xmpp:receipts\" id=\"richard2-4.1.247\"/>" + "</message>"); + + QXmppMessage receipt; + parsePacket(receipt, receiptXml); + QCOMPARE(receipt.id(), QString("bi29sg183b4v")); + QCOMPARE(receipt.to(), QString("northumberland@shakespeare.lit/westminster")); + QCOMPARE(receipt.from(), QString("kingrichard@royalty.england.lit/throne")); + QVERIFY(receipt.extendedAddresses().isEmpty()); + QCOMPARE(receipt.type(), QXmppMessage::Normal); + QCOMPARE(receipt.body(), QString()); + QCOMPARE(receipt.isAttentionRequested(), false); + QCOMPARE(receipt.isReceiptRequested(), false); + QCOMPARE(receipt.receiptId(), QString("richard2-4.1.247")); + serializePacket(receipt, receiptXml); + + const QByteArray oldXml( + "<message id=\"richard2-4.1.247\" to=\"northumberland@shakespeare.lit/westminster\" from=\"kingrichard@royalty.england.lit/throne\" type=\"normal\">" + "<received xmlns=\"urn:xmpp:receipts\"/>" + "</message>"); + + QXmppMessage old; + parsePacket(old, oldXml); + QCOMPARE(old.id(), QString("richard2-4.1.247")); + QCOMPARE(old.to(), QString("northumberland@shakespeare.lit/westminster")); + QCOMPARE(old.from(), QString("kingrichard@royalty.england.lit/throne")); + QVERIFY(old.extendedAddresses().isEmpty()); + QCOMPARE(old.type(), QXmppMessage::Normal); + QCOMPARE(old.body(), QString()); + QCOMPARE(old.isAttentionRequested(), false); + QCOMPARE(old.isReceiptRequested(), false); + QCOMPARE(old.receiptId(), QString("richard2-4.1.247")); +} + +void tst_QXmppMessage::testDelay_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<QDateTime>("stamp"); + + QTest::newRow("delay") + << QByteArray("<message type=\"normal\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06Z\"/>" + "</message>") + << QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC); + + QTest::newRow("legacy") + << QByteArray("<message type=\"normal\">" + "<x xmlns=\"jabber:x:delay\" stamp=\"20100629T08:23:06\"/>" + "</message>") + << QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC); +} + +void tst_QXmppMessage::testDelay() +{ + QFETCH(QByteArray, xml); + QFETCH(QDateTime, stamp); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.stamp(), stamp); + serializePacket(message, xml); +} + +void tst_QXmppMessage::testExtendedAddresses() +{ + QByteArray xml( + "<message to=\"multicast.jabber.org\" type=\"normal\">" + "<addresses xmlns=\"http://jabber.org/protocol/address\">" + "<address desc=\"Joe Hildebrand\" jid=\"hildjj@jabber.org/Work\" type=\"to\"/>" + "<address desc=\"Jeremie Miller\" jid=\"jer@jabber.org/Home\" type=\"cc\"/>" + "</addresses>" + "</message>"); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.extendedAddresses().size(), 2); + QCOMPARE(message.extendedAddresses()[0].description(), QLatin1String("Joe Hildebrand")); + QCOMPARE(message.extendedAddresses()[0].jid(), QLatin1String("hildjj@jabber.org/Work")); + QCOMPARE(message.extendedAddresses()[0].type(), QLatin1String("to")); + QCOMPARE(message.extendedAddresses()[1].description(), QLatin1String("Jeremie Miller")); + QCOMPARE(message.extendedAddresses()[1].jid(), QLatin1String("jer@jabber.org/Home")); + QCOMPARE(message.extendedAddresses()[1].type(), QLatin1String("cc")); + serializePacket(message, xml); +} + +void tst_QXmppMessage::testMucInvitation() +{ + QByteArray xml( + "<message to=\"hecate@shakespeare.lit\" from=\"crone1@shakespeare.lit/desktop\" type=\"normal\">" + "<x xmlns=\"jabber:x:conference\" jid=\"darkcave@macbeth.shakespeare.lit\" password=\"cauldronburn\" reason=\"Hey Hecate, this is the place for all good witches!\"/>" + "</message>"); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.mucInvitationJid(), QLatin1String("darkcave@macbeth.shakespeare.lit")); + QCOMPARE(message.mucInvitationPassword(), QLatin1String("cauldronburn")); + QCOMPARE(message.mucInvitationReason(), QLatin1String("Hey Hecate, this is the place for all good witches!")); + serializePacket(message, xml); +} + +void tst_QXmppMessage::testState_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("state"); + + QTest::newRow("none") + << QByteArray("<message type=\"normal\"/>") + << int(QXmppMessage::None); + + QTest::newRow("active") + << QByteArray("<message type=\"normal\"><active xmlns=\"http://jabber.org/protocol/chatstates\"/></message>") + << int(QXmppMessage::Active); + + QTest::newRow("inactive") + << QByteArray("<message type=\"normal\"><inactive xmlns=\"http://jabber.org/protocol/chatstates\"/></message>") + << int(QXmppMessage::Inactive); + + QTest::newRow("gone") + << QByteArray("<message type=\"normal\"><gone xmlns=\"http://jabber.org/protocol/chatstates\"/></message>") + << int(QXmppMessage::Gone); + + QTest::newRow("composing") + << QByteArray("<message type=\"normal\"><composing xmlns=\"http://jabber.org/protocol/chatstates\"/></message>") + << int(QXmppMessage::Composing); + + QTest::newRow("paused") + << QByteArray("<message type=\"normal\"><paused xmlns=\"http://jabber.org/protocol/chatstates\"/></message>") + << int(QXmppMessage::Paused); +} + +void tst_QXmppMessage::testState() +{ + QFETCH(QByteArray, xml); + QFETCH(int, state); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(int(message.state()), state); + serializePacket(message, xml); +} + +void tst_QXmppMessage::testXhtml() +{ + const QByteArray xml("<message type=\"normal\">" + "<body>hi!</body>" + "<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" + "<body xmlns=\"http://www.w3.org/1999/xhtml\">" + "<p style=\"font-weight:bold\">hi!</p>" + "</body>" + "</html>" + "</message>"); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.xhtml(), QLatin1String("<p style=\"font-weight:bold\">hi!</p>")); + serializePacket(message, xml); +} diff --git a/tests/all/message.h b/tests/all/message.h new file mode 100644 index 00000000..08c71283 --- /dev/null +++ b/tests/all/message.h @@ -0,0 +1,44 @@ +/* + * 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 <QObject> + +class tst_QXmppMessage : public QObject +{ + Q_OBJECT + +private slots: + void testBasic_data(); + void testBasic(); + void testMessageAttention(); + void testMessageReceipt(); + void testDelay_data(); + void testDelay(); + void testExtendedAddresses(); + void testMucInvitation(); + void testState_data(); + void testState(); + void testXhtml(); +}; + diff --git a/tests/all/presence.cpp b/tests/all/presence.cpp new file mode 100644 index 00000000..c2762622 --- /dev/null +++ b/tests/all/presence.cpp @@ -0,0 +1,223 @@ +/* + * 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<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"); + + // presence type + QTest::newRow("available") << QByteArray("<presence/>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unavailable") << QByteArray("<presence type=\"unavailable\"/>") << int(QXmppPresence::Unavailable) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("error") << QByteArray("<presence type=\"error\"/>") << int(QXmppPresence::Error) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("subscribe") << QByteArray("<presence type=\"subscribe\"/>") << int(QXmppPresence::Subscribe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unsubscribe") << QByteArray("<presence type=\"unsubscribe\"/>") << int(QXmppPresence::Unsubscribe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("subscribed") << QByteArray("<presence type=\"subscribed\"/>") << int(QXmppPresence::Subscribed) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("unsubscribed") << QByteArray("<presence type=\"unsubscribed\"/>") << int(QXmppPresence::Unsubscribed) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("probe") << QByteArray("<presence type=\"probe\"/>") << int(QXmppPresence::Probe) << 0 << int(QXmppPresence::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + // status text + priority + QTest::newRow("full") << QByteArray("<presence><show>away</show><status>In a meeting</status><priority>5</priority></presence>") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Away) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + // status type + QTest::newRow("away") << QByteArray("<presence><show>away</show></presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Away) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("dnd") << QByteArray("<presence><show>dnd</show></presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::DND) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("chat") << QByteArray("<presence><show>chat</show></presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Chat) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("xa") << QByteArray("<presence><show>xa</show></presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::XA) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + QTest::newRow("invisible") << QByteArray("<presence><show>invisible</show></presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Invisible) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); + + // photo + QTest::newRow("vcard-photo") << QByteArray( + "<presence>" + "<x xmlns=\"vcard-temp:x:update\">" + "<photo>73b908bc</photo>" + "</x>" + "</presence>") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::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::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( + "<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.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( + "<presence to=\"multicast.jabber.org\" from=\"hildjj@jabber.com\" type=\"unavailable\">" + "<addresses xmlns=\"http://jabber.org/protocol/address\">" + "<address jid=\"temas@jabber.org\" type=\"bcc\"/>" + "<address jid=\"jer@jabber.org\" type=\"bcc\"/>" + "</addresses>" + "</presence>"); + + 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( + "<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 tst_QXmppPresence::testPresenceWithMucPassword() +{ + const QByteArray xml( + "<presence " + "to=\"coven@chat.shakespeare.lit/thirdwitch\" " + "from=\"hag66@shakespeare.lit/pda\">" + "<x xmlns=\"http://jabber.org/protocol/muc\">" + "<password>pass</password>" + "</x>" + "</presence>"); + + 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( + "<presence " + "to=\"coven@chat.shakespeare.lit/thirdwitch\" " + "from=\"hag66@shakespeare.lit/pda\">" + "<x xmlns=\"http://jabber.org/protocol/muc\"/>" + "</presence>"); + + 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 new file mode 100644 index 00000000..74bd7ee8 --- /dev/null +++ b/tests/all/presence.h @@ -0,0 +1,40 @@ +/* + * 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 testPresenceWithExtendedAddresses(); + void testPresenceWithMucItem(); + void testPresenceWithMucPassword(); + void testPresenceWithMucSupport(); +}; + diff --git a/tests/all/register.cpp b/tests/all/register.cpp new file mode 100644 index 00000000..9dfe2fcb --- /dev/null +++ b/tests/all/register.cpp @@ -0,0 +1,186 @@ +/* + * 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 "QXmppRegisterIq.h" + +#include "util.h" +#include "register.h" + +void tst_QXmppRegisterIq::testGet() +{ + const QByteArray xml( + "<iq id=\"reg1\" to=\"shakespeare.lit\" type=\"get\">" + "<query xmlns=\"jabber:iq:register\"/>" + "</iq>"); + + QXmppRegisterIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("reg1")); + QCOMPARE(iq.to(), QLatin1String("shakespeare.lit")); + QCOMPARE(iq.from(), QString()); + QCOMPARE(iq.type(), QXmppIq::Get); + QCOMPARE(iq.instructions(), QString()); + QVERIFY(iq.username().isNull()); + QVERIFY(iq.password().isNull()); + QVERIFY(iq.email().isNull()); + QVERIFY(iq.form().isNull()); + serializePacket(iq, xml); +} + +void tst_QXmppRegisterIq::testResult() +{ + const QByteArray xml( + "<iq id=\"reg1\" type=\"result\">" + "<query xmlns=\"jabber:iq:register\">" + "<instructions>Choose a username and password for use with this service. Please also provide your email address.</instructions>" + "<username/>" + "<password/>" + "<email/>" + "</query>" + "</iq>"); + + QXmppRegisterIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("reg1")); + QCOMPARE(iq.to(), QString()); + QCOMPARE(iq.from(), QString()); + QCOMPARE(iq.type(), QXmppIq::Result); + QCOMPARE(iq.instructions(), QLatin1String("Choose a username and password for use with this service. Please also provide your email address.")); + QVERIFY(!iq.username().isNull()); + QVERIFY(iq.username().isEmpty()); + QVERIFY(!iq.password().isNull()); + QVERIFY(iq.password().isEmpty()); + QVERIFY(!iq.email().isNull()); + QVERIFY(iq.email().isEmpty()); + QVERIFY(iq.form().isNull()); + serializePacket(iq, xml); +} + +void tst_QXmppRegisterIq::testResultWithForm() +{ + const QByteArray xml( + "<iq id=\"reg3\" to=\"juliet@capulet.com/balcony\" from=\"contests.shakespeare.lit\" type=\"result\">" + "<query xmlns=\"jabber:iq:register\">" + "<instructions>Use the enclosed form to register. If your Jabber client does not support Data Forms, visit http://www.shakespeare.lit/contests.php</instructions>" + "<x xmlns=\"jabber:x:data\" type=\"form\">" + "<title>Contest Registration</title>" + "<instructions>" + "Please provide the following information" + "to sign up for our special contests!" + "</instructions>" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:register</value>" + "</field>" + "<field type=\"text-single\" label=\"Given Name\" var=\"first\">" + "<required/>" + "</field>" + "<field type=\"text-single\" label=\"Family Name\" var=\"last\">" + "<required/>" + "</field>" + "<field type=\"text-single\" label=\"Email Address\" var=\"email\">" + "<required/>" + "</field>" + "<field type=\"list-single\" label=\"Gender\" var=\"x-gender\">" + "<option label=\"Male\"><value>M</value></option>" + "<option label=\"Female\"><value>F</value></option>" + "</field>" + "</x>" + "</query>" + "</iq>"); + + QXmppRegisterIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("reg3")); + QCOMPARE(iq.to(), QLatin1String("juliet@capulet.com/balcony")); + QCOMPARE(iq.from(), QLatin1String("contests.shakespeare.lit")); + QCOMPARE(iq.type(), QXmppIq::Result); + QCOMPARE(iq.instructions(), QLatin1String("Use the enclosed form to register. If your Jabber client does not support Data Forms, visit http://www.shakespeare.lit/contests.php")); + QVERIFY(iq.username().isNull()); + QVERIFY(iq.password().isNull()); + QVERIFY(iq.email().isNull()); + QVERIFY(!iq.form().isNull()); + QCOMPARE(iq.form().title(), QLatin1String("Contest Registration")); + serializePacket(iq, xml); +} + +void tst_QXmppRegisterIq::testSet() +{ + const QByteArray xml( + "<iq id=\"reg2\" type=\"set\">" + "<query xmlns=\"jabber:iq:register\">" + "<username>bill</username>" + "<password>Calliope</password>" + "<email>bard@shakespeare.lit</email>" + "</query>" + "</iq>"); + + QXmppRegisterIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("reg2")); + QCOMPARE(iq.to(), QString()); + QCOMPARE(iq.from(), QString()); + QCOMPARE(iq.type(), QXmppIq::Set); + QCOMPARE(iq.username(), QLatin1String("bill")); + QCOMPARE(iq.password(), QLatin1String("Calliope")); + QCOMPARE(iq.email(), QLatin1String("bard@shakespeare.lit")); + QVERIFY(iq.form().isNull()); + serializePacket(iq, xml); +} + +void tst_QXmppRegisterIq::testSetWithForm() +{ + const QByteArray xml( + "<iq id=\"reg4\" to=\"contests.shakespeare.lit\" from=\"juliet@capulet.com/balcony\" type=\"set\">" + "<query xmlns=\"jabber:iq:register\">" + "<x xmlns=\"jabber:x:data\" type=\"submit\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:register</value>" + "</field>" + "<field type=\"text-single\" label=\"Given Name\" var=\"first\">" + "<value>Juliet</value>" + "</field>" + "<field type=\"text-single\" label=\"Family Name\" var=\"last\">" + "<value>Capulet</value>" + "</field>" + "<field type=\"text-single\" label=\"Email Address\" var=\"email\">" + "<value>juliet@capulet.com</value>" + "</field>" + "<field type=\"list-single\" label=\"Gender\" var=\"x-gender\">" + "<value>F</value>" + "</field>" + "</x>" + "</query>" + "</iq>"); + + QXmppRegisterIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.id(), QLatin1String("reg4")); + QCOMPARE(iq.to(), QLatin1String("contests.shakespeare.lit")); + QCOMPARE(iq.from(), QLatin1String("juliet@capulet.com/balcony")); + QCOMPARE(iq.type(), QXmppIq::Set); + QVERIFY(iq.username().isNull()); + QVERIFY(iq.password().isNull()); + QVERIFY(iq.email().isNull()); + QVERIFY(!iq.form().isNull()); + serializePacket(iq, xml); +} diff --git a/tests/all/register.h b/tests/all/register.h new file mode 100644 index 00000000..4c54e8c7 --- /dev/null +++ b/tests/all/register.h @@ -0,0 +1,37 @@ +/* + * 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 <QObject> + +class tst_QXmppRegisterIq : public QObject +{ + Q_OBJECT + +private slots: + void testGet(); + void testResult(); + void testResultWithForm(); + void testSet(); + void testSetWithForm(); +}; + diff --git a/tests/all/roster.cpp b/tests/all/roster.cpp new file mode 100644 index 00000000..2b664212 --- /dev/null +++ b/tests/all/roster.cpp @@ -0,0 +1,81 @@ +/* + * 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 "QXmppRosterIq.h" + +#include "roster.h" +#include "util.h" + +void tst_QXmppRosterIq::testItem_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<QString>("name"); + QTest::addColumn<int>("subscriptionType"); + + QTest::newRow("none") + << QByteArray("<item jid=\"foo@example.com\" subscription=\"none\"/>") + << "" + << int(QXmppRosterIq::Item::None); + QTest::newRow("from") + << QByteArray("<item jid=\"foo@example.com\" subscription=\"from\"/>") + << "" + << int(QXmppRosterIq::Item::From); + QTest::newRow("to") + << QByteArray("<item jid=\"foo@example.com\" subscription=\"to\"/>") + << "" + << int(QXmppRosterIq::Item::To); + QTest::newRow("both") + << QByteArray("<item jid=\"foo@example.com\" subscription=\"both\"/>") + << "" + << int(QXmppRosterIq::Item::Both); + QTest::newRow("remove") + << QByteArray("<item jid=\"foo@example.com\" subscription=\"remove\"/>") + << "" + << int(QXmppRosterIq::Item::Remove); + QTest::newRow("notset") + << QByteArray("<item jid=\"foo@example.com\"/>") + << "" + << int(QXmppRosterIq::Item::NotSet); + + QTest::newRow("name") + << QByteArray("<item jid=\"foo@example.com\" name=\"foo bar\"/>") + << "foo bar" + << int(QXmppRosterIq::Item::NotSet); +} + +void tst_QXmppRosterIq::testItem() +{ + QFETCH(QByteArray, xml); + QFETCH(QString, name); + QFETCH(int, subscriptionType); + + QXmppRosterIq::Item item; + parsePacket(item, xml); + QCOMPARE(item.bareJid(), QLatin1String("foo@example.com")); + QCOMPARE(item.groups(), QSet<QString>()); + QCOMPARE(item.name(), name); + QCOMPARE(int(item.subscriptionType()), subscriptionType); + QCOMPARE(item.subscriptionStatus(), QString()); + serializePacket(item, xml); +} + diff --git a/tests/all/roster.h b/tests/all/roster.h new file mode 100644 index 00000000..83240ec3 --- /dev/null +++ b/tests/all/roster.h @@ -0,0 +1,34 @@ +/* + * 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 <QObject> + +class tst_QXmppRosterIq : public QObject +{ + Q_OBJECT + +private slots: + void testItem_data(); + void testItem(); +}; + diff --git a/tests/all/rpc.cpp b/tests/all/rpc.cpp new file mode 100644 index 00000000..c0714957 --- /dev/null +++ b/tests/all/rpc.cpp @@ -0,0 +1,212 @@ +/* + * 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 "QXmppRpcIq.h" + +#include "rpc.h" +#include "util.h" + +static void checkVariant(const QVariant &value, const QByteArray &xml) +{ + // serialise + QBuffer buffer; + buffer.open(QIODevice::ReadWrite); + QXmlStreamWriter writer(&buffer); + QXmppRpcMarshaller::marshall(&writer, value); + qDebug() << "expect " << xml; + qDebug() << "writing" << buffer.data(); + QCOMPARE(buffer.data(), xml); + + // parse + QDomDocument doc; + QCOMPARE(doc.setContent(xml, true), true); + QDomElement element = doc.documentElement(); + QStringList errors; + QVariant test = QXmppRpcMarshaller::demarshall(element, errors); + if (!errors.isEmpty()) + qDebug() << errors; + QCOMPARE(errors, QStringList()); + QCOMPARE(test, value); +} + +void TestXmlRpc::testBase64() +{ + checkVariant(QByteArray("\0\1\2\3", 4), + QByteArray("<value><base64>AAECAw==</base64></value>")); +} + +void TestXmlRpc::testBool() +{ + checkVariant(false, + QByteArray("<value><boolean>0</boolean></value>")); + checkVariant(true, + QByteArray("<value><boolean>1</boolean></value>")); +} + +void TestXmlRpc::testDateTime() +{ + checkVariant(QDateTime(QDate(1998, 7, 17), QTime(14, 8, 55)), + QByteArray("<value><dateTime.iso8601>1998-07-17T14:08:55</dateTime.iso8601></value>")); +} + +void TestXmlRpc::testDouble() +{ + checkVariant(double(-12.214), + QByteArray("<value><double>-12.214</double></value>")); +} + +void TestXmlRpc::testInt() +{ + checkVariant(int(-12), + QByteArray("<value><i4>-12</i4></value>")); +} + +void TestXmlRpc::testNil() +{ + checkVariant(QVariant(), + QByteArray("<value><nil/></value>")); +} + +void TestXmlRpc::testString() +{ + checkVariant(QString("hello world"), + QByteArray("<value><string>hello world</string></value>")); +} + +void TestXmlRpc::testArray() +{ + checkVariant(QVariantList() << QString("hello world") << double(-12.214), + QByteArray("<value><array><data>" + "<value><string>hello world</string></value>" + "<value><double>-12.214</double></value>" + "</data></array></value>")); +} + +void TestXmlRpc::testStruct() +{ + QMap<QString, QVariant> map; + map["bar"] = QString("hello world"); + map["foo"] = double(-12.214); + checkVariant(map, + QByteArray("<value><struct>" + "<member>" + "<name>bar</name>" + "<value><string>hello world</string></value>" + "</member>" + "<member>" + "<name>foo</name>" + "<value><double>-12.214</double></value>" + "</member>" + "</struct></value>")); +} + +void TestXmlRpc::testInvoke() +{ + const QByteArray xml( + "<iq" + " id=\"rpc1\"" + " to=\"responder@company-a.com/jrpc-server\"" + " from=\"requester@company-b.com/jrpc-client\"" + " type=\"set\">" + "<query xmlns=\"jabber:iq:rpc\">" + "<methodCall>" + "<methodName>examples.getStateName</methodName>" + "<params>" + "<param>" + "<value><i4>6</i4></value>" + "</param>" + "</params>" + "</methodCall>" + "</query>" + "</iq>"); + + QXmppRpcInvokeIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.method(), QLatin1String("examples.getStateName")); + QCOMPARE(iq.arguments(), QVariantList() << int(6)); + serializePacket(iq, xml); +} + +void TestXmlRpc::testResponse() +{ + const QByteArray xml( + "<iq" + " id=\"rpc1\"" + " to=\"requester@company-b.com/jrpc-client\"" + " from=\"responder@company-a.com/jrpc-server\"" + " type=\"result\">" + "<query xmlns=\"jabber:iq:rpc\">" + "<methodResponse>" + "<params>" + "<param>" + "<value><string>Colorado</string></value>" + "</param>" + "</params>" + "</methodResponse>" + "</query>" + "</iq>"); + + QXmppRpcResponseIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.faultCode(), 0); + QCOMPARE(iq.faultString(), QString()); + QCOMPARE(iq.values(), QVariantList() << QString("Colorado")); + serializePacket(iq, xml); +} + +void TestXmlRpc::testResponseFault() +{ + const QByteArray xml( + "<iq" + " id=\"rpc1\"" + " to=\"requester@company-b.com/jrpc-client\"" + " from=\"responder@company-a.com/jrpc-server\"" + " type=\"result\">" + "<query xmlns=\"jabber:iq:rpc\">" + "<methodResponse>" + "<fault>" + "<value>" + "<struct>" + "<member>" + "<name>faultCode</name>" + "<value><i4>404</i4></value>" + "</member>" + "<member>" + "<name>faultString</name>" + "<value><string>Not found</string></value>" + "</member>" + "</struct>" + "</value>" + "</fault>" + "</methodResponse>" + "</query>" + "</iq>"); + + QXmppRpcResponseIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.faultCode(), 404); + QCOMPARE(iq.faultString(), QLatin1String("Not found")); + QCOMPARE(iq.values(), QVariantList()); + serializePacket(iq, xml); +} + diff --git a/tests/all/rpc.h b/tests/all/rpc.h new file mode 100644 index 00000000..f3a0c5e0 --- /dev/null +++ b/tests/all/rpc.h @@ -0,0 +1,45 @@ +/* + * 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 <QObject> + +class TestXmlRpc : public QObject +{ + Q_OBJECT + +private slots: + void testBase64(); + void testBool(); + void testDateTime(); + void testDouble(); + void testInt(); + void testNil(); + void testString(); + + void testArray(); + void testStruct(); + + void testInvoke(); + void testResponse(); + void testResponseFault(); +}; diff --git a/tests/all/rsm.cpp b/tests/all/rsm.cpp new file mode 100644 index 00000000..ca5438ad --- /dev/null +++ b/tests/all/rsm.cpp @@ -0,0 +1,155 @@ +/* + * 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 "QXmppResultSet.h" + +#include "rsm.h" +#include "util.h" + +void tst_QXmppResultSet::testQuery_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("max"); + QTest::addColumn<int>("index"); + QTest::addColumn<QString>("before"); + QTest::addColumn<QString>("after"); + + QTest::newRow("Example 3") << + QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "</set>") + << 10 << -1 << QString() << QString(); + + QTest::newRow("Example 5") << + QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "<after>peterpan@neverland.lit</after>" + "</set>") + << 10 << -1 << QString() << QString("peterpan@neverland.lit"); + + QTest::newRow("Example 5") << + QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "<before>peter@pixyland.org</before>" + "</set>") + << 10 << -1 << QString("peter@pixyland.org") << QString(); + + QTest::newRow("Example 11") << + QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "<before/>" + "</set>") + << 10 << -1 << QString("") << QString(); + + QTest::newRow("Example 12") << + QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "<index>371</index>" + "</set>") + << 10 << 371 << QString() << QString(); + + + QTest::newRow("Example 15") << + QByteArray("<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>0</max>" + "</set>") + << 0 << -1 << QString() << QString(); +} + +void tst_QXmppResultSet::testQuery() +{ + QFETCH(QByteArray, xml); + QFETCH(int, max); + QFETCH(int, index); + QFETCH(QString, before); + QFETCH(QString, after); + + QXmppResultSetQuery iq; + parsePacket(iq, xml); + QCOMPARE(iq.max(), max); + QCOMPARE(iq.index(), index); + QCOMPARE(iq.before(), before); + QCOMPARE(iq.before().isNull(), before.isNull()); + QCOMPARE(iq.after(), after); + QCOMPARE(iq.after().isNull(), after.isNull()); + serializePacket(iq, xml); +} + +void tst_QXmppResultSet::testReply_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("count"); + QTest::addColumn<int>("index"); + QTest::addColumn<QString>("first"); + QTest::addColumn<QString>("last"); + + QTest::newRow("Example 4") << + QByteArray( "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first index=\"0\">stpeter@jabber.org</first>" + "<last>peterpan@neverland.lit</last>" + "<count>800</count>" + "</set>") + << 800 << 0 << QString("stpeter@jabber.org") << QString("peterpan@neverland.lit"); + + QTest::newRow("Example 6") << + QByteArray( "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first index=\"0\">stpeter@jabber.org</first>" + "<last>peterpan@neverland.lit</last>" + "<count>800</count>" + "</set>") + << 800 << 0 << QString("stpeter@jabber.org") << QString("peterpan@neverland.lit"); + QTest::newRow("Example 4") << + QByteArray( "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first index=\"10\">peter@pixyland.org</first>" + "<last>peter@rabbit.lit</last>" + "<count>800</count>" + "</set>") + << 800 << 10 << QString("peter@pixyland.org") << QString("peter@rabbit.lit"); + + QTest::newRow("Example 7") << + QByteArray( "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<count>790</count>" + "</set>") + << 790 << -1 << QString() << QString(); +} + +void tst_QXmppResultSet::testReply() +{ + QFETCH(QByteArray, xml); + QFETCH(int, count); + QFETCH(int, index); + QFETCH(QString, first); + QFETCH(QString, last); + + QXmppResultSetReply iq; + parsePacket(iq, xml); + QCOMPARE(iq.count(), count); + QCOMPARE(iq.index(), index); + QCOMPARE(iq.first(), first); + QCOMPARE(iq.first().isNull(), first.isNull()); + QCOMPARE(iq.last(), last); + QCOMPARE(iq.last().isNull(), last.isNull()); + serializePacket(iq, xml); +} + diff --git a/tests/all/rsm.h b/tests/all/rsm.h new file mode 100644 index 00000000..120ea625 --- /dev/null +++ b/tests/all/rsm.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_QXmppResultSet : public QObject +{ + Q_OBJECT + +private slots: + void testQuery_data(); + void testQuery(); + void testReply_data(); + void testReply(); +}; + diff --git a/tests/all/rtp.cpp b/tests/all/rtp.cpp new file mode 100644 index 00000000..cc7ee112 --- /dev/null +++ b/tests/all/rtp.cpp @@ -0,0 +1,76 @@ +/* + * 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 <QtTest/QtTest> + +#include "QXmppRtpChannel.h" + +#include "rtp.h" + +void tst_QXmppRtpPacket::testBad() +{ + QXmppRtpPacket packet; + + // too short + QCOMPARE(packet.decode(QByteArray()), false); + QCOMPARE(packet.decode(QByteArray("\x80\x00\x3e", 3)), false); + QCOMPARE(packet.decode(QByteArray("\x84\x00\x3e\xd2\x00\x00\x00\x90\x5f\xbd\x16\x9e", 12)), false); + + // wrong RTP version + QCOMPARE(packet.decode(QByteArray("\x40\x00\x3e\xd2\x00\x00\x00\x90\x5f\xbd\x16\x9e", 12)), false); +} + +void tst_QXmppRtpPacket::testSimple() +{ + QByteArray data("\x80\x00\x3e\xd2\x00\x00\x00\x90\x5f\xbd\x16\x9e\x12\x34\x56", 15); + QXmppRtpPacket packet; + QCOMPARE(packet.decode(data), true); + QCOMPARE(packet.version, quint8(2)); + QCOMPARE(packet.marker, false); + QCOMPARE(packet.type, quint8(0)); + QCOMPARE(packet.sequence, quint16(16082)); + QCOMPARE(packet.stamp, quint32(144)); + QCOMPARE(packet.ssrc, quint32(1606227614)); + QCOMPARE(packet.csrc, QList<quint32>()); + QCOMPARE(packet.payload, QByteArray("\x12\x34\x56", 3)); + QCOMPARE(packet.encode(), data); +} + +void tst_QXmppRtpPacket::testWithCsrc() +{ + QByteArray data("\x84\x00\x3e\xd2\x00\x00\x00\x90\x5f\xbd\x16\x9e\xab\xcd\xef\x01\xde\xad\xbe\xef\x12\x34\x56", 23); + QXmppRtpPacket packet; + QCOMPARE(packet.decode(data), true); + QCOMPARE(packet.version, quint8(2)); + QCOMPARE(packet.marker, false); + QCOMPARE(packet.type, quint8(0)); + QCOMPARE(packet.sequence, quint16(16082)); + QCOMPARE(packet.stamp, quint32(144)); + QCOMPARE(packet.ssrc, quint32(1606227614)); + qDebug() << packet.csrc; + QCOMPARE(packet.csrc, QList<quint32>() << quint32(0xabcdef01) << quint32(0xdeadbeef)); + QCOMPARE(packet.payload, QByteArray("\x12\x34\x56", 3)); + QCOMPARE(packet.encode(), data); +} + + diff --git a/tests/all/rtp.h b/tests/all/rtp.h new file mode 100644 index 00000000..479a1a87 --- /dev/null +++ b/tests/all/rtp.h @@ -0,0 +1,35 @@ +/* + * 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 <QObject> + +class tst_QXmppRtpPacket : public QObject +{ + Q_OBJECT + +private slots: + void testBad(); + void testSimple(); + void testWithCsrc(); +}; + diff --git a/tests/all/sasl.cpp b/tests/all/sasl.cpp new file mode 100644 index 00000000..b276ddcd --- /dev/null +++ b/tests/all/sasl.cpp @@ -0,0 +1,401 @@ +/* + * 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 "QXmppSasl_p.h" + +#include "sasl.h" +#include "util.h" + +void tst_QXmppSasl::testParsing() +{ + // empty + QMap<QByteArray, QByteArray> empty = QXmppSaslDigestMd5::parseMessage(QByteArray()); + QCOMPARE(empty.size(), 0); + QCOMPARE(QXmppSaslDigestMd5::serializeMessage(empty), QByteArray()); + + // non-empty + const QByteArray bytes("number=12345,quoted_plain=\"quoted string\",quoted_quote=\"quoted\\\\slash\\\"quote\",string=string"); + + QMap<QByteArray, QByteArray> map = QXmppSaslDigestMd5::parseMessage(bytes); + QCOMPARE(map.size(), 4); + QCOMPARE(map["number"], QByteArray("12345")); + QCOMPARE(map["quoted_plain"], QByteArray("quoted string")); + QCOMPARE(map["quoted_quote"], QByteArray("quoted\\slash\"quote")); + QCOMPARE(map["string"], QByteArray("string")); + QCOMPARE(QXmppSaslDigestMd5::serializeMessage(map), bytes); +} + +void tst_QXmppSasl::testAuth_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<QString>("mechanism"); + QTest::addColumn<QByteArray>("value"); + + QTest::newRow("plain") + << QByteArray("<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">AGZvbwBiYXI=</auth>") + << "PLAIN" << QByteArray("\0foo\0bar", 8); + + QTest::newRow("digest-md5") + << QByteArray("<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"DIGEST-MD5\"/>") + << "DIGEST-MD5" << QByteArray(); +} + +void tst_QXmppSasl::testAuth() +{ + QFETCH(QByteArray, xml); + QFETCH(QString, mechanism); + QFETCH(QByteArray, value); + + // no condition + QXmppSaslAuth auth; + parsePacket(auth, xml); + QCOMPARE(auth.mechanism(), mechanism); + QCOMPARE(auth.value(), value); + serializePacket(auth, xml); +} + +void tst_QXmppSasl::testChallenge_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<QByteArray>("value"); + + QTest::newRow("empty") + << QByteArray("<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>") + << QByteArray(); + + QTest::newRow("value") + << QByteArray("<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">AGZvbwBiYXI=</challenge>") + << QByteArray("\0foo\0bar", 8); +} + +void tst_QXmppSasl::testChallenge() +{ + QFETCH(QByteArray, xml); + QFETCH(QByteArray, value); + + // no condition + QXmppSaslChallenge challenge; + parsePacket(challenge, xml); + QCOMPARE(challenge.value(), value); + serializePacket(challenge, xml); +} + +void tst_QXmppSasl::testFailure() +{ + // no condition + const QByteArray xml = "<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>"; + QXmppSaslFailure failure; + parsePacket(failure, xml); + QCOMPARE(failure.condition(), QString()); + serializePacket(failure, xml); + + // not authorized + const QByteArray xml2 = "<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"><not-authorized/></failure>"; + QXmppSaslFailure failure2; + parsePacket(failure2, xml2); + QCOMPARE(failure2.condition(), QLatin1String("not-authorized")); + serializePacket(failure2, xml2); +} + +void tst_QXmppSasl::testResponse_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<QByteArray>("value"); + + QTest::newRow("empty") + << QByteArray("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>") + << QByteArray(); + + QTest::newRow("value") + << QByteArray("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">AGZvbwBiYXI=</response>") + << QByteArray("\0foo\0bar", 8); +} + +void tst_QXmppSasl::testResponse() +{ + QFETCH(QByteArray, xml); + QFETCH(QByteArray, value); + + // no condition + QXmppSaslResponse response; + parsePacket(response, xml); + QCOMPARE(response.value(), value); + serializePacket(response, xml); +} + +void tst_QXmppSasl::testSuccess() +{ + const QByteArray xml = "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>"; + QXmppSaslSuccess stanza; + parsePacket(stanza, xml); + serializePacket(stanza, xml); +} + +void tst_QXmppSaslClient::testAvailableMechanisms() +{ + QCOMPARE(QXmppSaslClient::availableMechanisms(), QStringList() << "PLAIN" << "DIGEST-MD5" << "ANONYMOUS" << "X-FACEBOOK-PLATFORM" << "X-MESSENGER-OAUTH2" << "X-OAUTH2"); +} + +void tst_QXmppSaslClient::testBadMechanism() +{ + QXmppSaslClient *client = QXmppSaslClient::create("BAD-MECH"); + QVERIFY(client == 0); +} + +void tst_QXmppSaslClient::testAnonymous() +{ + QXmppSaslClient *client = QXmppSaslClient::create("ANONYMOUS"); + QVERIFY(client != 0); + QCOMPARE(client->mechanism(), QLatin1String("ANONYMOUS")); + + // initial step returns nothing + QByteArray response; + QVERIFY(client->respond(QByteArray(), response)); + QCOMPARE(response, QByteArray()); + + // any further step is an error + QVERIFY(!client->respond(QByteArray(), response)); + + delete client; +} + +void tst_QXmppSaslClient::testDigestMd5_data() +{ + QTest::addColumn<QByteArray>("qop"); + QTest::newRow("qop-none") << QByteArray(); + QTest::newRow("qop-auth") << QByteArray(",qop=\"auth\""); + QTest::newRow("qop-multi") << QByteArray(",qop=\"auth,auth-int\""); +} + +void tst_QXmppSaslClient::testDigestMd5() +{ + QFETCH(QByteArray, qop); + + QXmppSaslDigestMd5::setNonce("AMzVG8Oibf+sVUCPPlWLR8lZQvbbJtJB9vJd+u3c6dw="); + + QXmppSaslClient *client = QXmppSaslClient::create("DIGEST-MD5"); + QVERIFY(client != 0); + QCOMPARE(client->mechanism(), QLatin1String("DIGEST-MD5")); + + client->setUsername("qxmpp1"); + client->setPassword("qxmpp123"); + client->setHost("jabber.ru"); + client->setServiceType("xmpp"); + + // initial step returns nothing + QByteArray response; + QVERIFY(client->respond(QByteArray(), response)); + QCOMPARE(response, QByteArray()); + + QVERIFY(client->respond(QByteArray("nonce=\"2530347127\"") + qop + QByteArray("charset=utf-8,algorithm=md5-sess"), response)); + QCOMPARE(response, QByteArray("charset=utf-8,cnonce=\"AMzVG8Oibf+sVUCPPlWLR8lZQvbbJtJB9vJd+u3c6dw=\",digest-uri=\"xmpp/jabber.ru\",nc=00000001,nonce=2530347127,qop=auth,response=a61fbf4320577d74038b71a8546bc7ae,username=qxmpp1")); + + QVERIFY(client->respond(QByteArray("rspauth=d92bf7f4331700c24799cbab364a14b7"), response)); + QCOMPARE(response, QByteArray()); + + // any further step is an error + QVERIFY(!client->respond(QByteArray(), response)); + + delete client; +} + +void tst_QXmppSaslClient::testFacebook() +{ + QXmppSaslClient *client = QXmppSaslClient::create("X-FACEBOOK-PLATFORM"); + QVERIFY(client != 0); + QCOMPARE(client->mechanism(), QLatin1String("X-FACEBOOK-PLATFORM")); + + client->setUsername("123456789012345"); + client->setPassword("abcdefghijlkmno"); + + // initial step returns nothing + QByteArray response; + QVERIFY(client->respond(QByteArray(), response)); + QCOMPARE(response, QByteArray()); + + // challenge response + QVERIFY(client->respond(QByteArray("version=1&method=auth.xmpp_login&nonce=AA4EFEE16F2AB64B131EEFFE6EACDDB8"), response)); + QCOMPARE(response, QByteArray("access_token=abcdefghijlkmno&api_key=123456789012345&call_id=&method=auth.xmpp_login&nonce=AA4EFEE16F2AB64B131EEFFE6EACDDB8&v=1.0")); + + // any further step is an error + QVERIFY(!client->respond(QByteArray(), response)); + + delete client; +} + +void tst_QXmppSaslClient::testGoogle() +{ + QXmppSaslClient *client = QXmppSaslClient::create("X-OAUTH2"); + QVERIFY(client != 0); + QCOMPARE(client->mechanism(), QLatin1String("X-OAUTH2")); + + client->setUsername("foo"); + client->setPassword("bar"); + + // initial step returns data + QByteArray response; + QVERIFY(client->respond(QByteArray(), response)); + QCOMPARE(response, QByteArray("\0foo\0bar", 8)); + + // any further step is an error + QVERIFY(!client->respond(QByteArray(), response)); + + delete client; +} + +void tst_QXmppSaslClient::testPlain() +{ + QXmppSaslClient *client = QXmppSaslClient::create("PLAIN"); + QVERIFY(client != 0); + QCOMPARE(client->mechanism(), QLatin1String("PLAIN")); + + client->setUsername("foo"); + client->setPassword("bar"); + + // initial step returns data + QByteArray response; + QVERIFY(client->respond(QByteArray(), response)); + QCOMPARE(response, QByteArray("\0foo\0bar", 8)); + + // any further step is an error + QVERIFY(!client->respond(QByteArray(), response)); + + delete client; +} + +void tst_QXmppSaslClient::testWindowsLive() +{ + QXmppSaslClient *client = QXmppSaslClient::create("X-MESSENGER-OAUTH2"); + QVERIFY(client != 0); + QCOMPARE(client->mechanism(), QLatin1String("X-MESSENGER-OAUTH2")); + + client->setPassword(QByteArray("footoken").toBase64()); + + // initial step returns data + QByteArray response; + QVERIFY(client->respond(QByteArray(), response)); + QCOMPARE(response, QByteArray("footoken", 8)); + + // any further step is an error + QVERIFY(!client->respond(QByteArray(), response)); + + delete client; +} + +void tst_QXmppSaslServer::testBadMechanism() +{ + QXmppSaslServer *server = QXmppSaslServer::create("BAD-MECH"); + QVERIFY(server == 0); +} + +void tst_QXmppSaslServer::testAnonymous() +{ + QXmppSaslServer *server = QXmppSaslServer::create("ANONYMOUS"); + QVERIFY(server != 0); + QCOMPARE(server->mechanism(), QLatin1String("ANONYMOUS")); + + // initial step returns success + QByteArray response; + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Succeeded); + QCOMPARE(response, QByteArray()); + + // any further step is an error + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Failed); + + delete server; +} + +void tst_QXmppSaslServer::testDigestMd5() +{ + QXmppSaslDigestMd5::setNonce("OI08/m+QRm6Ma+fKOjuqVXtz40sR5u9/u5GN6sSW0rs="); + + QXmppSaslServer *server = QXmppSaslServer::create("DIGEST-MD5"); + QVERIFY(server != 0); + QCOMPARE(server->mechanism(), QLatin1String("DIGEST-MD5")); + + // initial step returns challenge + QByteArray response; + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Challenge); + QCOMPARE(response, QByteArray("algorithm=md5-sess,charset=utf-8,nonce=\"OI08/m+QRm6Ma+fKOjuqVXtz40sR5u9/u5GN6sSW0rs=\",qop=auth")); + + // password needed + const QByteArray request = QByteArray("charset=utf-8,cnonce=\"AMzVG8Oibf+sVUCPPlWLR8lZQvbbJtJB9vJd+u3c6dw=\",digest-uri=\"xmpp/jabber.ru\",nc=00000001,nonce=\"OI08/m+QRm6Ma+fKOjuqVXtz40sR5u9/u5GN6sSW0rs=\",qop=auth,response=70e9063257ee2bf6bfd108975b917410,username=qxmpp1"); + QCOMPARE(server->respond(request, response), QXmppSaslServer::InputNeeded); + QCOMPARE(server->username(), QLatin1String("qxmpp1")); + server->setPassword("qxmpp123"); + + // second challenge + QCOMPARE(server->respond(request, response), QXmppSaslServer::Challenge); + QCOMPARE(response, QByteArray("rspauth=2821a3add271b9ae02b813bed57ec878")); + + // success + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Succeeded); + QCOMPARE(response, QByteArray()); + + // any further step is an error + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Failed); + + delete server; +} + +void tst_QXmppSaslServer::testPlain() +{ + QXmppSaslServer *server = QXmppSaslServer::create("PLAIN"); + QVERIFY(server != 0); + QCOMPARE(server->mechanism(), QLatin1String("PLAIN")); + + // initial step returns success + QByteArray response; + QCOMPARE(server->respond(QByteArray("\0foo\0bar", 8), response), QXmppSaslServer::InputNeeded); + QCOMPARE(response, QByteArray()); + QCOMPARE(server->username(), QLatin1String("foo")); + QCOMPARE(server->password(), QLatin1String("bar")); + + // any further step is an error + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Failed); + + delete server; +} + +void tst_QXmppSaslServer::testPlainChallenge() +{ + QXmppSaslServer *server = QXmppSaslServer::create("PLAIN"); + QVERIFY(server != 0); + QCOMPARE(server->mechanism(), QLatin1String("PLAIN")); + + // initial step returns challenge + QByteArray response; + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Challenge); + QCOMPARE(response, QByteArray()); + + // initial step returns success + QCOMPARE(server->respond(QByteArray("\0foo\0bar", 8), response), QXmppSaslServer::InputNeeded); + QCOMPARE(response, QByteArray()); + QCOMPARE(server->username(), QLatin1String("foo")); + QCOMPARE(server->password(), QLatin1String("bar")); + + // any further step is an error + QCOMPARE(server->respond(QByteArray(), response), QXmppSaslServer::Failed); + + delete server; +} diff --git a/tests/all/sasl.h b/tests/all/sasl.h new file mode 100644 index 00000000..f70ff9af --- /dev/null +++ b/tests/all/sasl.h @@ -0,0 +1,69 @@ +/* + * 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 <QObject> + +class tst_QXmppSasl : public QObject +{ + Q_OBJECT + +private slots: + void testParsing(); + void testAuth_data(); + void testAuth(); + void testChallenge_data(); + void testChallenge(); + void testFailure(); + void testResponse_data(); + void testResponse(); + void testSuccess(); +}; + +class tst_QXmppSaslClient : public QObject +{ + Q_OBJECT + +private slots: + void testAvailableMechanisms(); + void testBadMechanism(); + void testAnonymous(); + void testDigestMd5(); + void testDigestMd5_data(); + void testFacebook(); + void testGoogle(); + void testPlain(); + void testWindowsLive(); +}; + +class tst_QXmppSaslServer : public QObject +{ + Q_OBJECT + +private slots: + void testBadMechanism(); + void testAnonymous(); + void testDigestMd5(); + void testPlain(); + void testPlainChallenge(); +}; + diff --git a/tests/all/si.cpp b/tests/all/si.cpp new file mode 100644 index 00000000..cdfc4568 --- /dev/null +++ b/tests/all/si.cpp @@ -0,0 +1,126 @@ +/* + * 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 "QXmppStreamInitiationIq_p.h" +#include "QXmppTransferManager.h" + +#include "si.h" +#include "util.h" + +void tst_QXmppStreamInitiationIq::testFileInfo_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<QDateTime>("date"); + QTest::addColumn<QString>("description"); + QTest::addColumn<QByteArray>("hash"); + QTest::addColumn<QString>("name"); + QTest::addColumn<qint64>("size"); + + QTest::newRow("normal") + << QByteArray("<file xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\" name=\"test.txt\" size=\"1022\"/>") + << QDateTime() + << QString() + << QByteArray() + << QString("test.txt") + << qint64(1022); + + QTest::newRow("full") + << QByteArray("<file xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\" " + "date=\"1969-07-21T02:56:15Z\" " + "hash=\"552da749930852c69ae5d2141d3766b1\" " + "name=\"test.txt\" " + "size=\"1022\">" + "<desc>This is a test. If this were a real file...</desc>" + "</file>") + << QDateTime(QDate(1969, 7, 21), QTime(2, 56, 15), Qt::UTC) + << QString("This is a test. If this were a real file...") + << QByteArray::fromHex("552da749930852c69ae5d2141d3766b1") + << QString("test.txt") + << qint64(1022); +} + +void tst_QXmppStreamInitiationIq::testFileInfo() +{ + QFETCH(QByteArray, xml); + QFETCH(QDateTime, date); + QFETCH(QString, description); + QFETCH(QByteArray, hash); + QFETCH(QString, name); + QFETCH(qint64, size); + + QXmppTransferFileInfo info; + parsePacket(info, xml); + QCOMPARE(info.date(), date); + QCOMPARE(info.description(), description); + QCOMPARE(info.hash(), hash); + QCOMPARE(info.name(), name); + QCOMPARE(info.size(), size); + serializePacket(info, xml); +} + +void tst_QXmppStreamInitiationIq::testOffer() +{ + QByteArray xml( + "<iq id=\"offer1\" to=\"receiver@jabber.org/resource\" type=\"set\">" + "<si xmlns=\"http://jabber.org/protocol/si\" id=\"a0\" mime-type=\"text/plain\" profile=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<file xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\" name=\"test.txt\" size=\"1022\"/>" + "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">" + "<x xmlns=\"jabber:x:data\" type=\"form\">" + "<field type=\"list-single\" var=\"stream-method\">" + "<option><value>http://jabber.org/protocol/bytestreams</value></option>" + "<option><value>http://jabber.org/protocol/ibb</value></option>" + "</field>" + "</x>" + "</feature>" + "</si>" + "</iq>"); + + QXmppStreamInitiationIq iq; + parsePacket(iq, xml); + QVERIFY(!iq.fileInfo().isNull()); + QCOMPARE(iq.fileInfo().name(), QString("test.txt")); + QCOMPARE(iq.fileInfo().size(), qint64(1022)); + serializePacket(iq, xml); +} + +void tst_QXmppStreamInitiationIq::testResult() +{ + QByteArray xml( + "<iq id=\"offer1\" to=\"sender@jabber.org/resource\" type=\"result\">" + "<si xmlns=\"http://jabber.org/protocol/si\">" + "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">" + "<x xmlns=\"jabber:x:data\" type=\"submit\">" + "<field type=\"list-single\" var=\"stream-method\">" + "<value>http://jabber.org/protocol/bytestreams</value>" + "</field>" + "</x>" + "</feature>" + "</si>" + "</iq>"); + + QXmppStreamInitiationIq iq; + parsePacket(iq, xml); + QVERIFY(iq.fileInfo().isNull()); + serializePacket(iq, xml); +} diff --git a/tests/all/si.h b/tests/all/si.h new file mode 100644 index 00000000..97e325b8 --- /dev/null +++ b/tests/all/si.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_QXmppStreamInitiationIq : public QObject +{ + Q_OBJECT + +private slots: + void testFileInfo_data(); + void testFileInfo(); + void testOffer(); + void testResult(); +}; + diff --git a/tests/all/stanza.cpp b/tests/all/stanza.cpp new file mode 100644 index 00000000..f1de73a4 --- /dev/null +++ b/tests/all/stanza.cpp @@ -0,0 +1,67 @@ +/* + * 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 "QXmppStanza.h" + +#include "stanza.h" +#include "util.h" + +void tst_QXmppStanza::testExtendedAddress_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<bool>("delivered"); + QTest::addColumn<QString>("description"); + QTest::addColumn<QString>("jid"); + QTest::addColumn<QString>("type"); + + QTest::newRow("simple") + << QByteArray("<address jid=\"foo@example.com/QXmpp\" type=\"bcc\"/>") + << false + << QString() + << QString("foo@example.com/QXmpp") + << QString("bcc"); + + QTest::newRow("full") + << QByteArray("<address delivered=\"true\" desc=\"some description\" jid=\"foo@example.com/QXmpp\" type=\"bcc\"/>") + << true + << QString("some description") + << QString("foo@example.com/QXmpp") + << QString("bcc"); +} + +void tst_QXmppStanza::testExtendedAddress() +{ + QFETCH(QByteArray, xml); + QFETCH(bool, delivered); + QFETCH(QString, description); + QFETCH(QString, jid); + QFETCH(QString, type); + + QXmppExtendedAddress address; + parsePacket(address, xml); + QCOMPARE(address.isDelivered(), delivered); + QCOMPARE(address.description(), description); + QCOMPARE(address.jid(), jid); + QCOMPARE(address.type(), type); + serializePacket(address, xml); +} diff --git a/tests/all/stanza.h b/tests/all/stanza.h new file mode 100644 index 00000000..8bd57d90 --- /dev/null +++ b/tests/all/stanza.h @@ -0,0 +1,34 @@ +/* + * 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 <QObject> + +class tst_QXmppStanza : public QObject +{ + Q_OBJECT + +private slots: + void testExtendedAddress_data(); + void testExtendedAddress(); +}; + diff --git a/tests/all/stun.cpp b/tests/all/stun.cpp new file mode 100644 index 00000000..8fa09d7f --- /dev/null +++ b/tests/all/stun.cpp @@ -0,0 +1,120 @@ +/* + * 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 "QXmppStun.h" + +#include "stun.h" +#include "util.h" + +void TestStun::testFingerprint() +{ + // without fingerprint + QXmppStunMessage msg; + msg.setType(0x0001); + QCOMPARE(msg.encode(QByteArray(), false), + QByteArray("\x00\x01\x00\x00\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 20)); + + // with fingerprint + QCOMPARE(msg.encode(QByteArray(), true), + QByteArray("\x00\x01\x00\x08\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x28\x00\x04\xB2\xAA\xF9\xF6", 28)); +} + +void TestStun::testIntegrity() +{ + QXmppStunMessage msg; + msg.setType(0x0001); + QCOMPARE(msg.encode(QByteArray("somesecret"), false), + QByteArray("\x00\x01\x00\x18\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x14\x96\x4B\x40\xD1\x84\x67\x6A\xFD\xB5\xE0\x7C\xC5\x1F\xFB\xBD\xA2\x61\xAF\xB1\x26", 44)); +} + +void TestStun::testIPv4Address() +{ + // encode + QXmppStunMessage msg; + msg.setType(0x0001); + msg.mappedHost = QHostAddress("127.0.0.1"); + msg.mappedPort = 12345; + QByteArray packet = msg.encode(QByteArray(), false); + QCOMPARE(packet, + QByteArray("\x00\x01\x00\x0C\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x08\x00\x01\x30\x39\x7F\x00\x00\x01", 32)); + + // decode + QXmppStunMessage msg2; + msg2.decode(packet); + QCOMPARE(msg2.mappedHost, QHostAddress("127.0.0.1")); + QCOMPARE(msg2.mappedPort, quint16(12345)); +} + +void TestStun::testIPv6Address() +{ + // encode + QXmppStunMessage msg; + msg.setType(0x0001); + msg.mappedHost = QHostAddress("::1"); + msg.mappedPort = 12345; + const QByteArray packet = msg.encode(QByteArray(), false); + QCOMPARE(packet, + QByteArray("\x00\x01\x00\x18\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x14\x00\x02\x30\x39\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 44)); + + // decode + QXmppStunMessage msg2; + msg2.decode(packet); + QCOMPARE(msg2.mappedHost, QHostAddress("::1")); + QCOMPARE(msg2.mappedPort, quint16(12345)); +} + +void TestStun::testXorIPv4Address() +{ + // encode + QXmppStunMessage msg; + msg.setType(0x0001); + msg.xorMappedHost = QHostAddress("127.0.0.1"); + msg.xorMappedPort = 12345; + QByteArray packet = msg.encode(QByteArray(), false); + QCOMPARE(packet, + QByteArray("\x00\x01\x00\x0C\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x08\x00\x01\x11\x2B\x5E\x12\xA4\x43", 32)); + + // decode + QXmppStunMessage msg2; + msg2.decode(packet); + QCOMPARE(msg2.xorMappedHost, QHostAddress("127.0.0.1")); + QCOMPARE(msg2.xorMappedPort, quint16(12345)); +} + +void TestStun::testXorIPv6Address() +{ + // encode + QXmppStunMessage msg; + msg.setType(0x0001); + msg.xorMappedHost = QHostAddress("::1"); + msg.xorMappedPort = 12345; + const QByteArray packet = msg.encode(QByteArray(), false); + QCOMPARE(packet, + QByteArray("\x00\x01\x00\x18\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x14\x00\x02\x11\x2B\x21\x12\xA4\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 44)); + + // decode + QXmppStunMessage msg2; + msg2.decode(packet); + QCOMPARE(msg2.xorMappedHost, QHostAddress("::1")); + QCOMPARE(msg2.xorMappedPort, quint16(12345)); +} diff --git a/tests/all/stun.h b/tests/all/stun.h new file mode 100644 index 00000000..1b0141d2 --- /dev/null +++ b/tests/all/stun.h @@ -0,0 +1,37 @@ +/* + * 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 <QObject> + +class TestStun : public QObject +{ + Q_OBJECT + +private slots: + void testFingerprint(); + void testIntegrity(); + void testIPv4Address(); + void testIPv6Address(); + void testXorIPv4Address(); + void testXorIPv6Address(); +}; diff --git a/tests/all/test.bmp b/tests/all/test.bmp Binary files differnew file mode 100644 index 00000000..de301a62 --- /dev/null +++ b/tests/all/test.bmp diff --git a/tests/all/test.gif b/tests/all/test.gif Binary files differnew file mode 100644 index 00000000..f39871a0 --- /dev/null +++ b/tests/all/test.gif diff --git a/tests/all/test.jpg b/tests/all/test.jpg Binary files differnew file mode 100644 index 00000000..684693b6 --- /dev/null +++ b/tests/all/test.jpg diff --git a/tests/all/test.mng b/tests/all/test.mng Binary files differnew file mode 100644 index 00000000..454977da --- /dev/null +++ b/tests/all/test.mng diff --git a/tests/all/test.png b/tests/all/test.png Binary files differnew file mode 100644 index 00000000..372cf93f --- /dev/null +++ b/tests/all/test.png diff --git a/tests/all/test.svg b/tests/all/test.svg new file mode 100644 index 00000000..b2838872 --- /dev/null +++ b/tests/all/test.svg @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg3056" + version="1.1" + inkscape:version="0.47 r22583" + width="6" + height="6" + sodipodi:docname="test.svg"> + <metadata + id="metadata3062"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs3060"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + id="perspective3064" /> + </defs> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="920" + inkscape:window-height="678" + id="namedview3058" + showgrid="true" + inkscape:snap-global="true" + inkscape:zoom="41.333333" + inkscape:cx="3" + inkscape:cy="3" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="0" + inkscape:current-layer="svg3056"> + <inkscape:grid + type="xygrid" + id="grid3072" /> + </sodipodi:namedview> + <rect + style="fill:#00ff00;fill-opacity:1;stroke:none" + id="rect3074" + height="6" + x="2" + y="0" + width="2" /> + <rect + width="2" + y="0" + x="0" + height="6" + id="rect3848" + style="fill:#ff0000;fill-opacity:1;stroke:none" /> + <rect + width="2" + y="0" + x="4" + height="6" + id="rect3850" + style="fill:#0000ff;fill-opacity:1;stroke:none" /> +</svg> diff --git a/tests/all/test.xpm b/tests/all/test.xpm new file mode 100644 index 00000000..ef56e2c6 --- /dev/null +++ b/tests/all/test.xpm @@ -0,0 +1,12 @@ +/* XPM */ +static char * test_xpm[] = { +"6 6 3 1", +" c #FF0000", +". c #00FF00", +"+ c #0000FF", +" ..++", +" ..++", +" ..++", +" ..++", +" ..++", +" ..++"}; diff --git a/tests/all/tests.cpp b/tests/all/tests.cpp new file mode 100644 index 00000000..2406813e --- /dev/null +++ b/tests/all/tests.cpp @@ -0,0 +1,967 @@ +/* + * 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 <cstdlib> + +#include <QCoreApplication> +#include <QDomDocument> +#include <QEventLoop> +#include <QtTest/QtTest> + +#include "QXmppArchiveIq.h" +#include "QXmppBindIq.h" +#include "QXmppClient.h" +#include "QXmppDiscoveryIq.h" +#include "QXmppNonSASLAuth.h" +#include "QXmppPasswordChecker.h" +#include "QXmppPubSubIq.h" +#include "QXmppSessionIq.h" +#include "QXmppServer.h" +#include "QXmppStreamFeatures.h" +#include "QXmppUtils.h" +#include "QXmppVersionIq.h" +#include "QXmppGlobal.h" +#include "QXmppEntityTimeIq.h" + +#include "codec.h" +#include "dataform.h" +#include "iq.h" +#include "jingle.h" +#include "message.h" +#include "presence.h" +#include "register.h" +#include "roster.h" +#include "rpc.h" +#include "rsm.h" +#include "rtp.h" +#include "sasl.h" +#include "si.h" +#include "stanza.h" +#include "stun.h" +#include "tests.h" +#include "util.h" +#include "vcard.h" + +void TestUtils::testCrc32() +{ + quint32 crc = QXmppUtils::generateCrc32(QByteArray()); + QCOMPARE(crc, 0u); + + crc = QXmppUtils::generateCrc32(QByteArray("Hi There")); + QCOMPARE(crc, 0xDB143BBEu); +} + +void TestUtils::testHmac() +{ + QByteArray hmac = QXmppUtils::generateHmacMd5(QByteArray(16, 0x0b), QByteArray("Hi There")); + QCOMPARE(hmac, QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d")); + + hmac = QXmppUtils::generateHmacMd5(QByteArray("Jefe"), QByteArray("what do ya want for nothing?")); + QCOMPARE(hmac, QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738")); + + hmac = QXmppUtils::generateHmacMd5(QByteArray(16, 0xaa), QByteArray(50, 0xdd)); + QCOMPARE(hmac, QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6")); +} + +void TestUtils::testJid() +{ + QCOMPARE(QXmppUtils::jidToBareJid("foo@example.com/resource"), QLatin1String("foo@example.com")); + QCOMPARE(QXmppUtils::jidToBareJid("foo@example.com"), QLatin1String("foo@example.com")); + QCOMPARE(QXmppUtils::jidToBareJid("example.com"), QLatin1String("example.com")); + QCOMPARE(QXmppUtils::jidToBareJid(QString()), QString()); + + QCOMPARE(QXmppUtils::jidToDomain("foo@example.com/resource"), QLatin1String("example.com")); + QCOMPARE(QXmppUtils::jidToDomain("foo@example.com"), QLatin1String("example.com")); + QCOMPARE(QXmppUtils::jidToDomain("example.com"), QLatin1String("example.com")); + QCOMPARE(QXmppUtils::jidToDomain(QString()), QString()); + + QCOMPARE(QXmppUtils::jidToResource("foo@example.com/resource"), QLatin1String("resource")); + QCOMPARE(QXmppUtils::jidToResource("foo@example.com"), QString()); + QCOMPARE(QXmppUtils::jidToResource("example.com"), QString()); + QCOMPARE(QXmppUtils::jidToResource(QString()), QString()); + + QCOMPARE(QXmppUtils::jidToUser("foo@example.com/resource"), QLatin1String("foo")); + QCOMPARE(QXmppUtils::jidToUser("foo@example.com"), QLatin1String("foo")); + QCOMPARE(QXmppUtils::jidToUser("example.com"), QString()); + QCOMPARE(QXmppUtils::jidToUser(QString()), QString()); +} + +// FIXME: how should we test MIME detection without expose getImageType? +#if 0 +QString getImageType(const QByteArray &contents); + +static void testMimeType(const QString &fileName, const QString fileType) +{ + // load file from resources + QFile file(":/" + fileName); + QCOMPARE(file.open(QIODevice::ReadOnly), true); + QCOMPARE(getImageType(file.readAll()), fileType); + file.close(); +} + +void TestUtils::testMime() +{ + testMimeType("test.bmp", "image/bmp"); + testMimeType("test.gif", "image/gif"); + testMimeType("test.jpg", "image/jpeg"); + testMimeType("test.mng", "video/x-mng"); + testMimeType("test.png", "image/png"); + testMimeType("test.svg", "image/svg+xml"); + testMimeType("test.xpm", "image/x-xpm"); +} +#else +void TestUtils::testMime() +{ +} +#endif + +void TestUtils::testLibVersion() +{ + QCOMPARE(QXmppVersion(), QString("0.7.3")); +} + +void TestUtils::testTimezoneOffset() +{ + // parsing + QCOMPARE(QXmppUtils::timezoneOffsetFromString("Z"), 0); + QCOMPARE(QXmppUtils::timezoneOffsetFromString("+00:00"), 0); + QCOMPARE(QXmppUtils::timezoneOffsetFromString("-00:00"), 0); + QCOMPARE(QXmppUtils::timezoneOffsetFromString("+01:30"), 5400); + QCOMPARE(QXmppUtils::timezoneOffsetFromString("-01:30"), -5400); + + // serialization + QCOMPARE(QXmppUtils::timezoneOffsetToString(0), QLatin1String("Z")); + QCOMPARE(QXmppUtils::timezoneOffsetToString(5400), QLatin1String("+01:30")); + QCOMPARE(QXmppUtils::timezoneOffsetToString(-5400), QLatin1String("-01:30")); +} + +void TestPackets::testArchiveList_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("max"); + + QTest::newRow("no rsm") << + QByteArray( + "<iq id=\"list_1\" type=\"get\">" + "<list xmlns=\"urn:xmpp:archive\" with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:00:00Z\" end=\"1479-07-21T04:00:00Z\"/>" + "</iq>") << -1; + + QTest::newRow("with rsm") << + QByteArray( + "<iq id=\"list_1\" type=\"get\">" + "<list xmlns=\"urn:xmpp:archive\" with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:00:00Z\" end=\"1479-07-21T04:00:00Z\">" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>30</max>" + "</set>" + "</list>" + "</iq>") << 30; +} + +void TestPackets::testArchiveList() +{ + QFETCH(QByteArray, xml); + QFETCH(int, max); + + QXmppArchiveListIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.type(), QXmppIq::Get); + QCOMPARE(iq.id(), QLatin1String("list_1")); + QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com")); + QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC)); + QCOMPARE(iq.end(), QDateTime(QDate(1479, 7, 21), QTime(4, 0, 0), Qt::UTC)); + QCOMPARE(iq.resultSetQuery().max(), max); + serializePacket(iq, xml); +} + +void TestPackets::testArchiveChat_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("count"); + + QTest::newRow("no rsm") << + QByteArray( + "<iq id=\"chat_1\" type=\"result\">" + "<chat xmlns=\"urn:xmpp:archive\"" + " with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:56:15Z\"" + " subject=\"She speaks!\"" + " version=\"4\"" + ">" + "<from secs=\"0\"><body>Art thou not Romeo, and a Montague?</body></from>" + "<to secs=\"11\"><body>Neither, fair saint, if either thee dislike.</body></to>" + "<from secs=\"7\"><body>How cam'st thou hither, tell me, and wherefore?</body></from>" + "</chat>" + "</iq>") << -1; + + QTest::newRow("with rsm") << + QByteArray( + "<iq id=\"chat_1\" type=\"result\">" + "<chat xmlns=\"urn:xmpp:archive\"" + " with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:56:15Z\"" + " subject=\"She speaks!\"" + " version=\"4\"" + ">" + "<from secs=\"0\"><body>Art thou not Romeo, and a Montague?</body></from>" + "<to secs=\"11\"><body>Neither, fair saint, if either thee dislike.</body></to>" + "<from secs=\"7\"><body>How cam'st thou hither, tell me, and wherefore?</body></from>" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<count>3</count>" + "</set>" + "</chat>" + "</iq>") << 3; +} + +void TestPackets::testArchiveChat() +{ + QFETCH(QByteArray, xml); + QFETCH(int, count); + + QXmppArchiveChatIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.type(), QXmppIq::Result); + QCOMPARE(iq.id(), QLatin1String("chat_1")); + QCOMPARE(iq.chat().with(), QLatin1String("juliet@capulet.com")); + QCOMPARE(iq.chat().messages().size(), 3); + QCOMPARE(iq.chat().messages()[0].isReceived(), true); + QCOMPARE(iq.chat().messages()[0].body(), QLatin1String("Art thou not Romeo, and a Montague?")); + QCOMPARE(iq.chat().messages()[0].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 15), Qt::UTC)); + QCOMPARE(iq.chat().messages()[1].isReceived(), false); + QCOMPARE(iq.chat().messages()[1].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 26), Qt::UTC)); + QCOMPARE(iq.chat().messages()[1].body(), QLatin1String("Neither, fair saint, if either thee dislike.")); + QCOMPARE(iq.chat().messages()[2].isReceived(), true); + QCOMPARE(iq.chat().messages()[2].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 33), Qt::UTC)); + QCOMPARE(iq.chat().messages()[2].body(), QLatin1String("How cam'st thou hither, tell me, and wherefore?")); + QCOMPARE(iq.resultSetReply().count(), count); + serializePacket(iq, xml); +} + +void TestPackets::testArchiveRemove() +{ + const QByteArray xml( + "<iq id=\"remove_1\" type=\"set\">" + "<remove xmlns=\"urn:xmpp:archive\" with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:00:00Z\" end=\"1479-07-21T04:00:00Z\"/>" + "</iq>"); + + QXmppArchiveRemoveIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.type(), QXmppIq::Set); + QCOMPARE(iq.id(), QLatin1String("remove_1")); + QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com")); + QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC)); + QCOMPARE(iq.end(), QDateTime(QDate(1479, 7, 21), QTime(4, 0, 0), Qt::UTC)); + serializePacket(iq, xml); +} + +void TestPackets::testArchiveRetrieve_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("max"); + + QTest::newRow("no rsm") << + QByteArray( + "<iq id=\"retrieve_1\" type=\"get\">" + "<retrieve xmlns=\"urn:xmpp:archive\" with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:00:00Z\"/>" + "</iq>") << -1; + + QTest::newRow("with rsm") << + QByteArray( + "<iq id=\"retrieve_1\" type=\"get\">" + "<retrieve xmlns=\"urn:xmpp:archive\" with=\"juliet@capulet.com\"" + " start=\"1469-07-21T02:00:00Z\">" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>30</max>" + "</set>" + "</retrieve>" + "</iq>") << 30; +} + +void TestPackets::testArchiveRetrieve() +{ + QFETCH(QByteArray, xml); + QFETCH(int, max); + + QXmppArchiveRetrieveIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.type(), QXmppIq::Get); + QCOMPARE(iq.id(), QLatin1String("retrieve_1")); + QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com")); + QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC)); + QCOMPARE(iq.resultSetQuery().max(), max); + serializePacket(iq, xml); +} + +void TestPackets::testBindNoResource() +{ + const QByteArray xml( + "<iq id=\"bind_1\" type=\"set\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" + "</iq>"); + + QXmppBindIq 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>"); + + QXmppBindIq 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>"); + + QXmppBindIq 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::testDiscovery() +{ + const QByteArray xml( + "<iq id=\"disco1\" from=\"benvolio@capulet.lit/230193\" type=\"result\">" + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<identity category=\"client\" name=\"Exodus 0.9.1\" type=\"pc\"/>" + "<feature var=\"http://jabber.org/protocol/caps\"/>" + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + "<feature var=\"http://jabber.org/protocol/disco#items\"/>" + "<feature var=\"http://jabber.org/protocol/muc\"/>" + "</query>" + "</iq>"); + + QXmppDiscoveryIq disco; + parsePacket(disco, xml); + QCOMPARE(disco.verificationString(), QByteArray::fromBase64("QgayPKawpkPSDYmwT/WM94uAlu0=")); + serializePacket(disco, xml); +} + +void TestPackets::testDiscoveryWithForm() +{ + const QByteArray xml( + "<iq id=\"disco1\" to=\"juliet@capulet.lit/chamber\" from=\"benvolio@capulet.lit/230193\" type=\"result\">" + "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w=\">" + "<identity xml:lang=\"en\" category=\"client\" name=\"Psi 0.11\" type=\"pc\"/>" + "<identity xml:lang=\"el\" category=\"client\" name=\"Ψ 0.11\" type=\"pc\"/>" + "<feature var=\"http://jabber.org/protocol/caps\"/>" + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + "<feature var=\"http://jabber.org/protocol/disco#items\"/>" + "<feature var=\"http://jabber.org/protocol/muc\"/>" + "<x xmlns=\"jabber:x:data\" type=\"result\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>urn:xmpp:dataforms:softwareinfo</value>" + "</field>" + "<field type=\"text-multi\" var=\"ip_version\">" + "<value>ipv4</value>" + "<value>ipv6</value>" + "</field>" + "<field type=\"text-single\" var=\"os\">" + "<value>Mac</value>" + "</field>" + "<field type=\"text-single\" var=\"os_version\">" + "<value>10.5.1</value>" + "</field>" + "<field type=\"text-single\" var=\"software\">" + "<value>Psi</value>" + "</field>" + "<field type=\"text-single\" var=\"software_version\">" + "<value>0.11</value>" + "</field>" + "</x>" + "</query>" + "</iq>"); + + QXmppDiscoveryIq disco; + parsePacket(disco, xml); + QCOMPARE(disco.verificationString(), QByteArray::fromBase64("q07IKJEyjvHSyhy//CH0CxmKi8w=")); + serializePacket(disco, xml); +} + +void TestPackets::testNonSaslAuth() +{ + // Client Requests Authentication Fields from Server + const QByteArray xml1( + "<iq id=\"auth1\" to=\"shakespeare.lit\" type=\"get\">" + "<query xmlns=\"jabber:iq:auth\"/>" + "</iq>"); + + QXmppNonSASLAuthIq iq1; + parsePacket(iq1, xml1); + serializePacket(iq1, xml1); + + // Client Provides Required Information (Plaintext) + const QByteArray xml3( + "<iq id=\"auth2\" type=\"set\">" + "<query xmlns=\"jabber:iq:auth\">" + "<username>bill</username>" + "<password>Calli0pe</password>" + "<resource>globe</resource>" + "</query>" + "</iq>"); + QXmppNonSASLAuthIq iq3; + parsePacket(iq3, xml3); + QCOMPARE(iq3.username(), QLatin1String("bill")); + QCOMPARE(iq3.digest(), QByteArray()); + QCOMPARE(iq3.password(), QLatin1String("Calli0pe")); + QCOMPARE(iq3.resource(), QLatin1String("globe")); + serializePacket(iq3, xml3); + + // Client Provides Required Information (Plaintext) + const QByteArray xml4( + "<iq id=\"auth2\" type=\"set\">" + "<query xmlns=\"jabber:iq:auth\">" + "<username>bill</username>" + "<digest>48fc78be9ec8f86d8ce1c39c320c97c21d62334d</digest>" + "<resource>globe</resource>" + "</query>" + "</iq>"); + QXmppNonSASLAuthIq iq4; + parsePacket(iq4, xml4); + QCOMPARE(iq4.username(), QLatin1String("bill")); + QCOMPARE(iq4.digest(), QByteArray("\x48\xfc\x78\xbe\x9e\xc8\xf8\x6d\x8c\xe1\xc3\x9c\x32\x0c\x97\xc2\x1d\x62\x33\x4d")); + QCOMPARE(iq4.password(), QString()); + QCOMPARE(iq4.resource(), QLatin1String("globe")); + serializePacket(iq4, xml4); +} + +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>"); + + QXmppSessionIq session; + parsePacket(session, xml); + QCOMPARE(session.id(), QString("session_1")); + QCOMPARE(session.to(), QString("example.com")); + QCOMPARE(session.type(), QXmppIq::Set); + serializePacket(session, xml); +} + +void TestPackets::testStreamFeatures() +{ + const QByteArray xml("<stream:features/>"); + QXmppStreamFeatures features; + parsePacket(features, xml); + QCOMPARE(features.bindMode(), QXmppStreamFeatures::Disabled); + QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Disabled); + QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Disabled); + QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Disabled); + QCOMPARE(features.authMechanisms(), QStringList()); + QCOMPARE(features.compressionMethods(), QStringList()); + serializePacket(features, xml); + + const QByteArray xml2("<stream:features>" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" + "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" + "<auth xmlns=\"http://jabber.org/features/iq-auth\"/>" + "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" + "<compression xmlns=\"http://jabber.org/features/compress\"><method>zlib</method></compression>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"><mechanism>PLAIN</mechanism></mechanisms>" + "</stream:features>"); + QXmppStreamFeatures features2; + parsePacket(features2, xml2); + QCOMPARE(features2.bindMode(), QXmppStreamFeatures::Enabled); + QCOMPARE(features2.sessionMode(), QXmppStreamFeatures::Enabled); + QCOMPARE(features2.nonSaslAuthMode(), QXmppStreamFeatures::Enabled); + QCOMPARE(features2.tlsMode(), QXmppStreamFeatures::Enabled); + QCOMPARE(features2.authMechanisms(), QStringList() << "PLAIN"); + QCOMPARE(features2.compressionMethods(), QStringList() << "zlib"); + serializePacket(features2, xml2); +} + +void TestPackets::testVersionGet() +{ + const QByteArray xmlGet( + "<iq id=\"version_1\" to=\"juliet@capulet.com/balcony\" " + "from=\"romeo@montague.net/orchard\" type=\"get\">" + "<query xmlns=\"jabber:iq:version\"/></iq>"); + + QXmppVersionIq verIqGet; + parsePacket(verIqGet, xmlGet); + QCOMPARE(verIqGet.id(), QLatin1String("version_1")); + QCOMPARE(verIqGet.to(), QLatin1String("juliet@capulet.com/balcony")); + QCOMPARE(verIqGet.from(), QLatin1String("romeo@montague.net/orchard")); + QCOMPARE(verIqGet.type(), QXmppIq::Get); + serializePacket(verIqGet, xmlGet); +} + +void TestPackets::testVersionResult() +{ + const QByteArray xmlResult( + "<iq id=\"version_1\" to=\"romeo@montague.net/orchard\" " + "from=\"juliet@capulet.com/balcony\" type=\"result\">" + "<query xmlns=\"jabber:iq:version\">" + "<name>qxmpp</name>" + "<os>Windows-XP</os>" + "<version>0.2.0</version>" + "</query></iq>"); + + QXmppVersionIq verIqResult; + parsePacket(verIqResult, xmlResult); + QCOMPARE(verIqResult.id(), QLatin1String("version_1")); + QCOMPARE(verIqResult.to(), QLatin1String("romeo@montague.net/orchard")); + QCOMPARE(verIqResult.from(), QLatin1String("juliet@capulet.com/balcony")); + QCOMPARE(verIqResult.type(), QXmppIq::Result); + QCOMPARE(verIqResult.name(), QString("qxmpp")); + QCOMPARE(verIqResult.version(), QString("0.2.0")); + QCOMPARE(verIqResult.os(), QString("Windows-XP")); + + serializePacket(verIqResult, xmlResult); +} + +void TestPackets::testEntityTimeGet() +{ + const QByteArray xml("<iq id=\"time_1\" " + "to=\"juliet@capulet.com/balcony\" " + "from=\"romeo@montague.net/orchard\" type=\"get\">" + "<time xmlns=\"urn:xmpp:time\"/>" + "</iq>"); + + QXmppEntityTimeIq entityTime; + parsePacket(entityTime, xml); + QCOMPARE(entityTime.id(), QLatin1String("time_1")); + QCOMPARE(entityTime.to(), QLatin1String("juliet@capulet.com/balcony")); + QCOMPARE(entityTime.from(), QLatin1String("romeo@montague.net/orchard")); + QCOMPARE(entityTime.type(), QXmppIq::Get); + serializePacket(entityTime, xml); +} + +void TestPackets::testEntityTimeResult() +{ + const QByteArray xml( + "<iq id=\"time_1\" to=\"romeo@montague.net/orchard\" from=\"juliet@capulet.com/balcony\" type=\"result\">" + "<time xmlns=\"urn:xmpp:time\">" + "<tzo>-06:00</tzo>" + "<utc>2006-12-19T17:58:35Z</utc>" + "</time>" + "</iq>"); + + QXmppEntityTimeIq entityTime; + parsePacket(entityTime, xml); + QCOMPARE(entityTime.id(), QLatin1String("time_1")); + QCOMPARE(entityTime.from(), QLatin1String("juliet@capulet.com/balcony")); + QCOMPARE(entityTime.to(), QLatin1String("romeo@montague.net/orchard")); + QCOMPARE(entityTime.type(), QXmppIq::Result); + QCOMPARE(entityTime.tzo(), -21600); + QCOMPARE(entityTime.utc(), QDateTime(QDate(2006, 12, 19), QTime(17, 58, 35), Qt::UTC)); + serializePacket(entityTime, xml); +} + +void TestPubSub::testItems() +{ + const QByteArray xml( + "<iq" + " id=\"items1\"" + " to=\"pubsub.shakespeare.lit\"" + " from=\"francisco@denmark.lit/barracks\"" + " type=\"get\">" + "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" + "<items node=\"storage:bookmarks\"/>" + "</pubsub>" + "</iq>"); + + 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( + "<iq" + " id=\"items1\"" + " to=\"francisco@denmark.lit/barracks\"" + " from=\"pubsub.shakespeare.lit\"" + " type=\"result\">" + "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" + "<items node=\"storage:bookmarks\">" + "<item id=\"current\">" + "<storage xmlns=\"storage:bookmarks\">" + "<conference" + " autojoin=\"true\"" + " jid=\"theplay@conference.shakespeare.lit\"" + " name=\"The Play's the Thing\">" + "<nick>JC</nick>" + "</conference>" + "</storage>" + "</item>" + "</items>" + "</pubsub>" + "</iq>"); + + 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( + "<iq" + " id=\"items1\"" + " to=\"pubsub.shakespeare.lit\"" + " from=\"francisco@denmark.lit/barracks\"" + " type=\"result\">" + "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" + "<publish node=\"storage:bookmarks\">" + "<item id=\"current\">" + "<storage xmlns=\"storage:bookmarks\">" + "<conference" + " autojoin=\"true\"" + " jid=\"theplay@conference.shakespeare.lit\"" + " name=\"The Play's the Thing\">" + "<nick>JC</nick>" + "</conference>" + "</storage>" + "</item>" + "</publish>" + "</pubsub>" + "</iq>"); + + 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( + "<iq" + " id=\"sub1\"" + " to=\"pubsub.shakespeare.lit\"" + " from=\"francisco@denmark.lit/barracks\"" + " type=\"set\">" + "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" + "<subscribe jid=\"francisco@denmark.lit\" node=\"princely_musings\"/>" + "</pubsub>" + "</iq>"); + + 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( + "<iq" + " id=\"sub1\"" + " to=\"francisco@denmark.lit/barracks\"" + " from=\"pubsub.shakespeare.lit\"" + " type=\"result\">" + "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" + "<subscription jid=\"francisco@denmark.lit\"" + " node=\"princely_musings\"" + " subid=\"ba49252aaa4f5d320c24d3766f0bdcade78c78d3\"" + " subscription=\"subscribed\"/>" + "</pubsub>" + "</iq>"); + + 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( + "<iq" + " id=\"subscriptions1\"" + " to=\"pubsub.shakespeare.lit\"" + " from=\"francisco@denmark.lit/barracks\"" + " type=\"get\">" + "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" + "<subscriptions/>" + "</pubsub>" + "</iq>"); + + 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); +} + +class TestPasswordChecker : public QXmppPasswordChecker +{ +public: + TestPasswordChecker(const QString &username, const QString &password) + : m_getPassword(true), m_username(username), m_password(password) + { + }; + + /// Retrieves the password for the given username. + QXmppPasswordReply::Error getPassword(const QXmppPasswordRequest &request, QString &password) + { + if (request.username() == m_username) + { + password = m_password; + return QXmppPasswordReply::NoError; + } else { + return QXmppPasswordReply::AuthorizationError; + } + }; + + /// Sets whether getPassword() is enabled. + void setGetPassword(bool getPassword) + { + m_getPassword = getPassword; + } + + /// Returns whether getPassword() is enabled. + bool hasGetPassword() const + { + return m_getPassword; + }; + +private: + bool m_getPassword; + QString m_username; + QString m_password; +}; + +void TestServer::testConnect_data() +{ + QTest::addColumn<QString>("username"); + QTest::addColumn<QString>("password"); + QTest::addColumn<QString>("mechanism"); + QTest::addColumn<bool>("connected"); + + QTest::newRow("plain-good") << "testuser" << "testpwd" << "PLAIN" << true; + QTest::newRow("plain-bad-username") << "baduser" << "testpwd" << "PLAIN" << false; + QTest::newRow("plain-bad-password") << "testuser" << "badpwd" << "PLAIN" << false; + + QTest::newRow("digest-good") << "testuser" << "testpwd" << "DIGEST-MD5" << true; + QTest::newRow("digest-bad-username") << "baduser" << "testpwd" << "DIGEST-MD5" << false; + QTest::newRow("digest-bad-password") << "testuser" << "badpwd" << "DIGEST-MD5" << false; +} + +void TestServer::testConnect() +{ + QFETCH(QString, username); + QFETCH(QString, password); + QFETCH(QString, mechanism); + QFETCH(bool, connected); + + const QString testDomain("localhost"); + const QHostAddress testHost(QHostAddress::LocalHost); + const quint16 testPort = 12345; + + QXmppLogger logger; + logger.setLoggingType(QXmppLogger::StdoutLogging); + + // prepare server + TestPasswordChecker passwordChecker("testuser", "testpwd"); + + QXmppServer server; + server.setDomain(testDomain); + server.setLogger(&logger); + server.setPasswordChecker(&passwordChecker); + server.listenForClients(testHost, testPort); + + // prepare client + QXmppClient client; + client.setLogger(&logger); + + QEventLoop loop; + connect(&client, SIGNAL(connected()), + &loop, SLOT(quit())); + connect(&client, SIGNAL(disconnected()), + &loop, SLOT(quit())); + + QXmppConfiguration config; + config.setDomain(testDomain); + config.setHost(testHost.toString()); + config.setPort(testPort); + config.setUser(username); + config.setPassword(password); + config.setSaslAuthMechanism(mechanism); + client.connectToServer(config); + loop.exec(); + QCOMPARE(client.isConnected(), connected); +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QXmppPresence pres; + pres.availableStatusType(); + + // run tests + int errors = 0; + + TestUtils testUtils; + errors += QTest::qExec(&testUtils); + + TestPackets testPackets; + errors += QTest::qExec(&testPackets); + +#ifdef QXMPP_AUTOTEST_INTERNAL + TestCodec testCodec; + errors += QTest::qExec(&testCodec); +#endif + + tst_QXmppDataForm testDataForm; + errors += QTest::qExec(&testDataForm); + + tst_QXmppIq testIq; + errors += QTest::qExec(&testIq); + + TestJingle testJingle; + errors += QTest::qExec(&testJingle); + + tst_QXmppMessage testMessage; + errors += QTest::qExec(&testMessage); + + tst_QXmppPresence testPresence; + errors += QTest::qExec(&testPresence); + + TestPubSub testPubSub; + errors += QTest::qExec(&testPubSub); + + tst_QXmppRegisterIq testRegister; + errors += QTest::qExec(&testRegister); + + tst_QXmppResultSet testRsm; + errors += QTest::qExec(&testRsm); + + tst_QXmppRosterIq testRoster; + errors += QTest::qExec(&testRoster); + + tst_QXmppRtpPacket testRtp; + errors += QTest::qExec(&testRtp); + +#ifdef QXMPP_AUTOTEST_INTERNAL + tst_QXmppSasl testSasl; + errors += QTest::qExec(&testSasl); + + tst_QXmppSaslClient testSaslClient; + errors += QTest::qExec(&testSaslClient); + + tst_QXmppSaslServer testSaslServer; + errors += QTest::qExec(&testSaslServer); +#endif + + TestServer testServer; + errors += QTest::qExec(&testServer); + + tst_QXmppStanza testStanza; + errors += QTest::qExec(&testStanza); + +#ifdef QXMPP_AUTOTEST_INTERNAL + tst_QXmppStreamInitiationIq testSI; + errors += QTest::qExec(&testSI); +#endif + + TestStun testStun; + errors += QTest::qExec(&testStun); + + tst_QXmppVCardIq testVCard; + errors += QTest::qExec(&testVCard); + + TestXmlRpc testXmlRpc; + errors += QTest::qExec(&testXmlRpc); + + if (errors) + { + qWarning() << "Total failed tests:" << errors; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +}; + diff --git a/tests/all/tests.h b/tests/all/tests.h new file mode 100644 index 00000000..1a32b6a3 --- /dev/null +++ b/tests/all/tests.h @@ -0,0 +1,86 @@ +/* + * 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 <QObject> + +class TestUtils : public QObject +{ + Q_OBJECT + +private slots: + void testCrc32(); + void testHmac(); + void testJid(); + void testMime(); + void testLibVersion(); + void testTimezoneOffset(); +}; + +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(); +}; + +class TestServer : public QObject +{ + Q_OBJECT + +private slots: + void testConnect_data(); + void testConnect(); +}; diff --git a/tests/all/tests.qrc b/tests/all/tests.qrc new file mode 100644 index 00000000..6bc9605e --- /dev/null +++ b/tests/all/tests.qrc @@ -0,0 +1,11 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>test.bmp</file> + <file>test.gif</file> + <file>test.jpg</file> + <file>test.mng</file> + <file>test.png</file> + <file>test.svg</file> + <file>test.xpm</file> +</qresource> +</RCC> diff --git a/tests/all/vcard.cpp b/tests/all/vcard.cpp new file mode 100644 index 00000000..350e8a7e --- /dev/null +++ b/tests/all/vcard.cpp @@ -0,0 +1,187 @@ +/* + * 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 "QXmppVCardIq.h" + +#include "util.h" +#include "vcard.h" + +void tst_QXmppVCardIq::testAddress_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("type"); + QTest::addColumn<QString>("country"); + QTest::addColumn<QString>("locality"); + QTest::addColumn<QString>("postcode"); + QTest::addColumn<QString>("region"); + QTest::addColumn<QString>("street"); + + QTest::newRow("none") << QByteArray("<ADR/>") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << ""; + QTest::newRow("HOME") << QByteArray("<ADR><HOME/></ADR>") << int(QXmppVCardAddress::Home) << "" << "" << "" << "" << ""; + QTest::newRow("WORK") << QByteArray("<ADR><WORK/></ADR>") << int(QXmppVCardAddress::Work) << "" << "" << "" << "" << ""; + QTest::newRow("POSTAL") << QByteArray("<ADR><POSTAL/></ADR>") << int(QXmppVCardAddress::Postal) << "" << "" << "" << "" << ""; + QTest::newRow("PREF") << QByteArray("<ADR><PREF/></ADR>") << int(QXmppVCardAddress::Preferred) << "" << "" << "" << "" << ""; + + QTest::newRow("country") << QByteArray("<ADR><CTRY>France</CTRY></ADR>") << int(QXmppVCardAddress::None) << "France" << "" << "" << "" << ""; + QTest::newRow("locality") << QByteArray("<ADR><LOCALITY>Paris</LOCALITY></ADR>") << int(QXmppVCardAddress::None) << "" << "Paris" << "" << "" << ""; + QTest::newRow("postcode") << QByteArray("<ADR><PCODE>75008</PCODE></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "75008" << "" << ""; + QTest::newRow("region") << QByteArray("<ADR><REGION>Ile de France</REGION></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "" << "Ile de France" << ""; + QTest::newRow("street") << QByteArray("<ADR><STREET>55 rue du faubourg Saint-Honoré</STREET></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << QString::fromUtf8("55 rue du faubourg Saint-Honoré"); +} + +void tst_QXmppVCardIq::testAddress() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + QFETCH(QString, country); + QFETCH(QString, locality); + QFETCH(QString, postcode); + QFETCH(QString, region); + QFETCH(QString, street); + + QXmppVCardAddress address; + parsePacket(address, xml); + QCOMPARE(int(address.type()), type); + QCOMPARE(address.country(), country); + QCOMPARE(address.locality(), locality); + QCOMPARE(address.postcode(), postcode); + QCOMPARE(address.region(), region); + QCOMPARE(address.street(), street); + serializePacket(address, xml); +} + +void tst_QXmppVCardIq::testEmail_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("type"); + + QTest::newRow("none") << QByteArray("<EMAIL><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::None); + QTest::newRow("HOME") << QByteArray("<EMAIL><HOME/><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::Home); + QTest::newRow("WORK") << QByteArray("<EMAIL><WORK/><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::Work); + QTest::newRow("INTERNET") << QByteArray("<EMAIL><INTERNET/><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::Internet); + QTest::newRow("X400") << QByteArray("<EMAIL><X400/><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::X400); + QTest::newRow("PREF") << QByteArray("<EMAIL><PREF/><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::Preferred); + QTest::newRow("all") << QByteArray("<EMAIL><HOME/><WORK/><INTERNET/><PREF/><X400/><USERID>foo.bar@example.com</USERID></EMAIL>") << int(QXmppVCardEmail::Home | QXmppVCardEmail::Work | QXmppVCardEmail::Internet | QXmppVCardEmail::Preferred | QXmppVCardEmail::X400); +} + +void tst_QXmppVCardIq::testEmail() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + + QXmppVCardEmail email; + parsePacket(email, xml); + QCOMPARE(email.address(), QLatin1String("foo.bar@example.com")); + QCOMPARE(int(email.type()), type); + serializePacket(email, xml); +} + +void tst_QXmppVCardIq::testPhone_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<int>("type"); + + QTest::newRow("none") << QByteArray("<PHONE><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::None); + QTest::newRow("HOME") << QByteArray("<PHONE><HOME/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Home); + QTest::newRow("WORK") << QByteArray("<PHONE><WORK/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Work); + QTest::newRow("VOICE") << QByteArray("<PHONE><VOICE/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Voice); + QTest::newRow("FAX") << QByteArray("<PHONE><FAX/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Fax); + QTest::newRow("PAGER") << QByteArray("<PHONE><PAGER/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Pager); + QTest::newRow("MSG") << QByteArray("<PHONE><MSG/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Messaging); + QTest::newRow("CELL") << QByteArray("<PHONE><CELL/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Cell); + QTest::newRow("VIDEO") << QByteArray("<PHONE><VIDEO/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Video); + QTest::newRow("BBS") << QByteArray("<PHONE><BBS/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::BBS); + QTest::newRow("MODEM") << QByteArray("<PHONE><MODEM/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Modem); + QTest::newRow("IDSN") << QByteArray("<PHONE><ISDN/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::ISDN); + QTest::newRow("PCS") << QByteArray("<PHONE><PCS/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::PCS); + QTest::newRow("PREF") << QByteArray("<PHONE><PREF/><NUMBER>12345</NUMBER></PHONE>") << int(QXmppVCardPhone::Preferred); +} + +void tst_QXmppVCardIq::testPhone() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + + QXmppVCardPhone phone; + parsePacket(phone, xml); + QCOMPARE(phone.number(), QLatin1String("12345")); + QCOMPARE(int(phone.type()), type); + serializePacket(phone, xml); +} + + +void tst_QXmppVCardIq::testVCard() +{ + const QByteArray xml( + "<iq id=\"vcard1\" type=\"set\">" + "<vCard xmlns=\"vcard-temp\">" + "<ADR><CTRY>France</CTRY></ADR>" + "<BDAY>1983-09-14</BDAY>" + "<DESC>I like XMPP.</DESC>" + "<EMAIL><INTERNET/><USERID>foo.bar@example.com</USERID></EMAIL>" + "<FN>Foo Bar!</FN>" + "<NICKNAME>FooBar</NICKNAME>" + "<N><GIVEN>Foo</GIVEN><FAMILY>Wiz</FAMILY><MIDDLE>Baz</MIDDLE></N>" + "<PHONE><HOME/><NUMBER>12345</NUMBER></PHONE>" + "<PHONE><WORK/><NUMBER>67890</NUMBER></PHONE>" + "<PHOTO>" + "<TYPE>image/png</TYPE>" + "<BINVAL>" + "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAAlwSFlzAAA" + "UIgAAFCIBjw1HyAAAAAd0SU1FB9oIHQInNvuJovgAAAAiSURBVAjXY2TQ+s/AwMDAwPD/GiMDlP" + "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC" + "</BINVAL>" + "</PHOTO>" + "<URL>http://code.google.com/p/qxmpp/</URL>" + "</vCard>" + "</iq>"); + + QXmppVCardIq vcard; + parsePacket(vcard, xml); + QCOMPARE(vcard.addresses().size(), 1); + QCOMPARE(vcard.addresses()[0].country(), QLatin1String("France")); + QCOMPARE(int(vcard.addresses()[0].type()), int(QXmppVCardEmail::None)); + QCOMPARE(vcard.birthday(), QDate(1983, 9, 14)); + QCOMPARE(vcard.description(), QLatin1String("I like XMPP.")); + QCOMPARE(vcard.email(), QLatin1String("foo.bar@example.com")); + QCOMPARE(vcard.emails().size(), 1); + QCOMPARE(vcard.emails()[0].address(), QLatin1String("foo.bar@example.com")); + QCOMPARE(int(vcard.emails()[0].type()), int(QXmppVCardEmail::Internet)); + QCOMPARE(vcard.nickName(), QLatin1String("FooBar")); + QCOMPARE(vcard.fullName(), QLatin1String("Foo Bar!")); + QCOMPARE(vcard.firstName(), QLatin1String("Foo")); + QCOMPARE(vcard.middleName(), QLatin1String("Baz")); + QCOMPARE(vcard.lastName(), QLatin1String("Wiz")); + QCOMPARE(vcard.phones().size(), 2); + QCOMPARE(vcard.phones()[0].number(), QLatin1String("12345")); + QCOMPARE(int(vcard.phones()[0].type()), int(QXmppVCardEmail::Home)); + QCOMPARE(vcard.phones()[1].number(), QLatin1String("67890")); + QCOMPARE(int(vcard.phones()[1].type()), int(QXmppVCardEmail::Work)); + QCOMPARE(vcard.photo(), QByteArray::fromBase64( + "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAAlwSFlzAAA" + "UIgAAFCIBjw1HyAAAAAd0SU1FB9oIHQInNvuJovgAAAAiSURBVAjXY2TQ+s/AwMDAwPD/GiMDlP" + "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC")); + QCOMPARE(vcard.photoType(), QLatin1String("image/png")); + QCOMPARE(vcard.url(), QLatin1String("http://code.google.com/p/qxmpp/")); + serializePacket(vcard, xml); +} diff --git a/tests/all/vcard.h b/tests/all/vcard.h new file mode 100644 index 00000000..29a1dcad --- /dev/null +++ b/tests/all/vcard.h @@ -0,0 +1,38 @@ +/* + * 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 <QObject> + +class tst_QXmppVCardIq : public QObject +{ + Q_OBJECT + +private slots: + void testAddress_data(); + void testAddress(); + void testEmail_data(); + void testEmail(); + void testPhone_data(); + void testPhone(); + void testVCard(); +}; |
