[complement-svn] SF.net SVN: complement: [1617] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-17 06:29:47
|
Revision: 1617 http://svn.sourceforge.net/complement/?rev=1617&view=rev Author: complement Date: 2007-07-16 23:29:46 -0700 (Mon, 16 Jul 2007) Log Message: ----------- was introduced stack of test suites, functions for asynchronous checks; add macros for asynchronous checkes [in case when point can't be unambiguously associated with some test case] Modified Paths: -------------- trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/exam/suite.cc Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-07-16 21:14:15 UTC (rev 1616) +++ trunk/complement/explore/include/exam/suite.h 2007-07-17 06:29:46 UTC (rev 1617) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 23:07:02 ptr> +// -*- C++ -*- Time-stamp: <07/07/17 09:47:24 ptr> #ifndef __suite_h #define __suite_h @@ -6,6 +6,7 @@ #include <iostream> #include <sstream> #include <map> +#include <stack> #include <boost/graph/adjacency_list.hpp> #include <string> #include <exception> @@ -205,7 +206,10 @@ void report( const char *, int, bool, const char * ); base_logger *set_global_logger( base_logger * ); base_logger *set_logger( base_logger * ); + void set_fail(); + static test_suite& top(); + private: enum { pass = 0, @@ -226,6 +230,7 @@ }; typedef std::map<vertex_t,test_case_collect> test_case_map_type; + int _last_state; test_case_map_type _test; base_logger::stat _stat; std::string _suite_name; @@ -233,6 +238,8 @@ static int _root_func( test_suite *, int = 0 ); static base_logger *logger; + + static std::stack<test_suite *> _stack; }; template <class TC> @@ -300,19 +307,25 @@ # define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) # define EXAM_RESULT __exam_counter # define EXAM_CHECK(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); __exam_counter |= 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) +# define EXAM_CHECK_ASYNC(C) if ( !(C) ) { exam::test_suite::top().report( __FILE__, __LINE__, false, #C ); exam::test_suite::top().set_fail(); } else exam::test_suite::top().report( __FILE__, __LINE__, true, #C ) # define EXAM_MESSAGE(M) __exam_ts->report( __FILE__, __LINE__, true, M ) +# define EXAM_MESSAGE_ASYNC(M) exam::test_suite::top().report( __FILE__, __LINE__, true, M ) # define EXAM_REQUIRE(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); return 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) # define EXAM_FAIL(M) __exam_ts->report( __FILE__, __LINE__, false, M ); return 1 # define EXAM_ERROR(M) __exam_ts->report( __FILE__, __LINE__, false, M ); __exam_counter |= 1 +# define EXAM_ERROR_ASYNC(M) exam::test_suite::top().report( __FILE__, __LINE__, false, M ); exam::test_suite::top().set_fail() #else # define EXAM_IMPL(F) F( exam::test_suite *, int ) # define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) # define EXAM_RESULT 0 # define EXAM_CHECK(C) +# define EXAM_CHECK_ASYNC(C) # define EXAM_MESSAGE(M) +# define EXAM_MESSAGE_ASYNC(M) # define EXAM_REQUIRE(C) # define EXAM_FAIL(M) # define EXAM_ERROR(M) +# define EXAM_ERROR_ASYNC(M) #endif Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-07-16 21:14:15 UTC (rev 1616) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-07-17 06:29:46 UTC (rev 1617) @@ -1,5 +1,9 @@ 2007-07-17 Petr Ovtchenkov <pt...@is...> + * suite.h, suite.cc: was introduced stack of test suites, functions + for asynchronous checks; add macros for asynchronous checkes + [in case when point can't be unambiguously associated with some test case]; + * suite.h, suite.cc: added multiple dependencies; * ut/exam_test_suite.cc, ut/exam_test_suite.h, ut/dummy_test.cc: Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-07-16 21:14:15 UTC (rev 1616) +++ trunk/complement/explore/lib/exam/suite.cc 2007-07-17 06:29:46 UTC (rev 1617) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/17 00:36:02 ptr> +// -*- C++ -*- Time-stamp: <07/07/17 10:03:02 ptr> #include <exam/suite.h> #include <boost/graph/breadth_first_search.hpp> @@ -101,26 +101,33 @@ test_suite::test_suite( const string& name ) : root( add_vertex( white_color, g ) ), + _last_state( 0 ), _suite_name( name ), local_logger( logger ) { testcase = get( vertex_testcase, g ); _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); _test[root].state = 0; + + _stack.push( this ); } test_suite::test_suite( const char *name ) : root( add_vertex( white_color, g ) ), + _last_state( 0 ), _suite_name( name ), local_logger( logger ) { testcase = get( vertex_testcase, g ); _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); _test[root].state = 0; + + _stack.push( this ); } test_suite::~test_suite() { + _stack.pop(); for ( test_case_map_type::iterator i = _test.begin(); i != _test.end(); ++i ) { delete i->second.tc; } @@ -193,10 +200,25 @@ return local_logger->flags( f ); } +void test_suite::set_fail() +{ + _last_state = fail; +} + trivial_logger __trivial_logger_inst( cerr ); base_logger *test_suite::logger = &__trivial_logger_inst; +stack<test_suite *> test_suite::_stack; +test_suite& test_suite::top() +{ + if ( _stack.empty() ) { + throw runtime_error( "stack of test suites empty" ); + } + + return *_stack.top(); +} + base_logger *test_suite::set_global_logger( base_logger *new_logger ) { base_logger *tmp = logger; @@ -225,8 +247,15 @@ ++_stat.total; if ( _test[v].state == 0 ) { if ( (*_test[v].tc)( this, 0 ) == 0 ) { - ++_stat.passed; - local_logger->tc( base_logger::pass, _test[v].name ); + if ( _last_state == 0 ) { + ++_stat.passed; + local_logger->tc( base_logger::pass, _test[v].name ); + } else { + _test[v].state = fail; + ++_stat.failed; + local_logger->tc( base_logger::fail, _test[v].name ); + _last_state = 0; + } } else { _test[v].state = fail; ++_stat.failed; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |