summaryrefslogtreecommitdiffstats
path: root/tests/auto/qglobal
diff options
context:
space:
mode:
authorRobert Griebl <rgriebl@trolltech.com>2009-06-10 13:46:23 +0200
committerRobert Griebl <rgriebl@trolltech.com>2009-06-10 13:46:23 +0200
commit7604f8087f88171ef933d8ae08f501467e647338 (patch)
tree51d071f462ed48d0b25884d9f62b8ba11c5dff13 /tests/auto/qglobal
parent8c265860b41214daade7c8a28237c1e07ea71a3c (diff)
Make Qt exception safer.
Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions, which also contains the full history. Rev-By: Harald Fernengel Rev-By: Ralf Engels
Diffstat (limited to 'tests/auto/qglobal')
-rw-r--r--tests/auto/qglobal/tst_qglobal.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/qglobal/tst_qglobal.cpp b/tests/auto/qglobal/tst_qglobal.cpp
index 88fbcd283e..b4d42e451b 100644
--- a/tests/auto/qglobal/tst_qglobal.cpp
+++ b/tests/auto/qglobal/tst_qglobal.cpp
@@ -50,6 +50,7 @@ private slots:
void qInternalCallbacks();
void for_each();
void qassert();
+ void qtry();
};
void tst_QGlobal::qIsNull()
@@ -190,5 +191,66 @@ void tst_QGlobal::qassert()
QVERIFY(passed);
}
+void tst_QGlobal::qtry()
+{
+ int i = 0;
+ QT_TRY {
+ i = 1;
+ QT_THROW(42);
+ i = 2;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 1);
+ i = 7;
+ }
+#ifdef QT_NO_EXCEPTIONS
+ QCOMPARE(i, 2);
+#else
+ QCOMPARE(i, 7);
+#endif
+
+ // check propper if/else scoping
+ i = 0;
+ if (true)
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 4;
+ }
+ else
+ QCOMPARE(i, 0);
+ QCOMPARE(i, 4);
+
+ i = 0;
+ if (false)
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 2;
+ }
+ else
+ i = 8;
+ QCOMPARE(i, 8);
+
+ i = 0;
+ if (false)
+ i = 42;
+ else
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 4;
+ }
+ QCOMPARE(i, 4);
+}
+
QTEST_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"