diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-11-09 14:34:44 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-11-17 11:46:12 +0100 |
commit | fed055790a226a0b9ade6880c418dbc565afd883 (patch) | |
tree | cab6d6bf7bddb5878a285cdc3ec951c9bd6c909c /tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp | |
parent | b6d6b3108baf3874166c28e16694d077f902c363 (diff) |
Simplify code in QExceptionSafetyPrimitives
QExceptionSafetyPrimitives::Destructor doesn't need an additional
template argument, and the freeze() method was unused.
Some methods of the Constructor class could also be simplified.
Change-Id: Iacf35bc8634f402519a8bd875b5efea7841f9db5
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index e5acee6971..d82f4c4a22 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -2384,7 +2384,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_constructor() { auto data = createDataPointer<ThrowingType>(20, 10); const auto originalSize = data.size; - const std::array<ThrowingType, 0> emptyRange{}; + std::array<ThrowingType, 0> emptyRange{}; doConstruction(data, data.end(), [] (Constructor &ctor) { return ctor.create(0); }); QCOMPARE(data.size, originalSize); @@ -2450,7 +2450,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_constructor() { auto data = createDataPointer<ThrowingType>(20, 10); auto reference = createDataPointer<ThrowingType>(20, 10); - const std::array<ThrowingType, 3> source = { + std::array<ThrowingType, 3> source = { ThrowingType(42), ThrowingType(43), ThrowingType(44) }; reference->copyAppend(source.begin(), source.end()); @@ -2542,7 +2542,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_constructor() { auto data = createDataPointer<ThrowingType>(20, 10); auto reference = createDataPointer<ThrowingType>(20, 10); - const std::array<ThrowingType, 4> source = { + std::array<ThrowingType, 4> source = { ThrowingType(42), ThrowingType(43), ThrowingType(44), ThrowingType(170) }; @@ -2570,7 +2570,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_constructor() void tst_QArrayData::exceptionSafetyPrimitives_destructor() { using Prims = QtPrivate::QArrayExceptionSafetyPrimitives<ThrowingType>; - using Destructor = typename Prims::Destructor<>; + using Destructor = typename Prims::Destructor; struct WatcherScope { @@ -2590,7 +2590,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() WatcherScope scope; Q_UNUSED(scope); { - auto where = data.end() - 1; + ThrowingType *where = data.end() - 1; Destructor destroyer(where); for (int i = 0; i < 2; ++i) { new (where + 1) ThrowingType(42); @@ -2613,7 +2613,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() WatcherScope scope; Q_UNUSED(scope); try { - auto where = data.end() - 1; + ThrowingType *where = data.end() - 1; Destructor destroyer(where); for (int i = 0; i < 2; ++i) { new (where + 1) ThrowingType(42 + i); @@ -2644,7 +2644,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() data.size -= 2; WatcherScope scope; Q_UNUSED(scope); { - auto where = data.begin() + 2; // Note: not updated data ptr, so begin + 2 + ThrowingType *where = data.begin() + 2; // Note: not updated data ptr, so begin + 2 Destructor destroyer(where); for (int i = 0; i < 2; ++i) { new (where - 1) ThrowingType(42); @@ -2670,7 +2670,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() data.size -= 2; WatcherScope scope; Q_UNUSED(scope); try { - auto where = data.begin() + 2; // Note: not updated data ptr, so begin + 2 + ThrowingType *where = data.begin() + 2; // Note: not updated data ptr, so begin + 2 Destructor destroyer(where); for (int i = 0; i < 2; ++i) { new (where - 1) ThrowingType(42 + i); @@ -2697,7 +2697,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() WatcherScope scope; Q_UNUSED(scope); try { - auto where = data.end() - 1; + ThrowingType *where = data.end() - 1; Destructor destroyer(where); ThrowingType::throwOnce = 1; new (where + 1) ThrowingType(42); @@ -2725,7 +2725,7 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() data.size -= 2; WatcherScope scope; Q_UNUSED(scope); try { - auto where = data.begin() - 1; // Note: intentionally out of range + ThrowingType *where = data.begin() - 1; // Note: intentionally out of range Destructor destroyer(where); for (int i = 0; i < 2; ++i) { new (where + 1) ThrowingType(42); @@ -2742,29 +2742,6 @@ void tst_QArrayData::exceptionSafetyPrimitives_destructor() QVERIFY(throwingTypeWatcher().destroyedIds[0] == 42); } } - - // extra: special case of freezing the position - { - auto data = createDataPointer<ThrowingType>(20, 10); - auto reference = createDataPointer<ThrowingType>(20, 10); - reference->erase(reference.end() - 1, reference.end()); - data.data()[data.size - 1] = ThrowingType(42); - - WatcherScope scope; Q_UNUSED(scope); - { - auto where = data.end(); - Destructor destroyer(where); - for (int i = 0; i < 3; ++i) { - --where; - destroyer.freeze(); - } - } - --data.size; // destroyed 1 element above - for (qsizetype i = 0; i < data.size; ++i) - QCOMPARE(data.data()[i], reference.data()[i]); - QVERIFY(throwingTypeWatcher().destroyedIds.size() == 1); - QCOMPARE(throwingTypeWatcher().destroyedIds[0], 42); - } } void tst_QArrayData::exceptionSafetyPrimitives_mover() |