g4tools  5.4.0
Public Member Functions | Protected Attributes | List of all members
tools::utest Class Reference
Inheritance diagram for tools::utest:
Inheritance graph
[legend]
Collaboration diagram for tools::utest:
Collaboration graph
[legend]

Public Member Functions

 utest (std::ostream &a_out)
 
virtual ~ utest ()
 
 utest (const utest &a_from)
 
utestoperator= (const utest &a_from)
 
void add (const std::string &a_name, test::func a_func)
 
void add (const std::string &a_name, test::func2 a_func)
 
void add (const std::string &a_name, test::func3 a_func)
 
void add (const std::string &a_name, test::cfunc a_func)
 
bool exec (const args &a_args, bool a_verbose, int a_argc=0, char **a_argv=0)
 
void list ()
 

Protected Attributes

std::ostream & m_out
 

Detailed Description

Definition at line 46 of file utest.

Constructor & Destructor Documentation

◆ utest() [1/2]

tools::utest::utest ( std::ostream &  a_out)
inline

Definition at line 50 of file utest.

50 :m_out(a_out){}

◆ ~ utest()

virtual tools::utest::~ utest ( )
inline

Definition at line 51 of file utest.

51 {}

◆ utest() [2/2]

tools::utest::utest ( const utest a_from)
inline

Definition at line 53 of file utest.

53 :parent(a_from),m_out(a_from.m_out){}

Member Function Documentation

◆ add() [1/4]

void tools::utest::add ( const std::string &  a_name,
test::cfunc  a_func 
)
inline

Definition at line 65 of file utest.

65  {
66  (*this).push_back(named_test(a_name,test(false,a_func)));
67  }

◆ add() [2/4]

void tools::utest::add ( const std::string &  a_name,
test::func  a_func 
)
inline

Definition at line 56 of file utest.

56  {
57  (*this).push_back(named_test(a_name,test(false,a_func)));
58  }

◆ add() [3/4]

void tools::utest::add ( const std::string &  a_name,
test::func2  a_func 
)
inline

Definition at line 59 of file utest.

59  {
60  (*this).push_back(named_test(a_name,test(false,a_func)));
61  }

◆ add() [4/4]

void tools::utest::add ( const std::string &  a_name,
test::func3  a_func 
)
inline

Definition at line 62 of file utest.

62  {
63  (*this).push_back(named_test(a_name,test(false,a_func)));
64  }

◆ exec()

bool tools::utest::exec ( const args a_args,
bool  a_verbose,
int  a_argc = 0,
char **  a_argv = 0 
)
inline

Definition at line 69 of file utest.

69  {
70  {tools_vforit(named_test,*this,it) (*it).second.m_do_it = false;}
71 
72  {tools_vforcit(args::arg,a_args.get_args(),it) {
73  const std::string& key = (*it).first;
74  bool found = false;
75  tools_vforit(named_test,*this,itn) {
76  const std::string& name = (*itn).first;
77  if(key==std::string("-"+name)) {found=true;break;}
78  if(key==std::string("-no_"+name)) {found=true;break;} //valid arg, but not a test.
79  }
80  if(!found) {
81  m_out << "WARNING : arg " << sout(key) << " is not a test." << std::endl;
82  }
83  }}
84 
85  bool some = false;
86  {tools_vforit(named_test,*this,it) {
87  const std::string& name = (*it).first;
88  if(a_args.is_arg("-"+name)) {
89  (*it).second.m_do_it = true;
90  some = true;
91  }
92  }}
93 
94  if(!some) { //do all.
95  tools_vforit(named_test,*this,it) (*it).second.m_do_it = true;
96  }
97 
98  {tools_vforit(named_test,*this,it) {
99  const std::string& name = (*it).first;
100  if(a_args.is_arg("-no_"+name)) {
101  (*it).second.m_do_it = false;
102  }
103  }}
104 
105  bool status = true;
106 
107  {tools_vforcit(named_test,*this,it) {
108  const std::string& name = (*it).first;
109  if((*it).second.m_do_it && (*it).second.m_func) {
110  if(a_verbose) m_out << "test_" << name << " ..." << std::endl;
111  if(!(*it).second.m_func(m_out,a_verbose)) {
112  m_out << "test_" << name << " failed." << std::endl;
113  status = false;
114  }
115  if(a_verbose) m_out << "test_" << name << " end." << std::endl;
116  }
117  }}
118 
119  {tools_vforcit(named_test,*this,it) {
120  const std::string& name = (*it).first;
121  if((*it).second.m_do_it && (*it).second.m_func2) {
122  if(a_verbose) m_out << "test_" << name << " ..." << std::endl;
123  if(!(*it).second.m_func2(m_out,a_args)) {
124  m_out << "test_" << name << " failed." << std::endl;
125  status = false;
126  }
127  if(a_verbose) m_out << "test_" << name << " end." << std::endl;
128  }
129  }}
130 
131  {tools_vforcit(named_test,*this,it) {
132  const std::string& name = (*it).first;
133  if((*it).second.m_do_it && (*it).second.m_func3) {
134  if(a_verbose) m_out << "test_" << name << " ..." << std::endl;
135  if(!(*it).second.m_func3(m_out,a_argc,a_argv)) {
136  m_out << "test_" << name << " failed." << std::endl;
137  status = false;
138  }
139  if(a_verbose) m_out << "test_" << name << " end." << std::endl;
140  }
141  }}
142 
143  {tools_vforcit(named_test,*this,it) {
144  const std::string& name = (*it).first;
145  if((*it).second.m_do_it && (*it).second.m_cfunc) {
146  if(a_verbose) m_out << "test_" << name << " ..." << std::endl;
147  if(!(*it).second.m_cfunc(stdout,a_verbose)) {
148  m_out << "test_" << name << " failed." << std::endl;
149  status = false;
150  }
151  if(a_verbose) m_out << "test_" << name << " end." << std::endl;
152  }
153  }}
154 
155  tools_vforit(named_test,*this,it) (*it).second.m_do_it = false;
156 
157  return status;
158  }

◆ list()

void tools::utest::list ( )
inline

Definition at line 160 of file utest.

160 {tools_vforit(named_test,*this,it) m_out << (*it).first << std::endl;}

◆ operator=()

utest& tools::utest::operator= ( const utest a_from)
inline

Definition at line 54 of file utest.

54 { parent::operator=(a_from);return *this;}

Member Data Documentation

◆ m_out

std::ostream& tools::utest::m_out
protected

Definition at line 162 of file utest.


The documentation for this class was generated from the following file:
tools::args::arg
std::pair< std::string, std::string > arg
Definition: args:30
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::utest::m_out
std::ostream & m_out
Definition: utest:162
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7