diff options
Diffstat (limited to 'tests/auto/corelib/tools/qpoint')
-rw-r--r-- | tests/auto/corelib/tools/qpoint/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qpoint/tst_qpoint.cpp | 41 |
2 files changed, 43 insertions, 8 deletions
diff --git a/tests/auto/corelib/tools/qpoint/CMakeLists.txt b/tests/auto/corelib/tools/qpoint/CMakeLists.txt index e68ff17a77..82ece1fc15 100644 --- a/tests/auto/corelib/tools/qpoint/CMakeLists.txt +++ b/tests/auto/corelib/tools/qpoint/CMakeLists.txt @@ -1,13 +1,19 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qpoint.pro. - ##################################################################### ## tst_qpoint Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpoint LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpoint SOURCES tst_qpoint.cpp + LIBRARIES + Qt::TestPrivate ) diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp index c183f79fb8..4763c1bf07 100644 --- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp +++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp @@ -1,5 +1,28 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QPoint> +#ifdef QVARIANT_H +# error "This test requires qpoint.h to not include qvariant.h" +#endif +#include <private/qcomparisontesthelper_p.h> + +// don't assume <type_traits> +template <typename T, typename U> +constexpr inline bool my_is_same_v = false; +template <typename T> +constexpr inline bool my_is_same_v<T, T> = true; + +#define CHECK(cvref) \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QPoint cvref >())), int cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QPoint cvref >())), int cvref >) + +CHECK(&); +CHECK(const &); +CHECK(&&); +CHECK(const &&); + +#undef CHECK #include <QTest> #include <QBuffer> @@ -49,6 +72,7 @@ private slots: void operator_unary_minus_data(); void operator_unary_minus(); + void operatorsCompile(); void operator_eq_data(); void operator_eq(); @@ -133,6 +157,8 @@ void tst_QPoint::toPointF() QFETCH(const QPointF, result); QCOMPARE(input.toPointF(), result); + // test also mixed-type comparison + QT_TEST_EQUALITY_OPS(input, result, true); } void tst_QPoint::transposed() @@ -328,6 +354,12 @@ void tst_QPoint::operator_unary_minus() QCOMPARE(-point, expected); } +void tst_QPoint::operatorsCompile() +{ + // Mixed-type comparison is tested in tst_QPointF. + QTestPrivate::testEqualityOperatorsCompile<QPoint>(); +} + void tst_QPoint::operator_eq_data() { QTest::addColumn<QPoint>("point1"); @@ -349,12 +381,9 @@ void tst_QPoint::operator_eq() QFETCH(QPoint, point2); QFETCH(bool, expectEqual); - bool equal = point1 == point2; - QCOMPARE(equal, expectEqual); - bool notEqual = point1 != point2; - QCOMPARE(notEqual, !expectEqual); + QT_TEST_EQUALITY_OPS(point1, point2, expectEqual); - if (equal) + if (expectEqual) QCOMPARE(qHash(point1), qHash(point2)); } |