aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-09-27 20:41:09 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-09-27 20:41:09 +0200
commit0f132eb9b0964840f799d19f6ea5ee327d3cd6c9 (patch)
tree83dd478f4b970a4f6e9e21cf183abab687c97745 /tests
parent6c944f97b202bc8d1c3ee25259455170ea82a80d (diff)
downloadqxmpp-0f132eb9b0964840f799d19f6ea5ee327d3cd6c9.tar.gz
split QXmppUtils tests
Diffstat (limited to 'tests')
-rw-r--r--tests/all/tests.cpp96
-rw-r--r--tests/all/tests.h13
-rw-r--r--tests/qxmpputils/qxmpputils.pro3
-rw-r--r--tests/tests.pro1
4 files changed, 4 insertions, 109 deletions
diff --git a/tests/all/tests.cpp b/tests/all/tests.cpp
index a7095408..640c26e4 100644
--- a/tests/all/tests.cpp
+++ b/tests/all/tests.cpp
@@ -48,99 +48,6 @@
#include "tests.h"
#include "util.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");
@@ -870,9 +777,6 @@ int main(int argc, char *argv[])
// run tests
int errors = 0;
- TestUtils testUtils;
- errors += QTest::qExec(&testUtils);
-
TestPackets testPackets;
errors += QTest::qExec(&testPackets);
diff --git a/tests/all/tests.h b/tests/all/tests.h
index 1a32b6a3..fe928346 100644
--- a/tests/all/tests.h
+++ b/tests/all/tests.h
@@ -24,19 +24,6 @@
#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
diff --git a/tests/qxmpputils/qxmpputils.pro b/tests/qxmpputils/qxmpputils.pro
new file mode 100644
index 00000000..040b66f0
--- /dev/null
+++ b/tests/qxmpputils/qxmpputils.pro
@@ -0,0 +1,3 @@
+include(../tests.pri)
+TARGET = tst_qxmpputils
+SOURCES += tst_qxmpputils.cpp
diff --git a/tests/tests.pro b/tests/tests.pro
index fd52820c..090daef6 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -13,6 +13,7 @@ SUBDIRS = \
qxmpprtppacket \
qxmppstanza \
qxmppstunmessage \
+ qxmpputils \
qxmppvcardiq
!isEmpty(QXMPP_AUTOTEST_INTERNAL) {