[complement-svn] SF.net SVN: complement: [1602] trunk/complement/explore/app/exam
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-11 07:35:15
|
Revision: 1602 http://svn.sourceforge.net/complement/?rev=1602&view=rev Author: complement Date: 2007-07-11 00:35:11 -0700 (Wed, 11 Jul 2007) Log Message: ----------- test functions return int, conditional run (from dependency) Modified Paths: -------------- trunk/complement/explore/app/exam/suite.cc trunk/complement/explore/app/exam/suite.h trunk/complement/explore/app/exam/zero.cc Modified: trunk/complement/explore/app/exam/suite.cc =================================================================== --- trunk/complement/explore/app/exam/suite.cc 2007-07-10 17:12:18 UTC (rev 1601) +++ trunk/complement/explore/app/exam/suite.cc 2007-07-11 07:35:11 UTC (rev 1602) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/08 23:39:10 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 11:10:45 ptr> #include "suite.h" #include <boost/graph/breadth_first_search.hpp> @@ -11,61 +11,87 @@ using namespace std; using namespace boost; +using namespace detail; +namespace detail { -template <class VertexList, class Tag> +template <class Tag> struct vertex_recorder : - public base_visitor<vertex_recorder<VertexList,Tag> > + public base_visitor<vertex_recorder<Tag> > { typedef Tag event_filter; - vertex_recorder(VertexList& pa) : - m_vertex(pa) + vertex_recorder(test_suite& ts) : + _suite(ts) { } template <class Vertex, class Graph> void operator()(Vertex v, const Graph& g) - { m_vertex.push_back( v ); } + { _suite.run_test_case( v ); } - VertexList& m_vertex; + test_suite& _suite; }; -template <class VertexList, class Tag> -vertex_recorder<VertexList, Tag> record_vertexes(VertexList& pa, Tag) -{ return vertex_recorder<VertexList, Tag>(pa); } +template <class Tag> +vertex_recorder<Tag> record_vertexes(test_suite& ts, Tag) +{ return vertex_recorder<Tag>(ts); } +template <class Tag> +struct skip_recorder : + public base_visitor<skip_recorder<Tag> > +{ + typedef Tag event_filter; + + skip_recorder(test_suite& ts) : + _suite(ts) + { } + + template <class Edge, class Graph> + void operator()(Edge e, const Graph& g) + { + // typename graph_traits<Graph>::vertex_descriptor u = boost::source( e, g ); + // typename graph_traits<Graph>::vertex_descriptor v = boost::target( e, g ); + _suite.check_test_case( boost::source( e, g ), boost::target( e, g ) ); + } + + test_suite& _suite; +}; + +template <class Tag> +skip_recorder<Tag> record_skip(test_suite& ts, Tag) +{ return skip_recorder<Tag>(ts); } + +int _root_func() +{ + return 0; +} + +} // namespace detail + test_suite::test_suite() : root( add_vertex( white_color, g ) ) { color = get( vertex_color, g ); testcase = get( vertex_testcase, g ); - _test[root] = 0; + _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); + _test[root].state = 0; } test_suite::~test_suite() { for ( test_case_map_type::iterator i = _test.begin(); i != _test.end(); ++i ) { - delete i->second; + delete i->second.tc; } } void test_suite::girdle() { stack<vertex_t> buffer; - list<vertex_t> v; breadth_first_visit( g, root, buffer, - make_bfs_visitor(record_vertexes(v,on_discover_vertex())), + make_bfs_visitor( + make_pair( record_vertexes(*this,on_discover_vertex()), + record_skip(*this,on_examine_edge()) ) ), color ); - - v.pop_front(); // remove root, it empty - - for ( list<vertex_t>::const_iterator i = v.begin(); i != v.end(); ++i ) { - try { - (*_test[*i])(); - } - catch ( ... ) { - } - } } void test_suite::girdle( test_suite::test_case_type start ) @@ -73,18 +99,10 @@ stack<vertex_t> buffer; list<vertex_t> v; breadth_first_visit( g, start, buffer, - make_bfs_visitor(record_vertexes(v,on_discover_vertex())), + make_bfs_visitor( + make_pair( record_vertexes(*this,on_discover_vertex()), + record_skip(*this,on_examine_edge()) ) ), color ); - - v.pop_front(); // remove root, it empty - - for ( list<vertex_t>::const_iterator i = v.begin(); i != v.end(); ++i ) { - try { - (*_test[*i])(); - } - catch ( ... ) { - } - } } @@ -92,7 +110,8 @@ { vertex_t v = add_vertex( white_color, g); add_edge( root, v, g ); - _test[v] = detail::make_test_case( detail::call( f ) ); + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; return v; } @@ -101,7 +120,8 @@ { vertex_t v = add_vertex( white_color, g); add_edge( depends, v, g ); - _test[v] = detail::make_test_case( detail::call( f ) ); + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; return v; } @@ -140,4 +160,25 @@ (*test_suite::_report)( file, line, cnd, expr ); } +void test_suite::run_test_case( test_suite::vertex_t v ) +{ + try { + if ( _test[v].state == 0 ) { + if ( (*_test[v].tc)() != 0 ) { + _test[v].state = fail; + } + } + } + catch ( ... ) { + _test[v].state = fail; + } +} + +void test_suite::check_test_case( test_suite::vertex_t u, test_suite::vertex_t v ) +{ + if ( _test[u].state != 0 ) { + _test[v].state = skip; + } +} + } // namespace exam Modified: trunk/complement/explore/app/exam/suite.h =================================================================== --- trunk/complement/explore/app/exam/suite.h 2007-07-10 17:12:18 UTC (rev 1601) +++ trunk/complement/explore/app/exam/suite.h 2007-07-11 07:35:11 UTC (rev 1602) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/08 23:40:05 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 11:02:41 ptr> #ifndef __suite_h #define __suite_h @@ -22,7 +22,7 @@ { virtual ~call_impl() { } - virtual void invoke() = 0; + virtual int invoke() = 0; }; template <typename F> @@ -34,8 +34,8 @@ _f( f ) { } - virtual void invoke() - { _f(); } + virtual int invoke() + { return _f(); } private: F _f; @@ -44,7 +44,7 @@ class dummy { public: - virtual void f() + virtual int f() { } private: virtual ~dummy() @@ -55,7 +55,7 @@ class method_invoker { public: - typedef void (TC::*mf_type)(); + typedef int (TC::*mf_type)(); explicit method_invoker( TC& instance, mf_type f ) : _inst(instance), @@ -67,8 +67,8 @@ _func( m._func ) { } - void operator()() - { (_inst.*_func)(); } + int operator()() + { return (_inst.*_func)(); } private: method_invoker& operator =( const method_invoker<TC>& ) @@ -88,8 +88,8 @@ call( F f ) { new (&_buf[0]) call_impl_t<F>(f); } - void operator()() - { reinterpret_cast<call_impl *>(&_buf[0])->invoke(); } + int operator()() + { return reinterpret_cast<call_impl *>(&_buf[0])->invoke(); } private: // call_impl *_f; @@ -104,8 +104,8 @@ _tc( f ) { } - void operator ()() - { _tc(); } + int operator ()() + { return _tc(); } private: call _tc; @@ -117,7 +117,7 @@ } template <class TC> -inline test_case *make_test_case( void (TC::*f)(), TC& instance ) +inline test_case *make_test_case( int (TC::*f)(), TC& instance ) { return new test_case( method_invoker<TC>(instance, f) ); } @@ -138,7 +138,7 @@ typedef boost::property_map<graph_t,vertex_testcase_t>::type vertex_testcase_map_t; public: - typedef void (*func_type)(); + typedef int (*func_type)(); typedef vertex_t test_case_type; test_suite(); @@ -148,14 +148,17 @@ test_case_type add( func_type, test_case_type ); template <class TC> - test_case_type add( void (TC::*)(), TC& ); + test_case_type add( int (TC::*)(), TC& ); template <class TC> - test_case_type add( void (TC::*)(), TC&, test_case_type ); + test_case_type add( int (TC::*)(), TC&, test_case_type ); void girdle(); void girdle( test_case_type start ); + void run_test_case( vertex_t v ); + void check_test_case( vertex_t u, vertex_t v ); + enum { trace = 1 }; @@ -165,12 +168,23 @@ static void report( const char *, int, bool, const char * ); private: + enum { + fail = 1, + skip = 2 + }; + graph_t g; vertex_t root; vertex_color_map_t color; vertex_testcase_map_t testcase; - typedef std::map<vertex_t,detail::test_case *> test_case_map_type; + struct test_case_collect + { + detail::test_case *tc; + int state; + }; + + typedef std::map<vertex_t,test_case_collect> test_case_map_type; test_case_map_type _test; static int _flags; @@ -178,21 +192,23 @@ }; template <class TC> -test_suite::test_case_type test_suite::add( void (TC::*f)(), TC& instance ) +test_suite::test_case_type test_suite::add( int (TC::*f)(), TC& instance ) { vertex_t v = boost::add_vertex( boost::white_color, g); boost::add_edge( root, v, g ); - _test[v] = detail::make_test_case( f, instance ); + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; return v; } template <class TC> -test_suite::test_case_type test_suite::add( void (TC::*f)(), TC& instance, test_suite::test_case_type depends ) +test_suite::test_case_type test_suite::add( int (TC::*f)(), TC& instance, test_suite::test_case_type depends ) { vertex_t v = boost::add_vertex( boost::white_color, g); boost::add_edge( depends, v, g ); - _test[v] = detail::make_test_case( f, instance ); + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; return v; } @@ -202,7 +218,7 @@ } // namespace exam #ifdef FIT_EXAM -# define EXAM_CHECK(C) if ( !(C) ) { exam::test_suite::report( __FILE__, __LINE__, false, #C ); } else if ( exam::test_suite::is_trace() ) { exam::test_suite::report( __FILE__, __LINE__, true, #C ); } +# define EXAM_CHECK(C) if ( !(C) ) { exam::test_suite::report( __FILE__, __LINE__, false, #C ); return 1; } else if ( exam::test_suite::is_trace() ) { exam::test_suite::report( __FILE__, __LINE__, true, #C ); } # define EXAM_MESSAGE(M) #else # define EXAM_CHECK(C) Modified: trunk/complement/explore/app/exam/zero.cc =================================================================== --- trunk/complement/explore/app/exam/zero.cc 2007-07-10 17:12:18 UTC (rev 1601) +++ trunk/complement/explore/app/exam/zero.cc 2007-07-11 07:35:11 UTC (rev 1602) @@ -2,18 +2,22 @@ #include "suite.h" -void func() +int func() { EXAM_CHECK(false); + + return 0; } class test_x { public: - void f() + int f() { EXAM_CHECK(false); + + return 0; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |