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:
parent
da4e9b7637
commit
cd99c6aad5
@ -32,6 +32,7 @@ private slots:
|
|||||||
void clear();
|
void clear();
|
||||||
void cpp17ctad();
|
void cpp17ctad();
|
||||||
void remove();
|
void remove();
|
||||||
|
void removeOnlyDetachesIfSomethingGetsRemoved();
|
||||||
void contains();
|
void contains();
|
||||||
void containsSet();
|
void containsSet();
|
||||||
void begin();
|
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()
|
void tst_QSet::contains()
|
||||||
{
|
{
|
||||||
QSet<QString> set1;
|
QSet<QString> set1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user