1 #ifndef TUT_RESTARTABLE_H_GUARD 2 #define TUT_RESTARTABLE_H_GUARD 26 std::string
escape(
const std::string& orig)
29 std::string::const_iterator i,e;
35 if( (*i >=
'a' && *i <=
'z') ||
36 (*i >=
'A' && *i <=
'Z') ||
37 (*i >=
'0' && *i <=
'9') )
44 rc += (
'a'+(((
unsigned int)*i)>>4));
45 rc += (
'a'+(((
unsigned int)*i)&0xF));
59 std::string::const_iterator i,e;
71 ++i;
if( i == e )
throw std::invalid_argument(
"unexpected end of string");
73 ++i;
if( i == e )
throw std::invalid_argument(
"unexpected end of string");
75 rc += (((c1-
'a')<<4) + (c2-
'a'));
97 default:
throw std::logic_error(
"operator << : bad result_type");
107 std::getline(is,tr.
group);
113 if( tr.
test < 0 )
throw std::logic_error(
"operator >> : bad test number");
123 default:
throw std::logic_error(
"operator >> : bad result_type");
129 if( !is.good() )
throw std::logic_error(
"malformed test result");
151 : runner_(
runner.get()), callback_(0), dir_(dir)
154 jrn_ = dir_+
'/'+
"journal.tut";
155 log_ = dir_+
'/'+
"log.tut";
196 std::string fail_group;
198 read_log_(fail_group,fail_test);
199 bool fail_group_reached = (fail_group ==
"");
203 tut::groupnames::const_iterator gni,gne;
209 if( !fail_group_reached )
211 if( *gni != fail_group )
216 fail_group_reached =
true;
220 int test = (*gni == fail_group && fail_test>=0)? fail_test+1:1;
224 register_execution_(*gni,test);
257 void invoke_callback_()
const 262 std::string current_group;
263 std::ifstream ijournal(jrn_.c_str());
264 while( ijournal.good() )
287 std::ofstream ojournal(jrn_.c_str(),std::ios::app);
289 ojournal << std::flush;
290 if( !ojournal.good() )
throw std::runtime_error(
"unable to register test result in file "+jrn_);
296 void register_execution_(
const std::string& grp,
int test)
const 299 std::ofstream olog(log_.c_str());
300 olog <<
util::escape(grp) << std::endl << test << std::endl << std::flush;
301 if( !olog.good() )
throw std::runtime_error(
"unable to register execution in file "+log_);
307 void truncate_()
const 309 std::ofstream olog(log_.c_str());
310 std::ofstream ojournal(jrn_.c_str());
316 void read_log_(std::string& fail_group,
int& fail_test)
const 319 std::ifstream ilog(log_.c_str());
320 std::getline(ilog,fail_group);
325 fail_group =
""; fail_test = -1;
Test runner.
Definition: tut.h:228
void deserialize(std::istream &is, tut::test_result &tr)
deserialization for test_result
Definition: tut_restartable.h:105
std::string group
Test group name.
Definition: tut.h:110
Exception to be throwed when attempted to execute missed test by number.
Definition: tut.h:29
groupnames list_groups() const
Returns list of known test groups.
Definition: tut_restartable.h:185
std::string unescape(const std::string &orig)
Un-escapes string.
Definition: tut_restartable.h:56
virtual void run_completed()
Called when all tests in run completed.
Definition: tut.h:217
const groupnames list_groups() const
Returns list of known test groups.
Definition: tut.h:288
callback & get_callback() const
Returns callback object.
Definition: tut.h:280
int test
Test number in group.
Definition: tut.h:115
test_result run_test(const std::string &group_name, int n) const
Runs one test in specified group.
Definition: tut.h:360
virtual void test_completed(const test_result &)
Called when a test finished.
Definition: tut.h:206
void serialize(std::ostream &os, const tut::test_result &tr)
Serialize test_result avoiding interfering with operator <<.
Definition: tut_restartable.h:86
result_type result
Definition: tut.h:125
Template Unit Tests Framework for C++.
Definition: tut-main.cpp:6
void register_group(const std::string &name, group_base *gr)
Stores another group for getting by name.
Definition: tut_restartable.h:161
callback & get_callback() const
Returns callback object.
Definition: tut_restartable.h:177
test_runner_singleton runner
Definition: tut-main.cpp:8
void set_callback(callback *cb)
Stores callback object.
Definition: tut.h:272
std::vector< std::string > groupnames
Typedef for runner::list_groups()
Definition: tut.h:223
Internal exception to be throwed when no more tests left in group or journal.
Definition: tut.h:57
void register_group(const std::string &name, group_base *gr)
Stores another group for getting by name.
Definition: tut.h:250
Interface.
Definition: tut.h:165
Restartable test runner wrapper.
Definition: tut_restartable.h:136
std::string message
Exception message for failed test.
Definition: tut.h:130
Return type of runned test/test group.
Definition: tut.h:105
void run_tests() const
Runs all tests in all groups.
Definition: tut_restartable.h:193
std::string escape(const std::string &orig)
Escapes non-alphabetical characters in string.
Definition: tut_restartable.h:26
restartable_wrapper(const std::string &dir=".")
Default constructor.
Definition: tut_restartable.h:150
void set_callback(callback *cb)
Stores callback object.
Definition: tut_restartable.h:169
No such test and passed test number is higher than any test number in current group.
Definition: tut.h:39
Test runner callback interface.
Definition: tut.h:184
virtual void run_started()
Called when new test run started.
Definition: tut.h:194