49 #ifndef TESTINGFRAMEWORK_HH 50 #define TESTINGFRAMEWORK_HH 66 #include <OpenMesh/Core/Utils/Noncopyable.hh> 114 #define TH_VERIFY( expr, expt ) \ 115 verify( expr, expt, #expr ) 118 #define TH_VERIFY_X( expr, expt ) \ 119 verify_x( expr, expt, #expr ) 129 typedef std::logic_error verify_error;
131 #ifndef DOXY_IGNORE_THIS 136 : th_(_th), name_(_n)
144 void operator() (
void )
151 catch( std::exception& x )
153 std::cerr <<
"<<Error>>: Cannot proceed test due to failure of last" 154 <<
" test: " << x.what() << std::endl;
158 std::cerr <<
"Fatal: cannot proceed test due to unknown error!" 168 virtual void prolog(
void)
173 virtual void body(
void) = 0;
175 virtual void epilog(
void)
184 TestFunc(
const TestFunc& _cpy ) : th_(_cpy.th_), name_(_cpy.name_) { }
188 TestFunc& begin(std::string _title,
const std::string& _info =
"")
189 { th_.begin(_title,_info);
return *
this; }
194 { th_.end();
return *
this; }
199 template <
typename ValueType>
201 verify(
const ValueType& _rc,
const ValueType& _expected,
203 {
return th_.verify( _rc, _expected, _info ); }
205 template <
typename ValueType>
207 verify_x(
const ValueType& _rc,
const ValueType& _expected,
210 if ( !verify(_rc, _expected, _info) )
211 throw verify_error(_info);
214 TestFunc& info(
const std::string& _info)
215 { th_.info(_info);
return *
this; }
217 TestFunc& info(
const std::ostringstream& _ostr)
218 { th_.info(_ostr);
return *
this; }
229 typedef TestFunc* TestFuncPtr;
230 typedef std::vector<TestFuncPtr> TestSet;
235 : errTotal_(0), errCount_(0),
236 verifyTotal_(0), verifyCount_(0),
237 testTotal_(0), testCount_(0),
243 #ifndef DOXY_IGNORE_THIS 246 void operator() (TestFuncPtr _tfptr) {
delete _tfptr; }
254 std::for_each(tests_.begin(), tests_.end(), TestDeleter() );
259 template <
typename ValueType>
260 bool verify(
const ValueType& _rc,
261 const ValueType& _expected,
262 const std::string& _info)
265 if ( _rc == _expected )
267 os_ <<
" " << _info <<
", result: " << _rc <<
", OK!" << std::endl;
271 os_ <<
" " << _info <<
", result: " << _rc <<
" != " << _expected
272 <<
" <<ERROR>>" << std::endl;
276 Self& begin(std::string _title,
const std::string& _info =
"")
278 std::ostringstream ostr;
281 errCount_ = errTotal_;
285 if ( !_info.empty() )
286 ostr <<
" ["<< _info <<
"]";
287 testTitle_ = ostr.str();
288 os_ <<
"Begin " << testTitle_ << std::endl;
297 os_ <<
"End " << testTitle_ <<
": " << errorCount() <<
" Error(s)." << std::endl;
301 Self& info(
const std::string& _info)
303 os_ <<
" + " << _info << std::endl;
307 Self& info(
const std::ostringstream& _ostr)
309 os_ <<
" + " << _ostr.str() << std::endl;
313 size_t errorTotal()
const {
return errTotal_; }
314 size_t errorCount()
const {
return errTotal_ - errCount_; }
315 size_t verifyTotal()
const {
return verifyTotal_; }
316 size_t verifyCount()
const {
return verifyTotal_ - verifyCount_; }
317 size_t goodTotal()
const {
return verifyTotal() - errorTotal(); }
318 size_t goodCount()
const {
return verifyCount() - errorCount(); }
320 size_t testTotal()
const {
return testTotal_; }
321 size_t testCount()
const {
return testCount_; }
327 os_ <<
"Test started\n";
329 std::for_each(tests_.begin(), tests_.end(), executer );
331 os_ <<
"All tests completed" << std::endl
332 <<
" #Tests: " << testCount() <<
"/" << testTotal() << std::endl
333 <<
" #Errors: " << errorTotal() <<
"/" << verifyTotal() << std::endl;
339 #ifndef DOXY_IGNORE_THIS 342 void operator() (TestFuncPtr _tfptr) { (*_tfptr)(); }
346 int reg(TestFuncPtr _tfptr)
348 tests_.push_back(_tfptr);
352 friend class TestFunc;
363 std::string testTitle_;
374 #endif // TESTINGFRMEWORK_HH
Helper class for test programms.
Definition: TestingFramework.hh:124
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:76
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64