diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-08-09 10:50:37 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2022-08-10 00:48:31 +0200 |
commit | cec3b3b4f90a1db642b8c3e03c493ab7d6c5f8a5 (patch) | |
tree | c09635309c10920000078d6978e78d37c8f6bc56 /tests/auto/corelib/kernel | |
parent | 395c9ac731e3789f336bad09cb4a8918a73be43d (diff) |
Remove assertion from ownMethodIndex that breaks tests
ownMethodIndex works for all kind of methods, also for constructors.
Therefore, remove the assertion there (that checks for non constructors)
and add a test in qtbase so it does not happen again.
The test broken by the assertion is in qtdeclarative:
tst_QJSEngine::newQMetaObject().
Also rename QMetaMethodPrivate::ownConstructorIndex() to
ownConstructorMethodIndex() as the previous naming implied that
ownMethodIndex() could not be used for constructors.
amends b73ab954dffffc462b6f6efe5a2dd97efeab0038
Task-number: QTBUG-105360
Change-Id: I0244993ed79bee055645b5443f5d02e1c089a6c6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp index 2b8ef8358d..4cc15159e7 100644 --- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -32,6 +32,9 @@ private slots: void parameterTypeName(); void isConst(); + + void methodIndexes_data(); + void methodIndexes(); }; struct CustomType { }; @@ -862,6 +865,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" |