boost test中的例子
boost test的使用说明中有一些例子。但有些例子如果照抄不能在VS2005中运行,需要引入boost test的某些宏定义。以下是修改后的例9:
#define BOOST_TEST_ALTERNATIVE_INIT_API
#define BOOST_TEST_NO_MAIN
#define BOOST_TEST_INCLUDED
#define BOOST_TEST_DYN_LINK
#include <boost/test/included/unit_test.hpp>
#include <boost/bind.hpp>
using namespace boost::unit_test;
//____________________________________________________________________________//
void free_test_function( int i, int j )
{
BOOST_CHECK( true /* test assertion */ );
}
//____________________________________________________________________________//
bool
init_function()
{
framework::master_test_suite().
add( BOOST_TEST_CASE( boost::bind( &free_test_function, 1, 1 ) ) );
framework::master_test_suite().
add( BOOST_TEST_CASE( boost::bind( &free_test_function, 1, 2 ) ) );
framework::master_test_suite().
add( BOOST_TEST_CASE( boost::bind( &free_test_function, 2, 1 ) ) );
return true;
}
//____________________________________________________________________________//
int
main( int argc, char* argv[] )
{
return ::boost::unit_test::unit_test_main( &init_function, argc, argv );
}
(相关帖子)
本文提供了一个在VS2005环境下运行的BoostTest测试框架示例代码。该示例通过宏定义解决了直接移植BoostTest官方示例时遇到的问题,并展示了如何使用`boost::bind`来添加多个测试案例。
499

被折叠的 条评论
为什么被折叠?



