summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-10-10 08:51:04 +0200
committerLars Knoll <lars.knoll@qt.io>2019-05-07 14:15:37 +0000
commitd510e1e7f919e01a3b875ff5a575b818e5ee03e8 (patch)
tree7ce9828d3e7f2867477736f2609762fb2977a56c /tests/auto/corelib
parent587bdd144b7e574e57f17167808774fa9783ee78 (diff)
Add swapItemsAt() to QVector
This closes one compatibility gap with QList, to make it easier to replace QList with QVector in Qt6. Change-Id: I5655bc4cd2150a6f09a1ed68c0742f3b42ca47e4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index f81ce11510..11c255b184 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -331,6 +331,8 @@ private slots:
void insertMove() const;
+ void swapItemsAt() const;
+
private:
template<typename T> void copyConstructor() const;
template<typename T> void add() const;
@@ -2990,5 +2992,22 @@ void tst_QVector::insertMove() const
QCOMPARE(Movable::counter.loadAcquire(), instancesCount);
}
+void tst_QVector::swapItemsAt() const
+{
+ QVector<int> v;
+ v << 0 << 1 << 2 << 3;
+
+ v.swapItemsAt(0, 2);
+ QCOMPARE(v.at(0), 2);
+ QCOMPARE(v.at(2), 0);
+
+ auto copy = v;
+ copy.swapItemsAt(0, 2);
+ QCOMPARE(v.at(0), 2);
+ QCOMPARE(v.at(2), 0);
+ QCOMPARE(copy.at(0), 0);
+ QCOMPARE(copy.at(2), 2);
+}
+
QTEST_MAIN(tst_QVector)
#include "tst_qvector.moc"