From 28c79d8c0bbe7d4316c52f0f6f5421c9aa724735 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Sun, 22 Apr 2012 20:47:08 +0200 Subject: Add comparison operators == and != for QMetaMethod This is done in preparation of introducing the QObject::connectNotify(QMetaMethod) function. Together with the forthcoming QMetaMethod::fromSignal() function, which returns the QMetaMethod corresponding to a Qt/C++ signal (member function), the comparison operators provide an effective way of checking which signal was connected to. Change-Id: I2de48628c4884a7174fb8574895f272cb3fe5634 Reviewed-by: Olivier Goffart Reviewed-by: Bradley T. Hughes --- .../corelib/kernel/qmetamethod/tst_qmetamethod.cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp index 55997a3ca0..b5ab61443c 100644 --- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -54,6 +54,8 @@ private slots: void method(); void invalidMethod(); + + void comparisonOperators(); }; struct CustomType { }; @@ -672,5 +674,40 @@ 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)); + } +} + QTEST_MAIN(tst_QMetaMethod) #include "tst_qmetamethod.moc" -- cgit v1.2.3