00001 #ifndef UNITTEST_EXECUTE_TEST_H
00002 #define UNITTEST_EXECUTE_TEST_H
00003
00004 #include "TestDetails.h"
00005 #include "MemoryOutStream.h"
00006 #include "AssertException.h"
00007 #include "CurrentTest.h"
00008
00009 #ifdef UNITTEST_POSIX
00010 #include "Posix/SignalTranslator.h"
00011 #endif
00012
00013 namespace UnitTest {
00014
00015 template< typename T >
00016 void ExecuteTest(T& testObject, TestDetails const& details)
00017 {
00018 CurrentTest::Details() = &details;
00019
00020 try
00021 {
00022 #ifdef UNITTEST_POSIX
00023 UNITTEST_THROW_SIGNALS
00024 #endif
00025 testObject.RunImpl();
00026 }
00027 catch (AssertException const& e)
00028 {
00029 CurrentTest::Results()->OnTestFailure(
00030 TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what());
00031 }
00032 catch (std::exception const& e)
00033 {
00034 MemoryOutStream stream;
00035 stream << "Unhandled exception: " << e.what();
00036 CurrentTest::Results()->OnTestFailure(details, stream.GetText());
00037 }
00038 catch (...)
00039 {
00040 CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!");
00041 }
00042 }
00043
00044 }
00045
00046 #endif