summaryrefslogtreecommitdiffstats
path: root/testsuites/samples/cdtest/main.cc
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2016-12-09 08:13:39 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-12-09 08:26:47 +0100
commit8c637ee3243828be703a15335df2f517a5ab493d (patch)
tree368f14cb0df102f54cb33ebfd8f9bdc0b2495164 /testsuites/samples/cdtest/main.cc
parentsptimecounter02: Add plot script (diff)
downloadrtems-8c637ee3243828be703a15335df2f517a5ab493d.tar.bz2
cdtest: Add std::runtime_error() test case
Update #2830.
Diffstat (limited to 'testsuites/samples/cdtest/main.cc')
-rw-r--r--testsuites/samples/cdtest/main.cc41
1 files changed, 26 insertions, 15 deletions
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 <cstdio>
#include <cstdlib>
+#include <stdexcept>
#ifdef RTEMS_TEST_IO_STREAM
#include <iostream>
@@ -35,7 +36,7 @@
const char rtems_test_name[] = "CONSTRUCTOR/DESTRUCTOR";
-extern "C"
+extern "C"
{
#include <tmacros.h>
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" );
}