summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-11-11 14:51:32 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-17 11:47:16 +0100
commit6431565e0a62365259196b02c1aec892d9f85a0a (patch)
tree9d33872d16de97171eb707355ea52c19db7be6da /tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
parentfaea8e266114abcc9ebd517a552bf7d0e6770575 (diff)
Simplify QArrayDataOps::insert() for movable types
Avoid ever having to call a destructor and unify the code for insertion at the front or at the end. Change-Id: Ie50ae2d4a75477cfdae9d5bd4bddf268426d95b5 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.cpp157
1 files changed, 0 insertions, 157 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index a5d2967c4a..7ab93d636a 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -85,7 +85,6 @@ private slots:
void selfEmplaceBackwards();
void selfEmplaceForward();
#ifndef QT_NO_EXCEPTIONS
- void exceptionSafetyPrimitives_constructor();
void exceptionSafetyPrimitives_displacer();
#endif
};
@@ -2349,162 +2348,6 @@ static QArrayDataPointer<T> createDataPointer(qsizetype capacity, qsizetype init
return adp;
}
-void tst_QArrayData::exceptionSafetyPrimitives_constructor()
-{
- using Prims = QtPrivate::QArrayExceptionSafetyPrimitives<ThrowingType>;
- using Constructor = typename Prims::Constructor;
-
- struct WatcherScope
- {
- WatcherScope() { throwingTypeWatcher().watch = true; }
- ~WatcherScope()
- {
- throwingTypeWatcher().watch = false;
- throwingTypeWatcher().destroyedIds.clear();
- }
- };
-
- const auto doConstruction = [] (auto &dataPointer, auto where, auto op) {
- Constructor ctor(where);
- dataPointer.size += op(ctor);
- };
-
- // empty ranges
- {
- auto data = createDataPointer<ThrowingType>(20, 10);
- const auto originalSize = data.size;
- const std::array<ThrowingType, 0> emptyRange{};
-
- doConstruction(data, data.end(), [] (Constructor &ctor) { return ctor.create(0); });
- QCOMPARE(data.size, originalSize);
-
- doConstruction(data, data.end(), [&emptyRange] (Constructor &ctor) {
- return ctor.copy(emptyRange.begin(), emptyRange.end());
- });
- QCOMPARE(data.size, originalSize);
-
- doConstruction(data, data.end(), [] (Constructor &ctor) {
- return ctor.clone(0, ThrowingType(42));
- });
- QCOMPARE(data.size, originalSize);
- }
-
- // successful create
- {
- auto data = createDataPointer<ThrowingType>(20, 10);
- auto reference = createDataPointer<ThrowingType>(20, 10);
- reference->appendInitialize(reference.size + 1);
-
- doConstruction(data, data.end(), [] (Constructor &ctor) { return ctor.create(1); });
-
- QCOMPARE(data.size, reference.size);
- for (qsizetype i = 0; i < data.size; ++i)
- QCOMPARE(data.data()[i], reference.data()[i]);
- }
-
- // successful copy
- {
- auto data = createDataPointer<ThrowingType>(20, 10);
- auto reference = createDataPointer<ThrowingType>(20, 10);
- const std::array<ThrowingType, 3> source = {
- ThrowingType(42), ThrowingType(43), ThrowingType(44)
- };
- reference->copyAppend(source.begin(), source.end());
-
- doConstruction(data, data.end(), [&source] (Constructor &ctor) {
- return ctor.copy(source.begin(), source.end());
- });
-
- QCOMPARE(data.size, reference.size);
- for (qsizetype i = 0; i < data.size; ++i)
- QCOMPARE(data.data()[i], reference.data()[i]);
-
- reference->copyAppend(2, source[0]);
-
- doConstruction(data, data.end(), [&source] (Constructor &ctor) {
- return ctor.clone(2, source[0]);
- });
-
- QCOMPARE(data.size, reference.size);
- for (qsizetype i = 0; i < data.size; ++i)
- QCOMPARE(data.data()[i], reference.data()[i]);
- }
-
- // failed create
- {
- auto data = createDataPointer<ThrowingType>(20, 10);
- auto reference = createDataPointer<ThrowingType>(20, 10);
-
- for (uint throwOnNthConstruction : {1, 3}) {
- WatcherScope scope; Q_UNUSED(scope);
- try {
- ThrowingType::throwOnce = throwOnNthConstruction;
- doConstruction(data, data.end(), [] (Constructor &ctor) {
- return ctor.create(5);
- });
- } catch (const std::runtime_error &e) {
- QCOMPARE(std::string(e.what()), ThrowingType::throwString);
- QCOMPARE(data.size, reference.size);
- for (qsizetype i = 0; i < data.size; ++i)
- QCOMPARE(data.data()[i], reference.data()[i]);
- QCOMPARE(throwingTypeWatcher().destroyedIds.size(), (throwOnNthConstruction - 1));
- for (auto id : throwingTypeWatcher().destroyedIds)
- QCOMPARE(id, 0);
- }
- }
- }
-
- // failed copy
- {
- auto data = createDataPointer<ThrowingType>(20, 10);
- auto reference = createDataPointer<ThrowingType>(20, 10);
- const std::array<ThrowingType, 4> source = {
- ThrowingType(42), ThrowingType(43), ThrowingType(44), ThrowingType(170)
- };
-
- // copy range
- for (uint throwOnNthConstruction : {1, 3}) {
- WatcherScope scope; Q_UNUSED(scope);
- try {
- ThrowingType::throwOnce = throwOnNthConstruction;
- doConstruction(data, data.end(), [&source] (Constructor &ctor) {
- return ctor.copy(source.begin(), source.end());
- });
- } catch (const std::runtime_error &e) {
- QCOMPARE(std::string(e.what()), ThrowingType::throwString);
- QCOMPARE(data.size, reference.size);
- for (qsizetype i = 0; i < data.size; ++i)
- QCOMPARE(data.data()[i], reference.data()[i]);
- const auto destroyedSize = throwingTypeWatcher().destroyedIds.size();
- QCOMPARE(destroyedSize, (throwOnNthConstruction - 1));
- for (size_t i = 0; i < destroyedSize; ++i)
- QCOMPARE(throwingTypeWatcher().destroyedIds[i], source[destroyedSize - i - 1]);
- }
- }
-
- // copy value
- for (uint throwOnNthConstruction : {1, 3}) {
- const ThrowingType value(512);
- QVERIFY(QArrayDataPointer<ThrowingType>::pass_parameter_by_value == false);
- WatcherScope scope; Q_UNUSED(scope);
- try {
- ThrowingType::throwOnce = throwOnNthConstruction;
- doConstruction(data, data.end(), [&value] (Constructor &ctor) {
- return ctor.clone(5, value);
- });
- } catch (const std::runtime_error &e) {
- QCOMPARE(std::string(e.what()), ThrowingType::throwString);
- QCOMPARE(data.size, reference.size);
- for (qsizetype i = 0; i < data.size; ++i)
- QCOMPARE(data.data()[i], reference.data()[i]);
- QCOMPARE(throwingTypeWatcher().destroyedIds.size(), (throwOnNthConstruction - 1));
- for (auto id : throwingTypeWatcher().destroyedIds)
- QCOMPARE(id, 512);
- }
- }
- }
-}
-
void tst_QArrayData::exceptionSafetyPrimitives_displacer()
{
QVERIFY(QTypeInfo<ThrowingType>::isRelocatable);