summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-11-26 22:30:27 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-11-26 22:35:48 +0100
commit4a8273a6fc2e741e811cf5dabc9a3c240306cf7f (patch)
tree2148abc88f8543eecdc0b97b2dd92594836af9b2 /tests/auto/corelib/kernel/qobject/tst_qobject.cpp
parent036c5db468164297d213764c59a4b59daa76d90a (diff)
parent1c2be58fecaff1de5f2849192eb712984ebd59bd (diff)
Merge remote-tracking branch 'origin/stable' into dev
For the conflicts in msvc_nmake.cpp the ifdefs are extended since we need to support windows phone in the target branch while it is not there in the current stable branch (as of Qt 5.2). Conflicts: configure qmake/generators/win32/msvc_nmake.cpp src/3rdparty/angle/src/libEGL/Surface.cpp src/angle/src/common/common.pri src/corelib/global/qglobal.h src/corelib/io/qstandardpaths.cpp src/plugins/platforms/qnx/qqnxintegration.cpp src/plugins/platforms/qnx/qqnxscreeneventhandler.h src/plugins/platforms/xcb/qglxintegration.h src/widgets/kernel/win.pri tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp tools/configure/configureapp.cpp Change-Id: I00b579eefebaf61d26ab9b00046d2b5bd5958812
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index f429500077..e4804e6079 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -152,6 +152,7 @@ private slots:
void contextDoesNotLeakFunctor();
void connectBase();
void qmlConnect();
+ void exceptions();
};
struct QObjectCreatedOnShutdown
@@ -6185,6 +6186,102 @@ void tst_QObject::qmlConnect()
#endif
}
+#ifndef QT_NO_EXCEPTIONS
+class ObjectException : public std::exception { };
+
+struct ThrowFunctor
+{
+ CountedStruct operator()(const CountedStruct &, CountedStruct s2) const
+ {
+ throw ObjectException();
+ return s2;
+ }
+ CountedStruct s;
+};
+#endif
+
+class ExceptionThrower : public QObject
+{
+ Q_OBJECT
+public slots:
+ CountedStruct throwException(const CountedStruct &, CountedStruct s2)
+ {
+#ifndef QT_NO_EXCEPTIONS
+ throw ObjectException();
+#endif
+ return s2;
+ }
+signals:
+ CountedStruct mySignal(const CountedStruct &s1, CountedStruct s2);
+};
+
+void tst_QObject::exceptions()
+{
+#ifndef QT_NO_EXCEPTIONS
+ ReceiverObject receiver;
+
+ // String based syntax
+ {
+ QCOMPARE(countedStructObjectsCount, 0);
+ ExceptionThrower thrower;
+ receiver.reset();
+
+ connect(&thrower, SIGNAL(mySignal(CountedStruct,CountedStruct)), &receiver, SLOT(slot1()));
+ connect(&thrower, SIGNAL(mySignal(CountedStruct,CountedStruct)), &thrower, SLOT(throwException(CountedStruct,CountedStruct)));
+ connect(&thrower, SIGNAL(mySignal(CountedStruct,CountedStruct)), &receiver, SLOT(slot2()));
+ try {
+ CountedStruct s;
+ emit thrower.mySignal(s, s);
+ QFAIL("Exception not thrown?");
+ } catch (ObjectException&) {}
+ QCOMPARE(receiver.count_slot1, 1);
+ QCOMPARE(receiver.count_slot2, 0);
+ QCOMPARE(countedStructObjectsCount, 0);
+ }
+ // Pointer to member function
+ {
+ QCOMPARE(countedStructObjectsCount, 0);
+ ExceptionThrower thrower;
+ receiver.reset();
+
+ connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot1);
+ connect(&thrower, &ExceptionThrower::mySignal, &thrower, &ExceptionThrower::throwException);
+ connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot2);
+ try {
+ CountedStruct s;
+ emit thrower.mySignal(s, s);
+ QFAIL("Exception not thrown?");
+ } catch (ObjectException&) {}
+ QCOMPARE(receiver.count_slot1, 1);
+ QCOMPARE(receiver.count_slot2, 0);
+ QCOMPARE(countedStructObjectsCount, 0);
+ }
+ // Functor
+ {
+ QCOMPARE(countedStructObjectsCount, 0);
+ ExceptionThrower thrower;
+ receiver.reset();
+
+ connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot1);
+ connect(&thrower, &ExceptionThrower::mySignal, ThrowFunctor());
+ connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot2);
+ try {
+ CountedStruct s;
+ emit thrower.mySignal(s, s);
+ QFAIL("Exception not thrown?");
+ } catch (ObjectException&) {}
+ QCOMPARE(receiver.count_slot1, 1);
+ QCOMPARE(receiver.count_slot2, 0);
+ QCOMPARE(countedStructObjectsCount, 1); // the Functor
+ }
+ QCOMPARE(countedStructObjectsCount, 0);
+
+
+#else
+ QSKIP("Needs exceptions");
+#endif
+}
+
// Test for QtPrivate::HasQ_OBJECT_Macro
Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value);
Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value);