tst_QSet: check whether remove/removeIf detach if nothing is removed

They do.

Task-number: QTBUG-132831
Pick-to: 6.8 6.5 6.2 5.15
Change-Id: Ia4e9de7e443d11af9675924718c551a06bc4b447
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit b80679a90f39106052f1b53f4073e679d5077a5f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-01-15 22:57:05 +01:00 committed by Qt Cherry-pick Bot
parent da4e9b7637
commit cd99c6aad5

View File

@ -32,6 +32,7 @@ private slots:
void clear();
void cpp17ctad();
void remove();
void removeOnlyDetachesIfSomethingGetsRemoved();
void contains();
void containsSet();
void begin();
@ -392,6 +393,37 @@ void tst_QSet::remove()
}
}
void tst_QSet::removeOnlyDetachesIfSomethingGetsRemoved()
{
const QSet<int> set = {0, 1, 2, 3, 4};
auto copy = set;
QVERIFY(!copy.isDetached());
QVERIFY(!copy.remove(42));
QEXPECT_FAIL("", "QTBUG-132831", Continue);
QVERIFY(!copy.isDetached());
copy = set;
QVERIFY(!copy.isDetached());
QCOMPARE(copy.removeIf([] (auto) { return false; }), 0);
QEXPECT_FAIL("", "QTBUG-132831", Continue);
QVERIFY(!copy.isDetached());
copy = set;
QVERIFY(!copy.isDetached());
QVERIFY(copy.remove(4));
QVERIFY(copy.isDetached());
copy = set;
QVERIFY(!copy.isDetached());
QCOMPARE(copy.removeIf([] (int e) { return e == 3; }), 1);
QVERIFY(copy.isDetached());
}
void tst_QSet::contains()
{
QSet<QString> set1;