tst_QAtomicInteger: fix UBs (signed overflow)
Drop addSub() test. It executes exactly the union of fetchAndAdd() and fetchAndSub(), which have already had their UBs fixed. No need to do fixes in duplicated code. Change-Id: Ib72caab0310fce3ff9a40c261d8a38518f91ecaf Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
24411e9743
commit
aedda12ef1
@ -179,9 +179,6 @@ private Q_SLOTS:
|
||||
void fetchAndSub_data() { addData(); }
|
||||
void fetchAndSub();
|
||||
|
||||
void addSub_data() { addData(); }
|
||||
void addSub();
|
||||
|
||||
void fetchAndOr_data() { addData(); }
|
||||
void fetchAndOr();
|
||||
|
||||
@ -661,96 +658,6 @@ void tst_QAtomicIntegerXX::fetchAndSub()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QAtomicIntegerXX::addSub()
|
||||
{
|
||||
QFETCH(LargeInt, value);
|
||||
QAtomicInteger<T> atomic(value);
|
||||
|
||||
// note: this test has undefined behavior for signed max and min
|
||||
T parcel1 = 42;
|
||||
T parcel2 = T(0-parcel1);
|
||||
T newValue1 = T(value) + parcel1;
|
||||
T newValue2 = T(value) - parcel1;
|
||||
|
||||
QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
|
||||
QCOMPARE(atomic.fetchAndAddAcquire(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndSubAcquire(parcel1), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubAcquire(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndAddAcquire(parcel1), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndAddAcquire(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndSubAcquire(parcel2), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubAcquire(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndAddAcquire(parcel2), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
|
||||
QCOMPARE(atomic.fetchAndAddRelease(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndSubRelease(parcel1), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubRelease(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndAddRelease(parcel1), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndAddRelease(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndSubRelease(parcel2), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubRelease(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndAddRelease(parcel2), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
|
||||
QCOMPARE(atomic.fetchAndAddOrdered(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndSubOrdered(parcel1), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubOrdered(parcel1), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndAddOrdered(parcel1), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndAddOrdered(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue2);
|
||||
QCOMPARE(atomic.fetchAndSubOrdered(parcel2), newValue2);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
QCOMPARE(atomic.fetchAndSubOrdered(parcel2), T(value));
|
||||
QCOMPARE(atomic.load(), newValue1);
|
||||
QCOMPARE(atomic.fetchAndAddOrdered(parcel2), newValue1);
|
||||
QCOMPARE(atomic.load(), T(value));
|
||||
|
||||
// operator+= and operator-=
|
||||
QCOMPARE(atomic += parcel1, newValue1);
|
||||
QCOMPARE(atomic -= parcel1, T(value));
|
||||
QCOMPARE(atomic -= parcel1, newValue2);
|
||||
QCOMPARE(atomic += parcel1, T(value));
|
||||
QCOMPARE(atomic += parcel2, newValue2);
|
||||
QCOMPARE(atomic -= parcel2, T(value));
|
||||
QCOMPARE(atomic -= parcel2, newValue1);
|
||||
QCOMPARE(atomic += parcel2, T(value));
|
||||
}
|
||||
|
||||
void tst_QAtomicIntegerXX::fetchAndOr()
|
||||
{
|
||||
QFETCH(LargeInt, value);
|
||||
|
Loading…
Reference in New Issue
Block a user