test ansi / iso exception behavior
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
76
src/libCom/test/epicsExceptionTest.cpp
Normal file
76
src/libCom/test/epicsExceptionTest.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
//
|
||||
// Verify that the local c++ exception mechanism maches the ANSI/ISO standard.
|
||||
// Author: Jeff Hill
|
||||
//
|
||||
|
||||
#include <new>
|
||||
#include <iostream>
|
||||
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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 ();
|
||||
}
|
||||
8
src/libCom/test/epicsExceptionTestMain.cpp
Normal file
8
src/libCom/test/epicsExceptionTestMain.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
void epicsExceptionTest ();
|
||||
|
||||
int main ()
|
||||
{
|
||||
epicsExceptionTest ();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user