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>
This commit is contained in:
parent
73efc9a2cd
commit
94ad841ab5
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user