summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-07-12 19:17:33 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-24 15:36:30 +0200
commit93ffb81df6e2cdc57ac8f70c6578f132024d7117 (patch)
tree979931da143ccbfaf567ca6a69c6430db2341f8a /tests
parentdacf9961da86751a59da0e84bc943fe0d1c8d95b (diff)
QHash/QSet - fix QHash::erase when the hash is shared
Before a call to erase on a shared instance would imply that the item was removed from the shared data (i.e all instances) This patch improves the behavior to detach and erase the item specified by the iterator (i.e same behavior as QVector) Since QSet uses QHash it improves QSet the same way. Change-Id: I850b1efcf7bdfc85ceddb23128b048af95f75063 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 71428310b8..af1c7aed15 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -78,6 +78,7 @@ private slots:
void qthash_data();
void qthash();
+ void eraseValidIteratorOnSharedHash();
};
struct Foo {
@@ -1352,5 +1353,34 @@ void tst_QHash::qthash()
QTEST(result, "hash");
}
+void tst_QHash::eraseValidIteratorOnSharedHash()
+{
+ QHash<int, int> a, b;
+ a.insert(10, 10);
+ a.insertMulti(10, 25);
+ a.insertMulti(10, 30);
+ a.insert(20, 20);
+ a.insert(40, 40);
+
+ QHash<int, int>::iterator i = a.begin();
+ while (i.value() != 25)
+ ++i;
+
+ b = a;
+ a.erase(i);
+
+ QCOMPARE(b.size(), 5);
+ QCOMPARE(a.size(), 4);
+
+ for (i = a.begin(); i != a.end(); ++i)
+ QVERIFY(i.value() != 25);
+
+ int itemsWith10 = 0;
+ for (i = b.begin(); i != b.end(); ++i)
+ itemsWith10 += (i.key() == 10);
+
+ QCOMPARE(itemsWith10, 3);
+}
+
QTEST_APPLESS_MAIN(tst_QHash)
#include "tst_qhash.moc"