diff options
Diffstat (limited to 'tests/auto/corelib/thread/qatomicinteger')
36 files changed, 169 insertions, 214 deletions
diff --git a/tests/auto/corelib/thread/qatomicinteger/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/CMakeLists.txt index 8f0637a4d2..03a6323a1f 100644 --- a/tests/auto/corelib/thread/qatomicinteger/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qatomicinteger.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(char) add_subdirectory(char16_t) diff --git a/tests/auto/corelib/thread/qatomicinteger/char/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/char/CMakeLists.txt index 57601dc0e4..882a9298f6 100644 --- a/tests/auto/corelib/thread/qatomicinteger/char/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/char/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from char.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_char Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_char LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_char SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/char/char.pro b/tests/auto/corelib/thread/qatomicinteger/char/char.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/char/char.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/char16_t/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/char16_t/CMakeLists.txt index 6ac58c9136..8e53b59689 100644 --- a/tests/auto/corelib/thread/qatomicinteger/char16_t/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/char16_t/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from char16_t.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_char16_t Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_char16_t LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_char16_t SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/char16_t/char16_t.pro b/tests/auto/corelib/thread/qatomicinteger/char16_t/char16_t.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/char16_t/char16_t.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/char32_t/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/char32_t/CMakeLists.txt index 911e9f5067..5881d475f4 100644 --- a/tests/auto/corelib/thread/qatomicinteger/char32_t/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/char32_t/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from char32_t.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_char32_t Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_char32_t LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_char32_t SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/char32_t/char32_t.pro b/tests/auto/corelib/thread/qatomicinteger/char32_t/char32_t.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/char32_t/char32_t.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/int/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/int/CMakeLists.txt index be59e2dc98..0915e77a8d 100644 --- a/tests/auto/corelib/thread/qatomicinteger/int/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/int/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from int.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_int Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_int LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_int SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/int/int.pro b/tests/auto/corelib/thread/qatomicinteger/int/int.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/int/int.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/long/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/long/CMakeLists.txt index 3f632ff212..adf6638bfa 100644 --- a/tests/auto/corelib/thread/qatomicinteger/long/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/long/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from long.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_long Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_long LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_long SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/long/long.pro b/tests/auto/corelib/thread/qatomicinteger/long/long.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/long/long.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri b/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri deleted file mode 100644 index f1030d41ef..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri +++ /dev/null @@ -1,11 +0,0 @@ -# Get our build type from the directory name -TYPE = $$basename(_PRO_FILE_PWD_) -dn = $$dirname(_PRO_FILE_PWD_) -FORCE = $$basename(dn) -suffix = $$TYPE - -CONFIG += testcase -QT = core testlib -TARGET = tst_qatomicinteger_$$lower($$suffix) -SOURCES = $$PWD/tst_qatomicinteger.cpp -DEFINES += QATOMIC_TEST_TYPE=$$TYPE tst_QAtomicIntegerXX=tst_QAtomicInteger_$$suffix diff --git a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro b/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro deleted file mode 100644 index 09458bd9c3..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro +++ /dev/null @@ -1,18 +0,0 @@ -TEMPLATE=subdirs -SUBDIRS=\ - char \ - char16_t \ - char32_t \ - int \ - long \ - qlonglong \ - qptrdiff \ - quintptr \ - qulonglong \ - schar \ - short \ - uchar \ - uint \ - ulong \ - ushort \ - wchar_t \ diff --git a/tests/auto/corelib/thread/qatomicinteger/qlonglong/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/qlonglong/CMakeLists.txt index 3de9227bb1..2ec977d7cb 100644 --- a/tests/auto/corelib/thread/qatomicinteger/qlonglong/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/qlonglong/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qlonglong.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_qlonglong Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_qlonglong LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_qlonglong SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/qlonglong/qlonglong.pro b/tests/auto/corelib/thread/qatomicinteger/qlonglong/qlonglong.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/qlonglong/qlonglong.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/qptrdiff/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/qptrdiff/CMakeLists.txt index cc6b5126d9..a2450931d5 100644 --- a/tests/auto/corelib/thread/qatomicinteger/qptrdiff/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/qptrdiff/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qptrdiff.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_qptrdiff Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_qptrdiff LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_qptrdiff SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/qptrdiff/qptrdiff.pro b/tests/auto/corelib/thread/qatomicinteger/qptrdiff/qptrdiff.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/qptrdiff/qptrdiff.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/quintptr/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/quintptr/CMakeLists.txt index 44cf39f06d..98302b5d07 100644 --- a/tests/auto/corelib/thread/qatomicinteger/quintptr/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/quintptr/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from quintptr.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_quintptr Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_quintptr LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_quintptr SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/quintptr/quintptr.pro b/tests/auto/corelib/thread/qatomicinteger/quintptr/quintptr.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/quintptr/quintptr.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/qulonglong/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/qulonglong/CMakeLists.txt index 18d3e384b9..13acfc3e2b 100644 --- a/tests/auto/corelib/thread/qatomicinteger/qulonglong/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/qulonglong/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qulonglong.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_qulonglong Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_qulonglong LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_qulonglong SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/qulonglong/qulonglong.pro b/tests/auto/corelib/thread/qatomicinteger/qulonglong/qulonglong.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/qulonglong/qulonglong.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/schar/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/schar/CMakeLists.txt index 760967532a..127f752cc2 100644 --- a/tests/auto/corelib/thread/qatomicinteger/schar/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/schar/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from schar.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_schar Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_schar LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_schar SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/schar/schar.pro b/tests/auto/corelib/thread/qatomicinteger/schar/schar.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/schar/schar.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/short/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/short/CMakeLists.txt index 3f762e34ab..df9d2af4c3 100644 --- a/tests/auto/corelib/thread/qatomicinteger/short/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/short/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from short.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_short Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_short LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_short SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/short/short.pro b/tests/auto/corelib/thread/qatomicinteger/short/short.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/short/short.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp index 8da52c95fb..d1a8a8f729 100644 --- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp +++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp @@ -1,62 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifdef QT_ATOMIC_FORCE_CXX11 -// We need to check if this compiler has C++11 atomics and constexpr support. -// We can't rely on qcompilerdetection.h because it forces all of qglobal.h to -// be included, which causes qbasicatomic.h to be included too. -// Incomplete, but ok -# if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1500 && (__cplusplus >= 201103L || defined(__INTEL_CXX11_MODE__)) -# elif defined(__clang__) && (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) -# if !__has_feature(cxx_constexpr) || !__has_feature(cxx_atomic) || !__has_include(<atomic>) -# undef QT_ATOMIC_FORCE_CXX11 -# endif -# elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) -# elif defined(_MSC_VER) - // We need MSVC 2015 because of: atomics (2012), constexpr (2015), and unrestricted unions (2015). - // Support for constexpr is not working completely on MSVC 2015 but it's enough for the test. -# else -# undef QT_ATOMIC_FORCE_CXX11 -# endif - -# ifndef QT_ATOMIC_FORCE_CXX11 -# undef QATOMIC_TEST_TYPE -# define QATOMIC_TEST_TYPE unsupported -# endif -#endif +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtTest> +#include <QTest> #include <QAtomicInt> #include <limits> #include <limits.h> #include <wchar.h> +#if !defined(Q_ATOMIC_INT8_IS_SUPPORTED) +# error "QAtomicInteger for 8-bit types must be supported!" +#endif +#if !defined(Q_ATOMIC_INT16_IS_SUPPORTED) +# error "QAtomicInteger for 16-bit types must be supported!" +#endif #if !defined(Q_ATOMIC_INT32_IS_SUPPORTED) # error "QAtomicInteger for 32-bit types must be supported!" #endif @@ -65,31 +22,21 @@ #endif // always supported types: +#define TYPE_SUPPORTED_char 1 +#define TYPE_SUPPORTED_uchar 1 +#define TYPE_SUPPORTED_schar 1 +#define TYPE_SUPPORTED_short 1 +#define TYPE_SUPPORTED_ushort 1 +#define TYPE_SUPPORTED_char16_t 1 +#define TYPE_SUPPORTED_wchar_t 1 #define TYPE_SUPPORTED_int 1 #define TYPE_SUPPORTED_uint 1 #define TYPE_SUPPORTED_long 1 #define TYPE_SUPPORTED_ulong 1 #define TYPE_SUPPORTED_qptrdiff 1 #define TYPE_SUPPORTED_quintptr 1 -#if (defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__-0) > 2) \ - || (defined(WCHAR_MAX) && (WCHAR_MAX-0 > 0x10000)) -# define TYPE_SUPPORTED_wchar_t 1 -#endif -#define TYPE_SUPPORTED_char32_t 1 +#define TYPE_SUPPORTED_char32_t 1 -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED -# define TYPE_SUPPORTED_char 1 -# define TYPE_SUPPORTED_uchar 1 -# define TYPE_SUPPORTED_schar 1 -#endif -#ifdef Q_ATOMIC_INT16_IS_SUPPORTED -# define TYPE_SUPPORTED_short 1 -# define TYPE_SUPPORTED_ushort 1 -# define TYPE_SUPPORTED_char16_t 1 -# ifndef TYPE_SUPPORTED_wchar_t -# define TYPE_SUPPORTED_wchar_t 1 -# endif -#endif #ifdef Q_ATOMIC_INT64_IS_SUPPORTED # define TYPE_SUPPORTED_qlonglong 1 # define TYPE_SUPPORTED_qulonglong 1 @@ -117,6 +64,7 @@ typedef signed char schar; typedef TEST_TYPE Type; typedef Type T; // shorthand +using U = std::make_unsigned_t<T>; enum { TypeIsUnsigned = Type(-1) > Type(0), TypeIsSigned = !TypeIsUnsigned @@ -127,6 +75,8 @@ template <> struct LargeIntTemplate<true> { typedef quint64 Type; }; template <> struct LargeIntTemplate<false> { typedef qint64 Type; }; typedef LargeIntTemplate<TypeIsUnsigned>::Type LargeInt; +namespace { + class tst_QAtomicIntegerXX : public QObject { Q_OBJECT @@ -342,46 +292,32 @@ void tst_QAtomicIntegerXX::loadAcquireStoreRelease() void tst_QAtomicIntegerXX::refDeref() { QFETCH(LargeInt, value); - const bool needToPreventOverflow = TypeIsSigned && value == std::numeric_limits<T>::max(); - const bool needToPreventUnderflow = TypeIsSigned && value == std::numeric_limits<T>::min(); - T nextValue = T(value); - if (!needToPreventOverflow) - ++nextValue; - T prevValue = T(value); - if (!needToPreventUnderflow) - --prevValue; + + // We perform arithmetic using the unsigned type U to avoid signed + // integer overflows in the non-atomic portion (atomics have well-defined, + // two's complement overflow, even signed ones). + T nextValue = T(U(value) + 1); + T prevValue = T(U(value) - 1); QAtomicInteger<T> atomic(value); - if (!needToPreventOverflow) { QCOMPARE(atomic.ref(), (nextValue != 0)); QCOMPARE(atomic.loadRelaxed(), nextValue); QCOMPARE(atomic.deref(), (value != 0)); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.deref(), (prevValue != 0)); QCOMPARE(atomic.loadRelaxed(), prevValue); QCOMPARE(atomic.ref(), (value != 0)); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(++atomic, nextValue); QCOMPARE(--atomic, T(value)); - } - if (!needToPreventUnderflow) { QCOMPARE(--atomic, prevValue); QCOMPARE(++atomic, T(value)); - } - if (!needToPreventOverflow) { QCOMPARE(atomic++, T(value)); QCOMPARE(atomic--, nextValue); - } - if (!needToPreventUnderflow) { QCOMPARE(atomic--, T(value)); QCOMPARE(atomic++, prevValue); - } QCOMPARE(atomic.loadRelaxed(), T(value)); } @@ -484,80 +420,55 @@ void tst_QAtomicIntegerXX::fetchAndAdd() QFETCH(LargeInt, value); QAtomicInteger<T> atomic(value); + // We perform the additions using the unsigned type U to avoid signed + // integer overflows in the non-atomic portion (atomics have well-defined, + // two's complement overflow, even signed ones). T parcel1 = 42; T parcel2 = T(0-parcel1); + T newValue1 = T(U(value) + parcel1); + T newValue2 = T(U(value) + parcel2); - const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits<T>::max() + parcel2; - const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits<T>::min() + parcel1; - - T newValue1 = T(value); - if (!needToPreventOverflow) - newValue1 += parcel1; - T newValue2 = T(value); - if (!needToPreventUnderflow) - newValue2 += parcel2; - - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), newValue1); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), newValue2); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddAcquire(parcel1), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndAddAcquire(parcel2), newValue1); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddAcquire(parcel2), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndAddAcquire(parcel1), newValue2); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddRelease(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndAddRelease(parcel2), newValue1); - } QCOMPARE(atomic.loadAcquire(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddRelease(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndAddRelease(parcel1), newValue2); - } QCOMPARE(atomic.loadAcquire(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddOrdered(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndAddOrdered(parcel2), newValue1); - } QCOMPARE(atomic.loadAcquire(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddOrdered(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndAddOrdered(parcel1), newValue2); - } QCOMPARE(atomic.loadAcquire(), T(value)); // operator+= - if (!needToPreventOverflow) { QCOMPARE(atomic += parcel1, newValue1); QCOMPARE(atomic += parcel2, T(value)); - } - if (!needToPreventUnderflow) { QCOMPARE(atomic += parcel2, newValue2); QCOMPARE(atomic += parcel1, T(value)); - } } void tst_QAtomicIntegerXX::fetchAndSub() @@ -565,80 +476,55 @@ void tst_QAtomicIntegerXX::fetchAndSub() QFETCH(LargeInt, value); QAtomicInteger<T> atomic(value); + // We perform the subtractions using the unsigned type U to avoid signed + // integer underrflows in the non-atomic portion (atomics have well-defined, + // two's complement underflow, even signed ones). T parcel1 = 42; T parcel2 = T(0-parcel1); + T newValue1 = T(U(value) - parcel1); + T newValue2 = T(U(value) - parcel2); - const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits<T>::max() - parcel1; - const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits<T>::min() - parcel2; - - T newValue1 = T(value); - if (!needToPreventUnderflow) - newValue1 -= parcel1; - T newValue2 = T(value); - if (!needToPreventOverflow) - newValue2 -= parcel2; - - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), newValue1); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), newValue2); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubAcquire(parcel1), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndSubAcquire(parcel2), newValue1); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubAcquire(parcel2), T(value)); QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndSubAcquire(parcel1), newValue2); - } QCOMPARE(atomic.loadRelaxed(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubRelease(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndSubRelease(parcel2), newValue1); - } QCOMPARE(atomic.loadAcquire(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubRelease(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndSubRelease(parcel1), newValue2); - } QCOMPARE(atomic.loadAcquire(), T(value)); - if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubOrdered(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndSubOrdered(parcel2), newValue1); - } QCOMPARE(atomic.loadAcquire(), T(value)); - if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubOrdered(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndSubOrdered(parcel1), newValue2); - } QCOMPARE(atomic.loadAcquire(), T(value)); // operator-= - if (!needToPreventUnderflow) { QCOMPARE(atomic -= parcel1, newValue1); QCOMPARE(atomic -= parcel2, T(value)); - } - if (!needToPreventOverflow) { QCOMPARE(atomic -= parcel2, newValue2); QCOMPARE(atomic -= parcel1, T(value)); - } } void tst_QAtomicIntegerXX::fetchAndOr() @@ -788,8 +674,9 @@ void tst_QAtomicIntegerXX::fetchAndXor() QCOMPARE(atomic ^= minusOne, T(~value)); QCOMPARE(atomic ^= minusOne, T(value)); } - -#include "tst_qatomicinteger.moc" +} QTEST_APPLESS_MAIN(tst_QAtomicIntegerXX) +#include "tst_qatomicinteger.moc" + diff --git a/tests/auto/corelib/thread/qatomicinteger/uchar/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/uchar/CMakeLists.txt index 912365a6e9..95d88d31a6 100644 --- a/tests/auto/corelib/thread/qatomicinteger/uchar/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/uchar/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from uchar.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_uchar Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_uchar LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_uchar SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/uchar/uchar.pro b/tests/auto/corelib/thread/qatomicinteger/uchar/uchar.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/uchar/uchar.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/uint/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/uint/CMakeLists.txt index 725fa91704..2ab977ef6a 100644 --- a/tests/auto/corelib/thread/qatomicinteger/uint/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/uint/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from uint.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_uint Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_uint LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_uint SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/uint/uint.pro b/tests/auto/corelib/thread/qatomicinteger/uint/uint.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/uint/uint.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/ulong/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/ulong/CMakeLists.txt index d5d35f587d..7707bd53b5 100644 --- a/tests/auto/corelib/thread/qatomicinteger/ulong/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/ulong/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from ulong.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_ulong Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_ulong LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_ulong SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/ulong/ulong.pro b/tests/auto/corelib/thread/qatomicinteger/ulong/ulong.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/ulong/ulong.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/ushort/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/ushort/CMakeLists.txt index fd7c002345..667e9eade6 100644 --- a/tests/auto/corelib/thread/qatomicinteger/ushort/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/ushort/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from ushort.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_ushort Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_ushort LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_ushort SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/ushort/ushort.pro b/tests/auto/corelib/thread/qatomicinteger/ushort/ushort.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/ushort/ushort.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) diff --git a/tests/auto/corelib/thread/qatomicinteger/wchar_t/CMakeLists.txt b/tests/auto/corelib/thread/qatomicinteger/wchar_t/CMakeLists.txt index aecb81005c..0e2d084b58 100644 --- a/tests/auto/corelib/thread/qatomicinteger/wchar_t/CMakeLists.txt +++ b/tests/auto/corelib/thread/qatomicinteger/wchar_t/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from wchar_t.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qatomicinteger_wchar_t Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qatomicinteger_wchar_t LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qatomicinteger_wchar_t SOURCES ../tst_qatomicinteger.cpp diff --git a/tests/auto/corelib/thread/qatomicinteger/wchar_t/wchar_t.pro b/tests/auto/corelib/thread/qatomicinteger/wchar_t/wchar_t.pro deleted file mode 100644 index 1e97d5cbae..0000000000 --- a/tests/auto/corelib/thread/qatomicinteger/wchar_t/wchar_t.pro +++ /dev/null @@ -1 +0,0 @@ -include(../qatomicinteger.pri) |