summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/CMakeLists.txt14
-rw-r--r--tests/auto/corelib/tools/collections/CMakeLists.txt7
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp193
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp423
-rw-r--r--tests/auto/corelib/tools/qalgorithms/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp101
-rw-r--r--tests/auto/corelib/tools/qarraydata/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h30
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp39
-rw-r--r--tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp157
-rw-r--r--tests/auto/corelib/tools/qbitarray/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp41
-rw-r--r--tests/auto/corelib/tools/qcache/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qcache/tst_qcache.cpp112
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/testhelper/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp29
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp35
-rw-r--r--tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp57
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt21
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/testdata.qrc6
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp145
-rw-r--r--tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp45
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp41
-rw-r--r--tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp29
-rw-r--r--tests/auto/corelib/tools/qflatmap/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp362
-rw-r--r--tests/auto/corelib/tools/qfreelist/CMakeLists.txt13
-rw-r--r--tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp29
-rw-r--r--tests/auto/corelib/tools/qhash/CMakeLists.txt7
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp467
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp111
-rw-r--r--tests/auto/corelib/tools/qhashseed/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp66
-rw-r--r--tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp29
-rw-r--r--tests/auto/corelib/tools/qline/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qline/tst_qline.cpp71
-rw-r--r--tests/auto/corelib/tools/qlist/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qlist/tst_qlist.cpp61
-rw-r--r--tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm31
-rw-r--r--tests/auto/corelib/tools/qmakearray/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp29
-rw-r--r--tests/auto/corelib/tools/qmap/CMakeLists.txt7
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp338
-rw-r--r--tests/auto/corelib/tools/qmargins/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qmargins/tst_qmargins.cpp92
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp140
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp50
-rw-r--r--tests/auto/corelib/tools/qpair/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qpair/tst_qpair.cpp31
-rw-r--r--tests/auto/corelib/tools/qpoint/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qpoint/tst_qpoint.cpp80
-rw-r--r--tests/auto/corelib/tools/qpointf/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qpointf/tst_qpointf.cpp51
-rw-r--r--tests/auto/corelib/tools/qqueue/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qqueue/tst_qqueue.cpp29
-rw-r--r--tests/auto/corelib/tools/qrect/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qrect/tst_qrect.cpp98
-rw-r--r--tests/auto/corelib/tools/qringbuffer/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp45
-rw-r--r--tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp97
-rw-r--r--tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp29
-rw-r--r--tests/auto/corelib/tools/qscopeguard/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp31
-rw-r--r--tests/auto/corelib/tools/qset/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp109
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.cpp33
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.h29
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp31
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h31
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/nontracked.cpp29
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/nontracked.h29
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp92
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/wrapper.cpp29
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/wrapper.h29
-rw-r--r--tests/auto/corelib/tools/qsize/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qsize/tst_qsize.cpp80
-rw-r--r--tests/auto/corelib/tools/qsizef/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qsizef/tst_qsizef.cpp51
-rw-r--r--tests/auto/corelib/tools/qstl/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qstl/tst_qstl.cpp29
-rw-r--r--tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp71
-rw-r--r--tests/auto/corelib/tools/qtimeline/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp83
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp315
-rw-r--r--tests/auto/corelib/tools/qversionnumber/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp74
102 files changed, 3141 insertions, 2074 deletions
diff --git a/tests/auto/corelib/tools/CMakeLists.txt b/tests/auto/corelib/tools/CMakeLists.txt
index 3398033b3f..9bcdc12bfc 100644
--- a/tests/auto/corelib/tools/CMakeLists.txt
+++ b/tests/auto/corelib/tools/CMakeLists.txt
@@ -1,4 +1,7 @@
-# Generated from tools.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+add_subdirectory(qatomicscopedvaluerollback)
if(NOT INTEGRITY)
add_subdirectory(collections)
endif()
@@ -14,7 +17,9 @@ add_subdirectory(qduplicatetracker)
add_subdirectory(qeasingcurve)
add_subdirectory(qexplicitlyshareddatapointer)
add_subdirectory(qflatmap)
-add_subdirectory(qfreelist)
+if(QT_FEATURE_private_tests)
+ add_subdirectory(qfreelist)
+endif()
add_subdirectory(qhash)
add_subdirectory(qhashfunctions)
add_subdirectory(qhashseed)
@@ -44,10 +49,7 @@ add_subdirectory(qsizef)
add_subdirectory(qstl)
add_subdirectory(qvarlengtharray)
add_subdirectory(qversionnumber)
-# QTBUG-88137 # special case
-if(NOT ANDROID)
- add_subdirectory(qtimeline)
-endif()
+add_subdirectory(qtimeline)
if(APPLE)
add_subdirectory(qmacautoreleasepool)
endif()
diff --git a/tests/auto/corelib/tools/collections/CMakeLists.txt b/tests/auto/corelib/tools/collections/CMakeLists.txt
index 32ef8d7506..952d2eb49d 100644
--- a/tests/auto/corelib/tools/collections/CMakeLists.txt
+++ b/tests/auto/corelib/tools/collections/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from collections.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_collections Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_collections
SOURCES
tst_collections.cpp
- DEFINES
- # -QT_NO_JAVA_STYLE_ITERATORS # special case remove
)
+
+qt_internal_undefine_global_definition(tst_collections QT_NO_JAVA_STYLE_ITERATORS)
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index 80d1d90f2a..af7a7ec0df 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
// test the container forwards
@@ -63,6 +38,9 @@ void foo()
#include <QTest>
#include <QVector>
+#include <QScopedPointer>
+#include <QThread>
+#include <QSemaphore>
#include <algorithm>
@@ -123,6 +101,15 @@ private slots:
void foreach_2();
void insert_remove_loop();
+
+ void detachAssociativeContainerQMap() { detachAssociativeContainerImpl<QMap>(); }
+ void detachAssociativeContainerQMultiMap() { detachAssociativeContainerImpl<QMultiMap>(); }
+ void detachAssociativeContainerQHash() { detachAssociativeContainerImpl<QHash>(); }
+ void detachAssociativeContainerQMultiHash() { detachAssociativeContainerImpl<QMultiHash>(); }
+
+private:
+ template <template<typename, typename> typename Container>
+ void detachAssociativeContainerImpl();
};
struct LargeStatic {
@@ -253,15 +240,11 @@ Q_DECLARE_METATYPE(NoCmpParamRecursiveMapK);
Q_DECLARE_METATYPE(NoCmpParamRecursiveMultiMapV);
Q_DECLARE_METATYPE(NoCmpParamRecursiveMultiMapK);
Q_DECLARE_METATYPE(NoCmpParamRecursiveHashK);
-// TODO: fix, this requires operator== from key type (QTBUG-96256)
-// Q_DECLARE_METATYPE(NoCmpParamRecursiveHashV);
+Q_DECLARE_METATYPE(NoCmpParamRecursiveHashV);
Q_DECLARE_METATYPE(NoCmpParamRecursiveMultiHashK);
-// TODO: fix, this requires operator== from key type (QTBUG-96256)
-// Q_DECLARE_METATYPE(NoCmpParamRecursiveMultiHashK);
+Q_DECLARE_METATYPE(NoCmpParamRecursiveMultiHashV);
Q_DECLARE_METATYPE(NoCmpRecursiveList);
-// TODO: fix, this requires operator== (QTBUG-96257)
-// Q_DECLARE_METATYPE(NoCmpRecursiveSet);
Q_DECLARE_METATYPE(NoCmpRecursiveMapV);
Q_DECLARE_METATYPE(NoCmpRecursiveMapK);
Q_DECLARE_METATYPE(NoCmpRecursiveMultiMapV);
@@ -287,9 +270,9 @@ static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMapV>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMapK>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiMapV>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiMapK>);
-static_assert(QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveHashV>);
+static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveHashV>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveHashK>);
-static_assert(QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiHashV>);
+static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiHashV>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiHashK>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveList>);
@@ -304,10 +287,15 @@ static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveHashK>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiHashV>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiHashK>);
+template <typename T>
+constexpr inline bool has_prepend_v = true;
+template <typename T, qsizetype N>
+constexpr inline bool has_prepend_v<QVarLengthArray<T,N>> = false; // deprecated in Qt 6.3
+
void tst_Collections::typeinfo()
{
- QVERIFY(QTypeInfo<int*>::isPointer);
- QVERIFY(!QTypeInfo<int>::isPointer);
+ QVERIFY(std::is_pointer_v<int*>);
+ QVERIFY(!std::is_pointer_v<int>);
QVERIFY(QTypeInfo<QString>::isComplex);
QVERIFY(!QTypeInfo<int>::isComplex);
}
@@ -696,7 +684,7 @@ QT_WARNING_POP
list.insert(0, "atzero");
QCOMPARE(list.at(0), QString("atzero"));
- int listCount = list.count();
+ int listCount = list.size();
list.insert(listCount, "atcount");
QCOMPARE(list.at(listCount), QString("atcount"));
}
@@ -2030,8 +2018,8 @@ void tst_Collections::qstring()
s = "ascii";
s += QChar((uchar) 0xb0);
QVERIFY(s.toUtf8() != s.toLatin1());
- QCOMPARE(s[s.length()-1].unicode(), (ushort)0xb0);
- QCOMPARE(s.left(s.length()-1), QLatin1String("ascii"));
+ QCOMPARE(s[s.size()-1].unicode(), char16_t(0xb0));
+ QCOMPARE(s.left(s.size()-1), QLatin1String("ascii"));
QVERIFY(s == QString::fromUtf8(s.toUtf8().constData()));
@@ -2083,7 +2071,7 @@ void tst_Collections::qstring()
QString str = "Hello";
- QString cstr = QString::fromRawData(str.unicode(), str.length());
+ QString cstr = QString::fromRawData(str.unicode(), str.size());
QCOMPARE(str, QLatin1String("Hello"));
QCOMPARE(cstr, QLatin1String("Hello"));
cstr.clear();
@@ -2705,7 +2693,7 @@ void tst_Collections::vector_stl()
QFETCH(QStringList, elements);
QList<QString> vector;
- for (int i = 0; i < elements.count(); ++i)
+ for (int i = 0; i < elements.size(); ++i)
vector << elements.at(i);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
@@ -2740,7 +2728,7 @@ void tst_Collections::list_stl()
QFETCH(QStringList, elements);
QList<QString> list;
- for (int i = 0; i < elements.count(); ++i)
+ for (int i = 0; i < elements.size(); ++i)
list << elements.at(i);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
@@ -2833,7 +2821,7 @@ void instantiateContainer()
container.clear();
container.contains(value);
- container.count();
+ container.size();
container.empty();
container.isEmpty();
container.size();
@@ -3081,9 +3069,8 @@ class T2;
void tst_Collections::forwardDeclared()
{
-#define COMMA ,
-#define TEST(type) do { \
- using C = type; \
+#define TEST(...) do { \
+ using C = __VA_ARGS__; \
C *x = nullptr; \
C::iterator i; \
C::const_iterator j; \
@@ -3092,16 +3079,15 @@ void tst_Collections::forwardDeclared()
Q_UNUSED(j); \
} while (false)
- TEST(QHash<Key1 COMMA T1>);
- TEST(QMap<Key1 COMMA T1>);
- TEST(QMultiMap<Key1 COMMA T1>);
+ TEST(QHash<Key1, T1>);
+ TEST(QMap<Key1, T1>);
+ TEST(QMultiMap<Key1, T1>);
TEST(QList<T1>);
TEST(QVector<T1>);
TEST(QStack<T1>);
TEST(QQueue<T1>);
TEST(QSet<T1>);
#undef TEST
-#undef COMMA
{
using C = QPair<T1, T2>;
@@ -3258,7 +3244,7 @@ template<template<class> class C> void QTBUG13079_collectionInsideCollectionImpl
QCOMPARE(nodeList.first().s, QString::fromLatin1("child"));
nodeList = nodeList.first().children;
- QCOMPARE(nodeList.count(), 0);
+ QCOMPARE(nodeList.size(), 0);
nodeList << QTBUG13079_Node<C>();
}
@@ -3283,7 +3269,7 @@ template<template<class, class> class C> void QTBUG13079_collectionInsideCollect
QCOMPARE(nodeMap[12].s, QString::fromLatin1("child"));
nodeMap = nodeMap[12].children;
- QCOMPARE(nodeMap.count(), 0);
+ QCOMPARE(nodeMap.size(), 0);
nodeMap[42] = QTBUG13079_NodeAssoc<C>();
}
@@ -3350,7 +3336,7 @@ void tst_Collections::QTBUG13079_collectionInsideCollection()
QSet<QTBUG13079_Node<QSet> > nodeSet;
nodeSet << QTBUG13079_Node<QSet>();
nodeSet = nodeSet.begin()->children;
- QCOMPARE(nodeSet.count(), 0);
+ QCOMPARE(nodeSet.size(), 0);
}
QTBUG13079_collectionInsideCollectionAssocImpl<QMap>();
@@ -3372,7 +3358,7 @@ template<class Container> void foreach_test_arrays(const Container &container)
set << val;
i++;
}
- QCOMPARE(set.count(), container.count());
+ QCOMPARE(set.size(), container.size());
//modify the container while iterating.
Container c2 = container;
@@ -3409,9 +3395,9 @@ void tst_Collections::foreach_2()
varl2 << i;
varl3 << i;
}
- QCOMPARE(varl1.count(), intlist.count());
- QCOMPARE(varl2.count(), intlist.count());
- QCOMPARE(varl3.count(), intlist.count());
+ QCOMPARE(varl1.size(), intlist.size());
+ QCOMPARE(varl2.size(), intlist.size());
+ QCOMPARE(varl3.size(), intlist.size());
QVarLengthArray<QString> varl4;
QVarLengthArray<QString, 3> varl5;
@@ -3421,9 +3407,9 @@ void tst_Collections::foreach_2()
varl5 << str;
varl6 << str;
}
- QCOMPARE(varl4.count(), strlist.count());
- QCOMPARE(varl5.count(), strlist.count());
- QCOMPARE(varl6.count(), strlist.count());
+ QCOMPARE(varl4.size(), strlist.size());
+ QCOMPARE(varl5.size(), strlist.size());
+ QCOMPARE(varl6.size(), strlist.size());
}
struct IntOrString
@@ -3444,14 +3430,17 @@ template<class Container> void insert_remove_loop_impl()
t.append(T(IntOrString(1)));
t << (T(IntOrString(2)));
t += (T(IntOrString(3)));
- t.prepend(T(IntOrString(4)));
+ if constexpr (has_prepend_v<Container>)
+ t.prepend(T(IntOrString(4)));
+ else
+ t.insert(t.cbegin(), T(IntOrString(4)));
t.insert(2, 3 , T(IntOrString(5)));
t.insert(4, T(IntOrString(6)));
t.insert(t.begin() + 2, T(IntOrString(7)));
t.insert(t.begin() + 5, 3, T(IntOrString(8)));
int expect1[] = { 4 , 1 , 7, 5 , 5 , 8, 8, 8, 6, 5, 2 , 3 };
- QCOMPARE(size_t(t.count()), sizeof(expect1)/sizeof(int));
- for (int i = 0; i < t.count(); i++) {
+ QCOMPARE(size_t(t.size()), sizeof(expect1)/sizeof(int));
+ for (int i = 0; i < t.size(); i++) {
QCOMPARE(t[i], T(IntOrString(expect1[i])));
}
@@ -3465,8 +3454,8 @@ template<class Container> void insert_remove_loop_impl()
t.remove(7);
t.remove(2, 3);
int expect2[] = { 4 , 1 , 9, 8, 6, 5, 2 , 3 };
- QCOMPARE(size_t(t.count()), sizeof(expect2)/sizeof(int));
- for (int i = 0; i < t.count(); i++) {
+ QCOMPARE(size_t(t.size()), sizeof(expect2)/sizeof(int));
+ for (int i = 0; i < t.size(); i++) {
QCOMPARE(t[i], T(IntOrString(expect2[i])));
}
@@ -3478,16 +3467,16 @@ template<class Container> void insert_remove_loop_impl()
}
int expect3[] = { 1 , 9, 5, 3 };
- QCOMPARE(size_t(t.count()), sizeof(expect3)/sizeof(int));
- for (int i = 0; i < t.count(); i++) {
+ QCOMPARE(size_t(t.size()), sizeof(expect3)/sizeof(int));
+ for (int i = 0; i < t.size(); i++) {
QCOMPARE(t[i], T(IntOrString(expect3[i])));
}
t.erase(t.begin() + 1, t.end() - 1);
int expect4[] = { 1 , 3 };
- QCOMPARE(size_t(t.count()), sizeof(expect4)/sizeof(int));
- for (int i = 0; i < t.count(); i++) {
+ QCOMPARE(size_t(t.size()), sizeof(expect4)/sizeof(int));
+ for (int i = 0; i < t.size(); i++) {
QCOMPARE(t[i], T(IntOrString(expect4[i])));
}
@@ -3504,8 +3493,8 @@ template<class Container> void insert_remove_loop_impl()
int expect5[] = { 1, 1, 2, 3*3, 3, 3*3+1, 10, 11*11, 11, 11*11+1, 12 , 13*13, 13, 13*13+1, 14,
15*15, 15, 15*15+1, 16 , 17*17, 17, 17*17+1 ,18 , 19*19, 19, 19*19+1, 20, 21*21, 21, 21*21+1 };
- QCOMPARE(size_t(t.count()), sizeof(expect5)/sizeof(int));
- for (int i = 0; i < t.count(); i++) {
+ QCOMPARE(size_t(t.size()), sizeof(expect5)/sizeof(int));
+ for (int i = 0; i < t.size(); i++) {
QCOMPARE(t[i], T(IntOrString(expect5[i])));
}
@@ -3515,8 +3504,8 @@ template<class Container> void insert_remove_loop_impl()
t.insert(2, 4, T(IntOrString(7)));
int expect6[] = { 1, 2, 7, 7, 7, 7, 9, 9, 9, 9, 3, 4 };
- QCOMPARE(size_t(t.count()), sizeof(expect6)/sizeof(int));
- for (int i = 0; i < t.count(); i++) {
+ QCOMPARE(size_t(t.size()), sizeof(expect6)/sizeof(int));
+ for (int i = 0; i < t.size(); i++) {
QCOMPARE(t[i], T(IntOrString(expect6[i])));
}
@@ -3549,7 +3538,63 @@ void tst_Collections::insert_remove_loop()
insert_remove_loop_impl<QVarLengthArray<std::string, 15>>();
}
+template <template<typename, typename> typename Container>
+void tst_Collections::detachAssociativeContainerImpl()
+{
+ constexpr int RUNS = 50;
+
+ for (int run = 0; run < RUNS; ++run) {
+ Container<int, int> container;
+
+ for (int i = 0; i < 1'000; ++i) {
+ container.insert(i, i);
+ container.insert(i, i); // for multi-keyed containers
+ }
+
+ const auto it = container.constBegin();
+ const auto &key = it.key();
+ const auto &value = it.value();
+ const auto keyCopy = key;
+ const auto valueCopy = value;
+
+ QSemaphore sem1, sem2;
+ auto detachInAnotherThread = [&sem1, &sem2, copy = container]() mutable {
+ sem1.release();
+ sem2.acquire();
+ copy.clear(); // <==
+ };
+
+ QScopedPointer thread(QThread::create(std::move(detachInAnotherThread)));
+ thread->start();
+
+ sem2.release();
+ sem1.acquire();
+
+ // The following call may detach (because the container is
+ // shared), and then use key/value to search+insert.
+ //
+ // This means that key/value, as references, have to be valid
+ // throughout the insertion procedure. Note that they are
+ // references into the container *itself*; and that the
+ // insertion procedure is working on a new (detached) copy of
+ // the container's payload.
+ //
+ // There is now a possible scenario in which the clear() above
+ // finds the copy's refcount at 1, hence not perform a detach,
+ // and destroy its payload. But key/value were references into
+ // *that* payload (it's the payload that `container` itself
+ // used to share). If inside insert() we don't take extra
+ // measures to keep the payload alive, now they're dangling and
+ // the insertion will malfunction.
+ container.insert(key, value);
+
+ QVERIFY(container.contains(keyCopy));
+ QCOMPARE(container.value(keyCopy), valueCopy);
+
+ thread->wait();
+ }
+}
QTEST_APPLESS_MAIN(tst_Collections)
#include "tst_collections.moc"
diff --git a/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt b/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt
index 68d6f4bc0e..247248f25d 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt
+++ b/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from containerapisymmetry.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_containerapisymmetry Test:
diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
index 3224a8c877..c438d6f961 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
+++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
@@ -1,36 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
-** 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) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include "qbytearray.h"
#include "qdebug.h"
#include "qhash.h"
+#include "qmap.h"
+#include "qset.h"
#include "qlist.h"
#include "qstring.h"
#include "qvarlengtharray.h"
@@ -38,17 +15,34 @@
#include <algorithm>
#include <functional>
#include <vector> // for reference
+#include <iostream>
#include <list>
#include <set>
+#include <sstream>
#include <map>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
-#if __cplusplus >= 202002L && defined(__cpp_lib_erase_if)
+#if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L
# define STDLIB_HAS_UNIFORM_ERASURE
#endif
+QT_BEGIN_NAMESPACE
+std::ostream &operator<<(std::ostream &os, const QChar &c)
+{
+ Q_ASSERT(c == QLatin1Char{c.toLatin1()});
+ return os << c.toLatin1();
+}
+std::istream &operator>>(std::istream &os, QChar &c)
+{
+ char cL1;
+ os >> cL1;
+ c = QLatin1Char{cL1};
+ return os;
+}
+QT_END_NAMESPACE
+
struct Movable
{
explicit Movable(int i = 0) noexcept
@@ -70,6 +64,11 @@ struct Movable
int i;
static int instanceCount;
+
+ friend std::ostream &operator<<(std::ostream &os, const Movable &m)
+ { return os << m.i; }
+ friend std::istream &operator>>(std::istream &os, Movable &m)
+ { return os >> m.i; }
};
int Movable::instanceCount = 0;
@@ -111,6 +110,11 @@ struct Complex
int i;
static int instanceCount;
+
+ friend std::ostream &operator<<(std::ostream &os, const Complex &c)
+ { return os << c.i; }
+ friend std::istream &operator>>(std::istream &os, Complex &c)
+ { return os >> c.i; }
};
int Complex::instanceCount = 0;
@@ -318,6 +322,27 @@ private Q_SLOTS:
private:
template <typename Container>
+ void resize_impl() const;
+
+private Q_SLOTS:
+ void resize_std_vector() { resize_impl<std::vector<int>>(); }
+ void resize_QList() { resize_impl<QList<qintptr>>(); }
+ void resize_QVarLengthArray() { resize_impl<QVarLengthArray<int>>(); }
+ void resize_QString() { resize_impl<QString>(); }
+ void resize_QByteArray() { resize_impl<QByteArray>(); }
+
+private:
+ template<typename Container>
+ void assign_impl() const;
+
+private Q_SLOTS:
+ void assign_std_vector()
+ { assign_impl<std::vector<int>>(); };
+ void assign_QVarLengthArray()
+ { assign_impl<QVarLengthArray<int, 4>>(); };
+
+private:
+ template <typename Container>
void front_back_impl() const;
private Q_SLOTS:
@@ -339,6 +364,15 @@ private:
template <typename Container>
void erase_if_associative_impl() const;
+ template <typename Container>
+ void member_erase_impl() const;
+
+ template <typename Container>
+ void member_erase_associative_impl() const;
+
+ template <typename Container>
+ void member_erase_set_impl() const;
+
private Q_SLOTS:
void erase_QList() { erase_impl<QList<int>>(); }
void erase_QVarLengthArray() { erase_impl<QVarLengthArray<int>>(); }
@@ -364,6 +398,27 @@ private Q_SLOTS:
void erase_if_QMultiMap() {erase_if_associative_impl<QMultiMap<int, int>>(); }
void erase_if_QHash() { erase_if_associative_impl<QHash<int, int>>(); }
void erase_if_QMultiHash() { erase_if_associative_impl<QMultiHash<int, int>>(); }
+
+ void member_erase_QList() { member_erase_impl<QList<int>>(); }
+ void member_erase_QVarLengthArray() { member_erase_impl<QVarLengthArray<int>>(); }
+ void member_erase_QString() { member_erase_impl<QString>(); }
+ void member_erase_QByteArray() { member_erase_impl<QByteArray>(); }
+ void member_erase_QSet() { member_erase_set_impl<QSet<int>>(); }
+
+ void member_erase_QMap() { member_erase_associative_impl<QMap<int, int>>(); }
+ void member_erase_QMultiMap() {member_erase_associative_impl<QMultiMap<int, int>>(); }
+ void member_erase_QHash() { member_erase_associative_impl<QHash<int, int>>(); }
+ void member_erase_QMultiHash() { member_erase_associative_impl<QMultiHash<int, int>>(); }
+
+private:
+ template <typename Container>
+ void keyValueRange_impl() const;
+
+private Q_SLOTS:
+ void keyValueRange_QMap() { keyValueRange_impl<QMap<int, int>>(); }
+ void keyValueRange_QMultiMap() { keyValueRange_impl<QMultiMap<int, int>>(); }
+ void keyValueRange_QHash() { keyValueRange_impl<QHash<int, int>>(); }
+ void keyValueRange_QMultiHash() { keyValueRange_impl<QMultiHash<int, int>>(); }
};
void tst_ContainerApiSymmetry::init()
@@ -422,12 +477,25 @@ void tst_ContainerApiSymmetry::ranged_ctor_non_associative_impl() const
// from itself
const Container c4(reference.begin(), reference.end());
+ // from stringsteam (= pure input_iterator)
+ const Container c5 = [&] {
+ {
+ std::stringstream ss;
+ for (auto &v : values1)
+ ss << v << ' ';
+ ss.seekg(0);
+ return Container(std::istream_iterator<V>{ss},
+ std::istream_iterator<V>{});
+ }
+ }();
+
QCOMPARE(c1, reference);
QCOMPARE(c2a, reference);
QCOMPARE(c2b, reference);
QCOMPARE(c3a, reference);
QCOMPARE(c3b, reference);
QCOMPARE(c4, reference);
+ QCOMPARE(c5, reference);
}
@@ -678,20 +746,109 @@ template <typename T> T clean(T &&t) { return std::forward<T>(t); }
inline char clean(QLatin1Char ch) { return ch.toLatin1(); }
template <typename Container>
+void tst_ContainerApiSymmetry::resize_impl() const
+{
+ using V = typename Container::value_type;
+ using S = typename Container::size_type;
+ auto c = make<Container>(3);
+ QCOMPARE(c.size(), S(3));
+ c.resize(4, V(5));
+ QCOMPARE(c.size(), S(4));
+ QCOMPARE(c.back(), V(5));
+
+ // ctor/resize symmetry:
+ {
+ Container c1(S(5), V(4));
+ QCOMPARE(c1.size(), S(5));
+
+ Container c2;
+ c2.resize(S(5), V(4));
+ QCOMPARE(c2.size(), S(5));
+
+ QCOMPARE(c1, c2);
+ }
+}
+
+template <typename Container>
+void tst_ContainerApiSymmetry::assign_impl() const
+{
+#define CHECK(Arr, ComparisonData, Sz_n, Sz_e, Cap_n, Cap_e) \
+ QCOMPARE(Sz_n, Sz_e); \
+ QCOMPARE(Cap_n, Cap_e); \
+ for (const auto &e : Arr) \
+ QCOMPARE(e, ComparisonData) \
+ /*end*/
+ using V = typename Container::value_type;
+ using S = typename Container::size_type;
+ auto tData = V(9);
+ {
+ // fill version
+ auto c = make<Container>(4);
+ c.assign(4, tData);
+ CHECK(c, tData, c.size(), S(4), c.capacity(), S(4));
+
+ c.assign(8, tData);
+ CHECK(c, tData, c.size(), S(8), c.capacity(), S(8));
+
+ c.assign(0, tData);
+ CHECK(c, tData, c.size(), S(0), c.capacity(), S(8));
+ }
+ {
+ // range version for non input iterator
+ auto c = make<Container>(4);
+ auto iter = make<Container>(1);
+
+ iter.assign(8, tData);
+ c.assign(iter.begin(), iter.end());
+ CHECK(c, tData, c.size(), S(8), c.capacity(), S(8));
+ }
+ {
+ // range version for input iterator
+ auto c = make<Container>(4);
+
+ std::stringstream ss("9 9 ");
+ c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{});
+ CHECK(c, tData, c.size(), S(2), c.capacity(), S(4));
+
+ ss.str("");
+ ss.clear();
+ ss << "9 9 9 9 ";
+ c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{});
+ CHECK(c, tData, c.size(), S(4), c.capacity(), S(4));
+
+ ss.str("");
+ ss.clear();
+ ss << "9 9 9 9 9 9 9 ";
+ c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{});
+ // We cannot check the capacity here because growth rates differ between implementations.
+ CHECK(c, tData, c.size(), S(7), S(8), S(8));
+ }
+ {
+ // initializer-list version
+ auto c = make<Container>(4);
+ std::initializer_list<V> list = {tData, tData, tData};
+ c.assign(list);
+ CHECK(c, tData, c.size(), S(3), c.capacity(), S(4));
+ }
+
+#undef CHECK
+}
+
+template<typename Container>
void tst_ContainerApiSymmetry::front_back_impl() const
{
using V = typename Container::value_type;
auto c1 = make<Container>(1);
QCOMPARE(clean(c1.front()), V(1));
QCOMPARE(clean(c1.back()), V(1));
- QCOMPARE(clean(qAsConst(c1).front()), V(1));
- QCOMPARE(clean(qAsConst(c1).back()), V(1));
+ QCOMPARE(clean(std::as_const(c1).front()), V(1));
+ QCOMPARE(clean(std::as_const(c1).back()), V(1));
auto c2 = make<Container>(2);
QCOMPARE(clean(c2.front()), V(1));
QCOMPARE(clean(c2.back()), V(2));
- QCOMPARE(clean(qAsConst(c2).front()), V(1));
- QCOMPARE(clean(qAsConst(c2).back()), V(2));
+ QCOMPARE(clean(std::as_const(c2).front()), V(1));
+ QCOMPARE(clean(std::as_const(c2).back()), V(2));
}
namespace {
@@ -731,21 +888,35 @@ void tst_ContainerApiSymmetry::erase_if_impl() const
auto c = make<Container>(7); // {1, 2, 3, 4, 5, 6, 7}
QCOMPARE(c.size(), S(7));
- auto result = erase_if(c, [](V i) { return Conv::toInt(i) % 2 == 0; });
+ decltype(c.size()) oldSize, count;
+
+ oldSize = c.size();
+ count = 0;
+ auto result = erase_if(c, [&](V i) { ++count; return Conv::toInt(i) % 2 == 0; });
QCOMPARE(result, S(3));
QCOMPARE(c.size(), S(4));
+ QCOMPARE(count, oldSize);
- result = erase_if(c, [](V i) { return Conv::toInt(i) % 123 == 0; });
+ oldSize = c.size();
+ count = 0;
+ result = erase_if(c, [&](V i) { ++count; return Conv::toInt(i) % 123 == 0; });
QCOMPARE(result, S(0));
QCOMPARE(c.size(), S(4));
+ QCOMPARE(count, oldSize);
- result = erase_if(c, [](V i) { return Conv::toInt(i) % 3 == 0; });
+ oldSize = c.size();
+ count = 0;
+ result = erase_if(c, [&](V i) { ++count; return Conv::toInt(i) % 3 == 0; });
QCOMPARE(result, S(1));
QCOMPARE(c.size(), S(3));
+ QCOMPARE(count, oldSize);
- result = erase_if(c, [](V i) { return Conv::toInt(i) % 2 == 1; });
+ oldSize = c.size();
+ count = 0;
+ result = erase_if(c, [&](V i) { ++count; return Conv::toInt(i) % 2 == 1; });
QCOMPARE(result, S(3));
QCOMPARE(c.size(), S(0));
+ QCOMPARE(count, oldSize);
}
template <typename Container>
@@ -797,5 +968,185 @@ void tst_ContainerApiSymmetry::erase_if_associative_impl() const
QCOMPARE(c.size(), S(0));
}
+template <typename Container>
+void tst_ContainerApiSymmetry::member_erase_impl() const
+{
+ using S = typename Container::size_type;
+ using V = typename Container::value_type;
+ const S size = 7;
+ auto c = make<Container>(size); // {1, 2, 3, 4, 5, 6, 7}
+ QCOMPARE(c.size(), size);
+
+ auto copy = c;
+ // Container::erase() returns an iterator, not const_iterator
+ auto it = c.erase(c.cbegin(), c.cbegin());
+ static_assert(std::is_same_v<decltype(it), typename Container::iterator>);
+ QCOMPARE(c.size(), size);
+ const V newVal{100};
+ QCOMPARE_NE(*it, newVal);
+ *it = newVal;
+ QCOMPARE(it, c.cbegin());
+ QCOMPARE(*c.cbegin(), newVal);
+
+ QCOMPARE(std::find(copy.cbegin(), copy.cend(), newVal), copy.cend());
+}
+
+template <typename Container>
+void tst_ContainerApiSymmetry::member_erase_associative_impl() const
+{
+ using S = typename Container::size_type;
+ using V = typename Container::mapped_type;
+
+ const S size = 20;
+ auto c = makeAssociative<Container>(size);
+ QCOMPARE(c.size(), size);
+
+ // Verify Container::erase() returns iterator, not const_iterator
+ auto it = c.erase(c.cbegin());
+ static_assert(std::is_same_v<decltype(it), typename Container::iterator>);
+ QCOMPARE(c.size(), size - 1);
+ QCOMPARE(it, c.cbegin());
+ const auto current = it.value();
+ it.value() = current + V(5);
+ QCOMPARE(c.cbegin().value(),current + V(5));
+}
+
+template <typename Container>
+void tst_ContainerApiSymmetry::member_erase_set_impl() const
+{
+ using S = typename Container::size_type;
+
+ const S size = 20;
+ auto c = make<Container>(size);
+ QCOMPARE(c.size(), size);
+
+ // Verify Container::erase() returns iterator, not const_iterator
+ auto it = c.erase(c.cbegin());
+ static_assert(std::is_same_v<decltype(it), typename Container::iterator>);
+ QCOMPARE(c.size(), size - 1);
+ QCOMPARE(it, c.cbegin());
+}
+
+template <typename Container>
+void tst_ContainerApiSymmetry::keyValueRange_impl() const
+{
+ constexpr int COUNT = 20;
+
+ using K = typename Container::key_type;
+ using V = typename Container::mapped_type;
+ QVector<K> keys;
+ keys.reserve(COUNT);
+ QVector<V> values;
+ values.reserve(COUNT);
+
+ auto c = makeAssociative<Container>(COUNT);
+ auto returnC = [&](){ return c; };
+
+ const auto verify = [](QVector<K> v, int count, int offset = 0) -> bool {
+ if (v.size() != count)
+ return false;
+ std::sort(v.begin(), v.end());
+ for (int i = 0; i < count; ++i) {
+ // vector is indexed from 0, but makeAssociative starts from 1
+ if (v[i] != i + 1 + offset)
+ return false;
+ }
+ return true;
+ };
+
+ // Check that the range has the right size
+ auto range = c.asKeyValueRange();
+ QCOMPARE(std::distance(range.begin(), range.end()), COUNT);
+
+ auto constRange = std::as_const(c).asKeyValueRange();
+ QCOMPARE(std::distance(constRange.begin(), constRange.end()), COUNT);
+
+ auto rvalueRange = returnC().asKeyValueRange();
+ QCOMPARE(std::distance(rvalueRange.begin(), rvalueRange.end()), COUNT);
+
+ // auto, mutating
+ keys.clear(); values.clear();
+ for (auto [key, value] : c.asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value);
+ QCOMPARE(c.value(key), value);
+ ++value;
+ QCOMPARE(key, value - 1);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT));
+
+ // auto, non-mutating
+ keys.clear(); values.clear();
+ for (auto [key, value] : c.asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value - 1);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT, 1));
+
+ // auto &&, mutating
+ keys.clear(); values.clear();
+ for (auto &&[key, value] : c.asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value - 1);
+ QCOMPARE(c.value(key), value);
+ ++value;
+ QCOMPARE(key, value - 2);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT, 1));
+
+ // auto, non-mutating (const map)
+ keys.clear(); values.clear();
+ for (auto [key, value] : std::as_const(c).asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value - 2);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT, 2));
+
+ // auto &&, non-mutating (const map)
+ keys.clear(); values.clear();
+ for (auto &&[key, value] : std::as_const(c).asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value - 2);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT, 2));
+
+ // auto, non-mutating (rvalue map)
+ keys.clear(); values.clear();
+ for (auto [key, value] : returnC().asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value - 2);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT, 2));
+
+ // auto &&, non-mutating (rvalue map)
+ keys.clear(); values.clear();
+ for (auto &&[key, value] : returnC().asKeyValueRange()) {
+ keys << key;
+ values << value;
+ QCOMPARE(key, value - 2);
+ QCOMPARE(c.value(key), value);
+ }
+ QVERIFY(verify(keys, COUNT));
+ QVERIFY(verify(values, COUNT, 2));
+}
+
QTEST_APPLESS_MAIN(tst_ContainerApiSymmetry)
#include "tst_containerapisymmetry.moc"
diff --git a/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt b/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt
index d793c81ce6..f7b0238b0a 100644
--- a/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qalgorithms.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qalgorithms Test:
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index 0b921ffdbe..8eb5392eb0 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -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 WITH Qt-GPL-exception-1.0
#include "../../../../../src/corelib/tools/qalgorithms.h"
#include <QTest>
@@ -95,6 +70,18 @@ private:
void countLeading_impl();
};
+template <typename T> struct PrintIfFailed
+{
+ T value;
+ PrintIfFailed(T v) : value(v) {}
+ ~PrintIfFailed()
+ {
+ if (!QTest::currentTestFailed())
+ return;
+ qWarning() << "Original value was" << Qt::hex << Qt::showbase << T(value);
+ }
+};
+
void tst_QAlgorithms::swap()
{
{
@@ -274,23 +261,26 @@ void tst_QAlgorithms::popCount_data_impl(size_t sizeof_T_Int)
const uint bits = bitsSetInByte(byte);
const quint64 value = static_cast<quint64>(byte);
const quint64 input = value << ((i % sizeof_T_Int) * 8U);
- QTest::addRow("0x%016llx", input) << input << bits;
+ QTest::addRow("%u-bits", i) << input << bits;
}
// and some random ones:
- if (sizeof_T_Int >= 8)
+ if (sizeof_T_Int >= 8) {
for (size_t i = 0; i < 1000; ++i) {
const quint64 input = QRandomGenerator::global()->generate64();
- QTest::addRow("0x%016llx", input) << input << bitsSetInInt64(input);
+ QTest::addRow("random-%zu", i) << input << bitsSetInInt64(input);
}
- else if (sizeof_T_Int >= 2)
- for (size_t i = 0; i < 1000 ; ++i) {
- const quint32 input = QRandomGenerator::global()->generate();
- if (sizeof_T_Int >= 4)
- QTest::addRow("0x%08x", input) << quint64(input) << bitsSetInInt(input);
- else
- QTest::addRow("0x%04x", quint16(input & 0xFFFF)) << quint64(input & 0xFFFF) << bitsSetInShort(input & 0xFFFF);
+ } else if (sizeof_T_Int >= 2) {
+ for (size_t i = 0; i < 1000 ; ++i) {
+ const quint32 input = QRandomGenerator::global()->generate();
+ if (sizeof_T_Int >= 4) {
+ QTest::addRow("random-%zu", i) << quint64(input) << bitsSetInInt(input);
+ } else {
+ QTest::addRow("random-%zu", i)
+ << quint64(input & 0xFFFF) << bitsSetInShort(input & 0xFFFF);
}
+ }
+ }
}
template <typename T_Int>
@@ -300,22 +290,23 @@ void tst_QAlgorithms::popCount_impl()
QFETCH(uint, expected);
const T_Int value = static_cast<T_Int>(input);
-
+ PrintIfFailed pf(value);
QCOMPARE(qPopulationCount(value), expected);
}
+// Number of test-cases per offset into each size (arbitrary):
+static constexpr int casesPerOffset = 3;
+
void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
{
using namespace QTest;
addColumn<quint64>("input");
addColumn<uint>("expected");
- int nibs = sizeof_T_Int*2;
-
- newRow(("0x"+QByteArray::number(0,16).rightJustified(nibs,'0')).constData()) << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
+ addRow("0") << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
const quint64 input = Q_UINT64_C(1) << i;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << i;
+ addRow("bit-%u", i) << input << i;
}
quint64 type_mask;
@@ -326,12 +317,12 @@ void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
- for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
+ const quint64 b = Q_UINT64_C(1) << i;
+ const quint64 mask = ((~(b - 1)) ^ b) & type_mask;
+ for (uint j = 0; j < sizeof_T_Int * casesPerOffset; ++j) {
const quint64 r = QRandomGenerator::global()->generate64();
- const quint64 b = Q_UINT64_C(1) << i;
- const quint64 mask = ((~(b-1)) ^ b) & type_mask;
const quint64 input = (r&mask) | b;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << i;
+ addRow("%u-bits-random-%u", i, j) << input << i;
}
}
}
@@ -343,7 +334,7 @@ void tst_QAlgorithms::countTrailing_impl()
QFETCH(uint, expected);
const T_Int value = static_cast<T_Int>(input);
-
+ PrintIfFailed pf(value);
QCOMPARE(qCountTrailingZeroBits(value), expected);
}
@@ -353,22 +344,20 @@ void tst_QAlgorithms::countLeading_data_impl(size_t sizeof_T_Int)
addColumn<quint64>("input");
addColumn<uint>("expected");
- int nibs = sizeof_T_Int*2;
-
- newRow(("0x"+QByteArray::number(0,16).rightJustified(nibs,'0')).constData()) << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
+ addRow("0") << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
const quint64 input = Q_UINT64_C(1) << i;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << uint(sizeof_T_Int*8-i-1);
+ addRow("bit-%u", i) << input << uint(sizeof_T_Int*8-i-1);
}
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
- for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
+ const quint64 b = Q_UINT64_C(1) << i;
+ const quint64 mask = b - 1;
+ for (uint j = 0; j < sizeof_T_Int * casesPerOffset; ++j) {
const quint64 r = QRandomGenerator::global()->generate64();
- const quint64 b = Q_UINT64_C(1) << i;
- const quint64 mask = b-1;
const quint64 input = (r&mask) | b;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << uint(sizeof_T_Int*8-i-1);
+ addRow("%u-bits-random-%u", i, j) << input << uint(sizeof_T_Int*8-i-1);
}
}
}
@@ -380,7 +369,7 @@ void tst_QAlgorithms::countLeading_impl()
QFETCH(uint, expected);
const T_Int value = static_cast<T_Int>(input);
-
+ PrintIfFailed pf(value);
QCOMPARE(qCountLeadingZeroBits(value), expected);
}
diff --git a/tests/auto/corelib/tools/qarraydata/CMakeLists.txt b/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
index 4a2f9d0d6a..9133d1bd8c 100644
--- a/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qarraydata.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qarraydata Test:
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index 1fc5e9b8e1..f433743911 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 WITH Qt-GPL-exception-1.0
#ifndef QARRAY_TEST_SIMPLE_VECTOR_H
@@ -32,6 +7,7 @@
#include <QtCore/qarraydata.h>
#include <QtCore/qarraydatapointer.h>
+#include <QtCore/qvarlengtharray.h>
#include <algorithm>
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index 81c75fffbc..987cee0349 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -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) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
@@ -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');
diff --git a/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt b/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt
new file mode 100644
index 0000000000..b6f29d5b7f
--- /dev/null
+++ b/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_test(tst_qatomicscopedvaluerollback
+ SOURCES
+ tst_qatomicscopedvaluerollback.cpp
+ LIBRARIES
+ Qt::CorePrivate
+)
diff --git a/tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp b/tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp
new file mode 100644
index 0000000000..81d8242f71
--- /dev/null
+++ b/tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp
@@ -0,0 +1,157 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QtCore/private/qatomicscopedvaluerollback_p.h>
+
+#include <QTest>
+
+class tst_QAtomicScopedValueRollback : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void leavingScope();
+ void leavingScopeAfterCommit();
+ void rollbackToPreviousCommit();
+ void exceptions();
+ void earlyExitScope();
+private:
+ void earlyExitScope_helper(int exitpoint, std::atomic<int> &member);
+};
+
+void tst_QAtomicScopedValueRollback::leavingScope()
+{
+ QAtomicInt i = 0;
+ QBasicAtomicInteger<bool> b = false;
+ std::atomic<bool> b2 = false;
+
+ //test rollback on going out of scope
+ {
+ QAtomicScopedValueRollback ri(i);
+ QAtomicScopedValueRollback rb(b);
+ QAtomicScopedValueRollback rb2(b2, true);
+ QCOMPARE(b.loadRelaxed(), false);
+ QCOMPARE(b2, true);
+ QCOMPARE(i.loadRelaxed(), 0);
+ b.storeRelaxed(true);
+ i.storeRelaxed(1);
+ QCOMPARE(b.loadRelaxed(), true);
+ QCOMPARE(i.loadRelaxed(), 1);
+ }
+ QCOMPARE(b.loadRelaxed(), false);
+ QCOMPARE(b2, false);
+ QCOMPARE(i.loadRelaxed(), 0);
+}
+
+void tst_QAtomicScopedValueRollback::leavingScopeAfterCommit()
+{
+ std::atomic<int> i = 0;
+ QAtomicInteger<bool> b = false;
+
+ //test rollback on going out of scope
+ {
+ QAtomicScopedValueRollback ri(i);
+ QAtomicScopedValueRollback rb(b);
+ QCOMPARE(b.loadRelaxed(), false);
+ QCOMPARE(i, 0);
+ b.storeRelaxed(true);
+ i = 1;
+ QCOMPARE(b.loadRelaxed(), true);
+ QCOMPARE(i, 1);
+ ri.commit();
+ rb.commit();
+ }
+ QCOMPARE(b.loadRelaxed(), true);
+ QCOMPARE(i, 1);
+}
+
+void tst_QAtomicScopedValueRollback::rollbackToPreviousCommit()
+{
+ QBasicAtomicInt i = 0;
+ {
+ QAtomicScopedValueRollback ri(i);
+ i++;
+ ri.commit();
+ i++;
+ }
+ QCOMPARE(i.loadRelaxed(), 1);
+ {
+ QAtomicScopedValueRollback ri1(i);
+ i++;
+ ri1.commit();
+ i++;
+ ri1.commit();
+ i++;
+ }
+ QCOMPARE(i.loadRelaxed(), 3);
+}
+
+void tst_QAtomicScopedValueRollback::exceptions()
+{
+ std::atomic<bool> b = false;
+ bool caught = false;
+ QT_TRY
+ {
+ QAtomicScopedValueRollback rb(b);
+ b = true;
+ QT_THROW(std::bad_alloc()); //if Qt compiled without exceptions this is noop
+ rb.commit(); //if Qt compiled without exceptions, true is committed
+ }
+ QT_CATCH(...)
+ {
+ caught = true;
+ }
+ QCOMPARE(b, !caught); //expect false if exception was thrown, true otherwise
+}
+
+void tst_QAtomicScopedValueRollback::earlyExitScope()
+{
+ QAtomicInt ai = 0;
+ std::atomic<int> aj = 0;
+ while (true) {
+ QAtomicScopedValueRollback ri(ai);
+ ++ai;
+ aj = ai.loadRelaxed();
+ if (ai.loadRelaxed() > 8) break;
+ ri.commit();
+ }
+ QCOMPARE(ai.loadRelaxed(), 8);
+ QCOMPARE(aj.load(), 9);
+
+ for (int i = 0; i < 5; ++i) {
+ aj = 1;
+ earlyExitScope_helper(i, aj);
+ QCOMPARE(aj.load(), 1 << i);
+ }
+}
+
+static void operator*=(std::atomic<int> &lhs, int rhs)
+{
+ int expected = lhs.load();
+ while (!lhs.compare_exchange_weak(expected, expected * rhs))
+ ;
+}
+
+void tst_QAtomicScopedValueRollback::earlyExitScope_helper(int exitpoint, std::atomic<int>& member)
+{
+ QAtomicScopedValueRollback r(member);
+ member *= 2;
+ if (exitpoint == 0)
+ return;
+ r.commit();
+ member *= 2;
+ if (exitpoint == 1)
+ return;
+ r.commit();
+ member *= 2;
+ if (exitpoint == 2)
+ return;
+ r.commit();
+ member *= 2;
+ if (exitpoint == 3)
+ return;
+ r.commit();
+}
+
+QTEST_MAIN(tst_QAtomicScopedValueRollback)
+#include "tst_qatomicscopedvaluerollback.moc"
diff --git a/tests/auto/corelib/tools/qbitarray/CMakeLists.txt b/tests/auto/corelib/tools/qbitarray/CMakeLists.txt
index 37e7a873e8..3c3a5db142 100644
--- a/tests/auto/corelib/tools/qbitarray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qbitarray/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qbitarray.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qbitarray Test:
diff --git a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp
index 263083972c..b205bb76ee 100644
--- a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp
+++ b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/QBuffer>
@@ -38,10 +13,10 @@
static QBitArray QStringToQBitArray(const QString &str)
{
QBitArray ba;
- ba.resize(str.length());
+ ba.resize(str.size());
int i;
QChar tru('1');
- for (i = 0; i < str.length(); i++)
+ for (i = 0; i < str.size(); i++)
{
if (str.at(i) == tru)
{
@@ -150,7 +125,6 @@ void tst_QBitArray::countBits_data()
QTest::newRow("11111111111111111111111111111111") << QString("11111111111111111111111111111111") << 32 << 32;
QTest::newRow("11111111111111111111111111111111111111111111111111111111")
<< QString("11111111111111111111111111111111111111111111111111111111") << 56 << 56;
- QTest::newRow("00000000000000000000000000000000000") << QString("00000000000000000000000000000000000") << 35 << 0;
QTest::newRow("00000000000000000000000000000000") << QString("00000000000000000000000000000000") << 32 << 0;
QTest::newRow("00000000000000000000000000000000000000000000000000000000")
<< QString("00000000000000000000000000000000000000000000000000000000") << 56 << 0;
@@ -168,6 +142,8 @@ void tst_QBitArray::countBits()
bits.setBit(i);
}
+ QCOMPARE(bits.size(), numBits);
+ // NOLINTNEXTLINE(qt-port-to-std-compatible-api): We want to test count() and size()
QCOMPARE(bits.count(), numBits);
QCOMPARE(bits.count(true), onBits);
QCOMPARE(bits.count(false), numBits - onBits);
@@ -497,7 +473,6 @@ void tst_QBitArray::datastream_data()
QTest::newRow("11111111111111111111111111111111") << QString("11111111111111111111111111111111") << 32 << 32;
QTest::newRow("11111111111111111111111111111111111111111111111111111111")
<< QString("11111111111111111111111111111111111111111111111111111111") << 56 << 56;
- QTest::newRow("00000000000000000000000000000000000") << QString("00000000000000000000000000000000000") << 35 << 0;
QTest::newRow("00000000000000000000000000000000") << QString("00000000000000000000000000000000") << 32 << 0;
QTest::newRow("00000000000000000000000000000000000000000000000000000000")
<< QString("00000000000000000000000000000000000000000000000000000000") << 56 << 0;
@@ -519,7 +494,7 @@ void tst_QBitArray::datastream()
bits.setBit(i);
}
- QCOMPARE(bits.count(), numBits);
+ QCOMPARE(bits.size(), numBits);
QCOMPARE(bits.count(true), onBits);
QCOMPARE(bits.count(false), numBits - onBits);
@@ -534,7 +509,7 @@ void tst_QBitArray::datastream()
QBitArray array1, array2, array3;
stream2 >> array1 >> array2 >> array3;
- QCOMPARE(array1.count(), numBits);
+ QCOMPARE(array1.size(), numBits);
QCOMPARE(array1.count(true), onBits);
QCOMPARE(array1.count(false), numBits - onBits);
diff --git a/tests/auto/corelib/tools/qcache/CMakeLists.txt b/tests/auto/corelib/tools/qcache/CMakeLists.txt
index 5ed12a7973..b51c1b1469 100644
--- a/tests/auto/corelib/tools/qcache/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcache/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qcache.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcache Test:
diff --git a/tests/auto/corelib/tools/qcache/tst_qcache.cpp b/tests/auto/corelib/tools/qcache/tst_qcache.cpp
index eb024e8f9e..0e018e18b8 100644
--- a/tests/auto/corelib/tools/qcache/tst_qcache.cpp
+++ b/tests/auto/corelib/tools/qcache/tst_qcache.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
@@ -37,6 +12,7 @@ public slots:
void initTestCase();
void cleanupTestCase();
private slots:
+ void empty();
void maxCost();
void setMaxCost();
void totalCost();
@@ -50,6 +26,7 @@ private slots:
void largeCache();
void internalChainOrderAfterEntryUpdate();
void emplaceLowerCost();
+ void trimWithMovingAcrossSpans();
};
@@ -75,6 +52,21 @@ void tst_QCache::cleanupTestCase()
QCOMPARE(Foo::count, 0);
}
+void tst_QCache::empty()
+{
+ QCache<int, int> cache;
+ QCOMPARE(cache.size(), 0);
+ QCOMPARE(cache.count(), 0);
+ QVERIFY(cache.isEmpty());
+ QVERIFY(!cache.contains(1));
+ QCOMPARE(cache.keys().size(), 0);
+ QCOMPARE(cache.take(1), nullptr);
+ QVERIFY(!cache.remove(1));
+ QCOMPARE(cache.object(1), nullptr);
+ QCOMPARE(cache[1], nullptr);
+ QCOMPARE(cache.totalCost(), 0);
+}
+
void tst_QCache::maxCost()
{
QCache<QString, int> cache1, cache2(100), cache3(200), cache4(-50);
@@ -446,5 +438,71 @@ void tst_QCache::emplaceLowerCost()
QVERIFY(cache.isEmpty());
}
+struct TrivialHashType {
+ int i = -1;
+ size_t hash = 0;
+
+ TrivialHashType(int i, size_t hash) : i(i), hash(hash) {}
+ TrivialHashType(const TrivialHashType &o) noexcept = default;
+ TrivialHashType &operator=(const TrivialHashType &o) noexcept = default;
+ TrivialHashType(TrivialHashType &&o) noexcept : i(o.i), hash(o.hash) {
+ o.i = -1;
+ o.hash = 0;
+ }
+ TrivialHashType &operator=(TrivialHashType &&o) noexcept {
+ i = o.i;
+ hash = o.hash;
+ o.i = -1;
+ o.hash = 0;
+ return *this;
+ }
+
+
+ friend bool operator==(const TrivialHashType &lhs, const TrivialHashType &rhs)
+ {
+ return lhs.i == rhs.i;
+ }
+};
+quint64 qHash(TrivialHashType t, size_t seed = 0)
+{
+ Q_UNUSED(seed);
+ return t.hash;
+}
+
+// During trim(), if the Node we have a pointer to in the function is moved
+// to another span in the hash table, our pointer would end up pointing to
+// garbage memory. Test that this no longer happens
+void tst_QCache::trimWithMovingAcrossSpans()
+{
+ qsizetype numBuckets = [](){
+ QHash<int, int> h;
+ h.reserve(1);
+ // Beholden to QHash internals:
+ return h.capacity() << 1;
+ }();
+
+ QCache<TrivialHashType, int> cache;
+ cache.setMaxCost(1000);
+
+ auto lastBucketInSpan = size_t(numBuckets - 1);
+ // If this fails then the test is no longer valid
+ QCOMPARE(QHashPrivate::GrowthPolicy::bucketForHash(numBuckets, lastBucketInSpan),
+ lastBucketInSpan);
+
+ // Pad some space so we have two spans:
+ for (int i = 2; i < numBuckets; ++i)
+ cache.insert({i, 0}, nullptr);
+
+ // These two are vying for the last bucket in the first span,
+ // when '0' is deleted, '1' is moved across the span boundary,
+ // invalidating any pointer to its Node.
+ cache.insert({0, lastBucketInSpan}, nullptr);
+ cache.insert({1, lastBucketInSpan}, nullptr);
+
+ QCOMPARE(cache.size(), numBuckets);
+ cache.setMaxCost(0);
+ QCOMPARE(cache.size(), 0);
+}
+
QTEST_APPLESS_MAIN(tst_QCache)
#include "tst_qcache.moc"
diff --git a/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt b/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt
index f25766164a..89c1e99a33 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#####################################################################
## tst_qcommandlineparser Test:
#####################################################################
diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/CMakeLists.txt b/tests/auto/corelib/tools/qcommandlineparser/testhelper/CMakeLists.txt
index 2068f988dd..20cec30a9c 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qcommandlineparser_test_helper.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qcommandlineparser_test_helper Binary:
diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
index dd4235ca40..758251f05a 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 David Faure <faure@kde.org>
-** 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) 2013 David Faure <faure@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QDebug>
#include <QCoreApplication>
diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
index 55206173e3..6252440232 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 David Faure <faure@kde.org>
-** Copyright (C) 2021 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 David Faure <faure@kde.org>
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#if QT_CONFIG(process)
@@ -528,7 +503,7 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes()
QVERIFY(parser.addOption(forceShort));
QVERIFY(parser.parse(commandLine));
QCOMPARE(parser.optionNames(), expectedOptionNames);
- for (int i = 0; i < expectedOptionValues.count(); ++i)
+ for (int i = 0; i < expectedOptionValues.size(); ++i)
QCOMPARE(parser.value(parser.optionNames().at(i)), expectedOptionValues.at(i));
QCOMPARE(parser.unknownOptionNames(), QStringList());
}
@@ -787,7 +762,7 @@ void tst_QCommandLineParser::testVeryLongOptionNames()
output.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
#endif
const QStringList lines = output.split('\n');
- const int last = lines.count() - 1;
+ const int last = lines.size() - 1;
// Let's not compare everything, just the final parts.
QCOMPARE(lines.at(last - 7), " cdefghijklmnopqrstuvwxyz");
QCOMPARE(lines.at(last - 6), " --looooooooooooong-option, --looooong-opt-alias <l Short description");
diff --git a/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt b/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt
index dc9722ccc7..7f0b53820e 100644
--- a/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qcontiguouscache.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcontiguouscache Test:
diff --git a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
index b25ed55648..395ed23cea 100644
--- a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
+++ b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QObject>
#include <QTest>
@@ -75,20 +50,24 @@ void tst_QContiguousCache::empty()
{
QContiguousCache<int> c(10);
QCOMPARE(c.capacity(), 10);
+ QCOMPARE(c.size(), 0);
+ // NOLINTNEXTLINE(qt-port-to-std-compatible-api): Test both size() and count()
QCOMPARE(c.count(), 0);
QVERIFY(c.isEmpty());
c.append(1);
+ // NOLINTNEXTLINE(qt-port-to-std-compatible-api): Test both size() and count()
QCOMPARE(c.count(), 1);
+ QCOMPARE(c.size(), 1);
QVERIFY(!c.isEmpty());
c.clear();
QCOMPARE(c.capacity(), 10);
- QCOMPARE(c.count(), 0);
+ QCOMPARE(c.size(), 0);
QVERIFY(c.isEmpty());
c.prepend(1);
- QCOMPARE(c.count(), 1);
+ QCOMPARE(c.size(), 1);
QVERIFY(!c.isEmpty());
c.clear();
- QCOMPARE(c.count(), 0);
+ QCOMPARE(c.size(), 0);
QVERIFY(c.isEmpty());
QCOMPARE(c.capacity(), 10);
}
@@ -99,9 +78,9 @@ void tst_QContiguousCache::swap()
c1.append(1);
c1.swap(c2);
QCOMPARE(c1.capacity(), 100);
- QCOMPARE(c1.count(), 0 );
+ QCOMPARE(c1.size(), 0 );
QCOMPARE(c2.capacity(), 10 );
- QCOMPARE(c2.count(), 1 );
+ QCOMPARE(c2.size(), 1 );
}
void tst_QContiguousCache::append_data()
@@ -137,7 +116,7 @@ void tst_QContiguousCache::append()
QCOMPARE(c.available(), qMax(qsizetype(0), cacheSize - i));
QCOMPARE(c.first(), qMax(qsizetype(1), i-cacheSize+1));
QCOMPARE(c.last(), i);
- QCOMPARE(c.count(), qMin(i, cacheSize));
+ QCOMPARE(c.size(), qMin(i, cacheSize));
QCOMPARE(c.isFull(), i >= cacheSize);
i++;
}
@@ -150,7 +129,7 @@ void tst_QContiguousCache::append()
// test taking from end until empty.
for (j = 0; j < cacheSize; j++, i--) {
QCOMPARE(c.takeLast(), i-1);
- QCOMPARE(c.count(), cacheSize-j-1);
+ QCOMPARE(c.size(), cacheSize-j-1);
QCOMPARE(c.available(), j+1);
QVERIFY(!c.isFull());
QCOMPARE(c.isEmpty(), j==cacheSize-1);
@@ -188,7 +167,7 @@ void tst_QContiguousCache::prepend()
QCOMPARE(c.available(), qMax(0, cacheSize - i));
QCOMPARE(c.last(), qMax(1, i-cacheSize+1));
QCOMPARE(c.first(), i);
- QCOMPARE(c.count(), qMin(i, cacheSize));
+ QCOMPARE(c.size(), qMin(i, cacheSize));
QCOMPARE(c.isFull(), i >= cacheSize);
i++;
}
@@ -201,7 +180,7 @@ void tst_QContiguousCache::prepend()
// test taking from start until empty.
for (j = 0; j < cacheSize; j++, i--) {
QCOMPARE(c.takeFirst(), i-1);
- QCOMPARE(c.count(), cacheSize-j-1);
+ QCOMPARE(c.size(), cacheSize-j-1);
QCOMPARE(c.available(), j+1);
QVERIFY(!c.isFull());
QCOMPARE(c.isEmpty(), j==cacheSize-1);
@@ -321,7 +300,7 @@ void tst_QContiguousCache::setCapacity()
for (i = 280; i < 310; ++i)
contiguousCache.insert(i, i);
QCOMPARE(contiguousCache.capacity(), 100);
- QCOMPARE(contiguousCache.count(), 30);
+ QCOMPARE(contiguousCache.size(), 30);
QCOMPARE(contiguousCache.firstIndex(), 280);
QCOMPARE(contiguousCache.lastIndex(), 309);
@@ -333,7 +312,7 @@ void tst_QContiguousCache::setCapacity()
contiguousCache.setCapacity(150);
QCOMPARE(contiguousCache.capacity(), 150);
- QCOMPARE(contiguousCache.count(), 30);
+ QCOMPARE(contiguousCache.size(), 30);
QCOMPARE(contiguousCache.firstIndex(), 280);
QCOMPARE(contiguousCache.lastIndex(), 309);
@@ -345,7 +324,7 @@ void tst_QContiguousCache::setCapacity()
contiguousCache.setCapacity(20);
QCOMPARE(contiguousCache.capacity(), 20);
- QCOMPARE(contiguousCache.count(), 20);
+ QCOMPARE(contiguousCache.size(), 20);
QCOMPARE(contiguousCache.firstIndex(), 290);
QCOMPARE(contiguousCache.lastIndex(), 309);
diff --git a/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt b/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt
index d8de1798f3..a32da3dedf 100644
--- a/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qcryptographichash.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcryptographichash Test:
@@ -16,20 +17,6 @@ qt_internal_add_test(tst_qcryptographichash
TESTDATA ${test_data}
)
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(testdata_resource_files
- "data/2c1517dad3678f03917f15849b052fd5.md5"
- "data/d41d8cd98f00b204e9800998ecf8427e.md5"
- )
-
- qt_internal_add_resource(tst_qcryptographichash "testdata"
- PREFIX
- "/"
- FILES
- ${testdata_resource_files}
- )
+if(QT_FEATURE_sanitize_address)
+ set_property(TEST tst_qcryptographichash APPEND PROPERTY ENVIRONMENT "QTEST_FUNCTION_TIMEOUT=900000")
endif()
diff --git a/tests/auto/corelib/tools/qcryptographichash/testdata.qrc b/tests/auto/corelib/tools/qcryptographichash/testdata.qrc
deleted file mode 100644
index 8f7bcea63c..0000000000
--- a/tests/auto/corelib/tools/qcryptographichash/testdata.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>data/2c1517dad3678f03917f15849b052fd5.md5</file>
- <file>data/d41d8cd98f00b204e9800998ecf8427e.md5</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
index 6b61349d01..a7c22ffe29 100644
--- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
+++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtCore/QCoreApplication>
@@ -56,10 +31,16 @@ private slots:
void files();
void hashLength_data();
void hashLength();
+ void addDataAcceptsNullByteArrayView_data() { hashLength_data(); }
+ void addDataAcceptsNullByteArrayView();
+ void move();
+ void swap();
// keep last
void moreThan4GiBOfData_data();
void moreThan4GiBOfData();
+ void keccakBufferOverflow();
private:
+ void ensureLargeData();
std::vector<char> large;
};
@@ -74,6 +55,8 @@ void tst_QCryptographicHash::repeated_result()
QCryptographicHash::Algorithm _algo = QCryptographicHash::Algorithm(algo);
QCryptographicHash hash(_algo);
+ QCOMPARE_EQ(hash.algorithm(), _algo);
+
QFETCH(QByteArray, first);
hash.addData(first);
@@ -414,7 +397,7 @@ void tst_QCryptographicHash::hashLength_data()
auto metaEnum = QMetaEnum::fromType<QCryptographicHash::Algorithm>();
for (int i = 0, value = metaEnum.value(i); value != -1; value = metaEnum.value(++i)) {
auto algorithm = QCryptographicHash::Algorithm(value);
- QTest::addRow("%s", metaEnum.valueToKey(value)) << algorithm;
+ QTest::addRow("%s", metaEnum.key(i)) << algorithm;
}
}
@@ -422,16 +405,81 @@ void tst_QCryptographicHash::hashLength()
{
QFETCH(const QCryptographicHash::Algorithm, algorithm);
- QByteArray output = QCryptographicHash::hash("test", algorithm);
- QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length());
+ qsizetype expectedSize;
+ if (algorithm == QCryptographicHash::NumAlgorithms) {
+ // It's UB to call ::hash() with NumAlgorithms, but hashLength() is
+ // fine and returns 0 for invalid values:
+ expectedSize = 0;
+ } else {
+ expectedSize = QCryptographicHash::hash("test", algorithm).size();
+ }
+ QCOMPARE(QCryptographicHash::hashLength(algorithm), expectedSize);
}
-void tst_QCryptographicHash::moreThan4GiBOfData_data()
+void tst_QCryptographicHash::addDataAcceptsNullByteArrayView()
+{
+ QFETCH(const QCryptographicHash::Algorithm, algorithm);
+
+ if (!QCryptographicHash::supportsAlgorithm(algorithm))
+ QSKIP("QCryptographicHash doesn't support this algorithm");
+
+ QCryptographicHash hash1(algorithm);
+ hash1.addData("meep");
+ hash1.addData(QByteArrayView{}); // after other data
+
+ QCryptographicHash hash2(algorithm);
+ hash2.addData(QByteArrayView{}); // before any other data
+ hash2.addData("meep");
+
+ const auto expected = QCryptographicHash::hash("meep", algorithm);
+
+ QCOMPARE(hash1.resultView(), expected);
+ QCOMPARE(hash2.resultView(), expected);
+}
+
+void tst_QCryptographicHash::move()
+{
+ QCryptographicHash hash1(QCryptographicHash::Sha1);
+ hash1.addData("a");
+
+ // move constructor
+ auto hash2(std::move(hash1));
+ hash2.addData("b");
+
+ // move assign operator
+ QCryptographicHash hash3(QCryptographicHash::Sha256);
+ hash3.addData("no effect on the end result");
+ hash3 = std::move(hash2);
+ hash3.addData("c");
+
+ QCOMPARE(hash3.resultView(), QByteArray::fromHex("A9993E364706816ABA3E25717850C26C9CD0D89D"));
+}
+
+void tst_QCryptographicHash::swap()
+{
+ QCryptographicHash hash1(QCryptographicHash::Sha1);
+ QCryptographicHash hash2(QCryptographicHash::Sha256);
+
+ hash1.addData("da");
+ hash2.addData("te");
+
+ hash1.swap(hash2);
+
+ hash2.addData("ta");
+ hash1.addData("st");
+
+ QCOMPARE(hash2.result(), QCryptographicHash::hash("data", QCryptographicHash::Sha1));
+ QCOMPARE(hash1.result(), QCryptographicHash::hash("test", QCryptographicHash::Sha256));
+}
+
+void tst_QCryptographicHash::ensureLargeData()
{
#if QT_POINTER_SIZE > 4
QElapsedTimer timer;
timer.start();
const size_t GiB = 1024 * 1024 * 1024;
+ if (large.size() == 4 * GiB + 1)
+ return;
try {
large.resize(4 * GiB + 1, '\0');
} catch (const std::bad_alloc &) {
@@ -440,7 +488,14 @@ void tst_QCryptographicHash::moreThan4GiBOfData_data()
QCOMPARE(large.size(), 4 * GiB + 1);
large.back() = '\1';
qDebug("created dataset in %lld ms", timer.elapsed());
+#endif
+}
+void tst_QCryptographicHash::moreThan4GiBOfData_data()
+{
+#if QT_POINTER_SIZE > 4
+ if (ensureLargeData(); large.empty())
+ return;
QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
auto me = QMetaEnum::fromType<QCryptographicHash::Algorithm>();
auto row = [me] (QCryptographicHash::Algorithm algo) {
@@ -503,5 +558,33 @@ void tst_QCryptographicHash::moreThan4GiBOfData()
QCOMPARE(single, chunked);
}
+void tst_QCryptographicHash::keccakBufferOverflow()
+{
+#if QT_POINTER_SIZE == 4
+ QSKIP("This is a 64-bit-only test");
+#else
+
+ if (ensureLargeData(); large.empty())
+ return;
+
+ QElapsedTimer timer;
+ timer.start();
+ const auto sg = qScopeGuard([&] {
+ qDebug() << "test finished in" << timer.restart() << "ms";
+ });
+
+ constexpr qsizetype magic = INT_MAX/4;
+ QCOMPARE_GE(large.size(), size_t(magic + 1));
+
+ QCryptographicHash hash(QCryptographicHash::Algorithm::Keccak_224);
+ const auto first = QByteArrayView{large}.first(1);
+ const auto second = QByteArrayView{large}.sliced(1, magic);
+ hash.addData(first);
+ hash.addData(second);
+ (void)hash.resultView();
+ QVERIFY(true); // didn't crash
+#endif
+}
+
QTEST_MAIN(tst_QCryptographicHash)
#include "tst_qcryptographichash.moc"
diff --git a/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt b/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt
index a38255f3e9..39a772ab8c 100644
--- a/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qduplicatetracker.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qduplicatetracker Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qduplicatetracker
SOURCES
tst_qduplicatetracker.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
index 12a4103060..8ea4802fa4 100644
--- a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
+++ b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
@@ -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 WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
@@ -38,6 +13,7 @@ class tst_QDuplicateTracker : public QObject
Q_OBJECT
private slots:
void hasSeen();
+ void clear();
void appendTo();
void appendTo_special();
};
@@ -76,6 +52,21 @@ void tst_QDuplicateTracker::hasSeen()
}
}
+void tst_QDuplicateTracker::clear()
+{
+ QDuplicateTracker<int, 2> tracker;
+ QVERIFY(!tracker.hasSeen(0));
+ QVERIFY(tracker.hasSeen(0));
+ QVERIFY(!tracker.hasSeen(1));
+ QVERIFY(tracker.hasSeen(1));
+
+ tracker.clear();
+ QVERIFY(!tracker.hasSeen(0));
+ QVERIFY(tracker.hasSeen(0));
+ QVERIFY(!tracker.hasSeen(1));
+ QVERIFY(tracker.hasSeen(1));
+}
+
void tst_QDuplicateTracker::appendTo()
{
QDuplicateTracker<int, 2> tracker;
diff --git a/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt b/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt
index ce12cd9bfc..781410c90e 100644
--- a/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qeasingcurve.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qeasingcurve Test:
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index 09ab680b49..4989de521f 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
@@ -399,7 +374,7 @@ void tst_QEasingCurve::valueForProgress()
// in theory the baseline should't have an error of more than 0.00005 due to how its rounded,
// but due to FP imprecision, we have to adjust the error a bit more.
const qreal errorBound = 0.00006;
- for (int i = 0; i < at.count(); ++i) {
+ for (int i = 0; i < at.size(); ++i) {
const qreal ex = expected.at(i);
const qreal error = qAbs(ex - curve.valueForProgress(at.at(i)/qreal(100)));
QVERIFY(error <= errorBound);
@@ -608,9 +583,9 @@ static inline void setupBezierSpline(QEasingCurve *easingCurve, const QString &s
points.append(point);
}
- QVERIFY(points.count() % 3 == 0);
+ QVERIFY(points.size() % 3 == 0);
- for (int i = 0; i < points.count() / 3; i++) {
+ for (int i = 0; i < points.size() / 3; i++) {
QPointF c1 = points.at(i * 3);
QPointF c2 = points.at(i * 3 + 1);
QPointF p1 = points.at(i * 3 + 2);
@@ -628,7 +603,7 @@ void tst_QEasingCurve::bezierSpline()
setupBezierSpline(&bezierEasingCurve, definition);
const qreal errorBound = 0.002;
- for (int i = 0; i < at.count(); ++i) {
+ for (int i = 0; i < at.size(); ++i) {
const qreal ex = expected.at(i);
const qreal value = bezierEasingCurve.valueForProgress(at.at(i)/qreal(100));
const qreal error = qAbs(ex - value);
@@ -671,7 +646,7 @@ static inline void setupTCBSpline(QEasingCurve *easingCurve, const QString &stri
foreach (const QString &str, pointStr) {
QStringList coordStr = str.split(QLatin1Char(','));
- Q_ASSERT(coordStr.count() == 5);
+ Q_ASSERT(coordStr.size() == 5);
QPointF point(coordStr.first().toDouble(), coordStr.at(1).toDouble());
qreal t = coordStr.at(2).toDouble();
qreal c = coordStr.at(3).toDouble();
@@ -690,7 +665,7 @@ void tst_QEasingCurve::tcbSpline()
setupTCBSpline(&tcbEasingCurve, definition);
const qreal errorBound = 0.002;
- for (int i = 0; i < at.count(); ++i) {
+ for (int i = 0; i < at.size(); ++i) {
const qreal ex = expected.at(i);
const qreal value = tcbEasingCurve.valueForProgress(at.at(i)/qreal(100));
const qreal error = qAbs(ex - value);
diff --git a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt
index 92850a8c4e..63da04185a 100644
--- a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qexplicitlyshareddatapointer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qexplicitlyshareddatapointer Test:
diff --git a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
index 8ff8a7309f..95c2fe612d 100644
--- a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
+++ b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
diff --git a/tests/auto/corelib/tools/qflatmap/CMakeLists.txt b/tests/auto/corelib/tools/qflatmap/CMakeLists.txt
index 5d79b16776..7ab9b60687 100644
--- a/tests/auto/corelib/tools/qflatmap/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qflatmap/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qflatmap.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qflatmap Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qflatmap
SOURCES
tst_qflatmap.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp b/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp
index 674d9fa6c0..112a393136 100644
--- a/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp
+++ b/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp
@@ -1,30 +1,8 @@
-/****************************************************************************
-**
-** 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 WITH Qt-GPL-exception-1.0
+
+#define QT_USE_QSTRINGBUILDER
+#define QFLATMAP_ENABLE_STL_COMPATIBLE_INSERT
#include <QTest>
@@ -38,6 +16,20 @@
#include <list>
#include <tuple>
+static constexpr bool is_even(int n) { return n % 2 == 0; }
+static constexpr bool is_empty(QAnyStringView v) { return v.isEmpty(); }
+
+namespace {
+template <typename P>
+constexpr inline bool is_pair_impl_v = false;
+template <typename T, typename S>
+constexpr inline bool is_pair_impl_v<std::pair<T,S>> = true;
+template <typename P>
+constexpr inline bool is_pair_v = is_pair_impl_v<std::decay_t<P>>;
+template <typename P>
+using if_pair = std::enable_if_t<is_pair_v<P>, bool>;
+}
+
class tst_QFlatMap : public QObject
{
Q_OBJECT
@@ -45,13 +37,25 @@ private slots:
void constructing();
void constAccess();
void insertion();
+ void insertRValuesAndLValues();
void removal();
void extraction();
void iterators();
+ void remove_if_pair() { remove_if_impl([](const auto &p) -> if_pair<decltype(p)> { return is_even(p.first) && is_empty(p.second); }); }
+ void remove_if_key_value() { remove_if_impl([](const auto &k, const auto &v) { return is_even(k) && is_empty(v); }); }
+ void remove_if_key() { remove_if_impl([](int k) { return is_even(k); }, true); }
void statefulComparator();
- void transparency();
+ void transparency_using();
+ void transparency_struct();
+ void try_emplace_and_insert_or_assign();
void viewIterators();
void varLengthArray();
+
+private:
+ template <typename Compare>
+ void transparency_impl();
+ template <typename Predicate>
+ void remove_if_impl(Predicate p, bool removeNonEmptyValues = false);
};
void tst_QFlatMap::constructing()
@@ -138,7 +142,7 @@ void tst_QFlatMap::insertion()
QCOMPARE(m.value("foo").data(), "FOO");
QCOMPARE(m.value("bar").data(), "BAR");
QCOMPARE(m.value("baz").data(), "BAZ");
- QCOMPARE(m.value("oof").data(), "OOF");
+ QCOMPARE(m.value("oof").data(), "eek");
QCOMPARE(m.value("bla").data(), "BLA");
QCOMPARE(m.value("blubb").data(), "BLUBB");
@@ -152,16 +156,52 @@ void tst_QFlatMap::insertion()
m.insert(std::begin(a1), std::end(a1));
m.insert(Qt::OrderedUniqueRange, std::begin(a2), std::end(a2));
QCOMPARE(m.size(), 10);
- QCOMPARE(m.value("narf").data(), "NARFFFFFF");
+ QCOMPARE(m.value("narf").data(), "NARF");
QCOMPARE(m.value("gnampf").data(), "GNAMPF");
}
+void tst_QFlatMap::insertRValuesAndLValues()
+{
+ using Map = QFlatMap<QByteArray, QByteArray>;
+ const QByteArray foo = QByteArrayLiteral("foo");
+ const QByteArray bar = QByteArrayLiteral("bar");
+
+ auto rvalue = [](const QByteArray &ba) { return ba; };
+#define lvalue(x) x
+
+ {
+ Map m;
+ QVERIFY( m.insert(lvalue(foo), lvalue(bar)).second);
+ QVERIFY(!m.insert(lvalue(foo), lvalue(bar)).second);
+ }
+
+ {
+ Map m;
+ QVERIFY( m.insert(lvalue(foo), rvalue(bar)).second);
+ QVERIFY(!m.insert(lvalue(foo), rvalue(bar)).second);
+ }
+
+ {
+ Map m;
+ QVERIFY( m.insert(rvalue(foo), lvalue(bar)).second);
+ QVERIFY(!m.insert(rvalue(foo), lvalue(bar)).second);
+ }
+
+ {
+ Map m;
+ QVERIFY( m.insert(rvalue(foo), rvalue(bar)).second);
+ QVERIFY(!m.insert(rvalue(foo), rvalue(bar)).second);
+ }
+
+#undef lvalue
+}
+
void tst_QFlatMap::extraction()
{
using Map = QFlatMap<int, QByteArray>;
Map::key_container_type expectedKeys = { 1, 2, 3 };
Map::mapped_container_type expectedValues = { "een", "twee", "dree" };
- Map m(expectedKeys, expectedValues);
+ Map m(Qt::OrderedUniqueRange, expectedKeys, expectedValues);
auto keys = m.keys();
auto values = m.values();
QCOMPARE(keys, expectedKeys);
@@ -174,7 +214,7 @@ void tst_QFlatMap::extraction()
void tst_QFlatMap::iterators()
{
using Map = QFlatMap<int, QByteArray>;
- auto m = Map{ { 1, "foo" }, { 2, "bar" }, { 3, "baz" } };
+ auto m = Map{ Qt::OrderedUniqueRange, { { 1, "foo" }, { 2, "bar" }, { 3, "baz" } } };
{
// forward / backward
Map::iterator a = m.begin();
@@ -318,6 +358,74 @@ void tst_QFlatMap::iterators()
}
}
+template <typename Pred>
+void tst_QFlatMap::remove_if_impl(Pred p, bool removeNonEmptyValues)
+{
+ // empty stays empty:
+ {
+ QFlatMap<int, QString> m;
+ QCOMPARE(m.remove_if(p), 0);
+ QVERIFY(m.isEmpty());
+ }
+ // a matching element is removed:
+ {
+ {
+ QFlatMap<int, QString> m;
+ m.insert_or_assign(0, "");
+ QCOMPARE(m.remove_if(p), 1);
+ QVERIFY(m.isEmpty());
+ }
+ if (removeNonEmptyValues) {
+ QFlatMap<int, QString> m;
+ m.insert_or_assign(0, "x");
+ QCOMPARE(m.remove_if(p), 1);
+ QVERIFY(m.isEmpty());
+ }
+ }
+ // a non-matching element is not removed:
+ {
+ {
+ QFlatMap<int, QString> m;
+ m.insert_or_assign(1, "");
+ QCOMPARE(m.remove_if(p), 0);
+ QVERIFY(m.contains(1));
+ QVERIFY(m[1].isEmpty());
+ }
+ if (removeNonEmptyValues) {
+ QFlatMap<int, QString> m;
+ m.insert_or_assign(1, "x");
+ QCOMPARE(m.remove_if(p), 0);
+ QVERIFY(m.contains(1));
+ QCOMPARE(m[1], "x");
+ }
+ }
+ // of matching and non-matching elements, only matching ones are removed:
+ {
+ {
+ QFlatMap<int, QString> m;
+ m.insert_or_assign(0, "");
+ m.insert_or_assign(1, "");
+ const auto copy = m;
+ QCOMPARE(m.remove_if(p), 1);
+ QCOMPARE(copy.size(), 2);
+ QCOMPARE(copy[0], "");
+ QCOMPARE(copy[1], "");
+ QCOMPARE(m.size(), 1);
+ QVERIFY(m.contains(1));
+ QVERIFY(m[1].isEmpty());
+ }
+ {
+ QFlatMap<int, QString> m;
+ m.insert_or_assign(1, "");
+ m.insert_or_assign(2, "");
+ QCOMPARE(m.remove_if(p), 1);
+ QCOMPARE(m.size(), 1);
+ QVERIFY(m.contains(1));
+ QVERIFY(m[1].isEmpty());
+ }
+ }
+}
+
void tst_QFlatMap::removal()
{
using Map = QFlatMap<int, QByteArray>;
@@ -365,17 +473,35 @@ void tst_QFlatMap::statefulComparator()
QVERIFY(m2.key_comp().count > m1.key_comp().count);
}
-void tst_QFlatMap::transparency()
+void tst_QFlatMap::transparency_using()
{
struct StringViewCompare
{
- using is_transparent = void;
- bool operator()(const QStringView &lhs, const QStringView &rhs) const
+ using is_transparent [[maybe_unused]] = void;
+ bool operator()(QAnyStringView lhs, QAnyStringView rhs) const
{
return lhs < rhs;
}
};
+ transparency_impl<StringViewCompare>();
+}
+void tst_QFlatMap::transparency_struct()
+{
+ struct StringViewCompare
+ {
+ struct is_transparent {};
+ bool operator()(QAnyStringView lhs, QAnyStringView rhs) const
+ {
+ return lhs < rhs;
+ }
+ };
+ transparency_impl<StringViewCompare>();
+}
+
+template <typename StringViewCompare>
+void tst_QFlatMap::transparency_impl()
+{
using Map = QFlatMap<QString, QString, StringViewCompare>;
auto m = Map{ { "one", "een" }, { "two", "twee" }, { "three", "dree" } };
@@ -384,8 +510,163 @@ void tst_QFlatMap::transparency()
const QStringView sv2{numbers.constData() + 4, 3};
const QStringView sv3{numbers.constData() + 8, 5};
QCOMPARE(m.lower_bound(sv1).value(), "een");
+ QCOMPARE(m.value(sv1), "een");
QCOMPARE(m.lower_bound(sv2).value(), "twee");
+ QCOMPARE(m.value(sv2), "twee");
QCOMPARE(m.lower_bound(sv3).value(), "dree");
+ QCOMPARE(m.value(sv3), "dree");
+
+ QVERIFY(m.contains(sv2));
+ auto twee = m.take(sv2);
+ static_assert(std::is_same_v<decltype(twee), QString>);
+ QCOMPARE(twee, "twee");
+ QVERIFY(!m.contains(sv2));
+
+ QVERIFY(m.contains(QLatin1String("one")));
+ QVERIFY(m.remove(QAnyStringView(u8"one")));
+ QVERIFY(!m.contains(QLatin1String("one")));
+}
+
+void tst_QFlatMap::try_emplace_and_insert_or_assign()
+{
+ using Map = QFlatMap<QByteArray, QByteArray>;
+
+ const QByteArray foo = QByteArrayLiteral("foo");
+ const qsizetype qqq_1 = 3;
+ const char qqq_2 = 'q';
+ const QByteArray qqq = QByteArray(qqq_1, qqq_2);
+
+ auto sb = [] (const auto &str) { return str % ""; };
+ auto rvalue = [](const auto &x) { return x; };
+#define lvalue(x) x
+#define CHECKS() \
+ do { \
+ QVERIFY(!m.try_emplace(rvalue(foo), lvalue(foo)).second); \
+ QCOMPARE(m.value(foo), qqq); \
+ QVERIFY(!m.try_emplace(lvalue(foo), lvalue(foo)).second); \
+ QCOMPARE(m.value(foo), qqq); \
+ QVERIFY(!m.try_emplace(lvalue(foo), sb(foo)).second); \
+ QCOMPARE(m.value(foo), qqq); \
+ QVERIFY(!m.try_emplace(rvalue(foo), sb(foo)).second); \
+ QCOMPARE(m.value(foo), qqq); \
+ } while (0) \
+ /* end */
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(lvalue(foo), lvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.insert_or_assign(lvalue(foo), lvalue(foo)).second);
+ QCOMPARE(m.value(foo), foo);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.insert_or_assign(lvalue(foo), lvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.try_emplace(lvalue(foo), lvalue(foo)).second);
+ QCOMPARE(m.value(foo), qqq);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(lvalue(foo), rvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.insert_or_assign(lvalue(foo), rvalue(foo)).second);
+ QCOMPARE(m.value(foo), foo);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.insert_or_assign(lvalue(foo), rvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.try_emplace(lvalue(foo), rvalue(foo)).second);
+ QCOMPARE(m.value(foo), qqq);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(lvalue(foo), qqq_1, qqq_2).second);
+ QCOMPARE(m.value(foo), qqq);
+ CHECKS();
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(lvalue(foo), sb(qqq)).second);
+ QCOMPARE(m.value(foo), qqq);
+ CHECKS();
+ QVERIFY(!m.insert_or_assign(lvalue(foo), sb(foo)).second);
+ QCOMPARE(m.value(foo), foo);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.insert_or_assign(lvalue(foo), sb(qqq)).second);
+ QCOMPARE(m.value(foo), qqq);
+ CHECKS();
+ QVERIFY(!m.try_emplace(lvalue(foo), sb(foo)).second);
+ QCOMPARE(m.value(foo), qqq);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(rvalue(foo), lvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.insert_or_assign(rvalue(foo), lvalue(foo)).second);
+ QCOMPARE(m.value(foo), foo);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.insert_or_assign(rvalue(foo), lvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.try_emplace(rvalue(foo), lvalue(foo)).second);
+ QCOMPARE(m.value(foo), qqq);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(rvalue(foo), rvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.insert_or_assign(rvalue(foo), rvalue(foo)).second);
+ QCOMPARE(m.value(foo), foo);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.insert_or_assign(rvalue(foo), rvalue(qqq)).second);
+ CHECKS();
+ QVERIFY(!m.try_emplace(rvalue(foo), rvalue(foo)).second);
+ QCOMPARE(m.value(foo), qqq);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(rvalue(foo), qqq_1, qqq_2).second);
+ QCOMPARE(m.value(foo), qqq);
+ CHECKS();
+ }
+
+ {
+ Map m;
+ QVERIFY(m.try_emplace(rvalue(foo), sb(qqq)).second);
+ QCOMPARE(m.value(foo), qqq);
+ CHECKS();
+ QVERIFY(!m.insert_or_assign(rvalue(foo), sb(foo)).second);
+ QCOMPARE(m.value(foo), foo);
+ }
+
+ {
+ Map m;
+ QVERIFY(m.insert_or_assign(rvalue(foo), sb(qqq)).second);
+ QCOMPARE(m.value(foo), qqq);
+ CHECKS();
+ QVERIFY(!m.try_emplace(rvalue(foo), sb(foo)).second);
+ QCOMPARE(m.value(foo), qqq);
+ }
+#undef CHECKS
+#undef lvalue
}
void tst_QFlatMap::viewIterators()
@@ -401,7 +682,7 @@ void tst_QFlatMap::viewIterators()
});
auto it = keys.begin();
QCOMPARE(*it, "kaksi");
- QCOMPARE(it->length(), 5);
+ QCOMPARE(it->size(), 5);
++it;
QCOMPARE(*it, "kolme");
it++;
@@ -422,7 +703,7 @@ void tst_QFlatMap::viewIterators()
});
auto it = values.begin();
QCOMPARE(*it, "twee");
- QCOMPARE(it->length(), 4);
+ QCOMPARE(it->size(), 4);
++it;
QCOMPARE(*it, "dree");
it++;
@@ -438,10 +719,9 @@ void tst_QFlatMap::viewIterators()
void tst_QFlatMap::varLengthArray()
{
- using Map = QFlatMap<int, QByteArray, std::less<int>,
- QVarLengthArray<int, 1024>, QVarLengthArray<QByteArray, 1024>>;
- Map m{ { 2, "twee" } };
- m.insert(1, "een");
+ using Map = QVarLengthFlatMap<int, QByteArray, 1024>;
+ Map m(Qt::OrderedUniqueRange, { { 2, "twee" } });
+ m.insert_or_assign(1, "een");
m.remove(1);
QVERIFY(!m.isEmpty());
m.remove(2);
diff --git a/tests/auto/corelib/tools/qfreelist/CMakeLists.txt b/tests/auto/corelib/tools/qfreelist/CMakeLists.txt
index b1ac63ccff..383e8c38ee 100644
--- a/tests/auto/corelib/tools/qfreelist/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qfreelist/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qfreelist.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfreelist Test:
@@ -7,14 +8,6 @@
qt_internal_add_test(tst_qfreelist
SOURCES
tst_qfreelist.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
-
-## Scopes:
-#####################################################################
-
-qt_internal_extend_target(tst_qfreelist CONDITION NOT QT_FEATURE_private_tests
- SOURCES
- ../../../../../src/corelib/tools/qfreelist.cpp
-)
diff --git a/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp b/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp
index 5537c70c48..1b2cd610da 100644
--- a/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp
+++ b/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtCore/QCoreApplication>
diff --git a/tests/auto/corelib/tools/qhash/CMakeLists.txt b/tests/auto/corelib/tools/qhash/CMakeLists.txt
index b01782aed5..36a23836c4 100644
--- a/tests/auto/corelib/tools/qhash/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qhash/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qhash.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qhash Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qhash
SOURCES
tst_qhash.cpp
- DEFINES
- #-QT_NO_JAVA_STYLE_ITERATORS # special case remove
)
+
+qt_internal_undefine_global_definition(tst_qhash QT_NO_JAVA_STYLE_ITERATORS)
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 3c873d093e..50b1248d91 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1,41 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <qhash.h>
#include <qmap.h>
+#include <qset.h>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <string>
+#include <qsemaphore.h>
+
+using namespace Qt::StringLiterals;
+
class tst_QHash : public QObject
{
Q_OBJECT
@@ -93,6 +73,20 @@ private slots:
void removeInEmptyHash();
void valueInEmptyHash();
void fineTuningInEmptyHash();
+
+ void reserveShared();
+ void reserveLessThanCurrentAmount();
+ void reserveKeepCapacity_data();
+ void reserveKeepCapacity();
+
+ void QTBUG98265();
+
+ void detachAndReferences();
+
+ void lookupUsingKeyIterator();
+
+ void squeeze();
+ void squeezeShared();
};
struct IdentityTracker {
@@ -176,13 +170,13 @@ void tst_QHash::count()
{
MyMap map;
MyMap map2( map );
- QCOMPARE( map.count(), 0 );
- QCOMPARE( map2.count(), 0 );
+ QCOMPARE( map.size(), 0 );
+ QCOMPARE( map2.size(), 0 );
QCOMPARE( MyClass::count, 0 );
// detach
map2["Hallo"] = MyClass( "Fritz" );
- QCOMPARE( map.count(), 0 );
- QCOMPARE( map2.count(), 1 );
+ QCOMPARE( map.size(), 0 );
+ QCOMPARE( map2.size(), 1 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 1 );
#endif
@@ -192,11 +186,11 @@ void tst_QHash::count()
{
typedef QHash<QString, MyClass> Map;
Map map;
- QCOMPARE( map.count(), 0);
+ QCOMPARE( map.size(), 0);
map.insert( "Torben", MyClass("Weis") );
- QCOMPARE( map.count(), 1 );
+ QCOMPARE( map.size(), 1 );
map.insert( "Claudia", MyClass("Sorg") );
- QCOMPARE( map.count(), 2 );
+ QCOMPARE( map.size(), 2 );
map.insert( "Lars", MyClass("Linzbach") );
map.insert( "Matthias", MyClass("Ettrich") );
map.insert( "Sue", MyClass("Paludo") );
@@ -204,7 +198,7 @@ void tst_QHash::count()
map.insert( "Haavard", MyClass("Nord") );
map.insert( "Arnt", MyClass("Gulbrandsen") );
map.insert( "Paul", MyClass("Tvete") );
- QCOMPARE( map.count(), 9 );
+ QCOMPARE( map.size(), 9 );
map.insert( "Paul", MyClass("Tvete 1") );
map.insert( "Paul", MyClass("Tvete 2") );
map.insert( "Paul", MyClass("Tvete 3") );
@@ -212,68 +206,68 @@ void tst_QHash::count()
map.insert( "Paul", MyClass("Tvete 5") );
map.insert( "Paul", MyClass("Tvete 6") );
- QCOMPARE( map.count(), 9 );
+ QCOMPARE( map.size(), 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
Map map2( map );
- QVERIFY( map2.count() == 9 );
+ QVERIFY( map2.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2.insert( "Kay", MyClass("Roemer") );
- QVERIFY( map2.count() == 10 );
- QVERIFY( map.count() == 9 );
+ QVERIFY( map2.size() == 10 );
+ QVERIFY( map.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 19 );
#endif
map2 = map;
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 9 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2.insert( "Kay", MyClass("Roemer") );
- QVERIFY( map2.count() == 10 );
+ QVERIFY( map2.size() == 10 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 19 );
#endif
map2.clear();
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2 = map;
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 9 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2.clear();
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map.remove( "Lars" );
- QVERIFY( map.count() == 8 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 8 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 8 );
#endif
map.remove( "Mist" );
- QVERIFY( map.count() == 8 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 8 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 8 );
#endif
@@ -287,22 +281,22 @@ void tst_QHash::count()
#ifndef Q_CC_SUN
QVERIFY( MyClass::count == 1 );
#endif
- QVERIFY( map.count() == 1 );
+ QVERIFY( map.size() == 1 );
(void)map["Torben"].str;
(void)map["Lars"].str;
#ifndef Q_CC_SUN
QVERIFY( MyClass::count == 2 );
#endif
- QVERIFY( map.count() == 2 );
+ QVERIFY( map.size() == 2 );
const Map& cmap = map;
(void)cmap["Depp"].str;
#ifndef Q_CC_SUN
QVERIFY( MyClass::count == 2 );
#endif
- QVERIFY( map.count() == 2 );
- QVERIFY( cmap.count() == 2 );
+ QVERIFY( map.size() == 2 );
+ QVERIFY( cmap.size() == 2 );
}
QCOMPARE( MyClass::count, 0 );
{
@@ -542,6 +536,22 @@ void tst_QHash::erase()
auto mit = h2.erase(bit);
mit = h2.erase(h2.begin());
QVERIFY(mit == h2.end());
+
+ h2 = QMultiHash<int, int>();
+ h2.emplace(1, 1);
+ h2.emplace(1, 2);
+ h2.emplace(3, 1);
+ h2.emplace(3, 4);
+ QMultiHash<int, int> h3 = h2;
+ auto it = h3.constFind(3);
+ ++it;
+ QVERIFY(h3.isSharedWith(h2));
+ it = h3.erase(it);
+ QVERIFY(!h3.isSharedWith(h2));
+ if (it != h3.cend()) {
+ auto it2 = h3.constFind(it.key());
+ QCOMPARE(it, it2);
+ }
}
/*
@@ -551,14 +561,40 @@ void tst_QHash::erase()
*/
void tst_QHash::erase_edge_case()
{
+ QHashSeed::setDeterministicGlobalSeed();
+ auto resetSeed = qScopeGuard([&]() {
+ QHashSeed::resetRandomGlobalSeed();
+ });
+
QHash<int, int> h1;
h1.reserve(2);
- h1.d->seed = 10230148258692185509ull;
- h1.insert(3, 4);
- h1.insert(5, 6);
+ qsizetype capacity = h1.capacity();
+ // Beholden to QHash internals:
+ qsizetype numBuckets = capacity << 1;
+
+ // Find some keys which will both be slotted into the last bucket:
+ int keys[2];
+ int index = 0;
+ for (qsizetype i = 0; i < numBuckets * 4 && index < 2; ++i) {
+ const size_t hash = qHash(i, QHashSeed::globalSeed());
+ const size_t bucketForHash = QHashPrivate::GrowthPolicy::bucketForHash(numBuckets, hash);
+ if (qsizetype(bucketForHash) == numBuckets - 1)
+ keys[index++] = i;
+ }
+ QCOMPARE(index, 2); // Sanity check. If this fails then the test needs an update!
+
+ // As mentioned earlier these are both calculated to be in the last bucket:
+ h1.insert(keys[0], 4);
+ h1.insert(keys[1], 6);
+ // As a sanity-check, make sure that the key we inserted last is the first one (because its
+ // allocation to the last bucket would make it wrap around):
+ // NOTE: If this fails this then this test may need an update!!!
+ QCOMPARE(h1.constBegin().key(), keys[1]);
+ // Then we delete the last entry:
QHash<int, int>::iterator it1 = h1.begin();
++it1;
it1 = h1.erase(it1);
+ // Now, since we deleted the last entry, the iterator should be at the end():
QVERIFY(it1 == h1.end());
}
@@ -870,16 +906,31 @@ class QGlobalQHashSeedResetter
int oldSeed;
public:
// not entirely correct (may lost changes made by another thread between the query
- // of the old and the setting of the new seed), but qSetGlobalQHashSeed doesn't
+ // of the old and the setting of the new seed), but setHashSeed() can't
// return the old value, so this is the best we can do:
explicit QGlobalQHashSeedResetter(int newSeed)
- : oldSeed(qGlobalQHashSeed())
+ : oldSeed(getHashSeed())
{
- qSetGlobalQHashSeed(newSeed);
+ setHashSeed(newSeed);
}
~QGlobalQHashSeedResetter()
{
- qSetGlobalQHashSeed(oldSeed);
+ setHashSeed(oldSeed);
+ }
+
+private:
+ // The functions are implemented to replace the deprecated
+ // qGlobalQHashSeed() and qSetGlobalQHashSeed()
+ static int getHashSeed()
+ {
+ return int(QHashSeed::globalSeed() & INT_MAX);
+ }
+ static void setHashSeed(int seed)
+ {
+ if (seed == 0)
+ QHashSeed::setDeterministicGlobalSeed();
+ else
+ QHashSeed::resetRandomGlobalSeed();
}
};
@@ -1595,9 +1646,9 @@ void tst_QHash::rehash_isnt_quadratic()
{
// this test should be incredibly slow if rehash() is quadratic
for (int j = 0; j < 5; ++j) {
- QMultiHash<int, int> testHash;
+ QHash<int, int> testHash;
for (int i = 0; i < 500000; ++i)
- testHash.insert(1, 1);
+ testHash.insert(i, 1);
}
}
@@ -1654,26 +1705,26 @@ void tst_QHash::qmultihash_specific()
}
QVERIFY(hash1.contains(9, 99));
- QCOMPARE(hash1.count(), 45);
+ QCOMPARE(hash1.size(), 45);
hash1.remove(9, 99);
QVERIFY(!hash1.contains(9, 99));
- QCOMPARE(hash1.count(), 44);
+ QCOMPARE(hash1.size(), 44);
hash1.remove(9, 99);
QVERIFY(!hash1.contains(9, 99));
- QCOMPARE(hash1.count(), 44);
+ QCOMPARE(hash1.size(), 44);
hash1.remove(1, 99);
- QCOMPARE(hash1.count(), 44);
+ QCOMPARE(hash1.size(), 44);
hash1.insert(1, 99);
hash1.insert(1, 99);
- QCOMPARE(hash1.count(), 46);
+ QCOMPARE(hash1.size(), 46);
hash1.remove(1, 99);
- QCOMPARE(hash1.count(), 44);
+ QCOMPARE(hash1.size(), 44);
hash1.remove(1, 99);
- QCOMPARE(hash1.count(), 44);
+ QCOMPARE(hash1.size(), 44);
{
QMultiHash<int, int>::const_iterator i = hash1.constFind(1, 11);
@@ -1719,10 +1770,10 @@ void tst_QHash::qmultihash_specific()
}
QCOMPARE(hash1.count(9), 8);
- QCOMPARE(hash1.count(), 44);
+ QCOMPARE(hash1.size(), 44);
hash1.remove(9);
QCOMPARE(hash1.count(9), 0);
- QCOMPARE(hash1.count(), 36);
+ QCOMPARE(hash1.size(), 36);
{
QMultiHash<int, int> map1;
@@ -1738,15 +1789,16 @@ void tst_QHash::qmultihash_specific()
map2.insert(42, 1);
map2.insert(10, 2);
map2.insert(48, 3);
- QCOMPARE(map1.count(), map2.count());
+ QCOMPARE(map1.size(), map2.size());
QVERIFY(map1.remove(42,5));
+ QVERIFY(map1 != map2);
QVERIFY(map2.remove(42,5));
QVERIFY(map1 == map2);
QHash<int, int> hash;
hash.insert(-1, -1);
map2.unite(hash);
- QCOMPARE(map2.count(), 6);
+ QCOMPARE(map2.size(), 6);
QCOMPARE(map2[-1], -1);
}
}
@@ -2133,7 +2185,7 @@ void tst_QHash::twoArguments_qHash()
void tst_QHash::initializerList()
{
QHash<int, QString> hash = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
- QCOMPARE(hash.count(), 2);
+ QCOMPARE(hash.size(), 2);
QCOMPARE(hash[1], QString("hello"));
QCOMPARE(hash[2], QString("initializer_list"));
@@ -2143,9 +2195,9 @@ void tst_QHash::initializerList()
// QCOMPARE(stdh[1], QString("bar"));
QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}};
- QCOMPARE(multiHash.count(), 3);
+ QCOMPARE(multiHash.size(), 3);
QList<int> values = multiHash.values("il");
- QCOMPARE(values.count(), 3);
+ QCOMPARE(values.size(), 3);
QHash<int, int> emptyHash{};
QVERIFY(emptyHash.isEmpty());
@@ -2317,7 +2369,7 @@ void tst_QHash::insert_hash()
hash.insert(hash2);
- QCOMPARE(hash.count(), 5);
+ QCOMPARE(hash.size(), 5);
for (int i = 0; i < 5; ++i)
QCOMPARE(hash[i], i);
}
@@ -2329,7 +2381,7 @@ void tst_QHash::insert_hash()
hash.insert(hash2);
- QCOMPARE(hash.count(), 1);
+ QCOMPARE(hash.size(), 1);
QCOMPARE(hash[0], 5);
}
{
@@ -2339,7 +2391,7 @@ void tst_QHash::insert_hash()
hash.insert(hash2);
- QCOMPARE(hash.count(), 1);
+ QCOMPARE(hash.size(), 1);
QCOMPARE(hash[0], 5);
QCOMPARE(hash, hash2);
}
@@ -2352,7 +2404,7 @@ void tst_QHash::insert_hash()
// insert into ourself, nothing should happen
hash.insert(hash);
- QCOMPARE(hash.count(), 3);
+ QCOMPARE(hash.size(), 3);
QCOMPARE(hash[0], 7);
QCOMPARE(hash[2], 5);
QCOMPARE(hash[7], 55);
@@ -2526,13 +2578,13 @@ void tst_QHash::countInEmptyHash()
{
{
QHash<int, int> hash;
- QCOMPARE(hash.count(), 0);
+ QCOMPARE(hash.size(), 0);
QCOMPARE(hash.count(42), 0);
}
{
QMultiHash<int, int> hash;
- QCOMPARE(hash.count(), 0);
+ QCOMPARE(hash.size(), 0);
QCOMPARE(hash.count(42), 0);
QCOMPARE(hash.count(42, 1), 0);
}
@@ -2598,5 +2650,250 @@ void tst_QHash::fineTuningInEmptyHash()
QVERIFY(hash.capacity() > 0);
}
+void tst_QHash::reserveShared()
+{
+ QHash<char, char> hash;
+ hash.insert('c', 'c');
+ auto hash2 = hash;
+
+ QCOMPARE(hash2.capacity(), hash.capacity());
+ auto oldCap = hash.capacity();
+
+ hash2.reserve(100); // This shouldn't crash
+
+ QVERIFY(hash2.capacity() >= 100);
+ QCOMPARE(hash.capacity(), oldCap);
+}
+
+void tst_QHash::reserveLessThanCurrentAmount()
+{
+ {
+ QHash<int, int> hash;
+ for (int i = 0; i < 1000; ++i)
+ hash.insert(i, i * 10);
+
+ // This used to hang in an infinite loop: QTBUG-102067
+ hash.reserve(1);
+
+ // Make sure that hash still has all elements
+ for (int i = 0; i < 1000; ++i)
+ QCOMPARE(hash.value(i), i * 10);
+ }
+ {
+ QMultiHash<int, int> hash;
+ for (int i = 0; i < 1000; ++i) {
+ hash.insert(i, i * 10);
+ hash.insert(i, i * 10 + 1);
+ }
+
+ // This used to hang in infinite loop: QTBUG-102067
+ hash.reserve(1);
+
+ // Make sure that hash still has all elements
+ for (int i = 0; i < 1000; ++i)
+ QCOMPARE(hash.values(i), QList<int>({ i * 10 + 1, i * 10 }));
+ }
+}
+
+void tst_QHash::reserveKeepCapacity_data()
+{
+ QTest::addColumn<qsizetype>("requested");
+ auto addRow = [](qsizetype requested) {
+ QTest::addRow("%td", ptrdiff_t(requested)) << requested;
+ };
+
+ QHash<int, int> testHash = {{1, 1}};
+ qsizetype minCapacity = testHash.capacity();
+ addRow(minCapacity - 1);
+ addRow(minCapacity + 0);
+ addRow(minCapacity + 1);
+ addRow(2 * minCapacity - 1);
+ addRow(2 * minCapacity + 0);
+ addRow(2 * minCapacity + 1);
+}
+
+void tst_QHash::reserveKeepCapacity()
+{
+ QFETCH(qsizetype, requested);
+
+ QHash<qsizetype, qsizetype> hash;
+ hash.reserve(requested);
+ qsizetype initialCapacity = hash.capacity();
+ QCOMPARE_GE(initialCapacity, requested);
+
+ // insert this many elements into the hash
+ for (qsizetype i = 0; i < requested; ++i)
+ hash.insert(i, i);
+
+ // it mustn't have increased capacity after inserting the elements
+ QCOMPARE(hash.capacity(), initialCapacity);
+}
+
+void tst_QHash::QTBUG98265()
+{
+ QMultiHash<QUuid, QByteArray> a;
+ QMultiHash<QUuid, QByteArray> b;
+ a.insert(QUuid("3e0dfb4d-90eb-43a4-bd54-88f5b69832c1"), QByteArray());
+ b.insert(QUuid("1b710ada-3dd7-432e-b7c8-e852e59f46a0"), QByteArray());
+
+ QVERIFY(a != b);
+}
+
+/*
+ Calling functions which take a const-ref argument for a key with a reference
+ to a key inside the hash itself should keep the key valid as long as it is
+ needed. If not users may get hard-to-debug races where CoW should've
+ shielded them.
+*/
+void tst_QHash::detachAndReferences()
+{
+#if !QT_CONFIG(cxx11_future)
+ QSKIP("This test requires cxx11_future")
+#else
+ // Repeat a few times because it's not a guarantee
+ for (int i = 0; i < 50; ++i) {
+ QHash<char, char> hash;
+ hash.insert('a', 'a');
+ hash.insert('b', 'a');
+ hash.insert('c', 'a');
+ hash.insert('d', 'a');
+ hash.insert('e', 'a');
+ hash.insert('f', 'a');
+ hash.insert('g', 'a');
+
+ QSemaphore sem;
+ QSemaphore sem2;
+ std::thread th([&sem, &sem2, hash]() mutable {
+ sem.release();
+ sem2.acquire();
+ hash.reserve(100); // [2]: ...then this rehashes directly, without detaching
+ });
+
+ // The key is a reference to an entry in the hash. If we were already
+ // detached then no problem occurs! The problem happens because _after_
+ // we detach but before using the key the other thread resizes and
+ // rehashes, leaving our const-ref dangling.
+ auto it = hash.constBegin();
+ const auto &key = it.key(); // [3]: leaving our const-refs dangling
+ auto kCopy = key;
+ const auto &value = it.value();
+ auto vCopy = value;
+ sem2.release();
+ sem.acquire();
+ hash.insert(key, value); // [1]: this detaches first...
+
+ th.join();
+ QCOMPARE(hash.size(), 7);
+ QVERIFY(hash.contains(kCopy));
+ QCOMPARE(hash.value(kCopy), vCopy);
+ }
+#endif
+}
+
+void tst_QHash::lookupUsingKeyIterator()
+{
+ QHash<QString, QString> hash;
+ hash.reserve(1);
+ qsizetype minCapacity = hash.capacity();
+ // Beholden to internal implementation details:
+ qsizetype rehashLimit = minCapacity == 64 ? 63 : 8;
+
+ for (char16_t c = u'a'; c <= u'a' + rehashLimit; ++c)
+ hash.insert(QString(QChar(c)), u"h"_s);
+
+ for (auto it = hash.keyBegin(), end = hash.keyEnd(); it != end; ++it)
+ QVERIFY(!hash[*it].isEmpty());
+}
+
+void tst_QHash::squeeze()
+{
+ {
+ QHash<int, int> hash;
+ hash.reserve(1000);
+ for (int i = 0; i < 10; ++i)
+ hash.insert(i, i * 10);
+ QVERIFY(hash.isDetached());
+ const size_t buckets = hash.bucket_count();
+ const qsizetype size = hash.size();
+
+ hash.squeeze();
+
+ QVERIFY(hash.bucket_count() < buckets);
+ QCOMPARE(hash.size(), size);
+ for (int i = 0; i < size; ++i)
+ QCOMPARE(hash.value(i), i * 10);
+ }
+ {
+ QMultiHash<int, int> hash;
+ hash.reserve(1000);
+ for (int i = 0; i < 10; ++i) {
+ hash.insert(i, i * 10);
+ hash.insert(i, i * 10 + 1);
+ }
+ QVERIFY(hash.isDetached());
+ const size_t buckets = hash.bucket_count();
+ const qsizetype size = hash.size();
+
+ hash.squeeze();
+
+ QVERIFY(hash.bucket_count() < buckets);
+ QCOMPARE(hash.size(), size);
+ for (int i = 0; i < (size / 2); ++i)
+ QCOMPARE(hash.values(i), QList<int>({ i * 10 + 1, i * 10 }));
+ }
+}
+
+void tst_QHash::squeezeShared()
+{
+ {
+ QHash<int, int> hash;
+ hash.reserve(1000);
+ for (int i = 0; i < 10; ++i)
+ hash.insert(i, i * 10);
+
+ QHash<int, int> other = hash;
+
+ // Check that when squeezing a hash with shared d_ptr, the number of
+ // buckets actually decreases.
+ QVERIFY(!other.isDetached());
+ const size_t buckets = other.bucket_count();
+ const qsizetype size = other.size();
+
+ other.squeeze();
+
+ QCOMPARE(hash.bucket_count(), buckets);
+ QVERIFY(other.bucket_count() < buckets);
+
+ QCOMPARE(other.size(), size);
+ for (int i = 0; i < size; ++i)
+ QCOMPARE(other.value(i), i * 10);
+ }
+ {
+ QMultiHash<int, int> hash;
+ hash.reserve(1000);
+ for (int i = 0; i < 10; ++i) {
+ hash.insert(i, i * 10);
+ hash.insert(i, i * 10 + 1);
+ }
+
+ QMultiHash<int, int> other = hash;
+
+ // Check that when squeezing a hash with shared d_ptr, the number of
+ // buckets actually decreases.
+ QVERIFY(!other.isDetached());
+ const size_t buckets = other.bucket_count();
+ const qsizetype size = other.size();
+
+ other.squeeze();
+
+ QCOMPARE(hash.bucket_count(), buckets);
+ QVERIFY(other.bucket_count() < buckets);
+
+ QCOMPARE(other.size(), size);
+ for (int i = 0; i < (size / 2); ++i)
+ QCOMPARE(other.values(i), QList<int>({ i * 10 + 1, i * 10 }));
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QHash)
#include "tst_qhash.moc"
diff --git a/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt b/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt
index 86d4207d6e..9f25182a3e 100644
--- a/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qhashfunctions.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qhashfunctions Test:
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index a440d43454..6daf418e7b 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -1,32 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
+#include <QVarLengthArray>
#include <qhash.h>
@@ -77,7 +53,11 @@ private Q_SLOTS:
void stdPair_string_pairIntInt() { stdPair_template(QString("Hello"), std::make_pair(42, -47)); } // QTBUG-92910
void stdPair_int_pairIntPairIntInt() { stdPair_template(1, std::make_pair(2, std::make_pair(3, 4))); }
+ void enum_int_consistent_hash_qtbug108032();
+
+#if QT_DEPRECATED_SINCE(6, 6)
void setGlobalQHashSeed();
+#endif
};
void tst_QHashFunctions::consistent()
@@ -230,8 +210,14 @@ namespace SomeNamespace {
struct Hashable { int i; };
inline size_t qHash(Hashable h, size_t seed = 0)
{ return QT_PREPEND_NAMESPACE(qHash)(h.i, seed); }
-}
+ struct AdlHashable {
+ int i;
+ private:
+ friend size_t qHash(AdlHashable h, size_t seed = 0)
+ { return QT_PREPEND_NAMESPACE(qHash)(h.i, seed); }
+ };
+}
void tst_QHashFunctions::range()
{
static const int ints[] = {0, 1, 2, 3, 4, 5};
@@ -253,10 +239,16 @@ void tst_QHashFunctions::range()
QCOMPARE(qHashRange(ints, ints + numInts, seed), qHashRange(it, end, seed));
}
- SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
- static const size_t numHashables = sizeof hashables / sizeof *hashables;
- // compile check: is qHash() found using ADL?
- (void)qHashRange(hashables, hashables + numHashables, seed);
+ {
+ SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
+ // compile check: is qHash() found using ADL?
+ [[maybe_unused]] auto r = qHashRange(std::begin(hashables), std::end(hashables), seed);
+ }
+ {
+ SomeNamespace::AdlHashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
+ // compile check: is qHash() found as a hidden friend?
+ [[maybe_unused]] auto r = qHashRange(std::begin(hashables), std::end(hashables), seed);
+ }
}
void tst_QHashFunctions::rangeCommutative()
@@ -279,15 +271,47 @@ void tst_QHashFunctions::rangeCommutative()
QCOMPARE(qHashRangeCommutative(ints, ints + numInts, seed), qHashRangeCommutative(it, end, seed));
}
- SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
- static const size_t numHashables = sizeof hashables / sizeof *hashables;
- // compile check: is qHash() found using ADL?
- (void)qHashRangeCommutative(hashables, hashables + numHashables, seed);
+ {
+ SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
+ // compile check: is qHash() found using ADL?
+ [[maybe_unused]] auto r = qHashRangeCommutative(std::begin(hashables), std::end(hashables), seed);
+ }
+ {
+ SomeNamespace::AdlHashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
+ // compile check: is qHash() found as a hidden friend?
+ [[maybe_unused]] auto r = qHashRangeCommutative(std::begin(hashables), std::end(hashables), seed);
+ }
}
+// QVarLengthArray these days has a qHash() as a hidden friend.
+// This checks that QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH can deal with that:
+
+QT_BEGIN_NAMESPACE
+QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(QVarLengthArray<QVector<int>>)
+QT_END_NAMESPACE
+
void tst_QHashFunctions::stdHash()
{
{
+ std::unordered_set<QVarLengthArray<QVector<int>>> s = {
+ {
+ {0, 1, 2},
+ {42, 43, 44},
+ {},
+ }, {
+ {11, 12, 13},
+ {},
+ },
+ };
+ QCOMPARE(s.size(), 2UL);
+ s.insert({
+ {11, 12, 13},
+ {},
+ });
+ QCOMPARE(s.size(), 2UL);
+ }
+
+ {
std::unordered_set<QString> s = {QStringLiteral("Hello"), QStringLiteral("World")};
QCOMPARE(s.size(), 2UL);
s.insert(QStringLiteral("Hello"));
@@ -350,8 +374,21 @@ void tst_QHashFunctions::stdPair_template(const T1 &t1, const T2 &t2)
QCOMPARE(qHash(vpair, seed), qHash(vpair, seed));
}
+void tst_QHashFunctions::enum_int_consistent_hash_qtbug108032()
+{
+ enum E { E1, E2, E3 };
+
+ static_assert(QHashPrivate::HasQHashSingleArgOverload<E>);
+
+ QCOMPARE(qHash(E1, seed), qHash(int(E1), seed));
+ QCOMPARE(qHash(E2, seed), qHash(int(E2), seed));
+ QCOMPARE(qHash(E3, seed), qHash(int(E3), seed));
+}
+
+#if QT_DEPRECATED_SINCE(6, 6)
void tst_QHashFunctions::setGlobalQHashSeed()
{
+QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
// Setter works as advertised
qSetGlobalQHashSeed(0);
QCOMPARE(qGlobalQHashSeed(), 0);
@@ -364,7 +401,9 @@ void tst_QHashFunctions::setGlobalQHashSeed()
// Reset works as advertised
qSetGlobalQHashSeed(-1);
QVERIFY(qGlobalQHashSeed() > 0);
+QT_WARNING_POP
}
+#endif // QT_DEPRECATED_SINCE(6, 6)
QTEST_APPLESS_MAIN(tst_QHashFunctions)
#include "tst_qhashfunctions.moc"
diff --git a/tests/auto/corelib/tools/qhashseed/CMakeLists.txt b/tests/auto/corelib/tools/qhashseed/CMakeLists.txt
index bc40c63b3e..a098f103a7 100644
--- a/tests/auto/corelib/tools/qhashseed/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qhashseed/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#####################################################################
## tst_qhashseed Test:
#####################################################################
diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
index 60f3fe9e3c..2562ebfaa6 100644
--- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
+++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 Intel Corporation.
-** 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 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
@@ -134,8 +109,13 @@ void tst_QHashSeed::reseeding()
void tst_QHashSeed::quality()
{
- constexpr int Iterations = 16;
+ // this "bad seed" is used internally in qhash.cpp and should never leak!
+ constexpr size_t BadSeed = size_t(Q_UINT64_C(0x5555'5555'5555'5555));
+
+ constexpr int Iterations = 24; // nicely divisible by 3
int oneThird = 0;
+ int badSeeds = 0;
+ int seedsToMinus1 = 0;
size_t ored = 0;
for (int i = 0; i < Iterations; ++i) {
@@ -146,21 +126,35 @@ void tst_QHashSeed::quality()
if (bits >= std::numeric_limits<size_t>::digits / 3)
++oneThird;
+ if (seed == BadSeed)
+ ++badSeeds;
+ if (ored != size_t(-1))
+ ++seedsToMinus1;
+
+ QHashSeed::resetRandomGlobalSeed();
}
// report out
+ qInfo() << "Number of seeds until all bits became set:" << seedsToMinus1 << '/' << Iterations;
qInfo() << "Number of seeds with at least one third of the bits set:"
<< oneThird << '/' << Iterations;
- qInfo() << "Number of bits in OR'ed value:" << qPopulationCount(quintptr(ored))
- << '/' << std::numeric_limits<size_t>::digits;
- if (std::numeric_limits<size_t>::digits > 32) {
- quint32 upper = quint64(ored) >> 32;
- qInfo() << "Number of bits in the upper half:" << qPopulationCount(upper) << "/ 32";
- QVERIFY(qPopulationCount(upper) > (32/3));
- }
+
+ // we must have set all bits after all the iterations
+ QCOMPARE(ored, size_t(-1));
// at least one third of the seeds must have one third of all the bits set
- QVERIFY(oneThird > (16/3));
+ QVERIFY(oneThird > (Iterations/3));
+
+ // at most one seed can be the bad seed, if 32-bit, none on 64-bit
+ if (std::numeric_limits<size_t>::digits > 32)
+ QCOMPARE(badSeeds, 0);
+ else
+ QVERIFY2(badSeeds <= 1, "badSeeds = " + QByteArray::number(badSeeds));
+
+ // we must have taken at most two thirds of the iterations to have set each
+ // bit at least once
+ QVERIFY2(seedsToMinus1 < 2*Iterations/3,
+ "seedsToMinus1 = " + QByteArray::number(seedsToMinus1));
}
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp
index 752228e5a1..57ecf09575 100644
--- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp
+++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 Intel Corporation.
-** 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 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <qhashfunctions.h>
#include <stdio.h>
diff --git a/tests/auto/corelib/tools/qline/CMakeLists.txt b/tests/auto/corelib/tools/qline/CMakeLists.txt
index 49253ff06c..5395d92f20 100644
--- a/tests/auto/corelib/tools/qline/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qline/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qline.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qline Test:
@@ -13,6 +14,6 @@ qt_internal_add_test(tst_qline
#####################################################################
qt_internal_extend_target(tst_qline CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY AND NOT VXWORKS
- PUBLIC_LIBRARIES
+ LIBRARIES
m
)
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp
index ad8438dfe9..dd7bb2b997 100644
--- a/tests/auto/corelib/tools/qline/tst_qline.cpp
+++ b/tests/auto/corelib/tools/qline/tst_qline.cpp
@@ -1,35 +1,12 @@
-/****************************************************************************
-**
-** 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) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <qline.h>
#include <qmath.h>
+#include <array>
+
class tst_QLine : public QObject
{
Q_OBJECT
@@ -58,6 +35,9 @@ private slots:
void testAngleTo_data();
void testSet();
+
+ void toLineF_data();
+ void toLineF();
};
const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4;
@@ -269,6 +249,13 @@ void tst_QLine::testLength()
QCOMPARE(l.length(), qreal(length));
l.setLength(lengthToSet);
+
+ if constexpr (std::numeric_limits<double>::has_denorm != std::denorm_present) {
+ if (qstrcmp(QTest::currentDataTag(), "[tiny,tiny]->|2| (-tiny/2,-tiny/2)") == 0
+ || qstrcmp(QTest::currentDataTag(), "[4e-323,5e-324]|1892|") == 0) {
+ QSKIP("Skipping 'denorm' as this type lacks denormals on this system");
+ }
+ }
// Scaling tiny values up to big can be imprecise: don't try to test vx, vy
if (length > 0 && qFuzzyIsNull(length)) {
QVERIFY(l.length() > lengthToSet / 2 && l.length() < lengthToSet * 2);
@@ -495,5 +482,35 @@ void tst_QLine::testAngleTo_data()
}
}
+void tst_QLine::toLineF_data()
+{
+ QTest::addColumn<QLine>("input");
+ QTest::addColumn<QLineF>("result");
+
+ auto row = [](int x1, int y1, int x2, int y2) {
+ QTest::addRow("((%d, %d)->(%d, %d))", x1, y1, x2, y2)
+ << QLine(x1, y1, x2, y2) << QLineF(x1, y1, x2, y2);
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int x1 : samples) {
+ for (int y1 : samples) {
+ for (int x2 : samples) {
+ for (int y2 : samples) {
+ row(x1, y1, x2, y2);
+ }
+ }
+ }
+ }
+}
+
+void tst_QLine::toLineF()
+{
+ QFETCH(const QLine, input);
+ QFETCH(const QLineF, result);
+
+ QCOMPARE(input.toLineF(), result);
+}
+
+
QTEST_MAIN(tst_QLine)
#include "tst_qline.moc"
diff --git a/tests/auto/corelib/tools/qlist/CMakeLists.txt b/tests/auto/corelib/tools/qlist/CMakeLists.txt
index 89b92ab305..debd47bc75 100644
--- a/tests/auto/corelib/tools/qlist/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qlist/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qlist.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qlist Test:
@@ -7,6 +8,8 @@
qt_internal_add_test(tst_qlist
SOURCES
tst_qlist.cpp
+ LIBRARIES
+ Qt::CorePrivate
)
## Scopes:
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
index f40370bfb8..482079b0fe 100644
--- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp
+++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
@@ -1,43 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 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 WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QAtomicInt>
#include <QThread>
#include <QSemaphore>
-#include <QScopedValueRollback>
+#include <private/qatomicscopedvaluerollback_p.h>
#include <qlist.h>
#if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11)
# if __has_include(<concepts>)
# include <concepts>
-# if defined(__cpp_concepts)
+# if defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
static_assert(std::contiguous_iterator<QList<int>::iterator>);
static_assert(std::contiguous_iterator<QList<int>::const_iterator>);
# endif
@@ -1103,20 +1078,20 @@ void tst_QList::count() const
{
// zero size
QList<T> myvec;
- QVERIFY(myvec.count() == 0);
+ QVERIFY(myvec.size() == 0);
QVERIFY(!myvec.isDetached());
// grow
myvec.append(SimpleValue<T>::at(0));
- QVERIFY(myvec.count() == 1);
+ QVERIFY(myvec.size() == 1);
myvec.append(SimpleValue<T>::at(1));
- QVERIFY(myvec.count() == 2);
+ QVERIFY(myvec.size() == 2);
// shrink
myvec.remove(0);
- QVERIFY(myvec.count() == 1);
+ QVERIFY(myvec.size() == 1);
myvec.remove(0);
- QVERIFY(myvec.count() == 0);
+ QVERIFY(myvec.size() == 0);
}
// count of items
@@ -1930,11 +1905,11 @@ void tst_QList::move() const
list << T_FOO << T_BAR << T_BAZ;
// move an item
- list.move(0, list.count() - 1);
+ list.move(0, list.size() - 1);
QCOMPARE(list, QList<T>() << T_BAR << T_BAZ << T_FOO);
// move it back
- list.move(list.count() - 1, 0);
+ list.move(list.size() - 1, 0);
QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ);
// move an item in the middle
@@ -2698,24 +2673,24 @@ void tst_QList::size() const
// zero size
QList<T> myvec;
QVERIFY(myvec.size() == 0);
- QCOMPARE(myvec.length(), myvec.size());
+ QCOMPARE(myvec.size(), myvec.size());
QVERIFY(!myvec.isDetached());
// grow
myvec.append(SimpleValue<T>::at(0));
QVERIFY(myvec.size() == 1);
- QCOMPARE(myvec.length(), myvec.size());
+ QCOMPARE(myvec.size(), myvec.size());
myvec.append(SimpleValue<T>::at(1));
QVERIFY(myvec.size() == 2);
- QCOMPARE(myvec.length(), myvec.size());
+ QCOMPARE(myvec.size(), myvec.size());
// shrink
myvec.remove(0);
QVERIFY(myvec.size() == 1);
- QCOMPARE(myvec.length(), myvec.size());
+ QCOMPARE(myvec.size(), myvec.size());
myvec.remove(0);
QVERIFY(myvec.size() == 0);
- QCOMPARE(myvec.length(), myvec.size());
+ QCOMPARE(myvec.size(), myvec.size());
}
// ::squeeze() is tested in ::capacity().
@@ -3206,7 +3181,7 @@ void tst_QList::emplaceReturnsIterator()
void tst_QList::emplaceFront() const
{
- QScopedValueRollback<QAtomicInt> rollback(Movable::counter, 0);
+ QAtomicScopedValueRollback rollback(Movable::counter, 0);
QList<Movable> vec;
vec.emplaceFront('b');
@@ -3231,7 +3206,7 @@ void tst_QList::emplaceFrontReturnsRef() const
void tst_QList::emplaceBack()
{
- QScopedValueRollback<QAtomicInt> rollback(Movable::counter, 0);
+ QAtomicScopedValueRollback rollback(Movable::counter, 0);
QList<Movable> vec;
diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt b/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt
index e2f1ed45ea..93db3e0077 100644
--- a/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmacautoreleasepool.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmacautoreleasepool Test:
@@ -7,6 +8,7 @@
qt_internal_add_test(tst_qmacautoreleasepool
SOURCES
tst_qmacautoreleasepool.mm
- PUBLIC_LIBRARIES
+ LIBRARIES
+ Qt::CorePrivate
${FWFoundation}
)
diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
index 56e9a2748d..e18d848f87 100644
--- a/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
+++ b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
@@ -1,33 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 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) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
+#include <QtCore/private/qcore_mac_p.h>
+
#include <Foundation/Foundation.h>
class tst_QMacAutoreleasePool : public QObject
diff --git a/tests/auto/corelib/tools/qmakearray/CMakeLists.txt b/tests/auto/corelib/tools/qmakearray/CMakeLists.txt
index fc5be609e1..2de6028f39 100644
--- a/tests/auto/corelib/tools/qmakearray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmakearray/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmakearray.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmakearray Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qmakearray
SOURCES
tst_qmakearray.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp b/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp
index 2e27272364..ffd99a0309 100644
--- a/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp
+++ b/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
diff --git a/tests/auto/corelib/tools/qmap/CMakeLists.txt b/tests/auto/corelib/tools/qmap/CMakeLists.txt
index c0a2cb79ab..056902eb82 100644
--- a/tests/auto/corelib/tools/qmap/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmap/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmap.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmap Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qmap
SOURCES
tst_qmap.cpp
- DEFINES
- #-QT_NO_JAVA_STYLE_ITERATORS # special case remove
)
+
+qt_internal_undefine_global_definition(tst_qmap QT_NO_JAVA_STYLE_ITERATORS)
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index e5bddb5d8d..577ea1e898 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <qmap.h>
#include <QTest>
@@ -85,6 +60,13 @@ private slots:
void eraseValidIteratorOnSharedMap();
void removeElementsInMap();
void toStdMap();
+
+ // Tests for deprecated APIs.
+#if QT_DEPRECATED_SINCE(6, 0)
+ void deprecatedInsertMulti();
+ void deprecatedIteratorApis();
+ void deprecatedInsert();
+#endif // QT_DEPRECATED_SINCE(6, 0)
};
struct IdentityTracker {
@@ -184,8 +166,8 @@ void tst_QMap::count()
{
MyMap map;
MyMap map2( map );
- QCOMPARE( map.count(), 0 );
- QCOMPARE( map2.count(), 0 );
+ QCOMPARE( map.size(), 0 );
+ QCOMPARE( map2.size(), 0 );
QCOMPARE( MyClass::count, int(0) );
QCOMPARE(map.count("key"), 0);
QCOMPARE(map.size(), 0);
@@ -194,9 +176,9 @@ void tst_QMap::count()
QVERIFY(!map2.isDetached());
// detach
map2["Hallo"] = MyClass( "Fritz" );
- QCOMPARE( map.count(), 0 );
QCOMPARE( map.size(), 0 );
- QCOMPARE( map2.count(), 1 );
+ QCOMPARE( map.size(), 0 );
+ QCOMPARE( map2.size(), 1 );
QCOMPARE( map2.size(), 1 );
QVERIFY(!map.isDetached());
#ifndef Q_CC_SUN
@@ -208,11 +190,11 @@ void tst_QMap::count()
{
typedef QMap<QString, MyClass> Map;
Map map;
- QCOMPARE( map.count(), 0);
+ QCOMPARE( map.size(), 0);
map.insert( "Torben", MyClass("Weis") );
- QCOMPARE( map.count(), 1 );
+ QCOMPARE( map.size(), 1 );
map.insert( "Claudia", MyClass("Sorg") );
- QCOMPARE( map.count(), 2 );
+ QCOMPARE( map.size(), 2 );
map.insert( "Lars", MyClass("Linzbach") );
map.insert( "Matthias", MyClass("Ettrich") );
map.insert( "Sue", MyClass("Paludo") );
@@ -220,7 +202,7 @@ void tst_QMap::count()
map.insert( "Haavard", MyClass("Nord") );
map.insert( "Arnt", MyClass("Gulbrandsen") );
map.insert( "Paul", MyClass("Tvete") );
- QCOMPARE( map.count(), 9 );
+ QCOMPARE( map.size(), 9 );
map.insert( "Paul", MyClass("Tvete 1") );
map.insert( "Paul", MyClass("Tvete 2") );
map.insert( "Paul", MyClass("Tvete 3") );
@@ -228,69 +210,69 @@ void tst_QMap::count()
map.insert( "Paul", MyClass("Tvete 5") );
map.insert( "Paul", MyClass("Tvete 6") );
- QCOMPARE( map.count(), 9 );
+ QCOMPARE( map.size(), 9 );
QCOMPARE( map.count("Paul"), 1 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
Map map2( map );
- QVERIFY( map2.count() == 9 );
+ QVERIFY( map2.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2.insert( "Kay", MyClass("Roemer") );
- QVERIFY( map2.count() == 10 );
- QVERIFY( map.count() == 9 );
+ QVERIFY( map2.size() == 10 );
+ QVERIFY( map.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 19 );
#endif
map2 = map;
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 9 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2.insert( "Kay", MyClass("Roemer") );
- QVERIFY( map2.count() == 10 );
+ QVERIFY( map2.size() == 10 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 19 );
#endif
map2.clear();
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2 = map;
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 9 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 9 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map2.clear();
- QVERIFY( map.count() == 9 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 9 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 9 );
#endif
map.remove( "Lars" );
- QVERIFY( map.count() == 8 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 8 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 8 );
#endif
map.remove( "Mist" );
- QVERIFY( map.count() == 8 );
- QVERIFY( map2.count() == 0 );
+ QVERIFY( map.size() == 8 );
+ QVERIFY( map2.size() == 0 );
#ifndef Q_CC_SUN
QCOMPARE( MyClass::count, 8 );
#endif
@@ -304,22 +286,22 @@ void tst_QMap::count()
#ifndef Q_CC_SUN
QVERIFY( MyClass::count == 1 );
#endif
- QVERIFY( map.count() == 1 );
+ QVERIFY( map.size() == 1 );
(void)map["Torben"].str;
(void)map["Lars"].str;
#ifndef Q_CC_SUN
QVERIFY( MyClass::count == 2 );
#endif
- QVERIFY( map.count() == 2 );
+ QVERIFY( map.size() == 2 );
const Map& cmap = map;
(void)cmap["Depp"].str;
#ifndef Q_CC_SUN
QVERIFY( MyClass::count == 2 );
#endif
- QVERIFY( map.count() == 2 );
- QVERIFY( cmap.count() == 2 );
+ QVERIFY( map.size() == 2 );
+ QVERIFY( cmap.size() == 2 );
}
QCOMPARE( MyClass::count, 0 );
{
@@ -336,8 +318,8 @@ void tst_QMap::count()
{
QMultiMap<int, MyClass> map;
QMultiMap<int, MyClass> map2(map);
- QCOMPARE(map.count(), 0);
- QCOMPARE(map2.count(), 0);
+ QCOMPARE(map.size(), 0);
+ QCOMPARE(map2.size(), 0);
QCOMPARE(MyClass::count, 0);
QCOMPARE(map.count(1), 0);
QCOMPARE(map.size(), 0);
@@ -347,26 +329,26 @@ void tst_QMap::count()
// detach
map2.insert(0, MyClass("value0"));
- QCOMPARE(map.count(), 0);
QCOMPARE(map.size(), 0);
- QCOMPARE(map2.count(), 1);
+ QCOMPARE(map.size(), 0);
+ QCOMPARE(map2.size(), 1);
QCOMPARE(map2.size(), 1);
QVERIFY(!map.isDetached());
QCOMPARE(MyClass::count, 1);
map2.insert(1, MyClass("value1"));
map2.insert(2, MyClass("value2"));
- QCOMPARE(map2.count(), 3);
+ QCOMPARE(map2.size(), 3);
QCOMPARE(MyClass::count, 3);
map2.insert(0, MyClass("value0_1"));
map2.insert(0, MyClass("value0_2"));
- QCOMPARE(map2.count(), 5);
+ QCOMPARE(map2.size(), 5);
QCOMPARE(map2.count(0), 3);
QCOMPARE(MyClass::count, 5);
map2.clear();
- QCOMPARE(map2.count(), 0);
+ QCOMPARE(map2.size(), 0);
QCOMPARE(MyClass::count, 0);
}
@@ -447,7 +429,12 @@ void tst_QMap::beginEnd()
// detach
map2.insert( "2", "c" );
QVERIFY( map.constBegin() == map.constBegin() );
- QVERIFY( map.constBegin() != map2.constBegin() );
+
+ // comparing iterators between two different std::map is UB (and raises an
+ // assertion failure with MSVC debug-mode iterators), so we compare the
+ // elements' addresses.
+ QVERIFY(&map.constBegin().key() != &map2.constBegin().key());
+ QVERIFY(&map.constBegin().value() != &map2.constBegin().value());
}
void tst_QMap::firstLast()
@@ -892,7 +879,7 @@ void tst_QMap::constFind()
for (i = 3; i < 10; ++i) {
compareString = testString.arg(i);
- map.insertMulti(4, compareString);
+ map.insert(4, compareString);
}
QMultiMap<int, QString>::const_iterator it = map.constFind(4);
@@ -998,7 +985,7 @@ void tst_QMap::lowerUpperBound()
map.insert(3, "three");
map.insert(7, "seven");
- map.insertMulti(7, "seven_2");
+ map.insert(7, "seven_2");
QCOMPARE(map.upperBound(0).key(), 1);
QCOMPARE(map.upperBound(1).key(), 3);
@@ -1129,29 +1116,6 @@ void tst_QMap::iterators()
QVERIFY(stlIt.value() == testString.arg(i));
QCOMPARE(i, 100);
- // Same but exercising deprecated APIs
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- stlIt = map.begin();
- QCOMPARE(stlIt.value(), QLatin1String("Teststring 1"));
-
- stlIt += 5;
- QCOMPARE(stlIt.value(), QLatin1String("Teststring 6"));
-
- stlIt++;
- QCOMPARE(stlIt.value(), QLatin1String("Teststring 7"));
-
- stlIt = stlIt - 3;
- QCOMPARE(stlIt.value(), QLatin1String("Teststring 4"));
-
- stlIt--;
- QCOMPARE(stlIt.value(), QLatin1String("Teststring 3"));
-
- for(stlIt = map.begin(), i = 1; stlIt != map.end(); ++stlIt, ++i)
- QVERIFY(stlIt.value() == testString.arg(i));
- QCOMPARE(i, 100);
-QT_WARNING_POP
-
//STL-Style const-iterators
QMap<int, QString>::const_iterator cstlIt = map.constBegin();
@@ -1173,29 +1137,6 @@ QT_WARNING_POP
QVERIFY(cstlIt.value() == testString.arg(i));
QCOMPARE(i, 100);
- // Same but exercising deprecated APIs
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- cstlIt = map.constBegin();
- QCOMPARE(cstlIt.value(), QLatin1String("Teststring 1"));
-
- cstlIt += 5;
- QCOMPARE(cstlIt.value(), QLatin1String("Teststring 6"));
-
- cstlIt++;
- QCOMPARE(cstlIt.value(), QLatin1String("Teststring 7"));
-
- cstlIt = cstlIt - 3;
- QCOMPARE(cstlIt.value(), QLatin1String("Teststring 4"));
-
- cstlIt--;
- QCOMPARE(cstlIt.value(), QLatin1String("Teststring 3"));
-
- for(cstlIt = map.constBegin(), i = 1; cstlIt != map.constEnd(); ++cstlIt, ++i)
- QVERIFY(cstlIt.value() == testString.arg(i));
- QCOMPARE(i, 100);
-QT_WARNING_POP
-
//Java-Style iterators
QMapIterator<int, QString> javaIt(map);
@@ -1648,26 +1589,26 @@ void tst_QMap::qmultimap_specific()
}
QVERIFY(map1.contains(9, 99));
- QCOMPARE(map1.count(), 45);
+ QCOMPARE(map1.size(), 45);
map1.remove(9, 99);
QVERIFY(!map1.contains(9, 99));
- QCOMPARE(map1.count(), 44);
+ QCOMPARE(map1.size(), 44);
map1.remove(9, 99);
QVERIFY(!map1.contains(9, 99));
- QCOMPARE(map1.count(), 44);
+ QCOMPARE(map1.size(), 44);
map1.remove(1, 99);
- QCOMPARE(map1.count(), 44);
+ QCOMPARE(map1.size(), 44);
map1.insert(1, 99);
map1.insert(1, 99);
- QCOMPARE(map1.count(), 46);
+ QCOMPARE(map1.size(), 46);
map1.remove(1, 99);
- QCOMPARE(map1.count(), 44);
+ QCOMPARE(map1.size(), 44);
map1.remove(1, 99);
- QCOMPARE(map1.count(), 44);
+ QCOMPARE(map1.size(), 44);
{
QMultiMap<int, int>::const_iterator i = map1.constFind(1, 11);
@@ -1726,7 +1667,7 @@ void tst_QMap::qmultimap_specific()
map2.insert(42, 1);
map2.insert(10, 2);
map2.insert(48, 3);
- QCOMPARE(map1.count(), map2.count());
+ QCOMPARE(map1.size(), map2.size());
QVERIFY(map1.remove(42,5));
QVERIFY(map2.remove(42,5));
QVERIFY(map1 == map2);
@@ -1848,7 +1789,7 @@ void tst_QMap::equal_range()
QCOMPARE(cresult.first, cmap.find(2));
QCOMPARE(cresult.second, cmap.find(4));
- map.insertMulti(1, "another one");
+ map.insert(1, "another one");
result = map.equal_range(1);
QCOMPARE(result.first, map.find(1));
@@ -1861,19 +1802,13 @@ void tst_QMap::equal_range()
QCOMPARE(map.count(1), 2);
}
-template <class T>
-const T &const_(const T &t)
-{
- return t;
-}
-
void tst_QMap::insert()
{
QMap<QString, float> map;
map.insert("cs/key1", 1);
map.insert("cs/key2", 2);
map.insert("cs/key1", 3);
- QCOMPARE(map.count(), 2);
+ QCOMPARE(map.size(), 2);
QMap<int, int> intMap;
for (int i = 0; i < 1000; ++i) {
@@ -1944,12 +1879,15 @@ void testDetachWhenInsert()
dest.insert(3, 3);
Map<int, int> destCopy = dest;
- dest.insert(source);
+ if constexpr (std::is_same_v<decltype(dest), QMap<int, int>>)
+ dest.insert(source); // QMap
+ else
+ dest.unite(source); // QMultiMap
QCOMPARE(source, referenceSource);
QCOMPARE(dest, referenceDestination);
- QCOMPARE(destCopy.count(), 1); // unchanged
+ QCOMPARE(destCopy.size(), 1); // unchanged
}
// copy insertion of shared map
@@ -1964,13 +1902,16 @@ void testDetachWhenInsert()
dest.insert(3, 3);
Map<int, int> destCopy = dest;
- dest.insert(source);
+ if constexpr (std::is_same_v<decltype(dest), QMap<int, int>>)
+ dest.insert(source); // QMap
+ else
+ dest.unite(source); // QMultiMap
QCOMPARE(source, referenceSource);
QCOMPARE(sourceCopy, referenceSource);
QCOMPARE(dest, referenceDestination);
- QCOMPARE(destCopy.count(), 1); // unchanged
+ QCOMPARE(destCopy.size(), 1); // unchanged
}
// move insertion of non-shared map
@@ -1984,10 +1925,13 @@ void testDetachWhenInsert()
dest.insert(3, 3);
Map<int, int> destCopy = dest;
- dest.insert(source);
+ if constexpr (std::is_same_v<decltype(dest), QMap<int, int>>)
+ dest.insert(source); // QMap
+ else
+ dest.unite(source); // QMultiMap
QCOMPARE(dest, referenceDestination);
- QCOMPARE(destCopy.count(), 1); // unchanged
+ QCOMPARE(destCopy.size(), 1); // unchanged
}
// move insertion of shared map
@@ -2002,12 +1946,15 @@ void testDetachWhenInsert()
dest.insert(3, 3);
Map<int, int> destCopy = dest;
- dest.insert(std::move(source));
+ if constexpr (std::is_same_v<decltype(dest), QMap<int, int>>)
+ dest.insert(std::move(source)); // QMap
+ else
+ dest.unite(std::move(source)); // QMultiMap
QCOMPARE(sourceCopy, referenceSource);
QCOMPARE(dest, referenceDestination);
- QCOMPARE(destCopy.count(), 1); // unchanged
+ QCOMPARE(destCopy.size(), 1); // unchanged
}
};
@@ -2038,7 +1985,7 @@ void tst_QMap::insertMap()
map.insert(map2);
- QCOMPARE(map.count(), 5);
+ QCOMPARE(map.size(), 5);
for (int i = 0; i < 5; ++i)
QCOMPARE(map[i], i);
}
@@ -2053,7 +2000,7 @@ void tst_QMap::insertMap()
map.insert(map2);
- QCOMPARE(map.count(), 17);
+ QCOMPARE(map.size(), 17);
for (int i = 0; i < 10; ++i) {
// i * 3 == i except for i = 4, 8
QCOMPARE(map[i * 3], (i && i % 4 == 0) ? i - (i / 4) : i);
@@ -2075,7 +2022,7 @@ void tst_QMap::insertMap()
QMap<int, int> map2;
map.insert(map2);
- QCOMPARE(map.count(), 1);
+ QCOMPARE(map.size(), 1);
QCOMPARE(map[1], 1);
}
{
@@ -2084,7 +2031,7 @@ void tst_QMap::insertMap()
map2.insert(1, 1);
map.insert(map2);
- QCOMPARE(map.count(), 1);
+ QCOMPARE(map.size(), 1);
QCOMPARE(map[1], 1);
QMap<int, int> map3;
@@ -2100,7 +2047,7 @@ void tst_QMap::insertMap()
// Test inserting into self, nothing should happen
map.insert(map);
- QCOMPARE(map.count(), 3);
+ QCOMPARE(map.size(), 3);
for (int i = 0; i < 3; ++i)
QCOMPARE(map[i], i);
}
@@ -2118,7 +2065,7 @@ void tst_QMap::insertMap()
map.insert(map2);
- QCOMPARE(map.count(), 1);
+ QCOMPARE(map.size(), 1);
}
testDetachWhenInsert<QMap>();
@@ -2180,7 +2127,7 @@ void tst_QMap::checkMostLeftNode()
void tst_QMap::initializerList()
{
QMap<int, QString> map = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
- QCOMPARE(map.count(), 2);
+ QCOMPARE(map.size(), 2);
QCOMPARE(map[1], QString("hello"));
QCOMPARE(map[2], QString("initializer_list"));
@@ -2190,9 +2137,9 @@ void tst_QMap::initializerList()
// QCOMPARE(stdm[1], QString("bar"));
QMultiMap<QString, int> multiMap{{"il", 1}, {"il", 2}, {"il", 3}};
- QCOMPARE(multiMap.count(), 3);
+ QCOMPARE(multiMap.size(), 3);
QList<int> values = multiMap.values("il");
- QCOMPARE(values.count(), 3);
+ QCOMPARE(values.size(), 3);
QMap<int, int> emptyMap{};
QVERIFY(emptyMap.isEmpty());
@@ -2274,48 +2221,48 @@ void tst_QMap::testInsertMultiWithHint()
{
QMultiMap<int, int> map;
- map.insertMulti(map.end(), 64, 65);
+ map.insert(map.end(), 64, 65);
map.insert(128, 129);
map.insert(256, 257);
sanityCheckTree(map, __LINE__);
- map.insertMulti(map.end(), 512, 513);
- map.insertMulti(map.end(), 512, 513 * 2);
+ map.insert(map.end(), 512, 513);
+ map.insert(map.end(), 512, 513 * 2);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 5);
- map.insertMulti(map.end(), 256, 258); // wrong hint
+ map.insert(map.end(), 256, 258); // wrong hint
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 6);
- QMultiMap<int, int>::iterator i = map.insertMulti(map.constBegin(), 256, 259); // wrong hint
+ QMultiMap<int, int>::iterator i = map.insert(map.constBegin(), 256, 259); // wrong hint
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 7);
- QMultiMap<int, int>::iterator j = map.insertMulti(map.constBegin(), 69, 66);
+ QMultiMap<int, int>::iterator j = map.insert(map.constBegin(), 69, 66);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 8);
- j = map.insertMulti(j, 68, 259);
+ j = map.insert(j, 68, 259);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 9);
- j = map.insertMulti(j, 67, 67);
+ j = map.insert(j, 67, 67);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 10);
- i = map.insertMulti(i, 256, 259);
+ i = map.insert(i, 256, 259);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 11);
- i = map.insertMulti(i, 256, 260);
+ i = map.insert(i, 256, 260);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 12);
- map.insertMulti(i, 64, 67);
+ map.insert(i, 64, 67);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 13);
- map.insertMulti(map.constBegin(), 20, 20);
+ map.insert(map.constBegin(), 20, 20);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 14);
}
@@ -2324,9 +2271,9 @@ void tst_QMap::eraseValidIteratorOnSharedMap()
{
QMultiMap<int, int> a, b;
a.insert(10, 10);
- a.insertMulti(10, 40);
- a.insertMulti(10, 25);
- a.insertMulti(10, 30);
+ a.insert(10, 40);
+ a.insert(10, 25);
+ a.insert(10, 30);
a.insert(20, 20);
QMultiMap<int, int>::iterator i = a.begin();
@@ -2351,8 +2298,8 @@ void tst_QMap::eraseValidIteratorOnSharedMap()
// Border cases
QMultiMap <QString, QString> ms1, ms2, ms3;
ms1.insert("foo", "bar");
- ms1.insertMulti("foo", "quux");
- ms1.insertMulti("foo", "bar");
+ ms1.insert("foo", "quux");
+ ms1.insert("foo", "bar");
QMultiMap <QString, QString>::iterator si = ms1.begin();
ms2 = ms1;
@@ -2601,5 +2548,72 @@ void tst_QMap::toStdMap()
toStdMapTestMethod<QMultiMap<int, QString>>(expectedMultiMap);
}
+#if QT_DEPRECATED_SINCE(6, 0)
+void tst_QMap::deprecatedInsertMulti()
+{
+ QMultiMap<int, QString> referenceMap;
+ referenceMap.insert(1, "value1");
+ referenceMap.insert(2, "value2");
+ referenceMap.insert(3, "value3");
+ referenceMap.insert(1, "value1_2");
+ referenceMap.insert(referenceMap.find(2), 2, "value2_2");
+ referenceMap.insert(referenceMap.end(), 1, "value1_3");
+
+ QMultiMap<int, QString> deprecatedMap;
+QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
+ deprecatedMap.insertMulti(1, "value1");
+ deprecatedMap.insertMulti(2, "value2");
+ deprecatedMap.insertMulti(3, "value3");
+ deprecatedMap.insertMulti(1, "value1_2");
+ deprecatedMap.insertMulti(deprecatedMap.find(2), 2, "value2_2");
+ deprecatedMap.insertMulti(deprecatedMap.end(), 1, "value1_3");
+QT_WARNING_POP
+
+ QCOMPARE(deprecatedMap, referenceMap);
+}
+
+void tst_QMap::deprecatedIteratorApis()
+{
+ QMap<int, QString> map;
+ QString testString = "Teststring %1";
+ for (int i = 1; i < 100; ++i)
+ map.insert(i, testString.arg(i));
+
+ auto it = map.begin();
+ QCOMPARE(it.value(), QLatin1String("Teststring 1"));
+ QT_IGNORE_DEPRECATIONS(it += 5;)
+ QCOMPARE(it.value(), QLatin1String("Teststring 6"));
+ QT_IGNORE_DEPRECATIONS(it = it - 3;)
+ QCOMPARE(it.value(), QLatin1String("Teststring 3"));
+
+ auto cit = map.constBegin();
+ QCOMPARE(cit.value(), QLatin1String("Teststring 1"));
+ QT_IGNORE_DEPRECATIONS(cit += 5;)
+ QCOMPARE(cit.value(), QLatin1String("Teststring 6"));
+ QT_IGNORE_DEPRECATIONS(cit = cit - 3;)
+ QCOMPARE(cit.value(), QLatin1String("Teststring 3"));
+}
+
+void tst_QMap::deprecatedInsert()
+{
+ QMultiMap<int, QString> refMap;
+ refMap.insert(1, "value1");
+ refMap.insert(2, "value2");
+ refMap.insert(3, "value3");
+
+ QMultiMap<int, QString> depMap = refMap;
+
+ QMultiMap<int, QString> otherMap;
+ otherMap.insert(1, "value1_2");
+ otherMap.insert(3, "value3_2");
+ otherMap.insert(4, "value4");
+
+ refMap.unite(otherMap);
+ QT_IGNORE_DEPRECATIONS(depMap.insert(otherMap);)
+
+ QCOMPARE(refMap, depMap);
+}
+#endif // QT_DEPRECATED_SINCE(6, 0)
+
QTEST_APPLESS_MAIN(tst_QMap)
#include "tst_qmap.moc"
diff --git a/tests/auto/corelib/tools/qmargins/CMakeLists.txt b/tests/auto/corelib/tools/qmargins/CMakeLists.txt
index aa58ce03ab..d3eea70fb8 100644
--- a/tests/auto/corelib/tools/qmargins/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmargins/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmargins.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmargins Test:
diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
index 8eaa4edd3b..4b49d152a3 100644
--- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
+++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
@@ -1,34 +1,40 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QMargins>
+#ifdef QVARIANT_H
+# error "This test requires qmargins.h to not include qvariant.h"
+#endif
+
+// don't assume <type_traits>
+template <typename T, typename U>
+constexpr inline bool my_is_same_v = false;
+template <typename T>
+constexpr inline bool my_is_same_v<T, T> = true;
+
+#define CHECK(cvref) \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QMargins cvref >())), int cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QMargins cvref >())), int cvref >); \
+ static_assert(my_is_same_v<decltype(get<2>(std::declval<QMargins cvref >())), int cvref >); \
+ static_assert(my_is_same_v<decltype(get<3>(std::declval<QMargins cvref >())), int cvref >); \
+ \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QMarginsF cvref >())), qreal cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QMarginsF cvref >())), qreal cvref >); \
+ static_assert(my_is_same_v<decltype(get<2>(std::declval<QMarginsF cvref >())), qreal cvref >); \
+ static_assert(my_is_same_v<decltype(get<3>(std::declval<QMarginsF cvref >())), qreal cvref >)
+
+CHECK(&);
+CHECK(const &);
+CHECK(&&);
+CHECK(const &&);
+
+#undef CHECK
#include <QTest>
#include <qmargins.h>
+#include <array>
+
Q_DECLARE_METATYPE(QMargins)
class tst_QMargins : public QObject
@@ -54,6 +60,9 @@ private slots:
#endif
void structuredBinding();
+
+ void toMarginsF_data();
+ void toMarginsF();
};
// Testing get/set functions
@@ -339,5 +348,34 @@ void tst_QMargins::structuredBinding()
}
}
+void tst_QMargins::toMarginsF_data()
+{
+ QTest::addColumn<QMargins>("input");
+ QTest::addColumn<QMarginsF>("result");
+
+ auto row = [](int x1, int y1, int x2, int y2) {
+ QTest::addRow("(%d, %d, %d, %d)", x1, y1, x2, y2)
+ << QMargins(x1, y1, x2, y2) << QMarginsF(x1, y1, x2, y2);
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int x1 : samples) {
+ for (int y1 : samples) {
+ for (int x2 : samples) {
+ for (int y2 : samples) {
+ row(x1, y1, x2, y2);
+ }
+ }
+ }
+ }
+}
+
+void tst_QMargins::toMarginsF()
+{
+ QFETCH(const QMargins, input);
+ QFETCH(const QMarginsF, result);
+
+ QCOMPARE(input.toMarginsF(), result);
+}
+
QTEST_APPLESS_MAIN(tst_QMargins)
#include "tst_qmargins.moc"
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt b/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt
index dcc86fe555..a898453671 100644
--- a/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmessageauthenticationcode.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmessageauthenticationcode Test:
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
index 3c8f8e13d1..c49cd538d2 100644
--- a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
-** 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) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtCore/QCoreApplication>
@@ -37,16 +12,64 @@ class tst_QMessageAuthenticationCode : public QObject
{
Q_OBJECT
private slots:
+ void repeated_setKey_data();
+ void repeated_setKey();
void result_data();
void result();
void result_incremental_data();
void result_incremental();
void addData_overloads_data();
void addData_overloads();
+ void move();
+ void swap();
};
Q_DECLARE_METATYPE(QCryptographicHash::Algorithm)
+void tst_QMessageAuthenticationCode::repeated_setKey_data()
+{
+ using A = QCryptographicHash::Algorithm;
+ QTest::addColumn<A>("algo");
+
+ const auto me = QMetaEnum::fromType<A>();
+ for (int i = 0, value; (value = me.value(i)) != -1; ++i)
+ QTest::addRow("%s", me.key(i)) << A(value);
+}
+
+void tst_QMessageAuthenticationCode::repeated_setKey()
+{
+ QFETCH(const QCryptographicHash::Algorithm, algo);
+
+ if (!QCryptographicHash::supportsAlgorithm(algo))
+ QSKIP("QCryptographicHash doesn't support this algorithm");
+
+ // GIVEN: two long keys, so we're sure the key needs to be hashed in order
+ // to fit into the hash algorithm's block
+
+ static const QByteArray key1(1024, 'a');
+ static const QByteArray key2(2048, 'b');
+
+ // WHEN: processing the same message
+
+ QMessageAuthenticationCode macX(algo);
+ QMessageAuthenticationCode mac1(algo, key1);
+ QMessageAuthenticationCode mac2(algo, key2);
+
+ const auto check = [](QMessageAuthenticationCode &mac) {
+ mac.addData("This is nonsense, ignore it, please.");
+ return mac.result();
+ };
+
+ macX.setKey(key1);
+ QCOMPARE(check(macX), check(mac1));
+
+ // THEN: the result does not depend on whether a new QMAC instance was used
+ // or an old one re-used (iow: setKey() reset()s)
+
+ macX.setKey(key2);
+ QCOMPARE(check(macX), check(mac2));
+}
+
void tst_QMessageAuthenticationCode::result_data()
{
QTest::addColumn<QCryptographicHash::Algorithm>("algo");
@@ -124,14 +147,13 @@ void tst_QMessageAuthenticationCode::result()
QFETCH(QByteArray, message);
QFETCH(QByteArray, code);
- QMessageAuthenticationCode mac(algo);
- mac.setKey(key);
+ QMessageAuthenticationCode mac(algo, key);
mac.addData(message);
- QByteArray result = mac.result();
+ QByteArrayView resultView = mac.resultView();
- QCOMPARE(result, code);
+ QCOMPARE(resultView, code);
- result = QMessageAuthenticationCode::hash(message, key, algo);
+ const auto result = QMessageAuthenticationCode::hash(message, key, algo);
QCOMPARE(result, code);
}
@@ -147,17 +169,16 @@ void tst_QMessageAuthenticationCode::result_incremental()
QFETCH(QByteArray, message);
QFETCH(QByteArray, code);
- int index = message.length() / 2;
+ int index = message.size() / 2;
QByteArray leftPart(message.mid(0, index));
QByteArray rightPart(message.mid(index));
QCOMPARE(leftPart + rightPart, message);
- QMessageAuthenticationCode mac(algo);
- mac.setKey(key);
+ QMessageAuthenticationCode mac(algo, key);
mac.addData(leftPart);
mac.addData(rightPart);
- QByteArray result = mac.result();
+ QByteArrayView result = mac.resultView();
QCOMPARE(result, code);
}
@@ -179,7 +200,7 @@ void tst_QMessageAuthenticationCode::addData_overloads()
QMessageAuthenticationCode mac(algo);
mac.setKey(key);
mac.addData(message.constData(), message.size());
- QByteArray result = mac.result();
+ QByteArrayView result = mac.resultView();
QCOMPARE(result, code);
}
@@ -191,12 +212,55 @@ void tst_QMessageAuthenticationCode::addData_overloads()
QMessageAuthenticationCode mac(algo);
mac.setKey(key);
QVERIFY(mac.addData(&buffer));
- QByteArray result = mac.result();
+ QByteArrayView result = mac.resultView();
buffer.close();
QCOMPARE(result, code);
}
}
+void tst_QMessageAuthenticationCode::move()
+{
+ const QByteArray key = "123";
+
+ QMessageAuthenticationCode src(QCryptographicHash::Sha1, key);
+ src.addData("a");
+
+ // move constructor
+ auto intermediary = std::move(src);
+ intermediary.addData("b");
+
+ // move assign operator
+ QMessageAuthenticationCode dst(QCryptographicHash::Sha256, key);
+ dst.addData("no effect on the end result");
+ dst = std::move(intermediary);
+ dst.addData("c");
+
+ QCOMPARE(dst.resultView(),
+ QMessageAuthenticationCode::hash("abc", key, QCryptographicHash::Sha1));
+}
+
+void tst_QMessageAuthenticationCode::swap()
+{
+ const QByteArray key1 = "123";
+ const QByteArray key2 = "abcdefg";
+
+ QMessageAuthenticationCode mac1(QCryptographicHash::Sha1, key1);
+ QMessageAuthenticationCode mac2(QCryptographicHash::Sha256, key2);
+
+ mac1.addData("da");
+ mac2.addData("te");
+
+ mac1.swap(mac2);
+
+ mac2.addData("ta");
+ mac1.addData("st");
+
+ QCOMPARE(mac2.resultView(),
+ QMessageAuthenticationCode::hash("data", key1, QCryptographicHash::Sha1));
+ QCOMPARE(mac1.resultView(),
+ QMessageAuthenticationCode::hash("test", key2, QCryptographicHash::Sha256));
+}
+
QTEST_MAIN(tst_QMessageAuthenticationCode)
#include "tst_qmessageauthenticationcode.moc"
diff --git a/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt b/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt
index 67dffe0284..9c56f0208d 100644
--- a/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qoffsetstringarray.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qoffsetstringarray Test:
@@ -7,7 +8,7 @@
qt_internal_add_test(tst_qoffsetstringarray
SOURCES
tst_qoffsetstringarray.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp
index 0130939b4e..669f14cc92 100644
--- a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp
+++ b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
@@ -38,6 +13,7 @@ class tst_QOffsetStringArray : public QObject
private slots:
void init();
void access();
+ void contains();
};
@@ -46,8 +22,7 @@ constexpr const auto messages = qOffsetStringArray(
"level - 1",
"level - 2",
"level - 3",
- "level - 4",
- ""
+ "level - 4"
);
constexpr const auto messages257 = qOffsetStringArray(
@@ -90,15 +65,15 @@ constexpr const auto messagesBigOffsets = qOffsetStringArray(
void tst_QOffsetStringArray::init()
{
- static_assert(messages.m_string.size() == 51);
+ static_assert(messages.m_string.size() == 50);
static_assert(messages.m_offsets.size() == 6);
static_assert(std::is_same_v<decltype(messages.m_offsets)::value_type, quint8>);
- static_assert(messages257.m_offsets.size() == 257);
+ static_assert(messages257.m_offsets.size() == 258);
static_assert(messages257.m_string.size() == 260);
static_assert(std::is_same_v<decltype(messages257.m_offsets)::value_type, quint16>);
- static_assert(messagesBigOffsets.m_offsets.size() == 4);
+ static_assert(messagesBigOffsets.m_offsets.size() == 5);
static_assert(messagesBigOffsets.m_string.size() == 364);
static_assert(std::is_same_v<decltype(messagesBigOffsets.m_offsets)::value_type, quint16>);
}
@@ -110,10 +85,21 @@ void tst_QOffsetStringArray::access()
QCOMPARE(messages[2], "level - 2");
QCOMPARE(messages[3], "level - 3");
QCOMPARE(messages[4], "level - 4");
+ // out of bounds returns empty strings:
QCOMPARE(messages[5], "");
QCOMPARE(messages[6], "");
}
+void tst_QOffsetStringArray::contains()
+{
+ QVERIFY(!messages.contains(""));
+ QVERIFY( messages.contains("level - 0"));
+ std::string l2 = "level - 2"; // make sure we don't compare pointer values
+ QVERIFY( messages.contains(l2));
+ QByteArray L4 = "Level - 4";
+ QVERIFY( messages.contains(L4, Qt::CaseInsensitive));
+ QVERIFY(!messages.contains(L4, Qt::CaseSensitive));
+}
QTEST_APPLESS_MAIN(tst_QOffsetStringArray)
#include "tst_qoffsetstringarray.moc"
diff --git a/tests/auto/corelib/tools/qpair/CMakeLists.txt b/tests/auto/corelib/tools/qpair/CMakeLists.txt
index 3d0ba82e44..b72ebd31e3 100644
--- a/tests/auto/corelib/tools/qpair/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qpair/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qpair.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpair Test:
diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp
index 3bdc7f8895..d3a706995f 100644
--- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp
+++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
-** 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) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
@@ -90,7 +65,7 @@ static_assert( QTypeInfo<QPairPM>::isRelocatable );
static_assert(!QTypeInfo<QPairPP>::isComplex);
static_assert( QTypeInfo<QPairPP>::isRelocatable );
-static_assert(!QTypeInfo<QPairPP>::isPointer);
+static_assert(!std::is_pointer_v<QPairPP>);
void tst_QPair::pairOfReferences()
diff --git a/tests/auto/corelib/tools/qpoint/CMakeLists.txt b/tests/auto/corelib/tools/qpoint/CMakeLists.txt
index ddc0733231..a385948f43 100644
--- a/tests/auto/corelib/tools/qpoint/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qpoint/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qpoint.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpoint Test:
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
index 3ce8c3942d..76a4ccc086 100644
--- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
+++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
@@ -1,36 +1,35 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QPoint>
+#ifdef QVARIANT_H
+# error "This test requires qpoint.h to not include qvariant.h"
+#endif
+
+// don't assume <type_traits>
+template <typename T, typename U>
+constexpr inline bool my_is_same_v = false;
+template <typename T>
+constexpr inline bool my_is_same_v<T, T> = true;
+
+#define CHECK(cvref) \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QPoint cvref >())), int cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QPoint cvref >())), int cvref >)
+
+CHECK(&);
+CHECK(const &);
+CHECK(&&);
+CHECK(const &&);
+
+#undef CHECK
#include <QTest>
#include <QBuffer>
#include <qpoint.h>
+#include <array>
+
class tst_QPoint : public QObject
{
Q_OBJECT
@@ -45,6 +44,9 @@ private slots:
void transposed();
+ void toPointF_data();
+ void toPointF();
+
void rx();
void ry();
@@ -131,6 +133,30 @@ void tst_QPoint::getSet()
QCOMPARE(point.y(), i);
}
+void tst_QPoint::toPointF_data()
+{
+ QTest::addColumn<QPoint>("input");
+ QTest::addColumn<QPointF>("result");
+
+ auto row = [](int x, int y) {
+ QTest::addRow("(%d, %d)", x, y) << QPoint(x, y) << QPointF(x, y);
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int x : samples) {
+ for (int y : samples) {
+ row(x, y);
+ }
+ }
+}
+
+void tst_QPoint::toPointF()
+{
+ QFETCH(const QPoint, input);
+ QFETCH(const QPointF, result);
+
+ QCOMPARE(input.toPointF(), result);
+}
+
void tst_QPoint::transposed()
{
QCOMPARE(QPoint(1, 2).transposed(), QPoint(2, 1));
diff --git a/tests/auto/corelib/tools/qpointf/CMakeLists.txt b/tests/auto/corelib/tools/qpointf/CMakeLists.txt
index 09f725f8e6..e30a343fad 100644
--- a/tests/auto/corelib/tools/qpointf/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qpointf/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qpointf.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpointf Test:
diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
index 645c1ba210..14953039a1 100644
--- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
+++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
@@ -1,30 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QPointF>
+#ifdef QVARIANT_H
+# error "This test requires qpoint.h to not include qvariant.h"
+#endif
+
+// don't assume <type_traits>
+template <typename T, typename U>
+constexpr inline bool my_is_same_v = false;
+template <typename T>
+constexpr inline bool my_is_same_v<T, T> = true;
+
+#define CHECK(cvref) \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QPointF cvref >())), qreal cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QPointF cvref >())), qreal cvref >)
+
+CHECK(&);
+CHECK(const &);
+CHECK(&&);
+CHECK(const &&);
+
+#undef CHECK
#include <QTest>
#include <QBuffer>
diff --git a/tests/auto/corelib/tools/qqueue/CMakeLists.txt b/tests/auto/corelib/tools/qqueue/CMakeLists.txt
index c3528163eb..943cef51a3 100644
--- a/tests/auto/corelib/tools/qqueue/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qqueue/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qqueue.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qqueue Test:
diff --git a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
index 959927cab8..ed66806f96 100644
--- a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
+++ b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
diff --git a/tests/auto/corelib/tools/qrect/CMakeLists.txt b/tests/auto/corelib/tools/qrect/CMakeLists.txt
index d48bec0c7d..0f8eef67bb 100644
--- a/tests/auto/corelib/tools/qrect/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qrect/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qrect.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qrect Test:
diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
index 4057eb67fb..d37a5c52b0 100644
--- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp
+++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <qrect.h>
@@ -32,6 +7,7 @@
#include <limits.h>
#include <qdebug.h>
+#include <array>
class tst_QRect : public QObject
{
@@ -124,6 +100,9 @@ private slots:
void margins();
void marginsf();
+ void toRectF_data();
+ void toRectF();
+
void translate_data();
void translate();
@@ -2526,16 +2505,11 @@ void tst_QRect::newMoveLeft_data()
{
// QTest::newRow( "LargestCoordQRect_MinimumInt" ) -- Not tested as it would cause an overflow
- QTest::newRow( "LargestCoordQRect_MiddleNegativeInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( MiddleNegativeInt )
- << QRect( QPoint( INT_MIN/2, INT_MIN ), QPoint(INT_MIN/2-1, INT_MAX ) );
- QTest::newRow( "LargestCoordQRect_ZeroInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( ZeroInt )
- << QRect( QPoint( 0, INT_MIN ), QPoint(-1, INT_MAX ) );
- QTest::newRow( "LargestCoordQRect_MiddlePositiveInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( MiddlePositiveInt )
- << QRect( QPoint( INT_MAX/2, INT_MIN ), QPoint(INT_MAX/2-1, INT_MAX ) );
- QTest::newRow( "LargestCoordQRect_MaximumInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( MaximumInt )
- << QRect( QPoint( INT_MAX, INT_MIN ), QPoint(INT_MAX-1, INT_MAX ) );
- QTest::newRow( "LargestCoordQRect_RandomInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( RandomInt )
- << QRect( QPoint( 4953, INT_MIN ), QPoint(4952, INT_MAX ) );
+ // QTest::newRow( "LargestCoordQRect_MiddleNegativeInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_ZeroInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_MiddlePositiveInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_MaximumInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_RandomInt" ) -- Not tested as it would cause an overflow
}
{
@@ -2695,16 +2669,11 @@ void tst_QRect::newMoveTop_data()
{
// QTest::newRow( "LargestCoordQRect_MinimumInt" ) -- Not tested as it would cause an overflow
- QTest::newRow( "LargestCoordQRect_MiddleNegativeInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( MiddleNegativeInt )
- << QRect( QPoint(INT_MIN,INT_MIN/2), QPoint(INT_MAX,INT_MIN/2-1) );
- QTest::newRow( "LargestCoordQRect_ZeroInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( ZeroInt )
- << QRect( QPoint(INT_MIN,0), QPoint(INT_MAX,-1) );
- QTest::newRow( "LargestCoordQRect_MiddlePositiveInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( MiddlePositiveInt )
- << QRect( QPoint(INT_MIN,INT_MAX/2), QPoint(INT_MAX,INT_MAX/2-1) );
- QTest::newRow( "LargestCoordQRect_MaximumInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( MaximumInt )
- << QRect( QPoint(INT_MIN,INT_MAX), QPoint(INT_MAX,INT_MAX-1) );
- QTest::newRow( "LargestCoordQRect_RandomInt" ) << getQRectCase( LargestCoordQRect ) << getIntCase( RandomInt )
- << QRect( QPoint(INT_MIN,4953), QPoint(INT_MAX,4952) );
+ // QTest::newRow( "LargestCoordQRect_MiddleNegativeInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_ZeroInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_MiddlePositiveInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_MaximumInt" ) -- Not tested as it would cause an overflow
+ // QTest::newRow( "LargestCoordQRect_RandomInt" ) -- Not tested as it would cause an overflow
}
{
@@ -3536,6 +3505,39 @@ void tst_QRect::marginsf()
QCOMPARE(a, rectangle.marginsRemoved(margins));
}
+void tst_QRect::toRectF_data()
+{
+ QTest::addColumn<QRect>("input");
+ QTest::addColumn<QRectF>("result");
+
+ auto row = [](int x1, int y1, int w, int h) {
+ // QRectF -> QRect conversion tries to maintain size(), not bottomRight(),
+ // so compare in (topLeft(), size()) space
+ QTest::addRow("((%d, %d) (%dx%d))", x1, y1, w, h)
+ << QRect({x1, y1}, QSize{w, h}) << QRectF(QPointF(x1, y1), QSizeF(w, h));
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int x1 : samples) {
+ for (int y1 : samples) {
+ for (int w : samples) {
+ for (int h : samples) {
+ row(x1, y1, w, h);
+ }
+ }
+ }
+ }
+}
+
+void tst_QRect::toRectF()
+{
+ QFETCH(const QRect, input);
+ QFETCH(const QRectF, result);
+
+ QCOMPARE(result.toRect(), input); // consistency check
+ QCOMPARE(input.toRectF(), result);
+}
+
+
void tst_QRect::translate_data()
{
QTest::addColumn<QRect>("r");
@@ -4313,8 +4315,6 @@ void tst_QRect::containsPointF_data()
QTest::addColumn<QPointF>("point");
QTest::addColumn<bool>("contains");
- QTest::newRow("test 27") << QRectF() << QPointF() << false;
-
QTest::newRow("test 01") << QRectF(0, 0, 10, 10) << QPointF( 0, 0) << true;
QTest::newRow("test 02") << QRectF(0, 0, 10, 10) << QPointF( 0, 10) << true;
QTest::newRow("test 03") << QRectF(0, 0, 10, 10) << QPointF(10, 0) << true;
diff --git a/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt b/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt
index d5d633c0bd..e29ab7ddaa 100644
--- a/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qringbuffer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qringbuffer Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qringbuffer
SOURCES
tst_qringbuffer.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index 3b922de0ca..dec6319159 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -1,33 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QBuffer>
+#include <QVarLengthArray>
#include <private/qringbuffer_p.h>
#include <qlist.h>
@@ -38,6 +14,7 @@ class tst_QRingBuffer : public QObject
private slots:
void constructing();
void usingInVector();
+ void usingInVarLengthArray();
void readPointerAtPositionWriteRead();
void readPointerAtPositionEmptyRead();
void readPointerAtPositionWithHead();
@@ -83,10 +60,20 @@ void tst_QRingBuffer::constructing()
void tst_QRingBuffer::usingInVector()
{
QRingBuffer ringBuffer;
- QList<QRingBuffer> buffers;
+ std::vector<QRingBuffer> buffers;
ringBuffer.reserve(5);
- buffers.append(ringBuffer);
+ buffers.push_back(std::move(ringBuffer));
+ QCOMPARE(buffers[0].size(), Q_INT64_C(5));
+}
+
+void tst_QRingBuffer::usingInVarLengthArray()
+{
+ QRingBuffer ringBuffer;
+ QVarLengthArray<QRingBuffer, 42> buffers;
+
+ ringBuffer.reserve(5);
+ buffers.push_back(std::move(ringBuffer));
QCOMPARE(buffers[0].size(), Q_INT64_C(5));
}
diff --git a/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt
index df2d2aa509..f396cfe0e3 100644
--- a/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qscopedpointer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qscopedpointer Test:
diff --git a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
index 967a3ccf55..367cfb5b5d 100644
--- a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
+++ b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/QScopedPointer>
@@ -61,6 +36,11 @@ private Q_SLOTS:
void comparison();
void array();
// TODO instanciate on const object
+
+ // Tests for deprecated APIs
+#if QT_DEPRECATED_SINCE(6, 1)
+ void deprecatedTake();
+#endif // QT_DEPRECATED_SINCE(6, 1)
};
void tst_QScopedPointer::defaultConstructor()
@@ -367,51 +347,57 @@ void scopedPointerComparisonTest(const A1 &a1, const A2 &a2, const B &b)
QVERIFY(a2 != b);
}
+// tst_QScopedPointer::comparison creates two QScopedPointers referring to the
+// same memory. This will lead to double-deletion error during cleanup if we
+// use a default QScopedPointer{Array}Deleter. This DummyDeleter does nothing,
+// so we can safely reference the same memory from multiple QScopedPointer
+// instances, and manage the memory manually.
+// That is fine for the comparison() test, because its goal is to check the
+// object's (in)equality, not the memory management
+struct DummyDeleter
+{
+ static inline void cleanup(RefCounted *) noexcept {}
+ void operator()(RefCounted *pointer) const noexcept
+ {
+ cleanup(pointer);
+ }
+};
+
void tst_QScopedPointer::comparison()
{
QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 0 );
{
- RefCounted *a = new RefCounted;
- RefCounted *b = new RefCounted;
+ auto a = std::make_unique<RefCounted>();
+ auto b = std::make_unique<RefCounted>();
QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 );
- QScopedPointer<RefCounted> pa1(a);
- QScopedPointer<RefCounted> pa2(a);
- QScopedPointer<RefCounted> pb(b);
+ QScopedPointer<RefCounted, DummyDeleter> pa1(a.get());
+ QScopedPointer<RefCounted, DummyDeleter> pa2(a.get());
+ QScopedPointer<RefCounted, DummyDeleter> pb(b.get());
scopedPointerComparisonTest(pa1, pa1, pb);
scopedPointerComparisonTest(pa2, pa2, pb);
scopedPointerComparisonTest(pa1, pa2, pb);
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- pa2.take();
-QT_WARNING_POP
-
QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 );
}
QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 0 );
{
- RefCounted *a = new RefCounted[42];
- RefCounted *b = new RefCounted[43];
+ auto a = std::make_unique<RefCounted[]>(42);
+ auto b = std::make_unique<RefCounted[]>(43);
QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 85 );
- QScopedArrayPointer<RefCounted> pa1(a);
- QScopedArrayPointer<RefCounted> pa2(a);
- QScopedArrayPointer<RefCounted> pb(b);
+ QScopedArrayPointer<RefCounted, DummyDeleter> pa1(a.get());
+ QScopedArrayPointer<RefCounted, DummyDeleter> pa2(a.get());
+ QScopedArrayPointer<RefCounted, DummyDeleter> pb(b.get());
scopedPointerComparisonTest(pa1, pa2, pb);
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- pa2.take();
-QT_WARNING_POP
-
QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 85 );
}
@@ -459,6 +445,23 @@ void tst_QScopedPointer::array()
QCOMPARE(instCount, RefCounted::instanceCount.loadRelaxed());
}
+#if QT_DEPRECATED_SINCE(6, 1)
+void tst_QScopedPointer::deprecatedTake()
+{
+ RefCounted *a = new RefCounted;
+
+ QScopedPointer<RefCounted> pa1(a);
+ QScopedPointer<RefCounted> pa2(a);
+
+ QCOMPARE(RefCounted::instanceCount.loadRelaxed(), 1);
+
+ QT_IGNORE_DEPRECATIONS(pa2.take();)
+
+ // check that pa2 holds nullptr, but the memory was not released
+ QVERIFY(pa2.isNull());
+ QCOMPARE(RefCounted::instanceCount.loadRelaxed(), 1);
+}
+#endif // QT_DEPRECATED_SINCE(6, 1)
QTEST_MAIN(tst_QScopedPointer)
#include "tst_qscopedpointer.moc"
diff --git a/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt b/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt
index fa3e3e3024..b268181bac 100644
--- a/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qscopedvaluerollback.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qscopedvaluerollback Test:
diff --git a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
index a05cf7ef33..ad36504ff6 100644
--- a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
+++ b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/QScopedValueRollback>
diff --git a/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt b/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt
index d21df799ea..050786cb41 100644
--- a/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qscopeguard.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qscopeguard Test:
diff --git a/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
index 90b3557ef5..015cbcc0e7 100644
--- a/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
+++ b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sérgio Martins <sergio.martins@kdab.com>
-** 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) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sérgio Martins <sergio.martins@kdab.com>
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/QScopeGuard>
diff --git a/tests/auto/corelib/tools/qset/CMakeLists.txt b/tests/auto/corelib/tools/qset/CMakeLists.txt
index ed92c1e036..fdaa020528 100644
--- a/tests/auto/corelib/tools/qset/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qset/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qset.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qset Test:
@@ -7,9 +8,6 @@
qt_internal_add_test(tst_qset
SOURCES
tst_qset.cpp
- #DEFINES # special case remove
- #-QT_NO_JAVA_STYLE_ITERATORS # special case remove
)
-## Scopes:
-#####################################################################
+qt_internal_undefine_global_definition(tst_qset QT_NO_JAVA_STYLE_ITERATORS)
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index 421657dc27..391e00485c 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <qset.h>
@@ -33,7 +8,7 @@
int toNumber(const QString &str)
{
int res = 0;
- for (int i = 0; i < str.length(); ++i)
+ for (int i = 0; i < str.size(); ++i)
res = (res * 10) + str[i].digitValue();
return res;
}
@@ -164,44 +139,44 @@ void tst_QSet::size()
QSet<int> set;
QVERIFY(set.size() == 0);
QVERIFY(set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
QVERIFY(!set.isDetached());
set.insert(1);
QVERIFY(set.size() == 1);
QVERIFY(!set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
set.insert(1);
QVERIFY(set.size() == 1);
QVERIFY(!set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
set.insert(2);
QVERIFY(set.size() == 2);
QVERIFY(!set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
set.remove(1);
QVERIFY(set.size() == 1);
QVERIFY(!set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
set.remove(1);
QVERIFY(set.size() == 1);
QVERIFY(!set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
set.remove(2);
QVERIFY(set.size() == 0);
QVERIFY(set.isEmpty());
- QVERIFY(set.count() == set.size());
+ QVERIFY(set.size() == set.size());
QVERIFY(set.isEmpty() == set.empty());
}
@@ -257,27 +232,39 @@ void tst_QSet::squeeze()
set.squeeze();
QVERIFY(set.capacity() < 100);
- for (int i = 0; i < 512; ++i)
+ for (int i = 0; i < 500; ++i)
set.insert(i);
- QVERIFY(set.capacity() == 512);
+ QCOMPARE(set.size(), 500);
+
+ // squeezed capacity for 500 elements
+ qsizetype capacity = set.capacity(); // current implementation: 512
+ QCOMPARE_GE(capacity, set.size());
set.reserve(50000);
- QVERIFY(set.capacity() >= 50000);
+ QVERIFY(set.capacity() >= 50000); // current implementation: 65536
set.squeeze();
- QVERIFY(set.capacity() == 512);
+ QCOMPARE(set.capacity(), capacity);
+ // removing elements does not shed capacity
set.remove(499);
- QVERIFY(set.capacity() == 512);
+ QCOMPARE(set.capacity(), capacity);
set.insert(499);
- QVERIFY(set.capacity() == 512);
+ QCOMPARE(set.capacity(), capacity);
- set.insert(1000);
- QVERIFY(set.capacity() == 1024);
+ // grow it beyond the current capacity
+ for (int i = set.size(); i <= capacity; ++i)
+ set.insert(i);
+ QCOMPARE(set.size(), capacity + 1);
+ QCOMPARE_GT(set.capacity(), capacity + 1);// current implementation: 2 * capacity (1024)
for (int i = 0; i < 500; ++i)
set.remove(i);
+
+ // removing elements does not shed capacity
+ QCOMPARE_GT(set.capacity(), capacity + 1);
+
set.squeeze();
QVERIFY(set.capacity() < 100);
}
@@ -1036,7 +1023,7 @@ void tst_QSet::makeSureTheComfortFunctionsCompile()
void tst_QSet::initializerList()
{
QSet<int> set = {1, 1, 2, 3, 4, 5};
- QCOMPARE(set.count(), 5);
+ QCOMPARE(set.size(), 5);
QVERIFY(set.contains(1));
QVERIFY(set.contains(2));
QVERIFY(set.contains(3));
@@ -1045,7 +1032,7 @@ void tst_QSet::initializerList()
// check _which_ of the equal elements gets inserted (in the QHash/QMap case, it's the last):
const QSet<IdentityTracker> set2 = {{1, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
- QCOMPARE(set2.count(), 5);
+ QCOMPARE(set2.size(), 5);
const int dummy = -1;
const IdentityTracker searchKey = {1, dummy};
QCOMPARE(set2.find(searchKey)->id, 0);
@@ -1064,23 +1051,33 @@ void tst_QSet::qhash()
//
{
// create some deterministic initial state:
- qSetGlobalQHashSeed(0);
+ QHashSeed::setDeterministicGlobalSeed();
QSet<int> s1;
s1.reserve(4);
s1 << 400 << 300 << 200 << 100;
- // also change the seed:
- qSetGlobalQHashSeed(0x10101010);
+ int retries = 128;
+ while (--retries >= 0) {
+ // reset the global seed to something different
+ QHashSeed::resetRandomGlobalSeed();
- QSet<int> s2;
- s2.reserve(100); // provoke different bucket counts
- s2 << 100 << 200 << 300 << 400; // and insert elements in different order, too
+ QSet<int> s2;
+ s2.reserve(100); // provoke different bucket counts
+ s2 << 100 << 200 << 300 << 400; // and insert elements in different order, too
+ QVERIFY(s1.capacity() != s2.capacity());
- QVERIFY(s1.capacity() != s2.capacity());
- QCOMPARE(s1, s2);
- QVERIFY(!std::equal(s1.cbegin(), s1.cend(), s2.cbegin())); // verify that the order _is_ different
- QCOMPARE(qHash(s1), qHash(s2));
+ // see if we got a _different_ order
+ if (std::equal(s1.cbegin(), s1.cend(), s2.cbegin()))
+ continue;
+
+ // check if the two QHashes still compare equal and produce the
+ // same hash, despite containing elements in different orders
+ QCOMPARE(s1, s2);
+ QCOMPARE(qHash(s1), qHash(s2));
+ }
+ QVERIFY2(retries != 0, "Could not find a QSet with a different order of elements even "
+ "after a lot of retries. This is unlikely, but possible.");
}
//
@@ -1112,7 +1109,7 @@ void tst_QSet::intersects()
s1 << 200;
QVERIFY(s1.intersects(s2));
- qSetGlobalQHashSeed(0x10101010);
+ QHashSeed::resetRandomGlobalSeed();
QSet<int> s3;
s3 << 500;
QVERIFY(!s1.intersects(s3));
diff --git a/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt
index d29f203bf9..518512560c 100644
--- a/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#####################################################################
## tst_qsharedpointer Test:
#####################################################################
@@ -8,6 +11,6 @@ qt_internal_add_test(tst_qsharedpointer
nontracked.cpp
wrapper.cpp
tst_qsharedpointer.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
index 37a24b6b9b..e35ac98a35 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "externaltests.h"
@@ -80,7 +55,7 @@ namespace QTest {
{
if (process.state() == QProcess::Running) {
process.terminate();
- QThread::msleep(20);
+ QThread::sleep(std::chrono::milliseconds{20});
if (process.state() == QProcess::Running)
process.kill();
}
@@ -362,7 +337,7 @@ namespace QTest {
"}\n"
"\n"
"#ifdef Q_OS_WIN\n"
- "#include <windows.h>\n"
+ "#include <qt_windows.h>\n"
"#if defined(Q_CC_MSVC)\n"
"#include <crtdbg.h>\n"
"#endif\n"
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.h b/tests/auto/corelib/tools/qsharedpointer/externaltests.h
index bae6adaefe..0d290ef3c7 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.h
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef QTEST_EXTERNAL_TESTS_H
diff --git a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp
index df343b5ebc..d8a5b3125b 100644
--- a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** 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) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "forwarddeclared.h"
#include "qsharedpointer.h"
diff --git a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h
index c72324841c..90811a9074 100644
--- a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h
+++ b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** 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) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef FORWARDDECLARED_H
#define FORWARDDECLARED_H
diff --git a/tests/auto/corelib/tools/qsharedpointer/nontracked.cpp b/tests/auto/corelib/tools/qsharedpointer/nontracked.cpp
index fa52c4f6c5..7d31897db7 100644
--- a/tests/auto/corelib/tools/qsharedpointer/nontracked.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/nontracked.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Intel Corporation.
-** 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) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
/*
* This file exists because tst_qsharedpointer.cpp is compiled with
diff --git a/tests/auto/corelib/tools/qsharedpointer/nontracked.h b/tests/auto/corelib/tools/qsharedpointer/nontracked.h
index 76af80d2d7..7562de43e6 100644
--- a/tests/auto/corelib/tools/qsharedpointer/nontracked.h
+++ b/tests/auto/corelib/tools/qsharedpointer/nontracked.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Intel Corporation.
-** 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) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef NONTRACKED_H
#define NONTRACKED_H
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index bd84d0bb3c..4b1354dc41 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Copyright (C) 2020 Intel Corporation.
-** Copyright (C) 2019 Klarälvdalens Datakonsult AB.
-** 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.
+// Copyright (C) 2022 Intel Corporation.
+// Copyright (C) 2021 Klarälvdalens Datakonsult AB.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#define QT_SHAREDPOINTER_TRACK_POINTERS
#include "qsharedpointer.h"
@@ -795,9 +770,14 @@ public:
void tst_QSharedPointer::downCast()
{
{
+ // copy construction
QSharedPointer<DerivedData> ptr = QSharedPointer<DerivedData>(new DerivedData);
+ QSharedPointer<DerivedData> copy = ptr;
QSharedPointer<Data> baseptr = qSharedPointerCast<Data>(ptr);
QSharedPointer<Data> other;
+ QWeakPointer<DerivedData> weak = ptr;
+ QWeakPointer<Data> baseweak = qSharedPointerCast<Data>(ptr);
+ QWeakPointer<Data> baseweak2 = qSharedPointerCast<Data>(weak);
QVERIFY(ptr == baseptr);
QVERIFY(baseptr == ptr);
@@ -808,11 +788,55 @@ void tst_QSharedPointer::downCast()
QVERIFY(other != ptr);
QVERIFY(! (ptr == other));
QVERIFY(! (other == ptr));
+
+ // copy assignments
+ baseptr = qSharedPointerCast<Data>(ptr);
+ baseweak = qSharedPointerCast<Data>(ptr);
+ baseweak2 = baseweak;
+
+ // move assignments (these don't actually move)
+ baseptr = qSharedPointerCast<Data>(std::move(ptr));
+ ptr = copy;
+ baseweak = qSharedPointerCast<Data>(std::move(ptr));
+ ptr = copy;
+ baseweak2 = qSharedPointerCast<Data>(std::move(baseweak));
+
+ // move construction (these don't actually move)
+ ptr = copy;
+ QSharedPointer<Data> ptr3(qSharedPointerCast<Data>(std::move(ptr)));
+ ptr = copy;
+ QWeakPointer<Data> baseweak3(qSharedPointerCast<Data>(std::move(ptr)));
+ ptr = copy;
+ QWeakPointer<Data> baseweak4(qSharedPointerCast<Data>(std::move(weak)));
}
{
+ // copy construction
QSharedPointer<DerivedData> ptr = QSharedPointer<DerivedData>(new DerivedData);
+ QSharedPointer<DerivedData> copy = ptr;
QSharedPointer<Data> baseptr = ptr;
+ QWeakPointer<DerivedData> weak = ptr;
+ QWeakPointer<Data> baseweak = ptr;
+ QWeakPointer<Data> baseweak2 = weak;
+
+ // copy assignments
+ baseptr = ptr;
+ baseweak = ptr;
+ baseweak2 = weak;
+
+ // move assignments (only the QSharedPointer-QSharedPointer actually moves)
+ baseweak = std::move(ptr);
+ baseweak2 = std::move(weak);
+ ptr = copy;
+ baseptr = std::move(ptr);
+
+ // move construction (only the QSharedPointer-QSharedPointer actually moves)
+ ptr = copy;
+ QWeakPointer<Data> baseweak3(std::move(ptr));
+ ptr = copy;
+ QWeakPointer<Data> baseweak4(std::move(weak));
+ ptr = copy;
+ QSharedPointer<Data> baseptr2(std::move(ptr));
}
int destructorCount;
@@ -1958,7 +1982,7 @@ class StrongThread: public QThread
protected:
void run() override
{
- usleep(QRandomGenerator::global()->bounded(2000));
+ sleep(std::chrono::microseconds{QRandomGenerator::global()->bounded(2000)});
ptr->ref();
ptr.clear();
}
@@ -1971,7 +1995,7 @@ class WeakThread: public QThread
protected:
void run() override
{
- usleep(QRandomGenerator::global()->bounded(2000));
+ sleep(std::chrono::microseconds{QRandomGenerator::global()->bounded(2000)});
QSharedPointer<ThreadData> ptr = weak;
if (ptr)
ptr->ref();
@@ -2034,11 +2058,11 @@ void tst_QSharedPointer::threadStressTest()
base.clear();
// start threads
- for (int i = 0; i < allThreads.count(); ++i)
+ for (int i = 0; i < allThreads.size(); ++i)
if (allThreads[i]) allThreads[i]->start();
// wait for them to finish
- for (int i = 0; i < allThreads.count(); ++i)
+ for (int i = 0; i < allThreads.size(); ++i)
if (allThreads[i]) allThreads[i]->wait();
qDeleteAll(allThreads);
@@ -2688,7 +2712,7 @@ void tst_QSharedPointer::constructorThrow()
int childDestructorCounter = ThrowData::childDestructorCounter;
QSharedPointer<ThrowData> ptr;
- QVERIFY_EXCEPTION_THROWN(ptr = QSharedPointer<ThrowData>::create(), QString);
+ QVERIFY_THROWS_EXCEPTION(QString, ptr = QSharedPointer<ThrowData>::create());
QVERIFY(ptr.isNull());
QCOMPARE(ThrowData::childGenerationCounter, childGeneration + 1);
// destructor should never be called, if a constructor throws
diff --git a/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp b/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp
index 24a0cdc9c1..07c837304e 100644
--- a/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifdef QT_SHAREDPOINTER_TRACK_POINTERS
# undef QT_SHAREDPOINTER_TRACK_POINTERS
diff --git a/tests/auto/corelib/tools/qsharedpointer/wrapper.h b/tests/auto/corelib/tools/qsharedpointer/wrapper.h
index 18cea6e199..32cc09f422 100644
--- a/tests/auto/corelib/tools/qsharedpointer/wrapper.h
+++ b/tests/auto/corelib/tools/qsharedpointer/wrapper.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef WRAPPER_H
#define WRAPPER_H
diff --git a/tests/auto/corelib/tools/qsize/CMakeLists.txt b/tests/auto/corelib/tools/qsize/CMakeLists.txt
index 5ecd154cd3..772aa42f4b 100644
--- a/tests/auto/corelib/tools/qsize/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qsize/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qsize.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsize Test:
diff --git a/tests/auto/corelib/tools/qsize/tst_qsize.cpp b/tests/auto/corelib/tools/qsize/tst_qsize.cpp
index 83b4f1bd34..77198c4576 100644
--- a/tests/auto/corelib/tools/qsize/tst_qsize.cpp
+++ b/tests/auto/corelib/tools/qsize/tst_qsize.cpp
@@ -1,34 +1,33 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QSize>
+#ifdef QVARIANT_H
+# error "This test requires qsize.h to not include qvariant.h"
+#endif
+
+// don't assume <type_traits>
+template <typename T, typename U>
+constexpr inline bool my_is_same_v = false;
+template <typename T>
+constexpr inline bool my_is_same_v<T, T> = true;
+
+#define CHECK(cvref) \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QSize cvref >())), int cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QSize cvref >())), int cvref >)
+
+CHECK(&);
+CHECK(const &);
+CHECK(&&);
+CHECK(const &&);
+
+#undef CHECK
#include <QTest>
#include <qsize.h>
+#include <array>
+
Q_DECLARE_METATYPE(QMargins)
class tst_QSize : public QObject
@@ -47,6 +46,9 @@ private slots:
void grownOrShrunkBy_data();
void grownOrShrunkBy();
+ void toSizeF_data();
+ void toSizeF();
+
void transpose_data();
void transpose();
@@ -232,6 +234,30 @@ void tst_QSize::grownOrShrunkBy()
QCOMPARE(shrunk.grownBy(margins), input);
}
+void tst_QSize::toSizeF_data()
+{
+ QTest::addColumn<QSize>("input");
+ QTest::addColumn<QSizeF>("result");
+
+ auto row = [](int w, int h) {
+ QTest::addRow("(%d, %d)", w, h) << QSize(w, h) << QSizeF(w, h);
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int w : samples) {
+ for (int h : samples) {
+ row(w, h);
+ }
+ }
+}
+
+void tst_QSize::toSizeF()
+{
+ QFETCH(const QSize, input);
+ QFETCH(const QSizeF, result);
+
+ QCOMPARE(input.toSizeF(), result);
+}
+
void tst_QSize::transpose_data()
{
QTest::addColumn<QSize>("input1");
diff --git a/tests/auto/corelib/tools/qsizef/CMakeLists.txt b/tests/auto/corelib/tools/qsizef/CMakeLists.txt
index eb59fc6d8e..d4be610e42 100644
--- a/tests/auto/corelib/tools/qsizef/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qsizef/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qsizef.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsizef Test:
diff --git a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
index 3a65506dee..018f929cca 100644
--- a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
+++ b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
@@ -1,30 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QSizeF>
+#ifdef QVARIANT_H
+# error "This test requires qsize.h to not include qvariant.h"
+#endif
+
+// don't assume <type_traits>
+template <typename T, typename U>
+constexpr inline bool my_is_same_v = false;
+template <typename T>
+constexpr inline bool my_is_same_v<T, T> = true;
+
+#define CHECK(cvref) \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QSizeF cvref >())), qreal cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QSizeF cvref >())), qreal cvref >)
+
+CHECK(&);
+CHECK(const &);
+CHECK(&&);
+CHECK(const &&);
+
+#undef CHECK
#include <QTest>
#include <qsize.h>
diff --git a/tests/auto/corelib/tools/qstl/CMakeLists.txt b/tests/auto/corelib/tools/qstl/CMakeLists.txt
index 49b209cffa..3651c3bde9 100644
--- a/tests/auto/corelib/tools/qstl/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qstl/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qstl.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstl Test:
diff --git a/tests/auto/corelib/tools/qstl/tst_qstl.cpp b/tests/auto/corelib/tools/qstl/tst_qstl.cpp
index 1cd74ad305..bd344fe43c 100644
--- a/tests/auto/corelib/tools/qstl/tst_qstl.cpp
+++ b/tests/auto/corelib/tools/qstl/tst_qstl.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
diff --git a/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt
index 7f3ae75028..1d5e644cb7 100644
--- a/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qtaggedpointer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtaggedpointer Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qtaggedpointer
SOURCES
tst_qtaggedpointer.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
)
diff --git a/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp b/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp
index dcc966fc2f..5cb82329d0 100644
--- a/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp
+++ b/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp
@@ -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 WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/qtaggedpointer.h>
@@ -36,6 +11,7 @@ class tst_QTaggedPointer : public QObject
private Q_SLOTS:
void constExpr();
void construction();
+ void assignment();
void dereferenceOperator();
void pointerOperator();
void negationOperator();
@@ -105,6 +81,47 @@ void tst_QTaggedPointer::construction()
}
}
+void tst_QTaggedPointer::assignment()
+{
+ QScopedPointer<int> rawPointer(new int(5));
+ QTaggedPointer<int> p(rawPointer.data(), 0x1);
+ QTaggedPointer<int> p2(rawPointer.data(), 0x2);
+
+ QCOMPARE(p.data(), rawPointer.data());
+ QCOMPARE(p.tag(), quintptr(0x1));
+
+ QCOMPARE(p2.data(), rawPointer.data());
+ QCOMPARE(p2.tag(), quintptr(0x2));
+
+ p = nullptr;
+ QCOMPARE(p.data(), nullptr);
+ QCOMPARE(p.tag(), quintptr(0x1));
+
+ p = rawPointer.data();
+ QCOMPARE(p.data(), rawPointer.data());
+ QCOMPARE(p.tag(), quintptr(0x1));
+
+ p = {};
+ QCOMPARE(p.data(), nullptr);
+ QCOMPARE(p.tag(), quintptr(0x0));
+
+ p = p2;
+ QCOMPARE(p.data(), rawPointer.data());
+ QCOMPARE(p.tag(), quintptr(0x2));
+
+ p = nullptr;
+ QCOMPARE(p.data(), nullptr);
+ QCOMPARE(p.tag(), quintptr(0x2));
+
+ p = {};
+ QCOMPARE(p.data(), nullptr);
+ QCOMPARE(p.tag(), quintptr(0x0));
+
+ p = rawPointer.data();
+ QCOMPARE(p.data(), rawPointer.data());
+ QCOMPARE(p.tag(), quintptr(0x0));
+}
+
class AbstractClass
{
public:
diff --git a/tests/auto/corelib/tools/qtimeline/CMakeLists.txt b/tests/auto/corelib/tools/qtimeline/CMakeLists.txt
index e3a24e9440..525077f7d4 100644
--- a/tests/auto/corelib/tools/qtimeline/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qtimeline/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qtimeline.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtimeline Test:
diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
index 1ea18d700c..7d0e121b30 100644
--- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
+++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
@@ -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 WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtTest/private/qpropertytesthelper_p.h>
@@ -105,7 +80,7 @@ void tst_QTimeLine::range()
timeLine.setStartFrame(5000);
QVERIFY(timeLine.currentFrame() > oldValue);
timeLine.setFrameRange(0, 500);
- QTRY_VERIFY(spy.count() > 1);
+ QTRY_VERIFY(spy.size() > 1);
QVERIFY(timeLine.currentFrame() < oldValue);
}
@@ -127,7 +102,7 @@ void tst_QTimeLine::currentTime()
spy.clear();
timeLine.setCurrentTime(timeLine.duration()/2);
timeLine.setCurrentTime(timeLine.duration()/2);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
QCOMPARE(timeLine.currentTime(), timeLine.duration()/2);
timeLine.resume();
@@ -178,10 +153,10 @@ void tst_QTimeLine::bindableCurrentTime()
spy.clear();
QProperty<int> referenceCurrentTime(timeLine.duration() / 2);
timeLine.bindableCurrentTime().setBinding([&]() { return referenceCurrentTime.value(); });
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
// setting it a second time to check that valueChanged() is emitted only once
referenceCurrentTime = timeLine.duration() / 2;
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
QCOMPARE(timeLine.currentTime(), timeLine.duration() / 2);
@@ -197,7 +172,7 @@ void tst_QTimeLine::bindableCurrentTime()
spy.clear();
referenceCurrentTime = 0;
QCOMPARE(currentTimeObserver.value(), timeLine.duration());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTimeLine::duration()
@@ -261,7 +236,7 @@ void tst_QTimeLine::frameRate()
timeLine.start();
QTest::qWait(timeLine.duration()*2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- int slowCount = spy.count();
+ int slowCount = spy.size();
// Faster!!
timeLine.setUpdateInterval(1000 / 100);
@@ -270,7 +245,7 @@ void tst_QTimeLine::frameRate()
timeLine.start();
QTest::qWait(timeLine.duration()*2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- QVERIFY2(slowCount < spy.count(), QByteArray::number(spy.count()));
+ QVERIFY2(slowCount < spy.size(), QByteArray::number(spy.size()));
}
void tst_QTimeLine::bindableUpdateInterval()
@@ -295,7 +270,7 @@ void tst_QTimeLine::bindableUpdateInterval()
timeLine.start();
QTest::qWait(timeLine.duration() * 2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- int slowCount = spy.count();
+ int slowCount = spy.size();
// Faster!!
updateIntervalReference = 1000 / 100;
@@ -304,7 +279,7 @@ void tst_QTimeLine::bindableUpdateInterval()
timeLine.start();
QTest::qWait(timeLine.duration() * 2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- QVERIFY2(slowCount < spy.count(), QByteArray::number(spy.count()));
+ QVERIFY2(slowCount < spy.size(), QByteArray::number(spy.size()));
}
void tst_QTimeLine::value()
@@ -319,7 +294,7 @@ void tst_QTimeLine::value()
QTRY_VERIFY(timeLine.currentValue() > 0);
QTRY_COMPARE(timeLine.state(), QTimeLine::NotRunning);
QCOMPARE(timeLine.currentValue(), 1.0);
- QVERIFY(spy.count() > 0);
+ QVERIFY(spy.size() > 0);
// Reverse should decrease the value
timeLine.setCurrentTime(100);
@@ -405,8 +380,8 @@ void tst_QTimeLine::loopCount()
loop.exec();
- QCOMPARE(finishedSpy.count(), 1);
- QCOMPARE(frameChangedSpy.count(), 11);
+ QCOMPARE(finishedSpy.size(), 1);
+ QCOMPARE(frameChangedSpy.size(), 11);
for (int i = 0; i < 11; ++i)
QCOMPARE(frameChangedSpy.at(i).at(0).toInt(), (i+1) % 3);
}
@@ -415,8 +390,8 @@ void tst_QTimeLine::loopCount()
timeLine.start();
loop.exec();
- QCOMPARE(finishedSpy.count(), 2);
- QCOMPARE(frameChangedSpy.count(), 22);
+ QCOMPARE(finishedSpy.size(), 2);
+ QCOMPARE(frameChangedSpy.size(), 22);
for (int i = 11; i < 22; ++i) {
QCOMPARE(frameChangedSpy.at(i).at(0).toInt(), 2 - (i+2) % 3);
}
@@ -481,8 +456,8 @@ void tst_QTimeLine::bindableLoopCount()
loop.exec();
- QCOMPARE(finishedSpy.count(), 1);
- QCOMPARE(frameChangedSpy.count(), 11);
+ QCOMPARE(finishedSpy.size(), 1);
+ QCOMPARE(frameChangedSpy.size(), 11);
for (int i = 0; i < 11; ++i)
QCOMPARE(frameChangedSpy.at(i).at(0).toInt(), (i + 1) % 3);
}
@@ -491,8 +466,8 @@ void tst_QTimeLine::bindableLoopCount()
timeLine.start();
loop.exec();
- QCOMPARE(finishedSpy.count(), 2);
- QCOMPARE(frameChangedSpy.count(), 22);
+ QCOMPARE(finishedSpy.size(), 2);
+ QCOMPARE(frameChangedSpy.size(), 22);
for (int i = 11; i < 22; ++i)
QCOMPARE(frameChangedSpy.at(i).at(0).toInt(), 2 - (i + 2) % 3);
}
@@ -661,14 +636,14 @@ void tst_QTimeLine::frameChanged()
timeLine.start();
QTest::qWait(timeLine.duration()/2);
QCOMPARE(timeLine.state(), QTimeLine::Running);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QTest::qWait(timeLine.duration());
if (timeLine.state() != QTimeLine::NotRunning)
QEXPECT_FAIL("", "QTBUG-24796: QTimeLine runs slower than it should", Abort);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- if (spy.count() != 1)
+ if (spy.size() != 1)
QEXPECT_FAIL("", "QTBUG-24796: QTimeLine runs slower than it should", Abort);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
// Test what happens when the frames are all emitted well before duration expires.
timeLine.setUpdateInterval(5);
@@ -677,7 +652,7 @@ void tst_QTimeLine::frameChanged()
timeLine.start();
QTest::qWait(timeLine.duration()*2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- QCOMPARE(spy.count(), 10);
+ QCOMPARE(spy.size(), 10);
}
void tst_QTimeLine::stopped()
@@ -690,11 +665,11 @@ void tst_QTimeLine::stopped()
timeLine.start();
QTest::qWait(timeLine.duration()*2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
spy.clear();
timeLine.start();
timeLine.stop();
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
timeLine.setDirection(QTimeLine::Backward);
QCOMPARE(timeLine.loopCount(), 1);
}
@@ -706,13 +681,13 @@ void tst_QTimeLine::finished()
QSignalSpy spy(&timeLine, &QTimeLine::finished);
QVERIFY(spy.isValid());
timeLine.start();
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.size(), 1);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
spy.clear();
timeLine.start();
timeLine.stop();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTimeLine::isRunning()
@@ -745,7 +720,7 @@ void tst_QTimeLine::multipleTimeLines()
timeLine.start();
timeLineKiller.stop();
QTest::qWait(timeLine.duration()*2);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QTimeLine::sineCurve()
diff --git a/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt b/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt
index bdc927d5b6..1123f92c2c 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qvarlengtharray.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qvarlengtharray Test:
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index 6e95577655..1ae18ca171 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -1,36 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QTest>
-#include <qvarlengtharray.h>
+#include <QVarLengthArray>
#include <qvariant.h>
#include <qscopeguard.h>
+#include <qscopedvaluerollback.h>
+#include <algorithm>
+#include <q20iterator.h>
#include <memory>
struct Tracker
@@ -64,12 +42,33 @@ public:
{ return !operator==(lhs, rhs); }
};
+class NonCopyable
+{
+ Q_DISABLE_COPY(NonCopyable)
+ int n;
+public:
+ NonCopyable() : n(0) {}
+ explicit NonCopyable(int n) : n(n) {}
+
+ friend bool operator==(const NonCopyable &lhs, const NonCopyable &rhs) noexcept
+ { return lhs.n == rhs.n; }
+ friend bool operator!=(const NonCopyable &lhs, const NonCopyable &rhs) noexcept
+ { return !operator==(lhs, rhs); }
+};
+
class tst_QVarLengthArray : public QObject
{
Q_OBJECT
private slots:
+ void defaultConstructor_int() { defaultConstructor<int>(); }
+ void defaultConstructor_QString() { defaultConstructor<QString>(); }
+ void sizeConstructor_int() { sizeConstructor<int>(); }
+ void sizeConstructor_QString() { sizeConstructor<QString>(); }
+ void sizeConstructor_NonCopyable() { sizeConstructor<NonCopyable>(); }
void append();
+#if QT_DEPRECATED_SINCE(6, 3)
void prepend();
+#endif
void emplace();
void move_int_1() { move_int<1>(); }
void move_int_2() { move_int<2>(); }
@@ -83,6 +82,7 @@ private slots:
void removeLast();
void oldTests();
void appendCausingRealloc();
+ void appendIsStronglyExceptionSafe();
void resize();
void realloc();
void iterators();
@@ -111,7 +111,13 @@ private slots:
void remove();
void erase();
+ // special cases:
+ void copesWithCopyabilityOfMoveOnlyVector(); // QTBUG-109745
private:
+ template <typename T>
+ void defaultConstructor();
+ template <typename T>
+ void sizeConstructor();
template <qsizetype N, typename T>
void move(T t1, T t2);
template <qsizetype N>
@@ -124,6 +130,48 @@ private:
void initializeList();
};
+template <typename T>
+void tst_QVarLengthArray::defaultConstructor()
+{
+ {
+ QVarLengthArray<T, 123> vla;
+ QCOMPARE(vla.size(), 0);
+ QVERIFY(vla.empty());
+ QVERIFY(vla.isEmpty());
+ QCOMPARE(vla.begin(), vla.end());
+ QCOMPARE(vla.capacity(), 123);
+ }
+ {
+ QVarLengthArray<T> vla;
+ QCOMPARE(vla.capacity(), 256); // notice, should we change the default
+ }
+}
+
+template <typename T>
+void tst_QVarLengthArray::sizeConstructor()
+{
+ {
+ QVarLengthArray<T, 123> vla(0);
+ QCOMPARE(vla.size(), 0);
+ QVERIFY(vla.empty());
+ QVERIFY(vla.isEmpty());
+ QCOMPARE(vla.begin(), vla.end());
+ QCOMPARE(vla.capacity(), 123);
+ }
+ {
+ QVarLengthArray<T, 124> vla(124);
+ QCOMPARE(vla.size(), 124);
+ QVERIFY(!vla.empty());
+ QCOMPARE(vla.capacity(), 124);
+ }
+ {
+ QVarLengthArray<T, 124> vla(125);
+ QCOMPARE(vla.size(), 125);
+ QVERIFY(!vla.empty());
+ QCOMPARE_GE(vla.capacity(), 125);
+ }
+}
+
void tst_QVarLengthArray::append()
{
QVarLengthArray<QString, 2> v;
@@ -146,6 +194,9 @@ void tst_QVarLengthArray::append()
v2.append(5);
}
+#if QT_DEPRECATED_SINCE(6, 3)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
void tst_QVarLengthArray::prepend()
{
QVarLengthArray<QString, 2> v;
@@ -164,6 +215,8 @@ void tst_QVarLengthArray::prepend()
v.prepend(v.back());
QCOMPARE(v.front(), v.back());
}
+QT_WARNING_POP
+#endif // QT_DEPRECATED_SINCE(6, 3)
void tst_QVarLengthArray::emplace()
{
@@ -180,6 +233,33 @@ void tst_QVarLengthArray::emplace()
QCOMPARE(&r, &strings.back());
QCOMPARE(strings.size(), 3);
QCOMPARE(strings.back(), QString(42, u'y'));
+
+ // test growing from empty arrays
+ QVarLengthArray<QString> emptyArrDefaultPrealloc;
+ QCOMPARE(emptyArrDefaultPrealloc.size(), 0);
+ emptyArrDefaultPrealloc.emplace_back();
+ QCOMPARE(emptyArrDefaultPrealloc.size(), 1);
+ emptyArrDefaultPrealloc.resize(1024);
+ QCOMPARE(emptyArrDefaultPrealloc.size(), 1024);
+ emptyArrDefaultPrealloc.resize(0);
+ QCOMPARE(emptyArrDefaultPrealloc.size(), 0);
+ emptyArrDefaultPrealloc.squeeze();
+ QCOMPARE(emptyArrDefaultPrealloc.size(), 0);
+ emptyArrDefaultPrealloc.emplace_back();
+ QCOMPARE(emptyArrDefaultPrealloc.size(), 1);
+
+ QVarLengthArray<QString, 1> emptyArrSmallPrealloc;
+ QCOMPARE(emptyArrSmallPrealloc.size(), 0);
+ emptyArrSmallPrealloc.emplace_back();
+ QCOMPARE(emptyArrSmallPrealloc.size(), 1);
+ emptyArrSmallPrealloc.resize(1024);
+ QCOMPARE(emptyArrSmallPrealloc.size(), 1024);
+ emptyArrSmallPrealloc.resize(0);
+ QCOMPARE(emptyArrSmallPrealloc.size(), 0);
+ emptyArrSmallPrealloc.squeeze();
+ QCOMPARE(emptyArrSmallPrealloc.size(), 0);
+ emptyArrSmallPrealloc.emplace_back();
+ QCOMPARE(emptyArrSmallPrealloc.size(), 1);
}
}
@@ -352,6 +432,80 @@ void tst_QVarLengthArray::appendCausingRealloc()
QVarLengthArray<float, 1> d(1);
for (int i=0; i<30; i++)
d.append(i);
+
+ // Regression test for QTBUG-110412:
+ constexpr qsizetype InitialCapacity = 10;
+ QVarLengthArray<float, InitialCapacity> d2(InitialCapacity);
+ std::iota(d2.begin(), d2.end(), 0.0f);
+ QCOMPARE_EQ(d2.size(), d2.capacity()); // by construction
+ float floats[1000];
+ std::iota(std::begin(floats), std::end(floats), InitialCapacity + 0.0f);
+ d2.append(floats, q20::ssize(floats));
+ QCOMPARE_EQ(d2.size(), q20::ssize(floats) + InitialCapacity);
+ QCOMPARE_GE(d2.capacity(), d2.size());
+}
+
+void tst_QVarLengthArray::appendIsStronglyExceptionSafe()
+{
+#ifdef QT_NO_EXCEPTIONS
+ QSKIP("This test requires exception support enabled in the compiler.");
+#else
+ static bool throwOnCopyNow = false;
+ static bool throwOnMoveNow = false;
+ struct Thrower {
+ Thrower() = default;
+ Thrower(const Thrower &)
+ {
+ if (throwOnCopyNow)
+ throw 1;
+ }
+ Thrower &operator=(const Thrower &) = default;
+ Thrower(Thrower &&)
+ {
+ if (throwOnMoveNow)
+ throw 1;
+ }
+ Thrower &operator=(Thrower &&) = default;
+ ~Thrower() = default;
+ };
+
+ {
+ QVarLengthArray<Thrower, 2> vla(1);
+ {
+ Thrower t;
+ const QScopedValueRollback rb(throwOnCopyNow, true);
+ QVERIFY_THROWS_EXCEPTION(int, vla.push_back(t));
+ QCOMPARE(vla.size(), 1);
+ }
+ {
+ const QScopedValueRollback rb(throwOnMoveNow, true);
+ QVERIFY_THROWS_EXCEPTION(int, vla.push_back({}));
+ QCOMPARE(vla.size(), 1);
+ }
+ vla.push_back({});
+ QCOMPARE(vla.size(), 2);
+ {
+ Thrower t;
+ {
+ // tests the copy inside append()
+ const QScopedValueRollback rb(throwOnCopyNow, true);
+ QVERIFY_THROWS_EXCEPTION(int, vla.push_back(t));
+ QCOMPARE(vla.size(), 2);
+ }
+ {
+ // tests the move inside reallocate()
+ const QScopedValueRollback rb(throwOnMoveNow, true);
+ QVERIFY_THROWS_EXCEPTION(int, vla.push_back(t));
+ QCOMPARE(vla.size(), 2);
+ }
+ }
+ {
+ const QScopedValueRollback rb(throwOnMoveNow, true);
+ QVERIFY_THROWS_EXCEPTION(int, vla.push_back({}));
+ QCOMPARE(vla.size(), 2);
+ }
+ }
+#endif
}
void tst_QVarLengthArray::resize()
@@ -480,6 +634,12 @@ struct MyBase
bool hasMoved() const { return !wasConstructedAt(this); }
protected:
+ void swap(MyBase &other) {
+ using std::swap;
+ swap(data, other.data);
+ swap(isCopy, other.isCopy);
+ }
+
MyBase(const MyBase *data, bool isCopy)
: data(data), isCopy(isCopy) {}
@@ -554,6 +714,14 @@ struct MyMovable
return *this;
}
+ void swap(MyMovable &other) noexcept
+ {
+ MyBase::swap(other);
+ std::swap(i, other.i);
+ }
+
+ friend void swap(MyMovable &lhs, MyMovable &rhs) noexcept { lhs.swap(rhs); }
+
bool operator==(const MyMovable &other) const
{
return i == other.i;
@@ -569,6 +737,15 @@ struct MyComplex
{
return i == other.i;
}
+
+ void swap(MyComplex &other) noexcept
+ {
+ MyBase::swap(other);
+ std::swap(i, other.i);
+ }
+
+ friend void swap(MyComplex &lhs, MyComplex &rhs) noexcept { lhs.swap(rhs); }
+
char i;
};
@@ -841,8 +1018,8 @@ void tst_QVarLengthArray::count()
// tests size(), count() and length(), since they're the same thing
{
const QVarLengthArray<int> list;
- QCOMPARE(list.length(), 0);
- QCOMPARE(list.count(), 0);
+ QCOMPARE(list.size(), 0);
+ QCOMPARE(list.size(), 0);
QCOMPARE(list.size(), 0);
QVERIFY(list.isEmpty());
}
@@ -850,8 +1027,8 @@ void tst_QVarLengthArray::count()
{
QVarLengthArray<int> list;
list.append(0);
- QCOMPARE(list.length(), 1);
- QCOMPARE(list.count(), 1);
+ QCOMPARE(list.size(), 1);
+ QCOMPARE(list.size(), 1);
QCOMPARE(list.size(), 1);
QVERIFY(!list.isEmpty());
}
@@ -860,8 +1037,8 @@ void tst_QVarLengthArray::count()
QVarLengthArray<int> list;
list.append(0);
list.append(1);
- QCOMPARE(list.length(), 2);
- QCOMPARE(list.count(), 2);
+ QCOMPARE(list.size(), 2);
+ QCOMPARE(list.size(), 2);
QCOMPARE(list.size(), 2);
QVERIFY(!list.isEmpty());
}
@@ -871,8 +1048,8 @@ void tst_QVarLengthArray::count()
list.append(0);
list.append(0);
list.append(0);
- QCOMPARE(list.length(), 3);
- QCOMPARE(list.count(), 3);
+ QCOMPARE(list.size(), 3);
+ QCOMPARE(list.size(), 3);
QCOMPARE(list.size(), 3);
QVERIFY(!list.isEmpty());
}
@@ -883,23 +1060,23 @@ void tst_QVarLengthArray::count()
list.append(0);
list.append(0);
list.append(0);
- QCOMPARE(list.length(), 3);
- QCOMPARE(list.count(), 3);
+ QCOMPARE(list.size(), 3);
+ QCOMPARE(list.size(), 3);
QCOMPARE(list.size(), 3);
QVERIFY(!list.isEmpty());
list.removeLast();
- QCOMPARE(list.length(), 2);
- QCOMPARE(list.count(), 2);
+ QCOMPARE(list.size(), 2);
+ QCOMPARE(list.size(), 2);
QCOMPARE(list.size(), 2);
QVERIFY(!list.isEmpty());
list.removeLast();
- QCOMPARE(list.length(), 1);
- QCOMPARE(list.count(), 1);
+ QCOMPARE(list.size(), 1);
+ QCOMPARE(list.size(), 1);
QCOMPARE(list.size(), 1);
QVERIFY(!list.isEmpty());
list.removeLast();
- QCOMPARE(list.length(), 0);
- QCOMPARE(list.count(), 0);
+ QCOMPARE(list.size(), 0);
+ QCOMPARE(list.size(), 0);
QCOMPARE(list.size(), 0);
QVERIFY(list.isEmpty());
}
@@ -938,16 +1115,16 @@ void tst_QVarLengthArray::first()
QCOMPARE(list.first(), 27);
list.append(1987);
QCOMPARE(list.first(), 27);
- QCOMPARE(list.length(), 3);
+ QCOMPARE(list.size(), 3);
// remove some, make sure it stays sane
list.removeLast();
QCOMPARE(list.first(), 27);
- QCOMPARE(list.length(), 2);
+ QCOMPARE(list.size(), 2);
list.removeLast();
QCOMPARE(list.first(), 27);
- QCOMPARE(list.length(), 1);
+ QCOMPARE(list.size(), 1);
}
void tst_QVarLengthArray::last()
@@ -960,16 +1137,16 @@ void tst_QVarLengthArray::last()
QCOMPARE(list.last(), 4);
list.append(1987);
QCOMPARE(list.last(), 1987);
- QCOMPARE(list.length(), 3);
+ QCOMPARE(list.size(), 3);
// remove some, make sure it stays sane
list.removeLast();
QCOMPARE(list.last(), 4);
- QCOMPARE(list.length(), 2);
+ QCOMPARE(list.size(), 2);
list.removeLast();
QCOMPARE(list.last(), 27);
- QCOMPARE(list.length(), 1);
+ QCOMPARE(list.size(), 1);
}
void tst_QVarLengthArray::squeeze()
@@ -1013,7 +1190,7 @@ void tst_QVarLengthArray::operators()
// +=: not provided, emulate
//myvla += myvlatwo;
- for (const QString &s : qAsConst(myvlatwo))
+ for (const QString &s : std::as_const(myvlatwo))
myvla.push_back(s);
QCOMPARE(myvla, combined);
@@ -1201,6 +1378,17 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::copyCount, 0);
{
+ MyMovable m1, m2;
+ QCOMPARE(MyBase::liveCount, 2);
+ QCOMPARE(MyBase::copyCount, 0);
+ using std::swap;
+ swap(m1, m2);
+ QCOMPARE(MyBase::liveCount, 2);
+ QCOMPARE(MyBase::movedCount, 0);
+ QCOMPARE(MyBase::copyCount, 0);
+ }
+
+ {
QVarLengthArray<MyMovable, 6> vec;
MyMovable m1;
MyMovable m2;
@@ -1226,7 +1414,7 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::liveCount, 6);
QCOMPARE(MyBase::movedCount, 2);
- vec.prepend(std::move(m1));
+ vec.insert(vec.cbegin(), std::move(m1));
QVERIFY(m1.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m3));
@@ -1298,7 +1486,7 @@ void tst_QVarLengthArray::nonCopyable()
QVERIFY(!val4);
QVERIFY(ptr3 == vec.at(0).get());
QVERIFY(ptr4 == vec.at(1).get());
- vec.prepend(std::move(val1));
+ vec.insert(vec.cbegin(), std::move(val1));
QVERIFY(!val1);
QVERIFY(ptr1 == vec.at(0).get());
QVERIFY(ptr3 == vec.at(1).get());
@@ -1545,5 +1733,26 @@ void tst_QVarLengthArray::erase()
QCOMPARE(arr, QVarLengthArray<QString>({ "val0" }));
}
+void tst_QVarLengthArray::copesWithCopyabilityOfMoveOnlyVector()
+{
+ // std::vector<move-only-type> is_copyable
+ // (https://quuxplusone.github.io/blog/2020/02/05/vector-is-copyable-except-when-its-not/)
+
+ QVarLengthArray<std::vector<std::unique_ptr<int>>, 2> vla;
+ vla.emplace_back(42);
+ vla.emplace_back(43);
+ vla.emplace_back(44); // goes to the heap
+ QCOMPARE_EQ(vla.size(), 3);
+ QCOMPARE_EQ(vla.front().size(), 42U);
+ QCOMPARE_EQ(vla.front().front(), nullptr);
+ QCOMPARE_EQ(vla.back().size(), 44U);
+
+ auto moved = std::move(vla);
+ QCOMPARE_EQ(moved.size(), 3);
+ QCOMPARE_EQ(moved.front().size(), 42U);
+ QCOMPARE_EQ(moved.front().front(), nullptr);
+ QCOMPARE_EQ(moved.back().size(), 44U);
+}
+
QTEST_APPLESS_MAIN(tst_QVarLengthArray)
#include "tst_qvarlengtharray.moc"
diff --git a/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt b/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt
index 2ab3703121..33849639bc 100644
--- a/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qversionnumber.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qversionnumber Test:
diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
index b0dbcb042d..cc17188c54 100644
--- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
+++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Keith Gardner <kreios4004@gmail.com>
-** 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) 2016 The Qt Company Ltd.
+// Copyright (C) 2014 Keith Gardner <kreios4004@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/qversionnumber.h>
@@ -73,6 +48,7 @@ private slots:
void assignment();
void fromString_data();
void fromString();
+ void fromString_extra();
void toString_data();
void toString();
void isNull_data();
@@ -511,7 +487,7 @@ void tst_QVersionNumber::fromString()
QFETCH(QVersionNumber, expectedVersion);
QFETCH(int, suffixIndex);
- int index;
+ qsizetype index;
QCOMPARE(QVersionNumber::fromString(constructionString), expectedVersion);
QCOMPARE(QVersionNumber::fromString(constructionString, &index), expectedVersion);
QCOMPARE(index, suffixIndex);
@@ -523,6 +499,46 @@ void tst_QVersionNumber::fromString()
QCOMPARE(QVersionNumber::fromString(QLatin1String(constructionString.toLatin1())), expectedVersion);
QCOMPARE(QVersionNumber::fromString(QLatin1String(constructionString.toLatin1()), &index), expectedVersion);
QCOMPARE(index, suffixIndex);
+
+#if QT_DEPRECATED_SINCE(6, 4)
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
+ // check deprecated `int *suffixIndex` overload, too
+ {
+ int i;
+ QCOMPARE(QVersionNumber::fromString(constructionString, &i), expectedVersion);
+ QCOMPARE(i, suffixIndex);
+
+ QCOMPARE(QVersionNumber::fromString(QStringView(constructionString), &i), expectedVersion);
+ QCOMPARE(i, suffixIndex);
+
+ QCOMPARE(QVersionNumber::fromString(QLatin1String(constructionString.toLatin1()), &i), expectedVersion);
+ QCOMPARE(i, suffixIndex);
+ }
+ QT_WARNING_POP
+#endif
+}
+
+void tst_QVersionNumber::fromString_extra()
+{
+ // check the overloaded fromString() functions aren't ambiguous
+ // when passing explicit nullptr:
+ {
+ auto v = QVersionNumber::fromString("1.2.3-rc1", nullptr);
+ QCOMPARE(v, QVersionNumber({1, 2, 3}));
+ }
+ {
+ auto v = QVersionNumber::fromString("1.2.3-rc1", 0);
+ QCOMPARE(v, QVersionNumber({1, 2, 3}));
+ }
+
+ // check the UTF16->L1 conversion isn't doing something weird
+ {
+ qsizetype i = -1;
+ auto v = QVersionNumber::fromString(u"1.0ı", &i); // LATIN SMALL LETTER DOTLESS I
+ QCOMPARE(v, QVersionNumber(1, 0));
+ QCOMPARE(i, 3);
+ }
}
void tst_QVersionNumber::toString_data()