[complement-svn] SF.net SVN: complement: [1614] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-16 14:34:45
|
Revision: 1614 http://svn.sourceforge.net/complement/?rev=1614&view=rev Author: complement Date: 2007-07-16 07:34:39 -0700 (Mon, 16 Jul 2007) Log Message: ----------- prepare exam for usage as lib and self-unit-test Added Paths: ----------- trunk/complement/explore/include/exam/ trunk/complement/explore/include/exam/logger.h trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ trunk/complement/explore/lib/exam/logger.cc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/ trunk/complement/explore/lib/exam/ut/Makefile trunk/complement/explore/lib/exam/ut/Makefile.inc trunk/complement/explore/lib/exam/ut/dummy_test.cc trunk/complement/explore/lib/exam/ut/exam_self_test.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Removed Paths: ------------- trunk/complement/explore/app/exam/dummy_test.cc trunk/complement/explore/app/exam/exam_self_test.cc trunk/complement/explore/app/exam/exam_test_suite.cc trunk/complement/explore/app/exam/exam_test_suite.h trunk/complement/explore/app/exam/logger.cc trunk/complement/explore/app/exam/logger.h trunk/complement/explore/app/exam/suite.cc trunk/complement/explore/app/exam/suite.h Deleted: trunk/complement/explore/app/exam/dummy_test.cc =================================================================== --- trunk/complement/explore/app/exam/dummy_test.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/dummy_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,36 +0,0 @@ -#include "suite.h" - -int EXAM_IMPL(func) -{ - EXAM_CHECK(false); - - return EXAM_RESULT; -} - -class test_x -{ - public: - - int EXAM_IMPL(f) - { - EXAM_CHECK(false); - EXAM_CHECK(true); - - return EXAM_RESULT; - } - - int EXAM_IMPL(f_good) - { - EXAM_CHECK(true); - EXAM_CHECK(true); - - return EXAM_RESULT; - } -}; - -int EXAM_IMPL(func_good) -{ - EXAM_CHECK(true); - - return EXAM_RESULT; -} Deleted: trunk/complement/explore/app/exam/exam_self_test.cc =================================================================== --- trunk/complement/explore/app/exam/exam_self_test.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/exam_self_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,14 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> - -#include "exam_test_suite.h" - -int main( int, char ** ) -{ - // exam::test_suite t( "exam self test" ); - // t.add( exam_self_test, "exam self test suite" ); - // - // return t.girdle(); - - return exam_self_test(0); -} - Deleted: trunk/complement/explore/app/exam/exam_test_suite.cc =================================================================== --- trunk/complement/explore/app/exam/exam_test_suite.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/exam_test_suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,239 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> - -#include "exam_test_suite.h" - -#include "dummy_test.cc" - -int EXAM_IMPL(exam_basic_test::function_good) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, good function" ); - t.set_logger( &logger ); - - test_x tx; - t.add( func_good, "function" ); - t.add( &test_x::f_good, tx, "member function" ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r0 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::function) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, fail function" ); - t.set_logger( &logger ); - - test_x tx; - t.add( func, "function" ); - t.add( &test_x::f, tx, "member function" ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r1 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::dep) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, fail function" ); - t.set_logger( &logger ); - - test_x tx; - t.add( func_good, "function good", // "child" - t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" - t.add( func, "function fail", // <- skiped, because depends upon failed (next line) - t.add( &test_x::f, tx, "member function fail" ) ); // <- fail - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r2 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::trace) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, fail function" ); - t.set_logger( &logger ); - - logger.flags( exam::base_logger::trace_suite ); - - test_x tx; - t.add( func_good, "function good", // "child" - t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" - t.add( func, "function fail", // <- skiped, because depends upon failed (next line) - t.add( &test_x::f, tx, "member function fail" ) ); // <- fail - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r3 ); - - buff.str( "" ); - buff.clear(); - - logger.flags( exam::base_logger::silent ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r4 ); - - buff.str( "" ); - buff.clear(); - - logger.flags( exam::base_logger::trace ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r5 ); - - buff.str( "" ); - buff.clear(); - - logger.flags( exam::base_logger::verbose ); - - t.girdle(); - - logger.flags( 0 ); - - EXAM_REQUIRE( buff.str() == r6 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::dep_test_suite) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t0( "exam self test, test suite master" ); - t0.set_logger( &logger ); - - test_x tx0; - t0.add( func_good, "function" ); - t0.add( &test_x::f_good, tx0, "member function" ); - - exam::test_suite t1( "exam self test, test suite slave" ); - t1.set_logger( &logger ); - - test_x tx1; - t1.add( func_good, "function good", // "child" - t1.add( &test_x::f_good, tx1, "member function good" ) ); // "parent" - t1.add( func, "function fail", // <- skiped, because depends upon failed (next line) - t1.add( &test_x::f, tx1, "member function fail" ) ); // <- fail - - exam::test_suite t( "exam self test, test suites dependency" ); - t.set_logger( &logger ); - - t.add( &exam::test_suite::run, t1, "slave test suite", - t.add( &exam::test_suite::run, t0, "master test suite" ) ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r7 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -const std::string exam_basic_test::r0 = "\ -*** PASS exam self test, good function (+2-0~0/2) ***\n"; - -const std::string exam_basic_test::r1 = "\ -dummy_test.cc:5: fail: false\n\ - FAIL function\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function\n\ -*** FAIL exam self test, fail function (+0-2~0/2) ***\n"; - -const std::string exam_basic_test::r2 = "\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r3 = "\ -== Begin test suite\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -== End test suite\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r4 = "\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r5 = "\ -dummy_test.cc:24: pass: true\n\ -dummy_test.cc:25: pass: true\n\ -dummy_test.cc:16: fail: false\n\ -dummy_test.cc:17: pass: true\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -dummy_test.cc:33: pass: true\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r6 = "\ - PASS member function good\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ - PASS function good\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r7 = "\ -*** PASS exam self test, test suite master (+2-0~0/2) ***\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -*** FAIL exam self test, test suite slave (+2-1~1/4) ***\n\ - FAIL slave test suite\n\ -*** FAIL exam self test, test suites dependency (+1-1~0/2) ***\n"; - -int EXAM_IMPL(exam_self_test) -{ - exam::test_suite t( "exam self test" ); - exam_basic_test exam_basic; - - t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); - t.add( &exam_basic_test::function, exam_basic, "call test, fail calls" ); - exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency" ); - t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); - t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); - - return t.girdle(); -} - Deleted: trunk/complement/explore/app/exam/exam_test_suite.h =================================================================== --- trunk/complement/explore/app/exam/exam_test_suite.h 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/exam_test_suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,42 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> - -#ifndef __exam_test_suite_h -#define __exam_test_suite_h - -#define FIT_EXAM - -#include "suite.h" -#include <string> -#include <sstream> - -class exam_basic_test -{ - public: - exam_basic_test() : - buff(), - logger( buff ) - { } - - int EXAM_DECL(function_good); - int EXAM_DECL(function); - int EXAM_DECL(dep); - int EXAM_DECL(trace); - int EXAM_DECL(dep_test_suite); - - private: - std::stringstream buff; - exam::trivial_logger logger; - - static const std::string r0; - static const std::string r1; - static const std::string r2; - static const std::string r3; - static const std::string r4; - static const std::string r5; - static const std::string r6; - static const std::string r7; -}; - -int EXAM_DECL(exam_self_test); - -#endif // __exam_test_suite_h Deleted: trunk/complement/explore/app/exam/logger.cc =================================================================== --- trunk/complement/explore/app/exam/logger.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/logger.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,111 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/13 10:53:32 ptr> - -#include "logger.h" -#include <iostream> - -namespace exam { - -using namespace std; - -int base_logger::flags() const -{ - return _flags; -} - -bool base_logger::is_trace() const -{ - return (_flags & trace) != 0; -} - -int base_logger::flags( int f ) -{ - int tmp = _flags; - _flags = f; - if ( (f & silent) != 0 ) { - _flags &= ~trace_suite; - } - return tmp; -} - -void trivial_logger::report( const char *file, int line, bool cnd, const char *expr ) -{ - if ( (cnd && ((_flags & trace) == 0)) || ((_flags & silent) != 0) ) { - return; - } - - if ( s != 0 ) { - *s << file << ":" << line << ": " << (cnd ? "pass" : "fail" ) << ": " << expr - << std::endl; - } else { - fprintf( f, "%s:%d: %s: %s\n", file, line, (cnd ? "pass" : "fail" ), expr ); - } -} - -void trivial_logger::begin_ts() -{ - if ( (_flags & trace_suite) == 0 ) { - return; - } - - if ( s != 0 ) { - *s << "== Begin test suite\n"; - } else { - fprintf( f, "== Begin test suite\n" ); - } -} - -void trivial_logger::end_ts() -{ - if ( (_flags & trace_suite) == 0 ) { - return; - } - - if ( *s ) { - *s << "== End test suite\n"; - } else { - fprintf( f, "== End test suite\n" ); - } -} - -void trivial_logger::result( const base_logger::stat& _stat, const string& suite_name ) -{ - if ( s != 0 ) { - *s << "*** " << (_stat.failed != 0 ? "FAIL " : "PASS " ) << suite_name - << " (+" << _stat.passed - << "-" << _stat.failed - << "~" << _stat.skipped << "/" << _stat.total << ") ***" << endl; - } else { - fprintf( f, "*** %s (+%d-%d~%d/%d) ***\n", (_stat.failed != 0 ? "FAIL" : "PASS" ), _stat.passed, _stat.failed, _stat.skipped, _stat.total ); - } -} - -void trivial_logger::tc( base_logger::tc_result r, const std::string& name ) -{ - if ( ((_flags & silent) != 0) || ((r == pass) && ((_flags & verbose) == 0) )) { - return; - } - - static const char *m[] = { " PASS ", " FAIL ", " SKIP " }; - const char *rs = ""; - - switch ( r ) - { - case pass: - rs = m[0]; - break; - case fail: - rs = m[1]; - break; - case skip: - rs = m[2]; - break; - } - - if ( s != 0 ) { - *s << rs << name << endl; - } else { - fprintf( f, "%s%s\n", rs, name.c_str() ); - } -} - -} //namespace exam Deleted: trunk/complement/explore/app/exam/logger.h =================================================================== --- trunk/complement/explore/app/exam/logger.h 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/logger.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,94 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/13 11:01:52 ptr> - -#ifndef __logger_h -#define __logger_h - -#include <string> -#include <cstdio> -#include <ostream> - -namespace exam { - -class base_logger -{ - public: - - enum trace_flags { - trace = 1, - trace_suite = 2, - silent = 4, - verbose = 8 - }; - - enum tc_result { - pass = 0, - fail, - skip - }; - - struct stat - { - stat() : - total(0), - passed(0), - failed(0), - skipped(0) - { } - - int total; - int passed; - int failed; - int skipped; - }; - - base_logger() : - _flags( 0 ) - { } - virtual ~base_logger() - { } - - int flags() const; - bool is_trace() const; - - int flags( int ); - - virtual void report( const char *, int, bool, const char * ) = 0; - - virtual void begin_ts() = 0; - virtual void end_ts() = 0; - virtual void result( const base_logger::stat&, const std::string& suite_name ) = 0; - virtual void tc( tc_result, const std::string& ) = 0; - - protected: - int _flags; -}; - -class trivial_logger : - public base_logger -{ - public: - explicit trivial_logger( std::ostream& str ) : - s( &str ), - f( 0 ) - { } - - explicit trivial_logger( FILE *fs ) : - s( 0 ), - f( fs ) - { } - - virtual void report( const char *, int, bool, const char * ); - - virtual void begin_ts(); - virtual void end_ts(); - virtual void result( const base_logger::stat&, const std::string& ); - virtual void tc( base_logger::tc_result, const std::string& ); - - private: - std::ostream *s; - FILE *f; -}; - -} // namespace exam - -#endif // __logger_h Deleted: trunk/complement/explore/app/exam/suite.cc =================================================================== --- trunk/complement/explore/app/exam/suite.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,265 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/15 16:33:03 ptr> - -#include "suite.h" -#include <boost/graph/breadth_first_search.hpp> -#include <stack> - -#include <cstdio> -#include <iostream> - -namespace exam { - -using namespace std; -using namespace boost; -using namespace detail; - -namespace detail { - -template <class Tag> -struct vertex_recorder : - public base_visitor<vertex_recorder<Tag> > -{ - typedef Tag event_filter; - - vertex_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Vertex, class Graph> - void operator()(Vertex v, const Graph& g) - { _suite.run_test_case( v ); } - - test_suite& _suite; -}; - -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); } - -template <class Tag> -struct white_recorder : - public base_visitor<white_recorder<Tag> > -{ - typedef Tag event_filter; - - white_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Vertex, class Graph> - void operator()(Vertex v, const Graph& g) - { - // std::cerr << "On vertex " << v << std::endl; - // boost::put( boost::vertex_color, g, v, white_color ); - _suite.clean_test_case_state( v ); - } - - test_suite& _suite; -}; - -template <class Tag> -white_recorder<Tag> record_white(test_suite& ts, Tag) -{ return white_recorder<Tag>(ts); } - - -} // namespace detail - -int EXAM_IMPL(test_suite::_root_func) -{ - throw init_exception(); - - return -1; -} - -test_suite::test_suite( const string& name ) : - root( add_vertex( white_color, g ) ), - _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; -} - -test_suite::test_suite( const char *name ) : - root( add_vertex( white_color, g ) ), - _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; -} - -test_suite::~test_suite() -{ - for ( test_case_map_type::iterator i = _test.begin(); i != _test.end(); ++i ) { - delete i->second.tc; - } -} - -int test_suite::girdle( test_suite::test_case_type start ) -{ - stack<vertex_t> buffer; - vertex_color_map_t color = get( vertex_color, g ); - - // detail::white_recorder<on_initialize_vertex> vis( *this ); - // - // vertex_iterator_t i, i_end; - - // for ( tie(i, i_end) = vertices(g); i != i_end; ++i ) { - // // vis.initialize_vertex( *i, g ); - // put( color, *i, white_color ); - // } - - _stat = base_logger::stat(); - local_logger->begin_ts(); - breadth_first_search( g, start, buffer, - make_bfs_visitor( - make_pair( record_white(*this,on_initialize_vertex()), - make_pair( record_vertexes(*this,on_discover_vertex()), - record_skip(*this,on_examine_edge()) ) ) ), - color ); - local_logger->end_ts(); - local_logger->result( _stat, _suite_name ); - - return _stat.failed; -} - -test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name ) -{ - vertex_t v = add_vertex( white_color, g); - add_edge( root, v, g ); - _test[v].tc = detail::make_test_case( detail::call( f ) ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name, test_suite::test_case_type depends ) -{ - vertex_t v = add_vertex( white_color, g); - add_edge( depends, v, g ); - _test[v].tc = detail::make_test_case( detail::call( f ) ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -int test_suite::flags() -{ - return local_logger->flags(); -} - -bool test_suite::is_trace() -{ - return local_logger->is_trace(); -} - -int test_suite::flags( int f ) -{ - return local_logger->flags( f ); -} - -trivial_logger __trivial_logger_inst( cerr ); - -base_logger *test_suite::logger = &__trivial_logger_inst; - -base_logger *test_suite::set_global_logger( base_logger *new_logger ) -{ - base_logger *tmp = logger; - logger = new_logger; - if ( tmp == local_logger ) { // if local_logger was identical to logger, switch it too - local_logger = logger; - } - return tmp; -} - -base_logger *test_suite::set_logger( base_logger *new_logger ) -{ - base_logger *tmp = local_logger; - local_logger = new_logger; - return tmp; -} - -void test_suite::report( const char *file, int line, bool cnd, const char *expr ) -{ - local_logger->report( file, line, cnd, expr ); -} - -void test_suite::run_test_case( test_suite::vertex_t v ) -{ - try { - ++_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 ); - } else { - _test[v].state = fail; - ++_stat.failed; - local_logger->tc( base_logger::fail, _test[v].name ); - } - } else { - ++_stat.skipped; - local_logger->tc( base_logger::skip, _test[v].name ); - } - } - catch ( init_exception& ) { - --_stat.total; - } - catch ( ... ) { - ++_stat.failed; - _test[v].state = fail; - local_logger->tc( base_logger::fail, _test[v].name ); - } -} - -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; - } -} - -void test_suite::clean_test_case_state( vertex_t v ) -{ - _test[v].state = 0; -} - -int test_suite::run( test_suite *, int ) -{ - return girdle( root ); -} - - -} // namespace exam Deleted: trunk/complement/explore/app/exam/suite.h =================================================================== --- trunk/complement/explore/app/exam/suite.h 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,284 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/15 16:33:17 ptr> - -#ifndef __suite_h -#define __suite_h - -#include <iostream> -#include <sstream> -#include <map> -#include <boost/graph/adjacency_list.hpp> -#include <string> -#include <exception> - -#include "logger.h" - -enum vertex_testcase_t { vertex_testcase }; - -namespace boost { - BOOST_INSTALL_PROPERTY( vertex, testcase ); -} // namespace boost - -namespace exam { - -class test_suite; - -namespace detail { - -struct call_impl -{ - virtual ~call_impl() - { } - // virtual int invoke() = 0; - virtual int invoke( test_suite *, int = 0 ) = 0; -}; - -template <typename F> -class call_impl_t : - public call_impl -{ - public: - explicit call_impl_t( F f ) : - _f( f ) - { } - - // virtual int invoke() - // { return _f(); } - - virtual int invoke( test_suite *s, int count = 0 ) - { return _f( s, count ); } - - - private: - F _f; -}; - -class dummy -{ - public: - // virtual int f() - // { return 0; } - - virtual int f( test_suite *, int count = 0 ) - { return count; } - - private: - virtual ~dummy() - { } -}; - -template <class TC> -class method_invoker -{ - public: - // typedef int (TC::*mf_type_a)(); - typedef int (TC::*mf_type)( test_suite *, int ); - - explicit method_invoker( TC& instance, mf_type f ) : - _inst(instance), - _func(f) - { } - - method_invoker( const method_invoker<TC>& m ) : - _inst( m._inst ), - _func( m._func ) - { } - - // int operator()() - // { return (_inst.*_func)(); } - - int operator()( test_suite *ts, int count = 0 ) - { return (_inst.*_func)( ts, count ); } - - private: - method_invoker& operator =( const method_invoker<TC>& ) - { return *this; } - - TC& _inst; - mf_type _func; -}; - -class call -{ - public: - call() - { } - - template <class F> - call( F f ) - { new (&_buf[0]) call_impl_t<F>(f); } - - // int operator()() - // { return reinterpret_cast<call_impl *>(&_buf[0])->invoke(); } - - int operator()( test_suite *ts, int count = 0 ) - { return reinterpret_cast<call_impl *>(&_buf[0])->invoke( ts, count ); } - - private: - // call_impl *_f; - char _buf[((sizeof(call_impl_t<method_invoker<dummy> >)+64) / 64) << 6]; -}; - - -class test_case -{ - public: - test_case( const call& f ) : - _tc( f ) - { } - - // int operator ()() - // { return _tc(); } - - int operator ()( test_suite *ts, int count = 0 ) - { return _tc( ts, count ); } - - 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( int (TC::*f)( test_suite *, int ), TC& instance ) -{ - return new test_case( method_invoker<TC>(instance, f) ); -} - -} // namespace detail - -class init_exception : - public std::exception -{ -}; - -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 int (*func_type)( test_suite *, int ); - typedef vertex_t test_case_type; - - test_suite( const std::string& name ); - test_suite( const char *name ); - ~test_suite(); - - test_case_type add( func_type, const std::string& name ); - test_case_type add( func_type, const std::string& name, test_case_type ); - - template <class TC> - test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name ); - - template <class TC> - test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name, test_case_type ); - - int girdle( test_case_type start ); - int girdle() - { return girdle( root ); } - int run( test_suite *, int count = 0 ); - - void run_test_case( vertex_t v ); - void check_test_case( vertex_t u, vertex_t v ); - void clean_test_case_state( vertex_t v ); - - int flags(); - int flags( int ); - bool is_trace(); - void report( const char *, int, bool, const char * ); - base_logger *set_global_logger( base_logger * ); - base_logger *set_logger( base_logger * ); - - private: - enum { - pass = 0, - fail = 1, - skip = 2 - }; - - graph_t g; - vertex_t root; - vertex_testcase_map_t testcase; - base_logger *local_logger; - - struct test_case_collect - { - detail::test_case *tc; - int state; - std::string name; - }; - - typedef std::map<vertex_t,test_case_collect> test_case_map_type; - test_case_map_type _test; - base_logger::stat _stat; - std::string _suite_name; - - static int _root_func( test_suite *, int = 0 ); - - static base_logger *logger; -}; - -template <class TC> -test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name ) -{ - vertex_t v = boost::add_vertex( boost::white_color, g); - boost::add_edge( root, v, g ); - _test[v].tc = detail::make_test_case( f, instance ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -template <class TC> -test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, test_suite::test_case_type depends ) -{ - vertex_t v = boost::add_vertex( boost::white_color, g); - boost::add_edge( depends, v, g ); - _test[v].tc = detail::make_test_case( f, instance ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -typedef test_suite::test_case_type test_case_type; - -} // namespace exam - -#ifdef FIT_EXAM -# define EXAM_IMPL(F) F( exam::test_suite *__exam_ts, int __exam_counter ) -# 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_MESSAGE(M) __exam_ts->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 -#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_MESSAGE(M) -# define EXAM_REQUIRE(C) -# define EXAM_FAIL(M) -# define EXAM_ERROR(M) -#endif - - -#endif // __suite_h - Copied: trunk/complement/explore/include/exam/logger.h (from rev 1612, trunk/complement/explore/app/exam/logger.h) =================================================================== --- trunk/complement/explore/include/exam/logger.h (rev 0) +++ trunk/complement/explore/include/exam/logger.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,94 @@ +// -*- C++ -*- Time-stamp: <07/07/13 11:01:52 ptr> + +#ifndef __logger_h +#define __logger_h + +#include <string> +#include <cstdio> +#include <ostream> + +namespace exam { + +class base_logger +{ + public: + + enum trace_flags { + trace = 1, + trace_suite = 2, + silent = 4, + verbose = 8 + }; + + enum tc_result { + pass = 0, + fail, + skip + }; + + struct stat + { + stat() : + total(0), + passed(0), + failed(0), + skipped(0) + { } + + int total; + int passed; + int failed; + int skipped; + }; + + base_logger() : + _flags( 0 ) + { } + virtual ~base_logger() + { } + + int flags() const; + bool is_trace() const; + + int flags( int ); + + virtual void report( const char *, int, bool, const char * ) = 0; + + virtual void begin_ts() = 0; + virtual void end_ts() = 0; + virtual void result( const base_logger::stat&, const std::string& suite_name ) = 0; + virtual void tc( tc_result, const std::string& ) = 0; + + protected: + int _flags; +}; + +class trivial_logger : + public base_logger +{ + public: + explicit trivial_logger( std::ostream& str ) : + s( &str ), + f( 0 ) + { } + + explicit trivial_logger( FILE *fs ) : + s( 0 ), + f( fs ) + { } + + virtual void report( const char *, int, bool, const char * ); + + virtual void begin_ts(); + virtual void end_ts(); + virtual void result( const base_logger::stat&, const std::string& ); + virtual void tc( base_logger::tc_result, const std::string& ); + + private: + std::ostream *s; + FILE *f; +}; + +} // namespace exam + +#endif // __logger_h Copied: trunk/complement/explore/include/exam/suite.h (from rev 1612, trunk/complement/explore/app/exam/suite.h) =================================================================== --- trunk/complement/explore/include/exam/suite.h (rev 0) +++ trunk/complement/explore/include/exam/suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,284 @@ +// -*- C++ -*- Time-stamp: <07/07/15 16:33:17 ptr> + +#ifndef __suite_h +#define __suite_h + +#include <iostream> +#include <sstream> +#include <map> +#include <boost/graph/adjacency_list.hpp> +#include <string> +#include <exception> + +#include "logger.h" + +enum vertex_testcase_t { vertex_testcase }; + +namespace boost { + BOOST_INSTALL_PROPERTY( vertex, testcase ); +} // namespace boost + +namespace exam { + +class test_suite; + +namespace detail { + +struct call_impl +{ + virtual ~call_impl() + { } + // virtual int invoke() = 0; + virtual int invoke( test_suite *, int = 0 ) = 0; +}; + +template <typename F> +class call_impl_t : + public call_impl +{ + public: + explicit call_impl_t( F f ) : + _f( f ) + { } + + // virtual int invoke() + // { return _f(); } + + virtual int invoke( test_suite *s, int count = 0 ) + { return _f( s, count ); } + + + private: + F _f; +}; + +class dummy +{ + public: + // virtual int f() + // { return 0; } + + virtual int f( test_suite *, int count = 0 ) + { return count; } + + private: + virtual ~dummy() + { } +}; + +template <class TC> +class method_invoker +{ + public: + // typedef int (TC::*mf_type_a)(); + typedef int (TC::*mf_type)( test_suite *, int ); + + explicit method_invoker( TC& instance, mf_type f ) : + _inst(instance), + _func(f) + { } + + method_invoker( const method_invoker<TC>& m ) : + _inst( m._inst ), + _func( m._func ) + { } + + // int operator()() + // { return (_inst.*_func)(); } + + int operator()( test_suite *ts, int count = 0 ) + { return (_inst.*_func)( ts, count ); } + + private: + method_invoker& operator =( const method_invoker<TC>& ) + { return *this; } + + TC& _inst; + mf_type _func; +}; + +class call +{ + public: + call() + { } + + template <class F> + call( F f ) + { new (&_buf[0]) call_impl_t<F>(f); } + + // int operator()() + // { return reinterpret_cast<call_impl *>(&_buf[0])->invoke(); } + + int operator()( test_suite *ts, int count = 0 ) + { return reinterpret_cast<call_impl *>(&_buf[0])->invoke( ts, count ); } + + private: + // call_impl *_f; + char _buf[((sizeof(call_impl_t<method_invoker<dummy> >)+64) / 64) << 6]; +}; + + +class test_case +{ + public: + test_case( const call& f ) : + _tc( f ) + { } + + // int operator ()() + // { return _tc(); } + + int operator ()( test_suite *ts, int count = 0 ) + { return _tc( ts, count ); } + + 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( int (TC::*f)( test_suite *, int ), TC& instance ) +{ + return new test_case( method_invoker<TC>(instance, f) ); +} + +} // namespace detail + +class init_exception : + public std::exception +{ +}; + +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 int (*func_type)( test_suite *, int ); + typedef vertex_t test_case_type; + + test_suite( const std::string& name ); + test_suite( const char *name ); + ~test_suite(); + + test_case_type add( func_type, const std::string& name ); + test_case_type add( func_type, const std::string& name, test_case_type ); + + template <class TC> + test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name ); + + template <class TC> + test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name, test_case_type ); + + int girdle( test_case_type start ); + int girdle() + { return girdle( root ); } + int run( test_suite *, int count = 0 ); + + void run_test_case( vertex_t v ); + void check_test_case( vertex_t u, vertex_t v ); + void clean_test_case_state( vertex_t v ); + + int flags(); + int flags( int ); + bool is_trace(); + void report( const char *, int, bool, const char * ); + base_logger *set_global_logger( base_logger * ); + base_logger *set_logger( base_logger * ); + + private: + enum { + pass = 0, + fail = 1, + skip = 2 + }; + + graph_t g; + vertex_t root; + vertex_testcase_map_t testcase; + base_logger *local_logger; + + struct test_case_collect + { + detail::test_case *tc; + int state; + std::string name; + }; + + typedef std::map<vertex_t,test_case_collect> test_case_map_type; + test_case_map_type _test; + base_logger::stat _stat; + std::string _suite_name; + + static int _root_func( test_suite *, int = 0 ); + + static base_logger *logger; +}; + +template <class TC> +test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name ) +{ + vertex_t v = boost::add_vertex( boost::white_color, g); + boost::add_edge( root, v, g ); + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +template <class TC> +test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, test_suite::test_case_type depends ) +{ + vertex_t v = boost::add_vertex( boost::white_color, g); + boost::add_edge( depends, v, g ); + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +typedef test_suite::test_case_type test_case_type; + +} // namespace exam + +#ifdef FIT_EXAM +# define EXAM_IMPL(F) F( exam::test_suite *__exam_ts, int __exam_counter ) +# 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_MESSAGE(M) __exam_ts->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 +#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_MESSAGE(M) +# define EXAM_REQUIRE(C) +# define EXAM_FAIL(M) +# define EXAM_ERROR(M) +#endif + + +#endif // __suite_h + Property changes on: trunk/complement/explore/lib/exam ___________________________________________________________________ Name: svn:ignore + obj Copied: trunk/complement/explore/lib/exam/logger.cc (from rev 1612, trunk/complement/explore/app/exam/logger.cc) =================================================================== --- trunk/complement/explore/lib/exam/logger.cc (rev 0) +++ trunk/complement/explore/lib/exam/logger.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,111 @@ +// -*- C++ -*- Time-stamp: <07/07/13 10:53:32 ptr> + +#include <exam/logger.h> +#include <iostream> + +namespace exam { + +using namespace std; + +int base_logger::flags() const +{ + return _flags; +} + +bool base_logger::is_trace() const +{ + return (_flags & trace) != 0; +} + +int base_logger::flags( int f ) +{ + int tmp = _flags; + _flags = f; + if ( (f & silent) != 0 ) { + _flags &= ~trace_suite; + } + return tmp; +} + +void trivial_logger::report( const char *file, int line, bool cnd, const char *expr ) +{ + if ( (cnd && ((_flags & trace) == 0)) || ((_flags & silent) != 0) ) { + return; + } + + if ( s != 0 ) { + *s << file << ":" << line << ": " << (cnd ? "pass" : "fail" ) << ": " << expr + << std::endl; + } else { + fprintf( f, "%s:%d: %s: %s\n", file, line, (cnd ? "pass" : "fail" ), expr ); + } +} + +void trivial_logger::begin_ts() +{ + if ( (_flags & trace_suite) == 0 ) { + return; + } + + if ( s != 0 ) { + *s << "== Begin test suite\n"; + } else { + fprintf( f, "== Begin test suite\n" ); + } +} + +void trivial_logger::end_ts() +{ + if ( (_flags & trace_suite) == 0 ) { + return; + } + + if ( *s ) { + *s << "== End test suite\n"; + } else { + fprintf( f, "== End test suite\n" ); + } +} + +void trivial_logger::result( const base_logger::stat& _stat, const string& suite_name ) +{ + if ( s != 0 ) { + *s << "*** " << (_stat.failed != 0 ? "FAIL " : "PASS " ) << suite_name + << " (+" << _stat.passed + << "-" << _stat.failed + << "~" << _stat.skipped << "/" << _stat.total << ") ***" << endl; + } else { + fprintf( f, "*** %s (+%d-%d~%d/%d) ***\n", (_stat.failed != 0 ? "FAIL" : "PASS" ), _stat.passed, _stat.failed, _stat.skipped, _stat.total ); + } +} + +void trivial_logger::tc( base_logger::tc_result r, const std::string& name ) +{ + if ( ((_flags & silent) != 0) || ((r == pass) && ((_flags & verbose) == 0) )) { + return; + } + + static const char *m[] = { " PASS ", " FAIL ", " SKIP " }; + const char *rs = ""; + + switch ( r ) + { + case pass: + rs = m[0]; + break; + case fail: + rs = m[1]; + break; + case skip: + rs = m[2]; + break; + } + + if ( s != 0 ) { + *s << rs << name << endl; + } else { + fprintf( f, "%s%s\n", rs, name.c_str() ); + } +} + +} //namespace exam Copied: trunk/complement/explore/lib/exam/suite.cc (from rev 1612, trunk/complement/explore/app/exam/suite.cc) =================================================================== --- trunk/complement/explore/lib/exam/suite.cc (rev 0) +++ trunk/complement/explore/lib/exam/suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,265 @@ +// -*- C++ -*- Time-stamp: <07/07/15 16:33:03 ptr> + +#include <exam/suite.h> +#include <boost/graph/breadth_first_search.hpp> +#include <stack> + +#include <cstdio> +#include <iostream> + +namespace exam { + +using namespace std; +using namespace boost; +using namespace detail; + +namespace detail { + +template <class Tag> +struct vertex_recorder : + public base_visitor<vertex_recorder<Tag> > +{ + typedef Tag event_filter; + + vertex_recorder(test_suite& ts) : + _suite(ts) + { } + + template <class Vertex, class Graph> + void operator()(Vertex v, const Graph& g) + { _suite.run_test_case( v ); } + + test_suite& _suite; +}; + +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); } + +template <class Tag> +struct white_recorder : + public base_visitor<white_recorder<Tag> > +{ + typedef Tag event_filter; + + white_recorder(test_suite& ts) : + _suite(ts) + { } + + template <class Vertex, class Graph> + void operator()(Vertex v, const Graph& g) + { + // std::cerr << "On vertex " << v << std::endl; + // boost::put( boost::vertex_color, g, v, white_color ); + _suite.clean_test_case_state( v ); + } + + test_suite& _suite; +}; + +template <class Tag> +white_recorder<Tag> record_white(test_suite& ts, Tag) +{ return white_recorder<Tag>(ts); } + + +} // namespace detail + +int EXAM_IMPL(test_suite::_root_func) +{ + throw init_exception(); + + return -1; +} + +test_suite::test_suite( const string& name ) : + root( add_vertex( white_color, g ) ), + _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; +} + +test_suite::test_suite( const char *name ) : + root( add_vertex( white_color, g ) ), + _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; +} + +test_suite::~test_suite() +{ + for ( test_case_map_type::iterator i = _test.begin(); i != _test.end(); ++i ) { + delete i->second.tc; + } +} + +int test_suite::girdle( test_suite::test_case_type start ) +{ + stack<vertex_t> buffer; + vertex_color_map_t color = get( vertex_color, g ); + + // detail::white_recorder<on_initialize_vertex> vis( *this ); + // + // vertex_iterator_t i, i_end; + + // for ( tie(i, i_end) = vertices(g); i != i_end; ++i ) { + // // vis.initialize_vertex( *i, g ); + // put( color, *i, white_color ); + // } + + _stat = base_logger::stat(); + local_logger->begin_ts(); + breadth_first_search( g, start, buffer, + make_bfs_visitor( + make_pair( record_white(*this,on_initialize_vertex()), + make_pair( record_vertexes(*this,on_discover_vertex()), + record_skip(*this,on_examine_edge()) ) ) ), + color ); + local_logger->end_ts(); + local_logger->result( _stat, _suite_name ); + + return _stat.failed; +} + +test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name ) +{ + vertex_t v = add_vertex( white_color, g); + add_edge( root, v, g ); + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name, test_suite::test_case_type depends ) +{ + vertex_t v = add_vertex( white_color, g); + add_edge( depends, v, g ); + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +int test_suite::flags() +{ + return local_logger->flags(); +} + +bool test_suite::is_trace() +{ + return local_logger->is_trace(); +} + +int test_suite::flags( int f ) +{ + return local_logger->flags( f ); +} + +trivial_logger __trivial_logger_inst( cerr ); + +base_logger *test_suite::logger = &__trivial_logger_inst; + +base_logger *test_suite::set_global_logger( base_logger *new_logger ) +{ + base_logger *tmp = logger; + logger = new_logger; + if ( tmp == local_logger ) { // if local_logger was identical to logger, switch it too + local_logger = logger; + } + return tmp; +} + +base_logger *test_suite::set_logger( base_logger *new_logger ) +{ + base_logger *tmp = local_logger; + local_logger = new_logger; + return tmp; +} + +void test_suite::report( const char *file, int line, bool cnd, const char *expr ) +{ + local_logger->report( file, line, cnd, expr ); +} + +void test_suite::run_test_case( test_suite::vertex_t v ) +{ + try { + ++_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 ); + } else { + _test[v].state = fail; + ++_stat.failed; + local_logger->tc( base_logger::fail, _test[v].name ); + } + } else { + ++_stat.skipped; + local_logger->tc( base_logger::skip, _test[v].name ); + } + } + catch ( init_exception& ) { + --_stat.total; + } + catch ( ... ) { + ++_stat.failed; + _test[v].state = fail; + local_logger->tc( base_logger::fail, _test[v].name ); + } +} + +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; + } +} + +void test_suite::clean_test_case_state( vertex_t v ) +{ + _test[v].state = 0; +} + +int test_suite::run( test_suite *, int ) +{ + return girdle( root ); +} + + +} // namespace exam Property changes on: trunk/complement/explore/lib/exam/ut ___________________________________________________________________ Name: svn:ignore + obj Copied: trunk/complement/explore/lib/exam/ut/Makefile (from rev 1606, trunk/complement/explore/app/exam/Makefile) =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile (rev 0) +++ trunk/complement/explore/lib/exam/ut/Makefile 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,11 @@ +# -*- Makefile -*- Time-stamp: <07/07/05 09:31:15 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +# INCLUDES += -I${BOOST_DIR} +INCLUDES += -I${CoMT_INCLUDE_DIR} + +LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} Copied: trunk/complement/explore/lib/exam/ut/Makefile.inc (from rev 1613, trunk/complement/explore/app/exam/Makefile.inc) =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile.inc (rev 0) +++ trunk/complement/explore/lib/exam/ut/Makefile.inc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,7 @@ +# -*- makefile -*- Time-stamp: <02/07/14 14:03:13 ptr> + +PRGNAME = exam_self_test +SRC_CC = exam_self_test.cc \ + exam_test_suite.cc \ + ../suite.cc \ + ../logger.cc Copied: trunk/complement/explore/lib/exam/ut/dummy_test.cc (from rev 1612, trunk/complement/explore/app/exam/dummy_test.cc) =================================================================== --- trunk/complement/explore/lib/exam/ut/dummy_test.cc (rev 0) +++ trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,36 @@ +#include <exam/suite.h> + +int EXAM_IMPL(func) +{ + EXAM_CHECK(false); + + return EXAM_RESULT; +} + +class test_x +{ + public: + + int EXAM_IMPL(f) + { + EXAM_CHECK(false); + EXAM_CHECK(true); + + return EXAM_RESULT; + } + + int EXAM_IMPL(f_good) + { + EXAM_CHECK(true); + EXAM_CHECK(true); + + return EXAM_RESULT; + } +}; + +int EXAM_IMPL(func_good) +{ + EXAM_CHECK(true); + + return EXAM_RESULT; +} Copied: trunk/complement/explore/lib/exam/ut/exam_self_test.cc (from rev 1613, trunk/complement/explore/app/exam/exam_self_test.cc) =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_self_test.cc (rev 0) +++ trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,14 @@ +// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> + +#include "exam_test_suite.h" + +int main( int, char ** ) +{ + // exam::test_suite t( "exam self test" ); + // t.add( exam_self_test, "exam self test suite" ); + // + // return t.girdle(); + + return exam_self_test(0); +} + Copied: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc (from rev 1612, trunk/complement/explore/app/exam/exam_test_suite.cc) =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc (rev 0) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,239 @@ +// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> + +#include "exam_test_suite.h" + +#include "dummy_test.cc" + +int EXAM_IMPL(exam_basic_test::function_good) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, good function" ); + t.set_logger( &logger ); + + test_x tx; + t.add( func_good, "function" ); + t.add( &test_x::f_good, tx, "member function" ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r0 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::function) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + t.add( func, "function" ); + t.add( &test_x::f, tx, "member function" ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r1 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::dep) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + t.add( func_good, "function good", // "child" + t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" + t.add( func, "function fail", // <- skiped, because depends upon failed (next line) + t.add( &test_x::f, tx, "member function fail" ) ); // <- fail + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r2 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::trace) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + logger.flags( exam::base_logger::trace_suite ); + + test_x tx; + t.add( func_good, "function good", // "child" + t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" + t.add( func, "function fail", // <- skiped, because depends upon failed (next line) + t.add( &test_x::f, tx, "member function fail" ) ); // <- fail + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r3 ); + + buff.str( "" ); + buff.clear(); + + logger.flags( exam::base_logger::silent ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r4 ); + + buff.str( "" ); + buff.clear(); + + logger.flags( exam::base_logger::trace ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r5 ); + + buff.str( "" ); + buff.clear(); + + logger.flags( exam::base_logger::verbose ); + + t.girdle(); + + logger.flags( 0 ); + + EXAM_REQUIRE( buff.str() == r6 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::dep_test_suite) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t0( "exam self test, test suite master" ); + t0.set_logger( &logger ); + + test_x tx0; + t0.add( func_good, "function" ); + t0.add( &test_x::f_good, tx0, "member function" ); + + exam::test_suite t1( "exam self test, test suite slave" ); + t1.set_logger( &logger ); + + test_x tx1; + t1.add( func_good, "function good", // "child" + t1.add( &test_x::f_good, tx1, "member function good" ) ); // "parent" + t1.add( func, "function fail", // <- skiped, because depends upon failed (next line) + t1.add( &test_x::f, tx1, "member function fail" ) ); // <- fail + + exam::test_suite t( "exam self test, test suites dependency" ); + t.set_logger( &logger ); + + t.add( &exam::test_suite::run, t1, "slave test suite", + t.add( &exam::test_suite::run, t0, "master test suite" ) ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r7 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +const std::string exam_basic_test::r0 = "\ +*** PASS exam self test, good function (+2-0~0/2) ***\n"; + +const std::string exam_basic_test::r1 = "\ +dummy_test.cc:5: fail: false\n\ + FAIL function\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function\n\ +*** FAIL exam self test, fail function (+0-2~0/2) ***\n"; + +const std::string exam_basic_test::r2 = "\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r3 = "\ +== Begin test suite\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +== End test suite\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r4 = "\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r5 = "\ +dummy_test.cc:24: pass: true\n\ +dummy_test.cc:25: pass: true\n\ +dummy_test.cc:16: fail: false\n\ +dummy_test.cc:17: pass: true\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +dummy_test.cc:33: pass: true\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r6 = "\ + PASS member function good\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ + PASS function good\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r7 = "\ +*** PASS exam self test, test suite master (+2-0~0/2) ***\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +*** FAIL exam self test, test suite slave (+2-1~1/4) ***\n\ + FAIL slave test suite\n\ +*** FAIL exam self test, test suites dependency (+1-1~0/2) ***\n"; + +int EXAM_IMPL(exam_self_test) +{ + exam::test_suite t( "exam self test" ); + exam_basic_test exam_basic; + + t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); + t.add( &exam_basic_test::function, exam_basic, "call test, fail calls" ); + exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency" ); + t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); + t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); + + return t.girdle(); +} + Copied: trunk/complement/explore/lib/exam/ut/exam_test_suite.h (from rev 1612, trunk/complement/explore/app/exam/exam_test_suite.h) =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h (rev 0) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,42 @@ +// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> + +#ifndef __exam_test_suite_h +#define __exam_test_suite_h + +#define FIT_EXAM + +#include <exam/suite.h> +#include <string> +#include <sstream> + +class exam_basic_test +{ + public: + exam_basic_test() : + buff(), + logger( buff ) + { } + + int EXAM_DECL(function_good); + int EXAM_DECL(function); + int EXAM_DECL(dep); + int EXAM_DECL(trace); + int EXAM_DECL(dep_test_suite); + + private: + std::stringstream buff; + exam::trivial_logger logger; + + static const std::string r0; + static const std::string r1; + static const std::string r2; + static const std::string r3; + static const std::string r4; + static const std::string r5; + static const std::string r6; + static const std::string r7; +}; + +int EXAM_DECL(exam_self_test); + +#endif // __exam_test_suite_h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |