其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
boost 中的 单元测试 库

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;

void force_division_by_zero()
{
    // unit test framework can catch operating system signals
    BOOST_CHECKPOINT("About to force division by zero!");
    int i = 1, j = 0;
    i = i / j;
}

void infinite_loop()
{
    // unit test framework can break infinite loops by timeout
#ifdef __unix  // don't have timeout on other platforms
    BOOST_CHECKPOINT("About to enter an infinite loop!");
    while(1);
#else
    BOOST_MESSAGE( "Timeout support is not implemented on your platform" );
#endif
}

test_suite*
init_unit_test_suite( int argc, char * argv[] ) {
    test_suite* test= BOOST_TEST_SUITE( "Unit test example 2" );

    test->add( BOOST_TEST_CASE( &force_division_by_zero ) );
    test->add( BOOST_TEST_CASE( &infinite_loop ), 0, /* timeout */ 2 );

    return test;
}

// EOF

输出:
Running 2 test cases...
Exception in "force_division_by_zero": signal: SIGFPE (arithmetic exception)
t7.cpp(7): last checkpoint: About to force division by zero!
Exception in "infinite_loop": signal: SIGALRM (timeout while executing function)
t7.cpp(16): last checkpoint: About to enter an infinite loop!

*** errors detected in test suite "Unit test example 2"; see standard output for
 details




相关文章

相关软件