QTestLib: prepare QVERIFY_THROWS_EXCEPTION for FAILED_ACTION = throw
We can't have a QTEST_FAILED_ACTION in a try-block if we intend to allow QTEST_FAILED_ACTION to be a throw statement. We could, of course, add a whitelisting catch-block for the eventual TestFailedException, but as of now, the intent it to give users full control over the definition of QTEST_FAILED_ACTION, and they may have their own idea of what to throw. So add a bool variable to record whether no exception was thrown and use it to drag QTEST_FAILED_ACTION out of the try block. It's ok to be in catch blocks, no action needed there. Change-Id: I0b004e43b1db82cd8b5b12f900ed985e58a56807 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
8d88f1282b
commit
2502e5a2cb
@ -116,17 +116,20 @@ inline void useVerifyThrowsException() {}
|
|||||||
|
|
||||||
# define QVERIFY_THROWS_EXCEPTION(exceptiontype, ...) \
|
# define QVERIFY_THROWS_EXCEPTION(exceptiontype, ...) \
|
||||||
do {\
|
do {\
|
||||||
|
bool qverify_throws_exception_did_not_throw = false; \
|
||||||
QT_TRY {\
|
QT_TRY {\
|
||||||
__VA_ARGS__; \
|
__VA_ARGS__; \
|
||||||
QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
|
QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
|
||||||
" but no exception caught", __FILE__, __LINE__); \
|
" but no exception caught", __FILE__, __LINE__); \
|
||||||
QTEST_FAIL_ACTION; \
|
qverify_throws_exception_did_not_throw = true; \
|
||||||
} QT_CATCH (const exceptiontype &) { \
|
} QT_CATCH (const exceptiontype &) { \
|
||||||
/* success */ \
|
/* success */ \
|
||||||
} QT_CATCH (...) {\
|
} QT_CATCH (...) {\
|
||||||
QTest::qCaught(#exceptiontype, __FILE__, __LINE__); \
|
QTest::qCaught(#exceptiontype, __FILE__, __LINE__); \
|
||||||
QTEST_FAIL_ACTION; \
|
QTEST_FAIL_ACTION; \
|
||||||
}\
|
}\
|
||||||
|
if (qverify_throws_exception_did_not_throw) \
|
||||||
|
QTEST_FAIL_ACTION; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#else // QT_NO_EXCEPTIONS
|
#else // QT_NO_EXCEPTIONS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user