diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-29 09:54:22 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-31 08:25:51 (GMT) |
commit | 624ea78d71dca5112272597f9f1ee165c2275c5c (patch) | |
tree | bb1c4ebd82ce217250736f37f19cff76e2fe1590 /tests/auto/qdbusmarshall | |
parent | 10c3a3bf11d6bbd8f8e99028ecab41acb89b7273 (diff) | |
download | Qt-624ea78d71dca5112272597f9f1ee165c2275c5c.zip Qt-624ea78d71dca5112272597f9f1ee165c2275c5c.tar.gz Qt-624ea78d71dca5112272597f9f1ee165c2275c5c.tar.bz2 |
Autotest: add some D-Bus tests sending complex structs and lists of them
Diffstat (limited to 'tests/auto/qdbusmarshall')
-rw-r--r-- | tests/auto/qdbusmarshall/common.h | 35 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp | 18 |
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/qdbusmarshall/common.h b/tests/auto/qdbusmarshall/common.h index 9df1e01..bdc9f09 100644 --- a/tests/auto/qdbusmarshall/common.h +++ b/tests/auto/qdbusmarshall/common.h @@ -103,6 +103,34 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, MyStruct &ms) return arg; } +struct MyVariantMapStruct +{ + QString s; + QVariantMap map; + + inline bool operator==(const MyVariantMapStruct &other) const + { return s == other.s && map == other.map; } +}; +Q_DECLARE_METATYPE(MyVariantMapStruct) +Q_DECLARE_METATYPE(QList<MyVariantMapStruct>) + +QDBusArgument &operator<<(QDBusArgument &arg, const MyVariantMapStruct &ms) +{ + arg.beginStructure(); + arg << ms.s << ms.map; + arg.endStructure(); + return arg; +} + +const QDBusArgument &operator>>(const QDBusArgument &arg, MyVariantMapStruct &ms) +{ + arg.beginStructure(); + arg >> ms.s >> ms.map; + arg.endStructure(); + return arg; +} + + void commonInit() { qDBusRegisterMetaType<QList<QDateTime> >(); @@ -127,6 +155,8 @@ void commonInit() qDBusRegisterMetaType<QHash<QDBusSignature, QString> >(); qDBusRegisterMetaType<MyStruct>(); + qDBusRegisterMetaType<MyVariantMapStruct>(); + qDBusRegisterMetaType<QList<MyVariantMapStruct> >(); } #ifdef USE_PRIVATE_CODE #include "private/qdbusintrospection_p.h" @@ -476,6 +506,11 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) else if (id == qMetaTypeId<MyStruct>()) return compare<MyStruct>(arg, v2); + + else if (id == qMetaTypeId<MyVariantMapStruct>()) + return compare<MyVariantMapStruct>(arg, v2); + else if (id == qMetaTypeId<QList<MyVariantMapStruct> >()) + return compare<QList<MyVariantMapStruct> >(arg, v2); } qWarning() << "Unexpected QVariant type" << v2.userType() diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp index 6e66393..b209aef 100644 --- a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp @@ -492,6 +492,24 @@ void tst_QDBusMarshall::sendStructs_data() QTest::newRow("time") << QVariant(time) << "(iiii)" << "[Argument: (iiii) 12, 25, 0, 0]"; QTest::newRow("datetime") << QVariant(QDateTime(date, time)) << "((iii)(iiii)i)" << "[Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 12, 25, 0, 0], 0]"; + + MyStruct ms = { 1, "Hello, World" }; + QTest::newRow("int-string") << qVariantFromValue(ms) << "(is)" << "[Argument: (is) 1, \"Hello, World\"]"; + + MyVariantMapStruct mvms = { "Hello, World", QVariantMap() }; + QTest::newRow("string-variantmap") << qVariantFromValue(mvms) << "(sa{sv})" << "[Argument: (sa{sv}) \"Hello, World\", [Argument: a{sv} {}]]"; + + // use only basic types, otherwise comparison will fail + mvms.map["int"] = 42; + mvms.map["uint"] = 42u; + mvms.map["short"] = qVariantFromValue<short>(-47); + mvms.map["bytearray"] = QByteArray("Hello, world"); + QTest::newRow("string-variantmap2") << qVariantFromValue(mvms) << "(sa{sv})" << "[Argument: (sa{sv}) \"Hello, World\", [Argument: a{sv} {\"bytearray\" = [Variant(QByteArray): {72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100}], \"int\" = [Variant(int): 42], \"short\" = [Variant(short): -47], \"uint\" = [Variant(uint): 42]}]]"; + + QList<MyVariantMapStruct> list; + QTest::newRow("empty-list-of-string-variantmap") << qVariantFromValue(list) << "a(sa{sv})" << "[Argument: a(sa{sv}) {}]"; + list << mvms; + QTest::newRow("list-of-string-variantmap") << qVariantFromValue(list) << "a(sa{sv})" << "[Argument: a(sa{sv}) {[Argument: (sa{sv}) \"Hello, World\", [Argument: a{sv} {\"bytearray\" = [Variant(QByteArray): {72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100}], \"int\" = [Variant(int): 42], \"short\" = [Variant(short): -47], \"uint\" = [Variant(uint): 42]}]]}]"; } void tst_QDBusMarshall::sendComplex_data() |