From d4eae78e6b34aef6adaa8a1460616b45504c1321 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 19 Sep 2023 10:46:15 +0200 Subject: [PATCH] Check that QMulti{Map,Hash} (still) store in reverse insertion order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's wrong, but let's not break it unconsciously. Pick-to: 6.5 Change-Id: Ic3daa7df4db2ef34ff5d08fddecf9a932ad92156 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 2d052b038d5c3e8ec55ca12b3ba531208a6d3cf1) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 21 +++++++++++++++++ tests/auto/corelib/tools/qmap/tst_qmap.cpp | 24 ++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index c906924b2b5..977fcc73b78 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -3,8 +3,10 @@ #include +#include #include #include +#include #include #include @@ -62,6 +64,7 @@ private slots: void eraseValidIteratorOnSharedHash(); void equal_range(); void insert_hash(); + void multiHashStoresInReverseInsertionOrder(); void emplace(); @@ -2484,6 +2487,24 @@ void tst_QHash::insert_hash() } } +void tst_QHash::multiHashStoresInReverseInsertionOrder() +{ + const QString strings[] = { + u"zero"_s, + u"null"_s, + u"nada"_s, + }; + { + QMultiHash hash; + for (const QString &string : strings) + hash.insert(0, string); + auto printOnFailure = qScopeGuard([&] { qDebug() << hash; }); + QVERIFY(std::equal(hash.begin(), hash.end(), + std::rbegin(strings), std::rend(strings))); + printOnFailure.dismiss(); + } +} + void tst_QHash::emplace() { { diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 577ea1e8989..93bf0b50706 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -3,7 +3,11 @@ #include #include + #include +#include + +using namespace Qt::StringLiterals; QT_WARNING_DISABLE_DEPRECATED @@ -61,6 +65,8 @@ private slots: void removeElementsInMap(); void toStdMap(); + void multiMapStoresInReverseInsertionOrder(); + // Tests for deprecated APIs. #if QT_DEPRECATED_SINCE(6, 0) void deprecatedInsertMulti(); @@ -2548,6 +2554,24 @@ void tst_QMap::toStdMap() toStdMapTestMethod>(expectedMultiMap); } +void tst_QMap::multiMapStoresInReverseInsertionOrder() +{ + const QString strings[] = { + u"zero"_s, + u"null"_s, + u"nada"_s, + }; + { + QMultiMap map; + for (const QString &string : strings) + map.insert(0, string); + auto printOnFailure = qScopeGuard([&] { qDebug() << map; }); + QVERIFY(std::equal(map.begin(), map.end(), + std::rbegin(strings), std::rend(strings))); + printOnFailure.dismiss(); + } +} + #if QT_DEPRECATED_SINCE(6, 0) void tst_QMap::deprecatedInsertMulti() {