[complement-svn] SF.net SVN: complement: [1600] trunk/complement/explore/app/exam
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-06 06:29:30
|
Revision: 1600 http://svn.sourceforge.net/complement/?rev=1600&view=rev Author: complement Date: 2007-07-05 23:29:26 -0700 (Thu, 05 Jul 2007) Log Message: ----------- state zero Added Paths: ----------- trunk/complement/explore/app/exam/Makefile trunk/complement/explore/app/exam/Makefile.inc trunk/complement/explore/app/exam/suite.cc trunk/complement/explore/app/exam/suite.h trunk/complement/explore/app/exam/zero.cc Property Changed: ---------------- trunk/complement/explore/app/exam/ Property changes on: trunk/complement/explore/app/exam ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/app/exam/Makefile =================================================================== --- trunk/complement/explore/app/exam/Makefile (rev 0) +++ trunk/complement/explore/app/exam/Makefile 2007-07-06 06:29:26 UTC (rev 1600) @@ -0,0 +1,10 @@ +# -*- Makefile -*- Time-stamp: <07/07/05 09:31:15 ptr> + +SRCROOT := ../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_DIR} + +LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} Added: trunk/complement/explore/app/exam/Makefile.inc =================================================================== --- trunk/complement/explore/app/exam/Makefile.inc (rev 0) +++ trunk/complement/explore/app/exam/Makefile.inc 2007-07-06 06:29:26 UTC (rev 1600) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <02/07/14 14:03:13 ptr> + +PRGNAME = zero +SRC_CC = zero.cc suite.cc Added: trunk/complement/explore/app/exam/suite.cc =================================================================== --- trunk/complement/explore/app/exam/suite.cc (rev 0) +++ trunk/complement/explore/app/exam/suite.cc 2007-07-06 06:29:26 UTC (rev 1600) @@ -0,0 +1,79 @@ +// -*- C++ -*- Time-stamp: <07/07/06 09:55:44 ptr> + +#include "suite.h" +#include <boost/graph/breadth_first_search.hpp> +#include <stack> + +namespace exam { + +using namespace std; +using namespace boost; + + +template <class VertexList, class Tag> +struct vertex_recorder : + public base_visitor<vertex_recorder<VertexList,Tag> > +{ + typedef Tag event_filter; + + vertex_recorder(VertexList& pa) : + m_vertex(pa) + { } + + template <class Vertex, class Graph> + void operator()(Vertex v, const Graph& g) + { m_vertex.push_back( v ); } + + VertexList& m_vertex; +}; + +template <class VertexList, class Tag> +vertex_recorder<VertexList, Tag> record_vertexes(VertexList& pa, Tag) +{ return vertex_recorder<VertexList, Tag>(pa); } + +test_suite::test_suite() : + root( add_vertex( white_color, g ) ) +{ + color = get( vertex_color, g ); + testcase = get( vertex_testcase, g ); + _test[root] = 0; +} + +void test_suite::girdle( int start ) +{ + stack<vertex_t> buffer; + list<vertex_t> v; + breadth_first_visit( g, root, buffer, + make_bfs_visitor(record_vertexes(v,on_discover_vertex())), + 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 ( ... ) { + } + } +} + +test_suite::test_case_type test_suite::add( test_suite::func_type f ) +{ + vertex_t v = add_vertex( white_color, g); + add_edge( root, v, g ); + _test[v] = detail::make_test_case( detail::call( f ) ); + + return v; +} + +test_suite::test_case_type test_suite::add( test_suite::func_type f, test_suite::test_case_type depends ) +{ + vertex_t v = add_vertex( white_color, g); + add_edge( depends, v, g ); + _test[v] = detail::make_test_case( detail::call( f ) ); + + return v; +} + +} // namespace exam Added: trunk/complement/explore/app/exam/suite.h =================================================================== --- trunk/complement/explore/app/exam/suite.h (rev 0) +++ trunk/complement/explore/app/exam/suite.h 2007-07-06 06:29:26 UTC (rev 1600) @@ -0,0 +1,154 @@ +// -*- C++ -*- Time-stamp: <07/07/06 09:58:06 ptr> + +#ifndef __suite_h +#define __suite_h + +#include <iostream> +#include <sstream> +#include <map> +#include <boost/graph/adjacency_list.hpp> + +enum vertex_testcase_t { vertex_testcase }; + +namespace boost { + BOOST_INSTALL_PROPERTY( vertex, testcase ); +} // namespace boost + +namespace exam { + +namespace detail { + +/* +struct invoker +{ + template <typename F> + void invoke( F& f ) + { f(); } +}; +*/ + +struct call_impl +{ + virtual ~call_impl() + { } + virtual void invoke() = 0; +}; + +template <typename F> +class call_impl_t : + public call_impl +{ + public: + explicit call_impl_t( F f ) : + _f( f ) + { } + + virtual void invoke() + { /* invoker().invoke( _f ); */ _f(); } + + private: + F _f; +}; + +class call +{ + public: + call() + { } + + template <class F> + call( F f ) : + _f( new call_impl_t<F>(f) ) + { } + + void operator()() + { _f->invoke(); } + + private: + call_impl *_f; +}; + +template <class TC> +class method_invoker +{ + public: + typedef void (TC::*mf_type)(); + method_invoker( TC& instance, mf_type f ) : + _inst(instance), + _func(f) + { } + + void operator()() + { _inst.*_func(); } + + private: + TC& _inst; + mf_type _func; +}; + +class test_case +{ + public: + test_case( const call& f ) : + _tc( f ) + { } + + void operator ()() + { _tc(); } + + private: + call _tc; +}; + +inline test_case *make_test_case( const call& f ) +{ + return new test_case( f ); +} + +template <class TC> +inline test_case *make_test_case( void (TC::*f)(), TC& instance ) +{ + return new test_case( method_invoker<TC>(instance, f) ); +} + +} // namespace detail + +class test_suite +{ + private: + typedef boost::property<vertex_testcase_t,int> TestCaseProperty; + typedef boost::property<boost::vertex_color_t, boost::default_color_type, TestCaseProperty> VColorProperty; + + typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VColorProperty > graph_t; + typedef boost::graph_traits<graph_t>::vertex_iterator vertex_iterator_t; + + typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t; + typedef boost::property_map<graph_t,boost::vertex_color_t>::type vertex_color_map_t; + typedef boost::property_map<graph_t,vertex_testcase_t>::type vertex_testcase_map_t; + + public: + typedef void (*func_type)(); + typedef vertex_t test_case_type; + + test_suite(); + + test_case_type add( func_type ); + test_case_type add( func_type, test_case_type ); + + void girdle( int start ); + + private: + graph_t g; + vertex_t root; + vertex_color_map_t color; + vertex_testcase_map_t testcase; + + std::map<vertex_t,detail::test_case *> _test; +}; + +typedef test_suite::test_case_type test_case_type; + +} // namespace exam + +#endif // __suite_h + Added: trunk/complement/explore/app/exam/zero.cc =================================================================== --- trunk/complement/explore/app/exam/zero.cc (rev 0) +++ trunk/complement/explore/app/exam/zero.cc 2007-07-06 06:29:26 UTC (rev 1600) @@ -0,0 +1,69 @@ +#define FIT_EXAM + +#ifdef FIT_EXAM +# define EXAM_CHECK(C) if ( !(C) ) { exam::report( __FILE__, __LINE__, false, #C ); } else if ( exam::base::is_trace() ) { exam::report( __FILE__, __LINE__, true, #C ); } +# define EXAM_MESSAGE(M) +#else +# define EXAM_CHECK(C) +# define EXAM_MESSAGE(M) +#endif + + +#include <cstdio> +#include <iostream> + +#include "suite.h" + +namespace exam { + +class base +{ + public: + enum { + trace = 1 + }; + + static int flags(); + static bool is_trace(); + + private: + + static int _flags; +}; + +void _report0( const char *file, int line, bool cnd, const char *expr ) +{ + std::cerr << file << ":" << line << ": " << (cnd ? "pass" : "fail" ) << " \"" << expr << "\"" + << std::endl; +} + +void _report1( const char *file, int line, bool cnd, const char *expr ) +{ + printf( "%s:%d: %s \"%s\"\n", file, line, (cnd ? "pass" : "fail"), expr ); +} + +void _report2( const char *file, int line, bool cnd, const char *expr ) +{ + fprintf( stderr, "%s:%d: %s \"%s\"\n", file, line, (cnd ? "pass" : "fail"), expr ); +} + +void (*report)( const char *, int, bool, const char * ) = _report0; + +} // namespec exam + +void func() +{ + EXAM_CHECK(false); +} + +int main( int argc, char **argv ) +{ + exam::test_suite t; + + t.add( func ); + + t.girdle( 0 ); + + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |