Check that QMulti{Map,Hash} (still) store in reverse insertion order
It's wrong, but let's not break it unconsciously. Change-Id: Ic3daa7df4db2ef34ff5d08fddecf9a932ad92156 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 2d052b038d5c3e8ec55ca12b3ba531208a6d3cf1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit d4eae78e6b34aef6adaa8a1460616b45504c1321)
This commit is contained in:
parent
4b02329841
commit
d7e6f9a504
@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
|
#include <qdebug.h>
|
||||||
#include <qhash.h>
|
#include <qhash.h>
|
||||||
#include <qmap.h>
|
#include <qmap.h>
|
||||||
|
#include <qscopeguard.h>
|
||||||
#include <qset.h>
|
#include <qset.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -62,6 +64,7 @@ private slots:
|
|||||||
void eraseValidIteratorOnSharedHash();
|
void eraseValidIteratorOnSharedHash();
|
||||||
void equal_range();
|
void equal_range();
|
||||||
void insert_hash();
|
void insert_hash();
|
||||||
|
void multiHashStoresInReverseInsertionOrder();
|
||||||
|
|
||||||
void emplace();
|
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<int, QString> 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()
|
void tst_QHash::emplace()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
|
|
||||||
#include <qmap.h>
|
#include <qmap.h>
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QScopeGuard>
|
||||||
|
|
||||||
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
|
|
||||||
@ -61,6 +65,8 @@ private slots:
|
|||||||
void removeElementsInMap();
|
void removeElementsInMap();
|
||||||
void toStdMap();
|
void toStdMap();
|
||||||
|
|
||||||
|
void multiMapStoresInReverseInsertionOrder();
|
||||||
|
|
||||||
// Tests for deprecated APIs.
|
// Tests for deprecated APIs.
|
||||||
#if QT_DEPRECATED_SINCE(6, 0)
|
#if QT_DEPRECATED_SINCE(6, 0)
|
||||||
void deprecatedInsertMulti();
|
void deprecatedInsertMulti();
|
||||||
@ -2548,6 +2554,24 @@ void tst_QMap::toStdMap()
|
|||||||
toStdMapTestMethod<QMultiMap<int, QString>>(expectedMultiMap);
|
toStdMapTestMethod<QMultiMap<int, QString>>(expectedMultiMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QMap::multiMapStoresInReverseInsertionOrder()
|
||||||
|
{
|
||||||
|
const QString strings[] = {
|
||||||
|
u"zero"_s,
|
||||||
|
u"null"_s,
|
||||||
|
u"nada"_s,
|
||||||
|
};
|
||||||
|
{
|
||||||
|
QMultiMap<int, QString> 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)
|
#if QT_DEPRECATED_SINCE(6, 0)
|
||||||
void tst_QMap::deprecatedInsertMulti()
|
void tst_QMap::deprecatedInsertMulti()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user