LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tutil.h
Go to the documentation of this file.
1 #include <iostream>
2 //#include <cstring>
3 #include <sstream>
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 class TEST{
8 
9 public:
10 
11  TEST( const std::string& tname, std::ostream& stream=std::cout ): _testname(tname), _out(stream){
12  _out << std::endl << "[" << _testname << "] ";
13  _out << "TEST_BEGIN ******************************" << std::endl << std::endl;
14  }
15 
16  ~TEST(){
17  _out << std::endl << "[" << _testname << "] ";
18  _out << "TEST_PASSED ******************************" << std::endl << std::endl;
19  }
20 
21  void LOG( const std::string& msg ){
22  _out << "[" << _testname << "] LOG: " << msg << std::endl;
23  }
24 
25  template <class V1, class V2 >
26  void operator()(const V1& v1, const V2& v2 , const std::string name ) {
27 
28  if ( ! (v1 == v2) ) {
29 
30  std::stringstream sstr ;
31  sstr << " " << name<< " : [" << v1 << "] != [" << v2 <<"]" ;
32  FAILED( sstr.str() ) ;
33  }
34  return ;
35  }
36 
37 // void operator()(bool cond, const std::string msg) {
38 // if ( ! cond ) FAILED( msg ) ;
39 // return ;
40 // }
41 
42  void FAILED( const std::string& msg ){
43 
44  std::stringstream errmsg;
45  errmsg << std::endl;
46  errmsg << "[" << _testname << "] TEST_FAILED ############################################" << std::endl;
47  errmsg << "[" << _testname << "] TEST_ERROR: " << msg << std::endl;
48  errmsg << "[" << _testname << "] TEST_FAILED ############################################" << std::endl;
49  errmsg << std::endl;
50 
51  _out << errmsg.str();
52 
53  // also send error to stderr
54  //std::cerr << errmsg.str();
55 
56  // abort program
57  exit(1);
58  }
59 
60 private:
63 };
std::string _testname
Definition: tutil.h:61
~TEST()
Definition: tutil.h:16
std::ostream & _out
Definition: tutil.h:62
T endl(T...args)
Definition: tutil.h:7
STL class.
void FAILED(const std::string &msg)
Definition: tutil.h:42
T str(T...args)
void operator()(const V1 &v1, const V2 &v2, const std::string name)
Definition: tutil.h:26
TEST(const std::string &tname, std::ostream &stream=std::cout)
Definition: tutil.h:11
void LOG(const std::string &msg)
Definition: tutil.h:21
STL class.