00001 #ifndef TUT_RESULT_H_GUARD
00002 #define TUT_RESULT_H_GUARD
00003 #include <tut/tut_config.hpp>
00004
00005 #include <string>
00006
00007 #if defined(TUT_USE_RTTI)
00008 #if (defined(_MSC_VER) && !defined(_CPPRTTI)) || (defined(__GNUC__) && !defined(__GXX_RTTI))
00009 #undef TUT_USE_RTTI
00010 #endif
00011 #endif
00012
00013 #if defined(TUT_USE_RTTI)
00014 #include <typeinfo>
00015 #endif
00016
00017 namespace tut
00018 {
00019
00020 #if defined(TUT_USE_RTTI)
00021 template<typename T>
00022 inline std::string type_name(const T& t)
00023 {
00024 return typeid(t).name();
00025 }
00026 #else
00027 template<typename T>
00028 inline std::string type_name(const T& t)
00029 {
00030 return "Unknown type, RTTI disabled";
00031 }
00032
00033 inline std::string type_name(const std::exception&)
00034 {
00035 return "Unknown std::exception, RTTI disabled";
00036 }
00037 #endif
00038
00039
00040 #if defined(TUT_USE_POSIX)
00041 struct test_result_posix
00042 {
00043 test_result_posix()
00044 : pid(getpid())
00045 {
00046 }
00047
00048 virtual ~test_result_posix()
00049 {
00050 }
00051
00052 pid_t pid;
00053 };
00054 #else
00055 struct test_result_posix
00056 {
00057 virtual ~test_result_posix()
00058 {
00059 }
00060 };
00061 #endif
00062
00069 struct test_result : public test_result_posix
00070 {
00074 std::string group;
00075
00079 int test;
00080
00084 std::string name;
00085
00089 enum result_type
00090 {
00091 ok,
00092 fail,
00093 ex,
00094 warn,
00095 term,
00096 ex_ctor,
00097 rethrown,
00098 skipped,
00099 dummy
00100 };
00101
00102 result_type result;
00103
00107 std::string message;
00108 std::string exception_typeid;
00109
00113 test_result()
00114 : group(),
00115 test(0),
00116 name(),
00117 result(ok),
00118 message(),
00119 exception_typeid()
00120 {
00121 }
00122
00126 test_result(const std::string& grp, int pos,
00127 const std::string& test_name, result_type res)
00128 : group(grp),
00129 test(pos),
00130 name(test_name),
00131 result(res),
00132 message(),
00133 exception_typeid()
00134 {
00135 }
00136
00140 test_result(const std::string& grp,int pos,
00141 const std::string& test_name, result_type res,
00142 const std::exception& ex)
00143 : group(grp),
00144 test(pos),
00145 name(test_name),
00146 result(res),
00147 message(ex.what()),
00148 exception_typeid(type_name(ex))
00149 {
00150 }
00151
00154 test_result(const std::string& grp,int pos,
00155 const std::string& test_name, result_type res,
00156 const std::string& ex_typeid,
00157 const std::string& msg)
00158 : group(grp),
00159 test(pos),
00160 name(test_name),
00161 result(res),
00162 message(msg),
00163 exception_typeid(ex_typeid)
00164 {
00165 }
00166
00167 virtual ~test_result()
00168 {
00169 }
00170 };
00171
00172 }
00173
00174 #endif