diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-10 07:45:39 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-10 07:45:39 +0000 |
| commit | 1147c4f57591397a53bc045ae77106e337c2d940 (patch) | |
| tree | b6fb54139ad68fefb7b1df6baee7ee45fcbe5428 | |
| parent | 0e9455bc58f89d242b4e58ed00fe88835833a412 (diff) | |
| download | qxmpp-1147c4f57591397a53bc045ae77106e337c2d940.tar.gz | |
test XML-RPC invoke/response IQs
| -rw-r--r-- | example/tests/tests.cpp | 54 | ||||
| -rw-r--r-- | example/tests/tests.h | 3 | ||||
| -rw-r--r-- | source/QXmppRpcIq.cpp | 33 | ||||
| -rw-r--r-- | source/QXmppRpcIq.h | 24 |
4 files changed, 111 insertions, 3 deletions
diff --git a/example/tests/tests.cpp b/example/tests/tests.cpp index 8e175844..21888856 100644 --- a/example/tests/tests.cpp +++ b/example/tests/tests.cpp @@ -32,6 +32,7 @@ #include "QXmppJingleIq.h" #include "QXmppMessage.h" #include "QXmppPresence.h" +#include "QXmppRpcIq.h" #include "QXmppSession.h" #include "QXmppUtils.h" #include "tests.h" @@ -415,6 +416,59 @@ void TestXmlRpc::testStruct() "</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.interface(), QLatin1String("examples")); + QCOMPARE(iq.method(), QLatin1String("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.values(), QVariantList() << QString("Colorado")); + serializePacket(iq, xml); +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); diff --git a/example/tests/tests.h b/example/tests/tests.h index 7e50cf1c..9dc1a01c 100644 --- a/example/tests/tests.h +++ b/example/tests/tests.h @@ -74,4 +74,7 @@ private slots: void testArray(); void testStruct(); + + void testInvoke(); + void testResponse(); }; diff --git a/source/QXmppRpcIq.cpp b/source/QXmppRpcIq.cpp index 3eb8af08..e812cf4e 100644 --- a/source/QXmppRpcIq.cpp +++ b/source/QXmppRpcIq.cpp @@ -1,5 +1,30 @@ -#include "QXmppRpcIq.h" +/* + * Copyright (C) 2009-2010 Ian Reinhard Geiser + * + * Authors: + * Ian Reinhard Geiser + * 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 "QXmppConstants.h" +#include "QXmppRpcIq.h" +#include "QXmppUtils.h" #include "xmlrpc.h" #include <QDomElement> @@ -73,7 +98,8 @@ void QXmppRpcResponseIq::parseElementFromChild(const QDomElement &element) void QXmppRpcResponseIq::toXmlElementFromChild(QXmlStreamWriter *writer) const { - writer->writeStartElement(ns_rpc, "query"); + writer->writeStartElement("query"); + helperToXmlAddAttribute(writer, "xmlns", ns_rpc); XMLRPC::ResponseMessage message; message.setValues(m_values); @@ -139,7 +165,8 @@ void QXmppRpcInvokeIq::parseElementFromChild(const QDomElement &element) void QXmppRpcInvokeIq::toXmlElementFromChild(QXmlStreamWriter *writer) const { - writer->writeStartElement(ns_rpc, "query"); + writer->writeStartElement("query"); + helperToXmlAddAttribute(writer, "xmlns", ns_rpc); QString methodName = m_interface + "." + m_method; XMLRPC::RequestMessage message; diff --git a/source/QXmppRpcIq.h b/source/QXmppRpcIq.h index d60fe308..0594f27d 100644 --- a/source/QXmppRpcIq.h +++ b/source/QXmppRpcIq.h @@ -1,3 +1,27 @@ +/* + * Copyright (C) 2009-2010 Ian Reinhard Geiser + * + * Authors: + * Ian Reinhard Geiser + * 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. + * + */ + #ifndef QXMPPRPCIQ_H #define QXMPPRPCIQ_H |
