summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2013-02-05 14:35:10 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-21 14:54:00 +0100
commit03b25125986f083a260b421abeed1f1d088d27b3 (patch)
tree307f0e248f006cbc9dc7f85abf900ee886f4a769 /tests
parent8fd1330029eafc3f9496febd1ac2597e786ba324 (diff)
Fix QMetaType of const references
This fixes QMetaType detection of const reference arguments in signals while connecting using the new syntax and Qt::QueuedConnection const references should have the same QMetaType as non references. That means we need to remove the const reference while getting the QMetaType. Change-Id: I9b2688da7fb9ae985aec0d8fa62a1165357ffe71 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp12
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp20
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 7f7486ef4b..9a75bad549 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -110,6 +110,7 @@ private slots:
void saveAndLoadCustom();
void metaObject();
void constexprMetaTypeIds();
+ void constRefs();
};
struct Foo { int i; };
@@ -1762,6 +1763,17 @@ void tst_QMetaType::constexprMetaTypeIds()
#endif
}
+void tst_QMetaType::constRefs()
+{
+ QCOMPARE(::qMetaTypeId<const int &>(), ::qMetaTypeId<int>());
+ QCOMPARE(::qMetaTypeId<const QString &>(), ::qMetaTypeId<QString>());
+ QCOMPARE(::qMetaTypeId<const CustomMovable &>(), ::qMetaTypeId<CustomMovable>());
+ QCOMPARE(::qMetaTypeId<const QList<CustomMovable> &>(), ::qMetaTypeId<QList<CustomMovable> >());
+#if defined(Q_COMPILER_CONSTEXPR)
+ Q_STATIC_ASSERT(::qMetaTypeId<const int &>() == ::qMetaTypeId<int>());
+#endif
+}
+
// Compile-time test, it should be possible to register function pointer types
class Undefined;
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index a6d1d9f14d..c3ecf419e0 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -1446,9 +1447,11 @@ public:
public slots:
void slot1(CustomType ct);
+ void slot2(const QList<CustomType> &ct);
signals:
void signal1(CustomType ct);
+ void signal2(const QList<CustomType> &ct);
public:
CustomType received;
@@ -1457,6 +1460,8 @@ public:
void QCustomTypeChecker::slot1(CustomType ct)
{ received = ct; }
+void QCustomTypeChecker::slot2(const QList< CustomType >& ct)
+{ received = ct[0]; }
void tst_QObject::customTypes()
{
@@ -4667,6 +4672,21 @@ void tst_QObject::customTypesPointer()
QCOMPARE(qRegisterMetaType<CustomType>("CustomType"), idx);
QCOMPARE(QMetaType::type("CustomType"), idx);
QVERIFY(QMetaType::isRegistered(idx));
+
+ // Test auto registered type (QList<CustomType>)
+ QList<CustomType> list;
+ QCOMPARE(instanceCount, 4);
+ list.append(t1);
+ QCOMPARE(instanceCount, 5);
+ QVERIFY(connect(&checker, &QCustomTypeChecker::signal2,
+ &checker, &QCustomTypeChecker::slot2, Qt::QueuedConnection));
+ emit checker.signal2(list);
+ QCOMPARE(instanceCount, 5); //because the list is implicitly shared.
+ list.clear();
+ QCOMPARE(instanceCount, 5);
+ QCoreApplication::processEvents();
+ QCOMPARE(checker.received.value(), t1.value());
+ QCOMPARE(instanceCount, 4);
}
QCOMPARE(instanceCount, 3);
}