diff options
author | mread <qt-info@nokia.com> | 2009-09-10 07:40:54 (GMT) |
---|---|---|
committer | mread <qt-info@nokia.com> | 2009-09-10 07:47:30 (GMT) |
commit | 680cbc408e7aadf19f58da2d65495e5e8e6d37b0 (patch) | |
tree | 695ab307b3d8c254cc6ee209c500670f8e4f6471 /tests | |
parent | 08b54f274d57e4735d0042e295237f176506433d (diff) | |
download | Qt-680cbc408e7aadf19f58da2d65495e5e8e6d37b0.zip Qt-680cbc408e7aadf19f58da2d65495e5e8e6d37b0.tar.gz Qt-680cbc408e7aadf19f58da2d65495e5e8e6d37b0.tar.bz2 |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index e3a70e9..420962d 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); |