summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qarraydata
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qarraydata')
-rw-r--r--tests/auto/corelib/tools/qarraydata/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h47
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp59
3 files changed, 34 insertions, 81 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/CMakeLists.txt b/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
index 4a2f9d0d6a..1d84630de2 100644
--- a/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qarraydata.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qarraydata Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qarraydata LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qarraydata
EXCEPTIONS
SOURCES
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index 1fc5e9b8e1..b92cd4a887 100644
--- a/tests/auto/corelib/tools/qarraydata/simplevector.h
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QARRAY_TEST_SIMPLE_VECTOR_H
@@ -32,6 +7,7 @@
#include <QtCore/qarraydata.h>
#include <QtCore/qarraydatapointer.h>
+#include <QtCore/qvarlengtharray.h>
#include <algorithm>
@@ -52,7 +28,7 @@ public:
}
explicit SimpleVector(size_t n, bool capacityReserved = false)
- : d(Data::allocate(n))
+ : d(n)
{
if (n)
d->appendInitialize(n);
@@ -61,7 +37,7 @@ public:
}
SimpleVector(size_t n, const T &t, bool capacityReserved = false)
- : d(Data::allocate(n))
+ : d(n)
{
if (n)
d->copyAppend(n, t);
@@ -70,7 +46,7 @@ public:
}
SimpleVector(const T *begin, const T *end, bool capacityReserved = false)
- : d(Data::allocate(end - begin))
+ : d(end - begin)
{
if (end - begin)
d->copyAppend(begin, end);
@@ -83,11 +59,6 @@ public:
{
}
- explicit SimpleVector(QPair<Data*, T*> ptr, size_t len = 0)
- : d(ptr, len)
- {
- }
-
SimpleVector(const QArrayDataPointer<T> &other)
: d(other)
{
@@ -159,7 +130,7 @@ public:
}
}
- SimpleVector detached(Data::allocate(qMax(n, size())));
+ SimpleVector detached(DataPointer(qMax(n, size())));
if (size()) {
detached.d->copyAppend(constBegin(), constEnd());
detached.d->setFlag(QArrayData::CapacityReserved);
@@ -173,7 +144,7 @@ public:
return;
if (d->needsDetach() || newSize > capacity()) {
- SimpleVector detached(Data::allocate(d->detachCapacity(newSize)));
+ SimpleVector detached(DataPointer(d->detachCapacity(newSize)));
if (newSize) {
if (newSize < size()) {
const T *const begin = constBegin();
@@ -247,7 +218,7 @@ public:
const T *const end = begin + d->size;
if (d->needsDetach()) {
- SimpleVector detached(Data::allocate(d->detachCapacity(size() - (last - first))));
+ SimpleVector detached(DataPointer(d->detachCapacity(size() - (last - first))));
if (first != begin)
detached.d->copyAppend(begin, first);
detached.d->copyAppend(last, end);
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++); });