Gennadiy Rozental wrote:
"Chris Miceli"
wrote in message news:46E6AE74.6010101@cct.lsu.edu... I have had nothing but troubles with boost test 1.34.1 after switched from 1.33. First I had trouble with the main from shared object issue, and now my code that worked before is not executing a test added to the framework.
#include <iostream> #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE File Test #include
#include template <typename Functor> struct my_test { void execute(int value) { //Never prints this message //Doesn't have to be a print, nothing gets here std::cerr << "Hi all" << std::endl << std::flush; } };
BOOST_AUTO_TEST_CASE( test123 ) { boost::shared_ptr
tester(new my_test<int>); boost::unit_test::framework::master_test_suite().add(BOOST_TEST_CASE(boost::bind(&my_test<int>::execute, tester, 5))); }
This is incorrect way to register test units.
this worked when it was not using boost::bind but just the address of a normal function. This is just an simple version that illustrated the problem. I am compiling as such g++ test.cpp -o test -L/usr/local/lib -lboost_unit_test_framework-gcc41-mt
I am not sure how it worked before, but the correct way to implement this is to use init function
#include <iostream> #define BOOST_TEST_DYN_LINK #include
#include template <typename Functor> struct my_test { void execute(int value) { //Never prints this message //Doesn't have to be a print, nothing gets here std::cerr << "Hi all" << std::endl << std::flush; } };
bool init_function() { boost::shared_ptr
tester(new my_test<int>); boost::unit_test::framework::master_test_suite().add( BOOST_TEST_CASE(boost::bind(&my_test<int>::execute, tester, 5)));
return true; }
int main( int argc, char* argv[] ) { return ::boost::unit_test::unit_test_main( &init_function, argc, argv ); }
Gennadiy
P.S. Alternatively, if you are not that interrested in either template or runtime parameter, you can use one of the other automated tools. For example:
#include <iostream> #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE Your test #include
typedef boost::mpl::list
test_types; BOOST_AUTO_TEST_CASE_TEMPLATE( test_case1, T, test_types ) { //Never prints this message //Doesn't have to be a print, nothing gets here std::cerr << "Hi all" << std::endl << std::flush; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks, worked like a charm. I do believe though that there should be better documentation for this great library. Chris Miceli