From 8c637ee3243828be703a15335df2f517a5ab493d Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Fri, 9 Dec 2016 08:13:39 +0100 Subject: cdtest: Add std::runtime_error() test case Update #2830. --- testsuites/samples/cdtest/main.cc | 41 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'testsuites/samples/cdtest/main.cc') diff --git a/testsuites/samples/cdtest/main.cc b/testsuites/samples/cdtest/main.cc index 8aea62f495..fb015fa7ac 100644 --- a/testsuites/samples/cdtest/main.cc +++ b/testsuites/samples/cdtest/main.cc @@ -28,6 +28,7 @@ #include #include +#include #ifdef RTEMS_TEST_IO_STREAM #include @@ -35,7 +36,7 @@ const char rtems_test_name[] = "CONSTRUCTOR/DESTRUCTOR"; -extern "C" +extern "C" { #include extern rtems_task main_task(rtems_task_argument); @@ -81,7 +82,7 @@ protected: class BClass : public AClass { public: - BClass(const char *p = "LOCAL" ) : AClass( p ) + BClass(const char *p = "LOCAL" ) : AClass( p ) { num_inst++; printf( @@ -112,21 +113,21 @@ public: }; -class RtemsException +class RtemsException { public: - + RtemsException( const char *module, int ln, int err = 0 ) : error( err ), line( ln ), file( module ) { printf( "RtemsException raised=File:%s, Line:%d, Error=%X\n", - file, line, error ); + file, line, error ); } void show() { printf( "RtemsException ---> File:%s, Line:%d, Error=%X\n", - file, line, error ); + file, line, error ); } private: @@ -165,19 +166,19 @@ cdtest(void) static void foo_function() { - try + try { - throw "foo_function() throw this exception"; + throw "foo_function() throw this exception"; } catch( const char *e ) { printf( "foo_function() catch block called:\n < %s >\n", e ); - throw "foo_function() re-throwing execption..."; + throw "foo_function() re-throwing execption..."; } } rtems_task main_task( - rtems_task_argument + rtems_task_argument ) { TEST_BEGIN(); @@ -188,7 +189,7 @@ rtems_task main_task( printf( "*** TESTING C++ EXCEPTIONS ***\n\n" ); - try + try { foo_function(); } @@ -196,17 +197,27 @@ rtems_task main_task( { printf( "Success catching a char * exception\n%s\n", e ); } - try + + try + { + throw std::runtime_error("thrown std::runtime object"); + } + catch (std::exception const& e) + { + printf("throw std::runtime: caught: %s\n", e.what()); + } + + try { printf( "throw an instance based exception\n" ); - throw RtemsException( __FILE__, __LINE__, 0x55 ); + throw RtemsException( __FILE__, __LINE__, 0x55 ); } - catch( RtemsException & ex ) + catch( RtemsException & ex ) { printf( "Success catching RtemsException...\n" ); ex.show(); } - catch(...) + catch(...) { printf( "Caught another exception.\n" ); } -- cgit v1.2.3