diff options
Diffstat (limited to 'tests/auto/corelib/kernel/qmetamethod')
-rw-r--r-- | tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp | 36 |
2 files changed, 32 insertions, 14 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt b/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt index 979b578ce7..0d46aef8bd 100644 --- a/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt +++ b/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt @@ -1,13 +1,19 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qmetamethod.pro. - ##################################################################### ## tst_qmetamethod Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmetamethod LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qmetamethod SOURCES tst_qmetamethod.cpp + LIBRARIES + Qt::TestPrivate ) diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp index 4cc15159e7..59fb747524 100644 --- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -1,9 +1,10 @@ // Copyright (C) 2016 The Qt Company Ltd. // 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 <QTest> +#include <QtTest/private/qcomparisontesthelper_p.h> #include <QTypeRevision> #include <qobject.h> @@ -14,6 +15,7 @@ class tst_QMetaMethod : public QObject Q_OBJECT private slots: + void compareCompiles(); void method_data(); void method(); @@ -22,6 +24,7 @@ private slots: void comparisonOperators(); void fromSignal(); + void fromSignalOfNullSignalIsInvalid(); void gadget(); void revision(); @@ -165,6 +168,11 @@ QVariant MethodTestObject::qvariantSlotBoolIntUIntLonglongULonglongDoubleLongSho } void MethodTestObject::voidSlotNoParameterNames(bool, int) {} +void tst_QMetaMethod::compareCompiles() +{ + QTestPrivate::testEqualityOperatorsCompile<QMetaMethod>(); +} + void tst_QMetaMethod::method_data() { QTest::addColumn<QByteArray>("signature"); @@ -646,6 +654,8 @@ void tst_QMetaMethod::method() // Bogus indexes QCOMPARE(method.parameterType(-1), 0); QCOMPARE(method.parameterType(parameterTypes.size()), 0); + QT_TEST_EQUALITY_OPS(method, QMetaMethod(), false); + QT_TEST_EQUALITY_OPS(QMetaMethod(), QMetaMethod(), true); } void tst_QMetaMethod::invalidMethod() @@ -658,6 +668,9 @@ void tst_QMetaMethod::invalidMethod() QMetaMethod method3 = staticMetaObject.method(-1); QVERIFY(!method3.isValid()); + QT_TEST_EQUALITY_OPS(method, method2, true); + QT_TEST_EQUALITY_OPS(method2, method3, true); + QT_TEST_EQUALITY_OPS(method, method3, true); } void tst_QMetaMethod::comparisonOperators() @@ -672,16 +685,9 @@ void tst_QMetaMethod::comparisonOperators() QMetaMethod other = x ? mo->constructor(j) : mo->method(j); bool expectedEqual = ((methodMo == other.enclosingMetaObject()) && (i == j)); - QCOMPARE(method == other, expectedEqual); - QCOMPARE(method != other, !expectedEqual); - QCOMPARE(other == method, expectedEqual); - QCOMPARE(other != method, !expectedEqual); + QT_TEST_EQUALITY_OPS(method, other, expectedEqual); } - - QVERIFY(method != QMetaMethod()); - QVERIFY(QMetaMethod() != method); - QVERIFY(!(method == QMetaMethod())); - QVERIFY(!(QMetaMethod() == method)); + QT_TEST_EQUALITY_OPS(method, QMetaMethod(), false); } } @@ -690,8 +696,7 @@ void tst_QMetaMethod::comparisonOperators() for (int i = 0; i < qMin(mo->methodCount(), mo->constructorCount()); ++i) { QMetaMethod method = mo->method(i); QMetaMethod constructor = mo->constructor(i); - QVERIFY(method != constructor); - QVERIFY(!(method == constructor)); + QT_TEST_EQUALITY_OPS(method, constructor, false); } } @@ -719,6 +724,12 @@ void tst_QMetaMethod::fromSignal() #undef FROMSIGNAL_HELPER } +void tst_QMetaMethod::fromSignalOfNullSignalIsInvalid() +{ + constexpr decltype(&QObject::destroyed) ptr = nullptr; + QVERIFY(!QMetaMethod::fromSignal(ptr).isValid()); +} + class MyGadget { Q_GADGET public: @@ -741,6 +752,7 @@ void tst_QMetaMethod::gadget() QMetaMethod getValueMethod = MyGadget::staticMetaObject.method(idx); QVERIFY(getValueMethod.isValid()); + QT_TEST_EQUALITY_OPS(setValueMethod, getValueMethod, false); { MyGadget gadget; QString string; |