diff options
Diffstat (limited to 'tests/auto/corelib/kernel/qmetamethod')
-rw-r--r-- | tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp index 55997a3ca0..2858bf64eb 100644 --- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -54,6 +54,10 @@ private slots: void method(); void invalidMethod(); + + void comparisonOperators(); + + void fromSignal(); }; struct CustomType { }; @@ -672,5 +676,65 @@ void tst_QMetaMethod::invalidMethod() QVERIFY(!method3.isValid()); } +void tst_QMetaMethod::comparisonOperators() +{ + static const QMetaObject *mo = &MethodTestObject::staticMetaObject; + for (int x = 0; x < 2; ++x) { + int count = x ? mo->constructorCount() : mo->methodCount(); + for (int i = 0; i < count; ++i) { + QMetaMethod method = x ? mo->constructor(i) : mo->method(i); + const QMetaObject *methodMo = method.enclosingMetaObject(); + for (int j = 0; j < count; ++j) { + 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); + } + + QVERIFY(method != QMetaMethod()); + QVERIFY(QMetaMethod() != method); + QVERIFY(!(method == QMetaMethod())); + QVERIFY(!(QMetaMethod() == method)); + } + } + + // Constructors and normal methods with identical index should not + // compare equal + 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)); + } +} + +void tst_QMetaMethod::fromSignal() +{ +#define FROMSIGNAL_HELPER(ObjectType, Name, Arguments) { \ + void (ObjectType::*signal)Arguments = &ObjectType::Name; \ + const QMetaObject *signalMeta = &ObjectType::staticMetaObject; \ + QCOMPARE(QMetaMethod::fromSignal(signal), \ + signalMeta->method(signalMeta->indexOfSignal(QMetaObject::normalizedSignature(#Name #Arguments)))); \ + } + + FROMSIGNAL_HELPER(MethodTestObject, voidSignal, ()) + FROMSIGNAL_HELPER(MethodTestObject, voidSignalQString, (const QString&)) + FROMSIGNAL_HELPER(QObject, destroyed, (QObject*)) + FROMSIGNAL_HELPER(QObject, objectNameChanged, (const QString &)) + + // Inherited from QObject + FROMSIGNAL_HELPER(MethodTestObject, destroyed, (QObject*)) + FROMSIGNAL_HELPER(MethodTestObject, objectNameChanged, (const QString &)) + + // Methods that are not signals; fromSignal should return invalid method + FROMSIGNAL_HELPER(MethodTestObject, voidSlot, ()) + FROMSIGNAL_HELPER(QObject, deleteLater, ()) + +#undef FROMSIGNAL_HELPER +} + QTEST_MAIN(tst_QMetaMethod) #include "tst_qmetamethod.moc" |