1

我正在尝试boost.test在带有 boost 1.33.1 的远程系统上使用。在我的电脑上,来自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

这是什么?如何解决?

4

3 回答 3

3

在 Boost 1.33 上使用:

#include <boost/test/auto_unit_test.hpp>

代替:

#include <boost/test/unit_test.hpp>

以及在#include 之前添加:

#define BOOST_AUTO_TEST_MAIN

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

于 2012-10-24T11:30:15.017 回答
0

如果你的 boost 版本早于 1.33,你应该尝试重命名BOOST_AUTO_TEST_CASEBOOST_AUTO_UNIT_TEST,它不应该破坏新版本的 boost 的编译。

请参阅这些 Boost.Test 1.33 发行说明

BOOST_AUTO_UNIT_TEST 重命名为 BOOST_AUTO_TEST_CASE。旧名称仍提供但已弃用

于 2010-12-06T18:07:40.680 回答
0

您的目标平台上的增强版本是什么?你在那里用的是旧版本吗?

由于您使用的是 boost.test 的仅标头版本(您包括 boost/test/included/unit_test.hpp 标头而不是 boost/test/unit_test.hpp),您不能只从您的 PC 复制工作的 boost 安装吗到目标机器并指示你的编译器使用它?

于 2010-12-06T18:14:25.387 回答