summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-08-18 16:36:53 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-08-28 00:41:00 +0200
commit4d5a048d96f1161e2059315d0fe350fdcebb2e05 (patch)
treeaf326c4ac72a449d9a168d657a68c96567fe2ca3 /tests
parent462b36c3dee591bd964670dc614b995ece335331 (diff)
Improve connect: Use existing metatypes if possible
As there is now a chance that a QMetaMethod already contains the metatypes for its arguments, we can just query it directly (and use the fallback to name lookup logic that already exists there). This also allows us to avoid creating a QList of names, and only requires us to do a name lookup in case the connection actually fails. Change-Id: Idda30bc4b538a94476ae6c533776c22340f0030d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
index 03c76aba5d..942f075723 100644
--- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
+++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
@@ -52,6 +52,8 @@ private slots:
void returnMetaType();
void parameterMetaType();
+
+ void parameterTypeName();
};
struct CustomType { };
@@ -632,6 +634,12 @@ void tst_QMetaMethod::method()
QCOMPARE(QMetaType::fromName(method.typeName()), QMetaType::fromName(returnTypeName));
}
+ // check that parameterNames and parameterTypeName agree
+ const auto methodParmaterTypes = method.parameterTypes();
+ for (int i = 0; i< methodParmaterTypes.size(); ++i) {
+ QCOMPARE(methodParmaterTypes[i], method.parameterTypeName(i));
+ }
+
if (method.parameterTypes() != parameterTypeNames) {
// QMetaMethod should always produce semantically equivalent typenames
QList<QByteArray> actualTypeNames = method.parameterTypes();
@@ -839,5 +847,24 @@ void tst_QMetaMethod::parameterMetaType()
}
+void tst_QMetaMethod::parameterTypeName()
+{
+ auto mo = MyTestClass::staticMetaObject;
+ const auto normalized = QMetaObject::normalizedSignature("doStuff(int, float, MyGadget)");
+ const int idx = mo.indexOfSlot(normalized);
+ QMetaMethod mm = mo.method(idx);
+ {
+ // check invalid indices
+ QVERIFY(mm.parameterTypeName(-1).isEmpty());
+ QVERIFY(mm.parameterTypeName(3).isEmpty());
+ }
+ {
+ QCOMPARE(mm.parameterTypeName(0), QByteArray("int"));
+ QCOMPARE(mm.parameterTypeName(1), QByteArray("float"));
+ QCOMPARE(mm.parameterTypeName(2), QByteArray("MyGadget"));
+ }
+}
+
+
QTEST_MAIN(tst_QMetaMethod)
#include "tst_qmetamethod.moc"