diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-07-21 22:16:24 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-07-21 22:16:24 +0200 |
| commit | 0a584900db720454f06d136e6bdf445a8f87e8b7 (patch) | |
| tree | c4b98aad62def1d9063abf9269c718a13d4b32b8 | |
| parent | 32183be3ef5fcbdca5b7f222e949898d5841a1a3 (diff) | |
| download | qxmpp-0a584900db720454f06d136e6bdf445a8f87e8b7.tar.gz | |
split out RPC and STUN tests
| -rw-r--r-- | tests/rpc.cpp | 212 | ||||
| -rw-r--r-- | tests/rpc.h | 45 | ||||
| -rw-r--r-- | tests/stun.cpp | 120 | ||||
| -rw-r--r-- | tests/stun.h | 37 | ||||
| -rw-r--r-- | tests/tests.cpp | 282 | ||||
| -rw-r--r-- | tests/tests.h | 34 | ||||
| -rw-r--r-- | tests/tests.pro | 5 |
7 files changed, 421 insertions, 314 deletions
diff --git a/tests/rpc.cpp b/tests/rpc.cpp new file mode 100644 index 00000000..a5136f65 --- /dev/null +++ b/tests/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 "tests.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/rpc.h b/tests/rpc.h new file mode 100644 index 00000000..f3a0c5e0 --- /dev/null +++ b/tests/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/stun.cpp b/tests/stun.cpp new file mode 100644 index 00000000..7238f05f --- /dev/null +++ b/tests/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 "tests.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/stun.h b/tests/stun.h new file mode 100644 index 00000000..1b0141d2 --- /dev/null +++ b/tests/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/tests.cpp b/tests/tests.cpp index 652f95f3..c48acfbe 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -27,7 +27,6 @@ #include <QCoreApplication> #include <QDomDocument> #include <QEventLoop> -#include <QVariant> #include <QtTest/QtTest> #include "QXmppArchiveIq.h" @@ -37,11 +36,9 @@ #include "QXmppNonSASLAuth.h" #include "QXmppPasswordChecker.h" #include "QXmppPubSubIq.h" -#include "QXmppRpcIq.h" #include "QXmppSessionIq.h" #include "QXmppServer.h" #include "QXmppStreamFeatures.h" -#include "QXmppStun.h" #include "QXmppUtils.h" #include "QXmppVCardIq.h" #include "QXmppVersionIq.h" @@ -55,9 +52,11 @@ #include "message.h" #include "presence.h" #include "register.h" +#include "rpc.h" #include "rsm.h" #include "rtp.h" #include "sasl.h" +#include "stun.h" #include "tests.h" void TestUtils::testCrc32() @@ -910,283 +909,6 @@ void TestServer::testConnect() QCOMPARE(client.isConnected(), connected); } -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)); -} - -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); -} - int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); diff --git a/tests/tests.h b/tests/tests.h index 78c87ae8..5ecadccd 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -109,37 +109,3 @@ private slots: void testConnect_data(); void testConnect(); }; - -class TestStun : public QObject -{ - Q_OBJECT - -private slots: - void testFingerprint(); - void testIntegrity(); - void testIPv4Address(); - void testIPv6Address(); - void testXorIPv4Address(); - void testXorIPv6Address(); -}; - -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/tests.pro b/tests/tests.pro index d73311b6..a415ac55 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,5 +1,6 @@ include(../qxmpp.pri) +QT -= gui QT += testlib TARGET = qxmpp-tests @@ -12,8 +13,10 @@ SOURCES += \ message.cpp \ presence.cpp \ register.cpp \ + rpc.cpp \ rsm.cpp \ rtp.cpp \ + stun.cpp \ tests.cpp HEADERS += \ dataform.h \ @@ -22,8 +25,10 @@ HEADERS += \ message.h \ presence.h \ register.h \ + rpc.h \ rsm.h \ rtp.h \ + stun.h \ tests.h !isEmpty(QXMPP_AUTOTEST_INTERNAL) { |
