From bc4f74f5863fc0d6cad891632019c37a9e38617d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 27 Mar 2012 12:14:14 -0300 Subject: Don't hardcode the order of elements in QHashes Instead use QMap if we want a stable order. Task-number: QTBUG-24995 Change-Id: I93f643df236f5078768f539615fa47163e5262e8 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Stephen Kelly --- tests/auto/dbus/qdbusmarshall/common.h | 41 +++++++--------------- .../auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp | 6 ++-- 2 files changed, 15 insertions(+), 32 deletions(-) (limited to 'tests/auto/dbus') diff --git a/tests/auto/dbus/qdbusmarshall/common.h b/tests/auto/dbus/qdbusmarshall/common.h index 025641531d..3efb8de499 100644 --- a/tests/auto/dbus/qdbusmarshall/common.h +++ b/tests/auto/dbus/qdbusmarshall/common.h @@ -85,8 +85,8 @@ Q_DECLARE_METATYPE(QList >) typedef QMap IntStringMap; typedef QMap StringStringMap; typedef QMap ObjectPathStringMap; -typedef QHash LLDateTimeMap; -typedef QHash SignatureStringMap; +typedef QMap LLDateTimeMap; +typedef QMap SignatureStringMap; Q_DECLARE_METATYPE(IntStringMap) Q_DECLARE_METATYPE(StringStringMap) Q_DECLARE_METATYPE(ObjectPathStringMap) @@ -209,8 +209,8 @@ void commonInit() qDBusRegisterMetaType >(); qDBusRegisterMetaType >(); qDBusRegisterMetaType >(); - qDBusRegisterMetaType >(); - qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); @@ -420,23 +420,6 @@ bool compare(const QMap &m1, const QMap &m2) return true; } -template -bool compare(const QHash &m1, const QHash &m2) -{ - if (m1.count() != m2.size()) - return false; - typename QHash::ConstIterator i1 = m1.constBegin(); - typename QHash::ConstIterator end = m1.constEnd(); - for ( ; i1 != end; ++i1) { - typename QHash::ConstIterator i2 = m2.find(i1.key()); - if (i2 == m2.constEnd()) - return false; - if (!compare(*i1, *i2)) - return false; - } - return true; -} - template inline bool compare(const QDBusArgument &arg, const QVariant &v2, T * = 0) { @@ -538,10 +521,10 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) return compare >(arg, v2); else if (id == qMetaTypeId >()) return compare >(arg, v2); - else if (id == qMetaTypeId >()) - return compare >(arg, v2); - else if (id == qMetaTypeId >()) - return compare >(arg, v2); + else if (id == qMetaTypeId >()) + return compare >(arg, v2); + else if (id == qMetaTypeId >()) + return compare >(arg, v2); else if (id == qMetaTypeId >()) return compare >(arg, v2); @@ -703,11 +686,11 @@ template<> bool compare(const QVariant &v1, const QVariant &v2) else if (id == qMetaTypeId >()) return compare(qvariant_cast >(v1), qvariant_cast >(v2)); - else if (id == qMetaTypeId >()) // lldtmap - return compare(qvariant_cast >(v1), qvariant_cast >(v2)); + else if (id == qMetaTypeId >()) // lldtmap + return compare(qvariant_cast >(v1), qvariant_cast >(v2)); - else if (id == qMetaTypeId >()) - return compare(qvariant_cast >(v1), qvariant_cast >(v2)); + else if (id == qMetaTypeId >()) + return compare(qvariant_cast >(v1), qvariant_cast >(v2)); else if (id == qMetaTypeId()) // (is) return qvariant_cast(v1) == qvariant_cast(v2); diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp index e8f5b255ab..13f3bd2060 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -502,7 +502,7 @@ void tst_QDBusMarshall::sendMaps_data() QTest::newRow("os-map") << qVariantFromValue(osmap) << "a{os}" << "[Argument: a{os} {[ObjectPath: /] = \"root\", [ObjectPath: /bar/baz] = \"bar and baz\", [ObjectPath: /foo] = \"foo\"}]"; - QHash gsmap; + QMap gsmap; QTest::newRow("empty-gs-map") << qVariantFromValue(gsmap) << "a{gs}" << "[Argument: a{gs} {}]"; gsmap[QDBusSignature("i")] = "int32"; @@ -601,7 +601,7 @@ void tst_QDBusMarshall::sendComplex_data() QTest::newRow("datetimelist") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" << "[Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 1977, 9, 13], [Argument: (iiii) 0, 0, 0, 0], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 13, 14, 0, 0], 0]}]"; - QHash lldtmap; + QMap lldtmap; QTest::newRow("empty-lldtmap") << qVariantFromValue(lldtmap) << "a{x((iii)(iiii)i)}" << "[Argument: a{x((iii)(iiii)i)} {}]"; lldtmap[0] = QDateTime(); @@ -621,7 +621,7 @@ void tst_QDBusMarshall::sendComplex_data() ssmap["c"] = "b"; ssmap["b"] = "c"; - QHash gsmap; + QMap gsmap; gsmap[QDBusSignature("i")] = "int32"; gsmap[QDBusSignature("s")] = "string"; gsmap[QDBusSignature("a{gs}")] = "array of dict_entry of (signature, string)"; -- cgit v1.2.3