aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-09-27 20:50:17 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-09-27 20:50:17 +0200
commit6a01a0f7bfd03deb3d0e6ed3e107ddbc4e07e5c8 (patch)
tree340a4ee17e107d484a3373db56443dc6060e23ae /tests
parent4dca74738a729a3f10f110c4003ba02c67b9fd47 (diff)
downloadqxmpp-6a01a0f7bfd03deb3d0e6ed3e107ddbc4e07e5c8.tar.gz
move sasl test code
Diffstat (limited to 'tests')
-rw-r--r--tests/all/all.pro5
-rw-r--r--tests/all/sasl.h69
-rw-r--r--tests/all/tests.cpp15
-rw-r--r--tests/qxmppsasl/tst_qxmppsasl.cpp (renamed from tests/all/sasl.cpp)50
-rw-r--r--tests/qxmpputils/tst_qxmpputils.cpp136
-rw-r--r--tests/tests.pro1
6 files changed, 186 insertions, 90 deletions
diff --git a/tests/all/all.pro b/tests/all/all.pro
index 4d2b678e..13afe30f 100644
--- a/tests/all/all.pro
+++ b/tests/all/all.pro
@@ -4,8 +4,3 @@ TARGET = tst_all
SOURCES += tests.cpp
HEADERS += tests.h
-
-!isEmpty(QXMPP_AUTOTEST_INTERNAL) {
- HEADERS += sasl.h
- SOURCES += sasl.cpp
-}
diff --git a/tests/all/sasl.h b/tests/all/sasl.h
deleted file mode 100644
index f70ff9af..00000000
--- a/tests/all/sasl.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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/tests.cpp b/tests/all/tests.cpp
index 640c26e4..f191dfde 100644
--- a/tests/all/tests.cpp
+++ b/tests/all/tests.cpp
@@ -27,7 +27,7 @@
#include <QCoreApplication>
#include <QDomDocument>
#include <QEventLoop>
-#include <QtTest/QtTest>
+#include <QtTest>
#include "QXmppArchiveIq.h"
#include "QXmppBindIq.h"
@@ -41,10 +41,8 @@
#include "QXmppStreamFeatures.h"
#include "QXmppUtils.h"
#include "QXmppVersionIq.h"
-#include "QXmppGlobal.h"
#include "QXmppEntityTimeIq.h"
-#include "sasl.h"
#include "tests.h"
#include "util.h"
@@ -783,17 +781,6 @@ int main(int argc, char *argv[])
TestPubSub testPubSub;
errors += QTest::qExec(&testPubSub);
-#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);
diff --git a/tests/all/sasl.cpp b/tests/qxmppsasl/tst_qxmppsasl.cpp
index b276ddcd..b85e49ee 100644
--- a/tests/all/sasl.cpp
+++ b/tests/qxmppsasl/tst_qxmppsasl.cpp
@@ -21,11 +21,54 @@
*
*/
+#include <QObject>
#include "QXmppSasl_p.h"
-
-#include "sasl.h"
#include "util.h"
+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();
+};
+
void tst_QXmppSasl::testParsing()
{
// empty
@@ -399,3 +442,6 @@ void tst_QXmppSaslServer::testPlainChallenge()
delete server;
}
+
+QTEST_MAIN(tst_QXmppSasl)
+#include "tst_qxmppsasl.moc"
diff --git a/tests/qxmpputils/tst_qxmpputils.cpp b/tests/qxmpputils/tst_qxmpputils.cpp
new file mode 100644
index 00000000..bf1c80dc
--- /dev/null
+++ b/tests/qxmpputils/tst_qxmpputils.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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>
+#include "QXmppUtils.h"
+#include "util.h"
+
+class tst_QXmppUtils : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testCrc32();
+ void testHmac();
+ void testJid();
+ void testMime();
+ void testLibVersion();
+ void testTimezoneOffset();
+};
+
+void tst_QXmppUtils::testCrc32()
+{
+ quint32 crc = QXmppUtils::generateCrc32(QByteArray());
+ QCOMPARE(crc, 0u);
+
+ crc = QXmppUtils::generateCrc32(QByteArray("Hi There"));
+ QCOMPARE(crc, 0xDB143BBEu);
+}
+
+void tst_QXmppUtils::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 tst_QXmppUtils::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 tst_QXmppUtils::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 tst_QXmppUtils::testMime()
+{
+}
+#endif
+
+void tst_QXmppUtils::testLibVersion()
+{
+ QCOMPARE(QXmppVersion(), QString("0.7.3"));
+}
+
+void tst_QXmppUtils::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"));
+}
+
+QTEST_MAIN(tst_QXmppUtils)
+#include "tst_qxmpputils.moc"
diff --git a/tests/tests.pro b/tests/tests.pro
index 090daef6..7bfeba14 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -18,5 +18,6 @@ SUBDIRS = \
!isEmpty(QXMPP_AUTOTEST_INTERNAL) {
SUBDIRS += qxmppcodec
+ SUBDIRS += qxmppsasl
SUBDIRS += qxmppstreaminitiationiq
}