aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-07-18 16:39:39 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-07-18 16:39:39 +0200
commitf880bbd5f96f505d8c00cdfe9d3ad46160d7c34c (patch)
tree5b94addbeef64b719663c676eaa9d781bfde9d41 /tests
parent2b2b251d5cfd324df9ec3bfdc110568a43f03140 (diff)
downloadqxmpp-f880bbd5f96f505d8c00cdfe9d3ad46160d7c34c.tar.gz
split QXmppMessage tests
Diffstat (limited to 'tests')
-rw-r--r--tests/message.cpp169
-rw-r--r--tests/message.h39
-rw-r--r--tests/tests.cpp145
-rw-r--r--tests/tests.h6
-rw-r--r--tests/tests.pro2
5 files changed, 214 insertions, 147 deletions
diff --git a/tests/message.cpp b/tests/message.cpp
new file mode 100644
index 00000000..94ff9155
--- /dev/null
+++ b/tests/message.cpp
@@ -0,0 +1,169 @@
+/*
+ * 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 "tests.h"
+
+void tst_QXmppMessage::testMessage()
+{
+ const QByteArray xml(
+ "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\"/>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QCOMPARE(message.to(), QString("foo@example.com/QXmpp"));
+ QCOMPARE(message.from(), QString("bar@example.com/QXmpp"));
+ QCOMPARE(message.type(), QXmppMessage::Normal);
+ QCOMPARE(message.body(), QString());
+ QCOMPARE(message.subject(), QString());
+ QCOMPARE(message.thread(), QString());
+ QCOMPARE(message.state(), QXmppMessage::None);
+ QCOMPARE(message.isAttentionRequested(), false);
+ QCOMPARE(message.isReceiptRequested(), false);
+ QCOMPARE(message.receiptId(), 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"));
+ 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"));
+ 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"));
+ 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"));
+ 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::testMessageFull()
+{
+ const QByteArray xml(
+ "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
+ "<subject>test subject</subject>"
+ "<body>test body &amp; stuff</body>"
+ "<thread>test thread</thread>"
+ "<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>"
+ "</message>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QCOMPARE(message.to(), QString("foo@example.com/QXmpp"));
+ QCOMPARE(message.from(), QString("bar@example.com/QXmpp"));
+ QCOMPARE(message.type(), QXmppMessage::Normal);
+ QCOMPARE(message.body(), QString("test body & stuff"));
+ QCOMPARE(message.subject(), QString("test subject"));
+ QCOMPARE(message.thread(), QString("test thread"));
+ QCOMPARE(message.state(), QXmppMessage::Composing);
+ serializePacket(message, xml);
+}
+
+void tst_QXmppMessage::testMessageDelay()
+{
+ const QByteArray xml(
+ "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
+ "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06Z\"/>"
+ "</message>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC));
+ serializePacket(message, xml);
+}
+
+void tst_QXmppMessage::testMessageLegacyDelay()
+{
+ const QByteArray xml(
+ "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
+ "<x xmlns=\"jabber:x:delay\" stamp=\"20100629T08:23:06\"/>"
+ "</message>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC));
+ serializePacket(message, xml);
+}
+
diff --git a/tests/message.h b/tests/message.h
new file mode 100644
index 00000000..ff23705d
--- /dev/null
+++ b/tests/message.h
@@ -0,0 +1,39 @@
+/*
+ * 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 testMessage();
+ void testMessageFull();
+ void testMessageAttention();
+ void testMessageReceipt();
+ void testMessageDelay();
+ void testMessageLegacyDelay();
+};
+
diff --git a/tests/tests.cpp b/tests/tests.cpp
index c4178e94..b2683999 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -54,6 +54,7 @@
#include "QXmppEntityTimeIq.h"
#include "dataform.h"
+#include "message.h"
#include "presence.h"
#include "register.h"
#include "rsm.h"
@@ -444,147 +445,6 @@ void TestPackets::testDiscoveryWithForm()
serializePacket(disco, xml);
}
-void TestPackets::testMessage()
-{
- const QByteArray xml(
- "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\"/>");
-
- QXmppMessage message;
- parsePacket(message, xml);
- QCOMPARE(message.to(), QString("foo@example.com/QXmpp"));
- QCOMPARE(message.from(), QString("bar@example.com/QXmpp"));
- QCOMPARE(message.type(), QXmppMessage::Normal);
- QCOMPARE(message.body(), QString());
- QCOMPARE(message.subject(), QString());
- QCOMPARE(message.thread(), QString());
- QCOMPARE(message.state(), QXmppMessage::None);
- QCOMPARE(message.isAttentionRequested(), false);
- QCOMPARE(message.isReceiptRequested(), false);
- QCOMPARE(message.receiptId(), QString());
- serializePacket(message, xml);
-}
-
-void TestPackets::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"));
- 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 TestPackets::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"));
- 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"));
- 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"));
- 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 TestPackets::testMessageFull()
-{
- const QByteArray xml(
- "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
- "<subject>test subject</subject>"
- "<body>test body &amp; stuff</body>"
- "<thread>test thread</thread>"
- "<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>"
- "</message>");
-
- QXmppMessage message;
- parsePacket(message, xml);
- QCOMPARE(message.to(), QString("foo@example.com/QXmpp"));
- QCOMPARE(message.from(), QString("bar@example.com/QXmpp"));
- QCOMPARE(message.type(), QXmppMessage::Normal);
- QCOMPARE(message.body(), QString("test body & stuff"));
- QCOMPARE(message.subject(), QString("test subject"));
- QCOMPARE(message.thread(), QString("test thread"));
- QCOMPARE(message.state(), QXmppMessage::Composing);
- serializePacket(message, xml);
-}
-
-void TestPackets::testMessageDelay()
-{
- const QByteArray xml(
- "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
- "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06Z\"/>"
- "</message>");
-
- QXmppMessage message;
- parsePacket(message, xml);
- QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC));
- serializePacket(message, xml);
-}
-
-void TestPackets::testMessageLegacyDelay()
-{
- const QByteArray xml(
- "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
- "<x xmlns=\"jabber:x:delay\" stamp=\"20100629T08:23:06\"/>"
- "</message>");
-
- QXmppMessage message;
- parsePacket(message, xml);
- QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC));
- serializePacket(message, xml);
-}
-
void TestPackets::testNonSaslAuth()
{
// Client Requests Authentication Fields from Server
@@ -1499,6 +1359,9 @@ int main(int argc, char *argv[])
TestJingle testJingle;
errors += QTest::qExec(&testJingle);
+ tst_QXmppMessage testMessage;
+ errors += QTest::qExec(&testMessage);
+
tst_QXmppPresence testPresence;
errors += QTest::qExec(&testPresence);
diff --git a/tests/tests.h b/tests/tests.h
index 4ee5671c..ab6526d3 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -79,12 +79,6 @@ private slots:
void testBindResult();
void testDiscovery();
void testDiscoveryWithForm();
- void testMessage();
- void testMessageFull();
- void testMessageAttention();
- void testMessageReceipt();
- void testMessageDelay();
- void testMessageLegacyDelay();
void testNonSaslAuth();
void testSession();
void testStreamFeatures();
diff --git a/tests/tests.pro b/tests/tests.pro
index e68b81d6..55aa4fab 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -7,6 +7,7 @@ TARGET = qxmpp-tests
RESOURCES += tests.qrc
SOURCES += \
dataform.cpp \
+ message.cpp \
presence.cpp \
register.cpp \
rsm.cpp \
@@ -14,6 +15,7 @@ SOURCES += \
tests.cpp
HEADERS += \
dataform.h \
+ message.h \
presence.h \
register.h \
rsm.h \