summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 52bf8e9004..0f7f75fb2e 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -6548,6 +6548,29 @@ signals:
CountedStruct mySignal(const CountedStruct &s1, CountedStruct s2);
};
+class CountedExceptionThrower : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit CountedExceptionThrower(bool throwException, QObject *parent = Q_NULLPTR)
+ : QObject(parent)
+ {
+ if (throwException)
+ throw ObjectException();
+ ++counter;
+ }
+
+ ~CountedExceptionThrower()
+ {
+ --counter;
+ }
+
+ static int counter;
+};
+
+int CountedExceptionThrower::counter = 0;
+
void tst_QObject::exceptions()
{
#ifndef QT_NO_EXCEPTIONS
@@ -6609,6 +6632,59 @@ void tst_QObject::exceptions()
}
QCOMPARE(countedStructObjectsCount, 0);
+ // Child object reaping in case of exceptions thrown by constructors
+ {
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+
+ try {
+ class ParentObject : public QObject {
+ public:
+ explicit ParentObject(QObject *parent = Q_NULLPTR)
+ : QObject(parent)
+ {
+ new CountedExceptionThrower(false, this);
+ new CountedExceptionThrower(false, this);
+ new CountedExceptionThrower(true, this); // throws
+ }
+ };
+
+ ParentObject p;
+ QFAIL("Exception not thrown");
+ } catch (const ObjectException &) {
+ } catch (...) {
+ QFAIL("Wrong exception thrown");
+ }
+
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+
+ try {
+ QObject o;
+ new CountedExceptionThrower(false, &o);
+ new CountedExceptionThrower(false, &o);
+ new CountedExceptionThrower(true, &o); // throws
+
+ QFAIL("Exception not thrown");
+ } catch (const ObjectException &) {
+ } catch (...) {
+ QFAIL("Wrong exception thrown");
+ }
+
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+
+ try {
+ QObject o;
+ CountedExceptionThrower c1(false, &o);
+ CountedExceptionThrower c2(false, &o);
+ CountedExceptionThrower c3(true, &o); // throws
+
+ QFAIL("Exception not thrown");
+ } catch (const ObjectException &) {
+ } catch (...) {
+ QFAIL("Wrong exception thrown");
+ }
+
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+ }
#else
QSKIP("Needs exceptions");