summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r--tests/auto/corelib/global/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/global/q20/CMakeLists.txt1
-rw-r--r--tests/auto/corelib/global/q20/memory/CMakeLists.txt16
-rw-r--r--tests/auto/corelib/global/q20/memory/tst_q20_memory.cpp161
-rw-r--r--tests/auto/corelib/global/q_func_info/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp2
-rw-r--r--tests/auto/corelib/global/qcompare/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qcompare/tst_qcompare.cpp746
-rw-r--r--tests/auto/corelib/global/qcomparehelpers/CMakeLists.txt39
-rw-r--r--tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp600
-rw-r--r--tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h63
-rw-r--r--tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp59
-rw-r--r--tests/auto/corelib/global/qcomparehelpers/wrappertypes.h116
-rw-r--r--tests/auto/corelib/global/qflags/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp6
-rw-r--r--tests/auto/corelib/global/qfloat16/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp241
-rw-r--r--tests/auto/corelib/global/qgetputenv/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp2
-rw-r--r--tests/auto/corelib/global/qglobal/CMakeLists.txt10
-rw-r--r--tests/auto/corelib/global/qglobal/qglobal.c29
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp245
-rw-r--r--tests/auto/corelib/global/qglobalstatic/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp2
-rw-r--r--tests/auto/corelib/global/qhooks/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qhooks/tst_qhooks.cpp2
-rw-r--r--tests/auto/corelib/global/qkeycombination/CMakeLists.txt10
-rw-r--r--tests/auto/corelib/global/qkeycombination/tst_qkeycombination.cpp69
-rw-r--r--tests/auto/corelib/global/qlogging/BLACKLIST10
-rw-r--r--tests/auto/corelib/global/qlogging/CMakeLists.txt10
-rw-r--r--tests/auto/corelib/global/qlogging/app/main.cpp2
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp111
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qmessagelogger.cpp2
-rw-r--r--tests/auto/corelib/global/qnativeinterface/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp2
-rw-r--r--tests/auto/corelib/global/qnumeric/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp87
-rw-r--r--tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp131
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp7
-rw-r--r--tests/auto/corelib/global/qtendian/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/global/qtendian/tst_qtendian.cpp91
-rw-r--r--tests/auto/corelib/global/qxp/CMakeLists.txt1
-rw-r--r--tests/auto/corelib/global/qxp/function_ref/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/global/qxp/function_ref/tst_qxp_function_ref.cpp4
-rw-r--r--tests/auto/corelib/global/qxp/is_virtual_base_of/CMakeLists.txt23
-rw-r--r--tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp102
48 files changed, 2896 insertions, 207 deletions
diff --git a/tests/auto/corelib/global/CMakeLists.txt b/tests/auto/corelib/global/CMakeLists.txt
index 6ccf3c2ed0..7970116672 100644
--- a/tests/auto/corelib/global/CMakeLists.txt
+++ b/tests/auto/corelib/global/CMakeLists.txt
@@ -1,10 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from global.pro.
if(NOT INTEGRITY)
add_subdirectory(qcompare)
endif()
+add_subdirectory(qcomparehelpers)
add_subdirectory(qflags)
add_subdirectory(q_func_info)
add_subdirectory(qgetputenv)
@@ -22,3 +22,4 @@ add_subdirectory(qglobalstatic)
add_subdirectory(qhooks)
add_subdirectory(qoperatingsystemversion)
add_subdirectory(qxp)
+add_subdirectory(q20)
diff --git a/tests/auto/corelib/global/q20/CMakeLists.txt b/tests/auto/corelib/global/q20/CMakeLists.txt
new file mode 100644
index 0000000000..bd28f8b999
--- /dev/null
+++ b/tests/auto/corelib/global/q20/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(memory)
diff --git a/tests/auto/corelib/global/q20/memory/CMakeLists.txt b/tests/auto/corelib/global/q20/memory/CMakeLists.txt
new file mode 100644
index 0000000000..f36ff0f592
--- /dev/null
+++ b/tests/auto/corelib/global/q20/memory/CMakeLists.txt
@@ -0,0 +1,16 @@
+# 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_q20_memory LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_q20_memory
+ EXCEPTIONS
+ SOURCES
+ tst_q20_memory.cpp
+ LIBRARIES
+ Qt::Core
+)
diff --git a/tests/auto/corelib/global/q20/memory/tst_q20_memory.cpp b/tests/auto/corelib/global/q20/memory/tst_q20_memory.cpp
new file mode 100644
index 0000000000..22dbb09e7c
--- /dev/null
+++ b/tests/auto/corelib/global/q20/memory/tst_q20_memory.cpp
@@ -0,0 +1,161 @@
+// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <q20memory.h>
+#include <QtCore/q20memory.h>
+
+#include <QTest>
+#include <QObject>
+#include <QExplicitlySharedDataPointer>
+#include <QSharedDataPointer>
+
+struct Private : QSharedData {};
+
+class tst_q20_memory : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void raw();
+ void smart();
+ void recursion();
+ void usesPointerTraits();
+ void prefersPointerTraits();
+
+private Q_SLOTS:
+ void to_address_broken_const_propagation_QExplicitlySharedDataPointer()
+ { to_address_broken_const_propagation<QExplicitlySharedDataPointer<Private>>(); }
+ void to_address_broken_const_propagation_QSharedDataPointer()
+ { to_address_broken_const_propagation<QSharedDataPointer<Private>>(); }
+ void to_address_broken_const_propagation_shared_ptr()
+ { to_address_broken_const_propagation<std::shared_ptr<Private>>(); }
+ void to_address_broken_const_propagation_unique_ptr()
+ { to_address_broken_const_propagation<std::unique_ptr<Private>>(); }
+
+private:
+ template <typename Pointer>
+ void to_address_broken_const_propagation();
+};
+
+void tst_q20_memory::raw()
+{
+ auto i = 0;
+ auto p = &i;
+ QVERIFY(q20::to_address(p) == &i);
+}
+
+template <typename T>
+class MinimalPtr {
+public:
+ using element_type = T;
+
+ explicit MinimalPtr(T *d) : d(d) {}
+
+ T *operator->() const noexcept { return d; }
+
+private:
+ T *d;
+};
+
+void tst_q20_memory::smart()
+{
+ int i;
+ MinimalPtr ptr(&i);
+ QCOMPARE_EQ(q20::to_address(ptr), &i);
+}
+
+template <typename T>
+class RecursivePtr {
+public:
+ using element_type = T;
+
+ explicit RecursivePtr(T *d) : d(d) {}
+
+ MinimalPtr<T> operator->() const noexcept { return d; }
+
+private:
+ MinimalPtr<T> d;
+};
+
+void tst_q20_memory::recursion()
+{
+ int i;
+ RecursivePtr ptr(&i);
+ QCOMPARE_EQ(q20::to_address(ptr), &i);
+}
+
+template <typename T>
+class NoDerefOperatorPtr {
+public:
+ using element_type = T;
+
+ explicit NoDerefOperatorPtr(T *d) : d(d) {}
+
+ T *get() const noexcept { return d; }
+
+private:
+ T *d;
+};
+
+namespace std {
+template <typename T>
+struct pointer_traits<NoDerefOperatorPtr<T>>
+{
+ static T *to_address(const NoDerefOperatorPtr<T> &ptr) noexcept { return ptr.get(); }
+};
+} // namespace std
+
+void tst_q20_memory::usesPointerTraits()
+{
+ int i;
+ NoDerefOperatorPtr ptr(&i);
+ QCOMPARE_EQ(q20::to_address(ptr), &i);
+}
+
+template <typename T>
+class PrefersPointerTraitsPtr
+{
+public:
+ using element_type = T;
+
+ explicit PrefersPointerTraitsPtr(T *d) : d(d) {}
+
+ T *operator->() const noexcept { return nullptr; }
+
+ T *get() const noexcept { return d; }
+
+private:
+ T *d;
+};
+
+namespace std {
+template <typename T>
+struct pointer_traits<PrefersPointerTraitsPtr<T>>
+{
+ static T *to_address(const PrefersPointerTraitsPtr<T> &p) noexcept { return p.get(); }
+};
+} // namespace std
+
+void tst_q20_memory::prefersPointerTraits()
+{
+ int i;
+ PrefersPointerTraitsPtr ptr(&i);
+ QCOMPARE_EQ(q20::to_address(ptr), &i);
+}
+
+template <typename Pointer>
+void tst_q20_memory::to_address_broken_const_propagation()
+{
+ Pointer p(nullptr);
+ QCOMPARE_EQ(q20::to_address(p), nullptr);
+ p = Pointer{new Private()};
+ QCOMPARE_EQ(q20::to_address(p), p.operator->());
+ static_assert(std::is_same_v<decltype(q20::to_address(p)),
+ decltype(std::as_const(p).operator->())>);
+}
+
+QTEST_GUILESS_MAIN(tst_q20_memory)
+#include "tst_q20_memory.moc"
+
diff --git a/tests/auto/corelib/global/q_func_info/CMakeLists.txt b/tests/auto/corelib/global/q_func_info/CMakeLists.txt
index 8d3682a4c4..88119484cd 100644
--- a/tests/auto/corelib/global/q_func_info/CMakeLists.txt
+++ b/tests/auto/corelib/global/q_func_info/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from q_func_info.pro.
-
#####################################################################
## tst_q_func_info Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_q_func_info LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_q_func_info
SOURCES
tst_q_func_info.cpp
diff --git a/tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp b/tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp
index 5320ba90c0..b288f1d3a1 100644
--- a/tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp
+++ b/tests/auto/corelib/global/q_func_info/tst_q_func_info.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 <QString>
diff --git a/tests/auto/corelib/global/qcompare/CMakeLists.txt b/tests/auto/corelib/global/qcompare/CMakeLists.txt
index bde33a1ae5..b29dcae618 100644
--- a/tests/auto/corelib/global/qcompare/CMakeLists.txt
+++ b/tests/auto/corelib/global/qcompare/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qcompare.pro.
-
#####################################################################
## tst_qcompare Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcompare LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcompare
SOURCES
tst_qcompare.cpp
diff --git a/tests/auto/corelib/global/qcompare/tst_qcompare.cpp b/tests/auto/corelib/global/qcompare/tst_qcompare.cpp
index cc21bd9d14..e36429e62b 100644
--- a/tests/auto/corelib/global/qcompare/tst_qcompare.cpp
+++ b/tests/auto/corelib/global/qcompare/tst_qcompare.cpp
@@ -1,18 +1,36 @@
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QtCompare>
#include <QtTest/QTest>
+#ifdef __cpp_lib_three_way_comparison
+#include <compare>
+#endif // __cpp_lib_three_way_comparison
+
class tst_QCompare: public QObject
{
Q_OBJECT
private slots:
+ void legacyPartialOrdering();
+ void legacyConversions();
+ void stdQtBinaryCompatibility();
void partialOrdering();
+ void weakOrdering();
+ void strongOrdering();
+ void threeWayCompareWithLiteralZero();
+ void conversions();
+ void is_eq_overloads();
+ void compareThreeWay();
};
-void tst_QCompare::partialOrdering()
+void tst_QCompare::legacyPartialOrdering()
{
+ static_assert(QPartialOrdering::Unordered == QPartialOrdering::unordered);
+ static_assert(QPartialOrdering::Less == QPartialOrdering::less);
+ static_assert(QPartialOrdering::Equivalent == QPartialOrdering::equivalent);
+ static_assert(QPartialOrdering::Greater == QPartialOrdering::greater);
+
static_assert(QPartialOrdering::Unordered == QPartialOrdering::Unordered);
static_assert(QPartialOrdering::Unordered != QPartialOrdering::Less);
static_assert(QPartialOrdering::Unordered != QPartialOrdering::Equivalent);
@@ -33,6 +51,12 @@ void tst_QCompare::partialOrdering()
static_assert(QPartialOrdering::Greater != QPartialOrdering::Equivalent);
static_assert(QPartialOrdering::Greater == QPartialOrdering::Greater);
+ static_assert(!is_eq (QPartialOrdering::Unordered));
+ static_assert(!is_neq (QPartialOrdering::Unordered));
+ static_assert(!is_lt (QPartialOrdering::Unordered));
+ static_assert(!is_lteq(QPartialOrdering::Unordered));
+ static_assert(!is_gt (QPartialOrdering::Unordered));
+ static_assert(!is_gteq(QPartialOrdering::Unordered));
static_assert(!(QPartialOrdering::Unordered == 0));
static_assert(!(QPartialOrdering::Unordered != 0));
@@ -49,6 +73,13 @@ void tst_QCompare::partialOrdering()
static_assert(!(0 >= QPartialOrdering::Unordered));
+ static_assert(!is_eq (QPartialOrdering::Less));
+ static_assert( is_neq (QPartialOrdering::Less));
+ static_assert( is_lt (QPartialOrdering::Less));
+ static_assert( is_lteq(QPartialOrdering::Less));
+ static_assert(!is_gt (QPartialOrdering::Less));
+ static_assert(!is_gteq(QPartialOrdering::Less));
+
static_assert(!(QPartialOrdering::Less == 0));
static_assert( (QPartialOrdering::Less != 0));
static_assert( (QPartialOrdering::Less < 0));
@@ -64,6 +95,13 @@ void tst_QCompare::partialOrdering()
static_assert( (0 >= QPartialOrdering::Less));
+ static_assert( is_eq (QPartialOrdering::Equivalent));
+ static_assert(!is_neq (QPartialOrdering::Equivalent));
+ static_assert(!is_lt (QPartialOrdering::Equivalent));
+ static_assert( is_lteq(QPartialOrdering::Equivalent));
+ static_assert(!is_gt (QPartialOrdering::Equivalent));
+ static_assert( is_gteq(QPartialOrdering::Equivalent));
+
static_assert( (QPartialOrdering::Equivalent == 0));
static_assert(!(QPartialOrdering::Equivalent != 0));
static_assert(!(QPartialOrdering::Equivalent < 0));
@@ -79,6 +117,13 @@ void tst_QCompare::partialOrdering()
static_assert( (0 >= QPartialOrdering::Equivalent));
+ static_assert(!is_eq (QPartialOrdering::Greater));
+ static_assert( is_neq (QPartialOrdering::Greater));
+ static_assert(!is_lt (QPartialOrdering::Greater));
+ static_assert(!is_lteq(QPartialOrdering::Greater));
+ static_assert( is_gt (QPartialOrdering::Greater));
+ static_assert( is_gteq(QPartialOrdering::Greater));
+
static_assert(!(QPartialOrdering::Greater == 0));
static_assert( (QPartialOrdering::Greater != 0));
static_assert(!(QPartialOrdering::Greater < 0));
@@ -94,5 +139,702 @@ void tst_QCompare::partialOrdering()
static_assert(!(0 >= QPartialOrdering::Greater));
}
+void tst_QCompare::legacyConversions()
+{
+#define CHECK_CONVERTS(Lhs, Rhs) static_assert(std::is_convertible_v<Lhs, Rhs>)
+#define CHECK_ALL(NS) do { \
+ CHECK_CONVERTS(QPartialOrdering, NS ::partial_ordering); \
+ static_assert(QPartialOrdering::Less == NS ::partial_ordering::less); \
+ static_assert(QPartialOrdering::Greater == NS ::partial_ordering::greater); \
+ static_assert(QPartialOrdering::Equivalent == NS ::partial_ordering::equivalent); \
+ static_assert(QPartialOrdering::Unordered == NS ::partial_ordering::unordered); \
+ \
+ CHECK_CONVERTS(NS ::partial_ordering, QPartialOrdering); \
+ CHECK_CONVERTS(NS ::weak_ordering, QPartialOrdering); \
+ CHECK_CONVERTS(NS ::strong_ordering, QPartialOrdering); \
+ } while (false)
+
+ CHECK_ALL(Qt);
+#ifdef __cpp_lib_three_way_comparison
+ CHECK_ALL(std);
+#endif // __cpp_lib_three_way_comparison
+
+#undef CHECK_ALL
+#undef CHECK_CONVERTS
+}
+
+void tst_QCompare::stdQtBinaryCompatibility()
+{
+#ifndef __cpp_lib_three_way_comparison
+ QSKIP("This test requires C++20 three-way-comparison support enabled in the stdlib.");
+#else
+ QCOMPARE_EQ(sizeof(std::partial_ordering), 1U);
+ QCOMPARE_EQ(sizeof( Qt::partial_ordering), 1U);
+ QCOMPARE_EQ(sizeof(std:: weak_ordering), 1U);
+ QCOMPARE_EQ(sizeof( Qt:: weak_ordering), 1U);
+ QCOMPARE_EQ(sizeof(std:: strong_ordering), 1U);
+ QCOMPARE_EQ(sizeof( Qt:: strong_ordering), 1U);
+
+ auto valueOf = [](auto obj) {
+ typename QIntegerForSizeof<decltype(obj)>::Unsigned value;
+ memcpy(&value, &obj, sizeof(obj));
+ return value;
+ };
+#define CHECK(type, flag) \
+ QCOMPARE_EQ(valueOf( Qt:: type ## _ordering :: flag), \
+ valueOf(std:: type ## _ordering :: flag)) \
+ /* end */
+ CHECK(partial, unordered);
+ CHECK(partial, less);
+ CHECK(partial, greater);
+ CHECK(partial, equivalent);
+
+ CHECK(weak, less);
+ CHECK(weak, greater);
+ CHECK(weak, equivalent);
+
+ CHECK(strong, less);
+ CHECK(strong, greater);
+ CHECK(strong, equivalent);
+ CHECK(strong, equal);
+#undef CHECK
+#endif //__cpp_lib_three_way_comparison
+}
+
+void tst_QCompare::partialOrdering()
+{
+ static_assert(Qt::partial_ordering::unordered == Qt::partial_ordering::unordered);
+ static_assert(Qt::partial_ordering::unordered != Qt::partial_ordering::less);
+ static_assert(Qt::partial_ordering::unordered != Qt::partial_ordering::equivalent);
+ static_assert(Qt::partial_ordering::unordered != Qt::partial_ordering::greater);
+
+ static_assert(Qt::partial_ordering::less != Qt::partial_ordering::unordered);
+ static_assert(Qt::partial_ordering::less == Qt::partial_ordering::less);
+ static_assert(Qt::partial_ordering::less != Qt::partial_ordering::equivalent);
+ static_assert(Qt::partial_ordering::less != Qt::partial_ordering::greater);
+
+ static_assert(Qt::partial_ordering::equivalent != Qt::partial_ordering::unordered);
+ static_assert(Qt::partial_ordering::equivalent != Qt::partial_ordering::less);
+ static_assert(Qt::partial_ordering::equivalent == Qt::partial_ordering::equivalent);
+ static_assert(Qt::partial_ordering::equivalent != Qt::partial_ordering::greater);
+
+ static_assert(Qt::partial_ordering::greater != Qt::partial_ordering::unordered);
+ static_assert(Qt::partial_ordering::greater != Qt::partial_ordering::less);
+ static_assert(Qt::partial_ordering::greater != Qt::partial_ordering::equivalent);
+ static_assert(Qt::partial_ordering::greater == Qt::partial_ordering::greater);
+
+ static_assert(!is_eq (Qt::partial_ordering::unordered));
+ static_assert(!is_neq (Qt::partial_ordering::unordered));
+ static_assert(!is_lt (Qt::partial_ordering::unordered));
+ static_assert(!is_lteq(Qt::partial_ordering::unordered));
+ static_assert(!is_gt (Qt::partial_ordering::unordered));
+ static_assert(!is_gteq(Qt::partial_ordering::unordered));
+
+ static_assert(!(Qt::partial_ordering::unordered == 0));
+ static_assert(!(Qt::partial_ordering::unordered != 0));
+ static_assert(!(Qt::partial_ordering::unordered < 0));
+ static_assert(!(Qt::partial_ordering::unordered <= 0));
+ static_assert(!(Qt::partial_ordering::unordered > 0));
+ static_assert(!(Qt::partial_ordering::unordered >= 0));
+
+ static_assert(!(0 == Qt::partial_ordering::unordered));
+ static_assert(!(0 != Qt::partial_ordering::unordered));
+ static_assert(!(0 < Qt::partial_ordering::unordered));
+ static_assert(!(0 <= Qt::partial_ordering::unordered));
+ static_assert(!(0 > Qt::partial_ordering::unordered));
+ static_assert(!(0 >= Qt::partial_ordering::unordered));
+
+
+ static_assert(!is_eq (Qt::partial_ordering::less));
+ static_assert( is_neq (Qt::partial_ordering::less));
+ static_assert( is_lt (Qt::partial_ordering::less));
+ static_assert( is_lteq(Qt::partial_ordering::less));
+ static_assert(!is_gt (Qt::partial_ordering::less));
+ static_assert(!is_gteq(Qt::partial_ordering::less));
+
+ static_assert(!(Qt::partial_ordering::less == 0));
+ static_assert( (Qt::partial_ordering::less != 0));
+ static_assert( (Qt::partial_ordering::less < 0));
+ static_assert( (Qt::partial_ordering::less <= 0));
+ static_assert(!(Qt::partial_ordering::less > 0));
+ static_assert(!(Qt::partial_ordering::less >= 0));
+
+ static_assert(!(0 == Qt::partial_ordering::less));
+ static_assert( (0 != Qt::partial_ordering::less));
+ static_assert(!(0 < Qt::partial_ordering::less));
+ static_assert(!(0 <= Qt::partial_ordering::less));
+ static_assert( (0 > Qt::partial_ordering::less));
+ static_assert( (0 >= Qt::partial_ordering::less));
+
+
+ static_assert( is_eq (Qt::partial_ordering::equivalent));
+ static_assert(!is_neq (Qt::partial_ordering::equivalent));
+ static_assert(!is_lt (Qt::partial_ordering::equivalent));
+ static_assert( is_lteq(Qt::partial_ordering::equivalent));
+ static_assert(!is_gt (Qt::partial_ordering::equivalent));
+ static_assert( is_gteq(Qt::partial_ordering::equivalent));
+
+ static_assert( (Qt::partial_ordering::equivalent == 0));
+ static_assert(!(Qt::partial_ordering::equivalent != 0));
+ static_assert(!(Qt::partial_ordering::equivalent < 0));
+ static_assert( (Qt::partial_ordering::equivalent <= 0));
+ static_assert(!(Qt::partial_ordering::equivalent > 0));
+ static_assert( (Qt::partial_ordering::equivalent >= 0));
+
+ static_assert( (0 == Qt::partial_ordering::equivalent));
+ static_assert(!(0 != Qt::partial_ordering::equivalent));
+ static_assert(!(0 < Qt::partial_ordering::equivalent));
+ static_assert( (0 <= Qt::partial_ordering::equivalent));
+ static_assert(!(0 > Qt::partial_ordering::equivalent));
+ static_assert( (0 >= Qt::partial_ordering::equivalent));
+
+
+ static_assert(!is_eq (Qt::partial_ordering::greater));
+ static_assert( is_neq (Qt::partial_ordering::greater));
+ static_assert(!is_lt (Qt::partial_ordering::greater));
+ static_assert(!is_lteq(Qt::partial_ordering::greater));
+ static_assert( is_gt (Qt::partial_ordering::greater));
+ static_assert( is_gteq(Qt::partial_ordering::greater));
+
+ static_assert(!(Qt::partial_ordering::greater == 0));
+ static_assert( (Qt::partial_ordering::greater != 0));
+ static_assert(!(Qt::partial_ordering::greater < 0));
+ static_assert(!(Qt::partial_ordering::greater <= 0));
+ static_assert( (Qt::partial_ordering::greater > 0));
+ static_assert( (Qt::partial_ordering::greater >= 0));
+
+ static_assert(!(0 == Qt::partial_ordering::greater));
+ static_assert( (0 != Qt::partial_ordering::greater));
+ static_assert( (0 < Qt::partial_ordering::greater));
+ static_assert( (0 <= Qt::partial_ordering::greater));
+ static_assert(!(0 > Qt::partial_ordering::greater));
+ static_assert(!(0 >= Qt::partial_ordering::greater));
+}
+
+void tst_QCompare::weakOrdering()
+{
+ static_assert(Qt::weak_ordering::less == Qt::weak_ordering::less);
+ static_assert(Qt::weak_ordering::less != Qt::weak_ordering::equivalent);
+ static_assert(Qt::weak_ordering::less != Qt::weak_ordering::greater);
+
+ static_assert(Qt::weak_ordering::equivalent != Qt::weak_ordering::less);
+ static_assert(Qt::weak_ordering::equivalent == Qt::weak_ordering::equivalent);
+ static_assert(Qt::weak_ordering::equivalent != Qt::weak_ordering::greater);
+
+ static_assert(Qt::weak_ordering::greater != Qt::weak_ordering::less);
+ static_assert(Qt::weak_ordering::greater != Qt::weak_ordering::equivalent);
+ static_assert(Qt::weak_ordering::greater == Qt::weak_ordering::greater);
+
+ static_assert(!is_eq (Qt::weak_ordering::less));
+ static_assert( is_neq (Qt::weak_ordering::less));
+ static_assert( is_lt (Qt::weak_ordering::less));
+ static_assert( is_lteq(Qt::weak_ordering::less));
+ static_assert(!is_gt (Qt::weak_ordering::less));
+ static_assert(!is_gteq(Qt::weak_ordering::less));
+
+ static_assert(!(Qt::weak_ordering::less == 0));
+ static_assert( (Qt::weak_ordering::less != 0));
+ static_assert( (Qt::weak_ordering::less < 0));
+ static_assert( (Qt::weak_ordering::less <= 0));
+ static_assert(!(Qt::weak_ordering::less > 0));
+ static_assert(!(Qt::weak_ordering::less >= 0));
+
+ static_assert(!(0 == Qt::weak_ordering::less));
+ static_assert( (0 != Qt::weak_ordering::less));
+ static_assert(!(0 < Qt::weak_ordering::less));
+ static_assert(!(0 <= Qt::weak_ordering::less));
+ static_assert( (0 > Qt::weak_ordering::less));
+ static_assert( (0 >= Qt::weak_ordering::less));
+
+
+ static_assert( is_eq (Qt::weak_ordering::equivalent));
+ static_assert(!is_neq (Qt::weak_ordering::equivalent));
+ static_assert(!is_lt (Qt::weak_ordering::equivalent));
+ static_assert( is_lteq(Qt::weak_ordering::equivalent));
+ static_assert(!is_gt (Qt::weak_ordering::equivalent));
+ static_assert( is_gteq(Qt::weak_ordering::equivalent));
+
+ static_assert( (Qt::weak_ordering::equivalent == 0));
+ static_assert(!(Qt::weak_ordering::equivalent != 0));
+ static_assert(!(Qt::weak_ordering::equivalent < 0));
+ static_assert( (Qt::weak_ordering::equivalent <= 0));
+ static_assert(!(Qt::weak_ordering::equivalent > 0));
+ static_assert( (Qt::weak_ordering::equivalent >= 0));
+
+ static_assert( (0 == Qt::weak_ordering::equivalent));
+ static_assert(!(0 != Qt::weak_ordering::equivalent));
+ static_assert(!(0 < Qt::weak_ordering::equivalent));
+ static_assert( (0 <= Qt::weak_ordering::equivalent));
+ static_assert(!(0 > Qt::weak_ordering::equivalent));
+ static_assert( (0 >= Qt::weak_ordering::equivalent));
+
+
+ static_assert(!is_eq (Qt::weak_ordering::greater));
+ static_assert( is_neq (Qt::weak_ordering::greater));
+ static_assert(!is_lt (Qt::weak_ordering::greater));
+ static_assert(!is_lteq(Qt::weak_ordering::greater));
+ static_assert( is_gt (Qt::weak_ordering::greater));
+ static_assert( is_gteq(Qt::weak_ordering::greater));
+
+ static_assert(!(Qt::weak_ordering::greater == 0));
+ static_assert( (Qt::weak_ordering::greater != 0));
+ static_assert(!(Qt::weak_ordering::greater < 0));
+ static_assert(!(Qt::weak_ordering::greater <= 0));
+ static_assert( (Qt::weak_ordering::greater > 0));
+ static_assert( (Qt::weak_ordering::greater >= 0));
+
+ static_assert(!(0 == Qt::weak_ordering::greater));
+ static_assert( (0 != Qt::weak_ordering::greater));
+ static_assert( (0 < Qt::weak_ordering::greater));
+ static_assert( (0 <= Qt::weak_ordering::greater));
+ static_assert(!(0 > Qt::weak_ordering::greater));
+ static_assert(!(0 >= Qt::weak_ordering::greater));
+}
+
+void tst_QCompare::strongOrdering()
+{
+ static_assert(Qt::strong_ordering::less == Qt::strong_ordering::less);
+ static_assert(Qt::strong_ordering::less != Qt::strong_ordering::equal);
+ static_assert(Qt::strong_ordering::less != Qt::strong_ordering::equivalent);
+ static_assert(Qt::strong_ordering::less != Qt::strong_ordering::greater);
+
+ static_assert(Qt::strong_ordering::equal != Qt::strong_ordering::less);
+ static_assert(Qt::strong_ordering::equal == Qt::strong_ordering::equal);
+ static_assert(Qt::strong_ordering::equal == Qt::strong_ordering::equivalent);
+ static_assert(Qt::strong_ordering::equal != Qt::strong_ordering::greater);
+
+ static_assert(Qt::strong_ordering::equivalent != Qt::strong_ordering::less);
+ static_assert(Qt::strong_ordering::equivalent == Qt::strong_ordering::equal);
+ static_assert(Qt::strong_ordering::equivalent == Qt::strong_ordering::equivalent);
+ static_assert(Qt::strong_ordering::equivalent != Qt::strong_ordering::greater);
+
+ static_assert(Qt::strong_ordering::greater != Qt::strong_ordering::less);
+ static_assert(Qt::strong_ordering::greater != Qt::strong_ordering::equal);
+ static_assert(Qt::strong_ordering::greater != Qt::strong_ordering::equivalent);
+ static_assert(Qt::strong_ordering::greater == Qt::strong_ordering::greater);
+
+ static_assert(!is_eq (Qt::strong_ordering::less));
+ static_assert( is_neq (Qt::strong_ordering::less));
+ static_assert( is_lt (Qt::strong_ordering::less));
+ static_assert( is_lteq(Qt::strong_ordering::less));
+ static_assert(!is_gt (Qt::strong_ordering::less));
+ static_assert(!is_gteq(Qt::strong_ordering::less));
+
+ static_assert(!(Qt::strong_ordering::less == 0));
+ static_assert( (Qt::strong_ordering::less != 0));
+ static_assert( (Qt::strong_ordering::less < 0));
+ static_assert( (Qt::strong_ordering::less <= 0));
+ static_assert(!(Qt::strong_ordering::less > 0));
+ static_assert(!(Qt::strong_ordering::less >= 0));
+
+ static_assert(!(0 == Qt::strong_ordering::less));
+ static_assert( (0 != Qt::strong_ordering::less));
+ static_assert(!(0 < Qt::strong_ordering::less));
+ static_assert(!(0 <= Qt::strong_ordering::less));
+ static_assert( (0 > Qt::strong_ordering::less));
+ static_assert( (0 >= Qt::strong_ordering::less));
+
+
+ static_assert( is_eq (Qt::strong_ordering::equal));
+ static_assert(!is_neq (Qt::strong_ordering::equal));
+ static_assert(!is_lt (Qt::strong_ordering::equal));
+ static_assert( is_lteq(Qt::strong_ordering::equal));
+ static_assert(!is_gt (Qt::strong_ordering::equal));
+ static_assert( is_gteq(Qt::strong_ordering::equal));
+
+ static_assert( (Qt::strong_ordering::equal == 0));
+ static_assert(!(Qt::strong_ordering::equal != 0));
+ static_assert(!(Qt::strong_ordering::equal < 0));
+ static_assert( (Qt::strong_ordering::equal <= 0));
+ static_assert(!(Qt::strong_ordering::equal > 0));
+ static_assert( (Qt::strong_ordering::equal >= 0));
+
+ static_assert( (0 == Qt::strong_ordering::equal));
+ static_assert(!(0 != Qt::strong_ordering::equal));
+ static_assert(!(0 < Qt::strong_ordering::equal));
+ static_assert( (0 <= Qt::strong_ordering::equal));
+ static_assert(!(0 > Qt::strong_ordering::equal));
+ static_assert( (0 >= Qt::strong_ordering::equal));
+
+
+ static_assert( is_eq (Qt::strong_ordering::equivalent));
+ static_assert(!is_neq (Qt::strong_ordering::equivalent));
+ static_assert(!is_lt (Qt::strong_ordering::equivalent));
+ static_assert( is_lteq(Qt::strong_ordering::equivalent));
+ static_assert(!is_gt (Qt::strong_ordering::equivalent));
+ static_assert( is_gteq(Qt::strong_ordering::equivalent));
+
+ static_assert( (Qt::strong_ordering::equivalent == 0));
+ static_assert(!(Qt::strong_ordering::equivalent != 0));
+ static_assert(!(Qt::strong_ordering::equivalent < 0));
+ static_assert( (Qt::strong_ordering::equivalent <= 0));
+ static_assert(!(Qt::strong_ordering::equivalent > 0));
+ static_assert( (Qt::strong_ordering::equivalent >= 0));
+
+ static_assert( (0 == Qt::strong_ordering::equivalent));
+ static_assert(!(0 != Qt::strong_ordering::equivalent));
+ static_assert(!(0 < Qt::strong_ordering::equivalent));
+ static_assert( (0 <= Qt::strong_ordering::equivalent));
+ static_assert(!(0 > Qt::strong_ordering::equivalent));
+ static_assert( (0 >= Qt::strong_ordering::equivalent));
+
+
+ static_assert(!is_eq (Qt::strong_ordering::greater));
+ static_assert( is_neq (Qt::strong_ordering::greater));
+ static_assert(!is_lt (Qt::strong_ordering::greater));
+ static_assert(!is_lteq(Qt::strong_ordering::greater));
+ static_assert( is_gt (Qt::strong_ordering::greater));
+ static_assert( is_gteq(Qt::strong_ordering::greater));
+
+ static_assert(!(Qt::strong_ordering::greater == 0));
+ static_assert( (Qt::strong_ordering::greater != 0));
+ static_assert(!(Qt::strong_ordering::greater < 0));
+ static_assert(!(Qt::strong_ordering::greater <= 0));
+ static_assert( (Qt::strong_ordering::greater > 0));
+ static_assert( (Qt::strong_ordering::greater >= 0));
+
+ static_assert(!(0 == Qt::strong_ordering::greater));
+ static_assert( (0 != Qt::strong_ordering::greater));
+ static_assert( (0 < Qt::strong_ordering::greater));
+ static_assert( (0 <= Qt::strong_ordering::greater));
+ static_assert(!(0 > Qt::strong_ordering::greater));
+ static_assert(!(0 >= Qt::strong_ordering::greater));
+}
+
+void tst_QCompare::threeWayCompareWithLiteralZero()
+{
+#ifndef __cpp_lib_three_way_comparison
+ QSKIP("This test requires C++20 <=> support enabled in the compiler and the stdlib.");
+#else
+ // the result of <=> is _always_ a std::_ordering type:
+#define CHECK(O) do { \
+ using StdO = typename QtOrderingPrivate::StdOrdering<O>::type; \
+ static_assert(std::is_same_v<decltype(0 <=> std::declval<O&>()), StdO>); \
+ static_assert(std::is_same_v<decltype(std::declval<O&>() <=> 0), StdO>); \
+ } while (false)
+
+ CHECK(Qt::partial_ordering);
+ CHECK(Qt::weak_ordering);
+ CHECK(Qt::strong_ordering);
+ CHECK(QPartialOrdering);
+ // API symmetry check:
+ CHECK(std::partial_ordering);
+ CHECK(std::weak_ordering);
+ CHECK(std::strong_ordering);
+
+#undef CHECK
+
+#define CHECK(O, what, reversed) do { \
+ using StdO = typename QtOrderingPrivate::StdOrdering<O>::type; \
+ static_assert((O :: what <=> 0) == StdO:: what); \
+ static_assert((0 <=> O :: what) == StdO:: reversed); \
+ } while (false)
+
+ CHECK(Qt::partial_ordering, unordered, unordered);
+ CHECK(Qt::partial_ordering, equivalent, equivalent);
+ CHECK(Qt::partial_ordering, less, greater);
+ CHECK(Qt::partial_ordering, greater, less);
+
+ CHECK(Qt::weak_ordering, equivalent, equivalent);
+ CHECK(Qt::weak_ordering, less, greater);
+ CHECK(Qt::weak_ordering, greater, less);
+
+ CHECK(Qt::strong_ordering, equal, equal);
+ CHECK(Qt::strong_ordering, less, greater);
+ CHECK(Qt::strong_ordering, greater, less);
+
+ CHECK(QPartialOrdering, unordered, unordered);
+ CHECK(QPartialOrdering, equivalent, equivalent);
+ CHECK(QPartialOrdering, less, greater);
+ CHECK(QPartialOrdering, greater, less);
+
+ // API symmetry check:
+
+ CHECK(std::partial_ordering, unordered, unordered);
+ CHECK(std::partial_ordering, equivalent, equivalent);
+ CHECK(std::partial_ordering, less, greater);
+ CHECK(std::partial_ordering, greater, less);
+
+ CHECK(std::weak_ordering, equivalent, equivalent);
+ CHECK(std::weak_ordering, less, greater);
+ CHECK(std::weak_ordering, greater, less);
+
+ CHECK(std::strong_ordering, equal, equal);
+ CHECK(std::strong_ordering, less, greater);
+ CHECK(std::strong_ordering, greater, less);
+
+#undef CHECK
+#endif // __cpp_lib_three_way_comparisons
+
+}
+
+void tst_QCompare::conversions()
+{
+ // Qt::weak_ordering -> Qt::partial_ordering
+ {
+ constexpr Qt::partial_ordering less = Qt::weak_ordering::less;
+ static_assert(less == Qt::partial_ordering::less);
+ constexpr Qt::partial_ordering equivalent = Qt::weak_ordering::equivalent;
+ static_assert(equivalent == Qt::partial_ordering::equivalent);
+ constexpr Qt::partial_ordering greater = Qt::weak_ordering::greater;
+ static_assert(greater == Qt::partial_ordering::greater);
+ }
+ // Qt::strong_ordering -> Qt::partial_ordering
+ {
+ constexpr Qt::partial_ordering less = Qt::strong_ordering::less;
+ static_assert(less == Qt::partial_ordering::less);
+ constexpr Qt::partial_ordering equal = Qt::strong_ordering::equal;
+ static_assert(equal == Qt::partial_ordering::equivalent);
+ constexpr Qt::partial_ordering equivalent = Qt::strong_ordering::equivalent;
+ static_assert(equivalent == Qt::partial_ordering::equivalent);
+ constexpr Qt::partial_ordering greater = Qt::strong_ordering::greater;
+ static_assert(greater == Qt::partial_ordering::greater);
+ }
+ // Qt::strong_ordering -> Qt::weak_ordering
+ {
+ constexpr Qt::weak_ordering less = Qt::strong_ordering::less;
+ static_assert(less == Qt::weak_ordering::less);
+ constexpr Qt::weak_ordering equal = Qt::strong_ordering::equal;
+ static_assert(equal == Qt::weak_ordering::equivalent);
+ constexpr Qt::weak_ordering equivalent = Qt::strong_ordering::equivalent;
+ static_assert(equivalent == Qt::weak_ordering::equivalent);
+ constexpr Qt::weak_ordering greater = Qt::strong_ordering::greater;
+ static_assert(greater == Qt::weak_ordering::greater);
+ }
+ // Mixed types
+ {
+ static_assert(Qt::partial_ordering::less == Qt::strong_ordering::less);
+ static_assert(Qt::partial_ordering::equivalent != Qt::strong_ordering::less);
+ static_assert(Qt::partial_ordering::equivalent == Qt::strong_ordering::equal);
+ static_assert(Qt::partial_ordering::greater == Qt::strong_ordering::greater);
+
+ static_assert(Qt::partial_ordering::less == Qt::weak_ordering::less);
+ static_assert(Qt::partial_ordering::equivalent == Qt::weak_ordering::equivalent);
+ static_assert(Qt::partial_ordering::greater == Qt::weak_ordering::greater);
+
+ static_assert(Qt::weak_ordering::less == Qt::strong_ordering::less);
+ static_assert(Qt::weak_ordering::equivalent != Qt::strong_ordering::greater);
+ static_assert(Qt::weak_ordering::equivalent == Qt::strong_ordering::equal);
+ static_assert(Qt::weak_ordering::greater == Qt::strong_ordering::greater);
+
+ static_assert(Qt::weak_ordering::less == Qt::partial_ordering::less);
+ static_assert(Qt::weak_ordering::equivalent == Qt::partial_ordering::equivalent);
+ static_assert(Qt::weak_ordering::greater == Qt::partial_ordering::greater);
+
+ static_assert(Qt::strong_ordering::less == Qt::partial_ordering::less);
+ static_assert(Qt::strong_ordering::equivalent == Qt::partial_ordering::equivalent);
+ static_assert(Qt::strong_ordering::equal == Qt::partial_ordering::equivalent);
+ static_assert(Qt::strong_ordering::greater == Qt::partial_ordering::greater);
+
+ static_assert(Qt::strong_ordering::less == Qt::weak_ordering::less);
+ static_assert(Qt::strong_ordering::equivalent == Qt::weak_ordering::equivalent);
+ static_assert(Qt::strong_ordering::equal == Qt::weak_ordering::equivalent);
+ static_assert(Qt::strong_ordering::greater == Qt::weak_ordering::greater);
+ }
+#ifdef __cpp_lib_three_way_comparison
+ // Qt::partial_ordering <-> std::partial_ordering
+ {
+ static_assert(Qt::partial_ordering::less == std::partial_ordering::less);
+ static_assert(Qt::partial_ordering::less != std::partial_ordering::greater);
+ static_assert(std::partial_ordering::unordered != Qt::partial_ordering::equivalent);
+ static_assert(std::partial_ordering::unordered == Qt::partial_ordering::unordered);
+
+ static_assert((Qt::partial_ordering(std::partial_ordering::less) ==
+ std::partial_ordering::less));
+ static_assert((Qt::partial_ordering(std::partial_ordering::equivalent) ==
+ std::partial_ordering::equivalent));
+ static_assert((Qt::partial_ordering(std::partial_ordering::greater) ==
+ std::partial_ordering::greater));
+ static_assert((Qt::partial_ordering(std::partial_ordering::unordered) ==
+ std::partial_ordering::unordered));
+ }
+ // Qt::weak_ordering <-> std::weak_ordering
+ {
+ static_assert(Qt::weak_ordering::less == std::weak_ordering::less);
+ static_assert(Qt::weak_ordering::less != std::weak_ordering::equivalent);
+ static_assert(std::weak_ordering::greater != Qt::weak_ordering::less);
+ static_assert(std::weak_ordering::equivalent == Qt::weak_ordering::equivalent);
+
+ static_assert((Qt::weak_ordering(std::weak_ordering::less) ==
+ std::weak_ordering::less));
+ static_assert((Qt::weak_ordering(std::weak_ordering::equivalent) ==
+ std::weak_ordering::equivalent));
+ static_assert((Qt::weak_ordering(std::weak_ordering::greater) ==
+ std::weak_ordering::greater));
+ }
+ // Qt::strong_ordering <-> std::strong_ordering
+ {
+ static_assert(Qt::strong_ordering::less == std::strong_ordering::less);
+ static_assert(Qt::strong_ordering::less != std::strong_ordering::equivalent);
+ static_assert(std::strong_ordering::greater != Qt::strong_ordering::less);
+ static_assert(std::strong_ordering::equivalent == Qt::strong_ordering::equivalent);
+
+ static_assert((Qt::strong_ordering(std::strong_ordering::less) ==
+ std::strong_ordering::less));
+ static_assert((Qt::strong_ordering(std::strong_ordering::equivalent) ==
+ std::strong_ordering::equivalent));
+ static_assert((Qt::strong_ordering(std::strong_ordering::greater) ==
+ std::strong_ordering::greater));
+ }
+ // Mixed Qt::*_ordering <> std::*_ordering types
+ {
+ static_assert(Qt::strong_ordering::less == std::partial_ordering::less);
+ static_assert(Qt::strong_ordering::less != std::partial_ordering::greater);
+ static_assert(Qt::strong_ordering::equal == std::weak_ordering::equivalent);
+ static_assert(Qt::strong_ordering::equivalent != std::weak_ordering::less);
+
+ static_assert(Qt::weak_ordering::less != std::partial_ordering::greater);
+ static_assert(Qt::weak_ordering::less == std::partial_ordering::less);
+ static_assert(Qt::weak_ordering::equivalent == std::strong_ordering::equivalent);
+ static_assert(Qt::weak_ordering::equivalent != std::strong_ordering::less);
+
+ static_assert(Qt::partial_ordering::less != std::weak_ordering::greater);
+ static_assert(Qt::partial_ordering::less == std::weak_ordering::less);
+ static_assert(Qt::partial_ordering::equivalent == std::strong_ordering::equivalent);
+ static_assert(Qt::partial_ordering::equivalent != std::strong_ordering::less);
+ }
+#endif
+
+}
+
+void tst_QCompare::is_eq_overloads()
+{
+#ifndef __cpp_lib_three_way_comparison
+ QSKIP("This test requires C++20 three-way-comparison support enabled in the stdlib.");
+#else
+ constexpr auto u = std::partial_ordering::unordered;
+ constexpr auto l = std::weak_ordering::less;
+ constexpr auto g = std::strong_ordering::greater;
+ constexpr auto e = std::weak_ordering::equivalent;
+ constexpr auto s = std::strong_ordering::equal;
+
+ // This is a compile-time check that unqualified name lookup of
+ // std::is_eq-like functions isn't ambiguous, so we can recommend it to our
+ // users for minimizing porting on the way to C++20.
+
+ // The goal is to check each std::ordering and each is_eq function at least
+ // once, not to test all combinations (we're not the stdlib test suite here).
+
+ QVERIFY(is_eq(s));
+ QVERIFY(is_neq(u));
+ QVERIFY(is_lt(l));
+ QVERIFY(is_gt(g));
+ QVERIFY(is_lteq(e));
+ QVERIFY(is_gteq(s));
+#endif // __cpp_lib_three_way_comparison
+}
+
+class StringWrapper
+{
+public:
+ explicit StringWrapper() {}
+ explicit StringWrapper(const QString &val) : m_val(val) {}
+ QString value() const { return m_val; }
+
+private:
+ static Qt::weak_ordering compareHelper(const QString &lhs, const QString &rhs) noexcept
+ {
+ const int res = QString::compare(lhs, rhs, Qt::CaseInsensitive);
+ if (res < 0)
+ return Qt::weak_ordering::less;
+ else if (res > 0)
+ return Qt::weak_ordering::greater;
+ else
+ return Qt::weak_ordering::equivalent;
+ }
+
+ friend bool comparesEqual(const StringWrapper &lhs, const StringWrapper &rhs) noexcept
+ { return QString::compare(lhs.m_val, rhs.m_val, Qt::CaseInsensitive) == 0; }
+ friend Qt::weak_ordering
+ compareThreeWay(const StringWrapper &lhs, const StringWrapper &rhs) noexcept
+ { return compareHelper(lhs.m_val, rhs.m_val); }
+ Q_DECLARE_WEAKLY_ORDERED(StringWrapper)
+
+ // these helper functions are intentionally non-noexcept
+ friend bool comparesEqual(const StringWrapper &lhs, int rhs)
+ { return comparesEqual(lhs, StringWrapper(QString::number(rhs))); }
+ friend Qt::weak_ordering compareThreeWay(const StringWrapper &lhs, int rhs)
+ { return compareHelper(lhs.m_val, QString::number(rhs)); }
+ Q_DECLARE_WEAKLY_ORDERED(StringWrapper, int)
+
+ QString m_val;
+};
+
+void tst_QCompare::compareThreeWay()
+{
+ // test noexcept
+
+ // for custom types
+ static_assert(noexcept(qCompareThreeWay(std::declval<StringWrapper>(),
+ std::declval<StringWrapper>())));
+ static_assert(!noexcept(qCompareThreeWay(std::declval<StringWrapper>(),
+ std::declval<int>())));
+ static_assert(!noexcept(qCompareThreeWay(std::declval<int>(),
+ std::declval<StringWrapper>())));
+ // for built-in types
+ static_assert(noexcept(qCompareThreeWay(std::declval<int>(), std::declval<int>())));
+ static_assert(noexcept(qCompareThreeWay(std::declval<float>(), std::declval<int>())));
+ static_assert(noexcept(qCompareThreeWay(std::declval<double>(), std::declval<float>())));
+ static_assert(noexcept(qCompareThreeWay(std::declval<int>(), std::declval<int>())));
+
+ // enums
+ enum TestEnum : int {
+ Smaller,
+ Bigger
+ };
+ static_assert(noexcept(qCompareThreeWay(std::declval<TestEnum>(), std::declval<TestEnum>())));
+
+ // pointers
+ static_assert(noexcept(qCompareThreeWay(std::declval<StringWrapper *>(),
+ std::declval<StringWrapper *>())));
+ static_assert(noexcept(qCompareThreeWay(std::declval<StringWrapper *>(), nullptr)));
+
+ // Test some actual comparison results
+
+ // for custom types
+ QCOMPARE_EQ(qCompareThreeWay(StringWrapper("ABC"), StringWrapper("abc")),
+ Qt::weak_ordering::equivalent);
+ QVERIFY(StringWrapper("ABC") == StringWrapper("abc"));
+ QCOMPARE_EQ(qCompareThreeWay(StringWrapper("ABC"), StringWrapper("qwe")),
+ Qt::weak_ordering::less);
+ QVERIFY(StringWrapper("ABC") != StringWrapper("qwe"));
+ QCOMPARE_EQ(qCompareThreeWay(StringWrapper("qwe"), StringWrapper("ABC")),
+ Qt::weak_ordering::greater);
+ QVERIFY(StringWrapper("qwe") != StringWrapper("ABC"));
+ QCOMPARE_EQ(qCompareThreeWay(StringWrapper("10"), 10), Qt::weak_ordering::equivalent);
+ QVERIFY(StringWrapper("10") == 10);
+ QCOMPARE_EQ(qCompareThreeWay(StringWrapper("10"), 12), Qt::weak_ordering::less);
+ QVERIFY(StringWrapper("10") != 12);
+ QCOMPARE_EQ(qCompareThreeWay(StringWrapper("12"), 10), Qt::weak_ordering::greater);
+ QVERIFY(StringWrapper("12") != 10);
+
+ // reversed compareThreeWay()
+ auto result = qCompareThreeWay(10, StringWrapper("12"));
+ QCOMPARE_EQ(result, Qt::weak_ordering::less);
+ static_assert(std::is_same_v<decltype(result), Qt::weak_ordering>);
+ QVERIFY(10 != StringWrapper("12"));
+ result = qCompareThreeWay(12, StringWrapper("10"));
+ QCOMPARE_EQ(result, Qt::weak_ordering::greater);
+ static_assert(std::is_same_v<decltype(result), Qt::weak_ordering>);
+ QVERIFY(12 != StringWrapper("10"));
+ result = qCompareThreeWay(10, StringWrapper("10"));
+ QCOMPARE_EQ(result, Qt::weak_ordering::equivalent);
+ static_assert(std::is_same_v<decltype(result), Qt::weak_ordering>);
+ QVERIFY(10 == StringWrapper("10"));
+
+ // built-in types
+ QCOMPARE_EQ(qCompareThreeWay(1, 1.0), Qt::partial_ordering::equivalent);
+ QCOMPARE_EQ(qCompareThreeWay(1, 2), Qt::strong_ordering::less);
+ QCOMPARE_EQ(qCompareThreeWay(2.0f, 1.0), Qt::partial_ordering::greater);
+
+ // enums
+ QCOMPARE_EQ(qCompareThreeWay(Smaller, Bigger), Qt::strong_ordering::less);
+
+ // pointers
+ std::array<int, 2> arr{1, 0};
+ QCOMPARE_EQ(qCompareThreeWay(&arr[1], &arr[0]), Qt::strong_ordering::greater);
+ QCOMPARE_EQ(qCompareThreeWay(arr.data(), &arr[0]), Qt::strong_ordering::equivalent);
+}
+
QTEST_MAIN(tst_QCompare)
#include "tst_qcompare.moc"
diff --git a/tests/auto/corelib/global/qcomparehelpers/CMakeLists.txt b/tests/auto/corelib/global/qcomparehelpers/CMakeLists.txt
new file mode 100644
index 0000000000..4bfdccdf86
--- /dev/null
+++ b/tests/auto/corelib/global/qcomparehelpers/CMakeLists.txt
@@ -0,0 +1,39 @@
+# 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_qcomparehelpers LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qcomparehelpers
+ SOURCES
+ tst_qcomparehelpers.h tst_qcomparehelpers.cpp tst_qcomparehelpers1.cpp
+ wrappertypes.h
+ LIBRARIES
+ Qt::TestPrivate
+)
+
+# CMake recognizes CXX_STANDARD=23 only starting from version 3.20
+# macOS has some issues with concepts, see QTBUG-117765
+if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.20" AND NOT MACOS AND NOT VXWORKS AND NOT (LINUX AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
+ qt_internal_add_test(tst_qcomparehelpers_cpp23
+ SOURCES
+ tst_qcomparehelpers.h tst_qcomparehelpers.cpp tst_qcomparehelpers1.cpp
+ wrappertypes.h
+ DEFINES
+ tst_QCompareHelpers=tst_QCompareHelpersCpp23
+ LIBRARIES
+ Qt::TestPrivate
+ )
+
+ # Try to build this test in C++23 mode to test std::float16_t support.
+ # Use CXX_STANDARD_REQUIRED OFF, so that we just fall back to C++17 if the
+ # compiler does not support C++23.
+ set_target_properties(tst_qcomparehelpers_cpp23
+ PROPERTIES
+ CXX_STANDARD 23
+ CXX_STANDARD_REQUIRED OFF
+ )
+endif()
diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp
new file mode 100644
index 0000000000..f140c23ed0
--- /dev/null
+++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp
@@ -0,0 +1,600 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "tst_qcomparehelpers.h"
+#include "wrappertypes.h"
+
+#if defined(__STDCPP_FLOAT16_T__) && __has_include(<stdfloat>)
+#include <stdfloat>
+#endif
+
+/*
+ NOTE: Do not add any other test cases to this cpp file!
+ minGW already complains about a too large tst_qcomparehelpers.cpp.obj
+ object file.
+
+ Create a new cpp file and add new tests there.
+*/
+
+template<typename LeftType, typename RightType, typename OrderingType>
+void tst_QCompareHelpers::compareImpl()
+{
+ QFETCH(LeftType, lhs);
+ QFETCH(RightType, rhs);
+ QFETCH(OrderingType, expectedOrdering);
+
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expectedOrdering);
+#ifdef __cpp_lib_three_way_comparison
+ // Also check std types.
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, QtOrderingPrivate::to_std(expectedOrdering));
+#endif // __cpp_lib_three_way_comparison
+}
+
+template<typename LeftType, typename RightType>
+void tst_QCompareHelpers::compareIntData()
+{
+ QTest::addColumn<LeftType>("lhs");
+ QTest::addColumn<RightType>("rhs");
+ QTest::addColumn<Qt::strong_ordering>("expectedOrdering");
+
+ auto createRow = [](auto lhs, auto rhs, Qt::strong_ordering ordering) {
+ QTest::addRow("%d vs %d", lhs, rhs) << LeftType(lhs) << RightType(rhs) << ordering;
+ };
+
+ createRow(0, 0, Qt::strong_ordering::equivalent);
+ createRow(-1, 0, Qt::strong_ordering::less);
+ createRow(1, 0, Qt::strong_ordering::greater);
+ constexpr int max = std::numeric_limits<int>::max();
+ constexpr int min = std::numeric_limits<int>::min();
+ createRow(max, max, Qt::strong_ordering::equivalent);
+ createRow(min, min, Qt::strong_ordering::equivalent);
+ createRow(max, min, Qt::strong_ordering::greater);
+ createRow(min, max, Qt::strong_ordering::less);
+}
+
+template<typename LeftType, typename RightType>
+void tst_QCompareHelpers::compareFloatData()
+{
+ QTest::addColumn<LeftType>("lhs");
+ QTest::addColumn<RightType>("rhs");
+ QTest::addColumn<Qt::partial_ordering>("expectedOrdering");
+
+ auto createRow = [](auto lhs, auto rhs, Qt::partial_ordering ordering) {
+ QTest::addRow("%f vs %f", lhs, rhs) << LeftType(lhs) << RightType(rhs) << ordering;
+ };
+
+ createRow(0.0, 0.0, Qt::partial_ordering::equivalent);
+ createRow(-0.000001, 0.0, Qt::partial_ordering::less);
+ createRow(0.000001, 0.0, Qt::partial_ordering::greater);
+
+ const double nan = qQNaN();
+ createRow(nan, 0.0, Qt::partial_ordering::unordered);
+ createRow(0.0, nan, Qt::partial_ordering::unordered);
+ createRow(nan, nan, Qt::partial_ordering::unordered);
+
+ const double inf = qInf();
+ createRow(inf, 0.0, Qt::partial_ordering::greater);
+ createRow(0.0, inf, Qt::partial_ordering::less);
+ createRow(-inf, 0.0, Qt::partial_ordering::less);
+ createRow(0.0, -inf, Qt::partial_ordering::greater);
+ createRow(inf, inf, Qt::partial_ordering::equivalent);
+ createRow(-inf, -inf, Qt::partial_ordering::equivalent);
+ createRow(-inf, inf, Qt::partial_ordering::less);
+ createRow(inf, -inf, Qt::partial_ordering::greater);
+
+ createRow(nan, inf, Qt::partial_ordering::unordered);
+ createRow(inf, nan, Qt::partial_ordering::unordered);
+ createRow(nan, -inf, Qt::partial_ordering::unordered);
+ createRow(-inf, nan, Qt::partial_ordering::unordered);
+}
+
+template<typename LeftType, typename RightType>
+void tst_QCompareHelpers::compareStringData()
+{
+ QTest::addColumn<LeftType>("lhs");
+ QTest::addColumn<RightType>("rhs");
+ QTest::addColumn<Qt::weak_ordering>("expectedOrdering");
+
+ auto createRow = [](auto lhs, auto rhs, Qt::weak_ordering ordering) {
+ QTest::addRow("'%s' vs '%s'", lhs, rhs) << LeftType(lhs) << RightType(rhs) << ordering;
+ };
+
+ createRow("", "", Qt::weak_ordering::equivalent);
+ createRow("Ab", "abc", Qt::weak_ordering::less);
+ createRow("aBc", "AB", Qt::weak_ordering::greater);
+ createRow("ab", "AB", Qt::weak_ordering::equivalent);
+ createRow("ABC", "abc", Qt::weak_ordering::equivalent);
+}
+
+void tst_QCompareHelpers::comparisonCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<IntWrapper>();
+ if (QTest::currentTestFailed())
+ return;
+
+ QTestPrivate::testAllComparisonOperatorsCompile<IntWrapper, int>();
+ if (QTest::currentTestFailed())
+ return;
+
+ QTestPrivate::testAllComparisonOperatorsCompile<DoubleWrapper>();
+ if (QTest::currentTestFailed())
+ return;
+
+ QTestPrivate::testAllComparisonOperatorsCompile<DoubleWrapper, double>();
+ if (QTest::currentTestFailed())
+ return;
+
+ QTestPrivate::testAllComparisonOperatorsCompile<DoubleWrapper, IntWrapper>();
+ if (QTest::currentTestFailed())
+ return;
+
+ QTestPrivate::testAllComparisonOperatorsCompile<StringWrapper<QString>>();
+ if (QTest::currentTestFailed())
+ return;
+
+ QTestPrivate::testAllComparisonOperatorsCompile<StringWrapper<QString>, QAnyStringView>();
+ if (QTest::currentTestFailed())
+ return;
+}
+
+void tst_QCompareHelpers::compare_IntWrapper_data()
+{
+ compareIntData<IntWrapper, IntWrapper>();
+}
+
+void tst_QCompareHelpers::compare_IntWrapper()
+{
+ compareImpl<IntWrapper, IntWrapper, Qt::strong_ordering>();
+}
+
+void tst_QCompareHelpers::compare_IntWrapper_int_data()
+{
+ compareIntData<IntWrapper, int>();
+}
+
+void tst_QCompareHelpers::compare_IntWrapper_int()
+{
+ compareImpl<IntWrapper, int, Qt::strong_ordering>();
+}
+
+void tst_QCompareHelpers::compare_DoubleWrapper_data()
+{
+ compareFloatData<DoubleWrapper, DoubleWrapper>();
+}
+
+void tst_QCompareHelpers::compare_DoubleWrapper()
+{
+ compareImpl<DoubleWrapper, DoubleWrapper, Qt::partial_ordering>();
+}
+
+void tst_QCompareHelpers::compare_DoubleWrapper_double_data()
+{
+ compareFloatData<DoubleWrapper, double>();
+}
+
+void tst_QCompareHelpers::compare_DoubleWrapper_double()
+{
+ compareImpl<DoubleWrapper, double, Qt::partial_ordering>();
+}
+
+void tst_QCompareHelpers::compare_IntWrapper_DoubleWrapper_data()
+{
+ QTest::addColumn<IntWrapper>("lhs");
+ QTest::addColumn<DoubleWrapper>("rhs");
+ QTest::addColumn<Qt::partial_ordering>("expectedOrdering");
+
+ auto createRow = [](auto lhs, auto rhs, Qt::partial_ordering ordering) {
+ QTest::addRow("%d vs %f", lhs, rhs) << IntWrapper(lhs) << DoubleWrapper(rhs) << ordering;
+ };
+
+ createRow(0, 0.0, Qt::partial_ordering::equivalent);
+ createRow(-1, 0.0, Qt::partial_ordering::less);
+ createRow(1, 0.0, Qt::partial_ordering::greater);
+ createRow(0, -0.000001, Qt::partial_ordering::greater);
+ createRow(0, 0.000001, Qt::partial_ordering::less);
+
+ constexpr int max = std::numeric_limits<int>::max();
+ constexpr int min = std::numeric_limits<int>::min();
+ const double nan = qQNaN();
+ createRow(0, nan, Qt::partial_ordering::unordered);
+ createRow(max, nan, Qt::partial_ordering::unordered);
+ createRow(min, nan, Qt::partial_ordering::unordered);
+
+ const double inf = qInf();
+ createRow(0, inf, Qt::partial_ordering::less);
+ createRow(0, -inf, Qt::partial_ordering::greater);
+ createRow(max, inf, Qt::partial_ordering::less);
+ createRow(max, -inf, Qt::partial_ordering::greater);
+ createRow(min, inf, Qt::partial_ordering::less);
+ createRow(min, -inf, Qt::partial_ordering::greater);
+}
+
+void tst_QCompareHelpers::compare_IntWrapper_DoubleWrapper()
+{
+ compareImpl<IntWrapper, DoubleWrapper, Qt::partial_ordering>();
+}
+
+void tst_QCompareHelpers::compare_StringWrapper_data()
+{
+ compareStringData<StringWrapper<QString>, StringWrapper<QString>>();
+}
+
+void tst_QCompareHelpers::compare_StringWrapper()
+{
+ compareImpl<StringWrapper<QString>, StringWrapper<QString>, Qt::weak_ordering>();
+}
+
+void tst_QCompareHelpers::compare_StringWrapper_AnyStringView_data()
+{
+ compareStringData<StringWrapper<QString>, QAnyStringView>();
+}
+
+void tst_QCompareHelpers::compare_StringWrapper_AnyStringView()
+{
+ compareImpl<StringWrapper<QString>, QAnyStringView, Qt::weak_ordering>();
+}
+
+#define DECLARE_TYPE(Name, Type, Attrs, RetType, Constexpr, Suffix) \
+class Dummy ## Name \
+{ \
+public: \
+ Constexpr Dummy ## Name () {} \
+\
+private: \
+ friend Attrs Constexpr bool \
+ comparesEqual(const Dummy ## Name &lhs, const Dummy ## Name &rhs) noexcept; \
+ friend Attrs Constexpr RetType \
+ compareThreeWay(const Dummy ## Name &lhs, const Dummy ## Name &rhs) noexcept; \
+ friend Attrs Constexpr bool \
+ comparesEqual(const Dummy ## Name &lhs, int rhs) noexcept; \
+ friend Attrs Constexpr RetType \
+ compareThreeWay(const Dummy ## Name &lhs, int rhs) noexcept; \
+ Q_DECLARE_ ## Type ##_ORDERED ## Suffix (Dummy ## Name) \
+ Q_DECLARE_ ## Type ##_ORDERED ## Suffix (Dummy ## Name, int) \
+}; \
+\
+Attrs Constexpr bool comparesEqual(const Dummy ## Name &lhs, const Dummy ## Name &rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return true; } \
+Attrs Constexpr RetType \
+compareThreeWay(const Dummy ## Name &lhs, const Dummy ## Name &rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return RetType::equivalent; } \
+Attrs Constexpr bool comparesEqual(const Dummy ## Name &lhs, int rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return true; } \
+Attrs Constexpr RetType compareThreeWay(const Dummy ## Name &lhs, int rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return RetType::equivalent; }
+
+DECLARE_TYPE(PartialConstAttr, PARTIALLY, Q_DECL_PURE_FUNCTION, Qt::partial_ordering, constexpr,
+ _LITERAL_TYPE)
+DECLARE_TYPE(PartialConst, PARTIALLY, /* no attrs */, Qt::partial_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(PartialAttr, PARTIALLY, Q_DECL_CONST_FUNCTION, Qt::partial_ordering, , )
+DECLARE_TYPE(Partial, PARTIALLY, /* no attrs */, Qt::partial_ordering, , )
+
+DECLARE_TYPE(WeakConstAttr, WEAKLY, Q_DECL_PURE_FUNCTION, Qt::weak_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(WeakConst, WEAKLY, /* no attrs */, Qt::weak_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(WeakAttr, WEAKLY, Q_DECL_CONST_FUNCTION, Qt::weak_ordering, , )
+DECLARE_TYPE(Weak, WEAKLY, /* no attrs */, Qt::weak_ordering, , )
+
+DECLARE_TYPE(StrongConstAttr, STRONGLY, Q_DECL_PURE_FUNCTION, Qt::strong_ordering, constexpr,
+ _LITERAL_TYPE)
+DECLARE_TYPE(StrongConst, STRONGLY, /* no attrs */, Qt::strong_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(StrongAttr, STRONGLY, Q_DECL_CONST_FUNCTION, Qt::strong_ordering, , )
+DECLARE_TYPE(Strong, STRONGLY, /* no attrs */, Qt::strong_ordering, , )
+
+#define DECLARE_EQUALITY_COMPARABLE(Name, Attrs, Constexpr, Suffix) \
+class Dummy ## Name \
+{ \
+public: \
+ Constexpr Dummy ## Name (int) {} \
+\
+private: \
+ friend Attrs Constexpr bool \
+ comparesEqual(const Dummy ## Name &lhs, const Dummy ## Name &rhs) noexcept; \
+ friend Attrs Constexpr bool comparesEqual(const Dummy ## Name &lhs, int rhs) noexcept; \
+ Q_DECLARE_EQUALITY_COMPARABLE ## Suffix (Dummy ## Name) \
+ Q_DECLARE_EQUALITY_COMPARABLE ## Suffix (Dummy ## Name, int) \
+}; \
+\
+Attrs Constexpr bool comparesEqual(const Dummy ## Name &lhs, const Dummy ## Name &rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return true; } \
+Attrs Constexpr bool comparesEqual(const Dummy ## Name &lhs, int rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return true; } \
+
+DECLARE_EQUALITY_COMPARABLE(ConstAttr, Q_DECL_PURE_FUNCTION, constexpr, _LITERAL_TYPE)
+DECLARE_EQUALITY_COMPARABLE(Const, /* no attrs */, constexpr, _LITERAL_TYPE)
+DECLARE_EQUALITY_COMPARABLE(Attr, Q_DECL_CONST_FUNCTION, , )
+DECLARE_EQUALITY_COMPARABLE(None, /* no attrs */, , )
+
+void tst_QCompareHelpers::generatedClasses()
+{
+#define COMPARE(ClassName) \
+ do { \
+ QTestPrivate::testAllComparisonOperatorsCompile<ClassName>(); \
+ QTestPrivate::testAllComparisonOperatorsCompile<ClassName, int>(); \
+ } while (0)
+
+ COMPARE(DummyPartialConstAttr);
+ COMPARE(DummyPartialConst);
+ COMPARE(DummyPartialAttr);
+ COMPARE(DummyPartial);
+
+ COMPARE(DummyWeakConstAttr);
+ COMPARE(DummyWeakConst);
+ COMPARE(DummyWeakAttr);
+ COMPARE(DummyWeak);
+
+ COMPARE(DummyStrongConstAttr);
+ COMPARE(DummyStrongConst);
+ COMPARE(DummyStrongAttr);
+ COMPARE(DummyStrong);
+#undef COMPARE
+
+ QTestPrivate::testEqualityOperatorsCompile<DummyConstAttr>();
+ QTestPrivate::testEqualityOperatorsCompile<DummyConstAttr, int>();
+
+ QTestPrivate::testEqualityOperatorsCompile<DummyConst>();
+ QTestPrivate::testEqualityOperatorsCompile<DummyConst, int>();
+
+ QTestPrivate::testEqualityOperatorsCompile<DummyAttr>();
+ QTestPrivate::testEqualityOperatorsCompile<DummyAttr, int>();
+
+ QTestPrivate::testEqualityOperatorsCompile<DummyNone>();
+ QTestPrivate::testEqualityOperatorsCompile<DummyNone, int>();
+}
+
+template <typename LeftType, typename RightType,
+ Qt::if_integral<LeftType> = true,
+ Qt::if_integral<RightType> = true>
+void testOrderForTypes()
+{
+ LeftType l0{0};
+ LeftType l1{1};
+ RightType r0{0};
+ RightType r1{1};
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, r1), Qt::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, r0), Qt::strong_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, r1), Qt::strong_ordering::equivalent);
+ // also swap types
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, l0), Qt::strong_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(r0, l1), Qt::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, l1), Qt::strong_ordering::equivalent);
+
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, r1), std::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, r0), std::strong_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, r1), std::strong_ordering::equivalent);
+
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, l0), std::strong_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(r0, l1), std::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, l1), std::strong_ordering::equivalent);
+#endif // __cpp_lib_three_way_comparison
+
+ if constexpr (std::is_signed_v<LeftType>) {
+ LeftType lm1{-1};
+ QCOMPARE_EQ(Qt::compareThreeWay(lm1, r1), Qt::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, lm1), Qt::strong_ordering::greater);
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(Qt::compareThreeWay(lm1, r1), std::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, lm1), std::strong_ordering::greater);
+#endif // __cpp_lib_three_way_comparison
+ }
+ if constexpr (std::is_signed_v<RightType>) {
+ RightType rm1{-1};
+ QCOMPARE_EQ(Qt::compareThreeWay(rm1, l1), Qt::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, rm1), Qt::strong_ordering::greater);
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(Qt::compareThreeWay(rm1, l1), std::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, rm1), std::strong_ordering::greater);
+#endif // __cpp_lib_three_way_comparison
+ }
+}
+
+template <typename LeftType, typename RightType,
+ Qt::if_floating_point<LeftType> = true,
+ Qt::if_floating_point<RightType> = true>
+void testOrderForTypes()
+{
+ constexpr auto lNeg = LeftType(-1);
+ constexpr auto lPos = LeftType( 1);
+
+ constexpr auto rNeg = RightType(-1);
+ constexpr auto rPos = RightType( 1);
+
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rPos), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(lPos, rNeg), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNeg, lPos), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(rPos, lNeg), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rNeg), Qt::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNeg, lNeg), Qt::partial_ordering::equivalent);
+
+ LeftType lNaN{std::numeric_limits<LeftType>::quiet_NaN()};
+ LeftType lInf{std::numeric_limits<LeftType>::infinity()};
+
+ RightType rNaN{std::numeric_limits<RightType>::quiet_NaN()};
+ RightType rInf{std::numeric_limits<RightType>::infinity()};
+
+ QCOMPARE_EQ(Qt::compareThreeWay(lNaN, rPos), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNeg, lNaN), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rNaN), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, lPos), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, lNaN), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNaN, rNaN), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNaN, rInf), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, -lInf), Qt::partial_ordering::unordered);
+
+ QCOMPARE_EQ(Qt::compareThreeWay(lInf, rPos), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(rPos, lInf), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(rInf, lNeg), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rInf), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(lInf, -rInf), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(-lInf, rInf), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(-rInf, lInf), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(rInf, -lInf), Qt::partial_ordering::greater);
+
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rPos), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(lPos, rNeg), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNeg, lPos), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(rPos, lNeg), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rNeg), std::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNeg, lNeg), std::partial_ordering::equivalent);
+
+ QCOMPARE_EQ(Qt::compareThreeWay(lNaN, rPos), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNeg, lNaN), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rNaN), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, lPos), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, lNaN), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNaN, rNaN), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNaN, rInf), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, -lInf), std::partial_ordering::unordered);
+
+ QCOMPARE_EQ(Qt::compareThreeWay(lInf, rPos), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(rPos, lInf), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(rInf, lNeg), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rInf), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(lInf, -rInf), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(-lInf, rInf), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(-rInf, lInf), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(rInf, -lInf), std::partial_ordering::greater);
+#endif // __cpp_lib_three_way_comparison
+}
+
+template <typename IntType, typename FloatType,
+ Qt::if_integral<IntType> = true,
+ Qt::if_floating_point<FloatType> = true>
+void testOrderForTypes()
+{
+ IntType l0{0};
+ IntType l1{1};
+
+ constexpr FloatType r0{0};
+ constexpr FloatType r1{1};
+ FloatType rNaN{std::numeric_limits<FloatType>::quiet_NaN()};
+
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, r1), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, r0), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, l0), Qt::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(r0, l1), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, r0), Qt::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(r0, l0), Qt::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, rNaN), Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, l1), Qt::partial_ordering::unordered);
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, r1), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l1, r0), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(r1, l0), std::partial_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(r0, l1), std::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, r0), std::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(r0, l0), std::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(l0, rNaN), std::partial_ordering::unordered);
+ QCOMPARE_EQ(Qt::compareThreeWay(rNaN, l1), std::partial_ordering::unordered);
+#endif // __cpp_lib_three_way_comparison
+}
+
+enum class TestEnum : quint8 {
+ Smaller,
+ Bigger
+};
+
+void tst_QCompareHelpers::builtinOrder()
+{
+#define TEST_BUILTIN(Left, Right) \
+ testOrderForTypes<Left, Right>(); \
+ if (QTest::currentTestFailed()) { \
+ qDebug("Failed Qt::compareThreeWay() test for builtin types " #Left " and " #Right); \
+ return; \
+ }
+
+ // some combinations
+ TEST_BUILTIN(char, char)
+#if CHAR_MIN < 0
+ TEST_BUILTIN(char, short)
+ TEST_BUILTIN(qint8, char)
+#else
+ TEST_BUILTIN(char, ushort)
+ TEST_BUILTIN(quint8, char)
+#endif
+ TEST_BUILTIN(qint8, qint8)
+ TEST_BUILTIN(qint8, int)
+ TEST_BUILTIN(ulong, quint8)
+ TEST_BUILTIN(ushort, uchar)
+ TEST_BUILTIN(int, int)
+ TEST_BUILTIN(uint, ulong)
+ TEST_BUILTIN(long, int)
+ TEST_BUILTIN(uint, quint64)
+ TEST_BUILTIN(qint64, short)
+ TEST_BUILTIN(wchar_t, wchar_t)
+ TEST_BUILTIN(uint, char16_t)
+ TEST_BUILTIN(char32_t, char32_t)
+ TEST_BUILTIN(char32_t, ushort)
+#ifdef __cpp_char8_t
+ TEST_BUILTIN(char8_t, char8_t)
+ TEST_BUILTIN(char8_t, ushort)
+ TEST_BUILTIN(char8_t, uint)
+ TEST_BUILTIN(char8_t, quint64)
+#endif // __cpp_char8_t
+#ifdef QT_SUPPORTS_INT128
+ TEST_BUILTIN(qint128, qint128)
+ TEST_BUILTIN(quint128, quint128)
+ TEST_BUILTIN(qint128, int)
+ TEST_BUILTIN(ushort, quint128)
+#endif
+ TEST_BUILTIN(float, double)
+ TEST_BUILTIN(double, float)
+ TEST_BUILTIN(quint64, float)
+ TEST_BUILTIN(qint64, double)
+#ifdef __STDCPP_FLOAT16_T__
+ TEST_BUILTIN(std::float16_t, std::float16_t)
+ TEST_BUILTIN(std::float16_t, double)
+ TEST_BUILTIN(qint64, std::float16_t)
+ TEST_BUILTIN(uint, std::float16_t)
+#endif
+ TEST_BUILTIN(long double, long double)
+ TEST_BUILTIN(float, long double)
+ TEST_BUILTIN(double, long double)
+ TEST_BUILTIN(quint64, long double)
+ TEST_BUILTIN(ushort, long double)
+
+#if QFLOAT16_IS_NATIVE
+ {
+ // Cannot use TEST_BUILTIN here, because std::numeric_limits are not defined
+ // for QtPrivate::NativeFloat16Type.
+ constexpr auto smaller = QtPrivate::NativeFloat16Type(1);
+ constexpr auto bigger = QtPrivate::NativeFloat16Type(2);
+ // native vs native
+ QCOMPARE_EQ(Qt::compareThreeWay(smaller, smaller), Qt::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(smaller, bigger), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(bigger, smaller), Qt::partial_ordering::greater);
+ // native vs float
+ QCOMPARE_EQ(Qt::compareThreeWay(smaller, 1.0f), Qt::partial_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(1.0f, bigger), Qt::partial_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(bigger, 1.0f), Qt::partial_ordering::greater);
+ const auto floatNaN = std::numeric_limits<float>::quiet_NaN();
+ QCOMPARE_EQ(Qt::compareThreeWay(bigger, floatNaN), Qt::partial_ordering::unordered);
+ }
+#endif
+
+ QCOMPARE_EQ(Qt::compareThreeWay(TestEnum::Smaller, TestEnum::Bigger),
+ Qt::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(TestEnum::Bigger, TestEnum::Smaller),
+ Qt::strong_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(TestEnum::Smaller, TestEnum::Smaller),
+ Qt::strong_ordering::equivalent);
+
+ std::array<int, 2> arr{1, 0};
+ QCOMPARE_EQ(Qt::compareThreeWay(&arr[0], &arr[1]), Qt::strong_ordering::less);
+ QCOMPARE_EQ(Qt::compareThreeWay(arr.data(), &arr[0]), Qt::strong_ordering::equivalent);
+
+ class Base {};
+ class Derived : public Base {};
+
+ auto b = std::make_unique<Base>();
+ auto d = std::make_unique<Derived>();
+ QCOMPARE_NE(Qt::compareThreeWay(b.get(), d.get()), Qt::strong_ordering::equivalent);
+ QCOMPARE_EQ(Qt::compareThreeWay(b.get(), nullptr), Qt::strong_ordering::greater);
+ QCOMPARE_EQ(Qt::compareThreeWay(nullptr, d.get()), Qt::strong_ordering::less);
+
+#undef TEST_BUILTIN
+}
+
+QTEST_MAIN(tst_QCompareHelpers)
+#include "tst_qcomparehelpers.moc"
diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h
new file mode 100644
index 0000000000..16398b0978
--- /dev/null
+++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef TST_QCOMPAREHELPERS_H
+#define TST_QCOMPAREHELPERS_H
+
+#include <QtCore/qcompare.h>
+
+#include <QtTest/qtest.h>
+#include <QtTest/private/qcomparisontesthelper_p.h>
+
+class tst_QCompareHelpers : public QObject
+{
+ Q_OBJECT
+
+private:
+ template <typename LeftType, typename RightType, typename OrderingType>
+ void compareImpl();
+
+ template <typename LeftType, typename RightType>
+ void compareIntData();
+
+ template <typename LeftType, typename RightType>
+ void compareFloatData();
+
+ template <typename LeftType, typename RightType>
+ void compareStringData();
+
+private Q_SLOTS:
+ // tst_qcomparehelpers.cpp
+ void comparisonCompiles();
+
+ void compare_IntWrapper_data();
+ void compare_IntWrapper();
+
+ void compare_IntWrapper_int_data();
+ void compare_IntWrapper_int();
+
+ void compare_DoubleWrapper_data();
+ void compare_DoubleWrapper();
+
+ void compare_DoubleWrapper_double_data();
+ void compare_DoubleWrapper_double();
+
+ void compare_IntWrapper_DoubleWrapper_data();
+ void compare_IntWrapper_DoubleWrapper();
+
+ void compare_StringWrapper_data();
+ void compare_StringWrapper();
+
+ void compare_StringWrapper_AnyStringView_data();
+ void compare_StringWrapper_AnyStringView();
+
+ void generatedClasses();
+
+ void builtinOrder();
+
+ // Add new test cases to tst_qcomparehelpers1.cpp, because minGW already
+ // complains about a too large tst_qcomparehelpers.cpp.obj object file
+ void compareWithAttributes();
+};
+
+#endif // TST_QCOMPAREHELPERS_H
diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp
new file mode 100644
index 0000000000..a3b8200a63
--- /dev/null
+++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp
@@ -0,0 +1,59 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "tst_qcomparehelpers.h"
+
+#define DECLARE_TYPE(Name, Type, RetType, Constexpr, Suffix) \
+class Deprecated ## Name \
+{ \
+public: \
+ Constexpr Deprecated ## Name () {} \
+\
+private: \
+ friend Constexpr bool \
+ comparesEqual(const Deprecated ## Name &lhs, int rhs) noexcept; \
+ friend Constexpr RetType \
+ compareThreeWay(const Deprecated ## Name &lhs, int rhs) noexcept; \
+ Q_DECLARE_ ## Type ## _ORDERED ## Suffix (Deprecated ## Name, int, \
+ Q_DECL_DEPRECATED_X("This op is deprecated")) \
+}; \
+\
+Constexpr bool comparesEqual(const Deprecated ## Name &lhs, int rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return true; } \
+Constexpr RetType compareThreeWay(const Deprecated ## Name &lhs, int rhs) noexcept \
+{ Q_UNUSED(lhs); Q_UNUSED(rhs); return RetType::equivalent; }
+
+DECLARE_TYPE(PartialConst, PARTIALLY, Qt::partial_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(Partial, PARTIALLY, Qt::partial_ordering, , )
+DECLARE_TYPE(WeakConst, WEAKLY, Qt::weak_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(Weak, WEAKLY, Qt::weak_ordering, , )
+DECLARE_TYPE(StrongConst, STRONGLY, Qt::strong_ordering, constexpr, _LITERAL_TYPE)
+DECLARE_TYPE(Strong, STRONGLY, Qt::strong_ordering, , )
+
+#undef DECLARE_TYPE
+
+void tst_QCompareHelpers::compareWithAttributes()
+{
+ // All these comparisons would trigger deprecation warnings.
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+
+#define COMPARE(ClassName) \
+ do { \
+ ClassName c; \
+ QCOMPARE_EQ(c, 0); \
+ QCOMPARE_LE(c, 0); \
+ QCOMPARE_GE(0, c); \
+ } while (false)
+
+ COMPARE(DeprecatedPartialConst);
+ COMPARE(DeprecatedPartial);
+ COMPARE(DeprecatedWeakConst);
+ COMPARE(DeprecatedWeak);
+ COMPARE(DeprecatedStrongConst);
+ COMPARE(DeprecatedStrong);
+
+#undef COMPARE
+
+QT_WARNING_POP
+}
diff --git a/tests/auto/corelib/global/qcomparehelpers/wrappertypes.h b/tests/auto/corelib/global/qcomparehelpers/wrappertypes.h
new file mode 100644
index 0000000000..1dd221a8b0
--- /dev/null
+++ b/tests/auto/corelib/global/qcomparehelpers/wrappertypes.h
@@ -0,0 +1,116 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef TST_QCOMPAREHELPERS_WRAPPERTYPES_H
+#define TST_QCOMPAREHELPERS_WRAPPERTYPES_H
+
+#include <QtCore/qanystringview.h>
+#include <QtCore/qcompare.h>
+
+class IntWrapper
+{
+public:
+ // implicit constructor and operator int() to simulate the case that
+ // triggers a bug on MSVC < 19.36.
+ IntWrapper(int val) : m_val(val) {}
+ operator int() const noexcept { return m_val; }
+
+ int value() const { return m_val; }
+
+private:
+ friend bool comparesEqual(const IntWrapper &lhs, const IntWrapper &rhs) noexcept
+ { return lhs.m_val == rhs.m_val; }
+ friend Qt::strong_ordering
+ compareThreeWay(const IntWrapper &lhs, const IntWrapper &rhs) noexcept
+ {
+ return Qt::compareThreeWay(lhs.m_val, rhs.m_val);
+ }
+ friend bool comparesEqual(const IntWrapper &lhs, int rhs) noexcept
+ { return lhs.m_val == rhs; }
+ friend Qt::strong_ordering compareThreeWay(const IntWrapper &lhs, int rhs) noexcept
+ { return compareThreeWay(lhs, IntWrapper(rhs)); }
+
+ Q_DECLARE_STRONGLY_ORDERED(IntWrapper)
+ Q_DECLARE_STRONGLY_ORDERED(IntWrapper, int)
+
+ int m_val = 0;
+};
+
+class DoubleWrapper
+{
+public:
+ explicit DoubleWrapper(double val) : m_val(val) {}
+ double value() const { return m_val; }
+
+private:
+ friend bool comparesEqual(const DoubleWrapper &lhs, const DoubleWrapper &rhs) noexcept
+ { return lhs.m_val == rhs.m_val; }
+ friend Qt::partial_ordering
+ compareThreeWay(const DoubleWrapper &lhs, const DoubleWrapper &rhs) noexcept
+ {
+ return Qt::compareThreeWay(lhs.m_val, rhs.m_val);
+ }
+ friend bool comparesEqual(const DoubleWrapper &lhs, const IntWrapper &rhs) noexcept
+ { return comparesEqual(lhs, DoubleWrapper(rhs.value())); }
+ friend Qt::partial_ordering
+ compareThreeWay(const DoubleWrapper &lhs, const IntWrapper &rhs) noexcept
+ { return compareThreeWay(lhs, DoubleWrapper(rhs.value())); }
+ friend bool comparesEqual(const DoubleWrapper &lhs, double rhs) noexcept
+ { return lhs.m_val == rhs; }
+ friend Qt::partial_ordering compareThreeWay(const DoubleWrapper &lhs, double rhs) noexcept
+ {
+ return Qt::compareThreeWay(lhs.m_val, rhs);
+ }
+
+ Q_DECLARE_PARTIALLY_ORDERED(DoubleWrapper)
+ Q_DECLARE_PARTIALLY_ORDERED(DoubleWrapper, IntWrapper)
+ Q_DECLARE_PARTIALLY_ORDERED(DoubleWrapper, double)
+
+ double m_val = 0.0;
+};
+
+template <typename String>
+class StringWrapper
+{
+public:
+ explicit StringWrapper(String val) : m_val(val) {}
+ String value() const { return m_val; }
+
+private:
+ static bool equalsHelper(QAnyStringView lhs, QAnyStringView rhs) noexcept
+ { return QAnyStringView::compare(lhs, rhs, Qt::CaseInsensitive) == 0; }
+
+ static Qt::weak_ordering compareHelper(QAnyStringView lhs, QAnyStringView rhs) noexcept
+ {
+ const int res = QAnyStringView::compare(lhs, rhs, Qt::CaseInsensitive);
+ if (res < 0)
+ return Qt::weak_ordering::less;
+ else if (res > 0)
+ return Qt::weak_ordering::greater;
+ else
+ return Qt::weak_ordering::equivalent;
+ }
+
+ // Some of the helper functions are intentionally NOT marked as noexcept
+ // to test the conditional noexcept in the macros.
+ template <typename T>
+ friend bool comparesEqual(const StringWrapper<T> &lhs, const StringWrapper<T> &rhs) noexcept
+ { return StringWrapper<T>::equalsHelper(lhs.m_val, rhs.m_val); }
+ template <typename T>
+ friend Qt::weak_ordering
+ compareThreeWay(const StringWrapper<T> &lhs, const StringWrapper<T> &rhs) noexcept
+ { return StringWrapper<T>::compareHelper(lhs.m_val, rhs.m_val); }
+ template <typename T>
+ friend bool comparesEqual(const StringWrapper<T> &lhs, QAnyStringView rhs)
+ { return StringWrapper<T>::equalsHelper(lhs.m_val, rhs); }
+ template <typename T>
+ friend Qt::weak_ordering compareThreeWay(const StringWrapper<T> &lhs, QAnyStringView rhs)
+ { return StringWrapper<T>::compareHelper(lhs.m_val, rhs); }
+
+ Q_DECLARE_WEAKLY_ORDERED(StringWrapper)
+ Q_DECLARE_WEAKLY_ORDERED(StringWrapper, QAnyStringView)
+
+ String m_val;
+};
+
+#endif // TST_QCOMPAREHELPERS_WRAPPERTYPES_H
diff --git a/tests/auto/corelib/global/qflags/CMakeLists.txt b/tests/auto/corelib/global/qflags/CMakeLists.txt
index 54853bf792..8b01ea774f 100644
--- a/tests/auto/corelib/global/qflags/CMakeLists.txt
+++ b/tests/auto/corelib/global/qflags/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qflags Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qflags LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qflags
SOURCES
tst_qflags.cpp
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp
index f267fc4497..d226e8d6b4 100644
--- a/tests/auto/corelib/global/qflags/tst_qflags.cpp
+++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp
@@ -1,5 +1,5 @@
// 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
#ifdef QFLAGS_TEST_NO_TYPESAFE_FLAGS
# ifdef QT_TYPESAFE_FLAGS
@@ -301,7 +301,7 @@ Q_DECLARE_FLAGS( MyStrictNoOpFlags, MyStrictNoOpEnum )
static_assert( !QTypeInfo<MyStrictFlags>::isComplex );
static_assert( QTypeInfo<MyStrictFlags>::isRelocatable );
-static_assert( !QTypeInfo<MyStrictFlags>::isPointer );
+static_assert( !std::is_pointer_v<MyStrictFlags> );
void tst_QFlags::classEnum()
{
@@ -475,7 +475,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags )
static_assert( !QTypeInfo<MyFlags>::isComplex );
static_assert( QTypeInfo<MyFlags>::isRelocatable );
-static_assert( !QTypeInfo<MyFlags>::isPointer );
+static_assert( !std::is_pointer_v<MyFlags> );
QTEST_MAIN(tst_QFlags)
#include "tst_qflags.moc"
diff --git a/tests/auto/corelib/global/qfloat16/CMakeLists.txt b/tests/auto/corelib/global/qfloat16/CMakeLists.txt
index f880112f31..f6ca52b0df 100644
--- a/tests/auto/corelib/global/qfloat16/CMakeLists.txt
+++ b/tests/auto/corelib/global/qfloat16/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qfloat16.pro.
-
#####################################################################
## tst_qfloat16 Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfloat16 LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qfloat16
SOURCES
tst_qfloat16.cpp
diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
index e61ceff1c0..7acf8c2cf6 100644
--- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
+++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
@@ -1,9 +1,13 @@
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2016 by Southwest Research Institute (R)
-// 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 <QFloat16>
+#include <QMetaType>
+#include <QTextStream>
+
+#include <private/qcomparisontesthelper_p.h>
#include <math.h>
@@ -16,6 +20,10 @@ class tst_qfloat16: public QObject
Q_OBJECT
private slots:
+ void compareCompiles();
+ void relationalOperatorsAreConstexpr();
+ void ordering_data();
+ void ordering();
void fuzzyCompare_data();
void fuzzyCompare();
void fuzzyIsNull_data();
@@ -41,8 +49,180 @@ private slots:
void properties();
void limits();
void mantissaOverflow();
+ void dataStream();
+ void textStream();
};
+void tst_qfloat16::compareCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, float>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, double>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, long double>();
+#if QFLOAT16_IS_NATIVE
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, qfloat16::NativeType>();
+#endif
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, int>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, qint8>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, quint8>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, qint16>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, quint16>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, char16_t>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, long>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, unsigned long>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, wchar_t>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, qint32>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, quint32>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, qint64>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, quint64>();
+#ifdef QT_SUPPORTS_INT128
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, qint128>();
+ QTestPrivate::testAllComparisonOperatorsCompile<qfloat16, quint128>();
+#endif
+}
+
+void tst_qfloat16::relationalOperatorsAreConstexpr()
+{
+#if QFLOAT16_IS_NATIVE
+
+#define CHECK_CONSTEXPR(Type) \
+ do { \
+ constexpr qfloat16 lhs = qfloat16(0.0f); \
+ constexpr Type rhs = 1; \
+ static_assert(lhs < rhs); \
+ static_assert(rhs >= lhs); \
+ } while (false)
+
+ CHECK_CONSTEXPR(qfloat16);
+ CHECK_CONSTEXPR(float);
+ CHECK_CONSTEXPR(double);
+ CHECK_CONSTEXPR(long double);
+ CHECK_CONSTEXPR(qfloat16::NativeType);
+ CHECK_CONSTEXPR(qint8);
+ CHECK_CONSTEXPR(quint8);
+ CHECK_CONSTEXPR(qint16);
+ CHECK_CONSTEXPR(quint16);
+ CHECK_CONSTEXPR(qint32);
+ CHECK_CONSTEXPR(quint32);
+ CHECK_CONSTEXPR(long);
+ CHECK_CONSTEXPR(unsigned long);
+ CHECK_CONSTEXPR(qint64);
+ CHECK_CONSTEXPR(quint64);
+#ifdef QT_SUPPORTS_INT128
+ CHECK_CONSTEXPR(qint128);
+ CHECK_CONSTEXPR(quint128);
+#endif
+
+#undef CHECK_CONSTEXPR
+
+#else
+ QSKIP("This check is only relevant for native float16 types");
+#endif // QFLOAT16_IS_NATIVE
+}
+
+void tst_qfloat16::ordering_data()
+{
+ QTest::addColumn<float>("left");
+ QTest::addColumn<float>("right");
+
+ auto row = [](float left, float right) {
+ QTest::addRow("%f_vs_%f", left, right) << left << right;
+ };
+
+ row(0.0f, 0.0f);
+ row(0.000001f, 0.0f);
+ row(0.0f, 0.000001f);
+ row(-1.000001f, 1.000001f);
+ const float nan = std::numeric_limits<float>::quiet_NaN();
+ const float inf = std::numeric_limits<float>::infinity();
+ row(nan, nan);
+ row(nan, inf);
+ row(inf, nan);
+ row(-inf, nan);
+ row(nan, -inf);
+ row(-inf, inf);
+ row(inf, -inf);
+ row(-inf, 0.0f);
+ row(0.0f, inf);
+ row(0.0f, nan);
+ row(nan, 0.0f);
+ row(2.0f, 314.159f);
+ row(-314.159f, 2.0f);
+ row(-2.0f, 314.159f);
+ row(nan, 314.159f);
+ row(-314.159f, inf);
+ row(-inf, 314.159f);
+ row(2.0f, -inf);
+ row(-2.0f, nan);
+ row(-inf, -2.0f);
+ // testing with values outside qfloat16 range
+ row(0.0f, 13e5f);
+ // generateRow(inf, 13e5f); // fails qfloat16 vs qfloat16 and qfloat16 vs int (QTBUG-118193)
+ row(0.0f, -13e5f);
+ // generateRow(-inf, -13e5f); // fails qfloat16 vs qfloat16 and qfloat16 vs int (QTBUG-118193)
+}
+
+void tst_qfloat16::ordering()
+{
+ QFETCH(float, left);
+ QFETCH(float, right);
+
+ const auto expectedOrder = Qt::compareThreeWay(left, right);
+ const auto lhs = qfloat16(left);
+
+#define POSTCHECK(msg) \
+ if (QTest::currentTestFailed()) { qDebug(msg); return; }
+
+#define CHECK_FP(RHS) \
+ do { \
+ QTestPrivate::testAllComparisonOperators(lhs, static_cast<RHS>(right), expectedOrder); \
+ POSTCHECK("qfloat16 vs " #RHS " comparison failed") \
+ } while (false) \
+ /* END */
+
+ CHECK_FP(qfloat16);
+ CHECK_FP(float);
+ CHECK_FP(double);
+ CHECK_FP(long double);
+
+#undef CHECK_FP
+
+#define CHECK_INT(RHS) \
+ do { \
+ const auto rhs = static_cast<RHS>(right); \
+ const auto expectedRes = Qt::compareThreeWay(left, rhs); \
+ QTestPrivate::testAllComparisonOperators(lhs, rhs, expectedRes); \
+ POSTCHECK("qfloat16 vs " #RHS " comparison failed") \
+ } while (false) \
+ /* END */
+
+ if (qIsFinite(right)) {
+ CHECK_INT(int);
+ CHECK_INT(qint8);
+ CHECK_INT(signed char);
+ CHECK_INT(qint16);
+ CHECK_INT(qint32);
+ CHECK_INT(qint64);
+#if QT_SUPPORTS_INT128
+ CHECK_INT(qint128);
+#endif
+ if (right >= 0) {
+ CHECK_INT(unsigned int);
+ CHECK_INT(quint8);
+ CHECK_INT(unsigned char);
+ CHECK_INT(quint16);
+ CHECK_INT(quint32);
+ CHECK_INT(quint64);
+ #if QT_SUPPORTS_INT128
+ CHECK_INT(quint128);
+ #endif
+ }
+ }
+
+#undef CHECK_INT
+#undef POSTCHECK
+}
+
void tst_qfloat16::fuzzyCompare_data()
{
QTest::addColumn<qfloat16>("val1");
@@ -301,7 +481,7 @@ void tst_qfloat16::promotionTests()
QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)*1));
QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)/1));
- QCOMPARE(QString::number(1.f),QString::number(qfloat16(1.f)));
+ QCOMPARE(QString::number(1.f),QString::number(double(qfloat16(1.f))));
}
void tst_qfloat16::arithOps_data()
@@ -624,12 +804,67 @@ void tst_qfloat16::mantissaOverflow()
float f;
memcpy(&f, &in, 4);
- qfloat16 f16 = f;
+ qfloat16 f16 = qfloat16(f);
qfloat16 f16s[1];
qFloatToFloat16(f16s, &f, 1);
QCOMPARE(f16, f16s[0]);
QVERIFY(qIsNaN(f16));
}
+void tst_qfloat16::dataStream()
+{
+ QByteArray ba;
+ QDataStream ds(&ba, QIODevice::ReadWrite);
+ ds << qfloat16(1.5) << qfloat16(-1);
+ QCOMPARE(ba.size(), 4);
+ QCOMPARE(ds.status(), QDataStream::Ok);
+ QCOMPARE(ba, QByteArray("\x3e\0\xbc\0", 4));
+
+ ds.device()->seek(0);
+ ds.resetStatus();
+ ds.setByteOrder(QDataStream::LittleEndian);
+ ds << qfloat16(0) << qfloat16(-1);
+ QCOMPARE(ds.status(), QDataStream::Ok);
+ QCOMPARE(ba, QByteArray("\0\0\0\xbc", 4));
+
+ ds.device()->seek(0);
+ ds.resetStatus();
+ qfloat16 zero = 1;
+ ds >> zero;
+ QCOMPARE(ds.status(), QDataStream::Ok);
+ QCOMPARE(zero, qfloat16(0));
+
+ ds.device()->seek(0);
+ ds.resetStatus();
+ QMetaType mt = QMetaType(QMetaType::Float16);
+ QVERIFY(mt.save(ds, &zero));
+
+ ds.device()->seek(0);
+ ds.resetStatus();
+ zero = -1;
+ QVERIFY(mt.load(ds, &zero));
+ QCOMPARE(zero, qfloat16(0));
+}
+
+void tst_qfloat16::textStream()
+{
+ QString buffer;
+ {
+ QTextStream ts(&buffer);
+ ts << qfloat16(0) << Qt::endl << qfloat16(1.5);
+ QCOMPARE(ts.status(), QTextStream::Ok);
+ }
+ QCOMPARE(buffer, "0\n1.5");
+
+ {
+ QTextStream ts(&buffer);
+ qfloat16 zero = qfloat16(-2.5), threehalves = 1234;
+ ts >> zero >> threehalves;
+ QCOMPARE(ts.status(), QTextStream::Ok);
+ QCOMPARE(zero, qfloat16(0));
+ QCOMPARE(threehalves, 1.5);
+ }
+}
+
QTEST_APPLESS_MAIN(tst_qfloat16)
#include "tst_qfloat16.moc"
diff --git a/tests/auto/corelib/global/qgetputenv/CMakeLists.txt b/tests/auto/corelib/global/qgetputenv/CMakeLists.txt
index 3ad6c04d51..f1a5cbeef3 100644
--- a/tests/auto/corelib/global/qgetputenv/CMakeLists.txt
+++ b/tests/auto/corelib/global/qgetputenv/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qgetputenv.pro.
-
#####################################################################
## tst_qgetputenv Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qgetputenv LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qgetputenv
SOURCES
tst_qgetputenv.cpp
diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
index 832319a652..96f2ce853c 100644
--- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
+++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.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 <qdebug.h>
#include <QTest>
diff --git a/tests/auto/corelib/global/qglobal/CMakeLists.txt b/tests/auto/corelib/global/qglobal/CMakeLists.txt
index 028cf0cf3e..5a0877663b 100644
--- a/tests/auto/corelib/global/qglobal/CMakeLists.txt
+++ b/tests/auto/corelib/global/qglobal/CMakeLists.txt
@@ -1,16 +1,22 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qglobal.pro.
-
#####################################################################
## tst_qglobal Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qglobal LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qglobal
SOURCES
qglobal.c
tst_qglobal.cpp
+ NO_PCH_SOURCES
+ tst_qglobal.cpp # undef QT_NO_FOREACH
)
## Scopes:
diff --git a/tests/auto/corelib/global/qglobal/qglobal.c b/tests/auto/corelib/global/qglobal/qglobal.c
index 64569f4de7..2cfbd5e3be 100644
--- a/tests/auto/corelib/global/qglobal/qglobal.c
+++ b/tests/auto/corelib/global/qglobal/qglobal.c
@@ -1,8 +1,10 @@
// Copyright (C) 2017 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 <QtCore/qglobal.h>
-#include <QtCore/qlibraryinfo.h>
+#include <QtCore/qtversion.h>
+#include <QtCore/qyieldcpu.h>
+#include <QtCore/qtypes.h>
#ifdef Q_COMPILER_THREAD_LOCAL
# include <threads.h>
@@ -13,6 +15,11 @@
* everything works.
*/
+#if defined(Q_OS_VXWORKS) && !defined(thread_local)
+// threads.h forgot to define this (should be fixed for version 23.11)
+# define thread_local _Thread_local
+#endif
+
/* Types and Q_UNUSED */
void tst_GlobalTypes()
{
@@ -44,8 +51,20 @@ void tst_GlobalTypes()
qintptr qip;
quintptr qup;
Q_UNUSED(qs); Q_UNUSED(qp); Q_UNUSED(qip); Q_UNUSED(qup);
+
+#ifdef QT_SUPPORTS_INT128
+ qint128 s128;
+ quint128 u128;
+ Q_UNUSED(s128); Q_UNUSED(u128);
+#endif /* QT_SUPPORTS_INT128 */
}
+#if QT_SUPPORTS_INT128
+qint128 tst_qint128_min() { return Q_INT128_MIN + 0; }
+qint128 tst_qint128_max() { return 0 + Q_INT128_MAX; }
+quint128 tst_quint128_max() { return Q_UINT128_MAX - 1 + 1; }
+#endif
+
/* Qt version */
int tst_QtVersion()
{
@@ -62,6 +81,12 @@ const char *tst_qVersion()
#endif
}
+void tst_qYieldCpu(void) Q_DECL_NOEXCEPT;
+void tst_qYieldCpu(void)
+{
+ qYieldCpu();
+}
+
/* Static assertion */
Q_STATIC_ASSERT(true);
Q_STATIC_ASSERT(1);
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
index 4b0b97de0b..1a19048bbe 100644
--- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
+++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
@@ -1,16 +1,20 @@
// 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!
+
#include <QTest>
#include <QPair>
#include <QSysInfo>
#include <QLatin1String>
#include <QString>
-#include <QLibraryInfo>
+#include <QtVersion>
#include <cmath>
+#include <limits>
+#include <type_traits>
class tst_QGlobal: public QObject
{
@@ -28,6 +32,7 @@ private slots:
void qCoreAppStartupFunction();
void qCoreAppStartupFunctionRestart();
void integerForSize();
+ void int128Literals();
void buildAbiEndianness();
void testqOverload();
void testqMinMax();
@@ -37,12 +42,19 @@ private slots:
void qRoundDoubles();
void PRImacros();
void testqToUnderlying();
+ void nodiscard();
};
extern "C" { // functions in qglobal.c
void tst_GlobalTypes();
int tst_QtVersion();
const char *tst_qVersion();
+#if QT_SUPPORTS_INT128
+qint128 tst_qint128_min();
+qint128 tst_qint128_max();
+quint128 tst_quint128_max();
+#endif
+
}
void tst_QGlobal::cMode()
@@ -421,11 +433,166 @@ void tst_QGlobal::integerForSize()
static_assert(sizeof(QIntegerForSize<2>::Signed) == 2);
static_assert(sizeof(QIntegerForSize<4>::Signed) == 4);
static_assert(sizeof(QIntegerForSize<8>::Signed) == 8);
+#ifdef QT_SUPPORTS_INT128
+ static_assert(sizeof(QIntegerForSize<16>::Signed) == 16);
+#endif
static_assert(sizeof(QIntegerForSize<1>::Unsigned) == 1);
static_assert(sizeof(QIntegerForSize<2>::Unsigned) == 2);
static_assert(sizeof(QIntegerForSize<4>::Unsigned) == 4);
static_assert(sizeof(QIntegerForSize<8>::Unsigned) == 8);
+#ifdef QT_SUPPORTS_INT128
+ static_assert(sizeof(QIntegerForSize<16>::Unsigned) == 16);
+#endif
+}
+
+void tst_QGlobal::int128Literals()
+{
+#ifdef QT_SUPPORTS_INT128
+#define COMPARE_EQ(lhs, rhs, Expected128) do { \
+ constexpr auto lhs_ = lhs; \
+ static_assert(std::is_same_v<std::remove_cv_t<decltype(lhs_)>, Expected128>); \
+ QCOMPARE_EQ(lhs_, rhs); \
+ } while (0)
+ COMPARE_EQ(Q_INT128_MIN, std::numeric_limits<qint128>::min(), qint128);
+ COMPARE_EQ(Q_INT128_MAX, std::numeric_limits<qint128>::max(), qint128);
+ COMPARE_EQ(Q_UINT128_MAX, std::numeric_limits<quint128>::max(), quint128);
+ QCOMPARE_EQ(tst_qint128_min(), Q_INT128_MIN);
+ QCOMPARE_EQ(tst_qint128_max(), Q_INT128_MAX);
+ QCOMPARE_EQ(tst_quint128_max(), Q_UINT128_MAX);
+ {
+ #define CHECK_S(x) COMPARE_EQ(Q_INT128_C(x), Q_INT64_C(x), qint128)
+ #define CHECK_U(x) COMPARE_EQ(Q_UINT128_C(x), Q_UINT64_C(x), quint128);
+ #define CHECK(x) do { CHECK_S(x); CHECK_U(x); } while (0)
+ // basics:
+ CHECK(0);
+ CHECK(1);
+ CHECK_S(-1);
+ QCOMPARE_EQ(Q_INT64_C(9223372036854775807), std::numeric_limits<qint64>::max());
+ CHECK(9223372036854775807); // LLONG_MAX
+ // Q_INT64_C(-9223372036854775808) gives -Wimplicitly-unsigned-literal on GCC, so use numeric_limits:
+ {
+ constexpr auto i = Q_INT128_C(-9223372036854775808); // LLONG_MIN
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ QCOMPARE_EQ(i, std::numeric_limits<qint64>::min());
+ }
+ // actual 128-bit numbers
+ {
+ constexpr auto i = Q_INT128_C( 9223372036854775808); // LLONG_MAX + 1
+ constexpr auto u = Q_UINT128_C(9223372036854775808); // LLONG_MAX + 1
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ static_assert(std::is_same_v<decltype(u), const quint128>);
+ QCOMPARE_EQ(i, qint128{ std::numeric_limits<qint64>::max()} + 1);
+ QCOMPARE_EQ(u, quint128{std::numeric_limits<qint64>::max()} + 1);
+ }
+ {
+ constexpr auto i = Q_INT128_C(-9223372036854775809); // LLONG_MIN - 1
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ QCOMPARE_EQ(i, qint128{std::numeric_limits<qint64>::min()} - 1);
+ }
+ {
+ constexpr auto i = Q_INT128_C( 18446744073709551616); // ULLONG_MAX + 1
+ constexpr auto u = Q_UINT128_C(18446744073709551616);
+ constexpr auto expected = qint128{1} << 64;
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ static_assert(std::is_same_v<decltype(expected), const qint128>);
+ static_assert(std::is_same_v<decltype(u), const quint128>);
+ QCOMPARE_EQ(i, expected);
+ QCOMPARE_EQ(u, quint128{expected});
+ }
+ {
+ // compilers don't let one write signed _MIN literals, so use MIN + 1:
+ // Q_INT128_C(-170141183460469231731687303715884105728) gives
+ // ERROR: ~~~ outside range of representable values of type qint128
+ // This is because the unary minus is technically speaking not part of
+ // the literal, but called on the result of the literal.
+ constexpr auto i = Q_INT128_C(-170141183460469231731687303715884105727); // 128-bit MIN + 1
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ QCOMPARE_EQ(i, std::numeric_limits<qint128>::min() + 1);
+ }
+ {
+ constexpr auto i = Q_INT128_C( 170141183460469231731687303715884105727); // MAX
+ constexpr auto u = Q_UINT128_C(340282366920938463463374607431768211455); // UMAX
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ static_assert(std::is_same_v<decltype(u), const quint128>);
+ QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
+ QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
+ QCOMPARE_EQ(u, Q_UINT128_C(-1));
+ }
+
+ // binary literals:
+ CHECK(0b0);
+ CHECK(0b1);
+ CHECK_S(-0b1);
+ CHECK(0b01);
+ CHECK(0b10);
+ CHECK(0b1'1); // with digit separator
+ CHECK(0b0111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111);
+ //bytes |---1---| |---2---| |---3---| |---4---| |---5---| |---6---| |---7---| |---8---|
+ {
+ // bytes: |---1---| |---2---| |---3---| |---4---| |---5---| |---6---| |---7---| |---8---| |---9---| |--10---| |--11---| |--12---| |--13---| |--14---| |--15---| |--16---|
+ constexpr auto i = Q_INT128_C( 0b0111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111);
+ constexpr auto u = Q_UINT128_C(0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111);
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ static_assert(std::is_same_v<decltype(u), const quint128>);
+ QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
+ QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
+ QCOMPARE_EQ(u, Q_UINT128_C(-0b1));
+ }
+
+ // octal literals:
+ CHECK(00);
+ CHECK(01);
+ CHECK(02);
+ CHECK(03);
+ CHECK(04);
+ CHECK(05);
+ CHECK(06);
+ CHECK(07);
+ CHECK_S(-01);
+ CHECK(010);
+ CHECK_S(-01'0); // with digit separator
+ CHECK(07'7777'7777'7777'7777'7777); // LLONG_MAX
+ {
+ // bits: 120| 108| 96| 84| 72| 60| 48| 36| 24| 12| 0|
+ constexpr auto i = Q_INT128_C( 0177'7777'7777'7777'7777'7777'7777'7777'7777'7777'7777);
+ constexpr auto u = Q_UINT128_C(0377'7777'7777'7777'7777'7777'7777'7777'7777'7777'7777);
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ static_assert(std::is_same_v<decltype(u), const quint128>);
+ QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
+ QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
+ QCOMPARE_EQ(u, Q_UINT128_C(-01));
+ }
+
+ // hex literals:
+ CHECK(0x0);
+ CHECK(0x1);
+ CHECK(0x9);
+ CHECK(0xA);
+ CHECK(0xB);
+ CHECK(0xC);
+ CHECK(0xD);
+ CHECK(0xE);
+ CHECK(0x0F);
+ CHECK(0x10);
+ CHECK_S(-0x1);
+ CHECK_S(-0x1'0); // with digit separator
+ CHECK(0x7FFF'FFFF'FFFF'FFFF);
+ {
+ constexpr auto i = Q_INT128_C( 0x7FFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF);
+ constexpr auto u = Q_UINT128_C(0xFFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF);
+ static_assert(std::is_same_v<decltype(i), const qint128>);
+ static_assert(std::is_same_v<decltype(u), const quint128>);
+ QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
+ QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
+ QCOMPARE_EQ(Q_UINT128_C(-1), u);
+ }
+ #undef CHECK
+ }
+#undef COMPARE_EQ
+#else
+ QSKIP("This test requires 128-bit integer support enabled in the compiler.");
+#endif
}
typedef QPair<const char *, const char *> stringpair;
@@ -691,5 +858,79 @@ void tst_QGlobal::testqToUnderlying()
QCOMPARE(qToUnderlying(EE2), 456UL);
}
+void tst_QGlobal::nodiscard()
+{
+ // Syntax-only test, just to make sure that the Q_NODISCARD_* compile
+ // on all platforms.
+ // Other code is just to silence all various compiler warnings about
+ // unused private members or methods.
+ class Test {
+ public:
+ Q_NODISCARD_CTOR_X("Why construct a Test instead of just passing the int through?")
+ explicit Test(int val) : m_val(val) {}
+ Q_NODISCARD_CTOR explicit Test(float val) : m_val(int(val)) {}
+
+ Q_NODISCARD_X("Why call get() if you don't use the returned value, hu?") // NOT idiomatic use!
+ int get() const { return m_val; }
+
+ private:
+ int m_val;
+ };
+
+ Test t{42};
+ QCOMPARE(t.get(), 42);
+ Test t2{42.0f};
+ QCOMPARE(t2.get(), 42);
+}
+
+QT_BEGIN_NAMESPACE
+
+// Compile-time typeinfo tests
+struct Complex1
+{
+ ~Complex1();
+};
+static_assert(QTypeInfo<Complex1>::isComplex);
+static_assert(!QTypeInfo<Complex1>::isRelocatable);
+
+struct Complex2
+{
+ Complex2(Complex2 &&);
+};
+static_assert(QTypeInfo<Complex2>::isComplex);
+static_assert(!QTypeInfo<Complex2>::isRelocatable);
+
+struct Complex3
+{
+ Complex3(int);
+};
+static_assert(QTypeInfo<Complex3>::isComplex);
+static_assert(QTypeInfo<Complex3>::isRelocatable);
+
+struct Relocatable1
+{
+ ~Relocatable1();
+};
+Q_DECLARE_TYPEINFO(Relocatable1, Q_RELOCATABLE_TYPE);
+static_assert(QTypeInfo<Relocatable1>::isComplex);
+static_assert(QTypeInfo<Relocatable1>::isRelocatable);
+
+struct Relocatable2
+{
+ Relocatable2(int);
+};
+Q_DECLARE_TYPEINFO(Relocatable2, Q_RELOCATABLE_TYPE);
+static_assert(QTypeInfo<Relocatable2>::isComplex);
+static_assert(QTypeInfo<Relocatable2>::isRelocatable);
+
+struct Trivial1
+{
+ int x[42];
+};
+static_assert(!QTypeInfo<Trivial1>::isComplex);
+static_assert(QTypeInfo<Trivial1>::isRelocatable);
+
+QT_END_NAMESPACE
+
QTEST_APPLESS_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"
diff --git a/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt b/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt
index 58f1c10397..6707e46dff 100644
--- a/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt
+++ b/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qglobalstatic.pro.
-
#####################################################################
## tst_qglobalstatic Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qglobalstatic LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qglobalstatic
EXCEPTIONS
SOURCES
diff --git a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp
index 4c5d0da638..b8836668f5 100644
--- a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp
+++ b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2016 Thiago Macieira <thiago@kde.org>
// 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 <QtCore/QThread>
#include <QTest>
diff --git a/tests/auto/corelib/global/qhooks/CMakeLists.txt b/tests/auto/corelib/global/qhooks/CMakeLists.txt
index f72e414572..2d2051015f 100644
--- a/tests/auto/corelib/global/qhooks/CMakeLists.txt
+++ b/tests/auto/corelib/global/qhooks/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qhooks.pro.
-
#####################################################################
## tst_qhooks Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhooks LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qhooks
SOURCES
tst_qhooks.cpp
diff --git a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp
index 26f628312b..efdd9d7da1 100644
--- a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp
+++ b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Volker Krause <volker.krause@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/global/qkeycombination/CMakeLists.txt b/tests/auto/corelib/global/qkeycombination/CMakeLists.txt
index 46c3e8a412..911eef7289 100644
--- a/tests/auto/corelib/global/qkeycombination/CMakeLists.txt
+++ b/tests/auto/corelib/global/qkeycombination/CMakeLists.txt
@@ -1,13 +1,19 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qkeycombination.pro.
-
#####################################################################
## tst_qkeycombination Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qkeycombination LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qkeycombination
SOURCES
tst_qkeycombination.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/global/qkeycombination/tst_qkeycombination.cpp b/tests/auto/corelib/global/qkeycombination/tst_qkeycombination.cpp
index 3091ed4129..9941f8e154 100644
--- a/tests/auto/corelib/global/qkeycombination/tst_qkeycombination.cpp
+++ b/tests/auto/corelib/global/qkeycombination/tst_qkeycombination.cpp
@@ -1,13 +1,15 @@
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@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 <QObject>
#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
class tst_QKeyCombination : public QObject
{
Q_OBJECT
private slots:
+ void compareCompiles();
void construction();
void operator_eq();
void operator_or();
@@ -24,6 +26,11 @@ constexpr auto bitwiseOr(T ... args)
return (... | ((int)args));
}
+void tst_QKeyCombination::compareCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QKeyCombination>();
+}
+
void tst_QKeyCombination::construction()
{
{
@@ -131,145 +138,125 @@ void tst_QKeyCombination::operator_eq()
// default
{
QKeyCombination a, b;
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
// key only
{
QKeyCombination a;
QKeyCombination b(Qt::Key_X);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::Key_Y);
QKeyCombination b;
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::Key_Y);
QKeyCombination b(Qt::Key_X);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::Key_F1);
QKeyCombination b(Qt::Key_F1);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
// modifier only
{
QKeyCombination a;
QKeyCombination b(Qt::CTRL);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::CTRL);
QKeyCombination b;
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::CTRL);
QKeyCombination b(Qt::SHIFT);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::CTRL);
QKeyCombination b(Qt::CTRL);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
{
QKeyCombination a(Qt::CTRL);
QKeyCombination b(Qt::ControlModifier);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
{
QKeyCombination a(Qt::ControlModifier);
QKeyCombination b(Qt::CTRL);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
{
QKeyCombination a(Qt::ControlModifier);
QKeyCombination b(Qt::ControlModifier);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
// key and modifier
{
QKeyCombination a(Qt::Key_A);
QKeyCombination b(Qt::SHIFT, Qt::Key_A);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::CTRL, Qt::Key_A);
QKeyCombination b(Qt::SHIFT, Qt::Key_A);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::SHIFT, Qt::Key_A);
QKeyCombination b(Qt::SHIFT, Qt::Key_A);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
{
QKeyCombination a(Qt::SHIFT, Qt::Key_A);
QKeyCombination b(Qt::SHIFT, Qt::Key_Escape);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::SHIFT, Qt::Key_A);
QKeyCombination b(Qt::ShiftModifier, Qt::Key_A);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
{
QKeyCombination a(Qt::SHIFT | Qt::CTRL, Qt::Key_A);
QKeyCombination b(Qt::ControlModifier | Qt::ShiftModifier, Qt::Key_A);
- QVERIFY(a == b);
- QVERIFY(!(a != b));
+ QT_TEST_EQUALITY_OPS(a, b, true);
}
// corner cases
{
QKeyCombination a(Qt::CTRL);
QKeyCombination b(Qt::Key_Control);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
{
QKeyCombination a(Qt::ALT);
QKeyCombination b(Qt::Key_Alt);
- QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QT_TEST_EQUALITY_OPS(a, b, false);
}
}
diff --git a/tests/auto/corelib/global/qlogging/BLACKLIST b/tests/auto/corelib/global/qlogging/BLACKLIST
index e2d930e37b..6cd7fc045d 100644
--- a/tests/auto/corelib/global/qlogging/BLACKLIST
+++ b/tests/auto/corelib/global/qlogging/BLACKLIST
@@ -1,9 +1,7 @@
[qMessagePattern:backtrace]
-# QTBUG-63915
-b2qt 64bit
+# QTBUG-121389
+b2qt 32bit
[qMessagePattern:backtrace depth,separator]
-# QTBUG-63915
-b2qt 64bit
-# QTBUG-85364
-b2qt cmake
+# QTBUG-121389
+b2qt 32bit
diff --git a/tests/auto/corelib/global/qlogging/CMakeLists.txt b/tests/auto/corelib/global/qlogging/CMakeLists.txt
index 00825c5526..b3c66aeb2e 100644
--- a/tests/auto/corelib/global/qlogging/CMakeLists.txt
+++ b/tests/auto/corelib/global/qlogging/CMakeLists.txt
@@ -1,9 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qlogging.pro.
-# This file is almost completely custom written
-# special case skip regeneration
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qlogging LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
qt_internal_add_executable(qlogging_helper
NO_INSTALL
@@ -24,6 +26,8 @@ qt_internal_add_test(tst_qlogging SOURCES tst_qlogging.cpp
HELPER_BINARY="${CMAKE_CURRENT_BINARY_DIR}/qlogging_helper"
)
+add_dependencies(tst_qlogging qlogging_helper)
+
qt_internal_add_test(tst_qmessagelogger SOURCES tst_qmessagelogger.cpp
DEFINES
QT_MESSAGELOGCONTEXT
diff --git a/tests/auto/corelib/global/qlogging/app/main.cpp b/tests/auto/corelib/global/qlogging/app/main.cpp
index 79d2dbcc92..e5b669e14f 100644
--- a/tests/auto/corelib/global/qlogging/app/main.cpp
+++ b/tests/auto/corelib/global/qlogging/app/main.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 <QCoreApplication>
#include <QLoggingCategory>
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index be27ab65b9..861e60e256 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -1,7 +1,7 @@
// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2022 Intel Corporation.
// Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.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 <qdebug.h>
#include <qglobal.h>
@@ -30,6 +30,8 @@ private slots:
#ifdef QT_BUILD_INTERNAL
void cleanupFuncinfo_data();
void cleanupFuncinfo();
+ void cleanupFuncinfoBad_data();
+ void cleanupFuncinfoBad();
#endif
void qMessagePattern_data();
@@ -166,9 +168,13 @@ public:
int operator%(int) { ADD("TestClass1::operator%"); return 0; }
int x;
int &operator++() { ADD("TestClass1::operator++"); return x; }
- int operator++(int) { ADD("TestClass1::operator++"); return 0; }
int &operator--() { ADD("TestClass1::operator--"); return x; }
- int operator--(int) { ADD("TestClass1::operator--"); return 0; }
+
+ // slightly different to avoid duplicate test rows
+#define ADD2(x) QTest::newRow(x ".postfix") << Q_FUNC_INFO << x;
+ int operator++(int) { ADD2("TestClass1::operator++"); return 0; }
+ int operator--(int) { ADD2("TestClass1::operator--"); return 0; }
+#undef ADD2
int nested_struct()
{
@@ -530,7 +536,7 @@ void tst_qmessagehandler::cleanupFuncinfo_data()
QTest::newRow("msvc_28")
<< "class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > *__thiscall TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > >::func_template1<class TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > >>(void)"
<< "TestClass2::func_template1";
- QTest::newRow("gcc_21")
+ QTest::newRow("gcc_28")
<< "T* TestClass2<T>::func_template1() [with S = TestClass2<std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > > >, T = std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > >]"
<< "TestClass2::func_template1";
@@ -599,6 +605,34 @@ void tst_qmessagehandler::cleanupFuncinfo_data()
<< "int TestClass1::operator>(int)"
<< "TestClass1::operator>";
+ QTest::newRow("gcc_40")
+ << "Polymorphic<void (*)(int)>::~Polymorphic()"
+ << "Polymorphic::~Polymorphic";
+
+ QTest::newRow("gcc_41")
+ << "function<void (int*)>()::S::f()"
+ << "function()::S::f";
+
+ QTest::newRow("msvc_41")
+ << "void `void function<void __cdecl(int *)>(void)'::`2'::S::f(void)"
+ << "function(void)'::`2'::S::f";
+
+ QTest::newRow("gcc_42")
+ << "function<Polymorphic<void (int*)> >()::S::f(Polymorphic<void (int*)>*)"
+ << "function()::S::f";
+
+ QTest::newRow("msvc_42")
+ << "void `void function<Polymorphic<void __cdecl(int *)> >(void)'::`2'::S::f(Polymorphic<void __cdecl(int *)> *)"
+ << "function(void)'::`2'::S::f";
+
+ QTest::newRow("gcc_lambda_1") << "main(int, char**)::<lambda()>"
+ << "main(int, char**)::<lambda()>";
+
+ QTest::newRow("gcc_lambda_with_auto_1")
+ << "SomeClass::someMethod(const QString&, const QString&)::<lambda(auto:57)> [with "
+ "auto:57 = QNetworkReply::NetworkError]"
+ << "SomeClass::someMethod(const QString&, const QString&)::<lambda(auto:57)>";
+
QTest::newRow("objc_1")
<< "-[SomeClass someMethod:withArguments:]"
<< "-[SomeClass someMethod:withArguments:]";
@@ -614,6 +648,14 @@ void tst_qmessagehandler::cleanupFuncinfo_data()
QTest::newRow("objc_4")
<< "__31-[SomeClass someMethodSchedulingBlock]_block_invoke"
<< "__31-[SomeClass someMethodSchedulingBlock]_block_invoke";
+
+ QTest::newRow("thunk-1")
+ << "non-virtual thunk to QFutureWatcherBasePrivate::postCallOutEvent(QFutureCallOutEvent const&)"
+ << "QFutureWatcherBasePrivate::postCallOutEvent";
+
+ QTest::newRow("thunk-2")
+ << "virtual thunk to std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()"
+ << "std::basic_iostream::~basic_iostream";
}
#endif
@@ -634,6 +676,41 @@ void tst_qmessagehandler::cleanupFuncinfo()
QEXPECT_FAIL("TestClass1::nested_struct_const", "Nested function processing is broken", Continue);
QTEST(QString::fromLatin1(result), "expected");
}
+
+void tst_qmessagehandler::cleanupFuncinfoBad_data()
+{
+ QTest::addColumn<QByteArray>("funcinfo");
+
+ auto addBadFrame = [i = 0](const char *symbol) mutable {
+ QTest::addRow("%d", ++i) << QByteArray(symbol);
+ };
+ addBadFrame("typeinfo for QEventLoop");
+ addBadFrame("typeinfo name for QtPrivate::ResultStoreBase");
+ addBadFrame("typeinfo name for ._anon_476");
+ addBadFrame("typeinfo name for std::__1::__function::__base<bool (void*, void*)>");
+ addBadFrame("vtable for BezierEase");
+ addBadFrame("vtable for Polymorphic<void ()>");
+ addBadFrame("vtable for Polymorphic<void (*)(int)>");
+ addBadFrame("TLS wrapper function for (anonymous namespace)::jitStacks");
+ addBadFrame("lcCheckIndex()::category");
+ addBadFrame("guard variable for lcEPDetach()::category");
+ addBadFrame("guard variable for QImageReader::read(QImage*)::disableNxImageLoading");
+ addBadFrame("VTT for std::__1::ostrstream");
+ addBadFrame("qIsRelocatable<(anonymous namespace)::Data>");
+ addBadFrame("qt_incomplete_metaTypeArray<(anonymous namespace)::qt_meta_stringdata_CLASSQNonContiguousByteDeviceIoDeviceImplENDCLASS_t, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, true> > >");
+ addBadFrame("f()::i");
+}
+
+void tst_qmessagehandler::cleanupFuncinfoBad()
+{
+ QFETCH(QByteArray, funcinfo);
+
+ // A corrupted stack trace may find non-sensical symbols that aren't
+ // functions. The result doesn't matter, so long as we don't crash or hang.
+
+ QByteArray result = qCleanupFuncinfo(funcinfo);
+ qDebug() << "Decode of" << funcinfo << "produced" << result;
+}
#endif
void tst_qmessagehandler::qMessagePattern_data()
@@ -716,38 +793,42 @@ void tst_qmessagehandler::qMessagePattern_data()
#define BACKTRACE_HELPER_NAME "qlogging_helper"
-#ifdef __GLIBC__
#ifdef QT_NAMESPACE
#define QT_NAMESPACE_STR QT_STRINGIFY(QT_NAMESPACE::)
#else
#define QT_NAMESPACE_STR ""
#endif
-#if QT_CONFIG(static)
- QSKIP("These test cases don't work with static Qt builds");
-#else
-#ifndef QT_NO_DEBUG
+#ifdef __GLIBC__
+# if QT_CONFIG(static)
+ // These test cases don't work with static Qt builds
+# elif !defined(Q_PROCESSOR_X86)
+ // On most RISC platforms, call frames do not have to be stored to the
+ // stack (the return pointer may be saved in any callee-saved register), so
+ // this test isn't reliable.
+# elif defined(QT_ASAN_ENABLED)
+ // These tests produce far more call frames under ASan
+# else
+# ifndef QT_NO_DEBUG
QList<QByteArray> expectedBacktrace = {
// MyClass::qt_static_metacall is explicitly marked as hidden in the
// Q_OBJECT macro hence the ?helper? frame
"[MyClass::myFunction|MyClass::mySlot1|?" BACKTRACE_HELPER_NAME "?|",
// QMetaObject::invokeMethodImpl calls internal function
- // (QMetaMethodPrivate::invokeImpl, at the tims of this writing), which
+ // (QMetaMethodPrivate::invokeImpl, at the time of this writing), which
// will usually show only as ?libQt6Core.so? or equivalent, so we skip
- // end of backtrace, actual message
"|" QT_NAMESPACE_STR "QMetaObject::invokeMethodImpl] from_a_function 34"
};
QTest::newRow("backtrace") << "[%{backtrace}] %{message}" << true << expectedBacktrace;
-#endif
+# endif
QTest::newRow("backtrace depth,separator") << "[%{backtrace depth=2 separator=\"\n\"}] %{message}" << true << (QList<QByteArray>()
<< "[MyClass::myFunction\nMyClass::mySlot1] from_a_function 34"
<< "[T::T\n");
-#endif // #if !QT_CONFIG(process)
+# endif // #if !QT_CONFIG(static)
#endif // #ifdef __GLIBC__
-
}
@@ -784,7 +865,7 @@ void tst_qmessagehandler::qMessagePattern()
QVERIFY(!output.isEmpty());
QCOMPARE(!output.contains("QT_MESSAGE_PATTERN"), valid);
- for (const QByteArray &e : qAsConst(expected)) {
+ for (const QByteArray &e : std::as_const(expected)) {
if (!output.contains(e)) {
// use QDebug so we get proper string escaping for the newlines
QString buf;
diff --git a/tests/auto/corelib/global/qlogging/tst_qmessagelogger.cpp b/tests/auto/corelib/global/qlogging/tst_qmessagelogger.cpp
index 4466c1b36b..9c6b9e275d 100644
--- a/tests/auto/corelib/global/qlogging/tst_qmessagelogger.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qmessagelogger.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 <qlogging.h>
#include <qloggingcategory.h>
diff --git a/tests/auto/corelib/global/qnativeinterface/CMakeLists.txt b/tests/auto/corelib/global/qnativeinterface/CMakeLists.txt
index bf41effc42..2c87e07b21 100644
--- a/tests/auto/corelib/global/qnativeinterface/CMakeLists.txt
+++ b/tests/auto/corelib/global/qnativeinterface/CMakeLists.txt
@@ -1,6 +1,12 @@
# 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_qnativeinterface LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qnativeinterface
SOURCES
tst_qnativeinterface.cpp
diff --git a/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp b/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp
index b7ec10df6c..602342770e 100644
--- a/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp
+++ b/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp
@@ -1,5 +1,5 @@
// 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>
diff --git a/tests/auto/corelib/global/qnumeric/CMakeLists.txt b/tests/auto/corelib/global/qnumeric/CMakeLists.txt
index 92e01fd99f..e53a096c92 100644
--- a/tests/auto/corelib/global/qnumeric/CMakeLists.txt
+++ b/tests/auto/corelib/global/qnumeric/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qnumeric.pro.
-
#####################################################################
## tst_qnumeric Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qnumeric LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qnumeric
SOURCES
tst_qnumeric.cpp
diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
index 03acf5c074..d21fabd74e 100644
--- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
+++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2022 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 <QTest>
@@ -91,7 +91,7 @@ void tst_QNumeric::fuzzyCompare_data()
QTest::addColumn<bool>("isEqual");
const F zero(0), one(1), ten(10);
const F huge = Fuzzy<F>::scale, tiny = one / huge;
- const F deci(.1), giga(1e9), nano(1e-9), big(1e7), small(1e-10);
+ const F deci(.1f), giga(1e9f), nano(1e-9f), big(1e7f), small(1e-10f);
QTest::newRow("zero") << zero << zero << true;
QTest::newRow("ten") << ten << ten << true;
@@ -321,8 +321,11 @@ void tst_QNumeric::classifyfp()
QCOMPARE(qFpClassify(inf), FP_INFINITE);
QCOMPARE(qFpClassify(-inf), FP_INFINITE);
+ QT_WARNING_PUSH;
+ QT_WARNING_DISABLE_MSVC(4056);
QCOMPARE(qFpClassify(huge * two), FP_INFINITE);
QCOMPARE(qFpClassify(huge * -two), FP_INFINITE);
+ QT_WARNING_POP;
QCOMPARE(qFpClassify(one), FP_NORMAL);
QCOMPARE(qFpClassify(huge), FP_NORMAL);
@@ -434,33 +437,33 @@ template <typename Int> static void addOverflow_template()
#define ADD_COMPARE_NONOVF(v1, v2, expected) \
do { \
- QCOMPARE(add_overflow(Int(v1), Int(v2), &r), false); \
+ QCOMPARE(qAddOverflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(r, Int(expected)); \
- QCOMPARE(add_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
+ QCOMPARE(qAddOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
QCOMPARE(r, Int(expected)); \
- QCOMPARE(add_overflow<v2>(Int(v1), &r), false); \
+ QCOMPARE(qAddOverflow<v2>(Int(v1), &r), false); \
QCOMPARE(r, Int(expected)); \
} while (false)
#define ADD_COMPARE_OVF(v1, v2) \
do { \
- QCOMPARE(add_overflow(Int(v1), Int(v2), &r), true); \
- QCOMPARE(add_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
- QCOMPARE(add_overflow<v2>(Int(v1), &r), true); \
+ QCOMPARE(qAddOverflow(Int(v1), Int(v2), &r), true); \
+ QCOMPARE(qAddOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
+ QCOMPARE(qAddOverflow<v2>(Int(v1), &r), true); \
} while (false)
#define SUB_COMPARE_NONOVF(v1, v2, expected) \
do { \
- QCOMPARE(sub_overflow(Int(v1), Int(v2), &r), false); \
+ QCOMPARE(qSubOverflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(r, Int(expected)); \
- QCOMPARE(sub_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
+ QCOMPARE(qSubOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
QCOMPARE(r, Int(expected)); \
- QCOMPARE(sub_overflow<v2>(Int(v1), &r), false); \
+ QCOMPARE(qSubOverflow<v2>(Int(v1), &r), false); \
QCOMPARE(r, Int(expected)); \
} while (false)
#define SUB_COMPARE_OVF(v1, v2) \
do { \
- QCOMPARE(sub_overflow(Int(v1), Int(v2), &r), true); \
- QCOMPARE(sub_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
- QCOMPARE(sub_overflow<v2>(Int(v1), &r), true); \
+ QCOMPARE(qSubOverflow(Int(v1), Int(v2), &r), true); \
+ QCOMPARE(qSubOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
+ QCOMPARE(qSubOverflow<v2>(Int(v1), &r), true); \
} while (false)
// basic values
@@ -611,18 +614,18 @@ template <typename Int> static void mulOverflow_template()
#define MUL_COMPARE_NONOVF(v1, v2, expected) \
do { \
- QCOMPARE(mul_overflow(Int(v1), Int(v2), &r), false); \
+ QCOMPARE(qMulOverflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(r, Int(expected)); \
- QCOMPARE(mul_overflow(Int(v1), (std::integral_constant<Int, v2>()), &r), false); \
+ QCOMPARE(qMulOverflow(Int(v1), (std::integral_constant<Int, v2>()), &r), false); \
QCOMPARE(r, Int(expected)); \
- QCOMPARE(mul_overflow<v2>(Int(v1), &r), false); \
+ QCOMPARE(qMulOverflow<v2>(Int(v1), &r), false); \
QCOMPARE(r, Int(expected)); \
} while (false);
#define MUL_COMPARE_OVF(v1, v2) \
do { \
- QCOMPARE(mul_overflow(Int(v1), Int(v2), &r), true); \
- QCOMPARE(mul_overflow(Int(v1), (std::integral_constant<Int, v2>()), &r), true); \
- QCOMPARE(mul_overflow<v2>(Int(v1), &r), true); \
+ QCOMPARE(qMulOverflow(Int(v1), Int(v2), &r), true); \
+ QCOMPARE(qMulOverflow(Int(v1), (std::integral_constant<Int, v2>()), &r), true); \
+ QCOMPARE(qMulOverflow<v2>(Int(v1), &r), true); \
} while (false);
// basic multiplications
@@ -723,28 +726,28 @@ void tst_QNumeric::signedOverflow()
const int maxInt = std::numeric_limits<int>::max();
int r;
- QCOMPARE(add_overflow(minInt + 1, int(-1), &r), false);
- QCOMPARE(add_overflow(minInt, int(-1), &r), true);
- QCOMPARE(add_overflow(minInt, minInt, &r), true);
- QCOMPARE(add_overflow(maxInt - 1, int(1), &r), false);
- QCOMPARE(add_overflow(maxInt, int(1), &r), true);
- QCOMPARE(add_overflow(maxInt, maxInt, &r), true);
-
- QCOMPARE(sub_overflow(minInt + 1, int(1), &r), false);
- QCOMPARE(sub_overflow(minInt, int(1), &r), true);
- QCOMPARE(sub_overflow(minInt, maxInt, &r), true);
- QCOMPARE(sub_overflow(maxInt - 1, int(-1), &r), false);
- QCOMPARE(sub_overflow(maxInt, int(-1), &r), true);
- QCOMPARE(sub_overflow(maxInt, minInt, &r), true);
-
- QCOMPARE(mul_overflow(minInt, int(1), &r), false);
- QCOMPARE(mul_overflow(minInt, int(-1), &r), true);
- QCOMPARE(mul_overflow(minInt, int(2), &r), true);
- QCOMPARE(mul_overflow(minInt, minInt, &r), true);
- QCOMPARE(mul_overflow(maxInt, int(1), &r), false);
- QCOMPARE(mul_overflow(maxInt, int(-1), &r), false);
- QCOMPARE(mul_overflow(maxInt, int(2), &r), true);
- QCOMPARE(mul_overflow(maxInt, maxInt, &r), true);
+ QCOMPARE(qAddOverflow(minInt + 1, int(-1), &r), false);
+ QCOMPARE(qAddOverflow(minInt, int(-1), &r), true);
+ QCOMPARE(qAddOverflow(minInt, minInt, &r), true);
+ QCOMPARE(qAddOverflow(maxInt - 1, int(1), &r), false);
+ QCOMPARE(qAddOverflow(maxInt, int(1), &r), true);
+ QCOMPARE(qAddOverflow(maxInt, maxInt, &r), true);
+
+ QCOMPARE(qSubOverflow(minInt + 1, int(1), &r), false);
+ QCOMPARE(qSubOverflow(minInt, int(1), &r), true);
+ QCOMPARE(qSubOverflow(minInt, maxInt, &r), true);
+ QCOMPARE(qSubOverflow(maxInt - 1, int(-1), &r), false);
+ QCOMPARE(qSubOverflow(maxInt, int(-1), &r), true);
+ QCOMPARE(qSubOverflow(maxInt, minInt, &r), true);
+
+ QCOMPARE(qMulOverflow(minInt, int(1), &r), false);
+ QCOMPARE(qMulOverflow(minInt, int(-1), &r), true);
+ QCOMPARE(qMulOverflow(minInt, int(2), &r), true);
+ QCOMPARE(qMulOverflow(minInt, minInt, &r), true);
+ QCOMPARE(qMulOverflow(maxInt, int(1), &r), false);
+ QCOMPARE(qMulOverflow(maxInt, int(-1), &r), false);
+ QCOMPARE(qMulOverflow(maxInt, int(2), &r), true);
+ QCOMPARE(qMulOverflow(maxInt, maxInt, &r), true);
}
QTEST_APPLESS_MAIN(tst_QNumeric)
diff --git a/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt b/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt
index e8906a66d9..f0e682d664 100644
--- a/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt
+++ b/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qoperatingsystemversion.pro.
-
#####################################################################
## tst_qoperatingsystemversion Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qoperatingsystemversion LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qoperatingsystemversion
SOURCES
tst_qoperatingsystemversion.cpp
diff --git a/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp b/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp
index 9c602a459c..4c4ff72722 100644
--- a/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp
+++ b/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.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 <qoperatingsystemversion.h>
@@ -10,11 +10,15 @@ class tst_QOperatingSystemVersion : public QObject
private slots:
void construction_data();
void construction();
+ void globals_data();
+ void globals();
void anyOf();
void comparison_data();
void comparison();
+ void comparison2_data();
+ void comparison2();
void mixedComparison();
};
@@ -52,6 +56,34 @@ void tst_QOperatingSystemVersion::construction()
QVERIFY(!systemVersion.name().isEmpty());
}
+void tst_QOperatingSystemVersion::globals_data()
+{
+ QTest::addColumn<QOperatingSystemVersion>("osver");
+ QTest::addColumn<QOperatingSystemVersion::OSType>("osType");
+
+#define ADDROW(os) QTest::newRow(#os) << QOperatingSystemVersion(QOperatingSystemVersion::os)
+ // legacy ones (global variables)
+ ADDROW(Windows7) << QOperatingSystemVersion::Windows;
+ ADDROW(Windows10) << QOperatingSystemVersion::Windows;
+ ADDROW(OSXMavericks) << QOperatingSystemVersion::MacOS;
+ ADDROW(MacOSMonterey) << QOperatingSystemVersion::MacOS;
+ ADDROW(AndroidJellyBean) << QOperatingSystemVersion::Android;
+ ADDROW(Android11) << QOperatingSystemVersion::Android;
+
+ // new ones (static constexpr)
+ ADDROW(Windows11) << QOperatingSystemVersion::Windows;
+ ADDROW(Android12) << QOperatingSystemVersion::Android;
+#undef ADDROW
+}
+
+void tst_QOperatingSystemVersion::globals()
+{
+ QFETCH(QOperatingSystemVersion, osver);
+ QFETCH(QOperatingSystemVersion::OSType, osType);
+ QCOMPARE(osver.type(), osType);
+ QCOMPARE_NE(osver.majorVersion(), 0);
+}
+
void tst_QOperatingSystemVersion::anyOf()
{
std::initializer_list<QOperatingSystemVersion::OSType> typesToCheck = {
@@ -82,47 +114,44 @@ void tst_QOperatingSystemVersion::comparison_data()
QTest::addColumn<int>("rhsMinor");
QTest::addColumn<int>("rhsMicro");
- QTest::addColumn<bool>("lessResult");
- QTest::addColumn<bool>("lessEqualResult");
- QTest::addColumn<bool>("moreResult");
- QTest::addColumn<bool>("moreEqualResult");
+ QTest::addColumn<Qt::partial_ordering>("expectedResult");
QTest::addRow("mismatching types") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
<< QOperatingSystemVersion::OSType::MacOS << 1 << 2 << 3
- << false << false << false << false;
+ << Qt::partial_ordering::unordered;
QTest::addRow("equal versions") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
<< QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
- << false << true << false << true;
+ << Qt::partial_ordering::equivalent;
QTest::addRow("lhs micro less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 2
<< QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
- << true << true << false << false;
+ << Qt::partial_ordering::less;
QTest::addRow("rhs micro less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 2
<< QOperatingSystemVersion::OSType::Windows << 1 << 2 << 1
- << false << false << true << true;
+ << Qt::partial_ordering::greater;
QTest::addRow("lhs minor less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
<< QOperatingSystemVersion::OSType::Windows << 1 << 3 << 3
- << true << true << false << false;
+ << Qt::partial_ordering::less;
QTest::addRow("rhs minor less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 2
<< QOperatingSystemVersion::OSType::Windows << 1 << 1 << 3
- << false << false << true << true;
+ << Qt::partial_ordering::greater;
QTest::addRow("lhs major less") << QOperatingSystemVersion::OSType::Windows << 0 << 5 << 6
<< QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
- << true << true << false << false;
+ << Qt::partial_ordering::less;
QTest::addRow("rhs major less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
<< QOperatingSystemVersion::OSType::Windows << 0 << 2 << 3
- << false << false << true << true;
+ << Qt::partial_ordering::greater;
QTest::addRow("different segmentCount")
<< QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
<< QOperatingSystemVersion::OSType::Windows << 1 << 2 << -1
- << false << true << false << true;
+ << Qt::partial_ordering::equivalent;
}
void tst_QOperatingSystemVersion::comparison()
@@ -141,17 +170,75 @@ void tst_QOperatingSystemVersion::comparison()
const QOperatingSystemVersion rhsSystemInfo(rhsType, rhsMajor, rhsMinor, rhsMicro);
- QFETCH(bool, lessResult);
- QCOMPARE(lhsSystemInfo < rhsSystemInfo, lessResult);
+ QFETCH(const Qt::partial_ordering, expectedResult);
- QFETCH(bool, lessEqualResult);
- QCOMPARE(lhsSystemInfo <= rhsSystemInfo, lessEqualResult);
+ QCOMPARE_EQ(lhsSystemInfo < rhsSystemInfo, is_lt(expectedResult));
+ QCOMPARE_EQ(lhsSystemInfo <= rhsSystemInfo, is_lteq(expectedResult));
+ QCOMPARE_EQ(lhsSystemInfo > rhsSystemInfo, is_gt(expectedResult));
+ QCOMPARE_EQ(lhsSystemInfo >= rhsSystemInfo, is_gteq(expectedResult));
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(lhsSystemInfo <=> rhsSystemInfo, expectedResult);
+#endif
+}
- QFETCH(bool, moreResult);
- QCOMPARE(lhsSystemInfo > rhsSystemInfo, moreResult);
+void tst_QOperatingSystemVersion::comparison2_data()
+{
+ QTest::addColumn<QOperatingSystemVersion>("lhs");
+ QTest::addColumn<QOperatingSystemVersion>("rhs");
+ QTest::addColumn<Qt::partial_ordering>("result");
+
+#define ADDROW(os1, os2) \
+ QTest::newRow(#os1 "-vs-" #os2) << QOperatingSystemVersion(QOperatingSystemVersion::os1) \
+ << QOperatingSystemVersion(QOperatingSystemVersion::os2)
+
+ // Cross-OS testing: not comparables.
+ ADDROW(Windows10, MacOSMonterey) << Qt::partial_ordering::unordered;
+ ADDROW(Windows11, MacOSMonterey) << Qt::partial_ordering::unordered;
+ ADDROW(MacOSMonterey, Windows10) << Qt::partial_ordering::unordered;
+ ADDROW(MacOSMonterey, Windows11) << Qt::partial_ordering::unordered;
+ ADDROW(Windows10, MacOSVentura) << Qt::partial_ordering::unordered;
+ ADDROW(Windows11, MacOSVentura) << Qt::partial_ordering::unordered;
+ ADDROW(MacOSVentura, Windows10) << Qt::partial_ordering::unordered;
+ ADDROW(MacOSVentura, Windows11) << Qt::partial_ordering::unordered;
+ ADDROW(Windows10, Android10) << Qt::partial_ordering::unordered;
+ ADDROW(Windows11, Android11) << Qt::partial_ordering::unordered;
+
+ // Same-OS tests. This list does not have to be exhaustive.
+ ADDROW(Windows7, Windows7) << Qt::partial_ordering::equivalent;
+ ADDROW(Windows7, Windows8) << Qt::partial_ordering::less;
+ ADDROW(Windows8, Windows7) << Qt::partial_ordering::greater;
+ ADDROW(Windows8, Windows10) << Qt::partial_ordering::less;
+ ADDROW(Windows10, Windows8) << Qt::partial_ordering::greater;
+ ADDROW(Windows10, Windows10_21H1) << Qt::partial_ordering::less;
+ ADDROW(Windows10_21H1, Windows10) << Qt::partial_ordering::greater;
+ ADDROW(Windows10, Windows11) << Qt::partial_ordering::less;
+ ADDROW(MacOSCatalina, MacOSCatalina) << Qt::partial_ordering::equivalent;
+ ADDROW(MacOSCatalina, MacOSBigSur) << Qt::partial_ordering::less;
+ ADDROW(MacOSBigSur, MacOSCatalina) << Qt::partial_ordering::greater;
+ ADDROW(MacOSMonterey, MacOSVentura) << Qt::partial_ordering::less;
+ ADDROW(MacOSVentura, MacOSVentura) << Qt::partial_ordering::equivalent;
+ ADDROW(MacOSVentura, MacOSMonterey) << Qt::partial_ordering::greater;
+#undef ADDROW
+}
- QFETCH(bool, moreEqualResult);
- QCOMPARE(lhsSystemInfo >= rhsSystemInfo, moreEqualResult);
+void tst_QOperatingSystemVersion::comparison2()
+{
+ QFETCH(QOperatingSystemVersion, lhs);
+ QFETCH(QOperatingSystemVersion, rhs);
+ QFETCH(const Qt::partial_ordering, result);
+
+ QEXPECT_FAIL("Windows10-vs-Windows10_21H1", "QTBUG-107907: Unexpected behavior", Abort);
+ QEXPECT_FAIL("Windows10-vs-Windows11", "QTBUG-107907: Unexpected behavior", Abort);
+
+ const bool comparable = (result != Qt::partial_ordering::unordered);
+ QCOMPARE_EQ(lhs < rhs, is_lt(result) && comparable);
+ QEXPECT_FAIL("Windows10_21H1-vs-Windows10", "QTBUG-107907: Unexpected behavior", Abort);
+ QCOMPARE_EQ(lhs <= rhs, is_lteq(result) && comparable);
+ QCOMPARE_EQ(lhs > rhs, is_gt(result) && comparable);
+ QCOMPARE_EQ(lhs >= rhs, is_gteq(result) && comparable);
+#ifdef __cpp_lib_three_way_comparison
+ QCOMPARE_EQ(lhs <=> rhs, result);
+#endif
}
void tst_QOperatingSystemVersion::mixedComparison()
diff --git a/tests/auto/corelib/global/qrandomgenerator/CMakeLists.txt b/tests/auto/corelib/global/qrandomgenerator/CMakeLists.txt
index a0b15db047..3d8f892414 100644
--- a/tests/auto/corelib/global/qrandomgenerator/CMakeLists.txt
+++ b/tests/auto/corelib/global/qrandomgenerator/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qrandomgenerator.pro.
-
#####################################################################
## tst_qrandomgenerator Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qrandomgenerator LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qrandomgenerator
SOURCES
tst_qrandomgenerator.cpp
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
index 9ada7352b4..a32045bbbb 100644
--- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
+++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2017 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>
#include <qlist.h>
@@ -128,6 +128,9 @@ void tst_QRandomGenerator::basics()
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wself-move")
QT_WARNING_DISABLE_CLANG("-Wself-assign-overloaded")
+#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1301
+QT_WARNING_DISABLE_GCC("-Wself-move")
+#endif
// copyable && movable
rng = rng;
rng = std::move(rng);
@@ -610,7 +613,7 @@ template <typename UInt> static void boundedQuality_template()
QVector<UInt> buffer(BufferCount, filler);
generate(buffer.begin(), buffer.end(), [&] { return rng.bounded(Bound); });
- for (UInt value : qAsConst(buffer)) {
+ for (UInt value : std::as_const(buffer)) {
QVERIFY(value < Bound);
histogram[value]++;
}
diff --git a/tests/auto/corelib/global/qtendian/CMakeLists.txt b/tests/auto/corelib/global/qtendian/CMakeLists.txt
index b5d7acffdc..cf1a22f678 100644
--- a/tests/auto/corelib/global/qtendian/CMakeLists.txt
+++ b/tests/auto/corelib/global/qtendian/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qtendian.pro.
-
#####################################################################
## tst_qtendian Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtendian LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtendian
SOURCES
tst_qtendian.cpp
diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp
index 401367ecaa..8e50b2bd08 100644
--- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp
+++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp
@@ -1,5 +1,5 @@
// 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>
@@ -7,6 +7,12 @@
#include <QtCore/private/qendian_p.h>
#include <QtCore/qsysinfo.h>
+#if QT_SUPPORTS_INT128
+#define ONLY_INT128(...) __VA_ARGS__
+#else
+#define ONLY_INT128(...)
+#endif
+
class tst_QtEndian: public QObject
{
Q_OBJECT
@@ -41,6 +47,9 @@ private slots:
struct TestData
{
+ ONLY_INT128(
+ quint128 data128;
+ )
quint64 data64;
quint32 data32;
quint16 data16;
@@ -57,6 +66,9 @@ template <> quint8 getData(const TestData &d) { return d.data8; }
template <> quint16 getData(const TestData &d) { return d.data16; }
template <> quint32 getData(const TestData &d) { return d.data32; }
template <> quint64 getData(const TestData &d) { return d.data64; }
+ONLY_INT128(
+template <> quint128 getData(const TestData &d) { return d.data128; }
+)
template <> float getData(const TestData &d) { return d.dataFloat; }
union RawTestData
@@ -74,6 +86,9 @@ Float int2Float(typename QIntegerForSizeof<Float>::Unsigned i)
}
static const TestData inNativeEndian = {
+ ONLY_INT128(
+ Q_UINT128_C(0x0123'4567'89ab'cdef'18ba'df00'd1da'cafe),
+ )
Q_UINT64_C(0x0123456789abcdef),
0x00c0ffee,
0xcafe,
@@ -83,6 +98,9 @@ static const TestData inNativeEndian = {
'\0'
};
static const RawTestData inBigEndian = {
+ ONLY_INT128(
+ "\x01\x23\x45\x67\x89\xab\xcd\xef\x18\xba\xdf\x00\xd1\xda\xca\xfe"
+ )
"\x01\x23\x45\x67\x89\xab\xcd\xef"
"\x00\xc0\xff\xee"
"\xca\xfe"
@@ -91,6 +109,9 @@ static const RawTestData inBigEndian = {
"\x01\x23\x45\x67\x89\xab\xcd\xef"
};
static const RawTestData inLittleEndian = {
+ ONLY_INT128(
+ "\xfe\xca\xda\xd1\x00\xdf\xba\x18\xef\xcd\xab\x89\x67\x45\x23\x01"
+ )
"\xef\xcd\xab\x89\x67\x45\x23\x01"
"\xee\xff\xc0\x00"
"\xfe\xca"
@@ -102,27 +123,37 @@ static const RawTestData inLittleEndian = {
#define EXPAND_ENDIAN_TEST(endian) \
do { \
/* Unsigned tests */ \
- ENDIAN_TEST(endian, quint, 64); \
- ENDIAN_TEST(endian, quint, 32); \
- ENDIAN_TEST(endian, quint, 16); \
- ENDIAN_TEST(endian, quint, 8); \
+ ONLY_INT128( \
+ ENDIAN_TEST_INT(endian, ui, 128); \
+ ) \
+ ENDIAN_TEST_INT(endian, ui, 64); \
+ ENDIAN_TEST_INT(endian, ui, 32); \
+ ENDIAN_TEST_INT(endian, ui, 16); \
+ ENDIAN_TEST_INT(endian, ui, 8); \
\
/* Signed tests */ \
- ENDIAN_TEST(endian, qint, 64); \
- ENDIAN_TEST(endian, qint, 32); \
- ENDIAN_TEST(endian, qint, 16); \
- ENDIAN_TEST(endian, qint, 8); \
+ ONLY_INT128( \
+ ENDIAN_TEST_INT(endian, i, 128); \
+ ) \
+ ENDIAN_TEST_INT(endian, i, 64); \
+ ENDIAN_TEST_INT(endian, i, 32); \
+ ENDIAN_TEST_INT(endian, i, 16); \
+ ENDIAN_TEST_INT(endian, i, 8); \
} while (false) \
/**/
-#define ENDIAN_TEST(endian, type, size) \
+#define ENDIAN_TEST_INT(Endian, Uns, Size) \
+ ENDIAN_TEST(Endian, q ## Uns ## nt ## Size, data ## Size)
+
+#define ENDIAN_TEST(endian, Type, Data) \
do { \
+ static_assert(std::is_same_v<decltype(qbswap(std::declval<Type>())), Type>); \
QCOMPARE(qFrom ## endian ## Endian( \
- (type ## size)(in ## endian ## Endian.data.data ## size)), \
- (type ## size)(inNativeEndian.data ## size)); \
- QCOMPARE(qFrom ## endian ## Endian<type ## size>( \
- in ## endian ## Endian.rawData + offsetof(TestData, data ## size)), \
- (type ## size)(inNativeEndian.data ## size)); \
+ (Type)(in ## endian ## Endian.data.Data)), \
+ (Type)(inNativeEndian.Data)); \
+ QCOMPARE(qFrom ## endian ## Endian<Type>( \
+ in ## endian ## Endian.rawData + offsetof(TestData, Data)), \
+ (Type)(inNativeEndian.Data)); \
} while (false) \
/**/
@@ -243,18 +274,18 @@ void tst_QtEndian::fromLittleEndianRegion()
}
}
-#define ENDIAN_TEST(endian, type, size) \
- do { \
- QCOMPARE(qTo ## endian ## Endian( \
- (type ## size)(inNativeEndian.data ## size)), \
- (type ## size)(in ## endian ## Endian.data.data ## size)); \
- \
- RawTestData test; \
- qTo ## endian ## Endian( \
- (type ## size)(inNativeEndian.data ## size), \
- test.rawData + offsetof(TestData, data ## size)); \
- QCOMPARE(test.data.data ## size, in ## endian ## Endian.data.data ## size ); \
- } while (false) \
+#define ENDIAN_TEST(endian, Type, Data) \
+ do { \
+ QCOMPARE(qTo ## endian ## Endian( \
+ (Type)(inNativeEndian.Data)), \
+ (Type)(in ## endian ## Endian.data.Data)); \
+ \
+ RawTestData test; \
+ qTo ## endian ## Endian( \
+ (Type)(inNativeEndian.Data), \
+ test.rawData + offsetof(TestData, Data)); \
+ QCOMPARE(test.data.Data, in ## endian ## Endian.data.Data ); \
+ } while (false) \
/**/
void tst_QtEndian::toBigEndian()
@@ -430,8 +461,7 @@ void tst_QtEndian::endianBitfieldUnions()
testBitfieldUnion<qint32_le_bitfield_union, qint32_le_bitfield_member>();
return;
}
- Q_UNREACHABLE();
- return;
+ Q_UNREACHABLE_RETURN();
case QSysInfo::BigEndian:
switch (signedness) {
case Unsigned:
@@ -441,8 +471,7 @@ void tst_QtEndian::endianBitfieldUnions()
testBitfieldUnion<qint32_be_bitfield_union, qint32_be_bitfield_member>();
return;
}
- Q_UNREACHABLE();
- return;
+ Q_UNREACHABLE_RETURN();
}
}
diff --git a/tests/auto/corelib/global/qxp/CMakeLists.txt b/tests/auto/corelib/global/qxp/CMakeLists.txt
index f289a04701..2178f446db 100644
--- a/tests/auto/corelib/global/qxp/CMakeLists.txt
+++ b/tests/auto/corelib/global/qxp/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory(function_ref)
+add_subdirectory(is_virtual_base_of)
diff --git a/tests/auto/corelib/global/qxp/function_ref/CMakeLists.txt b/tests/auto/corelib/global/qxp/function_ref/CMakeLists.txt
index d52618d527..351fe24b22 100644
--- a/tests/auto/corelib/global/qxp/function_ref/CMakeLists.txt
+++ b/tests/auto/corelib/global/qxp/function_ref/CMakeLists.txt
@@ -1,6 +1,12 @@
# 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_qxp_function_ref LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qxp_function_ref
EXCEPTIONS
SOURCES
diff --git a/tests/auto/corelib/global/qxp/function_ref/tst_qxp_function_ref.cpp b/tests/auto/corelib/global/qxp/function_ref/tst_qxp_function_ref.cpp
index 6264e6a5ae..ee50a311ef 100644
--- a/tests/auto/corelib/global/qxp/function_ref/tst_qxp_function_ref.cpp
+++ b/tests/auto/corelib/global/qxp/function_ref/tst_qxp_function_ref.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 <QtCore/qxpfunctional.h>
@@ -249,6 +249,8 @@ void tst_qxp_function_ref::ctad()
qxp::function_ref f2 = &fun; \
static_assert(std::is_same_v<decltype(f2), \
qxp::function_ref<sig>>); \
+ static_assert(std::is_trivially_copyable_v<decltype(f)>); \
+ static_assert(std::is_trivially_copyable_v<decltype(f2)>); \
} while (false)
CHECK(i_f_i_nx, int (int) noexcept);
diff --git a/tests/auto/corelib/global/qxp/is_virtual_base_of/CMakeLists.txt b/tests/auto/corelib/global/qxp/is_virtual_base_of/CMakeLists.txt
new file mode 100644
index 0000000000..85a6daab7c
--- /dev/null
+++ b/tests/auto/corelib/global/qxp/is_virtual_base_of/CMakeLists.txt
@@ -0,0 +1,23 @@
+# 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_qxp_is_virtual_base_of LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qxp_is_virtual_base_of
+ EXCEPTIONS
+ SOURCES
+ tst_is_virtual_base_of.cpp
+ LIBRARIES
+ Qt::Core
+)
+
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90449
+# GCCs < 10 have no way to suppress "inaccessible base" warnings, except by disabling all warnings:
+qt_internal_extend_target(tst_qxp_is_virtual_base_of
+ CONDITION GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10")
+ COMPILE_OPTIONS -w
+)
diff --git a/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp b/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp
new file mode 100644
index 0000000000..e50575f5ec
--- /dev/null
+++ b/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp
@@ -0,0 +1,102 @@
+// Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtCore/qxptype_traits.h>
+
+#include <QTest>
+
+class tst_qxp_is_virtual_base_of : public QObject
+{
+ Q_OBJECT
+};
+
+class Base {
+public:
+ virtual ~Base() {}
+};
+
+// Only works with classes
+static_assert(!qxp::is_virtual_base_of_v<int, int>);
+static_assert(!qxp::is_virtual_base_of_v<int, Base>);
+static_assert(!qxp::is_virtual_base_of_v<Base, int>);
+
+// A class isn't a virtual base of itself
+static_assert(!qxp::is_virtual_base_of_v<Base, Base>);
+
+// Non-virtual bases
+class NonVirtualDerived : public Base {};
+class NonVirtualPrivateDerived : private Base {};
+
+static_assert(!qxp::is_virtual_base_of_v<Base, NonVirtualDerived>);
+static_assert(!qxp::is_virtual_base_of_v<Base, NonVirtualPrivateDerived>);
+
+static_assert(!qxp::is_virtual_base_of_v<NonVirtualPrivateDerived, NonVirtualDerived>);
+static_assert(!qxp::is_virtual_base_of_v<NonVirtualDerived, NonVirtualPrivateDerived>);
+
+static_assert(!qxp::is_virtual_base_of_v<tst_qxp_is_virtual_base_of, QObject>);
+
+// Virtual bases
+class VirtualDerived1 : public virtual Base {};
+class VirtualDerived2 : public virtual Base {};
+class VirtualDerived3 : public VirtualDerived1, public VirtualDerived2 {};
+class VirtualDerived4 : public VirtualDerived3, public virtual Base {};
+class VirtualPrivateDerived : private virtual Base {};
+
+static_assert(qxp::is_virtual_base_of_v<Base, VirtualDerived1>);
+static_assert(qxp::is_virtual_base_of_v<Base, VirtualDerived2>);
+static_assert(qxp::is_virtual_base_of_v<Base, VirtualDerived3>);
+static_assert(!qxp::is_virtual_base_of_v<VirtualDerived1, VirtualDerived3>);
+static_assert(qxp::is_virtual_base_of_v<Base, VirtualDerived4>);
+static_assert(qxp::is_virtual_base_of_v<Base, VirtualPrivateDerived>);
+
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Winaccessible-base")
+QT_WARNING_DISABLE_CLANG("-Winaccessible-base")
+// Ambiguous non-virtual base
+class IntermediateDerived : public Base {};
+class AmbiguousBase1 : public IntermediateDerived, public Base {};
+class AmbiguousBase2 : public IntermediateDerived, public virtual Base {};
+
+static_assert(!qxp::is_virtual_base_of_v<Base, AmbiguousBase1>);
+#ifndef Q_CC_MSVC_ONLY // https://developercommunity.visualstudio.com/t/c-templates-multiple-inheritance-ambiguous-access/185674
+static_assert(!qxp::is_virtual_base_of_v<Base, AmbiguousBase2>);
+#endif
+QT_WARNING_POP
+
+// Const
+static_assert(!qxp::is_virtual_base_of_v< Base, const NonVirtualDerived>);
+static_assert(!qxp::is_virtual_base_of_v<const Base, NonVirtualDerived>);
+static_assert(!qxp::is_virtual_base_of_v<const Base, const NonVirtualDerived>);
+
+static_assert(!qxp::is_virtual_base_of_v< Base, const NonVirtualPrivateDerived>);
+static_assert(!qxp::is_virtual_base_of_v<const Base, NonVirtualPrivateDerived>);
+static_assert(!qxp::is_virtual_base_of_v<const Base, const NonVirtualPrivateDerived>);
+
+static_assert(qxp::is_virtual_base_of_v< Base, const VirtualDerived1>);
+static_assert(qxp::is_virtual_base_of_v<const Base, VirtualDerived1>);
+static_assert(qxp::is_virtual_base_of_v<const Base, const VirtualDerived1>);
+
+static_assert(qxp::is_virtual_base_of_v< Base, const VirtualDerived2>);
+static_assert(qxp::is_virtual_base_of_v<const Base, VirtualDerived2>);
+static_assert(qxp::is_virtual_base_of_v<const Base, const VirtualDerived2>);
+
+static_assert(qxp::is_virtual_base_of_v< Base, const VirtualDerived3>);
+static_assert(qxp::is_virtual_base_of_v<const Base, VirtualDerived3>);
+static_assert(qxp::is_virtual_base_of_v<const Base, const VirtualDerived3>);
+
+static_assert(qxp::is_virtual_base_of_v< Base, const VirtualDerived4>);
+static_assert(qxp::is_virtual_base_of_v<const Base, VirtualDerived4>);
+static_assert(qxp::is_virtual_base_of_v<const Base, const VirtualDerived4>);
+
+static_assert(qxp::is_virtual_base_of_v< Base, const VirtualDerived4>);
+static_assert(qxp::is_virtual_base_of_v<const Base, VirtualDerived4>);
+static_assert(qxp::is_virtual_base_of_v<const Base, const VirtualDerived4>);
+
+static_assert(qxp::is_virtual_base_of_v< Base, const VirtualPrivateDerived>);
+static_assert(qxp::is_virtual_base_of_v<const Base, VirtualPrivateDerived>);
+static_assert(qxp::is_virtual_base_of_v<const Base, const VirtualPrivateDerived>);
+
+
+QTEST_APPLESS_MAIN(tst_qxp_is_virtual_base_of);
+
+#include "tst_is_virtual_base_of.moc"