00001 #ifndef UNIT_BASE_GROUP
00002 #define UNIT_BASE_GROUP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00017
00021 #include <basis/astring.h>
00022 #include <basis/contracts.h>
00023 #include <basis/enhance_cpp.h>
00024 #include <basis/mutex.h>
00025 #include <structures/string_table.h>
00026
00027 namespace unit_test {
00028
00029
00030
00031
00032
00033
00034
00035 #define UNIT_BASE_THIS_OBJECT (*this)
00036
00037
00038 #define ASSERT_EQUAL(a, b, test_name) { \
00039 BASE_FUNCTION(func); \
00040 UNIT_BASE_THIS_OBJECT.assert_equal(a, b, function_name, test_name, basis::astring(#a) + " must be equal to " + #b); \
00041 }
00042 #define ASSERT_INEQUAL(a, b, test_name) { \
00043 BASE_FUNCTION(func); \
00044 UNIT_BASE_THIS_OBJECT.assert_not_equal(a, b, function_name, test_name, basis::astring(#a) + " must be inequal to " + #b); \
00045 }
00046 #define ASSERT_TRUE(a, test_name) { \
00047 BASE_FUNCTION(func); \
00048 UNIT_BASE_THIS_OBJECT.assert_true(a, function_name, test_name, basis::astring(#a) + " must be true"); \
00049 }
00050 #define ASSERT_FALSE(a, test_name) { \
00051 BASE_FUNCTION(func); \
00052 UNIT_BASE_THIS_OBJECT.assert_false(a, function_name, test_name, basis::astring(#a) + " must be false"); \
00053 }
00054
00055 #define ASSERT_NULL(x, y) ASSERT_FALSE(x, y)
00056 #define ASSERT_NON_NULL(x, y) ASSERT_TRUE(x, y)
00057
00058 class unit_base : public virtual basis::nameable
00059 {
00060 public:
00061 unit_base();
00062 virtual ~unit_base();
00063
00064 DEFINE_CLASS_NAME("unit_base");
00065
00066 int total_tests() const;
00067 int passed_tests() const;
00068 int failed_tests() const;
00069
00070 void assert_equal(const basis::hoople_standard &a, const basis::hoople_standard &b,
00071 const basis::astring &class_name, const basis::astring &test_name,
00072 const basis::astring &diagnostic_info);
00074 void assert_not_equal(const basis::hoople_standard &a, const basis::hoople_standard &b,
00075 const basis::astring &class_name, const basis::astring &test_name,
00076 const basis::astring &diagnostic_info);
00078
00079 void assert_equal(const basis::byte_array &a, const basis::byte_array &b,
00080 const basis::astring &class_name, const basis::astring &test_name,
00081 const basis::astring &diagnostic_info);
00083 void assert_not_equal(const basis::byte_array &a, const basis::byte_array &b,
00084 const basis::astring &class_name, const basis::astring &test_name,
00085 const basis::astring &diagnostic_info);
00087
00088 void assert_equal(int a, int b,
00089 const basis::astring &class_name, const basis::astring &test_name,
00090 const basis::astring &diagnostic_info);
00092 void assert_not_equal(int a, int b,
00093 const basis::astring &class_name, const basis::astring &test_name,
00094 const basis::astring &diagnostic_info);
00096
00097 void assert_equal(double a, double b,
00098 const basis::astring &class_name, const basis::astring &test_name,
00099 const basis::astring &diagnostic_info);
00101 void assert_not_equal(double a, double b,
00102 const basis::astring &class_name, const basis::astring &test_name,
00103 const basis::astring &diagnostic_info);
00105
00106 void assert_equal(const void *a, const void *b,
00107 const basis::astring &class_name, const basis::astring &test_name,
00108 const basis::astring &diagnostic_info);
00110
00113 void assert_not_equal(const void *a, const void *b,
00114 const basis::astring &class_name, const basis::astring &test_name,
00115 const basis::astring &diagnostic_info);
00117
00118 void assert_true(bool result,
00119 const basis::astring &class_name, const basis::astring &test_name,
00120 const basis::astring &diagnostic_info);
00122 void assert_false(bool result,
00123 const basis::astring &class_name, const basis::astring &test_name,
00124 const basis::astring &diagnostic_info);
00126
00127
00128
00129
00130
00131 void record_pass(const basis::astring &class_name,
00132 const basis::astring &test_name,
00133 const basis::astring &diagnostic_info);
00135 void record_fail(const basis::astring &class_name,
00136 const basis::astring &test_name,
00137 const basis::astring &diagnostic_info);
00139
00140 int final_report();
00142
00146 private:
00147 basis::mutex c_lock;
00148 int c_total_tests;
00149 int c_passed_tests;
00150 structures::string_table c_successful;
00151 structures::string_table c_failed;
00152
00153 void write_cppunit_xml();
00155
00156 void count_successful_test(const basis::astring &class_name, const basis::astring &test_name);
00158
00159 void count_failed_test(const basis::astring &class_name, const basis::astring &test_name, const basis::astring &diag);
00161
00162 void record_successful_assertion(const basis::astring &class_name, const basis::astring &test_name,
00163 const basis::astring &assertion_name);
00165
00166 void record_failed_object_compare(const basis::hoople_standard &a,
00167 const basis::hoople_standard &b, const basis::astring &class_name,
00168 const basis::astring &test_name, const basis::astring &assertion_name);
00169 void record_failed_int_compare(int a, int b,
00170 const basis::astring &class_name, const basis::astring &test_name,
00171 const basis::astring &assertion_name);
00172 void record_failed_double_compare(double a, double b,
00173 const basis::astring &class_name, const basis::astring &test_name,
00174 const basis::astring &assertion_name);
00175 void record_failed_tf_assertion(bool result, bool expected_result,
00176 const basis::astring &class_name, const basis::astring &test_name,
00177 const basis::astring &assertion_name);
00178 void record_failed_pointer_compare(const void *a, const void *b,
00179 const basis::astring &class_name, const basis::astring &test_name,
00180 const basis::astring &assertion_name);
00181 };
00182
00183 }
00184
00185 #endif
00186