summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp')
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp136
1 files changed, 92 insertions, 44 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
index 942f075723..59fb747524 100644
--- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
+++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// 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
+
+
+#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
+#include <QTypeRevision>
#include <qobject.h>
#include <qmetaobject.h>
@@ -38,6 +15,7 @@ class tst_QMetaMethod : public QObject
Q_OBJECT
private slots:
+ void compareCompiles();
void method_data();
void method();
@@ -46,6 +24,7 @@ private slots:
void comparisonOperators();
void fromSignal();
+ void fromSignalOfNullSignalIsInvalid();
void gadget();
void revision();
@@ -54,6 +33,11 @@ private slots:
void parameterMetaType();
void parameterTypeName();
+
+ void isConst();
+
+ void methodIndexes_data();
+ void methodIndexes();
};
struct CustomType { };
@@ -81,7 +65,7 @@ public:
uchar ucharArg, float floatArg);
Q_INVOKABLE MethodTestObject(bool, int);
- Q_INVOKABLE void voidInvokable();
+ Q_INVOKABLE void voidInvokable() const;
Q_INVOKABLE void voidInvokableInt(int voidInvokableIntArg);
Q_INVOKABLE void voidInvokableQReal(qreal voidInvokableQRealArg);
Q_INVOKABLE void voidInvokableQString(const QString &voidInvokableQStringArg);
@@ -142,7 +126,7 @@ MethodTestObject::MethodTestObject(bool, int, uint, qlonglong, qulonglong,
uchar, float) {}
MethodTestObject::MethodTestObject(bool, int) {}
-void MethodTestObject::voidInvokable() {}
+void MethodTestObject::voidInvokable() const {}
void MethodTestObject::voidInvokableInt(int) {}
void MethodTestObject::voidInvokableQReal(qreal) {}
void MethodTestObject::voidInvokableQString(const QString &) {}
@@ -184,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");
@@ -665,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()
@@ -677,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()
@@ -691,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);
}
}
@@ -709,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);
}
}
@@ -738,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:
@@ -760,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;
@@ -865,6 +858,61 @@ void tst_QMetaMethod::parameterTypeName()
}
}
+void tst_QMetaMethod::isConst()
+{
+ auto mo = MethodTestObject::staticMetaObject;
+ {
+ const auto normalized = QMetaObject::normalizedSignature("qrealInvokable()");
+ const int idx = mo.indexOfSlot(normalized);
+ QMetaMethod mm = mo.method(idx);
+ QVERIFY(mm.isValid());
+ QCOMPARE(mm.isConst(), false);
+ }
+ {
+ const auto normalized = QMetaObject::normalizedSignature("voidInvokable()");
+ const int idx = mo.indexOfSlot(normalized);
+ QMetaMethod mm = mo.method(idx);
+ QVERIFY(mm.isValid());
+ QCOMPARE(mm.isConst(), true);
+ }
+}
+
+void tst_QMetaMethod::methodIndexes_data()
+{
+ QTest::addColumn<QByteArray>("signature");
+ QTest::addColumn<QMetaMethod::MethodType>("methodType");
+
+ QTest::newRow("constructor1") << QByteArray("MethodTestObject()") << QMetaMethod::Constructor;
+ QTest::newRow("constructor5") << QByteArray("MethodTestObject(CustomUnregisteredType)")
+ << QMetaMethod::Constructor;
+ QTest::newRow("method0") << QByteArray("voidInvokable()") << QMetaMethod::Method;
+ QTest::newRow("method6") << QByteArray("boolInvokable()") << QMetaMethod::Method;
+}
+
+void tst_QMetaMethod::methodIndexes()
+{
+ QFETCH(QByteArray, signature);
+ QFETCH(QMetaMethod::MethodType, methodType);
+
+ const bool isConstructor = methodType == QMetaMethod::Constructor;
+
+ // roundtrip: index = QMetaObject::indexOfConstructor/Method()
+ // <-> method = QMetaObject::constructor/method()
+ // <-> indexThatShouldBeEqualToAboveIndex = QMetaMethod::methodIndex()
+
+ const QMetaObject *mo = &MethodTestObject::staticMetaObject;
+ const int index =
+ isConstructor ? mo->indexOfConstructor(signature) : mo->indexOfMethod(signature);
+ QVERIFY(index != -1);
+
+ QMetaMethod methodFromMetaObject =
+ mo->method(index); // should work on all methods (constructors, signals, ...)
+ const int absoluteMethodIndex =
+ methodFromMetaObject
+ .methodIndex(); // should work on all methods (constructors, signals, ...)
+
+ QCOMPARE(absoluteMethodIndex, index);
+}
QTEST_MAIN(tst_QMetaMethod)
#include "tst_qmetamethod.moc"