summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/testlib/qtestcase.h3
-rw-r--r--src/testlib/qtestcase.qdoc27
-rw-r--r--tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp8
3 files changed, 26 insertions, 12 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 03667a72a1..fbb756fe23 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -102,6 +102,7 @@ do {\
" but no exception caught", __FILE__, __LINE__);\
return;\
} QT_CATCH (const exceptiontype &) {\
+ /* success */\
}\
} QT_CATCH (const std::exception &e) {\
QByteArray msg = QByteArray() + "Expected exception of type " #exceptiontype \
@@ -111,7 +112,7 @@ do {\
} QT_CATCH (...) {\
QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
" but unknown exception caught", __FILE__, __LINE__);\
- return;\
+ QT_RETHROW;\
}\
} while (false)
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc
index 2cc0038056..2990be7d77 100644
--- a/src/testlib/qtestcase.qdoc
+++ b/src/testlib/qtestcase.qdoc
@@ -159,15 +159,24 @@
\relates QTest
- The QVERIFY_EXCEPTION_THROWN macro executes an \a expression and tries
- to catch an exception thrown from the \a expression. If the \a expression
- throws an exception and its type is the same as \a exceptiontype
- or \a exceptiontype is substitutable with the type of thrown exception
- (i.e. usually the type of thrown exception is publicly derived
- from \a exceptiontype) then execution will be continued. If not-substitutable
- type of exception is thrown or the \a expression doesn't throw an exception
- at all, then a failure will be recorded in the test log and
- the test won't be executed further.
+ The QVERIFY_EXCEPTION_THROWN macro executes \a expression
+ and tries to catch an exception thrown from \a expression.
+
+ There are several possible outcomes:
+
+ \list
+ \li If \a expression throws an exception that is either the same as
+ \a exceptiontype or derived from \a exceptiontype, then execution will continue.
+
+ \li Otherwise, if \a expression throws no exception, or the
+ exception thrown derives from \c{std::exception}, then a failure
+ will be recorded in the test log and the macro returns early
+ (from enclosing function).
+
+ \li If the thrown exception derives neither from \c{std::exception} nor from
+ \a exceptiontype, a failure will be recorded in the test log, and the exception is
+ re-thrown. This avoids problems with e.g. pthread cancellation exceptions.
+ \endlist
\note This macro can only be used in a test function that is invoked
by the test framework.
diff --git a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
index c9365360de..e0e26a0a47 100644
--- a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
+++ b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
@@ -112,12 +112,16 @@ void tst_VerifyExceptionThrown::testCorrectMyExceptions() const
void tst_VerifyExceptionThrown::testFailInt() const
{
- QVERIFY_EXCEPTION_THROWN(throw int(5), double);
+ try {
+ QVERIFY_EXCEPTION_THROWN(throw int(5), double);
+ } catch (int) {}
}
void tst_VerifyExceptionThrown::testFailStdString() const
{
- QVERIFY_EXCEPTION_THROWN(throw std::string("some string"), char*);
+ try {
+ QVERIFY_EXCEPTION_THROWN(throw std::string("some string"), char*);
+ } catch (const std::string &) {}
}
void tst_VerifyExceptionThrown::testFailStdRuntimeError() const