diff options
Diffstat (limited to 'tests/auto/qglobal/tst_qglobal.cpp')
-rw-r--r-- | tests/auto/qglobal/tst_qglobal.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/qglobal/tst_qglobal.cpp b/tests/auto/qglobal/tst_qglobal.cpp index 62bfd81..49e5d7d 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" |