From a5580b915ecedf8d840b15bde1f8e664f91296fc Mon Sep 17 00:00:00 2001 From: mutouyun Date: Mon, 17 Dec 2018 13:44:48 +0800 Subject: [PATCH] define QVERIFY_EXCEPTION_THROWN if it's not exist --- test/test_circ.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_circ.cpp b/test/test_circ.cpp index b42d2a5..af1be9b 100644 --- a/test/test_circ.cpp +++ b/test/test_circ.cpp @@ -320,6 +320,30 @@ void Unit::test_prod_cons_performance() { test_prod_cons <3 , 3 >(); // test & verify } +#ifndef QVERIFY_EXCEPTION_THROWN +#define QVERIFY_EXCEPTION_THROWN(expression, exceptiontype) \ +do {\ + QT_TRY {\ + QT_TRY {\ + expression;\ + QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \ + " but no exception caught", __FILE__, __LINE__);\ + return;\ + } QT_CATCH (const exceptiontype &) {\ + }\ + } QT_CATCH (const std::exception &e) {\ + QByteArray msg = QByteArray() + "Expected exception of type " #exceptiontype \ + " to be thrown but std::exception caught with message: " + e.what(); \ + QTest::qFail(msg.constData(), __FILE__, __LINE__);\ + return;\ + } QT_CATCH (...) {\ + QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \ + " but unknown exception caught", __FILE__, __LINE__);\ + return;\ + }\ +} while (false) +#endif/*!QVERIFY_EXCEPTION_THROWN*/ + void Unit::test_queue() { ipc::circ::queue queue; queue.push(1, 2);