summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp')
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp59
1 files changed, 17 insertions, 42 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index 856aa4b20f..e7a84d57ee 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -1,31 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <QtCore/QString>
@@ -97,7 +73,7 @@ void tst_QArrayData::referenceCounting()
{
{
// Reference counting initialized to 1 (owned)
- QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0 };
+ QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), {}, 0 };
QCOMPARE(array.ref_.loadRelaxed(), 1);
@@ -131,8 +107,8 @@ void tst_QArrayData::simpleVector()
SimpleVector<int> v4(nullptr, data, 0);
SimpleVector<int> v5(nullptr, data, 1);
SimpleVector<int> v6(nullptr, data, 7);
- SimpleVector<int> v7(10, 5);
- SimpleVector<int> v8(array, array + sizeof(array)/sizeof(*array));
+ const SimpleVector<int> v7(10, 5);
+ const SimpleVector<int> v8(array, array + sizeof(array)/sizeof(*array));
v3 = v1;
v1.swap(v3);
@@ -260,7 +236,7 @@ void tst_QArrayData::simpleVector()
{
int count = 0;
- Q_FOREACH (int value, v7) {
+ for (int value : v7) {
QCOMPARE(value, 5);
++count;
}
@@ -270,7 +246,7 @@ void tst_QArrayData::simpleVector()
{
int count = 0;
- Q_FOREACH (int value, v8) {
+ for (int value : v8) {
QCOMPARE(value, count);
++count;
}
@@ -508,7 +484,7 @@ void tst_QArrayData::allocate()
keeper.headers.append(data);
if (grow)
- QVERIFY(data->allocatedCapacity() > capacity);
+ QCOMPARE_GE(data->allocatedCapacity(), capacity);
else
QCOMPARE(data->allocatedCapacity(), capacity);
@@ -1140,8 +1116,7 @@ void tst_QArrayData::arrayOpsExtra()
const auto cloneArrayDataPointer = [] (auto &dataPointer, size_t capacity) {
using ArrayPointer = std::decay_t<decltype(dataPointer)>;
- using Type = std::decay_t<typename ArrayPointer::parameter_type>;
- ArrayPointer copy(QTypedArrayData<Type>::allocate(qsizetype(capacity)));
+ ArrayPointer copy{qsizetype(capacity)};
copy->copyAppend(dataPointer.begin(), dataPointer.end());
return copy;
};
@@ -1797,7 +1772,7 @@ void tst_QArrayData::literals()
{
{
QArrayDataPointer<char> d = Q_ARRAY_LITERAL(char, "ABCDEFGHIJ");
- QCOMPARE(d.size, 10u + 1u);
+ QCOMPARE(d.size, 10 + 1);
for (int i = 0; i < 10; ++i)
QCOMPARE(d.data()[i], char('A' + i));
}
@@ -1820,7 +1795,7 @@ void tst_QArrayData::literals()
{
// wchar_t is not necessarily 2-bytes
QArrayDataPointer<wchar_t> d = Q_ARRAY_LITERAL(wchar_t, L"ABCDEFGHIJ");
- QCOMPARE(d.size, 10u + 1u);
+ QCOMPARE(d.size, 10 + 1);
for (int i = 0; i < 10; ++i)
QCOMPARE(d.data()[i], wchar_t('A' + i));
}
@@ -1861,7 +1836,7 @@ void tst_QArrayData::variadicLiterals()
{
QArrayDataPointer<int> d =
Q_ARRAY_LITERAL(int, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
- QCOMPARE(d.size, 10u);
+ QCOMPARE(d.size, 10);
for (int i = 0; i < 10; ++i)
QCOMPARE(d.data()[i], i);
}
@@ -1869,7 +1844,7 @@ void tst_QArrayData::variadicLiterals()
{
QArrayDataPointer<char> d = Q_ARRAY_LITERAL(char,
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
- QCOMPARE(d.size, 10u);
+ QCOMPARE(d.size, 10);
for (int i = 0; i < 10; ++i)
QCOMPARE(d.data()[i], char('A' + i));
}
@@ -1877,7 +1852,7 @@ void tst_QArrayData::variadicLiterals()
{
QArrayDataPointer<const char *> d = Q_ARRAY_LITERAL(const char *,
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
- QCOMPARE(d.size, 10u);
+ QCOMPARE(d.size, 10);
for (int i = 0; i < 10; ++i) {
QCOMPARE(d.data()[i][0], char('A' + i));
QCOMPARE(d.data()[i][1], '\0');
@@ -2061,7 +2036,7 @@ void tst_QArrayData::dataPointerAllocate()
const auto createDataPointer = [] (qsizetype capacity, auto initValue) {
using Type = std::decay_t<decltype(initValue)>;
Q_UNUSED(initValue);
- return QArrayDataPointer<Type>(QTypedArrayData<Type>::allocate(capacity));
+ return QArrayDataPointer<Type>(capacity);
};
const auto testRealloc = [&] (qsizetype capacity, qsizetype newSize, auto initValue) {
@@ -2477,7 +2452,7 @@ void tst_QArrayData::relocateWithExceptions()
};
const auto createDataPointer = [](qsizetype capacity, qsizetype initSize) {
- QArrayDataPointer<ThrowingType> qadp(QTypedArrayData<ThrowingType>::allocate(capacity));
+ QArrayDataPointer<ThrowingType> qadp(capacity);
qadp->appendInitialize(initSize);
int i = 0;
std::generate(qadp.begin(), qadp.end(), [&i]() { return ThrowingType(i++); });