summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2013-10-05 20:24:14 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-05 17:37:05 +0100
commit94ad841ab547e98da111ac41f235cb94cf2d0a45 (patch)
tree0e008613acb824939943104e4609b8086914df77 /tests
parent73efc9a2cd9839c75eb8bd1449ce23232ac0d306 (diff)
Test that QMetaObject::invokeMethod is exception safe
Change-Id: Ie4662b7e475dc3d1ce9f36e8219361d9507622b4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
index 870e65f0cc..3afc2bc574 100644
--- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
@@ -155,6 +155,7 @@ private slots:
void invokeCustomTypes();
void invokeMetaConstructor();
void invokeTypedefTypes();
+ void invokeException();
void qtMetaObjectInheritance();
void normalizedSignature_data();
void normalizedSignature();
@@ -301,6 +302,19 @@ void tst_QMetaObject::connectSlotsByName()
struct MyUnregisteredType { };
+static int countedStructObjectsCount = 0;
+struct CountedStruct
+{
+ CountedStruct() { ++countedStructObjectsCount; }
+ CountedStruct(const CountedStruct &) { ++countedStructObjectsCount; }
+ CountedStruct &operator=(const CountedStruct &) { return *this; }
+ ~CountedStruct() { --countedStructObjectsCount; }
+};
+
+#ifndef QT_NO_EXCEPTIONS
+class ObjectException : public std::exception { };
+#endif
+
class QtTestObject: public QObject
{
friend class tst_QMetaObject;
@@ -340,6 +354,13 @@ public slots:
void slotWithUnregisteredParameterType(MyUnregisteredType);
+ CountedStruct throwingSlot(const CountedStruct &, CountedStruct s2) {
+#ifndef QT_NO_EXCEPTIONS
+ throw ObjectException();
+#endif
+ return s2;
+ }
+
signals:
void sig0();
QString sig1(QString s1);
@@ -847,6 +868,23 @@ void tst_QMetaObject::invokeTypedefTypes()
QCOMPARE(spy.at(0).at(0), QVariant(arg));
}
+void tst_QMetaObject::invokeException()
+{
+#ifndef QT_NO_EXCEPTIONS
+ QtTestObject obj;
+ QCOMPARE(countedStructObjectsCount, 0);
+ try {
+ CountedStruct s;
+ QVERIFY(QMetaObject::invokeMethod(&obj, "throwingSlot", Q_RETURN_ARG(CountedStruct, s),
+ Q_ARG(CountedStruct, s), Q_ARG(CountedStruct, s)));
+ QFAIL("Did not throw");
+ } catch(ObjectException &) {}
+ QCOMPARE(countedStructObjectsCount, 0);
+#else
+ QSKIP("Needs exceptions");
+#endif
+}
+
void tst_QMetaObject::normalizedSignature_data()
{
QTest::addColumn<QString>("signature");