summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-04-22 20:47:08 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-25 20:16:56 +0200
commit28c79d8c0bbe7d4316c52f0f6f5421c9aa724735 (patch)
tree0429012ccf81d45dbb4f6dcdb084ed275bd69302 /tests/auto
parent6624151c6a8772a3f01a291f744ea72b469106fc (diff)
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 <ogoffart@woboq.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp37
1 files changed, 37 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..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"