diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-08-22 18:05:45 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-27 21:54:47 +0000 |
commit | 62b4c9169c23f510747a384fe3f1ed78bee4b435 (patch) | |
tree | da2d833da0056f95e71643f6b5eaa7e6f06ab06b /tests/auto/corelib | |
parent | b17d6b270178523cd1071cc2472c9d4b9789a567 (diff) |
QMap: add operator+ and - for iterators
We missed the chance of deprecating them in 5.15, so
they'll just add to the pain of porting to 6.0. We
should not keep them around forever, though; QMap isn't
random access and so its iterators should only have
bidirectional APIs.
Fixes: QTBUG-95334
Change-Id: I3577f7d25e8ab793722d2f220fd27bc85c622b0d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit cc584c59de644195ae0c4f7f99ad428e189df07d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/tools/qmap/tst_qmap.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 3e9a51cf2c..e5bddb5d8d 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -1129,6 +1129,29 @@ void tst_QMap::iterators() QVERIFY(stlIt.value() == testString.arg(i)); QCOMPARE(i, 100); + // Same but exercising deprecated APIs +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + stlIt = map.begin(); + QCOMPARE(stlIt.value(), QLatin1String("Teststring 1")); + + stlIt += 5; + QCOMPARE(stlIt.value(), QLatin1String("Teststring 6")); + + stlIt++; + QCOMPARE(stlIt.value(), QLatin1String("Teststring 7")); + + stlIt = stlIt - 3; + QCOMPARE(stlIt.value(), QLatin1String("Teststring 4")); + + stlIt--; + QCOMPARE(stlIt.value(), QLatin1String("Teststring 3")); + + for(stlIt = map.begin(), i = 1; stlIt != map.end(); ++stlIt, ++i) + QVERIFY(stlIt.value() == testString.arg(i)); + QCOMPARE(i, 100); +QT_WARNING_POP + //STL-Style const-iterators QMap<int, QString>::const_iterator cstlIt = map.constBegin(); @@ -1150,6 +1173,29 @@ void tst_QMap::iterators() QVERIFY(cstlIt.value() == testString.arg(i)); QCOMPARE(i, 100); + // Same but exercising deprecated APIs +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + cstlIt = map.constBegin(); + QCOMPARE(cstlIt.value(), QLatin1String("Teststring 1")); + + cstlIt += 5; + QCOMPARE(cstlIt.value(), QLatin1String("Teststring 6")); + + cstlIt++; + QCOMPARE(cstlIt.value(), QLatin1String("Teststring 7")); + + cstlIt = cstlIt - 3; + QCOMPARE(cstlIt.value(), QLatin1String("Teststring 4")); + + cstlIt--; + QCOMPARE(cstlIt.value(), QLatin1String("Teststring 3")); + + for(cstlIt = map.constBegin(), i = 1; cstlIt != map.constEnd(); ++cstlIt, ++i) + QVERIFY(cstlIt.value() == testString.arg(i)); + QCOMPARE(i, 100); +QT_WARNING_POP + //Java-Style iterators QMapIterator<int, QString> javaIt(map); |