From 680cbc408e7aadf19f58da2d65495e5e8e6d37b0 Mon Sep 17 00:00:00 2001 From: mread Date: Thu, 10 Sep 2009 08:40:54 +0100 Subject: Make exception safety test work with XML output and warnings The QTestLib XML output system throws exceptions when the system is out of memory, which is normally quite reasonable. However when it is used to report warnings during a catch block, this terminates the program. So this change temporarily disables allocation failures while the warning is being recorded. Reviewed-by: Jason Barron --- .../tst_exceptionsafety_objects.cpp | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index e3a70e9920..420962d2d1 100644 --- a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp +++ b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp @@ -49,8 +49,8 @@ QT_USE_NAMESPACE // this test only works with // * GLIBC // * MSVC - only debug builds (we need the crtdbg.h helpers) -// * SYMBIAN - only when __UHEAP_BURSTFAILNEXT is available -#if (defined(QT_NO_EXCEPTIONS) || (!defined(__GLIBC__) && !defined(Q_CC_MSVC) && (!defined(Q_OS_SYMBIAN) || !defined(__UHEAP_BURSTFAILNEXT)))) && !defined(Q_MOC_RUN) +// * SYMBIAN +#if (defined(QT_NO_EXCEPTIONS) || (!defined(__GLIBC__) && !defined(Q_CC_MSVC) && !defined(Q_OS_SYMBIAN))) && !defined(Q_MOC_RUN) QTEST_NOOP_MAIN #else @@ -65,6 +65,7 @@ class tst_ExceptionSafetyObjects: public QObject public slots: void initTestCase(); + void cleanupTestCase(); private slots: void objects_data(); @@ -81,6 +82,10 @@ private slots: void linkedList_data(); void linkedList(); + +private: + static QtMsgHandler testMessageHandler; + static void safeMessageHandler(QtMsgType, const char *); }; // helper structs to create an arbitrary widget @@ -268,8 +273,22 @@ public: } }; +QtMsgHandler tst_ExceptionSafetyObjects::testMessageHandler; + +void tst_ExceptionSafetyObjects::safeMessageHandler(QtMsgType type, const char *msg) +{ + // this temporarily suspends OOM testing while handling a message + int currentIndex = mallocFailIndex; + AllocFailer allocFailer(0); + allocFailer.deactivate(); + (*testMessageHandler)(type, msg); + allocFailer.reactivateAt(currentIndex); +} + void tst_ExceptionSafetyObjects::initTestCase() { + testMessageHandler = qInstallMsgHandler(safeMessageHandler); + QVERIFY(AllocFailer::initialize()); // sanity check whether OOM simulation works @@ -307,6 +326,11 @@ void tst_ExceptionSafetyObjects::initTestCase() QCOMPARE(malloc2Failed, 1); } +void tst_ExceptionSafetyObjects::cleanupTestCase() +{ + qInstallMsgHandler(testMessageHandler); +} + void tst_ExceptionSafetyObjects::objects() { QFETCH(AbstractTester *, objectCreator); -- cgit v1.2.3