summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@trolltech.com>2006-03-28 18:58:58 +0000
committerThiago Macieira <thiago.macieira@trolltech.com>2006-03-28 18:58:58 +0000
commit164cbc6352ab3d45175613849863e5b0d4da2bab (patch)
treeda097d03b2fcafc4ccc316e8598c4e7d99388d1f
parentdb8ded6d988876b2207e3be549024000e873b662 (diff)
* test/qt/*: Sync with KDE Subversion revision 523647.
Update the testcases to the new API. Remove testcases for classes that are no longer public or have been removed.
-rw-r--r--ChangeLog6
-rw-r--r--test/qt/Makefile.am12
-rw-r--r--test/qt/common.h133
-rw-r--r--test/qt/ping.cpp333
-rw-r--r--test/qt/qpong.cpp11
-rw-r--r--test/qt/tst_qdbusabstractadaptor.cpp579
-rw-r--r--test/qt/tst_qdbusconnection.cpp90
-rw-r--r--test/qt/tst_qdbusinterface.cpp104
-rw-r--r--test/qt/tst_qdbusobject.cpp207
-rw-r--r--test/qt/tst_qdbustype.cpp273
-rw-r--r--test/qt/tst_qdbusxmlparser.cpp578
11 files changed, 843 insertions, 1483 deletions
diff --git a/ChangeLog b/ChangeLog
index 8b1b98b..04b5aa9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2006-03-28 Thiago Macieira <thiago.macieira@trolltech.com>
+ * test/qt/*: Sync with KDE Subversion revision 523647.
+ Update the testcases to the new API. Remove testcases for
+ classes that are no longer public or have been removed.
+
+2006-03-28 Thiago Macieira <thiago.macieira@trolltech.com>
+
* qt/*:
* dbus/qdbus.h: Sync with KDE Subversion revision
523647. Hopefully, this will be the last of the
diff --git a/test/qt/Makefile.am b/test/qt/Makefile.am
index 94283eb..f7a8efa 100644
--- a/test/qt/Makefile.am
+++ b/test/qt/Makefile.am
@@ -1,33 +1,26 @@
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=qdbustype qdbusxmlparser qdbusconnection qpong ping qdbusobject qdbusinterface qdbusabstractadaptor hal
+TEST_BINARIES=qdbusconnection qpong ping qdbusinterface qdbusabstractadaptor hal
TESTS=
else
TEST_BINARIES=
TESTS=
endif
-
noinst_PROGRAMS= $(TEST_BINARIES)
qpong_SOURCES= qpong.cpp
ping_SOURCES= ping.cpp
qdbusconnection_SOURCES= tst_qdbusconnection.cpp
-qdbusobject_SOURCES= tst_qdbusobject.cpp
qdbusinterface_SOURCES= tst_qdbusinterface.cpp
-qdbustype_SOURCES= tst_qdbustype.cpp
-qdbusxmlparser_SOURCES= tst_qdbusxmlparser.cpp common.h
qdbusabstractadaptor_SOURCES= tst_qdbusabstractadaptor.cpp common.h
hal_SOURCES = tst_hal.cpp
qpong.o: qpong.moc
ping.o: ping.moc
tst_qdbusconnection.o: tst_qdbusconnection.moc
-tst_qdbusobject.o: tst_qdbusobject.moc
tst_qdbusinterface.o: tst_qdbusinterface.moc
-tst_qdbustype.o: tst_qdbustype.moc
-tst_qdbusxmlparser.o: tst_qdbusxmlparser.moc
tst_qdbusabstractadaptor.o: tst_qdbusabstractadaptor.moc
tst_hal.o: tst_hal.moc
@@ -38,4 +31,5 @@ TEST_LIBS=$(DBUS_QTESTLIB_LIBS) $(top_builddir)/qt/libdbus-qt4-1.la
LDADD=$(TEST_LIBS)
-CLEANFILES=tst_qdbusconnection.moc
+clean-local:
+ -rm *.moc
diff --git a/test/qt/common.h b/test/qt/common.h
index e3c78bd..943d3d9 100644
--- a/test/qt/common.h
+++ b/test/qt/common.h
@@ -1,3 +1,17 @@
+#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>)
+#if 0
+#include "../qdbusintrospection_p.h"
+
// just to make it easier:
typedef QDBusIntrospection::Interfaces InterfaceMap;
typedef QDBusIntrospection::Objects ObjectMap;
@@ -17,7 +31,7 @@ Q_DECLARE_METATYPE(PropertyMap)
inline QDBusIntrospection::Argument arg(const char* type, const char *name = 0)
{
QDBusIntrospection::Argument retval;
- retval.type = QDBusType(type);
+ retval.type = QLatin1String(type);
retval.name = QLatin1String(name);
return retval;
}
@@ -40,12 +54,10 @@ 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.toString(QDBusType::ConventionalNames))
- .arg(arg.name);
+ .arg(arg.type, arg.name);
foreach (QDBusIntrospection::Argument arg, m.outputArgs)
result += QString("out %1 %2, ")
- .arg(arg.type.toString(QDBusType::ConventionalNames))
- .arg(arg.name);
+ .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());
@@ -59,8 +71,7 @@ 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.toString(QDBusType::ConventionalNames))
- .arg(arg.name);
+ .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());
@@ -78,7 +89,7 @@ QString printable(const QDBusIntrospection::Property& p)
result = "property write %1 %2, ";
else
result = "property readwrite %1 %2, ";
- result = result.arg(p.type.toString(QDBusType::ConventionalNames)).arg(p.name);
+ result = result.arg(p.type, p.name);
AnnotationsMap::const_iterator it = p.annotations.begin();
for ( ; it != p.annotations.end(); ++it)
@@ -125,3 +136,109 @@ namespace QTest {
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 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 < 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/ping.cpp b/test/qt/ping.cpp
index 1777a80..1cdbfca 100644
--- a/test/qt/ping.cpp
+++ b/test/qt/ping.cpp
@@ -1,8 +1,9 @@
-#define DBUS_API_SUBJECT_TO_CHANGE
#include <QtCore/QtCore>
#include <QtTest/QtTest>
#include <dbus/qdbus.h>
+#include "common.h"
+
class Ping: public QObject
{
Q_OBJECT
@@ -12,8 +13,23 @@ public slots:
void cleanupTestCase();
private slots:
- void sendPing_data();
- void sendPing();
+ 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;
@@ -31,75 +47,181 @@ void Ping::cleanupTestCase()
proc.close();
}
-Q_DECLARE_METATYPE(QVariant)
-
-void Ping::sendPing_data()
+void Ping::sendBasic_data()
{
QTest::addColumn<QVariant>("value");
+ QTest::addColumn<QString>("sig");
- QTest::newRow("string") << QVariant("ping");
- QTest::newRow("int") << QVariant(1);
- QTest::newRow("double") << QVariant(42.5);
+ // 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";
+}
+void Ping::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 Ping::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);
-
- QList<QVariant> ints;
- ints << 42 << -43 << 44 << 45;
- QTest::newRow("intlist") << QVariant(ints);
-
- QList<QVariant> uints;
- uints << uint(12) << uint(13) << uint(14);
- QTest::newRow("uintlist") << QVariant(uints);
-
- QList<QVariant> llints;
- llints << Q_INT64_C(99) << Q_INT64_C(-100);
- QTest::newRow("llintlist") << QVariant(llints);
-
- QList<QVariant> ullints;
- ullints << Q_UINT64_C(66) << Q_UINT64_C(67);
- QTest::newRow("ullintlist") << QVariant(ullints);
-
- QList<QVariant> doubles;
- doubles << 1.2 << 2.2 << 4.4;
- QTest::newRow("doublelist") << QVariant(doubles);
-
- QList<QVariant> stackedInts;
- stackedInts << 4 << ints << 5;
- QTest::newRow("stackedInts") << QVariant(stackedInts);
-
- QList<QVariant> stackedUInts;
- stackedUInts << uint(3) << uints << uint(4);
- QTest::newRow("stackedUInts") << QVariant(stackedUInts);
-
- QList<QVariant> stackedLlints;
- stackedLlints << Q_INT64_C(49) << llints << Q_INT64_C(-160);
- QTest::newRow("stackedLlintlist") << QVariant(stackedLlints);
-
- QList<QVariant> stackedUllints;
- stackedUllints << Q_UINT64_C(56) << ullints << Q_UINT64_C(57);
- QTest::newRow("stackedullintlist") << QVariant(stackedUllints);
-
- QList<QVariant> stackedDoubles;
- stackedDoubles << 6.2 << doubles << 6.4;
- QTest::newRow("stackedDoublelist") << QVariant(stackedDoubles);
-
- QMap<QString, QVariant> map;
- map["foo"] = "bar";
- map["kde"] = "great";
- QTest::newRow("map") << QVariant(map);
-
- QList<QVariant> byteArrays;
- byteArrays << QByteArray("test1") << QByteArray("t2");
- QTest::newRow("bytearray") << QVariant(byteArrays);
-
- QList<QVariant> lists;
- lists << QVariant(byteArrays) << QVariant(byteArrays);
- QTest::newRow("listoflists") << QVariant(lists);
+ QTest::newRow("stringlist") << QVariant(strings) << "as";
+
+ QByteArray bytearray(""); // empty, not null
+ QTest::newRow("emptybytearray") << QVariant(bytearray) << "ay";
+ bytearray = "foo";
+ QTest::newRow("bytearray") << 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 Ping::sendArrayOfArrays_data()
+{
+ sendArrays_data();
+}
+
+void Ping::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 Ping::sendStringMapOfMap_data()
+{
+ sendStringMap_data();
+}
+
+void Ping::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 Ping::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 Ping::sendPing()
+void Ping::sendArrays()
{
QFETCH(QVariant, value);
@@ -115,9 +237,90 @@ void Ping::sendPing()
// qDebug() << reply;
QCOMPARE(reply.count(), msg.count());
+ QTEST(reply.signature(), "sig");
for (int i = 0; i < reply.count(); ++i)
- QCOMPARE(reply.at(i), msg.at(i));
+ QVERIFY(compare(reply.at(i), msg.at(i)));
}
+void Ping::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 Ping::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 Ping::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 + "}}");
+
+ QEXPECT_FAIL("", "libdbus returns an empty set for un unknown reason", Abort);
+ for (int i = 0; i < reply.count(); ++i)
+ QVERIFY(compare(reply.at(i), msg.at(i)));
+}
+
+
QTEST_MAIN(Ping)
#include "ping.moc"
diff --git a/test/qt/qpong.cpp b/test/qt/qpong.cpp
index 38e5c78..4a3e976 100644
--- a/test/qt/qpong.cpp
+++ b/test/qt/qpong.cpp
@@ -1,6 +1,6 @@
-#define DBUS_API_SUBJECT_TO_CHANGE
#include <QtCore/QtCore>
#include <dbus/qdbus.h>
+#include <dbus/dbus.h>
class Pong: public QObject
{
@@ -11,6 +11,7 @@ public slots:
{
QDBusMessage reply = QDBusMessage::methodReply(msg);
reply << static_cast<QList<QVariant> >(msg);
+ reply.setSignature(msg.signature());
if (!msg.connection().send(reply))
exit(1);
}
@@ -21,7 +22,13 @@ int main(int argc, char *argv[])
QCoreApplication app(argc, argv);
QDBusConnection &con = QDBus::sessionBus();
- if (!con.requestName("org.kde.selftest"))
+ 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)
exit(2);
Pong pong;
diff --git a/test/qt/tst_qdbusabstractadaptor.cpp b/test/qt/tst_qdbusabstractadaptor.cpp
index 5c1c609..ec3f047 100644
--- a/test/qt/tst_qdbusabstractadaptor.cpp
+++ b/test/qt/tst_qdbusabstractadaptor.cpp
@@ -3,15 +3,12 @@
#include <QtTest/QtTest>
-#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/qdbus.h>
#include "common.h"
-Q_DECLARE_METATYPE(QVariant)
-
const char *slotSpy;
-QString propSpy;
+QString valueSpy;
namespace QTest {
char *toString(QDBusMessage::MessageType t)
@@ -39,8 +36,6 @@ class tst_QDBusAbstractAdaptor: public QObject
Q_OBJECT
private slots:
- void initTestCase();
-
void methodCalls_data();
void methodCalls();
void signalEmissions_data();
@@ -50,9 +45,9 @@ private slots:
void overloadedSignalEmission();
void readProperties();
void writeProperties();
- void adaptorIntrospection_data();
- void adaptorIntrospection();
- void objectTreeIntrospection();
+
+ void typeMatching_data();
+ void typeMatching();
};
class QDBusSignalSpy: public QObject
@@ -88,10 +83,6 @@ class Interface1: public QDBusAbstractAdaptor
public:
Interface1(QObject *parent) : QDBusAbstractAdaptor(parent)
{ }
-
- static QDBusIntrospection::Methods methodData;
- static QDBusIntrospection::Signals signalData;
- static QDBusIntrospection::Properties propertyData;
};
class Interface2: public QDBusAbstractAdaptor
@@ -111,7 +102,7 @@ public:
{ return __PRETTY_FUNCTION__; }
void setProp2(const QString &value)
- { slotSpy = __PRETTY_FUNCTION__; propSpy = value; }
+ { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; }
void emitSignal(const QString &, const QVariant &)
{ emit signal(); }
@@ -121,11 +112,6 @@ public slots:
signals:
void signal();
-
-public:
- static QDBusIntrospection::Methods methodData;
- static QDBusIntrospection::Signals signalData;
- static QDBusIntrospection::Properties propertyData;
};
class Interface3: public QDBusAbstractAdaptor
@@ -145,7 +131,7 @@ public:
{ return __PRETTY_FUNCTION__; }
void setProp2(const QString &value)
- { slotSpy = __PRETTY_FUNCTION__; propSpy = value; }
+ { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; }
void emitSignal(const QString &name, const QVariant &value)
{
@@ -166,11 +152,6 @@ signals:
void signalVoid();
void signalInt(int);
void signalString(const QString &);
-
-public:
- static QDBusIntrospection::Methods methodData;
- static QDBusIntrospection::Signals signalData;
- static QDBusIntrospection::Properties propertyData;
};
class Interface4: public QDBusAbstractAdaptor
@@ -190,7 +171,7 @@ public:
{ return __PRETTY_FUNCTION__; }
void setProp2(const QString &value)
- { slotSpy = __PRETTY_FUNCTION__; propSpy = value; }
+ { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; }
void emitSignal(const QString &, const QVariant &value)
{
@@ -219,84 +200,228 @@ signals:
void signal();
void signal(int);
void signal(const QString &);
+};
+class MyObject: public QObject
+{
+ Q_OBJECT
public:
- static QDBusIntrospection::Methods methodData;
- static QDBusIntrospection::Signals signalData;
- static QDBusIntrospection::Properties propertyData;
-};
+ 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);
+ }
+ }
+};
-QDBusIntrospection::Methods Interface1::methodData;
-QDBusIntrospection::Signals Interface1::signalData;
-QDBusIntrospection::Properties Interface1::propertyData;
-QDBusIntrospection::Methods Interface2::methodData;
-QDBusIntrospection::Signals Interface2::signalData;
-QDBusIntrospection::Properties Interface2::propertyData;
-QDBusIntrospection::Methods Interface3::methodData;
-QDBusIntrospection::Signals Interface3::signalData;
-QDBusIntrospection::Properties Interface3::propertyData;
-QDBusIntrospection::Methods Interface4::methodData;
-QDBusIntrospection::Signals Interface4::signalData;
-QDBusIntrospection::Properties Interface4::propertyData;
-
-void tst_QDBusAbstractAdaptor::initTestCase()
+class TypesInterface: public QDBusAbstractAdaptor
{
- QDBusIntrospection::Method method;
- method.name = "Method";
- Interface2::methodData << method;
- Interface4::methodData << method;
- method.inputArgs << arg("i");
- Interface4::methodData << method;
- method.inputArgs.clear();
- method.inputArgs << arg("s");
- Interface4::methodData << method;
-
- method.name = "MethodVoid";
- method.inputArgs.clear();
- Interface3::methodData << method;
- method.name = "MethodInt";
- method.inputArgs << arg("i");
- Interface3::methodData << method;
- method.name = "MethodString";
- method.inputArgs.clear();
- method.inputArgs << arg("s");
- Interface3::methodData << method;
-
- QDBusIntrospection::Signal signal;
- signal.name = "Signal";
- Interface2::signalData << signal;
- Interface4::signalData << signal;
- signal.outputArgs << arg("i");
- Interface4::signalData << signal;
- signal.outputArgs.clear();
- signal.outputArgs << arg("s");
- Interface4::signalData << signal;
-
- signal.name = "SignalVoid";
- signal.outputArgs.clear();
- Interface3::signalData << signal;
- signal.name = "SignalInt";
- signal.outputArgs << arg("i");
- Interface3::signalData << signal;
- signal.name = "SignalString";
- signal.outputArgs.clear();
- signal.outputArgs << arg("s");
- Interface3::signalData << signal;
-
- QDBusIntrospection::Property prop;
- prop.name = "Prop1";
- prop.type = QDBusType('s');
- prop.access = QDBusIntrospection::Property::Read;
- Interface2::propertyData << prop;
- Interface3::propertyData << prop;
- Interface4::propertyData << prop;
- prop.name = "Prop2";
- prop.access = QDBusIntrospection::Property::ReadWrite;
- Interface2::propertyData << prop;
- Interface3::propertyData << prop;
- Interface4::propertyData << prop;
-}
+ 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()
{
@@ -313,93 +438,78 @@ void tst_QDBusAbstractAdaptor::methodCalls()
QDBusConnection &con = QDBus::sessionBus();
QVERIFY(con.isConnected());
- QDBusObject dobj = con.findObject(con.baseService(), "/");
- QVERIFY(dobj.isValid());
+ //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");
- //QDBusInterface empty(dobj, QString());
- QDBusInterface if1(dobj, "local.Interface1");
- QDBusInterface if2(dobj, "local.Interface2");
- QDBusInterface if3(dobj, "local.Interface3");
- QDBusInterface if4(dobj, "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("method").type(), QDBusMessage::ErrorMessage);
-
- QObject obj;
- con.registerObject("/", &obj);
+ //QCOMPARE(empty->call("method").type(), QDBusMessage::ErrorMessage);
+ QCOMPARE(if1->call("method").type(), QDBusMessage::ErrorMessage);
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);
- }
+ MyObject obj(nInterfaces);
+ con.registerObject("/", &obj);
// must fail: no such method
- QCOMPARE(if1.call("method").type(), QDBusMessage::ErrorMessage);
+ QCOMPARE(if1->call("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("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(if3.call("methodVoid").type(), QDBusMessage::ReplyMessage);
+ 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(if3->call("methodVoid").type(), QDBusMessage::ReplyMessage);
QCOMPARE(slotSpy, "void Interface3::methodVoid()");
- QCOMPARE(if3.call("methodInt", 42).type(), QDBusMessage::ReplyMessage);
+ QCOMPARE(if3->call("methodInt", 42).type(), QDBusMessage::ReplyMessage);
QCOMPARE(slotSpy, "void Interface3::methodInt(int)");
- QCOMPARE(if3.call("methodString", QString("")).type(), QDBusMessage::ReplyMessage);
+ QCOMPARE(if3->call("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("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("method.i", 42).type(), QDBusMessage::ReplyMessage);
QCOMPARE(slotSpy, "void Interface4::method(int)");
- QCOMPARE(if4.call("method.s", QString()).type(), QDBusMessage::ReplyMessage);
+ QCOMPARE(if4->call("method.s", QString()).type(), QDBusMessage::ReplyMessage);
QCOMPARE(slotSpy, "void Interface4::method(QString)");
}
-static void emitSignal(QDBusConnection &con, const QString &iface, const QString &name,
+static void emitSignal(MyObject *obj, const QString &iface, const QString &name,
const QVariant &parameter)
{
- QObject obj;
- Interface2 *if2 = new Interface2(&obj);
- Interface3 *if3 = new Interface3(&obj);
- Interface4 *if4 = new Interface4(&obj);
- con.registerObject("/",&obj);
-
if (iface.endsWith('2'))
- if2->emitSignal(name, parameter);
+ obj->if2->emitSignal(name, parameter);
else if (iface.endsWith('3'))
- if3->emitSignal(name, parameter);
+ obj->if3->emitSignal(name, parameter);
else if (iface.endsWith('4'))
- if4->emitSignal(name, parameter);
+ obj->if4->emitSignal(name, parameter);
QTest::qWait(200);
}
@@ -426,22 +536,29 @@ void tst_QDBusAbstractAdaptor::signalEmissions()
QDBusConnection &con = QDBus::sessionBus();
QVERIFY(con.isConnected());
- QDBusObject dobj = con.findObject(con.baseService(), "/");
- QVERIFY(dobj.isValid());
+ MyObject obj(3);
+ con.registerObject("/", &obj);
- //QDBusInterface empty(dobj, QString());
- QDBusInterface if2(dobj, "local.Interface2");
- QDBusInterface if3(dobj, "local.Interface3");
+ //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;
- if2.connect("signal", &spy, SLOT(slot(QDBusMessage)));
- if3.connect("signalVoid", &spy, SLOT(slot(QDBusMessage)));
- if3.connect("signalInt", &spy, SLOT(slot(QDBusMessage)));
- if3.connect("signalString", &spy, SLOT(slot(QDBusMessage)));
+ 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(con, interface, name, parameter);
+ emitSignal(&obj, interface, name, parameter);
QCOMPARE(spy.count, 1);
QCOMPARE(spy.interface, interface);
@@ -454,10 +571,10 @@ void tst_QDBusAbstractAdaptor::signalEmissions()
{
QDBusSignalSpy spy;
con.connect(con.baseService(), "/", interface, name, &spy, SLOT(slot(QDBusMessage)));
- emitSignal(con, "local.Interface2", "signal", QVariant());
- emitSignal(con, "local.Interface3", "signalVoid", QVariant());
- emitSignal(con, "local.Interface3", "signalInt", QVariant(1));
- emitSignal(con, "local.Interface3", "signalString", QVariant("foo"));
+ 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);
@@ -472,15 +589,14 @@ void tst_QDBusAbstractAdaptor::sameSignalDifferentPaths()
QDBusConnection &con = QDBus::sessionBus();
QVERIFY(con.isConnected());
- QObject obj;
- Interface2 *if2 = new Interface2(&obj);
+ 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)));
- if2->emitSignal(QString(), QVariant());
+ obj.if2->emitSignal(QString(), QVariant());
QTest::qWait(200);
QCOMPARE(spy.count, 1);
@@ -491,7 +607,7 @@ void tst_QDBusAbstractAdaptor::sameSignalDifferentPaths()
// now connect the other one
spy.count = 0;
con.connect(con.baseService(), "/p2", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage)));
- if2->emitSignal(QString(), QVariant());
+ obj.if2->emitSignal(QString(), QVariant());
QTest::qWait(200);
QCOMPARE(spy.count, 2);
@@ -511,19 +627,25 @@ 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);
+ //QDBusInterface *if4 = con.findInterface(con.baseService(), "/", interface);
// connect all signals and emit only one
{
QDBusSignalSpy spy;
- if4.connect("signal.", &spy, SLOT(slot(QDBusMessage)));
- if4.connect("signal.i", &spy, SLOT(slot(QDBusMessage)));
- if4.connect("signal.s", &spy, SLOT(slot(QDBusMessage)));
+ 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(con, interface, name, parameter);
+ emitSignal(&obj, interface, name, parameter);
QCOMPARE(spy.count, 1);
QCOMPARE(spy.interface, interface);
@@ -537,9 +659,9 @@ void tst_QDBusAbstractAdaptor::overloadedSignalEmission()
{
QDBusSignalSpy spy;
con.connect(con.baseService(), "/", interface, name, signature, &spy, SLOT(slot(QDBusMessage)));
- emitSignal(con, "local.Interface4", "signal", QVariant());
- emitSignal(con, "local.Interface4", "signal", QVariant(1));
- emitSignal(con, "local.Interface4", "signal", QVariant("foo"));
+ 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);
@@ -554,24 +676,21 @@ void tst_QDBusAbstractAdaptor::readProperties()
QDBusConnection &con = QDBus::sessionBus();
QVERIFY(con.isConnected());
- QObject obj;
- new Interface2(&obj);
- new Interface3(&obj);
- new Interface4(&obj);
+ MyObject obj;
con.registerObject("/", &obj);
for (int i = 2; i <= 4; ++i) {
QString name = QString("Interface%1").arg(i);
- QDBusInterface iface = con.findInterface(con.baseService(), "/", "local." + name);
+ QDBusInterface *iface = con.findInterface(con.baseService(), "/", "local." + name);
for (int j = 1; j <= 2; ++j) {
QString propname = QString("prop%1").arg(j);
- QDBusVariant value = iface.property(propname);
+ QVariant value = iface->property(propname.toLatin1());
- QVERIFY(value.type == QDBusType('s'));
- QVERIFY(value.value.type() == QVariant::String);
- QCOMPARE(value.value.toString(), QString("QString %1::%2() const").arg(name, propname));
+ QCOMPARE(value.userType(), int(QVariant::String));
+ QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname));
}
+ iface->deleteLater();
}
}
@@ -580,28 +699,28 @@ void tst_QDBusAbstractAdaptor::writeProperties()
QDBusConnection &con = QDBus::sessionBus();
QVERIFY(con.isConnected());
- QObject obj;
- new Interface2(&obj);
- new Interface3(&obj);
- new Interface4(&obj);
+ MyObject obj;
con.registerObject("/", &obj);
for (int i = 2; i <= 4; ++i) {
QString name = QString("Interface%1").arg(i);
- QDBusInterface iface = con.findInterface(con.baseService(), "/", "local." + name);
+ QDBusInterface *iface = con.findInterface(con.baseService(), "/", "local." + name);
- QDBusVariant value(name);
+ QVariant value(name);
- propSpy.clear();
- iface.setProperty("prop1", value);
- QVERIFY(propSpy.isEmpty()); // call mustn't have succeeded
+ valueSpy.clear();
+ iface->setProperty("prop1", value);
+ QVERIFY(valueSpy.isEmpty()); // call mustn't have succeeded
- iface.setProperty("prop2", value);
- QCOMPARE(propSpy, name);
+ iface->setProperty("prop2", value);
+ QCOMPARE(valueSpy, name);
QCOMPARE(QString(slotSpy), QString("void %1::setProp2(const QString&)").arg(name));
+
+ iface->deleteLater();
}
}
+#if 0
void tst_QDBusAbstractAdaptor::adaptorIntrospection_data()
{
methodCalls_data();
@@ -785,7 +904,79 @@ void tst_QDBusAbstractAdaptor::objectTreeIntrospection()
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);
+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
+
+ reply = iface->call("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)
diff --git a/test/qt/tst_qdbusconnection.cpp b/test/qt/tst_qdbusconnection.cpp
index 52fb9ff..224a02c 100644
--- a/test/qt/tst_qdbusconnection.cpp
+++ b/test/qt/tst_qdbusconnection.cpp
@@ -3,7 +3,6 @@
#include <QtTest/QtTest>
-#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/qdbus.h>
class MyObject: public QObject
@@ -28,12 +27,6 @@ private slots:
void send();
void sendAsync();
void sendSignal();
- void requestName_data();
- void requestName();
- void getNameOwner_data();
- void getNameOwner();
- void releaseName_data();
- void releaseName();
void registerObject();
@@ -159,89 +152,6 @@ void tst_QDBusConnection::addConnection()
}
}
-void tst_QDBusConnection::requestName_data()
-{
- QTest::addColumn<QString>("requestedName");
- QTest::addColumn<int>("flags");
- QTest::addColumn<bool>("expectedResult");
-
- QTest::newRow("null") << QString() << (int)QDBusConnection::NoReplace << false;
- QTest::newRow("empty") << QString("") << (int)QDBusConnection::NoReplace << false;
- QTest::newRow("invalid") << "./invalid name" << (int)QDBusConnection::NoReplace << false;
-// QTest::newRow("existing") << "org.freedesktop.DBus"
-// << (int)QDBusConnection::NoReplace << false;
-
- QTest::newRow("ok1") << "com.trolltech.QtDBUS.tst_qdbusconnection"
- << (int)QDBusConnection::NoReplace << true;
-}
-
-void tst_QDBusConnection::requestName()
-{
- QDBusConnection &con = QDBus::sessionBus();
-
- QVERIFY(con.isConnected());
-
- QFETCH(QString, requestedName);
- QFETCH(int, flags);
- QFETCH(bool, expectedResult);
-
- bool result = con.requestName(requestedName, (QDBusConnection::NameRequestMode)flags);
-
-// QEXPECT_FAIL("existing", "For whatever reason, the bus lets us replace this name", Abort);
- QCOMPARE(result, expectedResult);
-}
-
-void tst_QDBusConnection::getNameOwner_data()
-{
- QTest::addColumn<QString>("name");
- QTest::addColumn<QString>("expectedResult");
-
- QTest::newRow("null") << QString() << QString();
- QTest::newRow("empty") << QString("") << QString();
-
- QTest::newRow("invalid") << ".invalid" << QString();
- QTest::newRow("non-existent") << "com.trolltech.QtDBUS.foo" << QString();
-
- QTest::newRow("bus") << "org.freedesktop.DBus" << "org.freedesktop.DBus";
-
- QString base = QDBus::sessionBus().baseService();
- QTest::newRow("address") << base << base;
- QTest::newRow("self") << "com.trolltech.QtDBUS.tst_qdbusconnection" << base;
-}
-
-void tst_QDBusConnection::getNameOwner()
-{
- QFETCH(QString, name);
- QFETCH(QString, expectedResult);
-
- QDBusConnection &con = QDBus::sessionBus();
- QVERIFY(con.isConnected());
-
- QString result = con.getNameOwner(name);
-
- QCOMPARE(result, expectedResult);
-}
-
-void tst_QDBusConnection::releaseName_data()
-{
- requestName_data();
-}
-
-void tst_QDBusConnection::releaseName()
-{
- QDBusConnection &con = QDBus::sessionBus();
-
- QVERIFY(con.isConnected());
-
- QFETCH(QString, requestedName);
- //QFETCH(int, flags);
- QFETCH(bool, expectedResult);
-
- bool result = con.releaseName(requestedName);
-
- QCOMPARE(result, expectedResult);
-}
-
void tst_QDBusConnection::registerObject()
{
QDBusConnection &con = QDBus::sessionBus();
diff --git a/test/qt/tst_qdbusinterface.cpp b/test/qt/tst_qdbusinterface.cpp
index a7f8c70..46dde97 100644
--- a/test/qt/tst_qdbusinterface.cpp
+++ b/test/qt/tst_qdbusinterface.cpp
@@ -20,7 +20,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
-#define DBUS_API_SUBJECT_TO_CHANGE 1
#include <qcoreapplication.h>
#include <qmetatype.h>
#include <QtTest/QtTest>
@@ -28,10 +27,11 @@
#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_SERVICE_NAME "com.trolltech.QtDBus.tst_qdbusinterface"
#define TEST_SIGNAL_NAME "somethingHappened"
const char introspectionData[] =
@@ -142,7 +142,6 @@ private slots:
void call_data();
void call();
- void introspect_data();
void introspect();
void signal();
@@ -152,7 +151,6 @@ void tst_QDBusInterface::initTestCase()
{
QDBusConnection &con = QDBus::sessionBus();
QVERIFY(con.isConnected());
- QVERIFY(con.requestName( TEST_SERVICE_NAME ));
con.registerObject("/", &obj, QDBusConnection::ExportAdaptors | QDBusConnection::ExportSlots);
}
@@ -169,16 +167,21 @@ void tst_QDBusInterface::call_data()
input << qVariantFromValue(1);
QTest::newRow("int") << "ping" << input << input;
QTest::newRow("int-int") << "ping.i" << input << input;
- QTest::newRow("int-int16") << "ping.n" << 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(1LL));
- QTest::newRow("int-uint64") << "ping.t" << input << (QVariantList() << qVariantFromValue(1ULL));
+ 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();
@@ -192,13 +195,23 @@ void tst_QDBusInterface::call_data()
output.clear();
output << qVariantFromValue(1);
- QTest::newRow("string-int") << "ping.i" << input << input;
+ 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));
@@ -219,8 +232,8 @@ void tst_QDBusInterface::call_data()
void tst_QDBusInterface::call()
{
QDBusConnection &con = QDBus::sessionBus();
- QDBusInterface iface = con.findInterface(con.baseService(), QLatin1String("/"),
- TEST_INTERFACE_NAME);
+ QDBusInterface *iface = con.findInterface(con.baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
QFETCH(QString, method);
QFETCH(QVariantList, input);
@@ -228,30 +241,30 @@ void tst_QDBusInterface::call()
QDBusMessage reply;
// try first callWithArgs:
- reply = iface.callWithArgs(method, input);
+ reply = iface->callWithArgs(method, input);
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
if (!output.isEmpty()) {
QCOMPARE(reply.count(), output.count());
- QCOMPARE(static_cast<QVariantList>(reply), output);
+ QVERIFY(compare(reply, output));
}
// try the template methods
if (input.isEmpty())
- reply = iface.call(method);
+ reply = iface->call(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(method, input.at(0).toInt());
break;
case QVariant::UInt:
- reply = iface.call(method, input.at(0).toUInt());
+ reply = iface->call(method, input.at(0).toUInt());
break;
case QVariant::String:
- reply = iface.call(method, input.at(0).toString());
+ reply = iface->call(method, input.at(0).toString());
break;
default:
@@ -259,73 +272,50 @@ void tst_QDBusInterface::call()
break;
}
else
- reply = iface.call(method, input.at(0).toString(), input.at(1).toString());
+ reply = iface->call(method, input.at(0).toString(), input.at(1).toString());
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
if (!output.isEmpty()) {
QCOMPARE(reply.count(), output.count());
- QCOMPARE(static_cast<QVariantList>(reply), output);
+ QVERIFY(compare(reply, output));
}
}
-void tst_QDBusInterface::introspect_data()
-{
- QTest::addColumn<QString>("service");
- QTest::newRow("base") << QDBus::sessionBus().baseService();
- QTest::newRow("name") << TEST_SERVICE_NAME;
-}
-
void tst_QDBusInterface::introspect()
{
- QFETCH(QString, service);
QDBusConnection &con = QDBus::sessionBus();
- QDBusInterface iface = con.findInterface(service, QLatin1String("/"),
- TEST_INTERFACE_NAME);
+ QDBusInterface *iface = con.findInterface(QDBus::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ const QMetaObject *mo = iface->metaObject();
- QDBusIntrospection::Methods mm = iface.methodData();
- QVERIFY(mm.count() == 2);
+ qDebug("Improve to a better testcase of QDBusMetaObject");
+ QCOMPARE(mo->methodCount() - mo->methodOffset(), 3);
+ QVERIFY(mo->indexOfSignal(TEST_SIGNAL_NAME "(QString)") != -1);
- QDBusIntrospection::Signals sm = iface.signalData();
- QVERIFY(sm.count() == 1);
- QVERIFY(sm.contains(TEST_SIGNAL_NAME));
+ QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 1);
+ QVERIFY(mo->indexOfProperty("prop1") != -1);
- QDBusIntrospection::Properties pm = iface.propertyData();
- QVERIFY(pm.count() == 1);
- QVERIFY(pm.contains("prop1"));
+ iface->deleteLater();
}
void tst_QDBusInterface::signal()
{
QDBusConnection &con = QDBus::sessionBus();
- QDBusInterface iface = con.findInterface(con.baseService(), QLatin1String("/"),
- TEST_INTERFACE_NAME);
-
- QString signalName = TEST_SIGNAL_NAME;
+ QDBusInterface *iface = con.findInterface(con.baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
QString arg = "So long and thanks for all the fish";
{
Spy spy;
- iface.connect(signalName, &spy, SLOT(spySlot(QString)));
+ spy.connect(iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString)));
- emitSignal(TEST_INTERFACE_NAME, signalName, arg);
- QVERIFY(spy.count == 1);
+ emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg);
+ QCOMPARE(spy.count, 1);
QCOMPARE(spy.received, arg);
}
- QDBusIntrospection::Signals sm = iface.signalData();
- QVERIFY(sm.contains(signalName));
-
- const QDBusIntrospection::Signal& signal = sm.value(signalName);
- QCOMPARE(signal.name, signalName);
- QVERIFY(!signal.outputArgs.isEmpty());
- {
- Spy spy;
- iface.connect(signal, &spy, SLOT(spySlot(QString)));
-
- emitSignal(TEST_INTERFACE_NAME, signalName, arg);
- QVERIFY(spy.count == 1);
- QCOMPARE(spy.received, arg);
- }
+ iface->deleteLater();
}
QTEST_MAIN(tst_QDBusInterface)
diff --git a/test/qt/tst_qdbusobject.cpp b/test/qt/tst_qdbusobject.cpp
deleted file mode 100644
index 904e98b..0000000
--- a/test/qt/tst_qdbusobject.cpp
+++ /dev/null
@@ -1,207 +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.
- *
- */
-#define DBUS_API_SUBJECT_TO_CHANGE 1
-#include <qcoreapplication.h>
-#include <qmetatype.h>
-#include <QtTest/QtTest>
-
-#include <dbus/qdbus.h>
-
-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=\"com.trolltech.tst_qdbusobject.MyObject\">"
- "<method name=\"ping\">"
- "<arg name=\"ping\" direction=\"in\" type=\"v\"/>"
- "<arg name=\"pong\" direction=\"out\" type=\"v\"/>"
- "</method>"
- "</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
-public:
- MyObject()
- {
- new IntrospectionAdaptor(this);
- }
-
-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 tst_QDBusObject: public QObject
-{
- Q_OBJECT
- MyObject obj;
-
-private slots:
- void initTestCase(); // connect to D-Bus
-
- void construction_data();
- void construction();
-
- void introspection_data();
- void introspection();
-};
-
-void tst_QDBusObject::initTestCase()
-{
- QDBusConnection &con = QDBus::sessionBus();
- QVERIFY(con.isConnected());
- QVERIFY(con.requestName("com.trolltech.tst_qdbusobject"));
-
- con.registerObject("/", &obj, QDBusConnection::ExportAdaptors | QDBusConnection::ExportSlots);
-}
-
-void tst_QDBusObject::construction_data()
-{
- QTest::addColumn<QString>("service");
- QTest::addColumn<QString>("path");
- QTest::addColumn<bool>("isValid");
- QTest::addColumn<bool>("exists");
-
- QTest::newRow("null") << QString() << QString() << false << false;
-
- QTest::newRow("invalid1") << "foo.foo1" << "" << false << false;
- QTest::newRow("invalid2") << "foo.foo1" << "foo.bar" << false << false;
- QTest::newRow("invalid3") << "foo.foo1" << "/foo.bar" << false << false;
- QTest::newRow("invalid4") << "" << "/" << false << false;
- QTest::newRow("invalid5") << "foo" << "/" << false << false;
- QTest::newRow("invalid6") << ".foo" << "/" << false << false;
-
- QTest::newRow("invalid7") << "org.freedesktop.DBus" << "" << false << false;
- QTest::newRow("invalid8") << "org.freedesktop.DBus" << "foo.bar" << false << false;
- QTest::newRow("invalid9") << "org.freedesktop.DBus" << "/foo.bar" << false << false;
-
- QTest::newRow("existing") << "org.freedesktop.DBus" << "/" << true << true;
- QTest::newRow("non-existing") << "org.freedesktop.DBus" << "/foo" << true << false;
-}
-
-void tst_QDBusObject::construction()
-{
- QDBusConnection &con = QDBus::sessionBus();
-
- QFETCH(QString, service);
- QFETCH(QString, path);
- QFETCH(bool, isValid);
- //QFETCH(bool, exists);
-
- QDBusObject o = con.findObject(service, path);
- QCOMPARE(o.isValid(), isValid);
-
- if (isValid) {
- QCOMPARE(o.service(), service);
- QCOMPARE(o.path(), path);
- }
- else {
- QVERIFY(o.service().isNull());
- QVERIFY(o.path().isNull());
- }
-
- //QCOMPARE(o.exists(), exists);
-}
-
-void tst_QDBusObject::introspection_data()
-{
- QTest::addColumn<QString>("service");
- QTest::addColumn<QString>("path");
- QTest::addColumn<QStringList>("interfaces");
-
- QStringList interfaces;
- QTest::newRow("nowhere") << QString() << QString() << interfaces;
-
- // IMPORTANT!
- // Keep the interface list sorted!
- interfaces << "org.freedesktop.DBus" << DBUS_INTERFACE_INTROSPECTABLE;
- QTest::newRow("server") << "org.freedesktop.DBus" << "/" << interfaces;
-
- QDBusConnection &con = QDBus::sessionBus();
- interfaces.clear();
- interfaces << "com.trolltech.tst_qdbusobject.MyObject" << DBUS_INTERFACE_INTROSPECTABLE;
-
- QTest::newRow("self1") << con.baseService() << "/" << interfaces;
- QTest::newRow("self2") << "com.trolltech.tst_qdbusobject" << "/" << interfaces;
-}
-
-void tst_QDBusObject::introspection()
-{
- QDBusConnection &con = QDBus::sessionBus();
-
- QFETCH(QString, service);
- QFETCH(QString, path);
-
- QDBusObject o = con.findObject(service, path);
-
- if (!o.isValid())
- QVERIFY(o.introspect().isEmpty());
- else {
- QFETCH(QStringList, interfaces);
- QStringList parsed = o.interfaces();
- parsed.sort();
- QCOMPARE(parsed.count(), interfaces.count());
- QCOMPARE(parsed, interfaces);
- }
-}
-
-QTEST_MAIN(tst_QDBusObject)
-
-#include "tst_qdbusobject.moc"
-
diff --git a/test/qt/tst_qdbustype.cpp b/test/qt/tst_qdbustype.cpp
deleted file mode 100644
index 9520ae6..0000000
--- a/test/qt/tst_qdbustype.cpp
+++ /dev/null
@@ -1,273 +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.
- *
- */
-#define DBUS_API_SUBJECT_TO_CHANGE 1
-#include <qcoreapplication.h>
-#include <QtTest/QtTest>
-
-#include <dbus/qdbus.h>
-
-class tst_QDBusType: public QObject
-{
- Q_OBJECT
-
-private slots:
- void fromType_data();
- void fromType();
- void fromSignature_data();
- void fromSignature();
- void arrayOf_data();
- void arrayOf();
- void mapOf_data();
- void mapOf();
-};
-
-inline QTestData &operator<<(QTestData &data, QVariant::Type t)
-{
- return data << int(t);
-}
-
-void tst_QDBusType::fromType_data()
-{
- fromSignature_data();
-}
-
-void tst_QDBusType:: arrayOf_data()
-{
- fromSignature_data();
-}
-
-void tst_QDBusType::mapOf_data()
-{
- fromSignature_data();
-}
-
-void tst_QDBusType::fromSignature_data()
-{
- QTest::addColumn<QString>("signature");
- QTest::addColumn<char>("type");
- QTest::addColumn<int>("qvariantType");
- QTest::addColumn<bool>("isValid");
- QTest::addColumn<bool>("isBasic");
- QTest::addColumn<bool>("isContainer");
- QTest::addColumn<int>("subtypeCount");
-
- QTest::newRow("null") << QString() << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("empty") << QString("") << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("invalid") << QString("~") << '\0' << QVariant::Invalid << false << false << false << 0;
-
- // integers:
- QTest::newRow("byte") << "y" << 'y' << QVariant::UInt << true << true << false << 0;
- QTest::newRow("boolean") << "b" << 'b' << QVariant::Bool << true << true << false << 0;
- QTest::newRow("int16") << "n" << 'n' << QVariant::Int << true << true << false << 0;
- QTest::newRow("uint16") << "q" << 'q' << QVariant::UInt << true << true << false << 0;
- QTest::newRow("int32") << "i" << 'i' << QVariant::Int << true << true << false << 0;
- QTest::newRow("uint32") << "u" << 'u' << QVariant::UInt << true << true << false << 0;
- QTest::newRow("int64") << "x" << 'x' << QVariant::LongLong << true << true << false << 0;
- QTest::newRow("uint64") << "t" << 't' << QVariant::ULongLong << true << true << false << 0;
-
- // double:
- QTest::newRow("double") << "d" << 'd' << QVariant::Double << true << true << false << 0;
-
- // string types:
- QTest::newRow("string") << "s" << 's' << QVariant::String << true << true << false << 0;
- QTest::newRow("objpath") << "o" << 'o' << QVariant::String << true << true << false << 0;
- QTest::newRow("signature")<<"g" << 'g' << QVariant::String << true << true << false << 0;
-
- // variant
- QTest::newRow("variant") << "v" << 'v' << QVariant::UserType << true << false << true << 0;
-
- // compound types:
- QTest::newRow("struct-empty") << "()" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("struct-invalid") << "(~)" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("struct-unterminated")<< "(iii" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("struct-bad-nest") << "(i(i)((i)i)" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("struct1") << "(i)" << 'r' << QVariant::List << true << false << true << 1;
- QTest::newRow("struct2") << "(ii)" << 'r' << QVariant::List << true << false << true << 2;
-
- QTest::newRow("array-empty") << "a" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("array-invalid") << "a~" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("array-simple") << "ab" << 'a' << QVariant::List << true << false << true << 1;
- QTest::newRow("bytearray") << "ay" << 'a' << QVariant::ByteArray << true << false << true << 1;
- QTest::newRow("stringlist") << "as" << 'a' << QVariant::StringList << true << false << true << 1;
-
- QTest::newRow("map-empty") << "e" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid1") << "a{}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid2") << "a{~}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid3") << "a{e}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid4") << "a{i}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid5") << "a{(i)d}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid6") << "{}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-invalid7") << "{i}" << '\0' << QVariant::Invalid << false << false << false << 0;
- //QTest::newRow("map-invalid8") << "{is}" << '\0' << QVariant::Invalid << false << false << false << 0; // this is valid when "a" is prepended
- QTest::newRow("map-bad-nesting") << "a{i(s}" << '\0' << QVariant::Invalid << false << false << false << 0;
- QTest::newRow("map-ok1") << "a{is}" << 'a' << QVariant::Map << true << false << true << 1;
- QTest::newRow("map-ok2") << "a{sv}" << 'a' << QVariant::Map << true << false << true << 1;
-
- // compound of compounds:
- QTest::newRow("struct-struct") << "((i))" << 'r' << QVariant::List << true << false << true << 1;
- QTest::newRow("struct-structs") << "((ii)d(i))" << 'r' << QVariant::List << true << false << true << 3;
- QTest::newRow("map-struct") << "a{s(ii)}" << 'a' << QVariant::Map << true << false << true << 1;
- QTest::newRow("map-stringlist") << "a{sas}" << 'a' << QVariant::Map << true << false << true << 1;
- QTest::newRow("map-map") << "a{ia{sv}}" << 'a' << QVariant::Map << true << false << true << 1;
- QTest::newRow("array-struct") << "a(ii)" << 'a' << QVariant::List << true << false << true << 1;
- QTest::newRow("array-array") << "aai" << 'a' << QVariant::List << true << false << true << 1;
- QTest::newRow("array-map") << "aa{sv}" << 'a' << QVariant::List << true << false << true << 1;
-}
-
-void tst_QDBusType::fromType()
-{
- QFETCH(QString, signature);
- if (signature.length() != 1)
- // can't transform to typecode
- return;
-
- QFETCH(char, type);
- QFETCH(int, qvariantType);
- QFETCH(bool, isValid);
- QFETCH(bool, isBasic);
- QFETCH(bool, isContainer);
-
- QDBusType t(signature.at(0).toLatin1());
-
- QCOMPARE((char)t.dbusType(), type);
- QCOMPARE(t.qvariantType(), QVariant::Type(qvariantType));
- QCOMPARE(t.isValid(), isValid);
- QCOMPARE(t.isBasic(), isBasic);
- QCOMPARE(t.isContainer(), isContainer);
-}
-
-void tst_QDBusType::fromSignature()
-{
- QFETCH(QString, signature);
- QFETCH(char, type);
- QFETCH(int, qvariantType);
- QFETCH(bool, isValid);
- QFETCH(bool, isBasic);
- QFETCH(bool, isContainer);
- QFETCH(int, subtypeCount);
-
- QDBusType t(signature);
-
- QCOMPARE((char)t.dbusType(), type);
- QCOMPARE(t.qvariantType(), QVariant::Type(qvariantType));
- QCOMPARE(t.isValid(), isValid);
- QCOMPARE(t.isBasic(), isBasic);
- QCOMPARE(t.isContainer(), isContainer);
-
- if (isValid)
- QCOMPARE(QLatin1String(t.dbusSignature()), signature);
-
- QCOMPARE(t.subTypes().count(), subtypeCount);
-}
-
-void tst_QDBusType::arrayOf()
-{
- QFETCH(QString, signature);
- QFETCH(char, type);
- QFETCH(int, qvariantType);
- QFETCH(bool, isValid);
- QFETCH(bool, isBasic);
- QFETCH(bool, isContainer);
- QFETCH(int, subtypeCount);
-
- QDBusType arr("a" + signature.toLatin1());
- QCOMPARE(arr.isValid(), isValid);
- QVERIFY(!arr.isBasic());
-
- if (isValid) {
- QVERIFY(arr.isContainer());
- QVERIFY(arr.isArray());
- QCOMPARE((char)arr.dbusType(), 'a');
- QCOMPARE(arr.subTypes().count(), 1);
-
- // handle special cases:
- if (type == 'y')
- QCOMPARE(arr.qvariantType(), QVariant::ByteArray);
- else if (type == 's' || type == 'o' || type == 'g')
- QCOMPARE(arr.qvariantType(), QVariant::StringList);
- else
- QCOMPARE(arr.qvariantType(), QVariant::List);
-
- // handle the array element now:
- QDBusType t = arr.arrayElement();
-
- QCOMPARE((char)t.dbusType(), type);
- QCOMPARE(t.qvariantType(), QVariant::Type(qvariantType));
- QCOMPARE(t.isValid(), isValid);
- QCOMPARE(t.isBasic(), isBasic);
- QCOMPARE(t.isContainer(), isContainer);
-
- QCOMPARE(QLatin1String(t.dbusSignature()), signature);
-
- QCOMPARE(t.subTypes().count(), subtypeCount);
- }
-}
-
-void tst_QDBusType::mapOf()
-{
- QFETCH(QString, signature);
- QFETCH(char, type);
- QFETCH(int, qvariantType);
- QFETCH(bool, isValid);
- QFETCH(bool, isBasic);
- QFETCH(bool, isContainer);
- QFETCH(int, subtypeCount);
-
- QDBusType map("a{s" + signature.toLatin1() + '}');
- QCOMPARE(map.isValid(), isValid);
- QVERIFY(!map.isBasic());
-
- if (isValid) {
- QVERIFY(map.isContainer());
- QVERIFY(map.isArray());
- QVERIFY(map.isMap());
- QCOMPARE((char)map.dbusType(), 'a');
- QCOMPARE(map.subTypes().count(), 1);
-
- // handle the array element now:
- QDBusType dict_entry = map.arrayElement();
- QVERIFY(dict_entry.isValid());
- QVERIFY(dict_entry.isContainer());
- QVERIFY(!dict_entry.isMap());
- QVERIFY(!dict_entry.isArray());
-
- QVERIFY(map.mapKey().isBasic());
-
- // handle the value:
- QDBusType t = map.mapValue();
-
- QCOMPARE((char)t.dbusType(), type);
- QCOMPARE(t.qvariantType(), QVariant::Type(qvariantType));
- QCOMPARE(t.isValid(), isValid);
- QCOMPARE(t.isBasic(), isBasic);
- QCOMPARE(t.isContainer(), isContainer);
-
- QCOMPARE(QLatin1String(t.dbusSignature()), signature);
-
- QCOMPARE(t.subTypes().count(), subtypeCount);
- }
-}
-
-QTEST_MAIN(tst_QDBusType)
-
-#include "tst_qdbustype.moc"
diff --git a/test/qt/tst_qdbusxmlparser.cpp b/test/qt/tst_qdbusxmlparser.cpp
deleted file mode 100644
index d908570..0000000
--- 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.
- *
- */
-#define DBUS_API_SUBJECT_TO_CHANGE 1
-#include <qcoreapplication.h>
-#include <qmetatype.h>
-#include <QtTest/QtTest>
-
-#include <dbus/qdbus.h>
-
-#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 = QDBusType("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 = QDBusType("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 = QDBusType("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"