diff options
Diffstat (limited to 'test/qt')
-rw-r--r-- | test/qt/.cvsignore | 11 | ||||
-rw-r--r-- | test/qt/Makefile.am | 38 | ||||
-rw-r--r-- | test/qt/common.h | 264 | ||||
-rw-r--r-- | test/qt/qpong.cpp | 38 | ||||
-rw-r--r-- | test/qt/tst_hal.cpp | 80 | ||||
-rw-r--r-- | test/qt/tst_headertest.cpp | 16 | ||||
-rw-r--r-- | test/qt/tst_qdbusabstractadaptor.cpp | 989 | ||||
-rw-r--r-- | test/qt/tst_qdbusconnection.cpp | 257 | ||||
-rw-r--r-- | test/qt/tst_qdbusinterface.cpp | 295 | ||||
-rw-r--r-- | test/qt/tst_qdbusmarshall.cpp | 342 | ||||
-rw-r--r-- | test/qt/tst_qdbusxmlparser.cpp | 578 |
11 files changed, 0 insertions, 2908 deletions
diff --git a/test/qt/.cvsignore b/test/qt/.cvsignore deleted file mode 100644 index f6454f28..00000000 --- a/test/qt/.cvsignore +++ /dev/null @@ -1,11 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -*.bb -*.bbg -*.da -*.gcov -*.moc diff --git a/test/qt/Makefile.am b/test/qt/Makefile.am deleted file mode 100644 index 8ebd3323..00000000 --- a/test/qt/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -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 = tst_headertest tst_qdbusxmlparser tst_qdbusconnection qpong tst_qdbusmarshall tst_qdbusinterface tst_qdbusabstractadaptor tst_hal -TESTS= -else -TEST_BINARIES= -TESTS= -endif - -noinst_PROGRAMS= $(TEST_BINARIES) - -qpong_SOURCES= qpong.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 -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 -tst_hal.o: tst_hal.moc - -%.moc: %.cpp - $(QT_MOC) $< > $@ - -TEST_LIBS=$(DBUS_QTESTLIB_LIBS) $(top_builddir)/qt/src/libdbus-qt4-1.la - -LDADD=$(TEST_LIBS) - -clean-local: - -rm *.moc diff --git a/test/qt/common.h b/test/qt/common.h deleted file mode 100644 index 58beae4e..00000000 --- a/test/qt/common.h +++ /dev/null @@ -1,264 +0,0 @@ -#include <math.h> // isnan - -Q_DECLARE_METATYPE(QVariant) -Q_DECLARE_METATYPE(QList<bool>) -Q_DECLARE_METATYPE(QList<short>) -Q_DECLARE_METATYPE(QList<ushort>) -Q_DECLARE_METATYPE(QList<int>) -Q_DECLARE_METATYPE(QList<uint>) -Q_DECLARE_METATYPE(QList<qlonglong>) -Q_DECLARE_METATYPE(QList<qulonglong>) -Q_DECLARE_METATYPE(QList<double>) -#ifdef USE_PRIVATE_CODE -#include "../../qt/src/qdbusintrospection_p.h" - -// just to make it easier: -typedef QDBusIntrospection::Interfaces InterfaceMap; -typedef QDBusIntrospection::Objects ObjectMap; -typedef QDBusIntrospection::Arguments ArgumentList; -typedef QDBusIntrospection::Annotations AnnotationsMap; -typedef QDBusIntrospection::Methods MethodMap; -typedef QDBusIntrospection::Signals SignalMap; -typedef QDBusIntrospection::Properties PropertyMap; - -Q_DECLARE_METATYPE(QDBusIntrospection::Method) -Q_DECLARE_METATYPE(QDBusIntrospection::Signal) -Q_DECLARE_METATYPE(QDBusIntrospection::Property) -Q_DECLARE_METATYPE(MethodMap) -Q_DECLARE_METATYPE(SignalMap) -Q_DECLARE_METATYPE(PropertyMap) - -inline QDBusIntrospection::Argument arg(const char* type, const char *name = 0) -{ - QDBusIntrospection::Argument retval; - retval.type = QLatin1String(type); - retval.name = QLatin1String(name); - return retval; -} - -template<typename T> -inline QMap<QString, T>& operator<<(QMap<QString, T>& map, const T& m) -{ map.insertMulti(m.name, m); return map; } - -inline const char* mapName(const MethodMap&) -{ return "MethodMap"; } - -inline const char* mapName(const SignalMap&) -{ return "SignalMap"; } - -inline const char* mapName(const PropertyMap&) -{ return "PropertyMap"; } - -QString printable(const QDBusIntrospection::Method& m) -{ - QString result = "method " + m.name + "("; - foreach (QDBusIntrospection::Argument arg, m.inputArgs) - result += QString("in %1 %2, ") - .arg(arg.type, arg.name); - foreach (QDBusIntrospection::Argument arg, m.outputArgs) - result += QString("out %1 %2, ") - .arg(arg.type, arg.name); - AnnotationsMap::const_iterator it = m.annotations.begin(); - for ( ; it != m.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); - - result += ")"; - return result; -} - -QString printable(const QDBusIntrospection::Signal& s) -{ - QString result = "signal " + s.name + "("; - foreach (QDBusIntrospection::Argument arg, s.outputArgs) - result += QString("out %1 %2, ") - .arg(arg.type, arg.name); - AnnotationsMap::const_iterator it = s.annotations.begin(); - for ( ; it != s.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); - - result += ")"; - return result; -} - -QString printable(const QDBusIntrospection::Property& p) -{ - QString result; - if (p.access == QDBusIntrospection::Property::Read) - result = "property read %1 %2, "; - else if (p.access == QDBusIntrospection::Property::Write) - result = "property write %1 %2, "; - else - result = "property readwrite %1 %2, "; - result = result.arg(p.type, p.name); - - AnnotationsMap::const_iterator it = p.annotations.begin(); - for ( ; it != p.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); - - return result; -} - -template<typename T> -char* printableMap(const QMap<QString, T>& map) -{ - QString contents = "\n"; - typename QMap<QString, T>::const_iterator it = map.begin(); - for ( ; it != map.end(); ++it) { - if (it.key() != it.value().name) - contents += it.value().name + ":"; - contents += printable(it.value()); - contents += ";\n"; - } - - QString result("%1(size = %2): {%3}"); - return qstrdup(qPrintable(result - .arg(mapName(map)) - .arg(map.size()) - .arg(contents))); -} - -namespace QTest { - template<> - inline char* toString(const MethodMap& map) - { - return printableMap(map); - } - - template<> - inline char* toString(const SignalMap& map) - { - return printableMap(map); - } - - template<> - inline char* toString(const PropertyMap& map) - { - return printableMap(map); - } -} -#endif -bool compare(const QVariantList &l1, const QVariantList &l2); -bool compare(const QVariantMap &m1, const QVariantMap &m2); -bool compare(const QVariant &v1, const QVariant &v2); - -bool compare(const QList<double> &l1, const QList<double> &l2) -{ - if (l1.count() != l2.count()) - return false; - - QList<double>::ConstIterator it1 = l1.constBegin(); - QList<double>::ConstIterator it2 = l2.constBegin(); - QList<double>::ConstIterator end = l1.constEnd(); - for ( ; it1 != end; ++it1, ++it2) - if (isnan(*it1) && isnan(*it2)) - continue; - else if (*it1 != *it2) - return false; - 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()) - return false; - - int id = v1.userType(); - if (id == QVariant::List) - return compare(v1.toList(), v2.toList()); - - 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; - - else if (id == QMetaType::UChar) - return qvariant_cast<uchar>(v1) == qvariant_cast<uchar>(v2); - - else if (id == QMetaType::Short) - return qvariant_cast<short>(v1) == qvariant_cast<short>(v2); - - else if (id == QMetaType::UShort) - return qvariant_cast<ushort>(v1) == qvariant_cast<ushort>(v2); - - else if (id == qMetaTypeId<QVariant>()) - return compare(qvariant_cast<QVariant>(v1), qvariant_cast<QVariant>(v2)); - - else if (id == qMetaTypeId<QList<bool> >()) - return qvariant_cast<QList<bool> >(v1) == qvariant_cast<QList<bool> >(v2); - - else if (id == qMetaTypeId<QList<short> >()) - return qvariant_cast<QList<short> >(v1) == qvariant_cast<QList<short> >(v2); - - else if (id == qMetaTypeId<QList<ushort> >()) - return qvariant_cast<QList<ushort> >(v1) == qvariant_cast<QList<ushort> >(v2); - - else if (id == qMetaTypeId<QList<int> >()) - return qvariant_cast<QList<int> >(v1) == qvariant_cast<QList<int> >(v2); - - else if (id == qMetaTypeId<QList<uint> >()) - return qvariant_cast<QList<uint> >(v1) == qvariant_cast<QList<uint> >(v2); - - else if (id == qMetaTypeId<QList<qlonglong> >()) - return qvariant_cast<QList<qlonglong> >(v1) == qvariant_cast<QList<qlonglong> >(v2); - - else if (id == qMetaTypeId<QList<qulonglong> >()) - return qvariant_cast<QList<qulonglong> >(v2) == qvariant_cast<QList<qulonglong> >(v2); - - else if (id == qMetaTypeId<QList<double> >()) - return compare(qvariant_cast<QList<double> >(v1), qvariant_cast<QList<double> >(v2)); - - else - return false; // unknown type -} - -bool compare(const QVariantList &l1, const QVariantList &l2) -{ - if (l1.count() != l2.size()) - return false; - QVariantList::ConstIterator i1 = l1.constBegin(); - QVariantList::ConstIterator i2 = l2.constBegin(); - QVariantList::ConstIterator end = l1.constEnd(); - for ( ; i1 != end; ++i1, ++i2) { - if (!compare(*i1, *i2)) - return false; - } - return true; -} - -bool compare(const QVariantMap &m1, const QVariantMap &m2) -{ - if (m1.count() != m2.size()) - return false; - QVariantMap::ConstIterator i1 = m1.constBegin(); - QVariantMap::ConstIterator end = m1.constEnd(); - for ( ; i1 != end; ++i1) { - QVariantMap::ConstIterator i2 = m2.find(i1.key()); - if (i2 == m2.constEnd()) - return false; - if (!compare(*i1, *i2)) - return false; - } - return true; -} diff --git a/test/qt/qpong.cpp b/test/qt/qpong.cpp deleted file mode 100644 index cad04eb6..00000000 --- a/test/qt/qpong.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include <QtCore/QtCore> -#include <dbus/qdbus.h> - -class Pong: public QObject -{ - Q_OBJECT -public slots: - - void ping(const QDBusMessage &msg) - { - QDBusMessage reply = QDBusMessage::methodReply(msg); - reply << static_cast<QList<QVariant> >(msg); - reply.setSignature(msg.signature()); - if (!msg.connection().send(reply)) - exit(1); - } -}; - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - QDBusConnection &con = QDBus::sessionBus(); - if (!con.isConnected()) - exit(1); - - if (con.busService()->requestName("org.kde.selftest", QDBusBusService::DoNotQueueName).isError()) - exit(2); - - Pong pong; - con.registerObject("/org/kde/selftest", &pong, QDBusConnection::ExportSlots); - - printf("ready.\n"); - - return app.exec(); -} - -#include "qpong.moc" diff --git a/test/qt/tst_hal.cpp b/test/qt/tst_hal.cpp deleted file mode 100644 index a69daf2f..00000000 --- a/test/qt/tst_hal.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include <qcoreapplication.h> -#include <qdebug.h> - -#include <QtTest/QtTest> -#include <dbus/qdbus.h> - -class tst_Hal: public QObject -{ - Q_OBJECT - -private slots: - void getDevices(); - void lock(); -}; - -class Spy: public QObject -{ - Q_OBJECT -public: - int count; - QDBusConnection &conn; - - Spy(QDBusConnection &c) : count(0), conn(c) - { } - -public slots: - void spySlot(int, const QVariantList&) - { - ++count; - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.Hal", - "/org/freedesktop/Hal/devices/acpi_CPU0", - "org.freedesktop.Hal.Device", "GetProperty"); - msg << "info.locked"; - - QDBusMessage reply = conn.sendWithReply(msg); - QVERIFY(!reply.isEmpty()); - } -}; - - -void tst_Hal::getDevices() -{ - QDBusConnection &con = QDBus::systemBus(); - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.Hal", - "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", - "GetAllDevices"); - - QDBusMessage reply = con.sendWithReply(msg); - QVERIFY(!reply.isEmpty()); - QVERIFY(reply.type() == QDBusMessage::ReplyMessage); - //qDebug() << reply; -} - -void tst_Hal::lock() -{ - QDBusConnection &con = QDBus::systemBus(); - QVERIFY(con.isConnected()); - - Spy spy( con ); - - con.connect("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/acpi_CPU0", - "org.freedesktop.Hal.Device", "PropertyModified", - &spy, SLOT(spySlot(int, QVariantList))); - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.Hal", - "/org/freedesktop/Hal/devices/acpi_CPU0", "org.freedesktop.Hal.Device", - "Lock"); - msg << "No reason..."; - - QDBusMessage reply = con.sendWithReply(msg); - //QTest::qWait(200); - //qDebug() << reply; - QCOMPARE(spy.count, 3); - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); -} - -QTEST_MAIN(tst_Hal) - -#include "tst_hal.moc" diff --git a/test/qt/tst_headertest.cpp b/test/qt/tst_headertest.cpp deleted file mode 100644 index eb90c555..00000000 --- a/test/qt/tst_headertest.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#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; -} diff --git a/test/qt/tst_qdbusabstractadaptor.cpp b/test/qt/tst_qdbusabstractadaptor.cpp deleted file mode 100644 index d47c5436..00000000 --- a/test/qt/tst_qdbusabstractadaptor.cpp +++ /dev/null @@ -1,989 +0,0 @@ -#include <qcoreapplication.h> -#include <qdebug.h> - -#include <QtTest/QtTest> - -#include <dbus/qdbus.h> - -#include "common.h" - -#ifdef Q_CC_MSVC -#define __PRETTY_FUNCTION__ __FUNCDNAME__ -#endif - -const char *slotSpy; -QString valueSpy; - -namespace QTest { - char *toString(QDBusMessage::MessageType t) - { - switch (t) - { - case QDBusMessage::InvalidMessage: - return qstrdup("InvalidMessage"); - case QDBusMessage::MethodCallMessage: - return qstrdup("MethodCallMessage"); - case QDBusMessage::ReplyMessage: - return qstrdup("ReplyMessage"); - case QDBusMessage::ErrorMessage: - return qstrdup("ErrorMessage"); - case QDBusMessage::SignalMessage: - return qstrdup("SignalMessage"); - default: - return 0; - } - } -} - -class tst_QDBusAbstractAdaptor: public QObject -{ - Q_OBJECT - -private slots: - void methodCalls_data(); - void methodCalls(); - void signalEmissions_data(); - void signalEmissions(); - void sameSignalDifferentPaths(); - void overloadedSignalEmission_data(); - void overloadedSignalEmission(); - void readProperties(); - void writeProperties(); - - void typeMatching_data(); - void typeMatching(); -}; - -class QDBusSignalSpy: public QObject -{ - Q_OBJECT - -public slots: - void slot(const QDBusMessage &msg) - { - ++count; - interface = msg.interface(); - name = msg.name(); - signature = msg.signature(); - value.clear(); - if (msg.count()) - value = msg.at(0); - } - -public: - QDBusSignalSpy() : count(0) { } - - int count; - QString interface; - QString name; - QString signature; - QVariant value; -}; - -class Interface1: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.Interface1") -public: - Interface1(QObject *parent) : QDBusAbstractAdaptor(parent) - { } -}; - -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) -public: - Interface2(QObject *parent) : QDBusAbstractAdaptor(parent) - { setAutoRelaySignals(true); } - - QString prop1() const - { return __PRETTY_FUNCTION__; } - - QString prop2() const - { return __PRETTY_FUNCTION__; } - - void setProp2(const QString &value) - { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; } - - void emitSignal(const QString &, const QVariant &) - { emit signal(); } - -public slots: - void method() { slotSpy = __PRETTY_FUNCTION__; } - -signals: - void signal(); -}; - -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) -public: - Interface3(QObject *parent) : QDBusAbstractAdaptor(parent) - { setAutoRelaySignals(true); } - - QString prop1() const - { return __PRETTY_FUNCTION__; } - - QString prop2() const - { return __PRETTY_FUNCTION__; } - - void setProp2(const QString &value) - { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; } - - void emitSignal(const QString &name, const QVariant &value) - { - if (name == "signalVoid") - emit signalVoid(); - else if (name == "signalInt") - emit signalInt(value.toInt()); - else if (name == "signalString") - emit signalString(value.toString()); - } - -public slots: - void methodVoid() { slotSpy = __PRETTY_FUNCTION__; } - void methodInt(int) { slotSpy = __PRETTY_FUNCTION__; } - void methodString(QString) { slotSpy = __PRETTY_FUNCTION__; } - -signals: - void signalVoid(); - void signalInt(int); - void signalString(const QString &); -}; - -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) -public: - Interface4(QObject *parent) : QDBusAbstractAdaptor(parent) - { setAutoRelaySignals(true); } - - QString prop1() const - { return __PRETTY_FUNCTION__; } - - QString prop2() const - { return __PRETTY_FUNCTION__; } - - void setProp2(const QString &value) - { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; } - - void emitSignal(const QString &, const QVariant &value) - { - switch (value.type()) - { - case QVariant::Invalid: - emit signal(); - break; - case QVariant::Int: - emit signal(value.toInt()); - break; - case QVariant::String: - emit signal(value.toString()); - break; - default: - break; - } - } - -public slots: - void method() { slotSpy = __PRETTY_FUNCTION__; } - void method(int) { slotSpy = __PRETTY_FUNCTION__; } - void method(QString) { slotSpy = __PRETTY_FUNCTION__; } - -signals: - void signal(); - void signal(int); - void signal(const QString &); -}; - -class MyObject: public QObject -{ - Q_OBJECT -public: - Interface1 *if1; - Interface2 *if2; - Interface3 *if3; - Interface4 *if4; - - MyObject(int n = 4) - : if1(0), if2(0), if3(0), if4(0) - { - switch (n) - { - case 4: - if4 = new Interface4(this); - case 3: - if3 = new Interface3(this); - case 2: - if2 = new Interface2(this); - case 1: - if1 = new Interface1(this); - } - } -}; - -class TypesInterface: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.TypesInterface") -public: - TypesInterface(QObject *parent) - : QDBusAbstractAdaptor(parent) - { } - - union - { - bool b; - uchar uc; - short s; - ushort us; - int i; - uint ui; - qlonglong ll; - qulonglong ull; - double d; - } dataSpy; - QVariant variantSpy; - QString stringSpy; - QVariantList listSpy; - QStringList stringlistSpy; - QByteArray bytearraySpy; - QVariantMap mapSpy; - -public slots: - void methodBool(bool b) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.b = b; - } - - void methodUChar(uchar uc) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.uc = uc; - } - - void methodShort(short s) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.s = s; - } - - void methodUShort(ushort us) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.us = us; - } - - void methodInt(int i) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.i = i; - } - - void methodUInt(uint ui) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.ui = ui; - } - - void methodLongLong(qlonglong ll) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.ll = ll; - } - - void methodULongLong(qulonglong ull) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.ull = ull; - } - - void methodDouble(double d) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.d = d; - } - - void methodString(const QString &s) - { - slotSpy = __PRETTY_FUNCTION__; - stringSpy = s; - } - - void methodVariant(const QVariant &v) - { - slotSpy = __PRETTY_FUNCTION__; - variantSpy = v; - } - - void methodList(const QVariantList &l) - { - slotSpy = __PRETTY_FUNCTION__; - listSpy = l; - } - - void methodStringList(const QStringList &sl) - { - slotSpy = __PRETTY_FUNCTION__; - stringlistSpy = sl; - } - - void methodByteArray(const QByteArray &ba) - { - slotSpy = __PRETTY_FUNCTION__; - bytearraySpy = ba; - } - - void methodMap(const QVariantMap &m) - { - slotSpy = __PRETTY_FUNCTION__; - mapSpy = m; - } - - bool retrieveBool() - { - return dataSpy.b; - } - - uchar retrieveUChar() - { - return dataSpy.uc; - } - - short retrieveShort() - { - return dataSpy.s; - } - - ushort retrieveUShort() - { - return dataSpy.us; - } - - int retrieveInt() - { - return dataSpy.i; - } - - uint retrieveUInt() - { - return dataSpy.ui; - } - - qlonglong retrieveLongLong() - { - return dataSpy.ll; - } - - qulonglong retrieveULongLong() - { - return dataSpy.ull; - } - - double retrieveDouble() - { - return dataSpy.d; - } - - QString retrieveString() - { - return stringSpy; - } - - QVariant retrieveVariant() - { - return variantSpy; - } - - QVariantList retrieveList() - { - return listSpy; - } - - QStringList retrieveStringList() - { - return stringlistSpy; - } - - QByteArray retrieveByteArray() - { - return bytearraySpy; - } - - QVariantMap retrieveMap() - { - return mapSpy; - } -}; - -void tst_QDBusAbstractAdaptor::methodCalls_data() -{ - QTest::addColumn<int>("nInterfaces"); - QTest::newRow("0") << 0; - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("3") << 3; - QTest::newRow("4") << 4; -} - -void tst_QDBusAbstractAdaptor::methodCalls() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - //QDBusInterface *empty = con.findInterface(con.baseService(), "/", QString()); - QDBusInterface *if1 = con.findInterface(con.baseService(), "/", "local.Interface1"); - QDBusInterface *if2 = con.findInterface(con.baseService(), "/", "local.Interface2"); - QDBusInterface *if3 = con.findInterface(con.baseService(), "/", "local.Interface3"); - QDBusInterface *if4 = con.findInterface(con.baseService(), "/", "local.Interface4"); - - QObject deleter; - if1->setParent(&deleter); - if2->setParent(&deleter); - if3->setParent(&deleter); - if4->setParent(&deleter); - - // must fail: no object - //QCOMPARE(empty->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(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ErrorMessage); - if (!nInterfaces--) - return; - if (!nInterfaces--) - return; - - // simple call: one such method exists - 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(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(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface3::methodVoid()"); - QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodInt", 42).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface3::methodInt(int)"); - 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(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface4::method()"); - - // method overloading: different parameters - QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method.i", 42).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface4::method(int)"); - QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method.s", QString()).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface4::method(QString)"); - -} - -static void emitSignal(MyObject *obj, const QString &iface, const QString &name, - const QVariant ¶meter) -{ - if (iface.endsWith('2')) - obj->if2->emitSignal(name, parameter); - else if (iface.endsWith('3')) - obj->if3->emitSignal(name, parameter); - else if (iface.endsWith('4')) - obj->if4->emitSignal(name, parameter); - - QTest::qWait(200); -} - -void tst_QDBusAbstractAdaptor::signalEmissions_data() -{ - QTest::addColumn<QString>("interface"); - QTest::addColumn<QString>("name"); - QTest::addColumn<QString>("signature"); - QTest::addColumn<QVariant>("parameter"); - - QTest::newRow("Interface2.signal") << "local.Interface2" << "signal" << QString() << QVariant(); - QTest::newRow("Interface3.signalVoid") << "local.Interface3" << "signalVoid" << QString() << QVariant(); - QTest::newRow("Interface3.signalInt") << "local.Interface3" << "signalInt" << "i" << QVariant(1); - QTest::newRow("Interface3.signalString") << "local.Interface3" << "signalString" << "s" << QVariant("foo"); -} - -void tst_QDBusAbstractAdaptor::signalEmissions() -{ - QFETCH(QString, interface); - QFETCH(QString, name); - QFETCH(QVariant, parameter); - - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj(3); - con.registerObject("/", &obj); - - //QDBusInterface empty = con.findInterface(con.baseService(), "/", QString()); - QDBusInterface *if2 = con.findInterface(con.baseService(), "/", "local.Interface2"); - QDBusInterface *if3 = con.findInterface(con.baseService(), "/", "local.Interface3"); - QObject deleter; - if2->setParent(&deleter); - if3->setParent(&deleter); - - // connect all signals and emit only one - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", "local.Interface2", "signal", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface3", "signalVoid", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface3", "signalInt", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface3", "signalString", - &spy, SLOT(slot(QDBusMessage))); - - emitSignal(&obj, interface, name, parameter); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } - - // connect one signal and emit them all - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", interface, name, &spy, SLOT(slot(QDBusMessage))); - emitSignal(&obj, "local.Interface2", "signal", QVariant()); - emitSignal(&obj, "local.Interface3", "signalVoid", QVariant()); - emitSignal(&obj, "local.Interface3", "signalInt", QVariant(1)); - emitSignal(&obj, "local.Interface3", "signalString", QVariant("foo")); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } -} - -void tst_QDBusAbstractAdaptor::sameSignalDifferentPaths() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj(2); - - con.registerObject("/p1",&obj); - con.registerObject("/p2",&obj); - - QDBusSignalSpy spy; - con.connect(con.baseService(), "/p1", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); - obj.if2->emitSignal(QString(), QVariant()); - QTest::qWait(200); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, QString("local.Interface2")); - QCOMPARE(spy.name, QString("signal")); - QVERIFY(spy.signature.isEmpty()); - - // now connect the other one - spy.count = 0; - con.connect(con.baseService(), "/p2", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); - obj.if2->emitSignal(QString(), QVariant()); - QTest::qWait(200); - - QCOMPARE(spy.count, 2); -} - -void tst_QDBusAbstractAdaptor::overloadedSignalEmission_data() -{ - QTest::addColumn<QString>("signature"); - QTest::addColumn<QVariant>("parameter"); - QTest::newRow("void") << QString("") << QVariant(); - QTest::newRow("int") << "i" << QVariant(1); - QTest::newRow("string") << "s" << QVariant("foo"); -} - -void tst_QDBusAbstractAdaptor::overloadedSignalEmission() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj; - con.registerObject("/", &obj); - - QString interface = "local.Interface4"; - QString name = "signal"; - QFETCH(QVariant, parameter); - //QDBusInterface *if4 = con.findInterface(con.baseService(), "/", interface); - - // connect all signals and emit only one - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", "local.Interface4", "signal", "", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface4", "signal", "i", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface4", "signal", "s", - &spy, SLOT(slot(QDBusMessage))); - - emitSignal(&obj, interface, name, parameter); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } - - QFETCH(QString, signature); - // connect one signal and emit them all - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", interface, name, signature, &spy, SLOT(slot(QDBusMessage))); - emitSignal(&obj, "local.Interface4", "signal", QVariant()); - emitSignal(&obj, "local.Interface4", "signal", QVariant(1)); - emitSignal(&obj, "local.Interface4", "signal", QVariant("foo")); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } -} - -void tst_QDBusAbstractAdaptor::readProperties() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - 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); - - for (int j = 1; j <= 2; ++j) { - QString propname = QString("prop%1").arg(j); - 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)); - } - } -} - -void tst_QDBusAbstractAdaptor::writeProperties() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - 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); - - QVariant value(name); - - valueSpy.clear(); - properties->call(QDBusInterface::UseEventLoop, "Set", "local." + name, QString("prop1"), - value); - QVERIFY(valueSpy.isEmpty()); // call mustn't have succeeded - - properties->call(QDBusInterface::UseEventLoop, "Set", "local." + name, QString("prop2"), - value); - QCOMPARE(valueSpy, name); - QCOMPARE(QString(slotSpy), QString("void %1::setProp2(const QString&)").arg(name)); - } -} - -#if 0 -void tst_QDBusAbstractAdaptor::adaptorIntrospection_data() -{ - methodCalls_data(); -} - -void tst_QDBusAbstractAdaptor::adaptorIntrospection() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - QObject obj; - con.registerObject("/", &obj); - - QFETCH(int, nInterfaces); - switch (nInterfaces) - { - case 4: - new Interface4(&obj); - case 3: - new Interface3(&obj); - case 2: - new Interface2(&obj); - case 1: - new Interface1(&obj); - } - - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QVERIFY(dobj.isValid()); - - QString xml = dobj.introspect(); - QVERIFY(!xml.isEmpty()); - - QStringList interfaces = dobj.interfaces(); - QCOMPARE(interfaces.count(), nInterfaces + 2); - switch (nInterfaces) - { - case 4: { - QVERIFY(interfaces.contains("local.Interface4")); - QDBusInterface iface(dobj, "local.Interface4"); - QCOMPARE(iface.methodData(), Interface4::methodData); - QCOMPARE(iface.signalData(), Interface4::signalData); - QCOMPARE(iface.propertyData(), Interface4::propertyData); - } - case 3: { - QVERIFY(interfaces.contains("local.Interface3")); - QDBusInterface iface(dobj, "local.Interface3"); - QCOMPARE(iface.methodData(), Interface3::methodData); - QCOMPARE(iface.signalData(), Interface3::signalData); - QCOMPARE(iface.propertyData(), Interface3::propertyData); - } - case 2: { - QVERIFY(interfaces.contains("local.Interface2")); - QDBusInterface iface(dobj, "local.Interface2"); - QCOMPARE(iface.methodData(), Interface2::methodData); - QCOMPARE(iface.signalData(), Interface2::signalData); - QCOMPARE(iface.propertyData(), Interface2::propertyData); - } - case 1: { - QVERIFY(interfaces.contains("local.Interface1")); - QDBusInterface iface(dobj, "local.Interface1"); - QCOMPARE(iface.methodData(), Interface1::methodData); - QCOMPARE(iface.signalData(), Interface1::signalData); - QCOMPARE(iface.propertyData(), Interface1::propertyData); - } - } -} - -void tst_QDBusAbstractAdaptor::objectTreeIntrospection() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.isEmpty()); - } - - QObject root; - con.registerObject("/", &root); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.isEmpty()); - } - - QObject p1; - con.registerObject("/p1", &p1); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("p1")); - } - - con.unregisterObject("/"); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("p1")); - } - - con.registerObject("/p1/q/r", &root); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p1"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("q")); - } - { - QDBusObject dobj = con.findObject(con.baseService(), "/p1/q"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("r")); - } - - con.unregisterObject("/p1", QDBusConnection::UnregisterTree); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.isEmpty()); - } - - QObject p2; - con.registerObject("/p2", &p2, QDBusConnection::ExportChildObjects); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(!tree.childObjects.contains("p1")); - QVERIFY(tree.childObjects.contains("p2")); - } - - QObject q; - q.setParent(&p2); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p2"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(!tree.childObjects.contains("q")); - } - - q.setObjectName("q"); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p2"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("q")); - } - - q.setParent(0); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p2"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(!tree.childObjects.contains("q")); - } -} -#endif - -static inline QVariant nest(const QVariant& v) -{ - QVariant ret; - qVariantSetValue(ret, v); - return ret; -} - -void tst_QDBusAbstractAdaptor::typeMatching_data() -{ - QTest::addColumn<QString>("basename"); - QTest::addColumn<QString>("signature"); - QTest::addColumn<QVariant>("value"); - - QTest::newRow("bool") << "Bool" << "b" << QVariant(true); - QTest::newRow("byte") << "UChar" << "y" << qVariantFromValue(uchar(42)); - QTest::newRow("short") << "Short" << "n" << qVariantFromValue(short(-43)); - QTest::newRow("ushort") << "UShort" << "q" << qVariantFromValue(ushort(44)); - QTest::newRow("int") << "Int" << "i" << QVariant(42); - QTest::newRow("uint") << "UInt" << "u" << QVariant(42U); - QTest::newRow("qlonglong") << "LongLong" << "x" << QVariant(Q_INT64_C(42)); - QTest::newRow("qulonglong") << "ULongLong" << "t" << QVariant(Q_UINT64_C(42)); - QTest::newRow("double") << "Double" << "d" << QVariant(2.5); - QTest::newRow("string") << "String" << "s" << QVariant("Hello, World!"); - - QTest::newRow("variant") << "Variant" << "v" << nest(QVariant("Hello again!")); - QTest::newRow("list") << "List" << "av" << QVariant(QVariantList() - << nest(42) - << nest(QString("foo")) - << nest(QByteArray("bar")) - << nest(nest(QString("baz")))); - QTest::newRow("stringlist") << "StringList" << "as" << QVariant(QStringList() << "Hello" << "world"); - QTest::newRow("bytearray") << "ByteArray" << "ay" << QVariant(QByteArray("foo")); - - QVariantMap map; - map["one"] = nest(1); // int - map["The answer to life, the Universe and everything"] = nest(42u); // uint - map["In the beginning..."] = nest(QString("There was nothing")); // string - map["but Unix came and said"] = nest(QByteArray("\"Hello, World\"")); // bytearray - map["two"] = nest(qVariantFromValue(short(2))); // short - QTest::newRow("map") << "Map" << "a{sv}" << QVariant(map); -} - -void tst_QDBusAbstractAdaptor::typeMatching() -{ - QObject obj; - new TypesInterface(&obj); - - QDBusConnection &con = QDBus::sessionBus(); - con.registerObject("/types", &obj); - - QFETCH(QString, basename); - QFETCH(QString, signature); - QFETCH(QVariant, value); - - QDBusMessage reply; - QDBusInterface *iface = con.findInterface(con.baseService(), "/types", "local.TypesInterface"); - - reply = iface->callWithArgs("method" + basename + '.' + signature, QVariantList() << value, - QDBusInterface::UseEventLoop); - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - - reply = iface->call(QDBusInterface::UseEventLoop, "retrieve" + basename); - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - QCOMPARE(reply.count(), 1); - - const QVariant &retval = reply.at(0); - QCOMPARE(retval.userType(), value.userType()); - QVERIFY(compare(retval, value)); - - iface->deleteLater(); -} - -QTEST_MAIN(tst_QDBusAbstractAdaptor) - -#include "tst_qdbusabstractadaptor.moc" diff --git a/test/qt/tst_qdbusconnection.cpp b/test/qt/tst_qdbusconnection.cpp deleted file mode 100644 index a887cd93..00000000 --- a/test/qt/tst_qdbusconnection.cpp +++ /dev/null @@ -1,257 +0,0 @@ -#include <qcoreapplication.h> -#include <qdebug.h> - -#include <QtTest/QtTest> - -#include <dbus/qdbus.h> - -class MyObject: public QObject -{ - Q_OBJECT -public slots: - void method(const QDBusMessage &msg) { serial = msg.serialNumber(); path = msg.path(); } - -public: - int serial; - QString path; - MyObject() : serial(0) { } -}; - -class tst_QDBusConnection: public QObject -{ - Q_OBJECT - -private slots: - void addConnection(); - void connect(); - void send(); - void sendAsync(); - void sendSignal(); - - void registerObject(); - -public: - bool callMethod(const QDBusConnection &conn, const QString &path); -}; - -class QDBusSpy: public QObject -{ - Q_OBJECT -public slots: - void handlePing(const QString &str) { args.clear(); args << str; } - void asyncReply(const QDBusMessage &msg) { args << msg; serial = msg.replySerialNumber(); } - -public: - QList<QVariant> args; - int serial; -}; - -void tst_QDBusConnection::sendSignal() -{ - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::signal("/org/kde/selftest", "org.kde.selftest", - "Ping"); - msg << QLatin1String("ping"); - - QVERIFY(con.send(msg)); - - QTest::qWait(1000); -} - -void tst_QDBusConnection::send() -{ - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.DBus", - "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); - - QDBusMessage reply = con.sendWithReply(msg); - - QCOMPARE(reply.count(), 1); - QCOMPARE(reply.at(0).typeName(), "QStringList"); - QVERIFY(reply.at(0).toStringList().contains(con.baseService())); -} - -void tst_QDBusConnection::sendAsync() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - QDBusSpy spy; - - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.DBus", - "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); - int msgId = con.sendWithReplyAsync(msg, &spy, SLOT(asyncReply(QDBusMessage))); - QVERIFY(msgId != 0); - - QTest::qWait(1000); - - QCOMPARE(spy.args.value(0).typeName(), "QStringList"); - QVERIFY(spy.args.at(0).toStringList().contains(con.baseService())); - QCOMPARE(spy.serial, msgId); -} - -void tst_QDBusConnection::connect() -{ - QDBusSpy spy; - - QDBusConnection &con = QDBus::sessionBus(); - - con.connect(con.baseService(), "/org/kde/selftest", "org.kde.selftest", "ping", &spy, - SLOT(handlePing(QString))); - - QDBusMessage msg = QDBusMessage::signal("/org/kde/selftest", "org.kde.selftest", - "ping"); - msg << QLatin1String("ping"); - - QVERIFY(con.send(msg)); - - QTest::qWait(1000); - - QCOMPARE(spy.args.count(), 1); - QCOMPARE(spy.args.at(0).toString(), QString("ping")); -} - -void tst_QDBusConnection::addConnection() -{ - { - QDBusConnection con = QDBusConnection::addConnection( - QDBusConnection::SessionBus, "bubu"); - - QVERIFY(con.isConnected()); - QVERIFY(!con.lastError().isValid()); - - QDBusConnection con2("foo"); - QVERIFY(!con2.isConnected()); - QVERIFY(!con2.lastError().isValid()); - - con2 = con; - QVERIFY(con.isConnected()); - QVERIFY(con2.isConnected()); - QVERIFY(!con.lastError().isValid()); - QVERIFY(!con2.lastError().isValid()); - } - - { - QDBusConnection con("bubu"); - QVERIFY(con.isConnected()); - QVERIFY(!con.lastError().isValid()); - } - - QDBusConnection::closeConnection("bubu"); - - { - QDBusConnection con("bubu"); - QVERIFY(!con.isConnected()); - QVERIFY(!con.lastError().isValid()); - } -} - -void tst_QDBusConnection::registerObject() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - // make sure nothing is using our paths: - QVERIFY(!callMethod(con, "/")); - QVERIFY(!callMethod(con, "/p1")); - QVERIFY(!callMethod(con, "/p2")); - QVERIFY(!callMethod(con, "/p1/q")); - QVERIFY(!callMethod(con, "/p1/q/r")); - - { - // register one object at root: - MyObject obj; - QVERIFY(con.registerObject("/", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/")); - QCOMPARE(obj.path, QString("/")); - } - // make sure it's gone - QVERIFY(!callMethod(con, "/")); - - { - // register one at an element: - MyObject obj; - QVERIFY(con.registerObject("/p1", &obj, QDBusConnection::ExportSlots)); - QVERIFY(!callMethod(con, "/")); - QVERIFY(callMethod(con, "/p1")); - QCOMPARE(obj.path, QString("/p1")); - - // re-register it somewhere else - QVERIFY(con.registerObject("/p2", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/p1")); - QCOMPARE(obj.path, QString("/p1")); - QVERIFY(callMethod(con, "/p2")); - QCOMPARE(obj.path, QString("/p2")); - } - // make sure it's gone - QVERIFY(!callMethod(con, "/p1")); - QVERIFY(!callMethod(con, "/p2")); - - { - // register at a deep path - MyObject obj; - QVERIFY(con.registerObject("/p1/q/r", &obj, QDBusConnection::ExportSlots)); - QVERIFY(!callMethod(con, "/")); - QVERIFY(!callMethod(con, "/p1")); - QVERIFY(!callMethod(con, "/p1/q")); - QVERIFY(callMethod(con, "/p1/q/r")); - QCOMPARE(obj.path, QString("/p1/q/r")); - } - // make sure it's gone - QVERIFY(!callMethod(con, "/p1/q/r")); - - { - MyObject obj; - QVERIFY(con.registerObject("/p1/q2", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/p1/q2")); - QCOMPARE(obj.path, QString("/p1/q2")); - - // try unregistering - con.unregisterObject("/p1/q2"); - QVERIFY(!callMethod(con, "/p1/q2")); - - // register it again - QVERIFY(con.registerObject("/p1/q2", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/p1/q2")); - QCOMPARE(obj.path, QString("/p1/q2")); - - // now try removing things around it: - con.unregisterObject("/p2"); - QVERIFY(callMethod(con, "/p1/q2")); // unrelated object shouldn't affect - - con.unregisterObject("/p1"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering just the parent shouldn't affect it - - con.unregisterObject("/p1/q2/r"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering non-existing child shouldn't affect it either - - con.unregisterObject("/p1/q"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering sibling (before) shouldn't affect - - con.unregisterObject("/p1/r"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering sibling (after) shouldn't affect - - // now remove it: - con.unregisterObject("/p1", QDBusConnection::UnregisterTree); - QVERIFY(!callMethod(con, "/p1/q2")); // we removed the full tree - } -} - -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, QDBusConnection::UseEventLoop); - - return reply.type() == QDBusMessage::ReplyMessage; -} - -QTEST_MAIN(tst_QDBusConnection) - -#include "tst_qdbusconnection.moc" - diff --git a/test/qt/tst_qdbusinterface.cpp b/test/qt/tst_qdbusinterface.cpp deleted file mode 100644 index a63b8e0b..00000000 --- a/test/qt/tst_qdbusinterface.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/* -*- C++ -*- - * - * Copyright (C) 2006 Trolltech AS. All rights reserved. - * Author: Thiago Macieira <thiago.macieira@trolltech.com> - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -#include <qcoreapplication.h> -#include <qmetatype.h> -#include <QtTest/QtTest> - -#include <dbus/qdbus.h> -#include <QtCore/qvariant.h> - -#include "common.h" - -Q_DECLARE_METATYPE(QVariantList) - -#define TEST_INTERFACE_NAME "com.trolltech.QtDBus.MyObject" -#define TEST_SIGNAL_NAME "somethingHappened" - -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() - { - QObject *subObject = new QObject(this); - subObject->setObjectName("subObject"); - } - -public slots: - - void ping(const QDBusMessage &msg) - { - QDBusMessage reply = QDBusMessage::methodReply(msg); - reply << static_cast<QList<QVariant> >(msg); - if (!msg.connection().send(reply)) - exit(1); - } -}; - -class Spy: public QObject -{ - Q_OBJECT -public: - QString received; - int count; - - Spy() : count(0) - { } - -public slots: - void spySlot(const QString& arg) - { - received = arg; - ++count; - } -}; - -// helper function -void emitSignal(const QString &interface, const QString &name, const QString &arg) -{ - QDBusMessage msg = QDBusMessage::signal("/", interface, name); - msg << arg; - QDBus::sessionBus().send(msg); - - QTest::qWait(200); -} - -class tst_QDBusInterface: public QObject -{ - Q_OBJECT - MyObject obj; -private slots: - void initTestCase(); - - void call_data(); - void call(); - - void introspect(); - - void signal(); -}; - -void tst_QDBusInterface::initTestCase() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - con.registerObject("/", &obj, QDBusConnection::ExportAdaptors | QDBusConnection::ExportSlots | - QDBusConnection::ExportChildObjects); -} - -void tst_QDBusInterface::call_data() -{ - QTest::addColumn<QString>("method"); - QTest::addColumn<QVariantList>("input"); - QTest::addColumn<QVariantList>("output"); - - QVariantList input; - QTest::newRow("empty") << "ping" << input << input; - - input << qVariantFromValue(1); - QTest::newRow("int") << "ping" << input << input; - QTest::newRow("int-int") << "ping.i" << input << input; - QTest::newRow("int-int16") << "ping.n" << input << (QVariantList() << qVariantFromValue(short(1))); - - // try doing some conversions - QVariantList output; - output << qVariantFromValue(1U); - QTest::newRow("int-uint") << "ping.u" << input << output; - -#if QT_VERSION >= 0x040200 - output.clear(); - output << qVariantFromValue(ushort(1)); - QTest::newRow("int-uint16") << "ping.q" << input << output; -#endif - - QTest::newRow("int-int64") << "ping.x" << input << (QVariantList() << qVariantFromValue(Q_INT64_C(1))); - QTest::newRow("int-uint64") << "ping.t" << input << (QVariantList() << qVariantFromValue(Q_UINT64_C(1))); - QTest::newRow("int-double") << "ping.d" << input << (QVariantList() << qVariantFromValue(1.0)); - - output.clear(); - output << QString("1"); - QTest::newRow("int-string") << "ping.s" << input << output; - - // try from string now - input = output; - QTest::newRow("string") << "ping" << input << output; - QTest::newRow("string-string") << "ping.s" << input << output; - - output.clear(); - output << qVariantFromValue(1); - QTest::newRow("string-int") << "ping.i" << input << output; - -#if QT_VERSION >= 0x040200 - output.clear(); - output << qVariantFromValue(short(1)); - QTest::newRow("string-int16") << "ping.n" << input << input; -#endif - - output.clear(); - output << qVariantFromValue(1U); - QTest::newRow("string-uint") << "ping.u" << input << output; - -#if QT_VERSION >= 0x040200 - output.clear(); - output << qVariantFromValue(ushort(1)); - QTest::newRow("string-uint16") << "ping.q" << input << output; -#endif - - QTest::newRow("string-int64") << "ping.x" << input << (QVariantList() << qVariantFromValue(1LL)); - QTest::newRow("string-uint64") << "ping.t" << input << (QVariantList() << qVariantFromValue(1ULL)); - QTest::newRow("string-double") << "ping.d" << input << (QVariantList() << qVariantFromValue(1.0)); - - // two args (must be strings!) - input.clear(); - input << QString("Hello") << QString("World"); - output = input; - QTest::newRow("two-strings") << "ping" << input << output; - QTest::newRow("two-strings") << "ping.ss" << input << output; - - // this should drop one of the arguments - output.removeLast(); - QTest::newRow("last-dropped") << "ping.s" << input << output; -} - -void tst_QDBusInterface::call() -{ - QDBusConnection &con = QDBus::sessionBus(); - QDBusInterface *iface = con.findInterface(con.baseService(), QLatin1String("/"), - TEST_INTERFACE_NAME); - - QFETCH(QString, method); - QFETCH(QVariantList, input); - QFETCH(QVariantList, output); - - QDBusMessage reply; - // try first callWithArgs: - reply = iface->callWithArgs(method, input, QDBusInterface::UseEventLoop); - - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - if (!output.isEmpty()) { - QCOMPARE(reply.count(), output.count()); - QVERIFY(compare(reply, output)); - } - - // try the template methods - if (input.isEmpty()) - reply = iface->call(QDBusInterface::UseEventLoop, method); - else if (input.count() == 1) - switch (input.at(0).type()) - { - case QVariant::Int: - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toInt()); - break; - - case QVariant::UInt: - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toUInt()); - break; - - case QVariant::String: - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toString()); - break; - - default: - QFAIL("Unknown type. Please update the test case"); - break; - } - else - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toString(), input.at(1).toString()); - - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - if (!output.isEmpty()) { - QCOMPARE(reply.count(), output.count()); - QVERIFY(compare(reply, output)); - } -} - -void tst_QDBusInterface::introspect() -{ - QDBusConnection &con = QDBus::sessionBus(); - QDBusInterface *iface = con.findInterface(QDBus::sessionBus().baseService(), QLatin1String("/"), - TEST_INTERFACE_NAME); - - const QMetaObject *mo = iface->metaObject(); - - qDebug("Improve to a better testcase of QDBusMetaObject"); - QCOMPARE(mo->methodCount() - mo->methodOffset(), 3); - QVERIFY(mo->indexOfSignal(TEST_SIGNAL_NAME "(QString)") != -1); - - QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 1); - QVERIFY(mo->indexOfProperty("prop1") != -1); - - iface->deleteLater(); -} - -void tst_QDBusInterface::signal() -{ - QDBusConnection &con = QDBus::sessionBus(); - QDBusInterface *iface = con.findInterface(con.baseService(), QLatin1String("/"), - TEST_INTERFACE_NAME); - - QString arg = "So long and thanks for all the fish"; - { - Spy spy; - spy.connect(iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); - - emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); - QCOMPARE(spy.count, 1); - QCOMPARE(spy.received, arg); - } - - iface->deleteLater(); -} - -QTEST_MAIN(tst_QDBusInterface) - -#include "tst_qdbusinterface.moc" - diff --git a/test/qt/tst_qdbusmarshall.cpp b/test/qt/tst_qdbusmarshall.cpp deleted file mode 100644 index 306f7b6a..00000000 --- a/test/qt/tst_qdbusmarshall.cpp +++ /dev/null @@ -1,342 +0,0 @@ -#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" diff --git a/test/qt/tst_qdbusxmlparser.cpp b/test/qt/tst_qdbusxmlparser.cpp deleted file mode 100644 index bf1ddec5..00000000 --- a/test/qt/tst_qdbusxmlparser.cpp +++ /dev/null @@ -1,578 +0,0 @@ -/* -*- C++ -*- - * - * Copyright (C) 2006 Trolltech AS. All rights reserved. - * Author: Thiago Macieira <thiago.macieira@trolltech.com> - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -#include <qcoreapplication.h> -#include <qmetatype.h> -#include <QtTest/QtTest> - -#include <dbus/qdbus.h> - -#define USE_PRIVATE_CODE -#include "common.h" - -class tst_QDBusXmlParser: public QObject -{ - Q_OBJECT - -private: - void parsing_common(const QString&); - -private slots: - void parsing_data(); - void parsing(); - void parsingWithDoctype_data(); - void parsingWithDoctype(); - - void objectWithContent_data(); - void objectWithContent(); - - void methods_data(); - void methods(); - void signals__data(); - void signals_(); - void properties_data(); - void properties(); -}; - -void tst_QDBusXmlParser::parsing_data() -{ - QTest::addColumn<QString>("xmlData"); - QTest::addColumn<int>("interfaceCount"); - QTest::addColumn<int>("objectCount"); - - QTest::newRow("null") << QString() << 0 << 0; - QTest::newRow("empty") << QString("") << 0 << 0; - - QTest::newRow("junk") << "<junk/>" << 0 << 0; - QTest::newRow("interface-inside-junk") << "<junk><interface name=\"iface.iface1\" /></junk>" - << 0 << 0; - QTest::newRow("object-inside-junk") << "<junk><node name=\"obj1\" /></junk>" - << 0 << 0; - - QTest::newRow("zero-interfaces") << "<node/>" << 0 << 0; - QTest::newRow("one-interface") << "<node><interface name=\"iface.iface1\" /></node>" << 1 << 0; - - - QTest::newRow("two-interfaces") << "<node><interface name=\"iface.iface1\" />" - "<interface name=\"iface.iface2\"></node>" - << 2 << 0; - - - QTest::newRow("one-object") << "<node><node name=\"obj1\"/></node>" << 0 << 1; - QTest::newRow("two-objects") << "<node><node name=\"obj1\"/><node name=\"obj2\"></node>" << 0 << 2; - - QTest::newRow("i1o1") << "<node><interface name=\"iface.iface1\"><node name=\"obj1\"></node>" << 1 << 1; - -} - -void tst_QDBusXmlParser::parsing_common(const QString &xmlData) -{ - QDBusIntrospection::ObjectTree obj = - QDBusIntrospection::parseObjectTree(xmlData, "local.testing", "/"); - QFETCH(int, interfaceCount); - QFETCH(int, objectCount); - QCOMPARE(obj.interfaces.count(), interfaceCount); - QCOMPARE(obj.childObjects.count(), objectCount); - - // also verify the naming - int i = 0; - foreach (QString name, obj.interfaces) - QCOMPARE(name, QString("iface.iface%1").arg(++i)); - - i = 0; - foreach (QString name, obj.childObjects) - QCOMPARE(name, QString("obj%1").arg(++i)); -} - -void tst_QDBusXmlParser::parsing() -{ - QFETCH(QString, xmlData); - - parsing_common(xmlData); -} - -void tst_QDBusXmlParser::parsingWithDoctype_data() -{ - parsing_data(); -} - -void tst_QDBusXmlParser::parsingWithDoctype() -{ - QString docType = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" - "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"; - QFETCH(QString, xmlData); - - parsing_common(docType + xmlData); -} - -void tst_QDBusXmlParser::objectWithContent_data() -{ - QTest::addColumn<QString>("xmlData"); - QTest::addColumn<QString>("probedObject"); - QTest::addColumn<int>("interfaceCount"); - QTest::addColumn<int>("objectCount"); - - QTest::newRow("zero") << "<node><node name=\"obj\"/></node>" << "obj" << 0 << 0; - - QString xmlData = "<node><node name=\"obj\">" - "<interface name=\"iface.iface1\" />" - "</node></node>"; - QTest::newRow("one-interface") << xmlData << "obj" << 1 << 0; - QTest::newRow("one-interface2") << xmlData << "obj2" << 0 << 0; - - xmlData = "<node><node name=\"obj\">" - "<interface name=\"iface.iface1\" />" - "<interface name=\"iface.iface2\" />" - "</node></node>"; - QTest::newRow("two-interfaces") << xmlData << "obj" << 2 << 0; - QTest::newRow("two-interfaces2") << xmlData << "obj2" << 0 << 0; - - xmlData = "<node><node name=\"obj\">" - "<interface name=\"iface.iface1\" />" - "<interface name=\"iface.iface2\" />" - "</node><node name=\"obj2\">" - "<interface name=\"iface.iface1\" />" - "</node></node>"; - QTest::newRow("two-nodes-two-interfaces") << xmlData << "obj" << 2 << 0; - QTest::newRow("two-nodes-one-interface") << xmlData << "obj2" << 1 << 0; - - xmlData = "<node><node name=\"obj\">" - "<node name=\"obj1\" />" - "</node></node>"; - QTest::newRow("one-object") << xmlData << "obj" << 0 << 1; - QTest::newRow("one-object2") << xmlData << "obj2" << 0 << 0; - - xmlData = "<node><node name=\"obj\">" - "<node name=\"obj1\" />" - "<node name=\"obj2\" />" - "</node></node>"; - QTest::newRow("two-objects") << xmlData << "obj" << 0 << 2; - QTest::newRow("two-objects2") << xmlData << "obj2" << 0 << 0; - - xmlData = "<node><node name=\"obj\">" - "<node name=\"obj1\" />" - "<node name=\"obj2\" />" - "</node><node name=\"obj2\">" - "<node name=\"obj1\" />" - "</node></node>"; - QTest::newRow("two-nodes-two-objects") << xmlData << "obj" << 0 << 2; - QTest::newRow("two-nodes-one-object") << xmlData << "obj2" << 0 << 1; -} - -void tst_QDBusXmlParser::objectWithContent() -{ - QFETCH(QString, xmlData); - QFETCH(QString, probedObject); - - QDBusIntrospection::ObjectTree tree = - QDBusIntrospection::parseObjectTree(xmlData, "local.testing", "/"); - - const ObjectMap &om = tree.childObjectData; - - if (om.contains(probedObject)) { - const QSharedDataPointer<QDBusIntrospection::ObjectTree>& obj = om.value(probedObject); - QVERIFY(obj != 0); - - QFETCH(int, interfaceCount); - QFETCH(int, objectCount); - - QCOMPARE(obj->interfaces.count(), interfaceCount); - QCOMPARE(obj->childObjects.count(), objectCount); - - // verify the object names - int i = 0; - foreach (QString name, obj->interfaces) - QCOMPARE(name, QString("iface.iface%1").arg(++i)); - - i = 0; - foreach (QString name, obj->childObjects) - QCOMPARE(name, QString("obj%1").arg(++i)); - } -} - -void tst_QDBusXmlParser::methods_data() -{ - QTest::addColumn<QString>("xmlDataFragment"); - QTest::addColumn<MethodMap>("methodMap"); - - MethodMap map; - QTest::newRow("no-methods") << QString() << map; - - // one method without arguments - QDBusIntrospection::Method method; - method.name = "Foo"; - map << method; - QTest::newRow("one-method") << "<method name=\"Foo\"/>" << map; - - // add another method without arguments - method.name = "Bar"; - map << method; - QTest::newRow("two-methods") << "<method name=\"Foo\"/>" - "<method name=\"Bar\"/>" - << map; - - // invert the order of the XML declaration - QTest::newRow("two-methods-inverse") << "<method name=\"Bar\"/>" - "<method name=\"Foo\"/>" - << map; - - // add a third, with annotations - method.name = "Baz"; - method.annotations.insert("foo.testing", "nothing to see here"); - map << method; - QTest::newRow("method-with-annotation") << - "<method name=\"Foo\"/>" - "<method name=\"Bar\"/>" - "<method name=\"Baz\"><annotation name=\"foo.testing\" value=\"nothing to see here\"></method>" - << map; - - // arguments - map.clear(); - method.annotations.clear(); - - method.name = "Method"; - method.inputArgs << arg("s"); - map << method; - QTest::newRow("one-in") << - "<method name=\"Method\">" - "<arg type=\"s\" direction=\"in\"/>" - "</method>" << map; - - // two arguments - method.inputArgs << arg("v"); - map.clear(); - map << method; - QTest::newRow("two-in") << - "<method name=\"Method\">" - "<arg type=\"s\" direction=\"in\"/>" - "<arg type=\"v\" direction=\"in\"/>" - "</method>" << map; - - // one invalid arg - QTest::newRow("two-in-one-invalid") << - "<method name=\"Method\">" - "<arg type=\"s\" direction=\"in\"/>" - "<arg type=\"~\" name=\"invalid\" direction=\"in\"/>" // this line should be ignored - "<arg type=\"v\" direction=\"in\"/>" - "</method>" << map; - - // one out argument - method.inputArgs.clear(); - method.outputArgs << arg("s"); - map.clear(); - map << method; - QTest::newRow("one-out") << - "<method name=\"Method\">" - "<arg type=\"s\" direction=\"out\"/>" - "</method>" << map; - - // two in and one out - method.inputArgs << arg("s") << arg("v"); - map.clear(); - map << method; - QTest::newRow("two-in-one-out") << - "<method name=\"Method\">" - "<arg type=\"s\" direction=\"in\"/>" - "<arg type=\"v\" direction=\"in\"/>" - "<arg type=\"s\" direction=\"out\"/>" - "</method>" << map; - - // let's try an arg with name - method.outputArgs.clear(); - method.inputArgs.clear(); - method.inputArgs << arg("s", "foo"); - map.clear(); - map << method; - QTest::newRow("one-in-with-name") << - "<method name=\"Method\">" - "<arg type=\"s\" name=\"foo\" direction=\"in\"/>" - "</method>" << map; - - // two args with name - method.inputArgs << arg("i", "bar"); - map.clear(); - map << method; - QTest::newRow("two-in-with-name") << - "<method name=\"Method\">" - "<arg type=\"s\" name=\"foo\" direction=\"in\"/>" - "<arg type=\"i\" name=\"bar\" direction=\"in\"/>" - "</method>" << map; - - // one complex - map.clear(); - method = QDBusIntrospection::Method(); - - // Method1(in STRING arg1, in BYTE arg2, out ARRAY of STRING) - method.inputArgs << arg("s", "arg1") << arg("y", "arg2"); - method.outputArgs << arg("as"); - method.name = "Method1"; - map << method; - - // Method2(in ARRAY of DICT_ENTRY of (STRING,VARIANT) variantMap, in UINT32 index, - // out STRING key, out VARIANT value) - // with annotation "foo.equivalent":"QVariantMap" - method = QDBusIntrospection::Method(); - method.inputArgs << arg("a{sv}", "variantMap") << arg("u", "index"); - method.outputArgs << arg("s", "key") << arg("v", "value"); - method.annotations.insert("foo.equivalent", "QVariantMap"); - method.name = "Method2"; - map << method; - - QTest::newRow("complex") << - "<method name=\"Method1\">" - "<arg name=\"arg1\" type=\"s\" direction=\"in\"/>" - "<arg name=\"arg2\" type=\"y\" direction=\"in\"/>" - "<arg type=\"as\" direction=\"out\"/>" - "</method>" - "<method name=\"Method2\">" - "<arg name=\"variantMap\" type=\"a{sv}\" direction=\"in\"/>" - "<arg name=\"index\" type=\"u\" direction=\"in\"/>" - "<arg name=\"key\" type=\"s\" direction=\"out\"/>" - "<arg name=\"value\" type=\"v\" direction=\"out\"/>" - "<annotation name=\"foo.equivalent\" value=\"QVariantMap\"/>" - "</method>" << map; -} - -void tst_QDBusXmlParser::methods() -{ - QString xmlHeader = "<node>" - "<interface name=\"iface.iface1\">", - xmlFooter = "</interface>" - "</node>"; - - QFETCH(QString, xmlDataFragment); - - QDBusIntrospection::Interface iface = - QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); - - QCOMPARE(iface.name, QString("iface.iface1")); - - QFETCH(MethodMap, methodMap); - MethodMap parsedMap = iface.methods; - - QCOMPARE(methodMap.count(), parsedMap.count()); - QCOMPARE(methodMap, parsedMap); -} - -void tst_QDBusXmlParser::signals__data() -{ - QTest::addColumn<QString>("xmlDataFragment"); - QTest::addColumn<SignalMap>("signalMap"); - - SignalMap map; - QTest::newRow("no-signals") << QString() << map; - - // one signal without arguments - QDBusIntrospection::Signal signal; - signal.name = "Foo"; - map << signal; - QTest::newRow("one-signal") << "<signal name=\"Foo\"/>" << map; - - // add another signal without arguments - signal.name = "Bar"; - map << signal; - QTest::newRow("two-signals") << "<signal name=\"Foo\"/>" - "<signal name=\"Bar\"/>" - << map; - - // invert the order of the XML declaration - QTest::newRow("two-signals-inverse") << "<signal name=\"Bar\"/>" - "<signal name=\"Foo\"/>" - << map; - - // add a third, with annotations - signal.name = "Baz"; - signal.annotations.insert("foo.testing", "nothing to see here"); - map << signal; - QTest::newRow("signal-with-annotation") << - "<signal name=\"Foo\"/>" - "<signal name=\"Bar\"/>" - "<signal name=\"Baz\"><annotation name=\"foo.testing\" value=\"nothing to see here\"></signal>" - << map; - - // one out argument - map.clear(); - signal.annotations.clear(); - signal.outputArgs << arg("s"); - signal.name = "Signal"; - map.clear(); - map << signal; - QTest::newRow("one-out") << - "<signal name=\"Signal\">" - "<arg type=\"s\" direction=\"out\"/>" - "</signal>" << map; - - // without saying which direction it is - QTest::newRow("one-out-no-direction") << - "<signal name=\"Signal\">" - "<arg type=\"s\"/>" - "</signal>" << map; - - // two args with name - signal.outputArgs << arg("i", "bar"); - map.clear(); - map << signal; - QTest::newRow("two-out-with-name") << - "<signal name=\"Signal\">" - "<arg type=\"s\" direction=\"out\"/>" - "<arg type=\"i\" name=\"bar\"/>" - "</signal>" << map; - - // one complex - map.clear(); - signal = QDBusIntrospection::Signal(); - - // Signal1(out ARRAY of STRING) - signal.outputArgs << arg("as"); - signal.name = "Signal1"; - map << signal; - - // Signal2(out STRING key, out VARIANT value) - // with annotation "foo.equivalent":"QVariantMap" - signal = QDBusIntrospection::Signal(); - signal.outputArgs << arg("s", "key") << arg("v", "value"); - signal.annotations.insert("foo.equivalent", "QVariantMap"); - signal.name = "Signal2"; - map << signal; - - QTest::newRow("complex") << - "<signal name=\"Signal1\">" - "<arg type=\"as\" direction=\"out\"/>" - "</signal>" - "<signal name=\"Signal2\">" - "<arg name=\"key\" type=\"s\" direction=\"out\"/>" - "<arg name=\"value\" type=\"v\" direction=\"out\"/>" - "<annotation name=\"foo.equivalent\" value=\"QVariantMap\"/>" - "</signal>" << map; -} - -void tst_QDBusXmlParser::signals_() -{ - QString xmlHeader = "<node>" - "<interface name=\"iface.iface1\">", - xmlFooter = "</interface>" - "</node>"; - - QFETCH(QString, xmlDataFragment); - - QDBusIntrospection::Interface iface = - QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); - - QCOMPARE(iface.name, QString("iface.iface1")); - - QFETCH(SignalMap, signalMap); - SignalMap parsedMap = iface.signals_; - - QCOMPARE(signalMap.count(), parsedMap.count()); - QCOMPARE(signalMap, parsedMap); -} - -void tst_QDBusXmlParser::properties_data() -{ - QTest::addColumn<QString>("xmlDataFragment"); - QTest::addColumn<PropertyMap>("propertyMap"); - - PropertyMap map; - QTest::newRow("no-signals") << QString() << map; - - // one readable signal - QDBusIntrospection::Property prop; - prop.name = "foo"; - prop.type = "s"; - prop.access = QDBusIntrospection::Property::Read; - map << prop; - QTest::newRow("one-readable") << "<property name=\"foo\" type=\"s\" access=\"read\"/>" << map; - - // one writable signal - prop.access = QDBusIntrospection::Property::Write; - map.clear(); - map << prop; - QTest::newRow("one-writable") << "<property name=\"foo\" type=\"s\" access=\"write\"/>" << map; - - // one read- & writable signal - prop.access = QDBusIntrospection::Property::ReadWrite; - map.clear(); - map << prop; - QTest::newRow("one-read-writable") << "<property name=\"foo\" type=\"s\" access=\"readwrite\"/>" - << map; - - // two, mixed properties - prop.name = "bar"; - prop.type = "i"; - prop.access = QDBusIntrospection::Property::Read; - map << prop; - QTest::newRow("two") << - "<property name=\"foo\" type=\"s\" access=\"readwrite\"/>" - "<property name=\"bar\" type=\"i\" access=\"read\"/>" << map; - - // invert the order of the declaration - QTest::newRow("two") << - "<property name=\"bar\" type=\"i\" access=\"read\"/>" - "<property name=\"foo\" type=\"s\" access=\"readwrite\"/>" << map; - - // add a third with annotations - prop.name = "baz"; - prop.type = "as"; - prop.access = QDBusIntrospection::Property::Write; - prop.annotations.insert("foo.annotation", "Hello, World"); - prop.annotations.insert("foo.annotation2", "Goodbye, World"); - map << prop; - QTest::newRow("complex") << - "<property name=\"bar\" type=\"i\" access=\"read\"/>" - "<property name=\"baz\" type=\"as\" access=\"write\">" - "<annotation name=\"foo.annotation\" value=\"Hello, World\" />" - "<annotation name=\"foo.annotation2\" value=\"Goodbye, World\" />" - "<property name=\"foo\" type=\"s\" access=\"readwrite\"/>" << map; - - // and now change the order - QTest::newRow("complex2") << - "<property name=\"baz\" type=\"as\" access=\"write\">" - "<annotation name=\"foo.annotation2\" value=\"Goodbye, World\" />" - "<annotation name=\"foo.annotation\" value=\"Hello, World\" />" - "<property name=\"bar\" type=\"i\" access=\"read\"/>" - "<property name=\"foo\" type=\"s\" access=\"readwrite\"/>" << map; -} - -void tst_QDBusXmlParser::properties() -{ - QString xmlHeader = "<node>" - "<interface name=\"iface.iface1\">", - xmlFooter = "</interface>" - "</node>"; - - QFETCH(QString, xmlDataFragment); - - QDBusIntrospection::Interface iface = - QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); - - QCOMPARE(iface.name, QString("iface.iface1")); - - QFETCH(PropertyMap, propertyMap); - PropertyMap parsedMap = iface.properties; - - QCOMPARE(propertyMap.count(), parsedMap.count()); - QCOMPARE(propertyMap, parsedMap); -} - -QTEST_MAIN(tst_QDBusXmlParser) - -#include "tst_qdbusxmlparser.moc" |