From 6c944f97b202bc8d1c3ee25259455170ea82a80d Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Thu, 27 Sep 2012 20:30:07 +0200 Subject: split RPC tests --- tests/all/all.pro | 8 +- tests/all/rpc.cpp | 212 -------------------------------- tests/all/rpc.h | 45 ------- tests/all/tests.cpp | 4 - tests/qxmpprpciq/qxmpprpciq.pro | 3 + tests/qxmpprpciq/tst_qxmpprpciq.cpp | 233 ++++++++++++++++++++++++++++++++++++ tests/tests.pro | 1 + 7 files changed, 239 insertions(+), 267 deletions(-) delete mode 100644 tests/all/rpc.cpp delete mode 100644 tests/all/rpc.h create mode 100644 tests/qxmpprpciq/qxmpprpciq.pro create mode 100644 tests/qxmpprpciq/tst_qxmpprpciq.cpp (limited to 'tests') diff --git a/tests/all/all.pro b/tests/all/all.pro index 5ba9e1f3..8ef977bb 100644 --- a/tests/all/all.pro +++ b/tests/all/all.pro @@ -3,12 +3,8 @@ include(../tests.pri) TARGET = tst_all RESOURCES += tests.qrc -SOURCES += \ - rpc.cpp \ - tests.cpp -HEADERS += \ - rpc.h \ - tests.h +SOURCES += tests.cpp +HEADERS += tests.h !isEmpty(QXMPP_AUTOTEST_INTERNAL) { HEADERS += sasl.h diff --git a/tests/all/rpc.cpp b/tests/all/rpc.cpp deleted file mode 100644 index c0714957..00000000 --- a/tests/all/rpc.cpp +++ /dev/null @@ -1,212 +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 "QXmppRpcIq.h" - -#include "rpc.h" -#include "util.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("AAECAw==")); -} - -void TestXmlRpc::testBool() -{ - checkVariant(false, - QByteArray("0")); - checkVariant(true, - QByteArray("1")); -} - -void TestXmlRpc::testDateTime() -{ - checkVariant(QDateTime(QDate(1998, 7, 17), QTime(14, 8, 55)), - QByteArray("1998-07-17T14:08:55")); -} - -void TestXmlRpc::testDouble() -{ - checkVariant(double(-12.214), - QByteArray("-12.214")); -} - -void TestXmlRpc::testInt() -{ - checkVariant(int(-12), - QByteArray("-12")); -} - -void TestXmlRpc::testNil() -{ - checkVariant(QVariant(), - QByteArray("")); -} - -void TestXmlRpc::testString() -{ - checkVariant(QString("hello world"), - QByteArray("hello world")); -} - -void TestXmlRpc::testArray() -{ - checkVariant(QVariantList() << QString("hello world") << double(-12.214), - QByteArray("" - "hello world" - "-12.214" - "")); -} - -void TestXmlRpc::testStruct() -{ - QMap map; - map["bar"] = QString("hello world"); - map["foo"] = double(-12.214); - checkVariant(map, - QByteArray("" - "" - "bar" - "hello world" - "" - "" - "foo" - "-12.214" - "" - "")); -} - -void TestXmlRpc::testInvoke() -{ - const QByteArray xml( - "" - "" - "" - "examples.getStateName" - "" - "" - "6" - "" - "" - "" - "" - ""); - - 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( - "" - "" - "" - "" - "" - "Colorado" - "" - "" - "" - "" - ""); - - 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( - "" - "" - "" - "" - "" - "" - "" - "faultCode" - "404" - "" - "" - "faultString" - "Not found" - "" - "" - "" - "" - "" - "" - ""); - - 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/all/rpc.h b/tests/all/rpc.h deleted file mode 100644 index f3a0c5e0..00000000 --- a/tests/all/rpc.h +++ /dev/null @@ -1,45 +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 - -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/all/tests.cpp b/tests/all/tests.cpp index 8fd2b806..a7095408 100644 --- a/tests/all/tests.cpp +++ b/tests/all/tests.cpp @@ -44,7 +44,6 @@ #include "QXmppGlobal.h" #include "QXmppEntityTimeIq.h" -#include "rpc.h" #include "sasl.h" #include "tests.h" #include "util.h" @@ -894,9 +893,6 @@ int main(int argc, char *argv[]) TestServer testServer; errors += QTest::qExec(&testServer); - TestXmlRpc testXmlRpc; - errors += QTest::qExec(&testXmlRpc); - if (errors) { qWarning() << "Total failed tests:" << errors; diff --git a/tests/qxmpprpciq/qxmpprpciq.pro b/tests/qxmpprpciq/qxmpprpciq.pro new file mode 100644 index 00000000..e818b0a3 --- /dev/null +++ b/tests/qxmpprpciq/qxmpprpciq.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +TARGET = tst_qxmpprpciq +SOURCES += tst_qxmpprpciq.cpp diff --git a/tests/qxmpprpciq/tst_qxmpprpciq.cpp b/tests/qxmpprpciq/tst_qxmpprpciq.cpp new file mode 100644 index 00000000..97f7f1fb --- /dev/null +++ b/tests/qxmpprpciq/tst_qxmpprpciq.cpp @@ -0,0 +1,233 @@ +/* + * 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 +#include "QXmppRpcIq.h" +#include "util.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); +} + +class tst_QXmppRpcIq : 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(); +}; +void tst_QXmppRpcIq::testBase64() +{ + checkVariant(QByteArray("\0\1\2\3", 4), + QByteArray("AAECAw==")); +} + +void tst_QXmppRpcIq::testBool() +{ + checkVariant(false, + QByteArray("0")); + checkVariant(true, + QByteArray("1")); +} + +void tst_QXmppRpcIq::testDateTime() +{ + checkVariant(QDateTime(QDate(1998, 7, 17), QTime(14, 8, 55)), + QByteArray("1998-07-17T14:08:55")); +} + +void tst_QXmppRpcIq::testDouble() +{ + checkVariant(double(-12.214), + QByteArray("-12.214")); +} + +void tst_QXmppRpcIq::testInt() +{ + checkVariant(int(-12), + QByteArray("-12")); +} + +void tst_QXmppRpcIq::testNil() +{ + checkVariant(QVariant(), + QByteArray("")); +} + +void tst_QXmppRpcIq::testString() +{ + checkVariant(QString("hello world"), + QByteArray("hello world")); +} + +void tst_QXmppRpcIq::testArray() +{ + checkVariant(QVariantList() << QString("hello world") << double(-12.214), + QByteArray("" + "hello world" + "-12.214" + "")); +} + +void tst_QXmppRpcIq::testStruct() +{ + QMap map; + map["bar"] = QString("hello world"); + map["foo"] = double(-12.214); + checkVariant(map, + QByteArray("" + "" + "bar" + "hello world" + "" + "" + "foo" + "-12.214" + "" + "")); +} + +void tst_QXmppRpcIq::testInvoke() +{ + const QByteArray xml( + "" + "" + "" + "examples.getStateName" + "" + "" + "6" + "" + "" + "" + "" + ""); + + QXmppRpcInvokeIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.method(), QLatin1String("examples.getStateName")); + QCOMPARE(iq.arguments(), QVariantList() << int(6)); + serializePacket(iq, xml); +} + +void tst_QXmppRpcIq::testResponse() +{ + const QByteArray xml( + "" + "" + "" + "" + "" + "Colorado" + "" + "" + "" + "" + ""); + + QXmppRpcResponseIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.faultCode(), 0); + QCOMPARE(iq.faultString(), QString()); + QCOMPARE(iq.values(), QVariantList() << QString("Colorado")); + serializePacket(iq, xml); +} + +void tst_QXmppRpcIq::testResponseFault() +{ + const QByteArray xml( + "" + "" + "" + "" + "" + "" + "" + "faultCode" + "404" + "" + "" + "faultString" + "Not found" + "" + "" + "" + "" + "" + "" + ""); + + QXmppRpcResponseIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.faultCode(), 404); + QCOMPARE(iq.faultString(), QLatin1String("Not found")); + QCOMPARE(iq.values(), QVariantList()); + serializePacket(iq, xml); +} + +QTEST_MAIN(tst_QXmppRpcIq) +#include "tst_qxmpprpciq.moc" diff --git a/tests/tests.pro b/tests/tests.pro index 47f6ff94..fd52820c 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -9,6 +9,7 @@ SUBDIRS = \ qxmppregisteriq \ qxmppresultset \ qxmpprosteriq \ + qxmpprpciq \ qxmpprtppacket \ qxmppstanza \ qxmppstunmessage \ -- cgit v1.2.3