00001 #define TRACE_NAME "UnitTest"
00002
00003 #include "UnitTest.h"
00004
00005 extern "C" {
00006 #include <string.h>
00007 #include <stdio.h>
00008 }
00009
00011
00012
00013
00015
00016 UnitTest *UnitTest::first_instance = 0;
00017
00018 UnitTest::UnitTest(function f, char *p_file, int p_num, char *p_other_name):
00019 function_pointer(f),
00020 file(p_file),
00021 num(p_num),
00022 other_name(p_other_name)
00023 {
00024 next_instance = first_instance;
00025 first_instance = this;
00026
00027 name=new char [strlen(file) + strlen(other_name) + 30];
00028 sprintf(name, "%s(#%d) %s", file, num, other_name);
00029
00030
00031
00032
00033
00034
00035
00036 }
00037
00038 #if 0
00039
00040 UnitTest::UnitTest(const UnitTest& other)
00041 {
00042 NOT_IMPLEMENTED
00043 }
00044
00045 const UnitTest& UnitTest::operator=(const UnitTest& other)
00046 {
00047 NOT_IMPLEMENTED
00048 }
00049
00050 bool UnitTest::operator==(const UnitTest& other) const
00051 {
00052 NOT_IMPLEMENTED
00053 }
00054
00055 bool UnitTest::operator<(const UnitTest& other) const
00056 {
00057 NOT_IMPLEMENTED
00058 }
00059
00060 size_t UnitTest::hash() const
00061 {
00062 NOT_IMPLEMENTED
00063 }
00064
00065 std::ostream& UnitTest::print_to(std::ostream& stream) const
00066 {
00067 NOT_IMPLEMENTED
00068 }
00069
00070 #endif
00071
00072 UnitTest::~UnitTest()
00073 {
00074 delete[] name;
00075 }
00076
00078
00079
00080
00082
00083 void UnitTest::run_tests(std::ostream& out, char *keyword)
00084 {
00085 for (UnitTest *t = first_instance; t; t=t->next_instance) {
00086 out << "Unit Test " << t->name << ": " ;
00087 if (strstr(t->name, keyword)) {
00088 if ((t->function_pointer)(out)) {
00089 out << " PASSED" << std::endl;
00090 } else {
00091 out << " **FAILED**" << std::endl;
00092 }
00093 } else {
00094 out << " skipped" << std::endl;
00095 }
00096 }
00097 }
00098
00099 void UnitTest::print_name(std::ostream& out)
00100 {
00101
00102 }
00103
00104
00105
00107
00108
00109
00111
00112
00113
00114 #undef TRACE_NAME