From 76c6ebf3a9a7253f9b19970b0485a085db57033e Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Sat, 23 Mar 2002 00:29:12 +0000 Subject: [PATCH] test ansi / iso exception behavior --- src/libCom/test/Makefile | 4 ++ src/libCom/test/epicsExceptionTest.cpp | 76 ++++++++++++++++++++++ src/libCom/test/epicsExceptionTestMain.cpp | 8 +++ 3 files changed, 88 insertions(+) create mode 100644 src/libCom/test/epicsExceptionTest.cpp create mode 100644 src/libCom/test/epicsExceptionTestMain.cpp diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index 590f30a46..de637d516 100644 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -45,6 +45,10 @@ epicsMutexTestHost_SRCS += epicsMutexTestMain.cpp epicsMutexTest.cpp PROD_HOST += epicsMutexTestHost OBJS_IOC += epicsMutexTest +epicsExceptionTestHost_SRCS += epicsExceptionTestMain.cpp epicsExceptionTest.cpp +PROD_HOST += epicsExceptionTestHost +OBJS_IOC += epicsExceptionTest + #fdmgrTest_SRCS += fdmgrTest.c #PROD_HOST += fdmgrTest diff --git a/src/libCom/test/epicsExceptionTest.cpp b/src/libCom/test/epicsExceptionTest.cpp new file mode 100644 index 000000000..83844ce9f --- /dev/null +++ b/src/libCom/test/epicsExceptionTest.cpp @@ -0,0 +1,76 @@ + +// +// Verify that the local c++ exception mechanism maches the ANSI/ISO standard. +// Author: Jeff Hill +// + +#include +#include + +#include +#include + +#include "epicsThread.h" + +using namespace std; + +class myThread : public epicsThreadRunable { +public: + myThread (); + void waitForCompletion (); +private: + epicsThread thread; + bool done; + void run (); +}; + +static void epicsExceptionTestPrivate () +{ + int excep = false; + try { + new char [LONG_MAX]; + assert ( 0 ); + } + catch ( const bad_alloc & ) { + excep = true; + } + catch ( ... ) { + assert ( 0 ); + } + try { + char * p = new ( nothrow ) char [LONG_MAX]; + assert ( p == 0); + } + catch( ... ) { + assert ( 0 ); + } +} + +myThread::myThread () : + thread ( *this, "testExceptions", epicsThreadGetStackSize(epicsThreadStackSmall) ), + done ( false ) +{ + this->thread.start (); +} + +void myThread::run () +{ + epicsExceptionTestPrivate (); + this->done = true; +} + +void myThread::waitForCompletion () +{ + while ( ! this->done ) { + epicsThreadSleep ( 0.1 ); + } +} + +void epicsExceptionTest () +{ + myThread athread; + + epicsExceptionTestPrivate (); + + athread.waitForCompletion (); +} diff --git a/src/libCom/test/epicsExceptionTestMain.cpp b/src/libCom/test/epicsExceptionTestMain.cpp new file mode 100644 index 000000000..0ef0e80a0 --- /dev/null +++ b/src/libCom/test/epicsExceptionTestMain.cpp @@ -0,0 +1,8 @@ + +void epicsExceptionTest (); + +int main () +{ + epicsExceptionTest (); + return 0; +} \ No newline at end of file