diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-13 19:56:56 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-13 19:56:56 +0000 |
| commit | 72be5ca32d8b44d777b31db7545b8a3045f727b1 (patch) | |
| tree | 1fba3d021fcb3fa0382488a462a2666fb13d4220 /source/tests.cpp | |
| parent | d576c4819bbf746f1301ac1a29c442411e57f715 (diff) | |
| download | qxmpp-72be5ca32d8b44d777b31db7545b8a3045f727b1.tar.gz | |
add tests for HMAC-MD5
Diffstat (limited to 'source/tests.cpp')
| -rw-r--r-- | source/tests.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/source/tests.cpp b/source/tests.cpp index 3d99bf99..f2d91b5b 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -32,9 +32,23 @@ #include "QXmppMessage.h" #include "QXmppPresence.h" #include "QXmppSession.h" +#include "QXmppUtils.h" #include "tests.h" -static void parsePacket(QXmppPacket &packet, const QByteArray &xml) +void TestUtils::testHmac() +{ + QByteArray hmac = generateHmacMd5(QByteArray(16, 0x0b), QByteArray("Hi There")); + QCOMPARE(hmac, QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d")); + + hmac = generateHmacMd5(QByteArray("Jefe"), QByteArray("what do ya want for nothing?")); + QCOMPARE(hmac, QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738")); + + hmac = generateHmacMd5(QByteArray(16, 0xaa), QByteArray(50, 0xdd)); + QCOMPARE(hmac, QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6")); +} + +template <class T> +static void parsePacket(T &packet, const QByteArray &xml) { //qDebug() << "parsing" << xml; QDomDocument doc; @@ -43,13 +57,15 @@ static void parsePacket(QXmppPacket &packet, const QByteArray &xml) packet.parse(element); } -static void serializePacket(QXmppPacket &packet, const QByteArray &xml) +template <class T> +static void serializePacket(T &packet, const QByteArray &xml) { QBuffer buffer; buffer.open(QIODevice::ReadWrite); QXmlStreamWriter writer(&buffer); packet.toXml(&writer); - //qDebug() << "writing" << buffer.data(); + qDebug() << "expect " << xml; + qDebug() << "writing" << buffer.data(); QCOMPARE(buffer.data(), xml); } @@ -218,6 +234,9 @@ int main(int argc, char *argv[]) // run tests int errors = 0; + TestUtils testUtils; + errors += QTest::qExec(&testUtils); + TestPackets testPackets; errors += QTest::qExec(&testPackets); |
