summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qmap/tst_qmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qmap/tst_qmap.cpp')
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index d66fd28779..c3a8a88f0c 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -71,6 +71,7 @@ private slots:
void setSharable();
void insert();
+ void insertMap();
void checkMostLeftNode();
void initializerList();
void testInsertWithHint();
@@ -1265,6 +1266,101 @@ void tst_QMap::insert()
}
}
+void tst_QMap::insertMap()
+{
+ {
+ QMap<int, int> map;
+ map.insert(1, 1);
+ map.insert(2, 2);
+ map.insert(0, -1);
+
+ QMap<int, int> map2;
+ map2.insert(0, 0);
+ map2.insert(3, 3);
+ map2.insert(4, 4);
+
+ map.insert(map2);
+
+ QCOMPARE(map.count(), 5);
+ for (int i = 0; i < 5; ++i)
+ QCOMPARE(map[i], i);
+ }
+ {
+ QMap<int, int> map;
+ for (int i = 0; i < 10; ++i)
+ map.insert(i * 3, i);
+
+ QMap<int, int> map2;
+ for (int i = 0; i < 10; ++i)
+ map2.insert(i * 4, i);
+
+ map.insert(map2);
+
+ QCOMPARE(map.count(), 17);
+ for (int i = 0; i < 10; ++i) {
+ // i * 3 == i except for i = 4, 8
+ QCOMPARE(map[i * 3], (i && i % 4 == 0) ? i - (i / 4) : i);
+ QCOMPARE(map[i * 4], i);
+ }
+
+ auto it = map.cbegin();
+ int prev = it.key();
+ ++it;
+ for (auto end = map.cend(); it != end; ++it) {
+ QVERIFY(prev < it.key());
+ prev = it.key();
+ }
+ }
+ {
+ QMap<int, int> map;
+ map.insert(1, 1);
+
+ QMap<int, int> map2;
+
+ map.insert(map2);
+ QCOMPARE(map.count(), 1);
+ QCOMPARE(map[1], 1);
+ }
+ {
+ QMap<int, int> map;
+ QMap<int, int> map2;
+ map2.insert(1, 1);
+
+ map.insert(map2);
+ QCOMPARE(map.count(), 1);
+ QCOMPARE(map[1], 1);
+ }
+ {
+ QMap<int, int> map;
+ map.insert(0, 0);
+ map.insert(1, 1);
+ map.insert(2, 2);
+
+ // Test inserting into self, nothing should happen
+ map.insert(map);
+
+ QCOMPARE(map.count(), 3);
+ for (int i = 0; i < 3; ++i)
+ QCOMPARE(map[i], i);
+ }
+ {
+ // Here we use a QMultiMap and insert that into QMap,
+ // since it has multiple values with the same key the
+ // ordering is undefined so we won't test that, but
+ // make sure this isn't adding multiple entries with the
+ // same key to the QMap.
+ QMap<int, int> map;
+ QMultiMap<int, int> map2;
+ map2.insert(0, 0);
+ map2.insert(0, 1);
+ map2.insert(0, 2);
+
+ map.insert(map2);
+
+ QCOMPARE(map.count(), 1);
+ }
+}
+
void tst_QMap::checkMostLeftNode()
{
QMap<int, int> map;