dbus/test/qt Makefile.am, 1.6, 1.7 common.h, 1.2, 1.3 ping.cpp, 1.2, NONE qpong.cpp, 1.2, 1.3 tst_hal.cpp, 1.3, 1.4 tst_headertest.cpp, NONE, 1.1 tst_qdbusabstractadaptor.cpp, 1.2, 1.3 tst_qdbusconnection.cpp, 1.6, 1.7 tst_qdbusinterface.cpp, 1.3, 1.4 tst_qdbusmarshall.cpp, NONE, 1.1 tst_qdbusxmlparser.cpp, 1.3, 1.4

Thiago J. Macieira thiago at kemper.freedesktop.org
Sun Jun 11 05:18:25 PDT 2006


Update of /cvs/dbus/dbus/test/qt
In directory kemper:/tmp/cvs-serv13604/test/qt

Modified Files:
	Makefile.am common.h qpong.cpp tst_hal.cpp 
	tst_qdbusabstractadaptor.cpp tst_qdbusconnection.cpp 
	tst_qdbusinterface.cpp 
Added Files:
	tst_headertest.cpp tst_qdbusmarshall.cpp 
	tst_qdbusxmlparser.cpp 
Removed Files:
	ping.cpp 
Log Message:
	* test/qt/*: Update the testcases, including testing the new
        functionality of sending null QByteArray and QString over the
        bus. Add new headertest test and restore the old
        qdbusxmlparser test.


Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile.am	28 Mar 2006 18:58:58 -0000	1.6
+++ Makefile.am	11 Jun 2006 12:18:23 -0000	1.7
@@ -1,7 +1,7 @@
 INCLUDES=-I$(top_srcdir) -I$(top_srcdir)/qt $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) $(DBUS_QTESTLIB_CFLAGS) -DDBUS_COMPILATION
 
 if DBUS_BUILD_TESTS
-TEST_BINARIES=qdbusconnection qpong ping qdbusinterface qdbusabstractadaptor hal
+TEST_BINARIES = tst_headertest tst_qdbusxmlparser tst_qdbusconnection qpong tst_qdbusmarshall tst_qdbusinterface tst_qdbusabstractadaptor tst_hal
 TESTS=
 else
 TEST_BINARIES=
@@ -11,14 +11,17 @@
 noinst_PROGRAMS= $(TEST_BINARIES)
 
 qpong_SOURCES= qpong.cpp
-ping_SOURCES= ping.cpp
-qdbusconnection_SOURCES= tst_qdbusconnection.cpp
-qdbusinterface_SOURCES= tst_qdbusinterface.cpp
-qdbusabstractadaptor_SOURCES= tst_qdbusabstractadaptor.cpp common.h
-hal_SOURCES = tst_hal.cpp
+tst_headertest_SOURCES = tst_headertest.cpp
+tst_qdbusconnection_SOURCES = tst_qdbusconnection.cpp
+tst_qdbusxmlparser_SOURCES = tst_qdbusxmlparser.cpp
+tst_qdbusmarshall_SOURCES = tst_qdbusmarshall.cpp
+tst_qdbusinterface_SOURCES = tst_qdbusinterface.cpp
+tst_qdbusabstractadaptor_SOURCES = tst_qdbusabstractadaptor.cpp common.h
+tst_hal_SOURCES = tst_hal.cpp
 
 qpong.o: qpong.moc
-ping.o: ping.moc
+tst_qdbusxmlparser.o: tst_qdbusxmlparser.moc
+tst_qdbusmarshall.o: tst_qdbusmarshall.moc
 tst_qdbusconnection.o: tst_qdbusconnection.moc
 tst_qdbusinterface.o: tst_qdbusinterface.moc
 tst_qdbusabstractadaptor.o: tst_qdbusabstractadaptor.moc
@@ -27,7 +30,7 @@
 %.moc: %.cpp
 	$(QT_MOC) $< > $@
 
-TEST_LIBS=$(DBUS_QTESTLIB_LIBS) $(top_builddir)/qt/libdbus-qt4-1.la
+TEST_LIBS=$(DBUS_QTESTLIB_LIBS) $(top_builddir)/qt/src/libdbus-qt4-1.la
 
 LDADD=$(TEST_LIBS)
 

Index: common.h
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/common.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- common.h	28 Mar 2006 18:58:58 -0000	1.2
+++ common.h	11 Jun 2006 12:18:23 -0000	1.3
@@ -9,8 +9,8 @@
 Q_DECLARE_METATYPE(QList<qlonglong>)
 Q_DECLARE_METATYPE(QList<qulonglong>)
 Q_DECLARE_METATYPE(QList<double>)
-#if 0
-#include "../qdbusintrospection_p.h"
+#ifdef USE_PRIVATE_CODE
+#include "../../qt/src/qdbusintrospection_p.h"
 
 // just to make it easier:
 typedef QDBusIntrospection::Interfaces InterfaceMap;
@@ -157,6 +157,20 @@
     return true;
 }
 
+bool compare(const QString &s1, const QString &s2)
+{
+    if (s1.isEmpty() && s2.isEmpty())
+        return true;            // regardless of whether one of them is null
+    return s1 == s2;
+}
+
+bool compare(const QByteArray &ba1, const QByteArray &ba2)
+{
+    if (ba1.isEmpty() && ba2.isEmpty())
+        return true;            // regardless of whether one of them is null
+    return ba1 == ba2;
+}
+
 bool compare(const QVariant &v1, const QVariant &v2)
 {
     if (v1.userType() != v2.userType())
@@ -169,6 +183,12 @@
     else if (id == QVariant::Map)
         return compare(v1.toMap(), v2.toMap());
 
+    else if (id == QVariant::String)
+        return compare(v1.toString(), v2.toString());
+
+    else if (id == QVariant::ByteArray)
+        return compare(v1.toByteArray(), v2.toByteArray());
+
     else if (id < int(QVariant::UserType)) // yes, v1.type()
         // QVariant can compare
         return v1 == v2;

--- ping.cpp DELETED ---

Index: qpong.cpp
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/qpong.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- qpong.cpp	28 Mar 2006 18:58:58 -0000	1.2
+++ qpong.cpp	11 Jun 2006 12:18:23 -0000	1.3
@@ -1,6 +1,5 @@
 #include <QtCore/QtCore>
 #include <dbus/qdbus.h>
-#include <dbus/dbus.h>
 
 class Pong: public QObject
 {
@@ -22,13 +21,10 @@
     QCoreApplication app(argc, argv);
 
     QDBusConnection &con = QDBus::sessionBus();
-    QDBusMessage msg = QDBusMessage::methodCall(DBUS_SERVICE_DBUS,
-                                                DBUS_PATH_DBUS,
-                                                DBUS_INTERFACE_DBUS,
-                                                "RequestName");
-    msg << "org.kde.selftest" << 0U;
-    msg = con.sendWithReply(msg);
-    if (msg.type() != QDBusMessage::ReplyMessage)
+    if (!con.isConnected())
+        exit(1);
+
+    if (con.busService()->requestName("org.kde.selftest", QDBusBusService::DoNotQueueName).isError())
         exit(2);
 
     Pong pong;

Index: tst_hal.cpp
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/tst_hal.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- tst_hal.cpp	10 Apr 2006 10:51:56 -0000	1.3
+++ tst_hal.cpp	11 Jun 2006 12:18:23 -0000	1.4
@@ -2,7 +2,6 @@
 #include <qdebug.h>
 
 #include <QtTest/QtTest>
-#define DBUS_API_SUBJECT_TO_CHANGE
 #include <dbus/qdbus.h>
 
 class tst_Hal: public QObject

--- NEW FILE: tst_headertest.cpp ---
#define QT_NO_KEYWORDS
#define signals Choke!
#define slots Choke!
#define emit Choke!
#define foreach Choke!
#define forever Choke!

#define QT_NO_CAST_FROM_ASCII
#define QT_NO_CAST_TO_ASCII

#include <dbus/qdbus.h>

int main(int, char **)
{
    return 0;
}

Index: tst_qdbusabstractadaptor.cpp
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/tst_qdbusabstractadaptor.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- tst_qdbusabstractadaptor.cpp	28 Mar 2006 18:58:58 -0000	1.2
+++ tst_qdbusabstractadaptor.cpp	11 Jun 2006 12:18:23 -0000	1.3
@@ -7,6 +7,10 @@
 
 #include "common.h"
 
+#ifdef Q_CC_MSVC
+#define __PRETTY_FUNCTION__ __FUNCDNAME__
+#endif
+
 const char *slotSpy;
 QString valueSpy;
 
@@ -79,7 +83,7 @@
 class Interface1: public QDBusAbstractAdaptor
 {
     Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "local.Interface1");
+    Q_CLASSINFO("D-Bus Interface", "local.Interface1")
 public:
     Interface1(QObject *parent) : QDBusAbstractAdaptor(parent)
     { }
@@ -88,9 +92,9 @@
 class Interface2: public QDBusAbstractAdaptor
 {
     Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "local.Interface2");
-    Q_PROPERTY(QString prop1 READ prop1);
-    Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2);
+    Q_CLASSINFO("D-Bus Interface", "local.Interface2")
+    Q_PROPERTY(QString prop1 READ prop1)
+    Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2)
 public:
     Interface2(QObject *parent) : QDBusAbstractAdaptor(parent)
     { setAutoRelaySignals(true); }
@@ -117,9 +121,9 @@
 class Interface3: public QDBusAbstractAdaptor
 {
     Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "local.Interface3");
-    Q_PROPERTY(QString prop1 READ prop1);
-    Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2);
+    Q_CLASSINFO("D-Bus Interface", "local.Interface3")
+    Q_PROPERTY(QString prop1 READ prop1)
+    Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2)
 public:
     Interface3(QObject *parent) : QDBusAbstractAdaptor(parent)
     { setAutoRelaySignals(true); }
@@ -157,9 +161,9 @@
 class Interface4: public QDBusAbstractAdaptor
 {
     Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "local.Interface4");
-    Q_PROPERTY(QString prop1 READ prop1);
-    Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2);
+    Q_CLASSINFO("D-Bus Interface", "local.Interface4")
+    Q_PROPERTY(QString prop1 READ prop1)
+    Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2)
 public:
     Interface4(QObject *parent) : QDBusAbstractAdaptor(parent)
     { setAutoRelaySignals(true); }
@@ -452,51 +456,51 @@
 
     // must fail: no object
     //QCOMPARE(empty->call("method").type(), QDBusMessage::ErrorMessage);
-    QCOMPARE(if1->call("method").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ErrorMessage);
 
     QFETCH(int, nInterfaces);
     MyObject obj(nInterfaces);
     con.registerObject("/", &obj);
 
     // must fail: no such method
-    QCOMPARE(if1->call("method").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ErrorMessage);
     if (!nInterfaces--)
         return;
     if (!nInterfaces--)
         return;
 
     // simple call: one such method exists
-    QCOMPARE(if2->call("method").type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface2::method()");
     if (!nInterfaces--)
         return;
 
     // multiple methods in multiple interfaces, no name overlap
-    QCOMPARE(if1->call("methodVoid").type(), QDBusMessage::ErrorMessage);
-    QCOMPARE(if1->call("methodInt").type(), QDBusMessage::ErrorMessage);
-    QCOMPARE(if1->call("methodString").type(), QDBusMessage::ErrorMessage);
-    QCOMPARE(if2->call("methodVoid").type(), QDBusMessage::ErrorMessage);
-    QCOMPARE(if2->call("methodInt").type(), QDBusMessage::ErrorMessage);
-    QCOMPARE(if2->call("methodString").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "methodInt").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "methodString").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "methodInt").type(), QDBusMessage::ErrorMessage);
+    QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "methodString").type(), QDBusMessage::ErrorMessage);
 
-    QCOMPARE(if3->call("methodVoid").type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface3::methodVoid()");
-    QCOMPARE(if3->call("methodInt", 42).type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodInt", 42).type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface3::methodInt(int)");
-    QCOMPARE(if3->call("methodString", QString("")).type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodString", QString("")).type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface3::methodString(QString)");
 
     if (!nInterfaces--)
         return;
 
     // method overloading: different interfaces
-    QCOMPARE(if4->call("method").type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface4::method()");
 
     // method overloading: different parameters
-    QCOMPARE(if4->call("method.i", 42).type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method.i", 42).type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface4::method(int)");
-    QCOMPARE(if4->call("method.s", QString()).type(), QDBusMessage::ReplyMessage);
+    QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method.s", QString()).type(), QDBusMessage::ReplyMessage);
     QCOMPARE(slotSpy, "void Interface4::method(QString)");
     
 }
@@ -679,18 +683,19 @@
     MyObject obj;
     con.registerObject("/", &obj);
 
+    QDBusInterfacePtr properties(con, con.baseService(), "/", "org.freedesktop.DBus.Properties");
     for (int i = 2; i <= 4; ++i) {
         QString name = QString("Interface%1").arg(i);
-        QDBusInterface *iface = con.findInterface(con.baseService(), "/", "local." + name);
 
         for (int j = 1; j <= 2; ++j) {
             QString propname = QString("prop%1").arg(j);
-            QVariant value = iface->property(propname.toLatin1());
+            QDBusReply<QVariant> reply =
+                properties->call(QDBusInterface::UseEventLoop, "Get", "local." + name, propname);
+            QVariant value = reply;
 
             QCOMPARE(value.userType(), int(QVariant::String));
             QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname));
         }
-        iface->deleteLater();
     }
 }
 
@@ -702,21 +707,21 @@
     MyObject obj;
     con.registerObject("/", &obj);
 
+    QDBusInterfacePtr properties(con, con.baseService(), "/", "org.freedesktop.DBus.Properties");
     for (int i = 2; i <= 4; ++i) {
         QString name = QString("Interface%1").arg(i);
-        QDBusInterface *iface = con.findInterface(con.baseService(), "/", "local." + name);
 
         QVariant value(name);
 
         valueSpy.clear();
-        iface->setProperty("prop1", value);
+        properties->call(QDBusInterface::UseEventLoop, "Set", "local." + name, QString("prop1"),
+                         value);
         QVERIFY(valueSpy.isEmpty()); // call mustn't have succeeded
 
-        iface->setProperty("prop2", value);
+        properties->call(QDBusInterface::UseEventLoop, "Set", "local." + name, QString("prop2"),
+                         value);
         QCOMPARE(valueSpy, name);
         QCOMPARE(QString(slotSpy), QString("void %1::setProp2(const QString&)").arg(name));
-
-        iface->deleteLater();
     }
 }
 
@@ -964,10 +969,11 @@
     QDBusMessage reply;
     QDBusInterface *iface = con.findInterface(con.baseService(), "/types", "local.TypesInterface");
 
-    reply = iface->callWithArgs("method" + basename + '.' + signature, QVariantList() << value);
+    reply = iface->callWithArgs("method" + basename + '.' + signature, QVariantList() << value,
+                                QDBusInterface::UseEventLoop);
     QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
 
-    reply = iface->call("retrieve" + basename);
+    reply = iface->call(QDBusInterface::UseEventLoop, "retrieve" + basename);
     QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
     QCOMPARE(reply.count(), 1);
 

Index: tst_qdbusconnection.cpp
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/tst_qdbusconnection.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- tst_qdbusconnection.cpp	28 Mar 2006 18:58:58 -0000	1.6
+++ tst_qdbusconnection.cpp	11 Jun 2006 12:18:23 -0000	1.7
@@ -246,7 +246,7 @@
 bool tst_QDBusConnection::callMethod(const QDBusConnection &conn, const QString &path)
 {
     QDBusMessage msg = QDBusMessage::methodCall(conn.baseService(), path, "local.any", "method");
-    QDBusMessage reply = conn.sendWithReply(msg);
+    QDBusMessage reply = conn.sendWithReply(msg, QDBusConnection::UseEventLoop);
 
     return reply.type() == QDBusMessage::ReplyMessage;
 }    

Index: tst_qdbusinterface.cpp
===================================================================
RCS file: /cvs/dbus/dbus/test/qt/tst_qdbusinterface.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- tst_qdbusinterface.cpp	28 Mar 2006 18:58:58 -0000	1.3
+++ tst_qdbusinterface.cpp	11 Jun 2006 12:18:23 -0000	1.4
@@ -34,63 +34,33 @@
 #define TEST_INTERFACE_NAME "com.trolltech.QtDBus.MyObject"
 #define TEST_SIGNAL_NAME "somethingHappened"
 
-const char introspectionData[] =
-    "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
-    "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
-    "<node>"
-
-    "<interface name=\"org.freedesktop.DBus.Introspectable\">"
-    "<method name=\"Introspect\">"
-    "<arg name=\"data\" direction=\"out\" type=\"s\"/>"
-    "</method>"
-    "</interface>"
-
-    "<interface name=\"" TEST_INTERFACE_NAME "\">"
-    "<method name=\"ping\">"
-    "<arg name=\"ping\" direction=\"in\"  type=\"v\"/>"
-    "<arg name=\"pong\" direction=\"out\" type=\"v\"/>"
-    "</method>"
-    "<method name=\"ping\">"
-    "<arg name=\"ping1\" direction=\"in\"  type=\"v\"/>"
-    "<arg name=\"ping2\" direction=\"in\"  type=\"v\"/>"
-    "<arg name=\"pong1\" direction=\"out\" type=\"v\"/>"
-    "<arg name=\"pong2\" direction=\"out\" type=\"v\"/>"
-    "</method>"
-    "<signal name=\"" TEST_SIGNAL_NAME "\">"
-    "<arg type=\"s\"/>"
-    "</signal>"
-    "<property name=\"prop1\" access=\"readwrite\" type=\"i\" />"
-    "</interface>"
-    "<node name=\"subObject\"/>"
-    "</node>";
-
-class IntrospectionAdaptor: public QDBusAbstractAdaptor
-{
-    Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.Introspectable")
-public:
-    IntrospectionAdaptor(QObject *parent)
-        : QDBusAbstractAdaptor(parent)
-    { }
-        
-public slots:
-
-    void Introspect(const QDBusMessage &msg)
-    {
-        QDBusMessage reply = QDBusMessage::methodReply(msg);
-        reply << ::introspectionData;
-        if (!msg.connection().send(reply))
-            exit(1);
-    }
-};    
-
 class MyObject: public QObject
 {
     Q_OBJECT
+    Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.MyObject")
+    Q_CLASSINFO("D-Bus Introspection", ""
+"  <interface name=\"com.trolltech.QtDBus.MyObject\" >\n"
+"    <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n"
+"    <signal name=\"somethingHappened\" >\n"
+"      <arg direction=\"out\" type=\"s\" />\n"
+"    </signal>\n"
+"    <method name=\"ping\" >\n"
+"      <arg direction=\"in\" type=\"v\" name=\"ping\" />\n"
+"      <arg direction=\"out\" type=\"v\" name=\"ping\" />\n"
+"    </method>\n"
+"    <method name=\"ping\" >\n"
+"      <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n"
+"      <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n"
+"      <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
+"      <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n"
+"    </method>\n"
+"  </interface>\n"
+        "")
 public:
     MyObject()
     {
-        new IntrospectionAdaptor(this);
+        QObject *subObject = new QObject(this);
+        subObject->setObjectName("subObject");
     }
 
 public slots:
@@ -152,7 +122,8 @@
     QDBusConnection &con = QDBus::sessionBus();
     QVERIFY(con.isConnected());
 
-    con.registerObject("/", &obj, QDBusConnection::ExportAdaptors | QDBusConnection::ExportSlots);
+    con.registerObject("/", &obj, QDBusConnection::ExportAdaptors | QDBusConnection::ExportSlots |
+                       QDBusConnection::ExportChildObjects);
 }
 
 void tst_QDBusInterface::call_data()
@@ -241,7 +212,7 @@
     
     QDBusMessage reply;
     // try first callWithArgs:
-    reply = iface->callWithArgs(method, input);
+    reply = iface->callWithArgs(method, input, QDBusInterface::UseEventLoop);
 
     QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
     if (!output.isEmpty()) {
@@ -251,20 +222,20 @@
 
     // try the template methods
     if (input.isEmpty())
-        reply = iface->call(method);
+        reply = iface->call(QDBusInterface::UseEventLoop, method);
     else if (input.count() == 1)
         switch (input.at(0).type())
         {
         case QVariant::Int:
-            reply = iface->call(method, input.at(0).toInt());
+            reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toInt());
             break;
 
         case QVariant::UInt:
-            reply = iface->call(method, input.at(0).toUInt());
+            reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toUInt());
             break;
 
         case QVariant::String:
-            reply = iface->call(method, input.at(0).toString());
+            reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toString());
             break;
 
         default:
@@ -272,7 +243,7 @@
             break;
         }
     else
-        reply = iface->call(method, input.at(0).toString(), input.at(1).toString());
+        reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toString(), input.at(1).toString());
 
     QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
     if (!output.isEmpty()) {

--- NEW FILE: tst_qdbusmarshall.cpp ---
#include <QtCore/QtCore>
#include <QtTest/QtTest>
#include <dbus/qdbus.h>

#include "common.h"
#include <limits>

class tst_QDBusMarshall: public QObject
{
    Q_OBJECT

public slots:
    void initTestCase();
    void cleanupTestCase();

private slots:
    void sendBasic_data();
    void sendBasic();

    void sendVariant_data();
    void sendVariant();

    void sendArrays_data();
    void sendArrays();

    void sendArrayOfArrays_data();
    void sendArrayOfArrays();

    void sendStringMap_data();
    void sendStringMap();

    void sendStringMapOfMap_data();
    void sendStringMapOfMap();

private:
    QProcess proc;
};

void tst_QDBusMarshall::initTestCase()
{
    proc.start("./qpong");
    QVERIFY(proc.waitForStarted());
    QTest::qWait(2000);
}

void tst_QDBusMarshall::cleanupTestCase()
{
    proc.close();
    proc.kill();
}

void tst_QDBusMarshall::sendBasic_data()
{
    QTest::addColumn<QVariant>("value");
    QTest::addColumn<QString>("sig");

    // basic types:
    QTest::newRow("bool") << QVariant(false) << "b";
    QTest::newRow("bool2") << QVariant(true) << "b";
    QTest::newRow("byte") << qVariantFromValue(uchar(1)) << "y";
    QTest::newRow("int16") << qVariantFromValue(short(2)) << "n";
    QTest::newRow("uint16") << qVariantFromValue(ushort(3)) << "q";
    QTest::newRow("int") << QVariant(1) << "i";
    QTest::newRow("uint") << QVariant(2U) << "u";
    QTest::newRow("int64") << QVariant(Q_INT64_C(3)) << "x";
    QTest::newRow("uint64") << QVariant(Q_UINT64_C(4)) << "t";
    QTest::newRow("double") << QVariant(42.5) << "d";
    QTest::newRow("string") << QVariant("ping") << "s";
    QTest::newRow("emptystring") << QVariant("") << "s";
    QTest::newRow("nullstring") << QVariant(QString()) << "s";
}

void tst_QDBusMarshall::sendVariant_data()
{
    sendBasic_data();

    // add a few more:
    QVariant nested(1);
    QTest::newRow("variant") << nested << "v";

    QVariant nested2;
    qVariantSetValue(nested2, nested);
    QTest::newRow("variant-variant") << nested2 << "v";
}

void tst_QDBusMarshall::sendArrays_data()
{
    QTest::addColumn<QVariant>("value");
    QTest::addColumn<QString>("sig");

    // arrays:
    QStringList strings;
    QTest::newRow("emptystringlist") << QVariant(strings) << "as";
    strings << "hello" << "world";
    QTest::newRow("stringlist") << QVariant(strings) << "as";

    strings.clear();
    strings << "" << "" << "";
    QTest::newRow("list-of-emptystrings") << QVariant(strings) << "as";

    strings.clear();
    strings << QString() << QString() << QString() << QString();
    QTest::newRow("list-of-nullstrings") << QVariant(strings) << "as";

    QByteArray bytearray;
    QTest::newRow("nullbytearray") << QVariant(bytearray) << "ay";
    bytearray = "";             // empty, not null
    QTest::newRow("emptybytearray") << QVariant(bytearray) << "ay";
    bytearray = "foo";
    QTest::newRow("bytearray") << QVariant(bytearray) << "ay";
    bytearray.clear();
    for (int i = 0; i < 4096; ++i)
        bytearray += QByteArray(1024, char(i));
    QTest::newRow("hugebytearray") << QVariant(bytearray) << "ay";

    QList<bool> bools; 
    QTest::newRow("emptyboollist") << qVariantFromValue(bools) << "ab";
    bools << false << true << false;
    QTest::newRow("boollist") << qVariantFromValue(bools) << "ab";

    QList<short> shorts;
    QTest::newRow("emptyshortlist") << qVariantFromValue(shorts) << "an";
    shorts << 42 << -43 << 44 << 45 << -32768 << 32767;
    QTest::newRow("shortlist") << qVariantFromValue(shorts) << "an";

    QList<ushort> ushorts;
    QTest::newRow("emptyushortlist") << qVariantFromValue(ushorts) << "aq";
    ushorts << 12u << 13u << 14u << 15 << 65535;
    QTest::newRow("ushortlist") << qVariantFromValue(ushorts) << "aq";

    QList<int> ints;
    QTest::newRow("emptyintlist") << qVariantFromValue(ints) << "ai";
    ints << 42 << -43 << 44 << 45 << 2147483647 << -2147483647-1;
    QTest::newRow("intlist") << qVariantFromValue(ints) << "ai";

    QList<uint> uints;
    QTest::newRow("emptyuintlist") << qVariantFromValue(uints) << "au";
    uints << uint(12) << uint(13) << uint(14) << 4294967295U;
    QTest::newRow("uintlist") << qVariantFromValue(uints) << "au";

    QList<qlonglong> llints;
    QTest::newRow("emptyllintlist") << qVariantFromValue(llints) << "ax";
    llints << Q_INT64_C(99) << Q_INT64_C(-100)
           << Q_INT64_C(-9223372036854775807)-1 << Q_INT64_C(9223372036854775807);
    QTest::newRow("llintlist") << qVariantFromValue(llints) << "ax";

    QList<qulonglong> ullints;
    QTest::newRow("emptyullintlist") << qVariantFromValue(ullints) << "at";
    ullints << Q_UINT64_C(66) << Q_UINT64_C(67)
            << Q_UINT64_C(18446744073709551615);
    QTest::newRow("ullintlist") << qVariantFromValue(ullints) << "at";

    QList<double> doubles;
    QTest::newRow("emptydoublelist") << qVariantFromValue(doubles) << "ad";
    doubles << 1.2 << 2.2 << 4.4
            << -std::numeric_limits<double>::infinity()
            << std::numeric_limits<double>::infinity()
            << std::numeric_limits<double>::quiet_NaN();
    QTest::newRow("doublelist") << qVariantFromValue(doubles) << "ad";

    QVariantList variants;
    QTest::newRow("emptyvariantlist") << QVariant(variants) << "av";
    variants << QString("Hello") << QByteArray("World") << 42 << -43.0 << 44U << Q_INT64_C(-45)
             << Q_UINT64_C(46) << true << qVariantFromValue(short(-47));
    for (int i = 0; i < variants.count(); ++i) {
        QVariant tmp = variants.at(i);
        qVariantSetValue(variants[i], tmp);
    }
    QTest::newRow("variantlist") << QVariant(variants) << "av";
}

void tst_QDBusMarshall::sendArrayOfArrays_data()
{
    sendArrays_data();
}

void tst_QDBusMarshall::sendStringMap_data()
{
    sendBasic_data();

    QVariant nested;
    qVariantSetValue(nested, QVariant(1));
    QTest::newRow("variant") << nested << "v";

    QVariant nested2;
    qVariantSetValue(nested2, nested);
    QTest::newRow("variant-variant") << nested2 << "v";

    sendArrays_data();
}

void tst_QDBusMarshall::sendStringMapOfMap_data()
{
    sendStringMap_data();
}

void tst_QDBusMarshall::sendBasic()
{
    QFETCH(QVariant, value);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");
    msg << value;

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    QTEST(reply.signature(), "sig");
    for (int i = 0; i < reply.count(); ++i)
        QVERIFY(compare(reply.at(i), msg.at(i)));
}

void tst_QDBusMarshall::sendVariant()
{
    QFETCH(QVariant, value);
    QVariant tmp = value;
    qVariantSetValue(value, tmp);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");
    msg << value;

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    QCOMPARE(reply.signature(), QString("v"));
    for (int i = 0; i < reply.count(); ++i)
        QVERIFY(compare(reply.at(i), msg.at(i)));
}

void tst_QDBusMarshall::sendArrays()
{
    QFETCH(QVariant, value);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");
    msg << value;

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    QTEST(reply.signature(), "sig");
    for (int i = 0; i < reply.count(); ++i)
        QVERIFY(compare(reply.at(i), msg.at(i)));
}

void tst_QDBusMarshall::sendArrayOfArrays()
{
    QFETCH(QVariant, value);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");
    msg << QVariant(QVariantList() << value << value);

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    QFETCH(QString, sig);
    QCOMPARE(reply.signature(), "a" + sig);
    for (int i = 0; i < reply.count(); ++i)
        QVERIFY(compare(reply.at(i), msg.at(i)));
}

void tst_QDBusMarshall::sendStringMap()
{
    QFETCH(QVariant, value);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");

    QVariantMap map;
    map["foo"] = value;
    map["bar"] = value;
    msg << QVariant(map);

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    QFETCH(QString, sig);
    QCOMPARE(reply.signature(), "a{s" + sig + "}");
    for (int i = 0; i < reply.count(); ++i)
        QVERIFY(compare(reply.at(i), msg.at(i)));
}

void tst_QDBusMarshall::sendStringMapOfMap()
{
    QFETCH(QVariant, value);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");

    QVariantMap map;
    map["foo"] = value;
    map["bar"] = value;

    QVariantMap map2;
    map2["foo"] = map;
    msg << QVariant(map2);

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    QFETCH(QString, sig);
    QCOMPARE(reply.signature(), "a{sa{s" + sig + "}}");

    for (int i = 0; i < reply.count(); ++i)
        QVERIFY(compare(reply.at(i), msg.at(i)));
}


QTEST_MAIN(tst_QDBusMarshall)
#include "tst_qdbusmarshall.moc"




More information about the dbus-commit mailing list