44 #ifndef TESTINGFRAMEWORK_HH
45 #define TESTINGFRAMEWORK_HH
61 #include <OpenMesh/Core/Utils/Noncopyable.hh>
109 #define TH_VERIFY( expr, expt ) \
110 verify( expr, expt, #expr )
113 #define TH_VERIFY_X( expr, expt ) \
114 verify_x( expr, expt, #expr )
124 typedef std::logic_error verify_error;
126 #ifndef DOXY_IGNORE_THIS
131 : th_(_th), name_(_n)
139 void operator() (
void )
146 catch( std::exception& x )
148 std::cerr <<
"<<Error>>: Cannot proceed test due to failure of last"
149 <<
" test: " << x.what() << std::endl;
153 std::cerr <<
"Fatal: cannot proceed test due to unknown error!"
163 virtual void prolog(
void)
168 virtual void body(
void) = 0;
170 virtual void epilog(
void)
179 TestFunc(
const TestFunc& _cpy ) : th_(_cpy.th_), name_(_cpy.name_) { }
183 TestFunc& begin(std::string _title,
const std::string& _info =
"")
184 { th_.begin(_title,_info);
return *
this; }
189 { th_.end();
return *
this; }
194 template <
typename ValueType>
196 verify(
const ValueType& _rc,
const ValueType& _expected,
198 {
return th_.verify( _rc, _expected, _info ); }
200 template <
typename ValueType>
202 verify_x(
const ValueType& _rc,
const ValueType& _expected,
205 if ( !verify(_rc, _expected, _info) )
206 throw verify_error(_info);
209 TestFunc& info(
const std::string& _info)
210 { th_.info(_info);
return *
this; }
212 TestFunc& info(
const std::ostringstream& _ostr)
213 { th_.info(_ostr);
return *
this; }
224 typedef TestFunc* TestFuncPtr;
225 typedef std::vector<TestFuncPtr> TestSet;
230 : errTotal_(0), errCount_(0),
231 verifyTotal_(0), verifyCount_(0),
232 testTotal_(0), testCount_(0),
238 #ifndef DOXY_IGNORE_THIS
241 void operator() (TestFuncPtr _tfptr) {
delete _tfptr; }
249 std::for_each(tests_.begin(), tests_.end(), TestDeleter() );
254 template <
typename ValueType>
255 bool verify(
const ValueType& _rc,
256 const ValueType& _expected,
257 const std::string& _info)
260 if ( _rc == _expected )
262 os_ <<
" " << _info <<
", result: " << _rc <<
", OK!" << std::endl;
266 os_ <<
" " << _info <<
", result: " << _rc <<
" != " << _expected
267 <<
" <<ERROR>>" << std::endl;
271 Self& begin(std::string _title,
const std::string& _info =
"")
273 std::ostringstream ostr;
276 errCount_ = errTotal_;
280 if ( !_info.empty() )
281 ostr <<
" ["<< _info <<
"]";
282 testTitle_ = ostr.str();
283 os_ <<
"Begin " << testTitle_ << std::endl;
292 os_ <<
"End " << testTitle_ <<
": " << errorCount() <<
" Error(s)." << std::endl;
296 Self& info(
const std::string& _info)
298 os_ <<
" + " << _info << std::endl;
302 Self& info(
const std::ostringstream& _ostr)
304 os_ <<
" + " << _ostr.str() << std::endl;
308 size_t errorTotal()
const {
return errTotal_; }
309 size_t errorCount()
const {
return errTotal_ - errCount_; }
310 size_t verifyTotal()
const {
return verifyTotal_; }
311 size_t verifyCount()
const {
return verifyTotal_ - verifyCount_; }
312 size_t goodTotal()
const {
return verifyTotal() - errorTotal(); }
313 size_t goodCount()
const {
return verifyCount() - errorCount(); }
315 size_t testTotal()
const {
return testTotal_; }
316 size_t testCount()
const {
return testCount_; }
322 os_ <<
"Test started\n";
324 std::for_each(tests_.begin(), tests_.end(), executer );
326 os_ <<
"All tests completed" << std::endl
327 <<
" #Tests: " << testCount() <<
"/" << testTotal() << std::endl
328 <<
" #Errors: " << errorTotal() <<
"/" << verifyTotal() << std::endl;
334 #ifndef DOXY_IGNORE_THIS
337 void operator() (TestFuncPtr _tfptr) { (*_tfptr)(); }
341 int reg(TestFuncPtr _tfptr)
343 tests_.push_back(_tfptr);
347 friend class TestFunc;
358 std::string testTitle_;
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:72
Helper class for test programms.
Definition: TestingFramework.hh:120