tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp
changeset 22 79de32ba3296
parent 18 2f34d5167611
equal deleted inserted replaced
19:fcece45ef507 22:79de32ba3296
    41 
    41 
    42 #include <QtGui/QtGui>
    42 #include <QtGui/QtGui>
    43 #include <QtTest/QtTest>
    43 #include <QtTest/QtTest>
    44 
    44 
    45 #include <stddef.h>
    45 #include <stddef.h>
       
    46 #include <exception>
    46 
    47 
    47 QT_USE_NAMESPACE
    48 QT_USE_NAMESPACE
    48 
    49 
    49 // this test only works with
    50 // this test only works with
    50 //   * GLIBC
    51 //   * GLIBC
   283     allocFailer.deactivate();
   284     allocFailer.deactivate();
   284     (*testMessageHandler)(type, msg);
   285     (*testMessageHandler)(type, msg);
   285     allocFailer.reactivateAt(currentIndex);
   286     allocFailer.reactivateAt(currentIndex);
   286 }
   287 }
   287 
   288 
       
   289 typedef void (*PVF)();
       
   290 PVF defaultTerminate;
       
   291 void debugTerminate()
       
   292 {
       
   293     // you can detect uncaught exceptions with a breakpoint in here
       
   294     (*defaultTerminate)();
       
   295 }
       
   296 
       
   297 PVF defaultUnexpected;
       
   298 void debugUnexpected()
       
   299 {
       
   300     // you can detect unexpected exceptions with a breakpoint in here
       
   301     (*defaultUnexpected)();
       
   302 }
       
   303 
   288 void tst_ExceptionSafetyObjects::initTestCase()
   304 void tst_ExceptionSafetyObjects::initTestCase()
   289 {
   305 {
       
   306     // set handlers for bad exception cases, you might want to step in and breakpoint the default handlers too
       
   307     defaultTerminate = std::set_terminate(&debugTerminate);
       
   308     defaultUnexpected = std::set_unexpected(&debugUnexpected);
   290     testMessageHandler = qInstallMsgHandler(safeMessageHandler);
   309     testMessageHandler = qInstallMsgHandler(safeMessageHandler);
   291 
   310 
   292     QVERIFY(AllocFailer::initialize());
   311     QVERIFY(AllocFailer::initialize());
   293 
   312 
   294     // sanity check whether OOM simulation works
   313     // sanity check whether OOM simulation works