00001 #include <iostream>
00002
00003 #include <sstream>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006
00007 class TEST{
00008
00009 public:
00010
00011 TEST( const std::string& tname, std::ostream& stream=std::cout ): _testname(tname), _out(stream){
00012 _out << std::endl << "[" << _testname << "] ";
00013 _out << "TEST_BEGIN ******************************" << std::endl << std::endl;
00014 }
00015
00016 ~TEST(){
00017 _out << std::endl << "[" << _testname << "] ";
00018 _out << "TEST_PASSED ******************************" << std::endl << std::endl;
00019 }
00020
00021 void LOG( const std::string& msg ){
00022 _out << "[" << _testname << "] LOG: " << msg << std::endl;
00023 }
00024
00025 template <class V1, class V2 >
00026 void operator()(const V1& v1, const V2& v2 , const std::string name ) {
00027
00028 if ( ! (v1 == v2) ) {
00029
00030 std::stringstream sstr ;
00031 sstr << " " << name<< " : [" << v1 << "] != [" << v2 <<"]" ;
00032 FAILED( sstr.str() ) ;
00033 }
00034 return ;
00035 }
00036
00037
00038
00039
00040
00041
00042 void FAILED( const std::string& msg ){
00043
00044 std::stringstream errmsg;
00045 errmsg << std::endl;
00046 errmsg << "[" << _testname << "] TEST_FAILED ############################################" << std::endl;
00047 errmsg << "[" << _testname << "] TEST_ERROR: " << msg << std::endl;
00048 errmsg << "[" << _testname << "] TEST_FAILED ############################################" << std::endl;
00049 errmsg << std::endl;
00050
00051 _out << errmsg.str();
00052
00053
00054
00055
00056
00057 exit(1);
00058 }
00059
00060 private:
00061 std::string _testname;
00062 std::ostream& _out;
00063 };