summaryrefslogtreecommitdiffstats
path: root/tests/auto/dbus
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-03-16 18:41:27 -0700
committerThiago Macieira <thiago.macieira@intel.com>2024-03-18 14:43:13 -0700
commit5401a9a6cd3263eda15911c3fbfc81ebea2e798f (patch)
treed0bb0b0e19deb747479f43a4d6880dc387d4b208 /tests/auto/dbus
parent990b60120e3b72394ba66220d090cf357c34e5d3 (diff)
QDBusArgument: disambiguate between QMap on std::pair and std::map
For QMap on a std::pair, QMap::iterator{}.operator->() would result in a type that has "first" and "second" members: std::pair itself. But it would be wrong to marshall and demarshall the first and second elements thereof as the key and value, so give preference to the .key() and .value() selection, which would store the std::pair as the type. Fixes: QTBUG-123401 Pick-to: 6.5 6.6 6.7 Change-Id: I6818d78a57394e37857bfffd17bd69bb692dd03b Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'tests/auto/dbus')
-rw-r--r--tests/auto/dbus/qdbusmarshall/common.h4
-rw-r--r--tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp11
2 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/dbus/qdbusmarshall/common.h b/tests/auto/dbus/qdbusmarshall/common.h
index a7d8196021..9a7c1e1553 100644
--- a/tests/auto/dbus/qdbusmarshall/common.h
+++ b/tests/auto/dbus/qdbusmarshall/common.h
@@ -152,7 +152,9 @@ void commonInit()
qDBusRegisterMetaType<QMap<QDBusObjectPath, QString> >();
qDBusRegisterMetaType<QMap<qlonglong, QDateTime> >();
qDBusRegisterMetaType<QMap<QDBusSignature, QString> >();
+ qDBusRegisterMetaType<QMap<QString, std::pair<int, int>>>();
+ qDBusRegisterMetaType<std::pair<int, int>>();
qDBusRegisterMetaType<MyStruct>();
qDBusRegisterMetaType<MyVariantMapStruct>();
qDBusRegisterMetaType<QList<MyVariantMapStruct> >();
@@ -471,6 +473,8 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2)
return compare<QMap<qlonglong, QDateTime> >(arg, v2);
else if (id == qMetaTypeId<QMap<QDBusSignature, QString> >())
return compare<QMap<QDBusSignature, QString> >(arg, v2);
+ else if (id == qMetaTypeId<QMap<QString, std::pair<int, int>>>())
+ return compare<QMap<QString, std::pair<int, int>>>(arg, v2);
else if (id == qMetaTypeId<QList<QByteArray> >())
return compare<QList<QByteArray> >(arg, v2);
diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp
index 8d61e12736..e7a8273115 100644
--- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp
+++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp
@@ -476,6 +476,17 @@ void tst_QDBusMarshall::sendMaps_data()
QTest::newRow("gs-map") << QVariant::fromValue(gsmap) << "a{gs}"
<< "[Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]";
+ QMap<QString, std::pair<int, int>> siimap;
+ QTest::newRow("empty-sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}"
+ << "[Argument: a{s(ii)} {}]";
+ siimap["0,0"] = { 0, 0 };
+ siimap["1,-1"] = { 1, -1 };
+ QTest::newRow("sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}"
+ << "[Argument: a{s(ii)} {"
+ "\"0,0\" = [Argument: (ii) 0, 0], "
+ "\"1,-1\" = [Argument: (ii) 1, -1]"
+ "}]";
+
if (fileDescriptorPassing) {
svmap["zzfiledescriptor"] = QVariant::fromValue(QDBusUnixFileDescriptor(fileDescriptorForTest()));
QTest::newRow("sv-map1-fd") << QVariant::fromValue(svmap) << "a{sv}"