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.txt3
-rw-r--r--tests/auto/corelib/tools/collections/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp5
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp205
-rw-r--r--tests/auto/corelib/tools/qalgorithms/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp2
-rw-r--r--tests/auto/corelib/tools/qarraydata/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h19
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp20
-rw-r--r--tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp11
-rw-r--r--tests/auto/corelib/tools/qbitarray/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp328
-rw-r--r--tests/auto/corelib/tools/qcache/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qcache/tst_qcache.cpp2
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp2
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp53
-rw-r--r--tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp2
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp126
-rw-r--r--tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp25
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp35
-rw-r--r--tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp3
-rw-r--r--tests/auto/corelib/tools/qflatmap/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp2
-rw-r--r--tests/auto/corelib/tools/qfreelist/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp5
-rw-r--r--tests/auto/corelib/tools/qhash/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp352
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp300
-rw-r--r--tests/auto/corelib/tools/qhashseed/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp6
-rw-r--r--tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp2
-rw-r--r--tests/auto/corelib/tools/qline/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qline/tst_qline.cpp127
-rw-r--r--tests/auto/corelib/tools/qlist/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qlist/tst_qlist.cpp239
-rw-r--r--tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm23
-rw-r--r--tests/auto/corelib/tools/qmakearray/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp2
-rw-r--r--tests/auto/corelib/tools/qmap/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp32
-rw-r--r--tests/auto/corelib/tools/qmargins/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qmargins/tst_qmargins.cpp101
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp2
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp2
-rw-r--r--tests/auto/corelib/tools/qpair/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qpair/tst_qpair.cpp2
-rw-r--r--tests/auto/corelib/tools/qpoint/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qpoint/tst_qpoint.cpp19
-rw-r--r--tests/auto/corelib/tools/qpointf/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qpointf/tst_qpointf.cpp58
-rw-r--r--tests/auto/corelib/tools/qqueue/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qqueue/tst_qqueue.cpp2
-rw-r--r--tests/auto/corelib/tools/qrect/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qrect/tst_qrect.cpp94
-rw-r--r--tests/auto/corelib/tools/qringbuffer/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp2
-rw-r--r--tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp2
-rw-r--r--tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp2
-rw-r--r--tests/auto/corelib/tools/qscopeguard/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp23
-rw-r--r--tests/auto/corelib/tools/qset/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp6
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.cpp2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.h2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/nontracked.cpp2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/nontracked.h2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp154
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/wrapper.cpp2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/wrapper.h2
-rw-r--r--tests/auto/corelib/tools/qsize/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qsize/tst_qsize.cpp39
-rw-r--r--tests/auto/corelib/tools/qsizef/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qsizef/tst_qsizef.cpp98
-rw-r--r--tests/auto/corelib/tools/qspan/CMakeLists.txt13
-rw-r--r--tests/auto/corelib/tools/qspan/tst_qspan.cpp481
-rw-r--r--tests/auto/corelib/tools/qstl/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qstl/tst_qstl.cpp2
-rw-r--r--tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp2
-rw-r--r--tests/auto/corelib/tools/qtimeline/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp2
-rw-r--r--tests/auto/corelib/tools/qtyperevision/CMakeLists.txt15
-rw-r--r--tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp202
-rw-r--r--tests/auto/corelib/tools/quniquehandle/CMakeLists.txt15
-rw-r--r--tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp308
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp12
-rw-r--r--tests/auto/corelib/tools/qversionnumber/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp431
106 files changed, 3737 insertions, 585 deletions
diff --git a/tests/auto/corelib/tools/CMakeLists.txt b/tests/auto/corelib/tools/CMakeLists.txt
index 9bcdc12bfc..5cca2e2df6 100644
--- a/tests/auto/corelib/tools/CMakeLists.txt
+++ b/tests/auto/corelib/tools/CMakeLists.txt
@@ -42,11 +42,14 @@ add_subdirectory(qscopedpointer)
add_subdirectory(qscopedvaluerollback)
add_subdirectory(qscopeguard)
add_subdirectory(qtaggedpointer)
+add_subdirectory(qtyperevision)
add_subdirectory(qset)
add_subdirectory(qsharedpointer)
add_subdirectory(qsize)
add_subdirectory(qsizef)
+add_subdirectory(qspan)
add_subdirectory(qstl)
+add_subdirectory(quniquehandle)
add_subdirectory(qvarlengtharray)
add_subdirectory(qversionnumber)
add_subdirectory(qtimeline)
diff --git a/tests/auto/corelib/tools/collections/CMakeLists.txt b/tests/auto/corelib/tools/collections/CMakeLists.txt
index 952d2eb49d..687d88b2e4 100644
--- a/tests/auto/corelib/tools/collections/CMakeLists.txt
+++ b/tests/auto/corelib/tools/collections/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_collections Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_collections LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_collections
SOURCES
tst_collections.cpp
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index af7a7ec0df..2fab6cae3a 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -1,6 +1,7 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#undef QT_NO_FOREACH // this file tests Q_FOREACH over containers (centralize in a tst_qforeach?)
// test the container forwards
#include <QtContainerFwd>
@@ -529,7 +530,7 @@ void tst_Collections::list()
list << "one" << "two" << "one" << "two";
QVERIFY(!list.removeOne("three"));
QVERIFY(list.removeOne("two"));
- QCOMPARE(list, QList<QString>() << "one" << "one" << "two");;
+ QCOMPARE(list, QList<QString>() << "one" << "one" << "two");
QVERIFY(list.removeOne("two"));
QCOMPARE(list, QList<QString>() << "one" << "one");
QVERIFY(!list.removeOne("two"));
diff --git a/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt b/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt
index 247248f25d..0ae1092043 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt
+++ b/tests/auto/corelib/tools/containerapisymmetry/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_containerapisymmetry Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_containerapisymmetry LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_containerapisymmetry
SOURCES
tst_containerapisymmetry.cpp
diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
index c438d6f961..5eb9dbfa36 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
+++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
@@ -1,5 +1,5 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -14,7 +14,6 @@
#include <algorithm>
#include <functional>
-#include <vector> // for reference
#include <iostream>
#include <list>
#include <set>
@@ -23,10 +22,7 @@
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
-
-#if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L
-# define STDLIB_HAS_UNIFORM_ERASURE
-#endif
+#include <q20vector.h> // For reference
QT_BEGIN_NAMESPACE
std::ostream &operator<<(std::ostream &os, const QChar &c)
@@ -332,14 +328,36 @@ private Q_SLOTS:
void resize_QByteArray() { resize_impl<QByteArray>(); }
private:
- template<typename Container>
+ template <typename Container>
+ void copesWithValueTypesWithConstMembers_impl();
+
+ struct ConstMember {
+ #ifndef __cpp_aggregate_paren_init // also check that we can emplace aggregates (C++20 only)
+ explicit ConstMember(int n) : n(n) {}
+ #endif
+ const int n;
+
+ friend bool operator==(const ConstMember &lhs, const ConstMember &rhs) noexcept
+ { return lhs.n == rhs.n; }
+ friend bool operator!=(const ConstMember &lhs, const ConstMember &rhs) noexcept
+ { return !(lhs == rhs); }
+ };
+
+private Q_SLOTS:
+ void copesWithValueTypesWithConstMembers_std_vector() { copesWithValueTypesWithConstMembers_impl<std::vector<ConstMember>>(); }
+ void copesWithValueTypesWithConstMembers_QVarLengthArray() { copesWithValueTypesWithConstMembers_impl<QVarLengthArray<ConstMember, 2>>(); }
+
+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>>(); };
+ void assign_std_vector() { assign_impl<std::vector<int>>(); };
+ void assign_std_string() { assign_impl<std::string>(); }
+ void assign_QVarLengthArray() { assign_impl<QVarLengthArray<int, 4>>(); };
+ void assign_QList() { assign_impl<QList<int>>(); }
+ void assign_QByteArray() { assign_impl<QByteArray>(); }
+ void assign_QString() { assign_impl<QString>(); }
private:
template <typename Container>
@@ -378,22 +396,14 @@ private Q_SLOTS:
void erase_QVarLengthArray() { erase_impl<QVarLengthArray<int>>(); }
void erase_QString() { erase_impl<QString>(); }
void erase_QByteArray() { erase_impl<QByteArray>(); }
- void erase_std_vector() {
-#ifdef STDLIB_HAS_UNIFORM_ERASURE
- erase_impl<std::vector<int>>();
-#endif
- }
+ void erase_std_vector() { erase_impl<std::vector<int>>(); }
void erase_if_QList() { erase_if_impl<QList<int>>(); }
void erase_if_QVarLengthArray() { erase_if_impl<QVarLengthArray<int>>(); }
void erase_if_QSet() { erase_if_impl<QSet<int>>(); }
void erase_if_QString() { erase_if_impl<QString>(); }
void erase_if_QByteArray() { erase_if_impl<QByteArray>(); }
- void erase_if_std_vector() {
-#ifdef STDLIB_HAS_UNIFORM_ERASURE
- erase_if_impl<std::vector<int>>();
-#endif
- }
+ void erase_if_std_vector() { erase_if_impl<std::vector<int>>(); }
void erase_if_QMap() { erase_if_associative_impl<QMap<int, int>>(); }
void erase_if_QMultiMap() {erase_if_associative_impl<QMultiMap<int, int>>(); }
void erase_if_QHash() { erase_if_associative_impl<QHash<int, int>>(); }
@@ -720,7 +730,8 @@ Container make(int size)
Container c;
c.reserve(size);
using V = typename Container::value_type;
- std::generate_n(std::inserter(c, c.end()), size, [i = 1]() mutable { return V(i++); });
+ int i = 0;
+ std::generate_n(std::inserter(c, c.end()), size, [&i] { return V(++i); });
return c;
}
@@ -753,7 +764,7 @@ void tst_ContainerApiSymmetry::resize_impl() const
auto c = make<Container>(3);
QCOMPARE(c.size(), S(3));
c.resize(4, V(5));
- QCOMPARE(c.size(), S(4));
+ QCOMPARE(std::size(c), S(4));
QCOMPARE(c.back(), V(5));
// ctor/resize symmetry:
@@ -769,29 +780,115 @@ void tst_ContainerApiSymmetry::resize_impl() const
}
}
+template <typename T>
+[[maybe_unused]]
+constexpr bool is_vector_v = false;
+template <typename...Args>
+constexpr bool is_vector_v<std::vector<Args...>> = true;
+
+template <typename Container, typename Value>
+void wrap_resize(Container &c, typename Container::size_type n, const Value &v)
+{
+#ifdef __GLIBCXX__ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981
+ if constexpr (is_vector_v<Container>) {
+ while (c.size() < n)
+ c.push_back(v);
+ } else
+#endif
+ {
+ c.resize(n, v);
+ }
+}
+
+template <typename Container>
+void tst_ContainerApiSymmetry::copesWithValueTypesWithConstMembers_impl()
+{
+ // The problem:
+ //
+ // using V = ConstMember;
+ // V v{42};
+ // assert(v.n == 42); // OK
+ // new (&v) V{24};
+ // assert(v.n == 24); // UB in C++17: v.n could still be 42 (C++17 [basic.life]/8)
+ // // OK in C++20 (C++20 [basic.life]/8)
+ // assert(std::launder(&v)->n == 24); // OK
+ // assert(v.n == 24); // _still_ UB!
+ //
+ // Containers:
+ // - must not expose this problem
+ // - must compile in the first place, even though V
+ // - is not assignable
+ // - is not default-constructible
+
+ using S = typename Container::size_type;
+ using V = typename Container::value_type;
+
+ Container c;
+ // the following are all functions that by rights should not require the type to be
+ // - default-constructible
+ // - assignable
+ // make sure they work
+ c.reserve(S(5));
+ c.shrink_to_fit();
+ wrap_resize(c, 1, V(42));
+ QCOMPARE(c[0], V(42));
+ wrap_resize(c, 2, V(48));
+ QCOMPARE(c[0], V(42));
+ QCOMPARE(c[1], V(48));
+ c.clear();
+ c.emplace_back(24);
+ QCOMPARE(c.front(), V(24));
+ c.push_back(V(41));
+ QCOMPARE(c.back(), V(41));
+ {
+ const auto v142 = V(142);
+ c.push_back(v142);
+ }
+ QCOMPARE(c.size(), S(3));
+ QCOMPARE(c[0], V(24));
+ QCOMPARE(c[1], V(41));
+ QCOMPARE(c[2], V(142));
+}
+
template <typename Container>
void tst_ContainerApiSymmetry::assign_impl() const
{
-#define CHECK(Arr, ComparisonData, Sz_n, Sz_e, Cap_n, Cap_e) \
+#define CHECK(Arr, ComparisonData, Sz_n, Sz_e) \
QCOMPARE(Sz_n, Sz_e); \
- QCOMPARE(Cap_n, Cap_e); \
for (const auto &e : Arr) \
QCOMPARE(e, ComparisonData) \
/*end*/
+#define RET_CHECK(...) \
+ do { \
+ if constexpr (std::is_void_v<decltype( __VA_ARGS__ )>) { \
+ /* e.g. std::vector */ \
+ __VA_ARGS__ ; \
+ } else { \
+ /* e.g. std::basic_string */ \
+ auto &&r = __VA_ARGS__ ; \
+ QCOMPARE_EQ(&r, &c); \
+ } \
+ } while (false) \
+ /* end */
using V = typename Container::value_type;
using S = typename Container::size_type;
- auto tData = V(9);
+ auto tData = V(65);
{
// fill version
auto c = make<Container>(4);
- c.assign(4, tData);
- CHECK(c, tData, c.size(), S(4), c.capacity(), S(4));
+ const S oldCapacity = c.capacity();
+ RET_CHECK(c.assign(4, tData));
+ CHECK(c, tData, c.size(), S(4));
+ QCOMPARE_EQ(c.capacity(), oldCapacity);
- c.assign(8, tData);
- CHECK(c, tData, c.size(), S(8), c.capacity(), S(8));
+ tData = V(66);
+ c.assign(8, tData); // may reallocate
+ CHECK(c, tData, c.size(), S(8));
+ const S grownCapacity = c.capacity();
c.assign(0, tData);
- CHECK(c, tData, c.size(), S(0), c.capacity(), S(8));
+ CHECK(c, tData, c.size(), S(0));
+ QCOMPARE_EQ(c.capacity(), grownCapacity);
}
{
// range version for non input iterator
@@ -799,38 +896,52 @@ void tst_ContainerApiSymmetry::assign_impl() const
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));
+ RET_CHECK(c.assign(iter.begin(), iter.end())); // may reallocate
+ CHECK(c, tData, c.size(), S(8));
+
+ const S oldCapacity = c.capacity();
+ c.assign(iter.begin(), iter.begin());
+ CHECK(c, tData, c.size(), S(0));
+ QCOMPARE_EQ(c.capacity(), oldCapacity);
}
{
// range version for input iterator
auto c = make<Container>(4);
+ const S oldCapacity = c.capacity();
- 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));
+ std::stringstream ss;
+ ss << tData << ' ' << tData << ' ';
+ RET_CHECK(c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{}));
+ CHECK(c, tData, c.size(), S(2));
+ QCOMPARE_EQ(c.capacity(), oldCapacity);
ss.str("");
ss.clear();
- ss << "9 9 9 9 ";
+ tData = V(66);
+ ss << tData << ' ' << tData << ' ' << tData << ' ' << tData << ' ';
c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{});
- CHECK(c, tData, c.size(), S(4), c.capacity(), S(4));
+ CHECK(c, tData, c.size(), S(4));
+ QCOMPARE_EQ(c.capacity(), oldCapacity);
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));
+ tData = V(67);
+ ss << tData << ' ' << tData << ' ' << tData << ' ' << tData << ' '
+ << tData << ' ' << tData << ' ' << tData << ' ';
+ c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{}); // may reallocate
+ CHECK(c, tData, c.size(), S(7));
}
{
// initializer-list version
auto c = make<Container>(4);
+ const S oldCapacity = c.capacity();
std::initializer_list<V> list = {tData, tData, tData};
- c.assign(list);
- CHECK(c, tData, c.size(), S(3), c.capacity(), S(4));
+ RET_CHECK(c.assign(list));
+ CHECK(c, tData, c.size(), S(3));
+ QCOMPARE_EQ(c.capacity(), oldCapacity);
}
+#undef RET_CHECK
#undef CHECK
}
@@ -867,6 +978,7 @@ void tst_ContainerApiSymmetry::erase_impl() const
auto c = make<Container>(7); // {1, 2, 3, 4, 5, 6, 7}
QCOMPARE(c.size(), S(7));
+ using q20::erase; // For std::vector
auto result = erase(c, V(1));
QCOMPARE(result, S(1));
QCOMPARE(c.size(), S(6));
@@ -892,7 +1004,10 @@ void tst_ContainerApiSymmetry::erase_if_impl() const
oldSize = c.size();
count = 0;
- auto result = erase_if(c, [&](V i) { ++count; return Conv::toInt(i) % 2 == 0; });
+
+ using q20::erase_if; // For std::vector
+
+ S 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);
diff --git a/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt b/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt
index f7b0238b0a..9e87144a4c 100644
--- a/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qalgorithms/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qalgorithms Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qalgorithms LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qalgorithms
SOURCES
tst_qalgorithms.cpp
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index 8eb5392eb0..8d68a7a270 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "../../../../../src/corelib/tools/qalgorithms.h"
#include <QTest>
diff --git a/tests/auto/corelib/tools/qarraydata/CMakeLists.txt b/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
index 9133d1bd8c..1d84630de2 100644
--- a/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qarraydata/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qarraydata Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qarraydata LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qarraydata
EXCEPTIONS
SOURCES
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index f433743911..b92cd4a887 100644
--- a/tests/auto/corelib/tools/qarraydata/simplevector.h
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QARRAY_TEST_SIMPLE_VECTOR_H
@@ -28,7 +28,7 @@ public:
}
explicit SimpleVector(size_t n, bool capacityReserved = false)
- : d(Data::allocate(n))
+ : d(n)
{
if (n)
d->appendInitialize(n);
@@ -37,7 +37,7 @@ public:
}
SimpleVector(size_t n, const T &t, bool capacityReserved = false)
- : d(Data::allocate(n))
+ : d(n)
{
if (n)
d->copyAppend(n, t);
@@ -46,7 +46,7 @@ public:
}
SimpleVector(const T *begin, const T *end, bool capacityReserved = false)
- : d(Data::allocate(end - begin))
+ : d(end - begin)
{
if (end - begin)
d->copyAppend(begin, end);
@@ -59,11 +59,6 @@ public:
{
}
- explicit SimpleVector(QPair<Data*, T*> ptr, size_t len = 0)
- : d(ptr, len)
- {
- }
-
SimpleVector(const QArrayDataPointer<T> &other)
: d(other)
{
@@ -135,7 +130,7 @@ public:
}
}
- SimpleVector detached(Data::allocate(qMax(n, size())));
+ SimpleVector detached(DataPointer(qMax(n, size())));
if (size()) {
detached.d->copyAppend(constBegin(), constEnd());
detached.d->setFlag(QArrayData::CapacityReserved);
@@ -149,7 +144,7 @@ public:
return;
if (d->needsDetach() || newSize > capacity()) {
- SimpleVector detached(Data::allocate(d->detachCapacity(newSize)));
+ SimpleVector detached(DataPointer(d->detachCapacity(newSize)));
if (newSize) {
if (newSize < size()) {
const T *const begin = constBegin();
@@ -223,7 +218,7 @@ public:
const T *const end = begin + d->size;
if (d->needsDetach()) {
- SimpleVector detached(Data::allocate(d->detachCapacity(size() - (last - first))));
+ SimpleVector detached(DataPointer(d->detachCapacity(size() - (last - first))));
if (first != begin)
detached.d->copyAppend(begin, first);
detached.d->copyAppend(last, end);
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index 987cee0349..e7a84d57ee 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -1,6 +1,7 @@
// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <QtCore/QString>
@@ -106,8 +107,8 @@ void tst_QArrayData::simpleVector()
SimpleVector<int> v4(nullptr, data, 0);
SimpleVector<int> v5(nullptr, data, 1);
SimpleVector<int> v6(nullptr, data, 7);
- SimpleVector<int> v7(10, 5);
- SimpleVector<int> v8(array, array + sizeof(array)/sizeof(*array));
+ const SimpleVector<int> v7(10, 5);
+ const SimpleVector<int> v8(array, array + sizeof(array)/sizeof(*array));
v3 = v1;
v1.swap(v3);
@@ -235,7 +236,7 @@ void tst_QArrayData::simpleVector()
{
int count = 0;
- Q_FOREACH (int value, v7) {
+ for (int value : v7) {
QCOMPARE(value, 5);
++count;
}
@@ -245,7 +246,7 @@ void tst_QArrayData::simpleVector()
{
int count = 0;
- Q_FOREACH (int value, v8) {
+ for (int value : v8) {
QCOMPARE(value, count);
++count;
}
@@ -483,7 +484,7 @@ void tst_QArrayData::allocate()
keeper.headers.append(data);
if (grow)
- QVERIFY(data->allocatedCapacity() > capacity);
+ QCOMPARE_GE(data->allocatedCapacity(), capacity);
else
QCOMPARE(data->allocatedCapacity(), capacity);
@@ -1115,8 +1116,7 @@ void tst_QArrayData::arrayOpsExtra()
const auto cloneArrayDataPointer = [] (auto &dataPointer, size_t capacity) {
using ArrayPointer = std::decay_t<decltype(dataPointer)>;
- using Type = std::decay_t<typename ArrayPointer::parameter_type>;
- ArrayPointer copy(QTypedArrayData<Type>::allocate(qsizetype(capacity)));
+ ArrayPointer copy{qsizetype(capacity)};
copy->copyAppend(dataPointer.begin(), dataPointer.end());
return copy;
};
@@ -2036,7 +2036,7 @@ void tst_QArrayData::dataPointerAllocate()
const auto createDataPointer = [] (qsizetype capacity, auto initValue) {
using Type = std::decay_t<decltype(initValue)>;
Q_UNUSED(initValue);
- return QArrayDataPointer<Type>(QTypedArrayData<Type>::allocate(capacity));
+ return QArrayDataPointer<Type>(capacity);
};
const auto testRealloc = [&] (qsizetype capacity, qsizetype newSize, auto initValue) {
@@ -2452,7 +2452,7 @@ void tst_QArrayData::relocateWithExceptions()
};
const auto createDataPointer = [](qsizetype capacity, qsizetype initSize) {
- QArrayDataPointer<ThrowingType> qadp(QTypedArrayData<ThrowingType>::allocate(capacity));
+ QArrayDataPointer<ThrowingType> qadp(capacity);
qadp->appendInitialize(initSize);
int i = 0;
std::generate(qadp.begin(), qadp.end(), [&i]() { return ThrowingType(i++); });
diff --git a/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt b/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt
index b6f29d5b7f..b20e56421f 100644
--- a/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qatomicscopedvaluerollback/CMakeLists.txt
@@ -1,9 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qatomicscopedvaluerollback LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
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
index 81d8242f71..89bd1d7ff6 100644
--- a/tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp
+++ b/tests/auto/corelib/tools/qatomicscopedvaluerollback/tst_qatomicscopedvaluerollback.cpp
@@ -1,7 +1,7 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-#include <QtCore/private/qatomicscopedvaluerollback_p.h>
+#include <QtCore/qatomicscopedvaluerollback.h>
#include <QTest>
@@ -24,23 +24,30 @@ void tst_QAtomicScopedValueRollback::leavingScope()
QAtomicInt i = 0;
QBasicAtomicInteger<bool> b = false;
std::atomic<bool> b2 = false;
+ int x = 0, y = 42;
+ QBasicAtomicPointer<int> p = &x;
//test rollback on going out of scope
{
QAtomicScopedValueRollback ri(i);
QAtomicScopedValueRollback rb(b);
QAtomicScopedValueRollback rb2(b2, true);
+ QAtomicScopedValueRollback rp(p);
QCOMPARE(b.loadRelaxed(), false);
QCOMPARE(b2, true);
QCOMPARE(i.loadRelaxed(), 0);
+ QCOMPARE(p.loadRelaxed(), &x);
b.storeRelaxed(true);
i.storeRelaxed(1);
+ p.storeRelaxed(&y);
QCOMPARE(b.loadRelaxed(), true);
QCOMPARE(i.loadRelaxed(), 1);
+ QCOMPARE(p.loadRelaxed(), &y);
}
QCOMPARE(b.loadRelaxed(), false);
QCOMPARE(b2, false);
QCOMPARE(i.loadRelaxed(), 0);
+ QCOMPARE(p.loadRelaxed(), &x);
}
void tst_QAtomicScopedValueRollback::leavingScopeAfterCommit()
diff --git a/tests/auto/corelib/tools/qbitarray/CMakeLists.txt b/tests/auto/corelib/tools/qbitarray/CMakeLists.txt
index 3c3a5db142..ac3bd24bd5 100644
--- a/tests/auto/corelib/tools/qbitarray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qbitarray/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qbitarray Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qbitarray LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qbitarray
SOURCES
tst_qbitarray.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp
index b205bb76ee..f52a368aa9 100644
--- a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp
+++ b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp
@@ -1,12 +1,16 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
#include <QtCore/QBuffer>
#include <QtCore/QDataStream>
#include "qbitarray.h"
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qscopeguard.h>
+
/**
* Helper function to initialize a bitarray from a string
*/
@@ -26,10 +30,18 @@ static QBitArray QStringToQBitArray(const QString &str)
return ba;
}
+static QBitArray detached(QBitArray a)
+{
+ a.detach();
+ return a;
+}
+
class tst_QBitArray : public QObject
{
Q_OBJECT
private slots:
+ void compareCompiles();
+ void canHandleIntMaxBits();
void size_data();
void size();
void countBits_data();
@@ -43,12 +55,21 @@ private slots:
// operator &=
void operator_andeq_data();
void operator_andeq();
+ // operator &
+ void operator_and_data() { operator_andeq_data(); }
+ void operator_and();
// operator |=
void operator_oreq_data();
void operator_oreq();
+ // operator |
+ void operator_or_data() { operator_oreq_data(); }
+ void operator_or();
// operator ^=
void operator_xoreq_data();
void operator_xoreq();
+ // operator ^
+ void operator_xor_data() { operator_xoreq_data(); }
+ void operator_xor();
// operator ~
void operator_neg_data();
void operator_neg();
@@ -66,6 +87,59 @@ private slots:
void toUInt32();
};
+void tst_QBitArray::compareCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QBitArray>();
+}
+
+void tst_QBitArray::canHandleIntMaxBits()
+{
+ QElapsedTimer timer;
+ timer.start();
+ const auto print = qScopeGuard([&] {
+ qDebug("Function took %lldms", qlonglong(timer.elapsed()));
+ });
+
+ try {
+ constexpr qsizetype Size1 = sizeof(void*) > sizeof(int) ? qsizetype(INT_MAX) + 2 :
+ INT_MAX - 2;
+ constexpr qsizetype Size2 = Size1 + 2;
+
+ QBitArray ba(Size1, true);
+ QCOMPARE(ba.size(), Size1);
+ QCOMPARE(ba.at(Size1 - 1), true);
+
+ ba.resize(Size2);
+ QCOMPARE(ba.size(), Size2);
+ QCOMPARE(ba.at(Size1 - 1), true);
+ QCOMPARE(ba.at(Size1), false);
+ QCOMPARE(ba.at(Size2 - 1), false);
+
+ QByteArray serialized;
+ if constexpr (sizeof(void*) > sizeof(int)) {
+ QDataStream ds(&serialized, QIODevice::WriteOnly);
+ ds.setVersion(QDataStream::Qt_5_15);
+ ds << ba;
+ QCOMPARE(ds.status(), QDataStream::Status::SizeLimitExceeded);
+ serialized.clear();
+ }
+ {
+ QDataStream ds(&serialized, QIODevice::WriteOnly);
+ ds << ba;
+ QCOMPARE(ds.status(), QDataStream::Status::Ok);
+ }
+ {
+ QDataStream ds(serialized);
+ QBitArray ba2;
+ ds >> ba2;
+ QCOMPARE(ds.status(), QDataStream::Status::Ok);
+ QT_TEST_EQUALITY_OPS(ba, ba2, true);
+ }
+ } catch (const std::bad_alloc &) {
+ QSKIP("Failed to allocate sufficient memory");
+ }
+}
+
void tst_QBitArray::size_data()
{
//create the testtable instance and define the elements
@@ -199,14 +273,20 @@ void tst_QBitArray::isEmpty()
QVERIFY(!a1.isEmpty());
QVERIFY(!a1.isNull());
QVERIFY(a1.size() == 2);
+
+ QT_TEST_EQUALITY_OPS(a1, a2, false);
+ QT_TEST_EQUALITY_OPS(a2, a3, false);
+ QT_TEST_EQUALITY_OPS(QBitArray(), QBitArray(), true);
+ a3 = a2;
+ QT_TEST_EQUALITY_OPS(a2, a3, true);
}
void tst_QBitArray::swap()
{
QBitArray b1 = QStringToQBitArray("1"), b2 = QStringToQBitArray("10");
b1.swap(b2);
- QCOMPARE(b1,QStringToQBitArray("10"));
- QCOMPARE(b2,QStringToQBitArray("1"));
+ QT_TEST_EQUALITY_OPS(b1,QStringToQBitArray("10"), true);
+ QT_TEST_EQUALITY_OPS(b2,QStringToQBitArray("1"), true);
}
void tst_QBitArray::fill()
@@ -256,7 +336,7 @@ void tst_QBitArray::toggleBit()
input.toggleBit(index);
- QCOMPARE(input, res);
+ QT_TEST_EQUALITY_OPS(input, res, true);
}
void tst_QBitArray::operator_andeq_data()
@@ -301,9 +381,64 @@ void tst_QBitArray::operator_andeq()
QFETCH(QBitArray, input2);
QFETCH(QBitArray, res);
- input1&=input2;
+ QBitArray result = input1;
+ result &= input2;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1;
+ result &= std::move(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1;
+ result &= detached(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is commutative
+ result = input2;
+ result &= input1;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2;
+ result &= std::move(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2;
+ result &= detached(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is idempotent
+ result &= result;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result &= std::move(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result &= detached(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+}
+
+void tst_QBitArray::operator_and()
+{
+ QFETCH(QBitArray, input1);
+ QFETCH(QBitArray, input2);
+ QFETCH(QBitArray, res);
- QCOMPARE(input1, res);
+ QBitArray result = input1 & input2;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1 & QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1 & detached(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is commutative
+ result = input2 & input1;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2 & QBitArray(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2 & detached(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is idempotent
+ result = result & result;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = result & QBitArray(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = result & detached(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
}
void tst_QBitArray::operator_oreq_data()
@@ -352,9 +487,64 @@ void tst_QBitArray::operator_oreq()
QFETCH(QBitArray, input2);
QFETCH(QBitArray, res);
- input1|=input2;
+ QBitArray result = input1;
+ result |= input2;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1;
+ result |= QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1;
+ result |= detached(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is commutative
+ result = input2;
+ result |= input1;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2;
+ result |= QBitArray(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2;
+ result |= detached(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is idempotent
+ result |= result;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result |= QBitArray(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result |= detached(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+}
+
+void tst_QBitArray::operator_or()
+{
+ QFETCH(QBitArray, input1);
+ QFETCH(QBitArray, input2);
+ QFETCH(QBitArray, res);
- QCOMPARE(input1, res);
+ QBitArray result = input1 | input2;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1 | QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1 | detached(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is commutative
+ result = input2 | input1;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2 | QBitArray(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2 | detached(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is idempotent
+ result = result | result;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = result | QBitArray(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = result | detached(result);
+ QT_TEST_EQUALITY_OPS(result, res, true);
}
void tst_QBitArray::operator_xoreq_data()
@@ -401,11 +591,102 @@ void tst_QBitArray::operator_xoreq()
QFETCH(QBitArray, input2);
QFETCH(QBitArray, res);
- input1^=input2;
-
- QCOMPARE(input1, res);
+ QBitArray result = input1;
+ result ^= input2;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1;
+ result ^= QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1;
+ result ^= detached(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is commutative
+ result = input2;
+ result ^= input1;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2;
+ result ^= QBitArray(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2;
+ result ^= detached(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // XORing with oneself is nilpotent
+ result = input1;
+ result ^= input1;
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input1.size()), true);
+ result = input1;
+ result ^= QBitArray(result);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input1.size()), true);
+ result = input1;
+ result ^= detached(result);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input1.size()), true);
+
+ result = input2;
+ result ^= input2;
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input2.size()), true);
+ result = input2;
+ result ^= QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input2.size()), true);
+ result = input2;
+ result ^= detached(input2);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input2.size()), true);
+
+ result = res;
+ result ^= res;
+ QT_TEST_EQUALITY_OPS(result, QBitArray(res.size()), true);
+ result = res;
+ result ^= QBitArray(res);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(res.size()), true);
+ result = res;
+ result ^= detached(res);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(res.size()), true);
}
+void tst_QBitArray::operator_xor()
+{
+ QFETCH(QBitArray, input1);
+ QFETCH(QBitArray, input2);
+ QFETCH(QBitArray, res);
+
+ QBitArray result = input1 ^ input2;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1 ^ QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input1 ^ detached(input2);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // operation is commutative
+ result = input2 ^ input1;
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2 ^ QBitArray(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+ result = input2 ^ detached(input1);
+ QT_TEST_EQUALITY_OPS(result, res, true);
+
+ // XORing with oneself is nilpotent
+ result = input1 ^ input1;
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input1.size()), true);
+ result = input1 ^ QBitArray(input1);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input1.size()), true);
+ result = input1 ^ detached(input1);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input1.size()), true);
+
+ result = input2 ^ input2;
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input2.size()), true);
+ result = input2 ^ QBitArray(input2);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input2.size()), true);
+ result = input2 ^ detached(input2);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(input2.size()), true);
+
+ result = res ^ res;
+ QT_TEST_EQUALITY_OPS(result, QBitArray(res.size()), true);
+ result = res ^ QBitArray(res);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(res.size()), true);
+ result = res ^ detached(res);
+ QT_TEST_EQUALITY_OPS(result, QBitArray(res.size()), true);
+}
void tst_QBitArray::operator_neg_data()
{
@@ -453,7 +734,8 @@ void tst_QBitArray::operator_neg()
input = ~input;
- QCOMPARE(input, res);
+ QT_TEST_EQUALITY_OPS(input, res, true);
+ QT_TEST_EQUALITY_OPS(~~input, res, true); // performs two in-place negations
}
void tst_QBitArray::datastream_data()
@@ -513,15 +795,15 @@ void tst_QBitArray::datastream()
QCOMPARE(array1.count(true), onBits);
QCOMPARE(array1.count(false), numBits - onBits);
- QCOMPARE(array1, bits);
- QCOMPARE(array2, bits);
- QCOMPARE(array3, bits);
+ QT_TEST_EQUALITY_OPS(array1, bits, true);
+ QT_TEST_EQUALITY_OPS(array2, bits, true);
+ QT_TEST_EQUALITY_OPS(array3, bits, true);
}
void tst_QBitArray::invertOnNull() const
{
QBitArray a;
- QCOMPARE(a = ~a, QBitArray());
+ QT_TEST_EQUALITY_OPS(a = ~a, QBitArray(), true);
}
void tst_QBitArray::operator_noteq_data()
@@ -562,7 +844,7 @@ void tst_QBitArray::operator_noteq()
QFETCH(bool, res);
bool b = input1 != input2;
- QCOMPARE(b, res);
+ QT_TEST_EQUALITY_OPS(b, res, true);
}
void tst_QBitArray::resize()
@@ -571,22 +853,22 @@ void tst_QBitArray::resize()
QBitArray a = QStringToQBitArray(QString("11"));
a.resize(10);
QVERIFY(a.size() == 10);
- QCOMPARE( a, QStringToQBitArray(QString("1100000000")) );
+ QT_TEST_EQUALITY_OPS( a, QStringToQBitArray(QString("1100000000")), true);
a.setBit(9);
a.resize(9);
// now the bit in a should have been gone:
- QCOMPARE( a, QStringToQBitArray(QString("110000000")) );
+ QT_TEST_EQUALITY_OPS( a, QStringToQBitArray(QString("110000000")), true);
// grow the array back and check the new bit
a.resize(10);
- QCOMPARE( a, QStringToQBitArray(QString("1100000000")) );
+ QT_TEST_EQUALITY_OPS( a, QStringToQBitArray(QString("1100000000")), true);
// other test with and
a.resize(9);
QBitArray b = QStringToQBitArray(QString("1111111111"));
b &= a;
- QCOMPARE( b, QStringToQBitArray(QString("1100000000")) );
+ QT_TEST_EQUALITY_OPS( b, QStringToQBitArray(QString("1100000000")), true);
}
@@ -640,9 +922,9 @@ void tst_QBitArray::fromBits()
QFETCH(QBitArray, expected);
QBitArray fromBits = QBitArray::fromBits(data, size);
- QCOMPARE(fromBits, expected);
+ QT_TEST_EQUALITY_OPS(fromBits, expected, true);
- QCOMPARE(QBitArray::fromBits(fromBits.bits(), fromBits.size()), expected);
+ QT_TEST_EQUALITY_OPS(QBitArray::fromBits(fromBits.bits(), fromBits.size()), expected, true);
}
void tst_QBitArray::toUInt32_data()
diff --git a/tests/auto/corelib/tools/qcache/CMakeLists.txt b/tests/auto/corelib/tools/qcache/CMakeLists.txt
index b51c1b1469..8ffe942d70 100644
--- a/tests/auto/corelib/tools/qcache/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcache/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qcache Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcache LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcache
SOURCES
tst_qcache.cpp
diff --git a/tests/auto/corelib/tools/qcache/tst_qcache.cpp b/tests/auto/corelib/tools/qcache/tst_qcache.cpp
index 0e018e18b8..5fccb8f1d0 100644
--- a/tests/auto/corelib/tools/qcache/tst_qcache.cpp
+++ b/tests/auto/corelib/tools/qcache/tst_qcache.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt b/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt
index 89c1e99a33..5aa8bd2500 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcommandlineparser/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qcommandlineparser Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcommandlineparser LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcommandlineparser
SOURCES
tst_qcommandlineparser.cpp
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 758251f05a..b5f178a3d1 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
@@ -1,5 +1,5 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 6252440232..812cf2d1b3 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
@@ -1,6 +1,6 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#if QT_CONFIG(process)
@@ -126,6 +126,7 @@ void tst_QCommandLineParser::testBooleanOption()
QVERIFY(parser.parse(args));
QCOMPARE(parser.optionNames(), expectedOptionNames);
QCOMPARE(parser.isSet("b"), expectedIsSet);
+ QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not expecting values: \"b\"");
QCOMPARE(parser.values("b"), QStringList());
QCOMPARE(parser.positionalArguments(), QStringList());
// Should warn on typos
@@ -163,6 +164,7 @@ void tst_QCommandLineParser::testOptionsAndPositional()
QVERIFY(parser.parse(args));
QCOMPARE(parser.optionNames(), expectedOptionNames);
QCOMPARE(parser.isSet("b"), expectedIsSet);
+ QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not expecting values: \"b\"");
QCOMPARE(parser.values("b"), QStringList());
QCOMPARE(parser.positionalArguments(), expectedPositionalArguments);
}
@@ -361,6 +363,7 @@ void tst_QCommandLineParser::testProcessNotCalled()
QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: call process() or parse() before isSet");
QVERIFY(!parser.isSet("b"));
QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: call process() or parse() before values");
+ QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not expecting values: \"b\"");
QCOMPARE(parser.values("b"), QStringList());
}
@@ -448,37 +451,40 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes_data()
QTest::addColumn<QStringList>("commandLine");
QTest::addColumn<QStringList>("expectedOptionNames");
QTest::addColumn<QStringList>("expectedOptionValues");
+ QTest::addColumn<QStringList>("invalidOptionValues");
QTest::newRow("collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-abc" << "val")
- << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val");
+ << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val")
+ << (QStringList() << "a" << "b");
QTest::newRow("collapsed_with_equalsign_value") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-abc=val")
- << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val");
+ << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val")
+ << (QStringList() << "a" << "b");
QTest::newRow("collapsed_explicit_longoption") << QCommandLineParser::ParseAsCompactedShortOptions << QStringList("--nn")
- << QStringList("nn") << QStringList();
+ << QStringList("nn") << QStringList() << QStringList();
QTest::newRow("collapsed_longoption_value") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "--abc" << "val")
- << QStringList("abc") << QStringList("val");
+ << QStringList("abc") << QStringList("val") << QStringList();
QTest::newRow("compiler") << QCommandLineParser::ParseAsCompactedShortOptions << QStringList("-cab")
- << QStringList("c") << QStringList("ab");
+ << QStringList("c") << QStringList("ab") << QStringList();
QTest::newRow("compiler_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val")
- << QStringList("c") << QStringList("val");
+ << QStringList("c") << QStringList("val") << QStringList();
QTest::newRow("implicitlylong") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-abc" << "val")
- << QStringList("abc") << QStringList("val");
+ << QStringList("abc") << QStringList("val") << QStringList();
QTest::newRow("implicitlylong_equal") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-abc=val")
- << QStringList("abc") << QStringList("val");
+ << QStringList("abc") << QStringList("val") << QStringList();
QTest::newRow("implicitlylong_longoption") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "--nn")
- << QStringList("nn") << QStringList();
+ << QStringList("nn") << QStringList() << QStringList();
QTest::newRow("implicitlylong_longoption_value") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "--abc" << "val")
- << QStringList("abc") << QStringList("val");
+ << QStringList("abc") << QStringList("val") << QStringList();
QTest::newRow("implicitlylong_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val")
- << QStringList("c") << QStringList("val");
+ << QStringList("c") << QStringList("val") << QStringList();
QTest::newRow("forceshort_detached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I" << "45")
- << QStringList("I") << QStringList("45");
+ << QStringList("I") << QStringList("45") << QStringList();
QTest::newRow("forceshort_attached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I46")
- << QStringList("I") << QStringList("46");
+ << QStringList("I") << QStringList("46") << QStringList();
QTest::newRow("forceshort_mixed") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I45" << "-nn")
- << (QStringList() << "I" << "nn") << QStringList("45");
+ << (QStringList() << "I" << "nn") << QStringList("45") << QStringList();
}
void tst_QCommandLineParser::testSingleDashWordOptionModes()
@@ -487,6 +493,7 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes()
QFETCH(QStringList, commandLine);
QFETCH(QStringList, expectedOptionNames);
QFETCH(QStringList, expectedOptionValues);
+ QFETCH(QStringList, invalidOptionValues);
commandLine.prepend("tst_QCommandLineParser");
@@ -503,14 +510,19 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes()
QVERIFY(parser.addOption(forceShort));
QVERIFY(parser.parse(commandLine));
QCOMPARE(parser.optionNames(), expectedOptionNames);
- for (int i = 0; i < expectedOptionValues.size(); ++i)
- QCOMPARE(parser.value(parser.optionNames().at(i)), expectedOptionValues.at(i));
+ for (int i = 0; i < expectedOptionValues.size(); ++i) {
+ const QString option = parser.optionNames().at(i);
+ if (invalidOptionValues.contains(option)) {
+ QByteArray msg = QLatin1String("QCommandLineParser: option not expecting values: \"%1\"").arg(option).toLatin1();
+ QTest::ignoreMessage(QtWarningMsg, msg.data());
+ }
+ QCOMPARE(parser.value(option), expectedOptionValues.at(i));
+ }
QCOMPARE(parser.unknownOptionNames(), QStringList());
}
void tst_QCommandLineParser::testCpp11StyleInitialization()
{
-#if defined(Q_COMPILER_UNIFORM_INIT)
QCoreApplication app(empty_argc, empty_argv);
QCommandLineParser parser;
@@ -524,9 +536,6 @@ void tst_QCommandLineParser::testCpp11StyleInitialization()
QVERIFY(parser.parse({"tst_QCommandLineParser", "-a", "-vvv", "--infile=in.txt"}));
QCOMPARE(parser.optionNames(), (QStringList{"a", "v", "v", "v", "infile"}));
QCOMPARE(parser.value("infile"), QString("in.txt"));
-#else
- QSKIP("This test requires C++11 uniform initialization support in the compiler.");
-#endif
}
void tst_QCommandLineParser::testVersionOption()
@@ -553,7 +562,7 @@ void tst_QCommandLineParser::testVersionOption()
static const char expectedOptionsHelp[] =
"Options:\n"
" -h, --help Displays help on commandline options.\n"
- " --help-all Displays help including Qt specific options.\n"
+ " --help-all Displays help, including generic Qt options.\n"
" -v, --version Displays version information.\n"
" --load <url> Load file from URL.\n"
" -o, --output <file> Set output file.\n"
diff --git a/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt b/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt
index 7f0b53820e..5c32c34023 100644
--- a/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qcontiguouscache Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcontiguouscache LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcontiguouscache
SOURCES
tst_qcontiguouscache.cpp
diff --git a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
index 395ed23cea..ca110b1240 100644
--- a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
+++ b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QObject>
#include <QTest>
diff --git a/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt b/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt
index a32da3dedf..8a0c08fcad 100644
--- a/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qcryptographichash/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qcryptographichash Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcryptographichash LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
index a7c22ffe29..47e0ead270 100644
--- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
+++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QCoreApplication>
@@ -8,9 +8,7 @@
#include <QCryptographicHash>
#include <QtCore/QMetaEnum>
-#if QT_CONFIG(cxx11_future)
-# include <thread>
-#endif
+#include <thread>
Q_DECLARE_METATYPE(QCryptographicHash::Algorithm)
@@ -22,16 +20,20 @@ private slots:
void repeated_result();
void intermediary_result_data();
void intermediary_result();
+ void static_hash_data() { intermediary_result_data(); }
+ void static_hash();
void sha1();
void sha3_data();
void sha3();
+ void keccak();
+ void keccak_data();
void blake2_data();
void blake2();
void files_data();
void files();
- void hashLength_data();
+ void hashLength_data() { all_methods(true); }
void hashLength();
- void addDataAcceptsNullByteArrayView_data() { hashLength_data(); }
+ void addDataAcceptsNullByteArrayView_data() { all_methods(false); }
void addDataAcceptsNullByteArrayView();
void move();
void swap();
@@ -40,6 +42,7 @@ private slots:
void moreThan4GiBOfData();
void keccakBufferOverflow();
private:
+ void all_methods(bool includingNumAlgorithms) const;
void ensureLargeData();
std::vector<char> large;
};
@@ -152,6 +155,27 @@ void tst_QCryptographicHash::intermediary_result_data()
<< QByteArray("abc") << QByteArray("abc")
<< QByteArray::fromHex("B751850B1A57168A5693CD924B6B096E08F621827444F70D884F5D0240D2712E10E116E9192AF3C91A7EC57647E3934057340B4CF408D5A56592F8274EEC53F0")
<< QByteArray::fromHex("BB582DA40D15399ACF62AFCBBD6CFC9EE1DD5129B1EF9935DD3B21668F1A73D7841018BE3B13F281C3A8E9DA7EDB60F57B9F9F1C04033DF4CE3654B7B2ADB310");
+
+ QTest::newRow("keccak_224_abc_abc")
+ << int(QCryptographicHash::Keccak_224)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("c30411768506ebe1c2871b1ee2e87d38df342317300a9b97a95ec6a8")
+ << QByteArray::fromHex("048330e7c7c8b4a41ab713b3a6f958d77b8cf3ee969930f1584dd550");
+ QTest::newRow("keccak_256_abc_abc")
+ << int(QCryptographicHash::Keccak_256)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
+ << QByteArray::fromHex("9f0adad0a59b05d2e04a1373342b10b9eb16c57c164c8a3bfcbf46dccee39a21");
+ QTest::newRow("keccak_384_abc_abc")
+ << int(QCryptographicHash::Keccak_384)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("f7df1165f033337be098e7d288ad6a2f74409d7a60b49c36642218de161b1f99f8c681e4afaf31a34db29fb763e3c28e")
+ << QByteArray::fromHex("d733b87d392d270889d3da23ae113f349e25574b445f319cde4cd3f877c753e9e3c65980421339b3a131457ff393939f");
+ QTest::newRow("keccak_512_abc_abc")
+ << int(QCryptographicHash::Keccak_512)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96")
+ << QByteArray::fromHex("a7c392d2a42155761ca76bddde1c47d55486b007edf465397bfb9dfa74d11c8f0d7c86cd29415283f1b5e7f655cec25b869c9e9c33a8986f0b38542fb12bfb93");
}
void tst_QCryptographicHash::intermediary_result()
@@ -176,6 +200,20 @@ void tst_QCryptographicHash::intermediary_result()
hash.reset();
}
+void tst_QCryptographicHash::static_hash()
+{
+ QFETCH(const int, algo);
+ QFETCH(const QByteArray, first);
+ QFETCH(const QByteArray, hash_first);
+
+ const auto _algo = QCryptographicHash::Algorithm(algo);
+
+ QCOMPARE(QCryptographicHash::hash(first, _algo), hash_first);
+
+ std::byte buffer[1024];
+ QCOMPARE(QCryptographicHash::hashInto(buffer, first, _algo), hash_first);
+}
+
void tst_QCryptographicHash::sha1()
{
@@ -258,6 +296,68 @@ void tst_QCryptographicHash::sha3()
QCOMPARE(result, expectedResult);
}
+void tst_QCryptographicHash::keccak_data()
+{
+ QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
+ QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<QByteArray>("expectedResult");
+
+#define ROW(Tag, Algorithm, Input, Result) \
+ QTest::newRow(Tag) << Algorithm << QByteArrayLiteral(Input) << QByteArray::fromHex(Result)
+
+ ROW("keccak_224_pangram",
+ QCryptographicHash::Keccak_224,
+ "The quick brown fox jumps over the lazy dog",
+ "310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe");
+
+ ROW("keccak_224_pangram_dot",
+ QCryptographicHash::Keccak_224,
+ "The quick brown fox jumps over the lazy dog.",
+ "c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab");
+
+ ROW("keccak_256_pangram",
+ QCryptographicHash::Keccak_256,
+ "The quick brown fox jumps over the lazy dog",
+ "4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15");
+
+ ROW("keccak_256_pangram_dot",
+ QCryptographicHash::Keccak_256,
+ "The quick brown fox jumps over the lazy dog.",
+ "578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d");
+
+ ROW("keccak_384_pangram",
+ QCryptographicHash::Keccak_384,
+ "The quick brown fox jumps over the lazy dog",
+ "283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3");
+
+ ROW("keccak_384_pangram_dot",
+ QCryptographicHash::Keccak_384,
+ "The quick brown fox jumps over the lazy dog.",
+ "9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b");
+
+ ROW("skeccak_512_pangram",
+ QCryptographicHash::Keccak_512,
+ "The quick brown fox jumps over the lazy dog",
+ "d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609");
+
+ ROW("keccak_512_pangram_dot",
+ QCryptographicHash::Keccak_512,
+ "The quick brown fox jumps over the lazy dog.",
+ "ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760");
+
+#undef ROW
+}
+
+void tst_QCryptographicHash::keccak()
+{
+ QFETCH(QCryptographicHash::Algorithm, algorithm);
+ QFETCH(QByteArray, data);
+ QFETCH(QByteArray, expectedResult);
+
+ const auto result = QCryptographicHash::hash(data, algorithm);
+ QCOMPARE(result, expectedResult);
+}
+
void tst_QCryptographicHash::blake2_data()
{
QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
@@ -391,12 +491,14 @@ void tst_QCryptographicHash::files()
}
}
-void tst_QCryptographicHash::hashLength_data()
+void tst_QCryptographicHash::all_methods(bool inclNumAlgos) const
{
QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
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);
+ if (!inclNumAlgos && algorithm == QCryptographicHash::Algorithm::NumAlgorithms)
+ continue;
QTest::addRow("%s", metaEnum.key(i)) << algorithm;
}
}
@@ -412,6 +514,9 @@ void tst_QCryptographicHash::hashLength()
expectedSize = 0;
} else {
expectedSize = QCryptographicHash::hash("test", algorithm).size();
+
+ std::byte buffer[1024];
+ QCOMPARE(QCryptographicHash::hashInto(buffer, "foo", algorithm).size(), expectedSize);
}
QCOMPARE(QCryptographicHash::hashLength(algorithm), expectedSize);
}
@@ -520,14 +625,7 @@ void tst_QCryptographicHash::moreThan4GiBOfData()
{
QFETCH(const QCryptographicHash::Algorithm, algorithm);
-# if QT_CONFIG(cxx11_future)
using MaybeThread = std::thread;
-# else
- struct MaybeThread {
- std::function<void()> func;
- void join() { func(); }
- };
-# endif
QElapsedTimer timer;
timer.start();
diff --git a/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt b/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt
index 39a772ab8c..13645c50b8 100644
--- a/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qduplicatetracker/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qduplicatetracker Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qduplicatetracker LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qduplicatetracker
SOURCES
tst_qduplicatetracker.cpp
diff --git a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
index 8ea4802fa4..ad0b6abbc7 100644
--- a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
+++ b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
@@ -1,11 +1,13 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QtTest>
#include <QtCore/private/qduplicatetracker_p.h>
#include <QObject>
+
+#include <string>
#include <utility>
class tst_QDuplicateTracker : public QObject
@@ -50,6 +52,27 @@ void tst_QDuplicateTracker::hasSeen()
QVERIFY(!tracker.hasSeen(string3));
QVERIFY(tracker.hasSeen(string3));
}
+
+ {
+ QDuplicateTracker<std::string, 2> tracker;
+ std::string string1("string1");
+ std::string string2("string2");
+ std::string string2_2("string2");
+ std::string string3("string3");
+
+ // Move when seen
+ QVERIFY(!tracker.hasSeen(string1));
+ QVERIFY(tracker.hasSeen(std::move(string1)));
+
+ // Move when unseen
+ QVERIFY(!tracker.hasSeen(std::move(string2)));
+ QVERIFY(tracker.hasSeen(string2_2));
+
+ // Past the prealloc amount
+ QVERIFY(!tracker.hasSeen(string3));
+ QVERIFY(tracker.hasSeen(string3));
+ }
+
}
void tst_QDuplicateTracker::clear()
diff --git a/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt b/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt
index 781410c90e..2569e0c7a9 100644
--- a/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qeasingcurve/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qeasingcurve Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qeasingcurve LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qeasingcurve
SOURCES
tst_qeasingcurve.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index 4989de521f..0a933a1e2b 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -1,7 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <private/qcomparisontesthelper_p.h>
#include <qeasingcurve.h>
@@ -16,6 +17,7 @@ private slots:
void valueForProgress_data();
void valueForProgress();
void setCustomType();
+ void comparisonCompiles();
void operators();
void properties();
void metaTypes();
@@ -420,6 +422,11 @@ void tst_QEasingCurve::setCustomType()
QCOMPARE(curve.valueForProgress(0.99), 0.99);
}
+void tst_QEasingCurve::comparisonCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QEasingCurve>();
+}
+
void tst_QEasingCurve::operators()
{
{ // member-swap()
@@ -447,28 +454,28 @@ void tst_QEasingCurve::operators()
curve2 = curve;
curve2.setOvershoot(qreal(1.70158));
QCOMPARE(curve.overshoot(), curve2.overshoot());
- QVERIFY(curve2 == curve);
+ QT_TEST_EQUALITY_OPS(curve2, curve, true);
curve.setOvershoot(3.0);
- QVERIFY(curve2 != curve);
+ QT_TEST_EQUALITY_OPS(curve2, curve, false);
curve2.setOvershoot(3.0);
- QVERIFY(curve2 == curve);
+ QT_TEST_EQUALITY_OPS(curve2, curve, true);
curve2.setType(QEasingCurve::Linear);
QCOMPARE(curve.overshoot(), curve2.overshoot());
- QVERIFY(curve2 != curve);
+ QT_TEST_EQUALITY_OPS(curve2, curve, false);
curve2.setType(QEasingCurve::InBack);
QCOMPARE(curve.overshoot(), curve2.overshoot());
- QVERIFY(curve2 == curve);
+ QT_TEST_EQUALITY_OPS(curve2, curve, true);
QEasingCurve curve3;
QEasingCurve curve4;
curve4.setAmplitude(curve4.amplitude());
QEasingCurve curve5;
curve5.setAmplitude(0.12345);
- QVERIFY(curve3 == curve4); // default value and not assigned
- QVERIFY(curve3 != curve5); // unassinged and other value
- QVERIFY(curve4 != curve5);
+ QT_TEST_EQUALITY_OPS(curve3, curve4, true); // default value and not assigned
+ QT_TEST_EQUALITY_OPS(curve3, curve5, false); // unassinged and other value
+ QT_TEST_EQUALITY_OPS(curve4, curve5, false);
}
class tst_QEasingProperties : public QObject
@@ -574,10 +581,10 @@ void tst_QEasingCurve::bezierSpline_data()
static inline void setupBezierSpline(QEasingCurve *easingCurve, const QString &string)
{
- QStringList pointStr = string.split(QLatin1Char(' '));
+ const QStringList pointStr = string.split(QLatin1Char(' '));
QList<QPointF> points;
- foreach (const QString &str, pointStr) {
+ for (const QString &str : pointStr) {
QStringList coordStr = str.split(QLatin1Char(','));
QPointF point(coordStr.first().toDouble(), coordStr.last().toDouble());
points.append(point);
@@ -642,9 +649,9 @@ void tst_QEasingCurve::tcbSpline_data()
static inline void setupTCBSpline(QEasingCurve *easingCurve, const QString &string)
{
- QStringList pointStr = string.split(QLatin1Char(' '));
+ const QStringList pointStr = string.split(QLatin1Char(' '));
- foreach (const QString &str, pointStr) {
+ for (const QString &str : pointStr) {
QStringList coordStr = str.split(QLatin1Char(','));
Q_ASSERT(coordStr.size() == 5);
QPointF point(coordStr.first().toDouble(), coordStr.at(1).toDouble());
@@ -890,7 +897,7 @@ void tst_QEasingCurve::streamInOut()
dsw << orig;
dsr >> copy;
- QCOMPARE(copy == orig, equality);
+ QT_TEST_EQUALITY_OPS(copy, orig, equality);
}
QTEST_MAIN(tst_QEasingCurve)
diff --git a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt
index 63da04185a..280918e302 100644
--- a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qexplicitlyshareddatapointer Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qexplicitlyshareddatapointer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qexplicitlyshareddatapointer
SOURCES
tst_qexplicitlyshareddatapointer.cpp
diff --git a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
index 95c2fe612d..5e105a090a 100644
--- a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
+++ b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -223,4 +223,3 @@ void tst_QExplicitlySharedDataPointer::swap() const
QTEST_MAIN(tst_QExplicitlySharedDataPointer)
#include "tst_qexplicitlyshareddatapointer.moc"
-// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/corelib/tools/qflatmap/CMakeLists.txt b/tests/auto/corelib/tools/qflatmap/CMakeLists.txt
index 7ab9b60687..bc98c669fc 100644
--- a/tests/auto/corelib/tools/qflatmap/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qflatmap/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qflatmap Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qflatmap LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qflatmap
SOURCES
tst_qflatmap.cpp
diff --git a/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp b/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp
index 112a393136..986cf2407b 100644
--- a/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp
+++ b/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#define QT_USE_QSTRINGBUILDER
#define QFLATMAP_ENABLE_STL_COMPATIBLE_INSERT
diff --git a/tests/auto/corelib/tools/qfreelist/CMakeLists.txt b/tests/auto/corelib/tools/qfreelist/CMakeLists.txt
index 383e8c38ee..a37d3131f5 100644
--- a/tests/auto/corelib/tools/qfreelist/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qfreelist/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qfreelist Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfreelist LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qfreelist
SOURCES
tst_qfreelist.cpp
diff --git a/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp b/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp
index 1b2cd610da..a45fa6d400 100644
--- a/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp
+++ b/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp
@@ -1,6 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QCoreApplication>
#include <QtCore/QElapsedTimer>
@@ -116,7 +115,7 @@ public:
needToRelease << i;
} while (t.elapsed() < TimeLimit);
- foreach (int x, needToRelease)
+ for (int x : std::as_const(needToRelease))
freelist.release(x);
}
};
diff --git a/tests/auto/corelib/tools/qhash/CMakeLists.txt b/tests/auto/corelib/tools/qhash/CMakeLists.txt
index 36a23836c4..8702b8bf23 100644
--- a/tests/auto/corelib/tools/qhash/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qhash/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qhash Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhash LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qhash
SOURCES
tst_qhash.cpp
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 50b1248d91..b3dbdfa40c 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1,10 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <qdebug.h>
#include <qhash.h>
#include <qmap.h>
+#include <qscopeguard.h>
#include <qset.h>
#include <algorithm>
@@ -36,12 +38,24 @@ private slots:
void qhash();
void take(); // copied from tst_QMap
void operator_eq(); // slightly modified from tst_QMap
+ void heterogeneousSearch();
+ void heterogeneousSearchConstKey();
+ void heterogeneousSearchByteArray();
+ void heterogeneousSearchString();
+ void heterogeneousSearchLatin1String();
+
void rehash_isnt_quadratic();
void dont_need_default_constructor();
void qmultihash_specific();
void qmultihash_qhash_rvalue_ref_ctor();
void qmultihash_qhash_rvalue_ref_unite();
void qmultihashUnite();
+ void qmultihashSize();
+ void qmultihashHeterogeneousSearch();
+ void qmultihashHeterogeneousSearchConstKey();
+ void qmultihashHeterogeneousSearchByteArray();
+ void qmultihashHeterogeneousSearchString();
+ void qmultihashHeterogeneousSearchLatin1String();
void compare();
void compare2();
@@ -61,6 +75,7 @@ private slots:
void eraseValidIteratorOnSharedHash();
void equal_range();
void insert_hash();
+ void multiHashStoresInReverseInsertionOrder();
void emplace();
@@ -1154,6 +1169,222 @@ void tst_QHash::operator_eq()
}
}
+#ifdef __cpp_concepts
+struct HeterogeneousHashingType
+{
+ inline static int conversionCount = 0;
+ QString s;
+
+ Q_IMPLICIT operator QString() const
+ {
+ ++conversionCount;
+ return s;
+ }
+
+ // std::equality_comparable_with requires we be self-comparable too
+ friend bool operator==(const HeterogeneousHashingType &t1, const HeterogeneousHashingType &t2) = default;
+
+ friend bool operator==(const QString &string, const HeterogeneousHashingType &tester)
+ { return tester.s == string; }
+ friend bool operator!=(const QString &string, const HeterogeneousHashingType &tester)
+ { return !(tester.s == string); }
+
+ friend size_t qHash(const HeterogeneousHashingType &tester, size_t seed)
+ { return qHash(tester.s, seed); }
+};
+QT_BEGIN_NAMESPACE
+template <> struct QHashHeterogeneousSearch<QString, HeterogeneousHashingType> : std::true_type {};
+template <> struct QHashHeterogeneousSearch<HeterogeneousHashingType, QString> : std::true_type {};
+QT_END_NAMESPACE
+static_assert(std::is_same_v<QString, std::common_type_t<QString, HeterogeneousHashingType>>);
+static_assert(std::equality_comparable_with<QString, HeterogeneousHashingType>);
+static_assert(QHashPrivate::HeterogeneouslySearchableWith<QString, HeterogeneousHashingType>);
+static_assert(QHashPrivate::HeterogeneouslySearchableWith<HeterogeneousHashingType, QString>);
+
+template <typename T> struct HeterogeneousSearchTestHelper
+{
+ static void resetCounter() {}
+ static void checkCounter() {}
+};
+template <> struct HeterogeneousSearchTestHelper<HeterogeneousHashingType>
+{
+ static void resetCounter()
+ {
+ HeterogeneousHashingType::conversionCount = 0;
+ }
+ static void checkCounter()
+ {
+ QTest::setThrowOnFail(true);
+ auto scopeExit = qScopeGuard([] { QTest::setThrowOnFail(false); });
+ QCOMPARE(HeterogeneousHashingType::conversionCount, 0);
+ }
+};
+#else
+using HeterogeneousHashingType = QString;
+#endif
+
+template <template <typename, typename> class Hash, typename String, typename View, typename Converter>
+static void heterogeneousSearchTest(const QList<std::remove_const_t<String>> &keys, Converter conv)
+{
+#ifdef __cpp_concepts
+ using Helper = HeterogeneousSearchTestHelper<View>;
+ String key = keys.last();
+ String otherKey = keys.first();
+ auto keyHolder = conv(key);
+ auto otherKeyHolder = conv(otherKey);
+ View keyView(keyHolder);
+ View otherKeyView(otherKeyHolder);
+
+ Hash<String, qsizetype> hash;
+ static constexpr bool IsMultiHash = !std::is_same_v<decltype(hash.remove(String())), bool>;
+ hash[key] = keys.size();
+
+ Helper::resetCounter();
+ QVERIFY(hash.contains(keyView));
+ QCOMPARE_EQ(hash.count(keyView), 1);
+ QCOMPARE_EQ(hash.value(keyView), keys.size());
+ QCOMPARE_EQ(hash.value(keyView, -1), keys.size());
+ QCOMPARE_EQ(std::as_const(hash)[keyView], keys.size());
+ QCOMPARE_EQ(hash.find(keyView), hash.begin());
+ QCOMPARE_EQ(std::as_const(hash).find(keyView), hash.constBegin());
+ QCOMPARE_EQ(hash.constFind(keyView), hash.constBegin());
+ QCOMPARE_EQ(hash.equal_range(keyView), std::make_pair(hash.begin(), hash.end()));
+ QCOMPARE_EQ(std::as_const(hash).equal_range(keyView),
+ std::make_pair(hash.constBegin(), hash.constEnd()));
+ Helper::checkCounter();
+
+ QVERIFY(!hash.contains(otherKeyView));
+ QCOMPARE_EQ(hash.count(otherKeyView), 0);
+ QCOMPARE_EQ(hash.value(otherKeyView), 0);
+ QCOMPARE_EQ(hash.value(otherKeyView, -1), -1);
+ QCOMPARE_EQ(std::as_const(hash)[otherKeyView], 0);
+ QCOMPARE_EQ(hash.find(otherKeyView), hash.end());
+ QCOMPARE_EQ(std::as_const(hash).find(otherKeyView), hash.constEnd());
+ QCOMPARE_EQ(hash.constFind(otherKeyView), hash.constEnd());
+ QCOMPARE_EQ(hash.equal_range(otherKeyView), std::make_pair(hash.end(), hash.end()));
+ QCOMPARE_EQ(std::as_const(hash).equal_range(otherKeyView),
+ std::make_pair(hash.constEnd(), hash.constEnd()));
+ Helper::checkCounter();
+
+ // non-const versions
+ QCOMPARE_EQ(hash[keyView], keys.size()); // already there
+ Helper::checkCounter();
+
+ QCOMPARE_EQ(hash[otherKeyView], 0); // inserts
+ Helper::resetCounter();
+ hash[otherKeyView] = INT_MAX;
+ Helper::checkCounter();
+
+ if constexpr (IsMultiHash) {
+ hash.insert(key, keys.size());
+ QCOMPARE_EQ(hash.count(keyView), 2);
+
+ // not depending on which of the two the current implementation finds
+ QCOMPARE_NE(hash.value(keyView), 0);
+ QCOMPARE_NE(hash.value(keyView, -1000), -1000);
+ QCOMPARE_NE(std::as_const(hash)[keyView], 0);
+ QCOMPARE_NE(hash.find(keyView), hash.end());
+ QCOMPARE_NE(std::as_const(hash).find(keyView), hash.constEnd());
+ QCOMPARE_NE(hash.constFind(keyView), hash.constEnd());
+ QCOMPARE_NE(hash.equal_range(keyView), std::make_pair(hash.end(), hash.end()));
+ QCOMPARE_NE(std::as_const(hash).equal_range(keyView),
+ std::make_pair(hash.constEnd(), hash.constEnd()));
+
+ // QMultiHash-specific functions
+ QVERIFY(hash.contains(keyView, keys.size()));
+ QCOMPARE_EQ(hash.count(keyView, 0), 0);
+ QCOMPARE_EQ(hash.count(keyView, keys.size()), 2);
+ QCOMPARE_EQ(hash.values(keyView), QList<qsizetype>({ keys.size(), keys.size() }));
+
+ hash.insert(key, -keys.size());
+ QCOMPARE_EQ(hash.count(keyView), 3);
+ QCOMPARE_EQ(hash.find(keyView, 0), hash.end());
+ QCOMPARE_NE(hash.find(keyView, keys.size()), hash.end());
+ QCOMPARE_NE(hash.find(keyView, -keys.size()), hash.end());
+ QCOMPARE_EQ(std::as_const(hash).find(keyView, 0), hash.constEnd());
+ QCOMPARE_NE(std::as_const(hash).find(keyView, keys.size()), hash.constEnd());
+ QCOMPARE_NE(std::as_const(hash).find(keyView, -keys.size()), hash.constEnd());
+ QCOMPARE_EQ(hash.constFind(keyView, 0), hash.constEnd());
+ QCOMPARE_NE(hash.constFind(keyView, keys.size()), hash.constEnd());
+ QCOMPARE_NE(hash.constFind(keyView, -keys.size()), hash.constEnd());
+
+ // removals
+ QCOMPARE_EQ(hash.remove(keyView, -keys.size()), 1);
+ QCOMPARE_EQ(hash.remove(keyView), 2);
+ } else {
+ // removals
+ QCOMPARE_EQ(hash.remove(keyView), true);
+ }
+
+ QCOMPARE_EQ(hash.take(otherKeyView), INT_MAX);
+ QVERIFY(hash.isEmpty());
+ Helper::checkCounter();
+
+ // repeat with more keys
+ for (qsizetype i = 0; i < keys.size() - 1; ++i) {
+ hash.insert(keys[i], -(i + 1));
+ hash.insert(keys[i], i + 1);
+ }
+
+ QVERIFY(!hash.contains(keyView));
+ QCOMPARE_EQ(hash.count(keyView), 0);
+ QCOMPARE_EQ(hash.value(keyView), 0);
+ QCOMPARE_EQ(hash.value(keyView, -1), -1);
+ QCOMPARE_EQ(std::as_const(hash)[keyView], 0);
+ QCOMPARE_EQ(hash.find(keyView), hash.end());
+ QCOMPARE_EQ(hash.constFind(keyView), hash.constEnd());
+ Helper::checkCounter();
+#else
+ Q_UNUSED(keys);
+ Q_UNUSED(conv);
+ QSKIP("This feature requires C++20 (concepts)");
+#endif
+}
+
+template <template <typename, typename> class Hash, typename String, typename View>
+static void heterogeneousSearchTest(const QList<std::remove_const_t<String>> &keys)
+{
+ heterogeneousSearchTest<Hash, String, View>(keys, [](const String &s) { return View(s); });
+}
+
+template <template <typename, typename> class Hash, typename T>
+static void heterogeneousSearchLatin1String(T)
+{
+ if constexpr (!T::value) {
+ QSKIP("QLatin1StringView and QString do not have the same hash on this platform");
+ } else {
+ // similar to the above
+ auto toLatin1 = [](const QString &s) { return s.toLatin1(); };
+ heterogeneousSearchTest<Hash, QString, QLatin1StringView>({ "Hello", {}, "World" }, toLatin1);
+ }
+}
+
+void tst_QHash::heterogeneousSearch()
+{
+ heterogeneousSearchTest<QHash, QString, HeterogeneousHashingType>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::heterogeneousSearchConstKey()
+{
+ // QHash<const QString, X> seen in the wild (e.g. Qt Creator)
+ heterogeneousSearchTest<QHash, const QString, HeterogeneousHashingType>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::heterogeneousSearchByteArray()
+{
+ heterogeneousSearchTest<QHash, QByteArray, QByteArrayView>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::heterogeneousSearchString()
+{
+ heterogeneousSearchTest<QHash, QString, QStringView>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::heterogeneousSearchLatin1String()
+{
+ ::heterogeneousSearchLatin1String<QHash>(QHashHeterogeneousSearch<QString, QLatin1StringView>{});
+}
+
void tst_QHash::compare()
{
QHash<int, QString> hash1,hash2;
@@ -2051,6 +2282,103 @@ void tst_QHash::qmultihashUnite()
}
}
+void tst_QHash::qmultihashSize()
+{
+ // QMultiHash has an extra m_size member that counts the number of values,
+ // while d->size (shared with QHash) counts the number of distinct keys.
+ {
+ QMultiHash<int, int> hash;
+ QCOMPARE(hash.size(), 0);
+ QVERIFY(hash.isEmpty());
+
+ hash.insert(0, 42);
+ QCOMPARE(hash.size(), 1);
+ QVERIFY(!hash.isEmpty());
+
+ hash.insert(0, 42);
+ QCOMPARE(hash.size(), 2);
+ QVERIFY(!hash.isEmpty());
+
+ hash.emplace(0, 42);
+ QCOMPARE(hash.size(), 3);
+ QVERIFY(!hash.isEmpty());
+
+ QCOMPARE(hash.take(0), 42);
+ QCOMPARE(hash.size(), 2);
+ QVERIFY(!hash.isEmpty());
+
+ QCOMPARE(hash.remove(0), 2);
+ QCOMPARE(hash.size(), 0);
+ QVERIFY(hash.isEmpty());
+ }
+
+ {
+ QMultiHash<int, int> hash;
+ hash.emplace(0, 0);
+ hash.emplace(0, 0);
+ QCOMPARE(hash.size(), 2);
+ QVERIFY(!hash.isEmpty());
+
+ hash.emplace(0, 1);
+ QCOMPARE(hash.size(), 3);
+ QVERIFY(!hash.isEmpty());
+
+ QCOMPARE(hash.remove(0, 0), 2);
+ QCOMPARE(hash.size(), 1);
+ QVERIFY(!hash.isEmpty());
+
+ hash.remove(0);
+ QCOMPARE(hash.size(), 0);
+ QVERIFY(hash.isEmpty());
+ }
+
+ {
+ QMultiHash<int, int> hash;
+
+ hash[0] = 0;
+ QCOMPARE(hash.size(), 1);
+ QVERIFY(!hash.isEmpty());
+
+ hash.replace(0, 1);
+ QCOMPARE(hash.size(), 1);
+ QVERIFY(!hash.isEmpty());
+
+ hash.insert(0, 1);
+ hash.erase(hash.cbegin());
+ QCOMPARE(hash.size(), 1);
+ QVERIFY(!hash.isEmpty());
+
+ hash.erase(hash.cbegin());
+ QCOMPARE(hash.size(), 0);
+ QVERIFY(hash.isEmpty());
+ }
+}
+
+void tst_QHash::qmultihashHeterogeneousSearch()
+{
+ heterogeneousSearchTest<QMultiHash, QString, HeterogeneousHashingType>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::qmultihashHeterogeneousSearchConstKey()
+{
+ heterogeneousSearchTest<QMultiHash, const QString, HeterogeneousHashingType>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::qmultihashHeterogeneousSearchByteArray()
+{
+ heterogeneousSearchTest<QMultiHash, QByteArray, QByteArrayView>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::qmultihashHeterogeneousSearchString()
+{
+ heterogeneousSearchTest<QMultiHash, QString, QStringView>({ "Hello", {}, "World" });
+}
+
+void tst_QHash::qmultihashHeterogeneousSearchLatin1String()
+{
+ ::heterogeneousSearchLatin1String<QMultiHash>(QHashHeterogeneousSearch<QString, QLatin1StringView>{});
+}
+
void tst_QHash::keys_values_uniqueKeys()
{
QMultiHash<QString, int> hash;
@@ -2411,6 +2739,24 @@ void tst_QHash::insert_hash()
}
}
+void tst_QHash::multiHashStoresInReverseInsertionOrder()
+{
+ const QString strings[] = {
+ u"zero"_s,
+ u"null"_s,
+ u"nada"_s,
+ };
+ {
+ QMultiHash<int, QString> hash;
+ for (const QString &string : strings)
+ hash.insert(0, string);
+ auto printOnFailure = qScopeGuard([&] { qDebug() << hash; });
+ QVERIFY(std::equal(hash.begin(), hash.end(),
+ std::rbegin(strings), std::rend(strings)));
+ printOnFailure.dismiss();
+ }
+}
+
void tst_QHash::emplace()
{
{
@@ -2747,9 +3093,6 @@ void tst_QHash::QTBUG98265()
*/
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;
@@ -2787,7 +3130,6 @@ void tst_QHash::detachAndReferences()
QVERIFY(hash.contains(kCopy));
QCOMPARE(hash.value(kCopy), vCopy);
}
-#endif
}
void tst_QHash::lookupUsingKeyIterator()
diff --git a/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt b/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt
index 9f25182a3e..6cbba503dc 100644
--- a/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qhashfunctions/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qhashfunctions Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhashfunctions LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qhashfunctions
SOURCES
tst_qhashfunctions.cpp
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index 6daf418e7b..00ee5763ed 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -1,10 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// Copyright (C) 2024 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QVarLengthArray>
#include <qhash.h>
+#include <qfloat16.h>
#include <iterator>
#include <sstream>
@@ -16,11 +18,11 @@ class tst_QHashFunctions : public QObject
{
Q_OBJECT
public:
- enum {
- // random value
- RandomSeed = 1045982819
- };
- uint seed;
+ // random values
+ static constexpr quint64 ZeroSeed = 0;
+ static constexpr quint64 RandomSeed32 = 1045982819;
+ static constexpr quint64 RandomSeed64 = QtPrivate::QHashCombine{}(RandomSeed32, RandomSeed32);
+ size_t seed;
template <typename T1, typename T2> void stdPair_template(const T1 &t1, const T2 &t2);
@@ -29,7 +31,15 @@ public slots:
void init();
private Q_SLOTS:
- void consistent();
+ void unsignedIntegerConsistency_data();
+ void unsignedIntegerConsistency();
+ void signedIntegerConsistency_data();
+ void signedIntegerConsistency();
+ void extendedIntegerConsistency();
+ void floatingPointConsistency_data();
+ void floatingPointConsistency();
+ void stringConsistency_data();
+ void stringConsistency();
void qhash();
void qhash_of_empty_and_null_qstring();
void qhash_of_empty_and_null_qbytearray();
@@ -60,26 +70,270 @@ private Q_SLOTS:
#endif
};
-void tst_QHashFunctions::consistent()
+void tst_QHashFunctions::initTestCase()
{
- // QString-like
- const QString s = QStringLiteral("abcdefghijklmnopqrstuvxyz").repeated(16);
- QCOMPARE(qHash(s), qHash(QStringView(s)));
+ QTest::addColumn<quint64>("seedValue");
+
+ QTest::newRow("zero-seed") << ZeroSeed;
+ QTest::newRow("zero-seed-negated") << ~ZeroSeed;
+ QTest::newRow("non-zero-seed-32bit") << RandomSeed32;
+ QTest::newRow("non-zero-seed-32bit-negated")
+ << quint64{~quint32(RandomSeed32)}; // ensure this->seed gets same value on 32/64-bit
+ if constexpr (sizeof(size_t) == sizeof(quint64)) {
+ QTest::newRow("non-zero-seed-64bit") << RandomSeed64;
+ QTest::newRow("non-zero-seed-64bit-negated") << ~RandomSeed64;
+ }
}
-void tst_QHashFunctions::initTestCase()
+void tst_QHashFunctions::init()
{
- static_assert(int(RandomSeed) > 0);
+ QFETCH_GLOBAL(quint64, seedValue);
+ seed = size_t(seedValue);
+}
- QTest::addColumn<uint>("seedValue");
- QTest::newRow("zero-seed") << 0U;
- QTest::newRow("non-zero-seed") << uint(RandomSeed);
+template <typename T> static void addPositiveCommonRows()
+{
+ QTest::addRow("zero") << T(0);
+ QTest::addRow("positive_7bit") << T(42);
+ QTest::addRow("positive_15bit") << T(0x1f3f);
+ QTest::addRow("positive_31bit") << T(0x4b3d'93c4);
+ QTest::addRow("positive_63bit") << T(Q_INT64_C(0x39df'7338'4b14'fcb0));
+
+ QTest::addRow("SCHAR_MAX") << T(SCHAR_MAX);
+ QTest::addRow("SHRT_MAX") << T(SHRT_MAX);
+ QTest::addRow("INT_MAX") << T(INT_MAX);
+ QTest::addRow("LLONG_MAX") << T(LLONG_MAX);
}
-void tst_QHashFunctions::init()
+void tst_QHashFunctions::signedIntegerConsistency_data()
+{
+ QTest::addColumn<qint64>("value");
+ addPositiveCommonRows<qint64>();
+ QTest::addRow("negative_7bit") << Q_INT64_C(-28);
+ QTest::addRow("negative_15bit") << Q_INT64_C(-0x387c);
+ QTest::addRow("negative_31bit") << qint64(-0x7713'30f9);
+
+ QTest::addRow("SCHAR_MIN") << qint64(SCHAR_MIN);
+ QTest::addRow("SHRT_MIN") << qint64(SHRT_MIN);
+ QTest::addRow("INT_MIN") << qint64(INT_MIN);
+ QTest::addRow("LLONG_MIN") << LLONG_MIN;
+}
+
+void tst_QHashFunctions::unsignedIntegerConsistency_data()
+{
+ QTest::addColumn<quint64>("value");
+ addPositiveCommonRows<quint64>();
+
+ QTest::addRow("positive_8bit") << Q_UINT64_C(0xE4);
+ QTest::addRow("positive_16bit") << Q_UINT64_C(0xcafe);
+ QTest::addRow("positive_32bit") << quint64(0xcafe'babe);
+
+ QTest::addRow("UCHAR_MAX") << quint64(UCHAR_MAX);
+ QTest::addRow("UHRT_MAX") << quint64(USHRT_MAX);
+ QTest::addRow("UINT_MAX") << quint64(UINT_MAX);
+ QTest::addRow("ULLONG_MAX") << ULLONG_MAX;
+}
+
+static void unsignedIntegerConsistency(quint64 value, size_t seed)
+{
+ quint8 v8 = quint8(value);
+ quint16 v16 = quint16(value);
+ quint32 v32 = quint32(value);
+
+ const auto hu8 = qHash(v8, seed);
+ const auto hu16 = qHash(v16, seed);
+ const auto hu32 = qHash(v32, seed);
+ const auto hu64 = qHash(value, seed);
+
+ if (v8 == value)
+ QCOMPARE(hu8, hu32);
+ if (v16 == value)
+ QCOMPARE(hu16, hu32);
+ if (v32 == value)
+ QCOMPARE(hu64, hu32);
+
+#if QT_SUPPORTS_INT128
+ const auto hu128 = qHash(quint128(value), seed);
+ QCOMPARE(hu128, hu64);
+#endif
+
+ // there are a few more unsigned types:
+#ifdef __cpp_char8_t
+ const auto hc8 = qHash(char8_t(value), seed);
+#endif
+ const auto hc16 = qHash(char16_t(value), seed);
+ const auto hc32 = qHash(char32_t(value), seed);
+#ifdef __cpp_char8_t
+ QCOMPARE(hc8, hu8);
+#endif
+ QCOMPARE(hc16, hu16);
+ QCOMPARE(hc32, hu32);
+}
+
+void tst_QHashFunctions::unsignedIntegerConsistency()
+{
+ QFETCH(quint64, value);
+ ::unsignedIntegerConsistency(value, seed);
+}
+
+void tst_QHashFunctions::signedIntegerConsistency()
+{
+ QFETCH(qint64, value);
+ qint8 v8 = qint8(value);
+ qint16 v16 = qint16(value);
+ qint32 v32 = qint32(value);
+
+ const auto hs8 = qHash(v8, seed);
+ const auto hs16 = qHash(v16, seed);
+ const auto hs32 = qHash(v32, seed);
+ const auto hs64 = qHash(value, seed);
+
+ if (v8 == value)
+ QCOMPARE(hs8, hs32);
+ if (v16 == value)
+ QCOMPARE(hs16, hs32);
+ if (v32 == value) {
+ // because of QTBUG-116080, this may not match, but we can't guarantee
+ // it mismatches 100% of the time either
+ if constexpr (sizeof(size_t) > sizeof(int) || QT_VERSION_MAJOR > 6)
+ QCOMPARE(hs64, hs32);
+ }
+
+#if QT_SUPPORTS_INT128
+ const auto hs128 = qHash(qint128(value), seed);
+ QCOMPARE(hs128, hs64);
+#endif
+
+ if (value > 0) {
+ quint64 u64 = quint64(value);
+ const auto hu64 = qHash(u64, seed);
+ QCOMPARE(hu64, hs64);
+ ::unsignedIntegerConsistency(u64, seed);
+ // by A == B && B == C -> A == C, we've shown hsXX == huXX for all XX
+ }
+}
+
+void tst_QHashFunctions::extendedIntegerConsistency()
+{
+#ifdef QT_SUPPORTS_INT128
+ // We only need to check qint128 and quint128 consistency here.
+ qint128 v65bit = Q_INT128_C(0x1'abea'06b7'dcf5'106a);
+ qint128 v127bit = Q_INT128_C(0x387c'ac7a'22a0'5242'9ee9'bcaa'6a53'13af);
+
+ QCOMPARE(qHash(quint128(v65bit), seed), qHash(v65bit, seed));
+ QCOMPARE(qHash(quint128(v127bit), seed), qHash(v127bit, seed));
+#else
+ QSKIP("This platform does not support extended integer types.");
+#endif
+}
+
+void tst_QHashFunctions::floatingPointConsistency_data()
+{
+ QTest::addColumn<double>("value");
+ QTest::addRow("zero") << 0.0;
+
+ QTest::addRow("1.0") << 1.0;
+ QTest::addRow("infinity") << std::numeric_limits<double>::infinity();
+
+ QTest::addRow("fp16_epsilon") << double(std::numeric_limits<qfloat16>::epsilon());
+ QTest::addRow("fp16_min") << double(std::numeric_limits<qfloat16>::min());
+ QTest::addRow("fp16_max") << double(std::numeric_limits<qfloat16>::max());
+
+ QTest::addRow("float_epsilon") << double(std::numeric_limits<float>::epsilon());
+ QTest::addRow("float_min") << double(std::numeric_limits<float>::min());
+ QTest::addRow("float_max") << double(std::numeric_limits<float>::max());
+
+ QTest::addRow("double_epsilon") << double(std::numeric_limits<double>::epsilon());
+ QTest::addRow("double_min") << double(std::numeric_limits<double>::min());
+ QTest::addRow("double_max") << double(std::numeric_limits<double>::max());
+}
+
+void tst_QHashFunctions::floatingPointConsistency()
{
- QFETCH_GLOBAL(uint, seedValue);
- seed = seedValue;
+ QFETCH(double, value);
+ long double lvalue = value;
+ float fp32 = float(value);
+ qfloat16 fp16 = qfloat16(value);
+
+ const auto hfld = qHash(lvalue, seed);
+ const auto hf64 = qHash(value, seed);
+ const auto hf32 = qHash(fp32, seed);
+ const auto hf16 = qHash(fp16, seed);
+
+ const auto hnfld = qHash(-lvalue, seed);
+ const auto hnf64 = qHash(-value, seed);
+ const auto hnf32 = qHash(-fp32, seed);
+ const auto hnf16 = qHash(-fp16, seed);
+
+ if (fp16 == fp32) {
+ QCOMPARE(hf16, hf32);
+ QCOMPARE(hnf16, hnf32);
+ }
+
+ // See QTBUG-116077; the rest isn't guaranteed to match (but we can't
+ // guarantee it will mismatch either).
+ return;
+
+ if (fp32 == value) {
+ QCOMPARE(hf32, hf64);
+ QCOMPARE(hnf32, hnf64);
+ }
+
+ QCOMPARE(hfld, hf64);
+ QCOMPARE(hnfld, hnf64);
+}
+
+void tst_QHashFunctions::stringConsistency_data()
+{
+ QTest::addColumn<QString>("value");
+ QTest::newRow("null") << QString();
+ QTest::newRow("empty") << "";
+ QTest::newRow("withnull") << QStringLiteral("A\0z");
+ QTest::newRow("short-ascii") << "Hello"; // 10 bytes
+ QTest::newRow("medium-ascii") << "Hello, World"; // 24 bytes
+ QTest::newRow("long-ascii") << QStringLiteral("abcdefghijklmnopqrstuvxyz").repeated(16);
+
+ QTest::newRow("short-latin1") << "Bokmål";
+ QTest::newRow("medium-latin1") << "Det går bra!"; // 24 bytes
+ QTest::newRow("long-latin1")
+ << R"(Alle mennesker er født frie og med samme menneskeverd og menneskerettigheter.
+ De er utstyrt med fornuft og samvittighet og bør handle mot hverandre i brorskapets ånd.)";
+
+ QTest::newRow("short-nonlatin1") << "Ελληνικά";
+ QTest::newRow("long-nonlatin1")
+ << R"('Ολοι οι άνθρωποι γεννιούνται ελεύθεροι και ίσοι στην αξιοπρέπεια και τα
+ δικαιώματα. Είναι προικισμένοι με λογική και συνείδηση, και οφείλουν να συμπεριφέρονται μεταξύ
+ τους με πνεύμα αδελφοσύνης.)";
+}
+
+void tst_QHashFunctions::stringConsistency()
+{
+ QFETCH(QString, value);
+ QStringView sv = value;
+ QByteArray u8ba = value.toUtf8();
+ QByteArray u8bav = u8ba;
+
+ // sanity checking:
+ QCOMPARE(sv.isNull(), value.isNull());
+ QCOMPARE(sv.isEmpty(), value.isEmpty());
+ QCOMPARE(u8ba.isNull(), value.isNull());
+ QCOMPARE(u8ba.isEmpty(), value.isEmpty());
+ QCOMPARE(u8bav.isNull(), value.isNull());
+ QCOMPARE(u8bav.isEmpty(), value.isEmpty());
+
+ QCOMPARE(qHash(sv, seed), qHash(value, seed));
+ QCOMPARE(qHash(u8bav, seed), qHash(u8ba, seed));
+
+ if (seed == 0 || QHashHeterogeneousSearch<QString, QLatin1StringView>::value) {
+ QByteArray l1ba = value.toLatin1();
+ QLatin1StringView l1sv(l1ba.data(), l1ba.size());
+#ifdef Q_PROCESSOR_ARM
+ // zero-extending aeshash not implemented on ARM
+#else
+ if (value == l1sv)
+ QCOMPARE(qHash(l1sv, seed), qHash(value, seed));
+#endif
+ }
}
void tst_QHashFunctions::qhash()
@@ -182,9 +436,7 @@ void tst_QHashFunctions::qhash_of_zero_floating_points()
{
QCOMPARE(qHash(-0.0f, seed), qHash(0.0f, seed));
QCOMPARE(qHash(-0.0 , seed), qHash(0.0 , seed));
-#ifndef Q_OS_DARWIN
QCOMPARE(qHash(-0.0L, seed), qHash(0.0L, seed));
-#endif
}
void tst_QHashFunctions::qthash_data()
@@ -354,13 +606,9 @@ void tst_QHashFunctions::stdPair_template(const T1 &t1, const T2 &t2)
std::pair<T1, T2> dpair{};
std::pair<T1, T2> vpair{t1, t2};
- size_t seed = QHashSeed::globalSeed();
-
// confirm proper working of the pair and of the underlying types
QVERIFY(t1 == t1);
QVERIFY(t2 == t2);
- QCOMPARE(qHash(t1), qHash(t1));
- QCOMPARE(qHash(t2), qHash(t2));
QCOMPARE(qHash(t1, seed), qHash(t1, seed));
QCOMPARE(qHash(t2, seed), qHash(t2, seed));
@@ -368,9 +616,7 @@ void tst_QHashFunctions::stdPair_template(const T1 &t1, const T2 &t2)
QVERIFY(vpair == vpair);
// therefore their hashes should be equal
- QCOMPARE(qHash(dpair), qHash(dpair));
QCOMPARE(qHash(dpair, seed), qHash(dpair, seed));
- QCOMPARE(qHash(vpair), qHash(vpair));
QCOMPARE(qHash(vpair, seed), qHash(vpair, seed));
}
diff --git a/tests/auto/corelib/tools/qhashseed/CMakeLists.txt b/tests/auto/corelib/tools/qhashseed/CMakeLists.txt
index a098f103a7..27b4cce133 100644
--- a/tests/auto/corelib/tools/qhashseed/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qhashseed/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qhashseed Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhashseed LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qhashseed
SOURCES
tst_qhashseed.cpp
diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
index 2562ebfaa6..e004a560a2 100644
--- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
+++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2021 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -21,7 +21,7 @@ private Q_SLOTS:
void deterministicSeed();
void reseeding();
void quality();
-#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && QT_DEPRECATED_SINCE(6,6)
void compatibilityApi();
void deterministicSeed_compat();
#endif
@@ -157,7 +157,7 @@ void tst_QHashSeed::quality()
"seedsToMinus1 = " + QByteArray::number(seedsToMinus1));
}
-#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && QT_DEPRECATED_SINCE(6,6)
QT_WARNING_DISABLE_DEPRECATED
void tst_QHashSeed::compatibilityApi()
{
diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp
index 57ecf09575..25e7909870 100644
--- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp
+++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed_helper.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2021 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 5395d92f20..7d9fdf51a9 100644
--- a/tests/auto/corelib/tools/qline/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qline/CMakeLists.txt
@@ -5,9 +5,17 @@
## tst_qline Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qline LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qline
SOURCES
tst_qline.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
## Scopes:
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp
index dd7bb2b997..10069e821b 100644
--- a/tests/auto/corelib/tools/qline/tst_qline.cpp
+++ b/tests/auto/corelib/tools/qline/tst_qline.cpp
@@ -1,9 +1,10 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qline.h>
#include <qmath.h>
+#include <private/qcomparisontesthelper_p.h>
#include <array>
@@ -11,6 +12,16 @@ class tst_QLine : public QObject
{
Q_OBJECT
private slots:
+ void testComparisonCompiles();
+ void testComparison_data();
+ void testComparison();
+
+ void testFuzzyCompare_data();
+ void testFuzzyCompare();
+
+ void testIsNull_data();
+ void testIsNull();
+
void testIntersection();
void testIntersection_data();
@@ -41,6 +52,120 @@ private slots:
};
const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4;
+constexpr static qreal qreal_min = std::numeric_limits<qreal>::min();
+
+void tst_QLine::testComparisonCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QLine>();
+ QTestPrivate::testEqualityOperatorsCompile<QLineF>();
+ QTestPrivate::testEqualityOperatorsCompile<QLineF, QLine>();
+}
+
+void tst_QLine::testComparison_data()
+{
+ QTest::addColumn<double>("xa1");
+ QTest::addColumn<double>("ya1");
+ QTest::addColumn<double>("xa2");
+ QTest::addColumn<double>("ya2");
+ QTest::addColumn<double>("xb1");
+ QTest::addColumn<double>("yb1");
+ QTest::addColumn<double>("xb2");
+ QTest::addColumn<double>("yb2");
+ QTest::addColumn<bool>("result");
+ QTest::addColumn<bool>("floatResult");
+ QTest::addColumn<bool>("mixedResult");
+
+ auto row = [&](double xa1, double ya1, double xa2, double ya2,
+ double xb1, double yb1, double xb2, double yb2,
+ bool result, bool floatResult, bool mixedResult)
+ {
+ QString str;
+ QDebug dbg(&str);
+ dbg.nospace() << "[(" << xa1 << ", " << ya1 << "); (" << xa2 << ", " << ya2 << ")] vs [("
+ << xb1 << ", " << yb1 << "); (" << xb2 << ", " << yb2 << ")]";
+ QTest::addRow("%s", str.toLatin1().constData())
+ << xa1 << ya1 << xa2 << ya2 << xb1 << yb1 << xb2 << yb2
+ << result << floatResult << mixedResult;
+ };
+
+ row(-1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, true, true, true);
+ row(-1.1, -0.9, 1.1, 0.9, -1.0, -1.0, 1.0, 1.0, true, false, false);
+ row(-1.0, -1.0, 1.0, 1.0, -0.9, -1.1, 0.9, 1.1, true, false, true);
+ row(-qreal_min, -1.0, 1.0, qreal_min, 0.0, -1.1, 0.9, 0.0, true, false, true);
+}
+
+void tst_QLine::testComparison()
+{
+ QFETCH(double, xa1);
+ QFETCH(double, ya1);
+ QFETCH(double, xa2);
+ QFETCH(double, ya2);
+ QFETCH(double, xb1);
+ QFETCH(double, yb1);
+ QFETCH(double, xb2);
+ QFETCH(double, yb2);
+ QFETCH(bool, result);
+ QFETCH(bool, floatResult);
+ QFETCH(bool, mixedResult);
+
+ const QLineF l1f(xa1, ya1, xa2, ya2);
+ const QLine l1 = l1f.toLine();
+
+ const QLineF l2f(xb1, yb1, xb2, yb2);
+ const QLine l2 = l2f.toLine();
+
+ QT_TEST_EQUALITY_OPS(l1, l2, result);
+ QT_TEST_EQUALITY_OPS(l1f, l2f, floatResult);
+ QT_TEST_EQUALITY_OPS(l1f, l2, mixedResult);
+}
+
+void tst_QLine::testFuzzyCompare_data()
+{
+ testComparison_data();
+}
+
+void tst_QLine::testFuzzyCompare()
+{
+ QFETCH(double, xa1);
+ QFETCH(double, ya1);
+ QFETCH(double, xa2);
+ QFETCH(double, ya2);
+ QFETCH(double, xb1);
+ QFETCH(double, yb1);
+ QFETCH(double, xb2);
+ QFETCH(double, yb2);
+ QFETCH(bool, floatResult);
+
+ const QLineF l1f(xa1, ya1, xa2, ya2);
+ const QLineF l2f(xb1, yb1, xb2, yb2);
+
+ QCOMPARE_EQ(qFuzzyCompare(l1f, l2f), floatResult);
+}
+
+void tst_QLine::testIsNull_data()
+{
+ QTest::addColumn<QLineF>("lineF");
+ QTest::addColumn<bool>("result");
+ QTest::addColumn<bool>("floatResult");
+
+ QTest::newRow("non-null") << QLineF(1.0, 1.0, 2.0, 2.0) << false << false;
+ QTest::newRow("null") << QLineF(1.0, 1.0, 1.0, 1.0) << true << true;
+ QTest::newRow("null_int_non-null_float") << QLineF(1.0, 1.0, 1.1, 1.1) << true << false;
+ QTest::newRow("with_qreal_min") << QLineF(-qreal_min, qreal_min, 0.0, 0.0) << true << true;
+}
+
+void tst_QLine::testIsNull()
+{
+ QFETCH(QLineF, lineF);
+ QFETCH(bool, result);
+ QFETCH(bool, floatResult);
+
+ const QLine line = lineF.toLine();
+
+ QCOMPARE_EQ(line.isNull(), result);
+ QCOMPARE_EQ(lineF.isNull(), floatResult);
+ QCOMPARE_EQ(qFuzzyIsNull(lineF), floatResult);
+}
void tst_QLine::testSet()
{
diff --git a/tests/auto/corelib/tools/qlist/CMakeLists.txt b/tests/auto/corelib/tools/qlist/CMakeLists.txt
index debd47bc75..fdcfcd7424 100644
--- a/tests/auto/corelib/tools/qlist/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qlist/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qlist Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qlist LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qlist
SOURCES
tst_qlist.cpp
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
index 482079b0fe..35d69e8433 100644
--- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp
+++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
@@ -1,15 +1,15 @@
// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QAtomicInt>
#include <QThread>
#include <QSemaphore>
-#include <private/qatomicscopedvaluerollback_p.h>
+#include <QAtomicScopedValueRollback>
#include <qlist.h>
-#if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11)
+#ifdef QT_COMPILER_HAS_LWG3346
# if __has_include(<concepts>)
# include <concepts>
# if defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
@@ -231,6 +231,16 @@ private slots:
void appendCustom() const { append<Custom>(); }
void appendRvalue() const;
void appendList() const;
+ void assignEmpty() const;
+ void assignInt() const { assign<int>(); }
+ void assignMovable() const { assign<Movable>(); }
+ void assignCustom() const { assign<Custom>(); }
+ void assignUsesPrependBuffer_int_data() { assignUsesPrependBuffer_data(); }
+ void assignUsesPrependBuffer_int() const { assignUsesPrependBuffer<int>(); }
+ void assignUsesPrependBuffer_Movable_data() { assignUsesPrependBuffer_data(); }
+ void assignUsesPrependBuffer_Movable() const { assignUsesPrependBuffer<Movable>(); }
+ void assignUsesPrependBuffer_Custom_data() { assignUsesPrependBuffer_data(); }
+ void assignUsesPrependBuffer_Custom() const { assignUsesPrependBuffer<Custom>(); }
void at() const;
void capacityInt() const { capacity<int>(); }
void capacityMovable() const { capacity<Movable>(); }
@@ -312,6 +322,7 @@ private slots:
void resizeToZero() const;
void resizeToTheSameSize_data();
void resizeToTheSameSize() const;
+ void resizeForOverwrite() const;
void iterators() const;
void constIterators() const;
void reverseIterators() const;
@@ -396,6 +407,9 @@ private:
template<typename T> void testAssignment() const;
template<typename T> void add() const;
template<typename T> void append() const;
+ template<typename T> void assign() const;
+ void assignUsesPrependBuffer_data() const;
+ template<typename T> void assignUsesPrependBuffer() const;
template<typename T> void assignFromInitializerList() const;
template<typename T> void capacity() const;
template<typename T> void clear() const;
@@ -548,25 +562,22 @@ void tst_QList::constructors_reserveAndInitialize() const
{
// default-initialise items
- QList<int> myInt(5, 42);
+ const QList<int> myInt(5, 42);
QVERIFY(myInt.capacity() == 5);
- foreach (int meaningoflife, myInt) {
+ for (int meaningoflife : myInt)
QCOMPARE(meaningoflife, 42);
- }
- QList<QString> myString(5, QString::fromLatin1("c++"));
+ const QList<QString> myString(5, QString::fromLatin1("c++"));
QVERIFY(myString.capacity() == 5);
// make sure all items are initialised ok
- foreach (QString meaningoflife, myString) {
+ for (const QString &meaningoflife : myString)
QCOMPARE(meaningoflife, QString::fromLatin1("c++"));
- }
- QList<Custom> myCustom(5, Custom('n'));
+ const QList<Custom> myCustom(5, Custom('n'));
QVERIFY(myCustom.capacity() == 5);
// make sure all items are initialised ok
- foreach (Custom meaningoflife, myCustom) {
+ for (Custom meaningoflife : myCustom)
QCOMPARE(meaningoflife.i, 'n');
- }
}
template<typename T>
@@ -750,6 +761,162 @@ void tst_QList::append() const
}
}
+void tst_QList::assignEmpty() const
+{
+ // Test that the realloc branch in assign(it, it) doesn't crash.
+ using T = int;
+ QList<T> list;
+ QList<T> ref1 = list;
+ QVERIFY(list.d.needsDetach());
+ list.assign(list.begin(), list.begin());
+
+#if !defined Q_OS_QNX // QNX has problems with the empty istream_iterator
+ auto empty = std::istream_iterator<T>{};
+ list.squeeze();
+ QCOMPARE_EQ(list.capacity(), 0);
+ ref1 = list;
+ QVERIFY(list.d.needsDetach());
+ list.assign(empty, empty);
+#endif
+}
+
+template <typename T>
+void tst_QList::assign() const
+{
+ TST_QLIST_CHECK_LEAKS(T)
+ {
+ QList<T> myvec;
+ myvec.assign(2, T_FOO);
+ QVERIFY(myvec.isDetached());
+ QCOMPARE(myvec, QList<T>() << T_FOO << T_FOO);
+
+ QList<T> myvecCopy = myvec;
+ QVERIFY(!myvec.isDetached());
+ QVERIFY(!myvecCopy.isDetached());
+ QVERIFY(myvec.isSharedWith(myvecCopy));
+ QVERIFY(myvecCopy.isSharedWith(myvec));
+
+ myvec.assign(3, T_BAR);
+ QCOMPARE(myvec, QList<T>() << T_BAR << T_BAR << T_BAR);
+ QVERIFY(myvec.isDetached());
+ QVERIFY(myvecCopy.isDetached());
+ QVERIFY(!myvec.isSharedWith(myvecCopy));
+ QVERIFY(!myvecCopy.isSharedWith(myvec));
+ }
+ {
+ QList<T> myvec;
+ myvec.assign(4, T_FOO);
+ QVERIFY(myvec.isDetached());
+ QCOMPARE(myvec, QList<T>() << T_FOO << T_FOO << T_FOO << T_FOO);
+
+ QList<T> myvecCopy = myvec;
+ QVERIFY(!myvec.isDetached());
+ QVERIFY(!myvecCopy.isDetached());
+ QVERIFY(myvec.isSharedWith(myvecCopy));
+ QVERIFY(myvecCopy.isSharedWith(myvec));
+
+ myvecCopy.assign(myvec.begin(), myvec.begin() + 2);
+ QVERIFY(myvec.isDetached());
+ QVERIFY(myvecCopy.isDetached());
+ QVERIFY(!myvec.isSharedWith(myvecCopy));
+ QVERIFY(!myvecCopy.isSharedWith(myvec));
+ QCOMPARE(myvecCopy, QList<T>() << T_FOO << T_FOO);
+ }
+}
+
+inline namespace Scenarios {
+Q_NAMESPACE
+enum ListState {
+ UnsharedList,
+ SharedList,
+};
+Q_ENUM_NS(ListState)
+enum RelationWithPrependBuffer {
+ FitsIntoFreeSpaceAtBegin,
+ FitsFreeSpaceAtBeginExactly,
+ ExceedsFreeSpaceAtBegin,
+ FitsFreeSpaceAtBeginPlusSizeExactly,
+ FullCapacity,
+};
+Q_ENUM_NS(RelationWithPrependBuffer)
+} // namespace Scenarios
+
+void tst_QList::assignUsesPrependBuffer_data() const
+{
+ QTest::addColumn<ListState>("listState");
+ QTest::addColumn<RelationWithPrependBuffer>("relationWithPrependBuffer");
+
+ const auto sme = QMetaEnum::fromType<ListState>();
+ const auto rme = QMetaEnum::fromType<RelationWithPrependBuffer>();
+
+ for (int i = 0, s = sme.value(i); s != -1; s = sme.value(++i)) {
+ for (int j = 0, r = rme.value(j); r != -1; r = rme.value(++j)) {
+ QTest::addRow("%s-%s", sme.key(i), rme.key(j))
+ << ListState(s) << RelationWithPrependBuffer(r);
+ }
+ }
+}
+
+template <typename T>
+void tst_QList::assignUsesPrependBuffer() const
+{
+ QFETCH(const ListState, listState);
+ QFETCH(const RelationWithPrependBuffer, relationWithPrependBuffer);
+
+ const auto capBegin = [](const QList<T> &l) {
+ return l.begin() - l.d.freeSpaceAtBegin();
+ };
+ const auto capEnd = [](const QList<T> &l) {
+ return l.end() + l.d.freeSpaceAtEnd();
+ };
+
+ TST_QLIST_CHECK_LEAKS(T)
+ {
+ // Test the prepend optimization.
+ QList<T> withFreeSpaceAtBegin(16, T_FOO);
+ // try at most 100 times to create freeSpaceAtBegin():
+ for (int i = 0; i < 100 && withFreeSpaceAtBegin.d.freeSpaceAtBegin() < 2; ++i)
+ withFreeSpaceAtBegin.prepend(T_FOO);
+ QCOMPARE_GT(withFreeSpaceAtBegin.d.freeSpaceAtBegin(), 1);
+
+ auto c = [&] {
+ switch (listState) {
+ case UnsharedList: return std::move(withFreeSpaceAtBegin);
+ case SharedList: return withFreeSpaceAtBegin;
+ }
+ Q_UNREACHABLE_RETURN(withFreeSpaceAtBegin);
+ }();
+
+ const auto n = [&] () -> qsizetype {
+ switch (relationWithPrependBuffer) {
+ case FitsIntoFreeSpaceAtBegin:
+ return qsizetype(1);
+ case FitsFreeSpaceAtBeginExactly:
+ return c.d.freeSpaceAtBegin();
+ case ExceedsFreeSpaceAtBegin:
+ return c.d.freeSpaceAtBegin() + 1;
+ case FitsFreeSpaceAtBeginPlusSizeExactly:
+ return c.d.freeSpaceAtBegin() + c.size();
+ case FullCapacity:
+ return c.capacity();
+ };
+ Q_UNREACHABLE_RETURN(0);
+ }();
+
+ const auto oldCapBegin = capBegin(c);
+ const auto oldCapEnd = capEnd(c);
+
+ const std::vector v(n, T_BAR);
+ c.assign(v.begin(), v.end());
+ QCOMPARE_EQ(c.d.freeSpaceAtBegin(), 0); // we used the prepend-buffer
+ if (listState != SharedList) {
+ // check that we didn't reallocate
+ QCOMPARE_EQ(capBegin(c), oldCapBegin);
+ QCOMPARE_EQ(capEnd(c), oldCapEnd);
+ }
+ }
+}
+
void tst_QList::appendRvalue() const
{
QList<QString> v;
@@ -941,6 +1108,7 @@ void tst_QList::appendList() const
// Using operators
// <<
QList<ConstructionCounted> v6;
+ v6.reserve(4);
v6 << (QList<ConstructionCounted>() << 1 << 2);
v6 << (QList<ConstructionCounted>() << 3 << 4);
QCOMPARE(v6, expectedFour);
@@ -2364,6 +2532,51 @@ void tst_QList::resizeToTheSameSize() const
QCOMPARE(y.size(), x.size());
}
+void tst_QList::resizeForOverwrite() const
+{
+ constexpr int BUILD_COUNT = 42;
+ {
+ // Smoke test
+ QList<int> l(BUILD_COUNT, Qt::Uninitialized);
+ l.resizeForOverwrite(l.size() + BUILD_COUNT);
+ }
+
+ {
+ const int beforeCounter = Movable::counter.loadRelaxed();
+ QList<Movable> l(BUILD_COUNT, Qt::Uninitialized);
+ const int after1Counter = Movable::counter.loadRelaxed();
+ QCOMPARE(after1Counter, beforeCounter + BUILD_COUNT);
+
+ l.resizeForOverwrite(l.size() + BUILD_COUNT);
+ const int after2Counter = Movable::counter.loadRelaxed();
+ QCOMPARE(after2Counter, after1Counter + BUILD_COUNT);
+ }
+
+ struct QtInitializationSupport {
+ bool wasInitialized;
+ QtInitializationSupport() : wasInitialized(true) {}
+ explicit QtInitializationSupport(Qt::Initialization) : wasInitialized(false) {}
+ };
+
+ {
+ QList<QtInitializationSupport> l(BUILD_COUNT);
+ for (const auto &elem : l)
+ QVERIFY(elem.wasInitialized);
+ l.resize(l.size() + BUILD_COUNT);
+ for (const auto &elem : l)
+ QVERIFY(elem.wasInitialized);
+ }
+
+ {
+ QList<QtInitializationSupport> l(BUILD_COUNT, Qt::Uninitialized);
+ for (const auto &elem : l)
+ QVERIFY(!elem.wasInitialized);
+ l.resizeForOverwrite(l.size() + BUILD_COUNT);
+ for (const auto &elem : l)
+ QVERIFY(!elem.wasInitialized);
+ }
+}
+
void tst_QList::iterators() const
{
QList<int> v;
@@ -3613,7 +3826,7 @@ void tst_QList::stability_append() const
std::generate(v.begin(), v.end(), [&k]() { return SimpleValue<T>::at(k++); });
QList<T> src(1, SimpleValue<T>::at(0));
v.append(src.begin(), src.end());
- QVERIFY(v.size() < v.capacity());
+ QCOMPARE_LE(v.size(), v.capacity());
for (int i = 0; i < v.capacity() - v.size(); ++i) {
auto [copy, reference] = qlistCopyAndReferenceFromRange(v.begin(), v.end());
diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt b/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt
index 93db3e0077..b968945ac6 100644
--- a/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmacautoreleasepool/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qmacautoreleasepool Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmacautoreleasepool LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmacautoreleasepool
SOURCES
tst_qmacautoreleasepool.mm
diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
index e18d848f87..e7923b47f3 100644
--- a/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
+++ b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
@@ -1,5 +1,5 @@
// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -14,7 +14,6 @@ private slots:
void noPool();
void rootLevelPool();
void stackAllocatedPool();
- void heapAllocatedPool();
};
static id lastDeallocedObject = nil;
@@ -63,26 +62,6 @@ void tst_QMacAutoreleasePool::stackAllocatedPool()
[pool drain];
}
-void tst_QMacAutoreleasePool::heapAllocatedPool()
-{
- // The special case, a pool allocated on the heap, or as a member of a
- // heap allocated object. This is not a supported use of QMacAutoReleasePool,
- // and will result in warnings if the pool is prematurely drained.
-
- NSObject *allocedObject = nil;
- {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- QMacAutoReleasePool *qtPool = nullptr;
- {
- qtPool = new QMacAutoReleasePool;
- allocedObject = [[[DeallocTracker alloc] init] autorelease];
- }
- [pool drain];
- delete qtPool;
- }
- QCOMPARE(lastDeallocedObject, allocedObject);
-}
-
QTEST_APPLESS_MAIN(tst_QMacAutoreleasePool)
#include "tst_qmacautoreleasepool.moc"
diff --git a/tests/auto/corelib/tools/qmakearray/CMakeLists.txt b/tests/auto/corelib/tools/qmakearray/CMakeLists.txt
index 2de6028f39..cec589628f 100644
--- a/tests/auto/corelib/tools/qmakearray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmakearray/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qmakearray Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmakearray LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmakearray
SOURCES
tst_qmakearray.cpp
diff --git a/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp b/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp
index ffd99a0309..1d796452b0 100644
--- a/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp
+++ b/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/corelib/tools/qmap/CMakeLists.txt b/tests/auto/corelib/tools/qmap/CMakeLists.txt
index 056902eb82..bddf9267f8 100644
--- a/tests/auto/corelib/tools/qmap/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmap/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qmap Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmap LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmap
SOURCES
tst_qmap.cpp
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index 577ea1e898..6950dcf705 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -1,9 +1,13 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qmap.h>
#include <QTest>
+
#include <QDebug>
+#include <QScopeGuard>
+
+using namespace Qt::StringLiterals;
QT_WARNING_DISABLE_DEPRECATED
@@ -61,6 +65,8 @@ private slots:
void removeElementsInMap();
void toStdMap();
+ void multiMapStoresInReverseInsertionOrder();
+
// Tests for deprecated APIs.
#if QT_DEPRECATED_SINCE(6, 0)
void deprecatedInsertMulti();
@@ -634,16 +640,19 @@ void tst_QMap::operator_eq()
QMap<int, int> b;
QVERIFY(a == b);
+ QCOMPARE(qHash(a), qHash(b));
QVERIFY(!(a != b));
a.insert(1,1);
b.insert(1,1);
QVERIFY(a == b);
+ QCOMPARE(qHash(a), qHash(b));
QVERIFY(!(a != b));
a.insert(0,1);
b.insert(0,1);
QVERIFY(a == b);
+ QCOMPARE(qHash(a), qHash(b));
QVERIFY(!(a != b));
// compare for inequality:
@@ -666,6 +675,7 @@ void tst_QMap::operator_eq()
QMap<QString, QString> b;
QVERIFY(a == b);
+ QCOMPARE(qHash(a), qHash(b));
QVERIFY(!(a != b));
a.insert("Hello", "World");
@@ -674,6 +684,7 @@ void tst_QMap::operator_eq()
b.insert("Hello", "World");
QVERIFY(a == b);
+ QCOMPARE(qHash(a), qHash(b));
QVERIFY(!(a != b));
a.insert("Goodbye", "cruel world");
@@ -690,6 +701,7 @@ void tst_QMap::operator_eq()
// empty keys and null keys match:
b.insert(QString(""), QString());
QVERIFY(a == b);
+ QCOMPARE(qHash(a), qHash(b));
QVERIFY(!(a != b));
}
@@ -2548,6 +2560,24 @@ void tst_QMap::toStdMap()
toStdMapTestMethod<QMultiMap<int, QString>>(expectedMultiMap);
}
+void tst_QMap::multiMapStoresInReverseInsertionOrder()
+{
+ const QString strings[] = {
+ u"zero"_s,
+ u"null"_s,
+ u"nada"_s,
+ };
+ {
+ QMultiMap<int, QString> map;
+ for (const QString &string : strings)
+ map.insert(0, string);
+ auto printOnFailure = qScopeGuard([&] { qDebug() << map; });
+ QVERIFY(std::equal(map.begin(), map.end(),
+ std::rbegin(strings), std::rend(strings)));
+ printOnFailure.dismiss();
+ }
+}
+
#if QT_DEPRECATED_SINCE(6, 0)
void tst_QMap::deprecatedInsertMulti()
{
diff --git a/tests/auto/corelib/tools/qmargins/CMakeLists.txt b/tests/auto/corelib/tools/qmargins/CMakeLists.txt
index d3eea70fb8..b0adf63f40 100644
--- a/tests/auto/corelib/tools/qmargins/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmargins/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qmargins Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmargins LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmargins
SOURCES
tst_qmargins.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
index 4b49d152a3..dc0b0e4085 100644
--- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
+++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QMargins>
#ifdef QVARIANT_H
@@ -32,15 +32,28 @@ CHECK(const &&);
#include <QTest>
#include <qmargins.h>
+#include <private/qcomparisontesthelper_p.h>
#include <array>
Q_DECLARE_METATYPE(QMargins)
+constexpr static qreal qreal_min = std::numeric_limits<qreal>::min();
+
class tst_QMargins : public QObject
{
Q_OBJECT
private slots:
+ void comparisonCompiles();
+ void comparison_data();
+ void comparison();
+
+ void fuzzyComparison_data();
+ void fuzzyComparison();
+
+ void isNull_data();
+ void isNull();
+
void getSetCheck();
#ifndef QT_NO_DATASTREAM
void dataStreamCheck();
@@ -65,6 +78,92 @@ private slots:
void toMarginsF();
};
+void tst_QMargins::comparisonCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QMargins>();
+ QTestPrivate::testEqualityOperatorsCompile<QMarginsF>();
+ QTestPrivate::testEqualityOperatorsCompile<QMarginsF, QMargins>();
+}
+
+void tst_QMargins::comparison_data()
+{
+ QTest::addColumn<QMarginsF>("lhs");
+ QTest::addColumn<QMarginsF>("rhs");
+ QTest::addColumn<bool>("result");
+ QTest::addColumn<bool>("floatResult");
+ QTest::addColumn<bool>("mixedResult");
+
+ auto row = [](const QMarginsF &lhs, const QMarginsF &rhs, bool res, bool fRes, bool mRes) {
+ QString str;
+ QDebug dbg(&str);
+ dbg.nospace() << "(" << lhs.left() << ", " << lhs.top() << ", " << lhs.right() << ", "
+ << lhs.bottom() << ") vs (" << rhs.left() << ", " << rhs.top() << ", "
+ << rhs.right() << ", " << rhs.bottom() << ")";
+ QTest::addRow("%s", str.toLatin1().constData()) << lhs << rhs << res << fRes << mRes;
+ };
+
+ row(QMarginsF(0.0, 0.0, 0.0, 0.0), QMarginsF(0.0, 0.0, 0.0, 0.0), true, true, true);
+ row(QMarginsF(qreal_min, -qreal_min, -qreal_min, qreal_min), QMarginsF(0.0, 0.0, 0.0, 0.0), true, true, true);
+ row(QMarginsF(1.0, 2.0, 3.0, 4.0), QMarginsF(1.1, 2.1, 2.9, 3.9), true, false, true);
+ row(QMarginsF(1.5, 2.5, 3.0, 4.0), QMarginsF(1.1, 2.1, 2.9, 3.9), false, false, false);
+}
+
+void tst_QMargins::comparison()
+{
+ QFETCH(const QMarginsF, lhs);
+ QFETCH(const QMarginsF, rhs);
+ QFETCH(const bool, result);
+ QFETCH(const bool, floatResult);
+ QFETCH(const bool, mixedResult);
+
+ QT_TEST_EQUALITY_OPS(lhs, rhs, floatResult);
+
+ const QMargins lhsInt = lhs.toMargins();
+ const QMargins rhsInt = rhs.toMargins();
+ QT_TEST_EQUALITY_OPS(lhsInt, rhsInt, result);
+
+ QT_TEST_EQUALITY_OPS(lhs, rhsInt, mixedResult);
+}
+
+void tst_QMargins::fuzzyComparison_data()
+{
+ comparison_data();
+}
+
+void tst_QMargins::fuzzyComparison()
+{
+ QFETCH(const QMarginsF, lhs);
+ QFETCH(const QMarginsF, rhs);
+ QFETCH(const bool, floatResult);
+
+ QCOMPARE_EQ(qFuzzyCompare(lhs, rhs), floatResult);
+}
+
+void tst_QMargins::isNull_data()
+{
+ QTest::addColumn<QMarginsF>("margins");
+ QTest::addColumn<bool>("result");
+
+ QTest::newRow("null") << QMarginsF(0.0, 0.0, 0.0, 0.0) << true;
+ QTest::newRow("non_null_left") << QMarginsF(1.0, 0.0, 0.0, 0.0) << false;
+ QTest::newRow("non_null_top") << QMarginsF(0.0, 0.5, 0.0, 0.0) << false;
+ QTest::newRow("non_null_right") << QMarginsF(0.0, 0.0, -2.0, 0.0) << false;
+ QTest::newRow("non_null_bottom") << QMarginsF(0.0, 0.0, 0.0, -0.6) << false;
+ QTest::newRow("almost_null") << QMarginsF(qreal_min, -qreal_min, qreal_min, -qreal_min) << true;
+}
+
+void tst_QMargins::isNull()
+{
+ QFETCH(const QMarginsF, margins);
+ QFETCH(const bool, result);
+
+ QCOMPARE_EQ(margins.isNull(), result);
+ QCOMPARE_EQ(qFuzzyIsNull(margins), result);
+
+ const QMargins marginsInt = margins.toMargins();
+ QCOMPARE_EQ(marginsInt.isNull(), result);
+}
+
// Testing get/set functions
void tst_QMargins::getSetCheck()
{
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt b/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt
index a898453671..a21481b7ba 100644
--- a/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qmessageauthenticationcode Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmessageauthenticationcode LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmessageauthenticationcode
SOURCES
tst_qmessageauthenticationcode.cpp
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
index c49cd538d2..9e94ad77e9 100644
--- a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
@@ -1,5 +1,5 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QCoreApplication>
diff --git a/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt b/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt
index 9c56f0208d..d0205cfa15 100644
--- a/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qoffsetstringarray Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qoffsetstringarray LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qoffsetstringarray
SOURCES
tst_qoffsetstringarray.cpp
diff --git a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp
index 669f14cc92..dbb24e7af4 100644
--- a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp
+++ b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/corelib/tools/qpair/CMakeLists.txt b/tests/auto/corelib/tools/qpair/CMakeLists.txt
index b72ebd31e3..2dd048e015 100644
--- a/tests/auto/corelib/tools/qpair/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qpair/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qpair Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpair LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpair
SOURCES
tst_qpair.cpp
diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp
index d3a706995f..0c9d87bb01 100644
--- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp
+++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp
@@ -1,5 +1,5 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/corelib/tools/qpoint/CMakeLists.txt b/tests/auto/corelib/tools/qpoint/CMakeLists.txt
index a385948f43..82ece1fc15 100644
--- a/tests/auto/corelib/tools/qpoint/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qpoint/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qpoint Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpoint LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpoint
SOURCES
tst_qpoint.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
index 76a4ccc086..4763c1bf07 100644
--- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
+++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
@@ -1,10 +1,11 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QPoint>
#ifdef QVARIANT_H
# error "This test requires qpoint.h to not include qvariant.h"
#endif
+#include <private/qcomparisontesthelper_p.h>
// don't assume <type_traits>
template <typename T, typename U>
@@ -71,6 +72,7 @@ private slots:
void operator_unary_minus_data();
void operator_unary_minus();
+ void operatorsCompile();
void operator_eq_data();
void operator_eq();
@@ -155,6 +157,8 @@ void tst_QPoint::toPointF()
QFETCH(const QPointF, result);
QCOMPARE(input.toPointF(), result);
+ // test also mixed-type comparison
+ QT_TEST_EQUALITY_OPS(input, result, true);
}
void tst_QPoint::transposed()
@@ -350,6 +354,12 @@ void tst_QPoint::operator_unary_minus()
QCOMPARE(-point, expected);
}
+void tst_QPoint::operatorsCompile()
+{
+ // Mixed-type comparison is tested in tst_QPointF.
+ QTestPrivate::testEqualityOperatorsCompile<QPoint>();
+}
+
void tst_QPoint::operator_eq_data()
{
QTest::addColumn<QPoint>("point1");
@@ -371,12 +381,9 @@ void tst_QPoint::operator_eq()
QFETCH(QPoint, point2);
QFETCH(bool, expectEqual);
- bool equal = point1 == point2;
- QCOMPARE(equal, expectEqual);
- bool notEqual = point1 != point2;
- QCOMPARE(notEqual, !expectEqual);
+ QT_TEST_EQUALITY_OPS(point1, point2, expectEqual);
- if (equal)
+ if (expectEqual)
QCOMPARE(qHash(point1), qHash(point2));
}
diff --git a/tests/auto/corelib/tools/qpointf/CMakeLists.txt b/tests/auto/corelib/tools/qpointf/CMakeLists.txt
index e30a343fad..28cbe185b2 100644
--- a/tests/auto/corelib/tools/qpointf/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qpointf/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qpointf Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpointf LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpointf
SOURCES
tst_qpointf.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
index 14953039a1..ebbac4ec7c 100644
--- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
+++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
@@ -1,10 +1,11 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QPointF>
#ifdef QVARIANT_H
# error "This test requires qpoint.h to not include qvariant.h"
#endif
+#include <private/qcomparisontesthelper_p.h>
// don't assume <type_traits>
template <typename T, typename U>
@@ -71,9 +72,13 @@ private slots:
void operator_unary_minus_data();
void operator_unary_minus();
+ void operatorsCompile();
void operator_eq_data();
void operator_eq();
+ void fuzzyCompare_data();
+ void fuzzyCompare();
+
void toPoint_data();
void toPoint();
@@ -101,15 +106,19 @@ void tst_QPointF::isNull()
{
QPointF point(0, 0);
QVERIFY(point.isNull());
+ QVERIFY(qFuzzyIsNull(point));
++point.rx();
QVERIFY(!point.isNull());
+ QVERIFY(!qFuzzyIsNull(point));
point.rx() -= 2;
QVERIFY(!point.isNull());
+ QVERIFY(!qFuzzyIsNull(point));
QPointF nullNegativeZero(qreal(-0.0), qreal(-0.0));
QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f);
QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f);
QVERIFY(nullNegativeZero.isNull());
+ QVERIFY(qFuzzyIsNull(nullNegativeZero));
}
void tst_QPointF::manhattanLength_data()
@@ -345,21 +354,29 @@ void tst_QPointF::operator_unary_minus()
QCOMPARE(-point, expected);
}
+void tst_QPointF::operatorsCompile()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QPointF>();
+ QTestPrivate::testEqualityOperatorsCompile<QPointF, QPoint>();
+}
+
void tst_QPointF::operator_eq_data()
{
QTest::addColumn<QPointF>("point1");
QTest::addColumn<QPointF>("point2");
QTest::addColumn<bool>("expectEqual");
-
- QTest::newRow("(0, 0) == (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << true;
- QTest::newRow("(-1, 0) == (-1, 0)") << QPointF(-1, 0) << QPointF(-1, 0) << true;
- QTest::newRow("(-1, 0) != (0, 0)") << QPointF(-1, 0) << QPointF(0, 0) << false;
- QTest::newRow("(-1, 0) != (0, -1)") << QPointF(-1, 0) << QPointF(0, -1) << false;
- QTest::newRow("(-1.125, 0.25) == (-1.125, 0.25)") << QPointF(-1.125, 0.25) << QPointF(-1.125, 0.25) << true;
+ QTest::addColumn<bool>("expectIntEqual");
+
+ QTest::newRow("(0, 0) == (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << true << true;
+ QTest::newRow("(-1, 0) == (-1, 0)") << QPointF(-1, 0) << QPointF(-1, 0) << true << true;
+ QTest::newRow("(-1, 0) != (0, 0)") << QPointF(-1, 0) << QPointF(0, 0) << false << false;
+ QTest::newRow("(-1, 0) != (0, -1)") << QPointF(-1, 0) << QPointF(0, -1) << false << false;
+ QTest::newRow("(-1.125, 0.25) == (-1.125, 0.25)")
+ << QPointF(-1.125, 0.25) << QPointF(-1.125, 0.25) << true << false;
QTest::newRow("(QREAL_MIN, QREAL_MIN) == (QREAL_MIN, QREAL_MIN)")
- << QPointF(QREAL_MIN, QREAL_MIN) << QPointF(QREAL_MIN, QREAL_MIN) << true;
+ << QPointF(QREAL_MIN, QREAL_MIN) << QPointF(QREAL_MIN, QREAL_MIN) << true << true;
QTest::newRow("(QREAL_MAX, QREAL_MAX) == (QREAL_MAX, QREAL_MAX)")
- << QPointF(QREAL_MAX, QREAL_MAX) << QPointF(QREAL_MAX, QREAL_MAX) << true;
+ << QPointF(QREAL_MAX, QREAL_MAX) << QPointF(QREAL_MAX, QREAL_MAX) << true << false;
}
void tst_QPointF::operator_eq()
@@ -367,11 +384,26 @@ void tst_QPointF::operator_eq()
QFETCH(QPointF, point1);
QFETCH(QPointF, point2);
QFETCH(bool, expectEqual);
+ QFETCH(bool, expectIntEqual);
+
+ QT_TEST_EQUALITY_OPS(point1, point2, expectEqual);
+
+ const QPoint intPoint2 = point2.toPoint();
+ QT_TEST_EQUALITY_OPS(point1, intPoint2, expectIntEqual);
+}
+
+void tst_QPointF::fuzzyCompare_data()
+{
+ operator_eq_data();
+}
+
+void tst_QPointF::fuzzyCompare()
+{
+ QFETCH(QPointF, point1);
+ QFETCH(QPointF, point2);
+ QFETCH(bool, expectEqual);
- bool equal = point1 == point2;
- QCOMPARE(equal, expectEqual);
- bool notEqual = point1 != point2;
- QCOMPARE(notEqual, !expectEqual);
+ QCOMPARE_EQ(qFuzzyCompare(point1, point2), expectEqual);
}
void tst_QPointF::toPoint_data()
diff --git a/tests/auto/corelib/tools/qqueue/CMakeLists.txt b/tests/auto/corelib/tools/qqueue/CMakeLists.txt
index 943cef51a3..bf229eee6a 100644
--- a/tests/auto/corelib/tools/qqueue/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qqueue/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qqueue Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qqueue LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qqueue
SOURCES
tst_qqueue.cpp
diff --git a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
index ed66806f96..44d4c34768 100644
--- a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
+++ b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/corelib/tools/qrect/CMakeLists.txt b/tests/auto/corelib/tools/qrect/CMakeLists.txt
index 0f8eef67bb..c98c836379 100644
--- a/tests/auto/corelib/tools/qrect/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qrect/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qrect Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qrect LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qrect
SOURCES
tst_qrect.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
index d37a5c52b0..c7c8b3a560 100644
--- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp
+++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qrect.h>
@@ -7,6 +7,8 @@
#include <limits.h>
#include <qdebug.h>
+#include <private/qcomparisontesthelper_p.h>
+
#include <array>
class tst_QRect : public QObject
@@ -33,8 +35,14 @@ public:
static QPoint getQPointCase( QPointCases p );
private slots:
+ void comparisonCompiles();
+ void comparison_data();
+ void comparison();
+ void fuzzyComparison_data();
+ void fuzzyComparison();
void isNull_data();
void isNull();
+ void fuzzyIsNull();
void newIsEmpty_data();
void newIsEmpty();
void newIsValid_data();
@@ -160,6 +168,8 @@ private slots:
#define LARGE 1000000000
static bool isLarge(int x) { return x > LARGE || x < -LARGE; }
+static constexpr qreal qreal_min = std::numeric_limits<qreal>::min();
+
QRect tst_QRect::getQRectCase( QRectCases c )
{
// Should return the best variety of possible QRects, if a
@@ -242,6 +252,80 @@ QPoint tst_QRect::getQPointCase( QPointCases p )
}
}
+void tst_QRect::comparisonCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QRect>();
+ QTestPrivate::testEqualityOperatorsCompile<QRectF>();
+ QTestPrivate::testEqualityOperatorsCompile<QRectF, QRect>();
+}
+
+void tst_QRect::comparison_data()
+{
+ QTest::addColumn<QRectF>("lhsF");
+ QTest::addColumn<QRectF>("rhsF");
+ QTest::addColumn<bool>("result");
+ QTest::addColumn<bool>("floatResult");
+ QTest::addColumn<bool>("mixedResult");
+
+ QTest::newRow("Invalid_vs_Invalid") << getQRectCase(InvalidQRect).toRectF()
+ << getQRectCase(InvalidQRect).toRectF()
+ << true << true << true;
+
+ QTest::newRow("Null_vs_Null") << getQRectCase(NullQRect).toRectF()
+ << getQRectCase(NullQRect).toRectF()
+ << true << true << true;
+
+ QTest::newRow("Empty_vs_Empty") << getQRectCase(EmptyQRect).toRectF()
+ << getQRectCase(EmptyQRect).toRectF()
+ << true << true << true;
+
+ QTest::newRow("NegativeSize_vs_NegativeSize") << getQRectCase(NegativeSizeQRect).toRectF()
+ << getQRectCase(NegativeSizeQRect).toRectF()
+ << true << true << true;
+
+ QTest::newRow("Invalid_vs_Null") << getQRectCase(InvalidQRect).toRectF()
+ << getQRectCase(NullQRect).toRectF()
+ << false << false << false;
+
+ QTest::newRow("NearlySimilar") << QRectF(QPointF(1.1, 9.9), QPointF(9.9, 1.1))
+ << QRectF(QPointF(1., 10.), QPointF(10., 1.))
+ << true << false << true;
+
+ QTest::newRow("WithQREAL_MIN") << QRectF(QPointF(0., -10.), QPointF(-1., 0.))
+ << QRectF(QPointF(-qreal_min, -10.), QPointF(-1., qreal_min))
+ << true << true << true;
+}
+
+void tst_QRect::comparison()
+{
+ QFETCH(const QRectF, lhsF);
+ QFETCH(const QRectF, rhsF);
+ QFETCH(const bool, result);
+ QFETCH(const bool, floatResult);
+ QFETCH(const bool, mixedResult);
+
+ const QRect lhs = lhsF.toRect();
+ const QRect rhs = rhsF.toRect();
+
+ QT_TEST_EQUALITY_OPS(lhs, rhs, result);
+ QT_TEST_EQUALITY_OPS(lhsF, rhsF, floatResult);
+ QT_TEST_EQUALITY_OPS(lhs, rhsF, mixedResult);
+}
+
+void tst_QRect::fuzzyComparison_data()
+{
+ comparison_data();
+}
+
+void tst_QRect::fuzzyComparison()
+{
+ QFETCH(const QRectF, lhsF);
+ QFETCH(const QRectF, rhsF);
+ QFETCH(const bool, floatResult);
+
+ QCOMPARE_EQ(qFuzzyCompare(lhsF, rhsF), floatResult);
+}
+
void tst_QRect::isNull_data()
{
QTest::addColumn<QRect>("r");
@@ -271,6 +355,14 @@ void tst_QRect::isNull()
QVERIFY( rf.isNull() == isNull );
}
+void tst_QRect::fuzzyIsNull()
+{
+ QRectF rf(QPointF(-qreal_min, qreal_min), QPointF(qreal_min, -qreal_min));
+
+ QVERIFY(!rf.isNull()); // QRectF::isNull() does strict comparison
+ QVERIFY(qFuzzyIsNull(rf));
+}
+
void tst_QRect::newIsEmpty_data()
{
QTest::addColumn<QRect>("r");
diff --git a/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt b/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt
index e29ab7ddaa..cfb7c6f461 100644
--- a/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qringbuffer/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qringbuffer Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qringbuffer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qringbuffer
SOURCES
tst_qringbuffer.cpp
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index dec6319159..c7b79cfae1 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QBuffer>
diff --git a/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt
index f396cfe0e3..7bfcfdebbf 100644
--- a/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qscopedpointer/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qscopedpointer Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qscopedpointer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qscopedpointer
SOURCES
tst_qscopedpointer.cpp
diff --git a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
index 367cfb5b5d..3468c97f42 100644
--- a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
+++ b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtCore/QScopedPointer>
diff --git a/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt b/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt
index b268181bac..359a910a0a 100644
--- a/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qscopedvaluerollback/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qscopedvaluerollback Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qscopedvaluerollback LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qscopedvaluerollback
SOURCES
tst_qscopedvaluerollback.cpp
diff --git a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
index ad36504ff6..3b493b4e75 100644
--- a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
+++ b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtCore/QScopedValueRollback>
diff --git a/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt b/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt
index 050786cb41..6f6d664554 100644
--- a/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qscopeguard/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qscopeguard Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qscopeguard LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qscopeguard
SOURCES
tst_qscopeguard.cpp
diff --git a/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
index 015cbcc0e7..b7c2b952e2 100644
--- a/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
+++ b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
@@ -1,10 +1,12 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtCore/QScopeGuard>
+#include <optional>
+
/*!
\class tst_QScopeGuard
\internal
@@ -20,6 +22,7 @@ private Q_SLOTS:
void construction();
void constructionFromLvalue();
void constructionFromRvalue();
+ void optionalGuard();
void leavingScope();
void exceptions();
};
@@ -117,6 +120,24 @@ void tst_QScopeGuard::constructionFromRvalue()
QCOMPARE(Callable::moved, 1);
}
+void tst_QScopeGuard::optionalGuard()
+{
+ int i = 0;
+ auto lambda = [&] { ++i; };
+ std::optional sg = false ? std::optional{qScopeGuard(lambda)} : std::nullopt;
+ QVERIFY(!sg);
+ QCOMPARE(i, 0);
+ sg.emplace(qScopeGuard(lambda));
+ QVERIFY(sg);
+ sg->dismiss();
+ sg.reset();
+ QCOMPARE(i, 0);
+ sg.emplace(qScopeGuard(lambda));
+ QCOMPARE(i, 0);
+ sg.reset();
+ QCOMPARE(i, 1);
+}
+
void tst_QScopeGuard::leavingScope()
{
auto cleanup = qScopeGuard([] { s_globalState++; QCOMPARE(s_globalState, 3); });
diff --git a/tests/auto/corelib/tools/qset/CMakeLists.txt b/tests/auto/corelib/tools/qset/CMakeLists.txt
index fdaa020528..9e3e33ee7c 100644
--- a/tests/auto/corelib/tools/qset/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qset/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qset Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qset LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qset
SOURCES
tst_qset.cpp
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index 391e00485c..116d38112b 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qset.h>
@@ -856,7 +856,7 @@ void tst_QSet::setOperationsOnEmptySet()
empty.unite(nonEmpty);
QCOMPARE(empty, nonEmpty);
- QVERIFY(empty.isDetached());
+ QVERIFY(!empty.isDetached());
}
}
@@ -939,13 +939,11 @@ void tst_QSet::javaIterator()
QSetIterator<QString> i(set1);
QSetIterator<QString> j(set1);
- int n = 0;
while (i.hasNext()) {
QVERIFY(j.hasNext());
set1.remove(i.peekNext());
sum1 += toNumber(i.next());
sum2 += toNumber(j.next());
- ++n;
}
QVERIFY(!j.hasNext());
QVERIFY(sum1 == 24999 * 25000 / 2);
diff --git a/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt
index 518512560c..0db0cba4c0 100644
--- a/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qsharedpointer Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsharedpointer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsharedpointer
SOURCES
forwarddeclared.cpp
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
index e35ac98a35..c676924668 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "externaltests.h"
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.h b/tests/auto/corelib/tools/qsharedpointer/externaltests.h
index 0d290ef3c7..790ca61992 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.h
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QTEST_EXTERNAL_TESTS_H
diff --git a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp
index d8a5b3125b..5a0af60c11 100644
--- a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.cpp
@@ -1,6 +1,6 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 90811a9074..ba436d99cf 100644
--- a/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h
+++ b/tests/auto/corelib/tools/qsharedpointer/forwarddeclared.h
@@ -1,6 +1,6 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 7d31897db7..b572fa1b9f 100644
--- a/tests/auto/corelib/tools/qsharedpointer/nontracked.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/nontracked.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
/*
* 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 7562de43e6..e10ea08a4d 100644
--- a/tests/auto/corelib/tools/qsharedpointer/nontracked.h
+++ b/tests/auto/corelib/tools/qsharedpointer/nontracked.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 4b1354dc41..f42637a3fe 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -1,7 +1,7 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#define QT_SHAREDPOINTER_TRACK_POINTERS
#include "qsharedpointer.h"
@@ -91,6 +91,7 @@ private slots:
void invalidConstructs_data();
void invalidConstructs();
#endif
+ void ownerComparisons();
// let invalidConstructs be the last test, because it's the slowest;
// add new tests above this block
@@ -1275,6 +1276,22 @@ void tst_QSharedPointer::virtualBaseDifferentPointers()
QVERIFY(baseptr == aBase);
}
safetyCheck();
+ {
+ VirtualDerived *aData = new VirtualDerived;
+
+ QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData);
+ QWeakPointer<VirtualDerived> wptr = ptr;
+
+ ptr.reset();
+ QVERIFY(wptr.toStrongRef().isNull());
+
+ QWeakPointer<Data> wptr2 = wptr;
+ QVERIFY(wptr2.toStrongRef().isNull());
+
+ QWeakPointer<Data> wptr3 = std::move(wptr);
+ QVERIFY(wptr3.toStrongRef().isNull());
+ }
+ safetyCheck();
}
#ifndef QTEST_NO_RTTI
@@ -2825,5 +2842,140 @@ void tst_QSharedPointer::overloads()
weakOverloaded.test();
}
+void tst_QSharedPointer::ownerComparisons()
+{
+ using SP = QSharedPointer<int>;
+ using WP = QWeakPointer<int>;
+
+#define CHECK_EQ(a, b) \
+ do { \
+ QVERIFY(a.owner_equal(b)); \
+ QVERIFY(b.owner_equal(a)); \
+ QVERIFY(!a.owner_before(b)); \
+ QVERIFY(!b.owner_before(a)); \
+ QVERIFY(a.owner_hash() == b.owner_hash()); \
+ } while (false)
+
+#define CHECK_NOT_EQ(a, b) \
+ do { \
+ QVERIFY(!a.owner_equal(b)); \
+ QVERIFY(!b.owner_equal(a)); \
+ QVERIFY(a.owner_before(b) || b.owner_before(a)); \
+ } while (false)
+
+ // null
+ {
+ SP sp1;
+ SP sp2;
+ WP wp1 = sp1;
+ WP wp2;
+
+ CHECK_EQ(sp1, sp1);
+ CHECK_EQ(sp1, sp2);
+ CHECK_EQ(sp1, wp1);
+ CHECK_EQ(sp2, wp2);
+ CHECK_EQ(wp1, wp1);
+ CHECK_EQ(wp1, wp2);
+ CHECK_EQ(wp2, wp2);
+ }
+
+ // same owner
+ {
+ SP sp1 = SP::create(123);
+ SP sp2 = sp1;
+ WP wp1 = sp1;
+ SP wp2 = sp2;
+
+ CHECK_EQ(sp1, sp1);
+ CHECK_EQ(sp1, sp2);
+ CHECK_EQ(sp1, wp1);
+ CHECK_EQ(sp2, wp2);
+ CHECK_EQ(wp1, wp1);
+ CHECK_EQ(wp1, wp2);
+ }
+
+ // owning vs null
+ {
+ SP sp1 = SP::create(123);
+ SP sp2;
+ WP wp1 = sp1;
+ WP wp2 = sp2;
+
+ CHECK_EQ(sp1, sp1);
+ CHECK_NOT_EQ(sp1, sp2);
+ CHECK_EQ(sp1, wp1);
+ CHECK_EQ(sp2, wp2);
+ CHECK_EQ(wp1, wp1);
+ CHECK_NOT_EQ(wp1, wp2);
+ }
+
+ // different owners
+ {
+ SP sp1 = SP::create(123);
+ SP sp2 = SP::create(456);
+ WP wp1 = sp1;
+ WP wp2 = sp2;
+
+ CHECK_EQ(sp1, sp1);
+ CHECK_NOT_EQ(sp1, sp2);
+ CHECK_EQ(sp1, wp1);
+ CHECK_EQ(sp2, wp2);
+ CHECK_EQ(wp1, wp1);
+ CHECK_NOT_EQ(wp1, wp2);
+ }
+
+ // reset vs. null
+ {
+ SP sp1 = SP::create(123);
+ SP sp2;
+ WP wp1 = sp1;
+ WP wp2;
+
+ CHECK_EQ(sp1, sp1);
+ CHECK_NOT_EQ(sp1, sp2);
+ CHECK_EQ(sp1, wp1);
+ CHECK_NOT_EQ(sp1, wp2);
+ CHECK_EQ(wp1, wp1);
+ CHECK_NOT_EQ(wp1, wp2);
+
+ sp1.reset();
+
+ CHECK_EQ(sp1, sp1);
+ CHECK_EQ(sp1, sp2);
+ CHECK_NOT_EQ(sp1, wp1);
+ CHECK_EQ(sp2, wp2);
+ CHECK_EQ(wp1, wp1);
+ CHECK_NOT_EQ(wp1, wp2);
+ }
+
+ // expired weak pointers
+ {
+ WP wp1 = SP::create(123);
+ WP wp2;
+
+ CHECK_EQ(wp1, wp1);
+ CHECK_NOT_EQ(wp1, wp2);
+ }
+
+ {
+ WP wp1 = SP::create(123);
+ WP wp2 = wp1;
+
+ CHECK_EQ(wp1, wp1);
+ CHECK_EQ(wp1, wp2);
+ }
+
+ {
+ WP wp1 = SP::create(123);
+ WP wp2 = SP::create(456);
+
+ CHECK_EQ(wp1, wp1);
+ CHECK_EQ(wp2, wp2);
+ CHECK_NOT_EQ(wp1, wp2);
+ }
+#undef CHECK_EQ
+#undef CHECK_NOT_EQ
+}
+
QTEST_MAIN(tst_QSharedPointer)
#include "tst_qsharedpointer.moc"
diff --git a/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp b/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp
index 07c837304e..b39eee7d98 100644
--- a/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/wrapper.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 32cc09f422..3b0bc09fed 100644
--- a/tests/auto/corelib/tools/qsharedpointer/wrapper.h
+++ b/tests/auto/corelib/tools/qsharedpointer/wrapper.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#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 772aa42f4b..4a4c96b52c 100644
--- a/tests/auto/corelib/tools/qsize/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qsize/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qsize Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsize LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsize
SOURCES
tst_qsize.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qsize/tst_qsize.cpp b/tests/auto/corelib/tools/qsize/tst_qsize.cpp
index 77198c4576..d379275dd8 100644
--- a/tests/auto/corelib/tools/qsize/tst_qsize.cpp
+++ b/tests/auto/corelib/tools/qsize/tst_qsize.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QSize>
#ifdef QVARIANT_H
@@ -24,6 +24,7 @@ CHECK(const &&);
#undef CHECK
#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
#include <qsize.h>
#include <array>
@@ -34,6 +35,10 @@ class tst_QSize : public QObject
{
Q_OBJECT
private slots:
+ void compareCompiles();
+ void compare_data();
+ void compare();
+
void getSetCheck();
void scale();
@@ -55,6 +60,38 @@ private slots:
void structuredBinding();
};
+void tst_QSize::compareCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QSize>();
+}
+
+void tst_QSize::compare_data()
+{
+ QTest::addColumn<QSize>("lhs");
+ QTest::addColumn<QSize>("rhs");
+ QTest::addColumn<bool>("result");
+
+ auto row = [](QSize lhs, QSize rhs, bool res) {
+ QTest::addRow("(%d, %d) vs (%d, %d)", lhs.width(), lhs.height(), rhs.width(), rhs.height())
+ << lhs << rhs << res;
+ };
+
+ row(QSize(0, 0), QSize(0, 0), true);
+ row(QSize(1, 0), QSize(0, 1), false);
+ row(QSize(-1, -1), QSize(-1, -1), true);
+ row(QSize(-1, -1), QSize(1, 1), false);
+ row(QSize(INT_MIN, INT_MAX), QSize(INT_MAX, INT_MIN), false);
+}
+
+void tst_QSize::compare()
+{
+ QFETCH(QSize, lhs);
+ QFETCH(QSize, rhs);
+ QFETCH(bool, result);
+
+ QT_TEST_EQUALITY_OPS(lhs, rhs, result);
+}
+
// Testing get/set functions
void tst_QSize::getSetCheck()
{
diff --git a/tests/auto/corelib/tools/qsizef/CMakeLists.txt b/tests/auto/corelib/tools/qsizef/CMakeLists.txt
index d4be610e42..d8a1c7f46e 100644
--- a/tests/auto/corelib/tools/qsizef/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qsizef/CMakeLists.txt
@@ -5,7 +5,15 @@
## tst_qsizef Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsizef LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsizef
SOURCES
tst_qsizef.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
index 018f929cca..bb087e89de 100644
--- a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
+++ b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QSizeF>
#ifdef QVARIANT_H
@@ -24,17 +24,30 @@ CHECK(const &&);
#undef CHECK
#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
#include <qsize.h>
Q_DECLARE_METATYPE(QMarginsF)
+static constexpr qreal qreal_min = std::numeric_limits<qreal>::min();
+
class tst_QSizeF : public QObject
{
Q_OBJECT
private slots:
+ void compareCompiles();
+ void compare_data();
+ void compare();
+
+ void fuzzyCompare_data();
+ void fuzzyCompare();
+
void isNull_data();
void isNull();
+ void fuzzyIsNull_data();
+ void fuzzyIsNull();
+
void scale();
void expandedTo();
@@ -52,6 +65,61 @@ private slots:
void structuredBinding();
};
+void tst_QSizeF::compareCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QSizeF>();
+ QTestPrivate::testEqualityOperatorsCompile<QSizeF, QSize>();
+}
+
+void tst_QSizeF::compare_data()
+{
+ QTest::addColumn<QSizeF>("lhs");
+ QTest::addColumn<QSizeF>("rhs");
+ QTest::addColumn<bool>("result");
+ QTest::addColumn<bool>("mixedResult");
+
+ auto row = [&](QSizeF lhs, QSizeF rhs, bool res, bool mixedRes) {
+ QString str;
+ QDebug dbg(&str);
+ dbg.nospace() << "(" << lhs.width() << ", " << lhs.height() << ") vs "
+ << "(" << rhs.width() << ", " << rhs.height() << ")";
+ QTest::addRow("%s", str.toLatin1().constData()) << lhs << rhs << res << mixedRes;
+ };
+
+ row(QSizeF(0.0, 0.0), QSizeF(0.0, 0.0), true, true);
+ row(QSizeF(1.0, 2.0), QSizeF(1.0, 2.0), true, true);
+ row(QSizeF(1.0, -1.0), QSizeF(-1.0, 1.0), false, false);
+ row(QSizeF(0.1, 1.1), QSizeF(0.1, 1.1), true, false);
+ row(QSizeF(qreal_min, 0.0), QSizeF(0.0, -qreal_min), true, true);
+}
+
+void tst_QSizeF::compare()
+{
+ QFETCH(QSizeF, lhs);
+ QFETCH(QSizeF, rhs);
+ QFETCH(bool, result);
+ QFETCH(bool, mixedResult);
+
+ QT_TEST_EQUALITY_OPS(lhs, rhs, result);
+
+ const QSize rhsFixed = rhs.toSize();
+ QT_TEST_EQUALITY_OPS(lhs, rhsFixed, mixedResult);
+}
+
+void tst_QSizeF::fuzzyCompare_data()
+{
+ compare_data();
+}
+
+void tst_QSizeF::fuzzyCompare()
+{
+ QFETCH(QSizeF, lhs);
+ QFETCH(QSizeF, rhs);
+ QFETCH(bool, result);
+
+ QCOMPARE_EQ(qFuzzyCompare(lhs, rhs), result);
+}
+
void tst_QSizeF::isNull_data()
{
QTest::addColumn<qreal>("width");
@@ -66,6 +134,7 @@ void tst_QSizeF::isNull_data()
QTest::newRow("0, -0.1") << qreal(0) << qreal(-0.1) << false;
QTest::newRow("0.1, 0") << qreal(0.1) << qreal(0) << false;
QTest::newRow("0, 0.1") << qreal(0) << qreal(0.1) << false;
+ QTest::newRow("qreal_min, -qreal_min") << qreal_min << -qreal_min << false;
}
void tst_QSizeF::isNull()
@@ -80,6 +149,33 @@ void tst_QSizeF::isNull()
QCOMPARE(size.isNull(), isNull);
}
+void tst_QSizeF::fuzzyIsNull_data()
+{
+ QTest::addColumn<qreal>("width");
+ QTest::addColumn<qreal>("height");
+ QTest::addColumn<bool>("fuzzyNull");
+
+ QTest::newRow("0, 0") << qreal(0.0) << qreal(0.0) << true;
+ QTest::newRow("-0, -0") << qreal(-0.0) << qreal(-0.0) << true;
+ QTest::newRow("0, -0") << qreal(0) << qreal(-0.0) << true;
+ QTest::newRow("-0, 0") << qreal(-0.0) << qreal(0) << true;
+ QTest::newRow("-0.1, 0") << qreal(-0.1) << qreal(0) << false;
+ QTest::newRow("0, -0.1") << qreal(0) << qreal(-0.1) << false;
+ QTest::newRow("0.1, 0") << qreal(0.1) << qreal(0) << false;
+ QTest::newRow("0, 0.1") << qreal(0) << qreal(0.1) << false;
+ QTest::newRow("qreal_min, -qreal_min") << qreal_min << -qreal_min << true;
+}
+
+void tst_QSizeF::fuzzyIsNull()
+{
+ QFETCH(qreal, width);
+ QFETCH(qreal, height);
+ QFETCH(bool, fuzzyNull);
+
+ QSizeF size(width, height);
+ QCOMPARE(qFuzzyIsNull(size), fuzzyNull);
+}
+
void tst_QSizeF::scale() {
QSizeF t1(10.4, 12.8);
t1.scale(60.6, 60.6, Qt::IgnoreAspectRatio);
diff --git a/tests/auto/corelib/tools/qspan/CMakeLists.txt b/tests/auto/corelib/tools/qspan/CMakeLists.txt
new file mode 100644
index 0000000000..595d19dc43
--- /dev/null
+++ b/tests/auto/corelib/tools/qspan/CMakeLists.txt
@@ -0,0 +1,13 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qspan LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qspan
+ SOURCES
+ tst_qspan.cpp
+)
diff --git a/tests/auto/corelib/tools/qspan/tst_qspan.cpp b/tests/auto/corelib/tools/qspan/tst_qspan.cpp
new file mode 100644
index 0000000000..c7456ac7f2
--- /dev/null
+++ b/tests/auto/corelib/tools/qspan/tst_qspan.cpp
@@ -0,0 +1,481 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QSpan>
+
+#include <QList>
+#include <QTest>
+
+#include <algorithm>
+#include <array>
+#ifdef __cpp_lib_span
+#include <span>
+#endif
+#include <vector>
+
+namespace {
+
+struct NotNothrowMovable {
+ NotNothrowMovable(NotNothrowMovable &&) noexcept(false) {};
+ NotNothrowMovable &operator=(NotNothrowMovable &&) noexcept(false) { return *this; };
+};
+static_assert(!std::is_nothrow_move_constructible_v<NotNothrowMovable>);
+static_assert(!std::is_nothrow_move_assignable_v<NotNothrowMovable>);
+
+} // unnamed namespace
+
+//
+// QSpan is nothrow movable even if the payload type is not:
+//
+static_assert(std::is_nothrow_move_constructible_v<QSpan<NotNothrowMovable>>);
+static_assert(std::is_nothrow_move_constructible_v<QSpan<NotNothrowMovable, 42>>);
+static_assert(std::is_nothrow_move_constructible_v<QSpan<NotNothrowMovable, 0>>);
+
+static_assert(std::is_nothrow_move_assignable_v<QSpan<NotNothrowMovable>>);
+static_assert(std::is_nothrow_move_assignable_v<QSpan<NotNothrowMovable, 42>>);
+static_assert(std::is_nothrow_move_assignable_v<QSpan<NotNothrowMovable, 0>>);
+
+//
+// All QSpans are trivially destructible and trivially copyable:
+//
+static_assert(std::is_trivially_copyable_v<QSpan<NotNothrowMovable>>);
+static_assert(std::is_trivially_copyable_v<QSpan<NotNothrowMovable, 42>>);
+static_assert(std::is_trivially_copyable_v<QSpan<NotNothrowMovable, 0>>);
+
+static_assert(std::is_trivially_destructible_v<QSpan<NotNothrowMovable>>);
+static_assert(std::is_trivially_destructible_v<QSpan<NotNothrowMovable, 42>>);
+static_assert(std::is_trivially_destructible_v<QSpan<NotNothrowMovable, 0>>);
+
+//
+// Fixed-size QSpans implicitly convert to variable-sized ones:
+//
+static_assert(std::is_convertible_v<QSpan<int, 42>, QSpan<int>>);
+static_assert(std::is_convertible_v<QSpan<int, 0>, QSpan<int>>);
+
+#ifdef __cpp_lib_span
+static_assert(std::is_convertible_v<std::span<int, 42>, QSpan<int>>);
+static_assert(std::is_convertible_v<std::span<int, 0>, QSpan<int>>);
+
+#ifdef __cpp_lib_concepts
+// requires enable_borrowed_range
+static_assert(std::is_convertible_v<QSpan<int, 42>, std::span<int>>);
+static_assert(std::is_convertible_v<QSpan<int, 0>, std::span<int>>);
+#endif // __cpp_lib_concepts
+#endif // __cpp_lib_span
+
+//
+// Mutable spans implicitly convert to read-only ones, but not vice versa:
+//
+static_assert(std::is_convertible_v<QSpan<int>, QSpan<const int>>);
+static_assert(std::is_convertible_v<QSpan<int, 42>, QSpan<const int, 42>>);
+static_assert(std::is_convertible_v<QSpan<int, 0>, QSpan<const int, 0>>);
+
+static_assert(!std::is_convertible_v<QSpan<const int>, QSpan<int>>);
+static_assert(!std::is_convertible_v<QSpan<const int, 42>, QSpan<int, 42>>);
+static_assert(!std::is_convertible_v<QSpan<const int, 0>, QSpan<int, 0>>);
+
+#ifdef __cpp_lib_span
+static_assert(std::is_convertible_v<std::span<int>, QSpan<const int>>);
+static_assert(std::is_convertible_v<std::span<int, 42>, QSpan<const int, 42>>);
+static_assert(std::is_convertible_v<std::span<int, 0>, QSpan<const int, 0>>);
+
+static_assert(!std::is_convertible_v<std::span<const int>, QSpan<int>>);
+static_assert(!std::is_convertible_v<std::span<const int, 42>, QSpan<int, 42>>);
+static_assert(!std::is_convertible_v<std::span<const int, 0>, QSpan<int, 0>>);
+
+static_assert(std::is_convertible_v<QSpan<int>, std::span<const int>>);
+// fixed-size std::span constructors are explicit:
+static_assert(!std::is_convertible_v<QSpan<int, 42>, std::span<const int, 42>>);
+static_assert(!std::is_convertible_v<QSpan<int, 0>, std::span<const int, 0>>);
+// observe: is_convertible<From,To>, but is_constuctible<To,From>!
+static_assert(std::is_constructible_v<std::span<const int, 42>, QSpan<int, 42>>);
+static_assert(std::is_constructible_v<std::span<const int, 0>, QSpan<int, 0>>);
+
+static_assert(!std::is_convertible_v<QSpan<const int>, std::span<int>>);
+static_assert(!std::is_convertible_v<QSpan<const int, 42>, std::span<int, 42>>);
+static_assert(!std::is_convertible_v<QSpan<const int, 0>, std::span<int, 0>>);
+#endif // __cpp_lib_span
+
+// Spans don't convert from nonsense:
+static_assert(!std::is_constructible_v<QSpan<const int>, int&&>);
+
+// Span is constructible from initializer_list
+static_assert( std::is_convertible_v<std::initializer_list<int>, QSpan<const int>>);
+static_assert(!std::is_convertible_v<std::initializer_list<int>, QSpan< int>>);
+static_assert(!std::is_constructible_v<QSpan<int>, std::initializer_list<int>>);
+
+static_assert( std::is_convertible_v<std::initializer_list<int>, QSpan<const int, 4>>); // non-standard, but QSpan considers initializer_list a range
+static_assert( std::is_constructible_v<QSpan<const int, 4>, std::initializer_list<int>>);
+static_assert(!std::is_constructible_v<QSpan< int, 4>, std::initializer_list<int>>);
+
+class tst_QSpan : public QObject
+{
+ Q_OBJECT
+public:
+ using QObject::QObject;
+
+private Q_SLOTS:
+ void onlyZeroExtentSpansHaveDefaultCtors() const;
+ void zeroExtentSpansMaintainADataPointer() const;
+ void fromArray() const;
+ void fromStdArray() const;
+ void fromStdInitializerList() const;
+ void fromZeroSizeStdArray() const;
+ void fromStdVector() const;
+ void fromQList() const;
+ void fromInitList() const;
+
+private:
+ template <typename T, std::size_t N>
+ void check_nonempty_span(QSpan<T, N>, qsizetype expectedSize) const;
+ template <typename T, std::size_t N>
+ void check_empty_span_incl_subspans(QSpan<T, N>) const;
+ template <typename T, std::size_t N>
+ void check_empty_span(QSpan<T, N>) const;
+ template <typename T, std::size_t N>
+ void check_null_span(QSpan<T, N>) const;
+
+ template <std::size_t ExpectedExtent, typename C>
+ void from_container_impl(C &&c) const;
+ template <typename C>
+ void from_variable_size_container_impl(C &&c) const;
+};
+
+template <typename T>
+const void *as_const_void(T *p) noexcept { return static_cast<const void *>(p); }
+
+#define RETURN_IF_FAILED() \
+ do { if (QTest::currentTestFailed()) return; } while (false)
+
+void tst_QSpan::onlyZeroExtentSpansHaveDefaultCtors() const
+{
+ static_assert(std::is_nothrow_default_constructible_v<QSpan<int, 0>>);
+ static_assert(std::is_nothrow_default_constructible_v<QSpan<const int, 0>>);
+ static_assert(std::is_nothrow_default_constructible_v<QSpan<int>>);
+ static_assert(std::is_nothrow_default_constructible_v<QSpan<const int>>);
+
+ QSpan<int, 0> si;
+ check_null_span(si);
+ RETURN_IF_FAILED();
+
+ QSpan<const int, 0> sci;
+ check_null_span(sci);
+ RETURN_IF_FAILED();
+
+ QSpan<int> sdi;
+ check_null_span(sdi);
+ RETURN_IF_FAILED();
+
+ QSpan<const int> sdci;
+ check_null_span(sdci);
+ RETURN_IF_FAILED();
+
+ static_assert(!std::is_default_constructible_v<QSpan<int, 1>>);
+ static_assert(!std::is_default_constructible_v<QSpan<const int, 42>>);
+}
+
+void tst_QSpan::zeroExtentSpansMaintainADataPointer() const
+{
+ int i = 0;
+ QSpan<int, 0> si{&i, 0};
+ QCOMPARE(si.data(), &i);
+ check_empty_span_incl_subspans(si);
+ RETURN_IF_FAILED();
+
+ QSpan<const int, 0> sci{&i, 0};
+ QCOMPARE(sci.data(), &i);
+ check_empty_span_incl_subspans(sci);
+ RETURN_IF_FAILED();
+
+ QSpan<int, 0> sdi{&i, 0};
+ QCOMPARE(sdi.data(), &i);
+ check_empty_span_incl_subspans(sdi);
+ RETURN_IF_FAILED();
+
+ QSpan<const int, 0> sdci{&i, 0};
+ QCOMPARE(sdci.data(), &i);
+ check_empty_span_incl_subspans(sdci);
+ RETURN_IF_FAILED();
+}
+
+template <typename T, std::size_t N>
+void tst_QSpan::check_nonempty_span(QSpan<T, N> s, qsizetype expectedSize) const
+{
+ static_assert(N > 0);
+ QCOMPARE_GT(expectedSize, 0); // otherwise, use check_empty_span!
+
+ QVERIFY(!s.empty());
+ QVERIFY(!s.isEmpty());
+
+ QCOMPARE_EQ(s.size(), expectedSize);
+ QCOMPARE_NE(s.data(), nullptr);
+
+ QCOMPARE_NE(s.begin(), s.end());
+ QCOMPARE_NE(s.rbegin(), s.rend());
+ QCOMPARE_NE(s.cbegin(), s.cend());
+ QCOMPARE_NE(s.crbegin(), s.crend());
+
+ QCOMPARE_EQ(s.end() - s.begin(), s.size());
+ QCOMPARE_EQ(s.cend() - s.cbegin(), s.size());
+ QCOMPARE_EQ(s.rend() - s.rbegin(), s.size());
+ QCOMPARE_EQ(s.crend() - s.crbegin(), s.size());
+
+ QCOMPARE_EQ(std::addressof(s.front()), std::addressof(*s.begin()));
+ QCOMPARE_EQ(std::addressof(s.front()), std::addressof(*s.cbegin()));
+ QCOMPARE_EQ(std::addressof(s.front()), std::addressof(s[0]));
+ QCOMPARE_EQ(std::addressof(s.back()), std::addressof(*s.rbegin()));
+ QCOMPARE_EQ(std::addressof(s.back()), std::addressof(*s.crbegin()));
+ QCOMPARE_EQ(std::addressof(s.back()), std::addressof(s[s.size() - 1]));
+
+ // ### more?
+
+ if (expectedSize == 1) {
+ // don't run into Mandates: Offset >= Extent
+ if constexpr (N > 0) { // incl. N == std::dynamic_extent
+ check_empty_span_incl_subspans(s.template subspan<1>());
+ RETURN_IF_FAILED();
+ }
+ check_empty_span_incl_subspans(s.subspan(1));
+ RETURN_IF_FAILED();
+ } else {
+ // don't run into Mandates: Offset >= Extent
+ if constexpr (N > 1) { // incl. N == std::dynamic_extent
+ check_nonempty_span(s.template subspan<1>(), expectedSize - 1);
+ RETURN_IF_FAILED();
+ }
+ check_nonempty_span(s.subspan(1), expectedSize - 1);
+ RETURN_IF_FAILED();
+ }
+}
+
+template <typename T, std::size_t N>
+void tst_QSpan::check_empty_span(QSpan<T, N> s) const
+{
+ QVERIFY(s.empty());
+ QVERIFY(s.isEmpty());
+
+ QCOMPARE_EQ(s.size(), 0);
+
+ QCOMPARE_EQ(s.begin(), s.end());
+ QCOMPARE_EQ(s.cbegin(), s.cend());
+ QCOMPARE_EQ(s.rbegin(), s.rend());
+ QCOMPARE_EQ(s.crbegin(), s.crend());
+}
+
+template <typename T, std::size_t N>
+void tst_QSpan::check_empty_span_incl_subspans(QSpan<T, N> s) const
+{
+ check_empty_span(s);
+ RETURN_IF_FAILED();
+
+ {
+ const auto fi = s.template first<0>();
+ check_empty_span(fi);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(fi.data(), s.data());
+ }
+ {
+ const auto la = s.template last<0>();
+ check_empty_span(la);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(la.data(), s.data());
+ }
+ {
+ const auto ss = s.template subspan<0>();
+ check_empty_span(ss);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(ss.data(), s.data());
+ }
+ {
+ const auto ss = s.template subspan<0, 0>();
+ check_empty_span(ss);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(ss.data(), s.data());
+ }
+
+ {
+ const auto fi = s.first(0);
+ check_empty_span(fi);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(fi.data(), s.data());
+ }
+ {
+ const auto la = s.last(0);
+ check_empty_span(la);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(la.data(), s.data());
+ }
+ {
+ const auto ss = s.subspan(0);
+ check_empty_span(ss);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(ss.data(), s.data());
+ }
+ {
+ const auto ss = s.subspan(0, 0);
+ check_empty_span(ss);
+ RETURN_IF_FAILED();
+ QCOMPARE_EQ(ss.data(), s.data());
+ }
+}
+
+
+template<typename T, std::size_t N>
+void tst_QSpan::check_null_span(QSpan<T, N> s) const
+{
+ QCOMPARE_EQ(s.data(), nullptr);
+ QCOMPARE_EQ(s.begin(), nullptr);
+ QCOMPARE_EQ(s.cbegin(), nullptr);
+ QCOMPARE_EQ(s.end(), nullptr);
+ check_empty_span_incl_subspans(s);
+}
+
+template <std::size_t ExpectedExtent, typename C>
+void tst_QSpan::from_container_impl(C &&c) const
+{
+ const auto c_size = qsizetype(QSpanPrivate::adl_size(c));
+ const auto c_data = QSpanPrivate::adl_data(c);
+
+ using V = std::remove_reference_t<QSpanPrivate::range_reference_t<C>>;
+ constexpr auto ExpectedBytesExtent
+ = ExpectedExtent == q20::dynamic_extent ? q20::dynamic_extent : ExpectedExtent * sizeof(V);
+ {
+ QSpan si = c; // CTAD
+ static_assert(std::is_same_v<decltype(si), QSpan<V, ExpectedExtent>>);
+
+ QCOMPARE_EQ(si.size(), c_size);
+ QCOMPARE_EQ(si.data(), c_data);
+
+ check_nonempty_span(si, c_size);
+ RETURN_IF_FAILED();
+
+ auto bi = as_bytes(si);
+ static_assert(std::is_same_v<decltype(bi), QSpan<const std::byte, ExpectedBytesExtent>>);
+ QCOMPARE_EQ(bi.size(), si.size_bytes());
+ QCOMPARE_EQ(as_const_void(bi.data()),
+ as_const_void(si.data()));
+
+ if constexpr (!std::is_const_v<V>) { // e.g. std::initializer_list<int>
+ auto wbi = as_writable_bytes(si);
+ static_assert(std::is_same_v<decltype(wbi), QSpan<std::byte, ExpectedBytesExtent>>);
+ QCOMPARE_EQ(wbi.size(), si.size_bytes());
+ QCOMPARE_EQ(as_const_void(wbi.data()),
+ as_const_void(si.data()));
+ }
+
+ QSpan<const int> sci = c;
+
+ QCOMPARE_EQ(sci.size(), c_size);
+ QCOMPARE_EQ(sci.data(), c_data);
+
+ check_nonempty_span(sci, c_size);
+ RETURN_IF_FAILED();
+
+ auto bci = as_bytes(sci);
+ static_assert(std::is_same_v<decltype(bci), QSpan<const std::byte>>);
+ QCOMPARE_EQ(bci.size(), sci.size_bytes());
+ QCOMPARE_EQ(as_const_void(bci.data()),
+ as_const_void(sci.data()));
+ }
+ {
+ QSpan sci = std::as_const(c); // CTAD
+ static_assert(std::is_same_v<decltype(sci), QSpan<const int, ExpectedExtent>>);
+
+ QCOMPARE_EQ(sci.size(), c_size);
+ QCOMPARE_EQ(sci.data(), c_data);
+
+ check_nonempty_span(sci, c_size);
+ RETURN_IF_FAILED();
+
+ auto bci = as_bytes(sci);
+ static_assert(std::is_same_v<decltype(bci), QSpan<const std::byte, ExpectedBytesExtent>>);
+ QCOMPARE_EQ(bci.size(), sci.size_bytes());
+ QCOMPARE_EQ(as_const_void(bci.data()),
+ as_const_void(sci.data()));
+ }
+}
+
+template <typename C>
+void tst_QSpan::from_variable_size_container_impl(C &&c) const
+{
+ constexpr auto E = q20::dynamic_extent;
+ from_container_impl<E>(std::forward<C>(c));
+}
+
+void tst_QSpan::fromArray() const
+{
+ int ai[] = {42, 84, 168, 336};
+ from_container_impl<4>(ai);
+}
+
+void tst_QSpan::fromStdArray() const
+{
+ std::array<int, 4> ai = {42, 84, 168, 336};
+ from_container_impl<4>(ai);
+}
+
+void tst_QSpan::fromStdInitializerList() const
+{
+ std::initializer_list<int> il = {42, 84, 168, 336};
+
+ QSpan sci = il; // CTAD
+ // special case: always deduced as <const int>:
+ static_assert(std::is_same_v<decltype(sci), QSpan<const int>>);
+
+ QCOMPARE_EQ(sci.size(), qsizetype(il.size()));
+ QCOMPARE_EQ(sci.data(), il.begin());
+
+ check_nonempty_span(sci, 4);
+ RETURN_IF_FAILED();
+}
+
+void tst_QSpan::fromZeroSizeStdArray() const
+{
+ std::array<int, 0> ai = {};
+ QSpan si = ai; // CTAD
+ static_assert(std::is_same_v<decltype(si), QSpan<int, 0>>);
+ QCOMPARE_EQ(si.data(), ai.data());
+
+ const std::array<int, 0> cai = {};
+ QSpan csi = cai; // CTAD
+ static_assert(std::is_same_v<decltype(csi), QSpan<const int, 0>>);
+ QCOMPARE_EQ(csi.data(), cai.data());
+
+ std::array<const int, 0> aci = {};
+ QSpan sci = aci; // CTAD
+ static_assert(std::is_same_v<decltype(sci), QSpan<const int, 0>>);
+ QCOMPARE_EQ(sci.data(), aci.data());
+
+ std::array<const int, 0> caci = {};
+ QSpan csci = caci; // CTAD
+ static_assert(std::is_same_v<decltype(csci), QSpan<const int, 0>>);
+ QCOMPARE_EQ(csci.data(), caci.data());
+}
+
+void tst_QSpan::fromStdVector() const
+{
+ std::vector<int> vi = {42, 84, 168, 336};
+ from_variable_size_container_impl(vi);
+}
+
+void tst_QSpan::fromQList() const
+{
+ QList<int> li = {42, 84, 168, 336};
+ from_variable_size_container_impl(li);
+}
+
+void tst_QSpan::fromInitList() const
+{
+ from_variable_size_container_impl(std::initializer_list<int>{42, 84, 168, 336});
+
+ auto l1 = [](QSpan<const int>){};
+ l1({1, 2, 3});
+
+ auto l2 = [](QSpan<const int, 3>){};
+ l2({4, 5, 6});
+}
+
+#undef RETURN_IF_FAILED
+
+QTEST_APPLESS_MAIN(tst_QSpan);
+#include "tst_qspan.moc"
diff --git a/tests/auto/corelib/tools/qstl/CMakeLists.txt b/tests/auto/corelib/tools/qstl/CMakeLists.txt
index 3651c3bde9..b2f053e6ce 100644
--- a/tests/auto/corelib/tools/qstl/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qstl/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qstl Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstl LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstl
SOURCES
tst_qstl.cpp
diff --git a/tests/auto/corelib/tools/qstl/tst_qstl.cpp b/tests/auto/corelib/tools/qstl/tst_qstl.cpp
index bd344fe43c..43d40bc128 100644
--- a/tests/auto/corelib/tools/qstl/tst_qstl.cpp
+++ b/tests/auto/corelib/tools/qstl/tst_qstl.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt
index 1d5e644cb7..fb2e5dc922 100644
--- a/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qtaggedpointer/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qtaggedpointer Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtaggedpointer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtaggedpointer
SOURCES
tst_qtaggedpointer.cpp
diff --git a/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp b/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp
index 5cb82329d0..a1e61fc3a1 100644
--- a/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp
+++ b/tests/auto/corelib/tools/qtaggedpointer/tst_qtaggedpointer.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtCore/qtaggedpointer.h>
diff --git a/tests/auto/corelib/tools/qtimeline/CMakeLists.txt b/tests/auto/corelib/tools/qtimeline/CMakeLists.txt
index 525077f7d4..a43e93990a 100644
--- a/tests/auto/corelib/tools/qtimeline/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qtimeline/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qtimeline Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtimeline LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtimeline
SOURCES
tst_qtimeline.cpp
diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
index 7d0e121b30..3593a65c4e 100644
--- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
+++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtTest/private/qpropertytesthelper_p.h>
diff --git a/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt b/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt
new file mode 100644
index 0000000000..527156e3c2
--- /dev/null
+++ b/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtyperevision LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qtyperevision
+ SOURCES
+ tst_qtyperevision.cpp
+ LIBRARIES
+ Qt::TestPrivate
+)
diff --git a/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp b/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp
new file mode 100644
index 0000000000..66c746382a
--- /dev/null
+++ b/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp
@@ -0,0 +1,202 @@
+// 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
+
+#include <QTest>
+#include <QtCore/qtyperevision.h>
+#include <QtTest/private/qcomparisontesthelper_p.h>
+
+using namespace Qt::StringLiterals;
+
+class tst_QTypeRevision : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void qTypeRevision_data();
+ void qTypeRevision();
+ void qTypeRevisionTypes();
+ void qTypeRevisionComparisonCompiles();
+ void qTypeRevisionComparison_data();
+ void qTypeRevisionComparison();
+};
+
+template<typename Integer>
+void compileTestRevisionMajorMinor()
+{
+ const Integer major = 8;
+ const Integer minor = 4;
+
+ const QTypeRevision r2 = QTypeRevision::fromVersion(major, minor);
+ QCOMPARE(r2.majorVersion(), 8);
+ QCOMPARE(r2.minorVersion(), 4);
+
+ const QTypeRevision r3 = QTypeRevision::fromMajorVersion(major);
+ QCOMPARE(r3.majorVersion(), 8);
+ QVERIFY(!r3.hasMinorVersion());
+
+ const QTypeRevision r4 = QTypeRevision::fromMinorVersion(minor);
+ QVERIFY(!r4.hasMajorVersion());
+ QCOMPARE(r4.minorVersion(), 4);
+}
+
+
+template<typename Integer>
+void compileTestRevision()
+{
+ if (std::is_signed<Integer>::value)
+ compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Signed>();
+ else
+ compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Unsigned>();
+
+ const Integer value = 0x0510;
+ const QTypeRevision r = QTypeRevision::fromEncodedVersion(value);
+
+ QCOMPARE(r.majorVersion(), 5);
+ QCOMPARE(r.minorVersion(), 16);
+ QCOMPARE(r.toEncodedVersion<Integer>(), value);
+
+ compileTestRevisionMajorMinor<Integer>();
+}
+
+template<>
+void compileTestRevision<qint16>()
+{
+ compileTestRevisionMajorMinor<quint8>();
+}
+
+template<>
+void compileTestRevision<quint8>()
+{
+ compileTestRevisionMajorMinor<quint8>();
+}
+
+template<>
+void compileTestRevision<qint8>()
+{
+ compileTestRevisionMajorMinor<qint8>();
+}
+
+void tst_QTypeRevision::qTypeRevision_data()
+{
+ QTest::addColumn<QTypeRevision>("revision");
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<int>("major");
+ QTest::addColumn<int>("minor");
+
+ QTest::addRow("Qt revision") << QTypeRevision::fromVersion(QT_VERSION_MAJOR, QT_VERSION_MINOR)
+ << true << QT_VERSION_MAJOR << QT_VERSION_MINOR;
+ QTest::addRow("invalid") << QTypeRevision() << false << 0xff << 0xff;
+ QTest::addRow("major") << QTypeRevision::fromMajorVersion(6) << true << 6 << 0xff;
+ QTest::addRow("minor") << QTypeRevision::fromMinorVersion(15) << true << 0xff << 15;
+ QTest::addRow("zero") << QTypeRevision::fromVersion(0, 0) << true << 0 << 0;
+
+ // We're intentionally not testing negative numbers.
+ // There are asserts against negative numbers in QTypeRevision.
+ // You must not pass them as major or minor versions, or values.
+}
+
+void tst_QTypeRevision::qTypeRevision()
+{
+ const QTypeRevision other = QTypeRevision::fromVersion(127, 128);
+
+ QFETCH(QTypeRevision, revision);
+
+ QFETCH(bool, valid);
+ QFETCH(int, major);
+ QFETCH(int, minor);
+
+ QCOMPARE(revision.isValid(), valid);
+ QCOMPARE(revision.majorVersion(), major);
+ QCOMPARE(revision.minorVersion(), minor);
+
+ QCOMPARE(revision.hasMajorVersion(), QTypeRevision::isValidSegment(major));
+ QCOMPARE(revision.hasMinorVersion(), QTypeRevision::isValidSegment(minor));
+
+ const QTypeRevision copy = QTypeRevision::fromEncodedVersion(revision.toEncodedVersion<int>());
+ QCOMPARE(copy, revision);
+
+ QVERIFY(revision != other);
+ QVERIFY(copy != other);
+}
+
+void tst_QTypeRevision::qTypeRevisionTypes()
+{
+ compileTestRevision<quint64>();
+ compileTestRevision<qint64>();
+
+ QVERIFY(!QTypeRevision::isValidSegment(0xff));
+ QVERIFY(!QTypeRevision::isValidSegment(-1));
+
+ const QTypeRevision maxRevision = QTypeRevision::fromVersion(254, 254);
+ QVERIFY(maxRevision.hasMajorVersion());
+ QVERIFY(maxRevision.hasMinorVersion());
+}
+
+void tst_QTypeRevision::qTypeRevisionComparisonCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QTypeRevision>();
+}
+
+void tst_QTypeRevision::qTypeRevisionComparison_data()
+{
+ QTest::addColumn<QTypeRevision>("lhs");
+ QTest::addColumn<QTypeRevision>("rhs");
+ QTest::addColumn<Qt::strong_ordering>("expectedResult");
+
+ static auto versionStr = [](QTypeRevision r) {
+ QByteArray res = r.hasMajorVersion() ? QByteArray::number(r.majorVersion())
+ : "x"_ba;
+ res.append('.');
+ res.append(r.hasMinorVersion() ? QByteArray::number(r.minorVersion())
+ : "x"_ba);
+ return res;
+ };
+
+ const QTypeRevision revisions[] = {
+ QTypeRevision::zero(),
+ QTypeRevision::fromMajorVersion(0),
+ QTypeRevision::fromVersion(0, 1),
+ QTypeRevision::fromVersion(0, 20),
+ QTypeRevision::fromMinorVersion(0),
+ QTypeRevision(),
+ QTypeRevision::fromMinorVersion(1),
+ QTypeRevision::fromMinorVersion(20),
+ QTypeRevision::fromVersion(1, 0),
+ QTypeRevision::fromMajorVersion(1),
+ QTypeRevision::fromVersion(1, 1),
+ QTypeRevision::fromVersion(1, 20),
+ QTypeRevision::fromVersion(20, 0),
+ QTypeRevision::fromMajorVersion(20),
+ QTypeRevision::fromVersion(20, 1),
+ QTypeRevision::fromVersion(20, 20),
+ };
+
+ const int length = sizeof(revisions) / sizeof(QTypeRevision);
+ for (int i = 0; i < length; ++i) {
+ for (int j = i; j < length; ++j) {
+ const Qt::strong_ordering expectedRes = (i == j)
+ ? Qt::strong_ordering::equal
+ : (i < j) ? Qt::strong_ordering::less
+ : Qt::strong_ordering::greater;
+
+ const auto lhs = revisions[i];
+ const auto rhs = revisions[j];
+ QTest::addRow("%s_vs_%s", versionStr(lhs).constData(), versionStr(rhs).constData())
+ << lhs << rhs << expectedRes;
+ }
+ }
+}
+
+void tst_QTypeRevision::qTypeRevisionComparison()
+{
+ QFETCH(const QTypeRevision, lhs);
+ QFETCH(const QTypeRevision, rhs);
+ QFETCH(const Qt::strong_ordering, expectedResult);
+
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expectedResult);
+}
+
+QTEST_APPLESS_MAIN(tst_QTypeRevision)
+
+#include "tst_qtyperevision.moc"
diff --git a/tests/auto/corelib/tools/quniquehandle/CMakeLists.txt b/tests/auto/corelib/tools/quniquehandle/CMakeLists.txt
new file mode 100644
index 0000000000..fe46826f37
--- /dev/null
+++ b/tests/auto/corelib/tools/quniquehandle/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_quniquehandle LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_quniquehandle
+ SOURCES
+ tst_quniquehandle.cpp
+ LIBRARIES
+ Qt::CorePrivate
+)
diff --git a/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp b/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp
new file mode 100644
index 0000000000..ed46999e73
--- /dev/null
+++ b/tests/auto/corelib/tools/quniquehandle/tst_quniquehandle.cpp
@@ -0,0 +1,308 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <private/quniquehandle_p.h>
+
+#include <QTest>
+
+QT_USE_NAMESPACE;
+
+// clang-format off
+namespace GlobalResource {
+
+std::array<bool, 3> s_resources = { false, false, false };
+
+using handle = size_t;
+constexpr handle s_invalidHandle = static_cast<handle>(-1);
+
+handle open()
+{
+ const auto it = std::find_if(s_resources.begin(), s_resources.end(),
+ [](bool resource) {
+ return !resource;
+ });
+
+ if (it == s_resources.end())
+ return s_invalidHandle;
+
+ *it = true;
+
+ return std::distance(s_resources.begin(), it);
+}
+
+bool open(handle* dest)
+{
+ const handle resource = open();
+
+ if (resource == s_invalidHandle)
+ return false;
+
+ *dest = resource;
+ return true;
+}
+
+bool close(handle h)
+{
+ if (h >= s_resources.size())
+ return false; // Invalid handle
+
+ if (!s_resources[h])
+ return false; // Un-allocated resource
+
+ s_resources[h] = false;
+ return true;
+}
+
+bool isOpen(handle h)
+{
+ return s_resources[h];
+}
+
+void reset()
+{
+ std::fill(s_resources.begin(), s_resources.end(), false);
+}
+
+bool isReset()
+{
+ return std::all_of(s_resources.begin(), s_resources.end(), [](bool res) {
+ return !res;
+ });
+}
+
+} // namespace GlobalResource
+
+struct TestTraits
+{
+ using Type = GlobalResource::handle;
+
+ static bool close(Type handle)
+ {
+ return GlobalResource::close(handle);
+ }
+
+ static Type invalidValue() noexcept
+ {
+ return GlobalResource::s_invalidHandle;
+ }
+};
+
+using Handle = QUniqueHandle<TestTraits>;
+
+class tst_QUniqueHandle : public QObject
+{
+ Q_OBJECT
+
+private slots:
+
+ void init() const
+ {
+ GlobalResource::reset();
+ }
+
+ void cleanup() const
+ {
+ QVERIFY(GlobalResource::isReset());
+ }
+
+ void defaultConstructor_initializesToInvalidHandle() const
+ {
+ const Handle h;
+ QCOMPARE_EQ(h.get(), TestTraits::invalidValue());
+ }
+
+ void constructor_initializesToValid_whenCalledWithValidHandle() const
+ {
+ const auto res = GlobalResource::open();
+
+ const Handle h{ res };
+
+ QCOMPARE_EQ(h.get(), res);
+ }
+
+ void copyConstructor_and_assignmentOperator_areDeleted() const
+ {
+ static_assert(!std::is_copy_constructible_v<Handle> && !std::is_copy_assignable_v<Handle>);
+ }
+
+ void moveConstructor_movesOwnershipAndResetsSource() const
+ {
+ Handle source{ GlobalResource::open() };
+ const Handle dest{ std::move(source) };
+
+ QVERIFY(!source.isValid());
+ QVERIFY(dest.isValid());
+ QVERIFY(GlobalResource::isOpen(dest.get()));
+ }
+
+ void moveAssignment_movesOwnershipAndResetsSource() const
+ {
+ Handle source{ GlobalResource::open() };
+ Handle dest;
+ dest = { std::move(source) };
+
+ QVERIFY(!source.isValid());
+ QVERIFY(dest.isValid());
+ QVERIFY(GlobalResource::isOpen(dest.get()));
+ }
+
+ void isValid_returnsFalse_onlyWhenHandleIsInvalid() const
+ {
+ const Handle invalid;
+ QVERIFY(!invalid.isValid());
+
+ const Handle valid{ GlobalResource::open() };
+ QVERIFY(valid.isValid());
+ }
+
+ void destructor_callsClose_whenHandleIsValid()
+ {
+ {
+ const Handle h0{ GlobalResource::open() };
+ const Handle h1{ GlobalResource::open() };
+ const Handle h2{ GlobalResource::open() };
+ QVERIFY(!GlobalResource::isReset());
+ }
+
+ QVERIFY(GlobalResource::isReset());
+ }
+
+ void operatorBool_returnsFalse_onlyWhenHandleIsInvalid() const
+ {
+ const Handle invalid;
+ QVERIFY(!invalid);
+
+ const Handle valid{ GlobalResource::open() };
+ QVERIFY(valid);
+ }
+
+ void get_returnsValue() const
+ {
+ const Handle invalid;
+ QCOMPARE_EQ(invalid.get(), GlobalResource::s_invalidHandle);
+
+ const auto resource = GlobalResource::open();
+ const Handle valid{ resource };
+ QCOMPARE_EQ(valid.get(), resource);
+ }
+
+ void reset_resetsPreviousValueAndTakesOwnership() const
+ {
+ const auto resource0 = GlobalResource::open();
+ const auto resource1 = GlobalResource::open();
+
+ Handle h1{ resource0 };
+ h1.reset(resource1);
+
+ QVERIFY(!GlobalResource::isOpen(resource0));
+ QVERIFY(GlobalResource::isOpen(resource1));
+ }
+
+ void release_returnsInvalidResource_whenCalledOnInvalidHandle() const
+ {
+ Handle h;
+ QCOMPARE_EQ(h.release(), GlobalResource::s_invalidHandle);
+ }
+
+ void release_releasesOwnershipAndReturnsResource_whenHandleOwnsObject() const
+ {
+ GlobalResource::handle resource{ GlobalResource::open() };
+ GlobalResource::handle released{};
+ {
+ Handle h{ resource };
+ released = h.release();
+ }
+ QVERIFY(GlobalResource::isOpen(resource));
+ QCOMPARE_EQ(resource, released);
+
+ GlobalResource::close(resource);
+ }
+
+ void swap_swapsOwnership() const
+ {
+ const auto resource0 = GlobalResource::open();
+ const auto resource1 = GlobalResource::open();
+
+ Handle h0{ resource0 };
+ Handle h1{ resource1 };
+
+ std::swap(h0, h1);
+
+ QCOMPARE_EQ(h0.get(), resource1);
+ QCOMPARE_EQ(h1.get(), resource0);
+ }
+
+ void comparison_behavesAsInt_whenHandleTypeIsInt_data() const
+ {
+ QTest::addColumn<int>("lhs");
+ QTest::addColumn<int>("rhs");
+
+ QTest::addRow("lhs == rhs") << 1 << 1;
+ QTest::addRow("lhs < rhs") << 0 << 1;
+ QTest::addRow("lhs > rhs") << 1 << 0;
+ }
+
+ void comparison_behavesAsInt_whenHandleTypeIsInt() const
+ {
+ struct IntTraits
+ {
+ using Type = int;
+
+ static bool close(Type)
+ {
+ return true;
+ }
+
+ static Type invalidValue() noexcept
+ {
+ return INT_MAX;
+ }
+ };
+
+ using Handle = QUniqueHandle<IntTraits>;
+
+ QFETCH(int, lhs);
+ QFETCH(int, rhs);
+
+ QCOMPARE_EQ(Handle{ lhs } == Handle{ rhs }, lhs == rhs);
+ QCOMPARE_EQ(Handle{ lhs } != Handle{ rhs }, lhs != rhs);
+ QCOMPARE_EQ(Handle{ lhs } < Handle{ rhs }, lhs < rhs);
+ QCOMPARE_EQ(Handle{ lhs } <= Handle{ rhs }, lhs <= rhs);
+ QCOMPARE_EQ(Handle{ lhs } > Handle{ rhs }, lhs > rhs);
+ QCOMPARE_EQ(Handle{ lhs } >= Handle{ rhs }, lhs >= rhs);
+
+ QCOMPARE_EQ(Handle{ }, Handle{ });
+ }
+
+ void sort_sortsHandles() const
+ {
+ const auto resource0 = GlobalResource::open();
+ const auto resource1 = GlobalResource::open();
+
+ QVERIFY(resource1 > resource0); // Precondition of underlying allocator
+
+ Handle h0{ resource0 };
+ Handle h1{ resource1 };
+
+ std::vector<Handle> handles;
+ handles.push_back(std::move(h1));
+ handles.push_back(std::move(h0));
+
+ std::sort(handles.begin(), handles.end());
+
+ QCOMPARE_LT(handles.front(), handles.back());
+ QCOMPARE_LT(handles.front().get(), handles.back().get());
+ }
+
+ void addressOf_returnsAddressOfHandle() const
+ {
+ Handle h;
+ QVERIFY(GlobalResource::open(&h));
+ QVERIFY(h.isValid());
+ }
+
+};
+
+// clang-format on
+QTEST_MAIN(tst_QUniqueHandle)
+#include "tst_quniquehandle.moc"
diff --git a/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt b/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt
index 1123f92c2c..eccb2634cc 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qvarlengtharray/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qvarlengtharray Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qvarlengtharray LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qvarlengtharray
SOURCES
tst_qvarlengtharray.cpp
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index 1ae18ca171..6a92663bc4 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
#include <QVarLengthArray>
@@ -66,6 +66,7 @@ private slots:
void sizeConstructor_QString() { sizeConstructor<QString>(); }
void sizeConstructor_NonCopyable() { sizeConstructor<NonCopyable>(); }
void append();
+ void preallocatedSize();
#if QT_DEPRECATED_SINCE(6, 3)
void prepend();
#endif
@@ -194,6 +195,15 @@ void tst_QVarLengthArray::append()
v2.append(5);
}
+void tst_QVarLengthArray::preallocatedSize()
+{
+ // The default is 256:
+ static_assert(QVarLengthArray<int>::PreallocatedSize == 256);
+ // Otherwise, whatever was given as template argument:
+ static_assert(QVarLengthArray<int, 42>::PreallocatedSize == 42);
+ static_assert(QVarLengthArray<int, 1'000'000>::PreallocatedSize == 1'000'000);
+}
+
#if QT_DEPRECATED_SINCE(6, 3)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
diff --git a/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt b/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt
index 33849639bc..5b9fa60c64 100644
--- a/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qversionnumber/CMakeLists.txt
@@ -5,9 +5,17 @@
## tst_qversionnumber Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qversionnumber LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qversionnumber
SOURCES
tst_qversionnumber.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
## Scopes:
diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
index cc17188c54..5ccf56c1d1 100644
--- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
+++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
@@ -1,8 +1,9 @@
// 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
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
#include <QtCore/qversionnumber.h>
#include <QtCore/qlibraryinfo.h>
@@ -16,24 +17,15 @@ private:
private slots:
void initTestCase();
+ void compareCompiles();
void constructorDefault();
void constructorVersioned_data();
void constructorVersioned();
void constructorExplicit();
void constructorCopy_data();
void constructorCopy();
- void compareGreater_data();
- void compareGreater();
- void compareGreaterEqual_data();
- void compareGreaterEqual();
- void compareLess_data();
- void compareLess();
- void compareLessEqual_data();
- void compareLessEqual();
- void compareEqual_data();
- void compareEqual();
- void compareNotEqual_data();
- void compareNotEqual();
+ void comparisonOperators_data();
+ void comparisonOperators();
void compare_data();
void compare();
void isPrefixOf_data();
@@ -53,14 +45,14 @@ private slots:
void toString();
void isNull_data();
void isNull();
+ void iterators_data();
+ void iterators();
+ void iteratorsAreDefaultConstructible();
+ void valueInitializedIteratorsCompareEqual();
void serialize_data();
void serialize();
void moveSemantics();
void qtVersion();
- void qTypeRevision_data();
- void qTypeRevision();
- void qTypeRevisionTypes();
- void qTypeRevisionComparison();
};
void tst_QVersionNumber::singleInstanceData()
@@ -121,74 +113,69 @@ void tst_QVersionNumber::comparisonData()
{
QTest::addColumn<QVersionNumber>("lhs");
QTest::addColumn<QVersionNumber>("rhs");
- QTest::addColumn<bool>("equal");
- QTest::addColumn<bool>("notEqual");
- QTest::addColumn<bool>("lessThan");
- QTest::addColumn<bool>("lessThanOrEqual");
- QTest::addColumn<bool>("greaterThan");
- QTest::addColumn<bool>("greaterThanOrEqual");
+ QTest::addColumn<Qt::strong_ordering>("ordering");
QTest::addColumn<int>("compareResult");
QTest::addColumn<bool>("isPrefix");
QTest::addColumn<QVersionNumber>("common");
- // LHS RHS == != < <= > >= compareResult isPrefixOf commonPrefix
- QTest::newRow("null, null") << QVersionNumber() << QVersionNumber() << true << false << false << true << false << true << 0 << true << QVersionNumber();
- QTest::newRow("null, 0") << QVersionNumber() << QVersionNumber(0) << false << true << true << true << false << false << -1 << true << QVersionNumber();
- QTest::newRow("0, null") << QVersionNumber(0) << QVersionNumber() << false << true << false << false << true << true << 1 << false << QVersionNumber();
- QTest::newRow("0, 0") << QVersionNumber(0) << QVersionNumber(0) << true << false << false << true << false << true << 0 << true << QVersionNumber(0);
- QTest::newRow("1.0, 1.0") << QVersionNumber(1, 0) << QVersionNumber(1, 0) << true << false << false << true << false << true << 0 << true << QVersionNumber(1, 0);
- QTest::newRow("1, 1.0") << QVersionNumber(1) << QVersionNumber(1, 0) << false << true << true << true << false << false << -1 << true << QVersionNumber(1);
- QTest::newRow("1.0, 1") << QVersionNumber(1, 0) << QVersionNumber(1) << false << true << false << false << true << true << 1 << false << QVersionNumber(1);
-
- QTest::newRow("0.1.2, 0.1") << QVersionNumber(0, 1, 2) << QVersionNumber(0, 1) << false << true << false << false << true << true << 2 << false << QVersionNumber(0, 1);
- QTest::newRow("0.1, 0.1.2") << QVersionNumber(0, 1) << QVersionNumber(0, 1, 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(0, 1);
- QTest::newRow("0.1.2, 0.1.2") << QVersionNumber(0, 1, 2) << QVersionNumber(0, 1, 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(0, 1, 2);
- QTest::newRow("0.1.2, 1.1.2") << QVersionNumber(0, 1, 2) << QVersionNumber(1, 1, 2) << false << true << true << true << false << false << -1 << false << QVersionNumber();
- QTest::newRow("1.1.2, 0.1.2") << QVersionNumber(1, 1, 2) << QVersionNumber(0, 1, 2) << false << true << false << false << true << true << 1 << false << QVersionNumber();
- QTest::newRow("1, -1") << QVersionNumber(1) << QVersionNumber(-1) << false << true << false << false << true << true << 2 << false << QVersionNumber();
- QTest::newRow("-1, 1") << QVersionNumber(-1) << QVersionNumber(1) << false << true << true << true << false << false << -2 << false << QVersionNumber();
- QTest::newRow("0.1, 0.-1") << QVersionNumber(0, 1) << QVersionNumber(0, -1) << false << true << false << false << true << true << 2 << false << QVersionNumber(0);
- QTest::newRow("0.-1, 0.1") << QVersionNumber(0, -1) << QVersionNumber(0, 1) << false << true << true << true << false << false << -2 << false << QVersionNumber(0);
- QTest::newRow("0.-1, 0") << QVersionNumber(0, -1) << QVersionNumber(0) << false << true << true << true << false << false << -1 << false << QVersionNumber(0);
- QTest::newRow("0, 0.-1") << QVersionNumber(0) << QVersionNumber(0, -1) << false << true << false << false << true << true << 1 << true << QVersionNumber(0);
-
- QTest::newRow("0.127.2, 0.127") << QVersionNumber(0, 127, 2) << QVersionNumber(0, 127) << false << true << false << false << true << true << 2 << false << QVersionNumber(0, 127);
- QTest::newRow("0.127, 0.127.2") << QVersionNumber(0, 127) << QVersionNumber(0, 127, 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(0, 127);
- QTest::newRow("0.127.2, 0.127.2") << QVersionNumber(0, 127, 2) << QVersionNumber(0, 127, 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(0, 127, 2);
- QTest::newRow("0.127.2, 127.127.2") << QVersionNumber(0, 127, 2) << QVersionNumber(127, 127, 2) << false << true << true << true << false << false << -127 << false << QVersionNumber();
- QTest::newRow("127.127.2, 0.127.2") << QVersionNumber(127, 127, 2) << QVersionNumber(0, 127, 2) << false << true << false << false << true << true << 127 << false << QVersionNumber();
- QTest::newRow("127, -128") << QVersionNumber(127) << QVersionNumber(-128) << false << true << false << false << true << true << 255 << false << QVersionNumber();
- QTest::newRow("-128, 127") << QVersionNumber(-128) << QVersionNumber(127) << false << true << true << true << false << false << -255 << false << QVersionNumber();
- QTest::newRow("0.127, 0.-128") << QVersionNumber(0, 127) << QVersionNumber(0, -128) << false << true << false << false << true << true << 255 << false << QVersionNumber(0);
- QTest::newRow("0.-128, 0.127") << QVersionNumber(0, -128) << QVersionNumber(0, 127) << false << true << true << true << false << false << -255 << false << QVersionNumber(0);
- QTest::newRow("0.-128, 0") << QVersionNumber(0, -128) << QVersionNumber(0) << false << true << true << true << false << false << -128 << false << QVersionNumber(0);
- QTest::newRow("0, 0.-128") << QVersionNumber(0) << QVersionNumber(0, -128) << false << true << false << false << true << true << 128 << true << QVersionNumber(0);
-
- QTest::newRow("0.128.2, 0.128") << QVersionNumber(0, 128, 2) << QVersionNumber(0, 128) << false << true << false << false << true << true << 2 << false << QVersionNumber(0, 128);
- QTest::newRow("0.128, 0.128.2") << QVersionNumber(0, 128) << QVersionNumber(0, 128, 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(0, 128);
- QTest::newRow("0.128.2, 0.128.2") << QVersionNumber(0, 128, 2) << QVersionNumber(0, 128, 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(0, 128, 2);
- QTest::newRow("0.128.2, 128.128.2") << QVersionNumber(0, 128, 2) << QVersionNumber(128, 128, 2) << false << true << true << true << false << false << -128 << false << QVersionNumber();
- QTest::newRow("128.128.2, 0.128.2") << QVersionNumber(128, 128, 2) << QVersionNumber(0, 128, 2) << false << true << false << false << true << true << 128 << false << QVersionNumber();
- QTest::newRow("128, -129") << QVersionNumber(128) << QVersionNumber(-129) << false << true << false << false << true << true << 257 << false << QVersionNumber();
- QTest::newRow("-129, 128") << QVersionNumber(-129) << QVersionNumber(128) << false << true << true << true << false << false << -257 << false << QVersionNumber();
- QTest::newRow("0.128, 0.-129") << QVersionNumber(0, 128) << QVersionNumber(0, -129) << false << true << false << false << true << true << 257 << false << QVersionNumber(0);
- QTest::newRow("0.-129, 0.128") << QVersionNumber(0, -129) << QVersionNumber(0, 128) << false << true << true << true << false << false << -257 << false << QVersionNumber(0);
- QTest::newRow("0.-129, 0") << QVersionNumber(0, -129) << QVersionNumber(0) << false << true << true << true << false << false << -129 << false << QVersionNumber(0);
- QTest::newRow("0, 0.-129") << QVersionNumber(0) << QVersionNumber(0, -129) << false << true << false << false << true << true << 129 << true << QVersionNumber(0);
+ // LHS RHS ordering compareResult isPrefixOf commonPrefix
+ QTest::newRow("null, null") << QVersionNumber() << QVersionNumber() << Qt::strong_ordering::equal << 0 << true << QVersionNumber();
+ QTest::newRow("null, 0") << QVersionNumber() << QVersionNumber(0) << Qt::strong_ordering::less << -1 << true << QVersionNumber();
+ QTest::newRow("0, null") << QVersionNumber(0) << QVersionNumber() << Qt::strong_ordering::greater << 1 << false << QVersionNumber();
+ QTest::newRow("0, 0") << QVersionNumber(0) << QVersionNumber(0) << Qt::strong_ordering::equal << 0 << true << QVersionNumber(0);
+ QTest::newRow("1.0, 1.0") << QVersionNumber(1, 0) << QVersionNumber(1, 0) << Qt::strong_ordering::equal << 0 << true << QVersionNumber(1, 0);
+ QTest::newRow("1, 1.0") << QVersionNumber(1) << QVersionNumber(1, 0) << Qt::strong_ordering::less << -1 << true << QVersionNumber(1);
+ QTest::newRow("1.0, 1") << QVersionNumber(1, 0) << QVersionNumber(1) << Qt::strong_ordering::greater << 1 << false << QVersionNumber(1);
+
+ QTest::newRow("0.1.2, 0.1") << QVersionNumber(0, 1, 2) << QVersionNumber(0, 1) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(0, 1);
+ QTest::newRow("0.1, 0.1.2") << QVersionNumber(0, 1) << QVersionNumber(0, 1, 2) << Qt::strong_ordering::less << -2 << true << QVersionNumber(0, 1);
+ QTest::newRow("0.1.2, 0.1.2") << QVersionNumber(0, 1, 2) << QVersionNumber(0, 1, 2) << Qt::strong_ordering::equal << 0 << true << QVersionNumber(0, 1, 2);
+ QTest::newRow("0.1.2, 1.1.2") << QVersionNumber(0, 1, 2) << QVersionNumber(1, 1, 2) << Qt::strong_ordering::less << -1 << false << QVersionNumber();
+ QTest::newRow("1.1.2, 0.1.2") << QVersionNumber(1, 1, 2) << QVersionNumber(0, 1, 2) << Qt::strong_ordering::greater << 1 << false << QVersionNumber();
+ QTest::newRow("1, -1") << QVersionNumber(1) << QVersionNumber(-1) << Qt::strong_ordering::greater << 2 << false << QVersionNumber();
+ QTest::newRow("-1, 1") << QVersionNumber(-1) << QVersionNumber(1) << Qt::strong_ordering::less << -2 << false << QVersionNumber();
+ QTest::newRow("0.1, 0.-1") << QVersionNumber(0, 1) << QVersionNumber(0, -1) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(0);
+ QTest::newRow("0.-1, 0.1") << QVersionNumber(0, -1) << QVersionNumber(0, 1) << Qt::strong_ordering::less << -2 << false << QVersionNumber(0);
+ QTest::newRow("0.-1, 0") << QVersionNumber(0, -1) << QVersionNumber(0) << Qt::strong_ordering::less << -1 << false << QVersionNumber(0);
+ QTest::newRow("0, 0.-1") << QVersionNumber(0) << QVersionNumber(0, -1) << Qt::strong_ordering::greater << 1 << true << QVersionNumber(0);
+
+ QTest::newRow("0.127.2, 0.127") << QVersionNumber(0, 127, 2) << QVersionNumber(0, 127) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(0, 127);
+ QTest::newRow("0.127, 0.127.2") << QVersionNumber(0, 127) << QVersionNumber(0, 127, 2) << Qt::strong_ordering::less << -2 << true << QVersionNumber(0, 127);
+ QTest::newRow("0.127.2, 0.127.2") << QVersionNumber(0, 127, 2) << QVersionNumber(0, 127, 2) << Qt::strong_ordering::equal << 0 << true << QVersionNumber(0, 127, 2);
+ QTest::newRow("0.127.2, 127.127.2") << QVersionNumber(0, 127, 2) << QVersionNumber(127, 127, 2) << Qt::strong_ordering::less << -127 << false << QVersionNumber();
+ QTest::newRow("127.127.2, 0.127.2") << QVersionNumber(127, 127, 2) << QVersionNumber(0, 127, 2) << Qt::strong_ordering::greater << 127 << false << QVersionNumber();
+ QTest::newRow("127, -128") << QVersionNumber(127) << QVersionNumber(-128) << Qt::strong_ordering::greater << 255 << false << QVersionNumber();
+ QTest::newRow("-128, 127") << QVersionNumber(-128) << QVersionNumber(127) << Qt::strong_ordering::less << -255 << false << QVersionNumber();
+ QTest::newRow("0.127, 0.-128") << QVersionNumber(0, 127) << QVersionNumber(0, -128) << Qt::strong_ordering::greater << 255 << false << QVersionNumber(0);
+ QTest::newRow("0.-128, 0.127") << QVersionNumber(0, -128) << QVersionNumber(0, 127) << Qt::strong_ordering::less << -255 << false << QVersionNumber(0);
+ QTest::newRow("0.-128, 0") << QVersionNumber(0, -128) << QVersionNumber(0) << Qt::strong_ordering::less << -128 << false << QVersionNumber(0);
+ QTest::newRow("0, 0.-128") << QVersionNumber(0) << QVersionNumber(0, -128) << Qt::strong_ordering::greater << 128 << true << QVersionNumber(0);
+
+ QTest::newRow("0.128.2, 0.128") << QVersionNumber(0, 128, 2) << QVersionNumber(0, 128) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(0, 128);
+ QTest::newRow("0.128, 0.128.2") << QVersionNumber(0, 128) << QVersionNumber(0, 128, 2) << Qt::strong_ordering::less << -2 << true << QVersionNumber(0, 128);
+ QTest::newRow("0.128.2, 0.128.2") << QVersionNumber(0, 128, 2) << QVersionNumber(0, 128, 2) << Qt::strong_ordering::equal << 0 << true << QVersionNumber(0, 128, 2);
+ QTest::newRow("0.128.2, 128.128.2") << QVersionNumber(0, 128, 2) << QVersionNumber(128, 128, 2) << Qt::strong_ordering::less << -128 << false << QVersionNumber();
+ QTest::newRow("128.128.2, 0.128.2") << QVersionNumber(128, 128, 2) << QVersionNumber(0, 128, 2) << Qt::strong_ordering::greater << 128 << false << QVersionNumber();
+ QTest::newRow("128, -129") << QVersionNumber(128) << QVersionNumber(-129) << Qt::strong_ordering::greater << 257 << false << QVersionNumber();
+ QTest::newRow("-129, 128") << QVersionNumber(-129) << QVersionNumber(128) << Qt::strong_ordering::less << -257 << false << QVersionNumber();
+ QTest::newRow("0.128, 0.-129") << QVersionNumber(0, 128) << QVersionNumber(0, -129) << Qt::strong_ordering::greater << 257 << false << QVersionNumber(0);
+ QTest::newRow("0.-129, 0.128") << QVersionNumber(0, -129) << QVersionNumber(0, 128) << Qt::strong_ordering::less << -257 << false << QVersionNumber(0);
+ QTest::newRow("0.-129, 0") << QVersionNumber(0, -129) << QVersionNumber(0) << Qt::strong_ordering::less << -129 << false << QVersionNumber(0);
+ QTest::newRow("0, 0.-129") << QVersionNumber(0) << QVersionNumber(0, -129) << Qt::strong_ordering::greater << 129 << true << QVersionNumber(0);
const QList<int> common = QList<int>({ 0, 1, 2, 3, 4, 5, 6 });
using namespace UglyOperator;
- QTest::newRow("0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.0.1") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 0 + 1) << false << true << false << false << true << true << 2 << false << QVersionNumber(common + 0 + 1);
- QTest::newRow("0.1.2.3.4.5.6.0.1, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 0 + 1) << QVersionNumber(common + 0 + 1 + 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(common + 0 + 1);
- QTest::newRow("0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 0 + 1 + 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(common + 0 + 1 + 2);
- QTest::newRow("0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.1.1.2") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 1 + 1 + 2) << false << true << true << true << false << false << -1 << false << QVersionNumber(common);
- QTest::newRow("0.1.2.3.4.5.6.1.1.2, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 1 + 1 + 2) << QVersionNumber(common + 0 + 1 + 2) << false << true << false << false << true << true << 1 << false << QVersionNumber(common);
- QTest::newRow("0.1.2.3.4.5.6.1, 0.1.2.3.4.5.6.-1") << QVersionNumber(common + 1) << QVersionNumber(common + -1) << false << true << false << false << true << true << 2 << false << QVersionNumber(common);
- QTest::newRow("0.1.2.3.4.5.6.-1, 0.1.2.3.4.5.6.1") << QVersionNumber(common + -1) << QVersionNumber(common + 1) << false << true << true << true << false << false << -2 << false << QVersionNumber(common);
- QTest::newRow("0.1.2.3.4.5.6.0.1, 0.1.2.3.4.5.6.0.-1") << QVersionNumber(common + 0 + 1) << QVersionNumber(common + 0 + -1) << false << true << false << false << true << true << 2 << false << QVersionNumber(common + 0);
- QTest::newRow("0.1.2.3.4.5.6.0.-1, 0.1.2.3.4.5.6.0.1") << QVersionNumber(common + 0 + -1) << QVersionNumber(common + 0 + 1) << false << true << true << true << false << false << -2 << false << QVersionNumber(common + 0);
- QTest::newRow("0.1.2.3.4.5.6.0.-1, 0.1.2.3.4.5.6.0") << QVersionNumber(common + 0 + -1) << QVersionNumber(common + 0) << false << true << true << true << false << false << -1 << false << QVersionNumber(common + 0);
- QTest::newRow("0.1.2.3.4.5.6.0, 0.1.2.3.4.5.6.0.-1") << QVersionNumber(common + 0) << QVersionNumber(common + 0 + -1) << false << true << false << false << true << true << 1 << true << QVersionNumber(common + 0);
+ QTest::newRow("0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.0.1") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 0 + 1) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(common + 0 + 1);
+ QTest::newRow("0.1.2.3.4.5.6.0.1, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 0 + 1) << QVersionNumber(common + 0 + 1 + 2) << Qt::strong_ordering::less << -2 << true << QVersionNumber(common + 0 + 1);
+ QTest::newRow("0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 0 + 1 + 2) << Qt::strong_ordering::equal << 0 << true << QVersionNumber(common + 0 + 1 + 2);
+ QTest::newRow("0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.1.1.2") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 1 + 1 + 2) << Qt::strong_ordering::less << -1 << false << QVersionNumber(common);
+ QTest::newRow("0.1.2.3.4.5.6.1.1.2, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 1 + 1 + 2) << QVersionNumber(common + 0 + 1 + 2) << Qt::strong_ordering::greater << 1 << false << QVersionNumber(common);
+ QTest::newRow("0.1.2.3.4.5.6.1, 0.1.2.3.4.5.6.-1") << QVersionNumber(common + 1) << QVersionNumber(common + -1) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(common);
+ QTest::newRow("0.1.2.3.4.5.6.-1, 0.1.2.3.4.5.6.1") << QVersionNumber(common + -1) << QVersionNumber(common + 1) << Qt::strong_ordering::less << -2 << false << QVersionNumber(common);
+ QTest::newRow("0.1.2.3.4.5.6.0.1, 0.1.2.3.4.5.6.0.-1") << QVersionNumber(common + 0 + 1) << QVersionNumber(common + 0 + -1) << Qt::strong_ordering::greater << 2 << false << QVersionNumber(common + 0);
+ QTest::newRow("0.1.2.3.4.5.6.0.-1, 0.1.2.3.4.5.6.0.1") << QVersionNumber(common + 0 + -1) << QVersionNumber(common + 0 + 1) << Qt::strong_ordering::less << -2 << false << QVersionNumber(common + 0);
+ QTest::newRow("0.1.2.3.4.5.6.0.-1, 0.1.2.3.4.5.6.0") << QVersionNumber(common + 0 + -1) << QVersionNumber(common + 0) << Qt::strong_ordering::less << -1 << false << QVersionNumber(common + 0);
+ QTest::newRow("0.1.2.3.4.5.6.0, 0.1.2.3.4.5.6.0.-1") << QVersionNumber(common + 0) << QVersionNumber(common + 0 + -1) << Qt::strong_ordering::greater << 1 << true << QVersionNumber(common + 0);
}
void tst_QVersionNumber::initTestCase()
@@ -196,6 +183,11 @@ void tst_QVersionNumber::initTestCase()
qRegisterMetaType<QList<int>>();
}
+void tst_QVersionNumber::compareCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QVersionNumber>();
+}
+
void tst_QVersionNumber::constructorDefault()
{
QVersionNumber version;
@@ -244,6 +236,11 @@ void tst_QVersionNumber::constructorExplicit()
QVersionNumber v8 = {4, 5, 6};
QCOMPARE(v7.segments(), v8.segments());
+
+ QVersionNumber v9(4, 5, 6);
+ QVersionNumber vA({4, 5, 6});
+
+ QCOMPARE(v9.segments(), vA.segments());
}
void tst_QVersionNumber::constructorCopy_data()
@@ -265,88 +262,18 @@ void tst_QVersionNumber::constructorCopy()
QCOMPARE(version.segments(), expectedVersion.segments());
}
-void tst_QVersionNumber::compareGreater_data()
-{
- comparisonData();
-}
-
-void tst_QVersionNumber::compareGreater()
-{
- QFETCH(QVersionNumber, lhs);
- QFETCH(QVersionNumber, rhs);
- QFETCH(bool, greaterThan);
-
- QCOMPARE(lhs > rhs, greaterThan);
-}
-
-void tst_QVersionNumber::compareGreaterEqual_data()
+void tst_QVersionNumber::comparisonOperators_data()
{
comparisonData();
}
-void tst_QVersionNumber::compareGreaterEqual()
+void tst_QVersionNumber::comparisonOperators()
{
QFETCH(QVersionNumber, lhs);
QFETCH(QVersionNumber, rhs);
- QFETCH(bool, greaterThanOrEqual);
+ QFETCH(Qt::strong_ordering, ordering);
- QCOMPARE(lhs >= rhs, greaterThanOrEqual);
-}
-
-void tst_QVersionNumber::compareLess_data()
-{
- comparisonData();
-}
-
-void tst_QVersionNumber::compareLess()
-{
- QFETCH(QVersionNumber, lhs);
- QFETCH(QVersionNumber, rhs);
- QFETCH(bool, lessThan);
-
- QCOMPARE(lhs < rhs, lessThan);
-}
-
-void tst_QVersionNumber::compareLessEqual_data()
-{
- comparisonData();
-}
-
-void tst_QVersionNumber::compareLessEqual()
-{
- QFETCH(QVersionNumber, lhs);
- QFETCH(QVersionNumber, rhs);
- QFETCH(bool, lessThanOrEqual);
-
- QCOMPARE(lhs <= rhs, lessThanOrEqual);
-}
-
-void tst_QVersionNumber::compareEqual_data()
-{
- comparisonData();
-}
-
-void tst_QVersionNumber::compareEqual()
-{
- QFETCH(QVersionNumber, lhs);
- QFETCH(QVersionNumber, rhs);
- QFETCH(bool, equal);
-
- QCOMPARE(lhs == rhs, equal);
-}
-
-void tst_QVersionNumber::compareNotEqual_data()
-{
- comparisonData();
-}
-
-void tst_QVersionNumber::compareNotEqual()
-{
- QFETCH(QVersionNumber, lhs);
- QFETCH(QVersionNumber, rhs);
- QFETCH(bool, notEqual);
-
- QCOMPARE(lhs != rhs, notEqual);
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, ordering);
}
void tst_QVersionNumber::compare_data()
@@ -389,7 +316,7 @@ void tst_QVersionNumber::commonPrefix()
QFETCH(QVersionNumber, common);
QVersionNumber calculatedPrefix = QVersionNumber::commonPrefix(lhs, rhs);
- QCOMPARE(calculatedPrefix, common);
+ QT_TEST_EQUALITY_OPS(calculatedPrefix, common, true);
QCOMPARE(calculatedPrefix.segments(), common.segments());
}
@@ -525,18 +452,18 @@ void tst_QVersionNumber::fromString_extra()
// when passing explicit nullptr:
{
auto v = QVersionNumber::fromString("1.2.3-rc1", nullptr);
- QCOMPARE(v, QVersionNumber({1, 2, 3}));
+ QT_TEST_EQUALITY_OPS(v, QVersionNumber({1, 2, 3}), true);
}
{
auto v = QVersionNumber::fromString("1.2.3-rc1", 0);
- QCOMPARE(v, QVersionNumber({1, 2, 3}));
+ QT_TEST_EQUALITY_OPS(v, QVersionNumber({1, 2, 3}), true);
}
// 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));
+ QT_TEST_EQUALITY_OPS(v, QVersionNumber(1, 0), true);
QCOMPARE(i, 3);
}
}
@@ -574,6 +501,45 @@ void tst_QVersionNumber::isNull()
QCOMPARE(version.isNull(), isNull);
}
+void tst_QVersionNumber::iterators_data()
+{
+ singleInstanceData();
+}
+
+void tst_QVersionNumber::iterators()
+{
+ QFETCH(const QList<int>, segments);
+ QFETCH(QVersionNumber, expectedVersion);
+
+ QVERIFY(std::equal(expectedVersion.begin(), expectedVersion.end(),
+ segments.begin(), segments.end()));
+ QVERIFY(std::equal(std::as_const(expectedVersion).begin(), std::as_const(expectedVersion).end(),
+ segments.begin(), segments.end()));
+ QVERIFY(std::equal(expectedVersion.cbegin(), expectedVersion.cend(),
+ segments.cbegin(), segments.cend()));
+ QVERIFY(std::equal(expectedVersion.rbegin(), expectedVersion.rend(),
+ segments.rbegin(), segments.rend()));
+ QVERIFY(std::equal(std::as_const(expectedVersion).rbegin(), std::as_const(expectedVersion).rend(),
+ segments.rbegin(), segments.rend()));
+ QVERIFY(std::equal(expectedVersion.crbegin(), expectedVersion.crend(),
+ segments.crbegin(), segments.crend()));
+}
+
+void tst_QVersionNumber::iteratorsAreDefaultConstructible()
+{
+ static_assert(std::is_default_constructible_v<QVersionNumber::const_iterator>);
+ [[maybe_unused]] QVersionNumber::const_iterator ci;
+ [[maybe_unused]] QVersionNumber::const_reverse_iterator cri;
+}
+
+void tst_QVersionNumber::valueInitializedIteratorsCompareEqual()
+{
+ QVersionNumber::const_iterator it = {}, jt = {};
+ QCOMPARE_EQ(it, jt);
+ QVersionNumber::const_reverse_iterator rit = {}, rjt = {};
+ QCOMPARE_EQ(rit, rjt);
+}
+
void tst_QVersionNumber::serialize_data()
{
singleInstanceData();
@@ -608,14 +574,14 @@ void tst_QVersionNumber::moveSemantics()
{
QVersionNumber v1(1, 2, 3);
QVersionNumber v2 = std::move(v1);
- QCOMPARE(v2, QVersionNumber(1, 2, 3));
+ QT_TEST_EQUALITY_OPS(v2, QVersionNumber(1, 2, 3), true);
}
// QVersionNumber &operator=(QVersionNumber &&)
{
QVersionNumber v1(1, 2, 3);
QVersionNumber v2;
v2 = std::move(v1);
- QCOMPARE(v2, QVersionNumber(1, 2, 3));
+ QT_TEST_EQUALITY_OPS(v2, QVersionNumber(1, 2, 3), true);
}
// QVersionNumber(QList<int> &&)
{
@@ -624,7 +590,7 @@ void tst_QVersionNumber::moveSemantics()
QVersionNumber v2(std::move(segments));
QVERIFY(!v1.isNull());
QVERIFY(!v2.isNull());
- QCOMPARE(v1, v2);
+ QT_TEST_EQUALITY_OPS(v1, v2, true);
}
#ifdef Q_COMPILER_REF_QUALIFIERS
// normalized()
@@ -665,153 +631,6 @@ void tst_QVersionNumber::qtVersion()
QCOMPARE(v.toString(), QString(qVersion()));
}
-template<typename Integer>
-void compileTestRevisionMajorMinor()
-{
- const Integer major = 8;
- const Integer minor = 4;
-
- const QTypeRevision r2 = QTypeRevision::fromVersion(major, minor);
- QCOMPARE(r2.majorVersion(), 8);
- QCOMPARE(r2.minorVersion(), 4);
-
- const QTypeRevision r3 = QTypeRevision::fromMajorVersion(major);
- QCOMPARE(r3.majorVersion(), 8);
- QVERIFY(!r3.hasMinorVersion());
-
- const QTypeRevision r4 = QTypeRevision::fromMinorVersion(minor);
- QVERIFY(!r4.hasMajorVersion());
- QCOMPARE(r4.minorVersion(), 4);
-}
-
-
-template<typename Integer>
-void compileTestRevision()
-{
- if (std::is_signed<Integer>::value)
- compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Signed>();
- else
- compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Unsigned>();
-
- const Integer value = 0x0510;
- const QTypeRevision r = QTypeRevision::fromEncodedVersion(value);
-
- QCOMPARE(r.majorVersion(), 5);
- QCOMPARE(r.minorVersion(), 16);
- QCOMPARE(r.toEncodedVersion<Integer>(), value);
-
- compileTestRevisionMajorMinor<Integer>();
-}
-
-template<>
-void compileTestRevision<qint16>()
-{
- compileTestRevisionMajorMinor<quint8>();
-}
-
-template<>
-void compileTestRevision<quint8>()
-{
- compileTestRevisionMajorMinor<quint8>();
-}
-
-template<>
-void compileTestRevision<qint8>()
-{
- compileTestRevisionMajorMinor<qint8>();
-}
-
-void tst_QVersionNumber::qTypeRevision_data()
-{
- QTest::addColumn<QTypeRevision>("revision");
- QTest::addColumn<bool>("valid");
- QTest::addColumn<int>("major");
- QTest::addColumn<int>("minor");
-
- QTest::addRow("Qt revision") << QTypeRevision::fromVersion(QT_VERSION_MAJOR, QT_VERSION_MINOR)
- << true << QT_VERSION_MAJOR << QT_VERSION_MINOR;
- QTest::addRow("invalid") << QTypeRevision() << false << 0xff << 0xff;
- QTest::addRow("major") << QTypeRevision::fromMajorVersion(6) << true << 6 << 0xff;
- QTest::addRow("minor") << QTypeRevision::fromMinorVersion(15) << true << 0xff << 15;
- QTest::addRow("zero") << QTypeRevision::fromVersion(0, 0) << true << 0 << 0;
-
- // We're intentionally not testing negative numbers.
- // There are asserts against negative numbers in QTypeRevision.
- // You must not pass them as major or minor versions, or values.
-}
-
-void tst_QVersionNumber::qTypeRevision()
-{
- const QTypeRevision other = QTypeRevision::fromVersion(127, 128);
-
- QFETCH(QTypeRevision, revision);
-
- QFETCH(bool, valid);
- QFETCH(int, major);
- QFETCH(int, minor);
-
- QCOMPARE(revision.isValid(), valid);
- QCOMPARE(revision.majorVersion(), major);
- QCOMPARE(revision.minorVersion(), minor);
-
- QCOMPARE(revision.hasMajorVersion(), QTypeRevision::isValidSegment(major));
- QCOMPARE(revision.hasMinorVersion(), QTypeRevision::isValidSegment(minor));
-
- const QTypeRevision copy = QTypeRevision::fromEncodedVersion(revision.toEncodedVersion<int>());
- QCOMPARE(copy, revision);
-
- QVERIFY(revision != other);
- QVERIFY(copy != other);
-}
-
-void tst_QVersionNumber::qTypeRevisionTypes()
-{
- compileTestRevision<quint64>();
- compileTestRevision<qint64>();
-
- QVERIFY(!QTypeRevision::isValidSegment(0xff));
- QVERIFY(!QTypeRevision::isValidSegment(-1));
-
- const QTypeRevision maxRevision = QTypeRevision::fromVersion(254, 254);
- QVERIFY(maxRevision.hasMajorVersion());
- QVERIFY(maxRevision.hasMinorVersion());
-}
-
-void tst_QVersionNumber::qTypeRevisionComparison()
-{
- const QTypeRevision revisions[] = {
- QTypeRevision::zero(),
- QTypeRevision::fromMajorVersion(0),
- QTypeRevision::fromVersion(0, 1),
- QTypeRevision::fromVersion(0, 20),
- QTypeRevision::fromMinorVersion(0),
- QTypeRevision(),
- QTypeRevision::fromMinorVersion(1),
- QTypeRevision::fromMinorVersion(20),
- QTypeRevision::fromVersion(1, 0),
- QTypeRevision::fromMajorVersion(1),
- QTypeRevision::fromVersion(1, 1),
- QTypeRevision::fromVersion(1, 20),
- QTypeRevision::fromVersion(20, 0),
- QTypeRevision::fromMajorVersion(20),
- QTypeRevision::fromVersion(20, 1),
- QTypeRevision::fromVersion(20, 20),
- };
-
- const int length = sizeof(revisions) / sizeof(QTypeRevision);
-
- for (int i = 0; i < length; ++i) {
- for (int j = 0; j < length; ++j) {
- QCOMPARE(revisions[i] == revisions[j], i == j);
- QCOMPARE(revisions[i] != revisions[j], i != j);
- QCOMPARE(revisions[i] < revisions[j], i < j);
- QCOMPARE(revisions[i] > revisions[j], i > j);
- QCOMPARE(revisions[i] <= revisions[j], i <= j);
- QCOMPARE(revisions[i] >= revisions[j], i >= j);
- }
- }
-}
-
QTEST_APPLESS_MAIN(tst_QVersionNumber)
#include "tst_qversionnumber.moc"