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.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
index 2b8ef8358d..47012f9a28 100644
--- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
+++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
@@ -1,6 +1,6 @@
// 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>
@@ -22,6 +22,7 @@ private slots:
void comparisonOperators();
void fromSignal();
+ void fromSignalOfNullSignalIsInvalid();
void gadget();
void revision();
@@ -32,6 +33,9 @@ private slots:
void parameterTypeName();
void isConst();
+
+ void methodIndexes_data();
+ void methodIndexes();
};
struct CustomType { };
@@ -716,6 +720,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:
@@ -862,6 +872,42 @@ void tst_QMetaMethod::isConst()
}
}
+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"