42 #ifndef TESTINGFRAMEWORK_HH
43 #define TESTINGFRAMEWORK_HH
59 #include <OpenMesh/Core/Utils/Noncopyable.hh>
107 #define TH_VERIFY( expr, expt ) \
108 verify( expr, expt, #expr )
111 #define TH_VERIFY_X( expr, expt ) \
112 verify_x( expr, expt, #expr )
122 typedef std::logic_error verify_error;
124 #ifndef DOXY_IGNORE_THIS
129 : th_(_th), name_(_n)
137 void operator() (
void )
144 catch( std::exception& x )
146 std::cerr <<
"<<Error>>: Cannot proceed test due to failure of last"
147 <<
" test: " << x.what() << std::endl;
151 std::cerr <<
"Fatal: cannot proceed test due to unknown error!"
161 virtual void prolog(
void)
166 virtual void body(
void) = 0;
168 virtual void epilog(
void)
177 TestFunc(
const TestFunc& _cpy ) : th_(_cpy.th_), name_(_cpy.name_) { }
181 TestFunc& begin(std::string _title,
const std::string& _info =
"")
182 { th_.begin(_title,_info);
return *
this; }
187 { th_.end();
return *
this; }
192 template <
typename ValueType>
194 verify(
const ValueType& _rc,
const ValueType& _expected,
196 {
return th_.verify( _rc, _expected, _info ); }
198 template <
typename ValueType>
200 verify_x(
const ValueType& _rc,
const ValueType& _expected,
203 if ( !verify(_rc, _expected, _info) )
204 throw verify_error(_info);
207 TestFunc& info(
const std::string& _info)
208 { th_.info(_info);
return *
this; }
210 TestFunc& info(
const std::ostringstream& _ostr)
211 { th_.info(_ostr);
return *
this; }
222 typedef TestFunc* TestFuncPtr;
223 typedef std::vector<TestFuncPtr> TestSet;
228 : errTotal_(0), errCount_(0),
229 verifyTotal_(0), verifyCount_(0),
230 testTotal_(0), testCount_(0),
236 #ifndef DOXY_IGNORE_THIS
239 void operator() (TestFuncPtr _tfptr) {
delete _tfptr; }
247 std::for_each(tests_.begin(), tests_.end(), TestDeleter() );
252 template <
typename ValueType>
253 bool verify(
const ValueType& _rc,
254 const ValueType& _expected,
255 const std::string& _info)
258 if ( _rc == _expected )
260 os_ <<
" " << _info <<
", result: " << _rc <<
", OK!" << std::endl;
264 os_ <<
" " << _info <<
", result: " << _rc <<
" != " << _expected
265 <<
" <<ERROR>>" << std::endl;
269 Self& begin(std::string _title,
const std::string& _info =
"")
271 std::ostringstream ostr;
274 errCount_ = errTotal_;
278 if ( !_info.empty() )
279 ostr <<
" ["<< _info <<
"]";
280 testTitle_ = ostr.str();
281 os_ <<
"Begin " << testTitle_ << std::endl;
290 os_ <<
"End " << testTitle_ <<
": " << errorCount() <<
" Error(s)." << std::endl;
294 Self& info(
const std::string& _info)
296 os_ <<
" + " << _info << std::endl;
300 Self& info(
const std::ostringstream& _ostr)
302 os_ <<
" + " << _ostr.str() << std::endl;
306 size_t errorTotal()
const {
return errTotal_; }
307 size_t errorCount()
const {
return errTotal_ - errCount_; }
308 size_t verifyTotal()
const {
return verifyTotal_; }
309 size_t verifyCount()
const {
return verifyTotal_ - verifyCount_; }
310 size_t goodTotal()
const {
return verifyTotal() - errorTotal(); }
311 size_t goodCount()
const {
return verifyCount() - errorCount(); }
313 size_t testTotal()
const {
return testTotal_; }
314 size_t testCount()
const {
return testCount_; }
320 os_ <<
"Test started\n";
322 std::for_each(tests_.begin(), tests_.end(), executer );
324 os_ <<
"All tests completed" << std::endl
325 <<
" #Tests: " << testCount() <<
"/" << testTotal() << std::endl
326 <<
" #Errors: " << errorTotal() <<
"/" << verifyTotal() << std::endl;
332 #ifndef DOXY_IGNORE_THIS
335 void operator() (TestFuncPtr _tfptr) { (*_tfptr)(); }
339 int reg(TestFuncPtr _tfptr)
341 tests_.push_back(_tfptr);
345 friend class TestFunc;
356 std::string testTitle_;
367 #endif // TESTINGFRMEWORK_HH
Helper class for test programms.
Definition: TestingFramework.hh:117
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:69