c++ - 旧版本的 boost.test 问题

标签 c++ include boost-test

我正在尝试在带有 boost 1.33.1 的远程系统上使用 boost.test。在我的电脑上,这个小例子来自 http://www.boost.org/doc/libs/1_42_0/libs/test/doc/html/tutorials/hello-the-testing-world.html作品:

#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp> // I've changed here

int add( int i, int j ) { return i+j; }

BOOST_AUTO_TEST_CASE( my_test )   // <--- line 7
{
// seven ways to detect and report the same error:
BOOST_CHECK( add( 2,2 ) == 4 );        // #1 continues on error

BOOST_REQUIRE( add( 2,2 ) == 4 );      // #2 throws on error

if( add( 2,2 ) != 4 )
  BOOST_ERROR( "Ouch..." );            // #3 continues on error

if( add( 2,2 ) != 4 )
  BOOST_FAIL( "Ouch..." );             // #4 throws on error

if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error

BOOST_CHECK_MESSAGE( add( 2,2 ) == 4,  // #6 continues on error
                     "add(..) result: " << add( 2,2 ) );

BOOST_CHECK_EQUAL( add( 2,2 ), 4 );   // #7 continues on error
}

但在远程系统上,文件 unit_test.hpp 不存在。在我的电脑上,文件 unit_test_framework.hpp 很简单:

// deprecated
#include <boost/test/included/unit_test.hpp>

它存在于主系统上。所以我尝试将包含更改为:

#include <boost/test/included/unit_test_framework.hpp>

但是编译器说:

main.cpp:7: error: expected constructor, destructor, or type conversion before ‘(’ token

这是什么?如何解决?

最佳答案

在 Boost 1.33 上使用:

#include <boost/test/auto_unit_test.hpp>

代替:

#include <boost/test/unit_test.hpp>

并且在#include 之前添加:

#define BOOST_AUTO_TEST_MAIN

否则你会得到一个链接器错误

关于c++ - 旧版本的 boost.test 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4369356/

相关文章:

c++ - 通过 C/C++ 使用 JPEG 像素格式在 v4l2 中设置/获取相机 jpeg 压缩质量

c++ - 使用多个文件时,我应该把预处理器命令放在哪里?

c - 专业#include内容

javascript - 除一个 PHP 包含文件外,所有其他都可以工作

c++ - 从 Visual Studio 2010 运行 BOOST 单元测试

c++ - 应用程序中奇怪的执行错误

c++ - 此声明在 C++ 中没有存储类或类型说明符

c++ - 从 C++ 解压 ZIP 的最简单方法?

c++ - 或者接线员不工作

c++ - 从 Atmel Studio 6 运行单元测试