2010-12-06 34 views
1

我试图在带有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这个小例子工程:boost.test与旧版本的问题

#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 

这是什么?如何解决它?

+0

您更改了哪个系统包括? – 2010-12-06 18:03:58

+0

您能否告诉我们您的远程系统上安装了哪种版本的boost? – jopasserat 2010-12-06 18:11:46

回答

3

升压1.33用途:

#include <boost/test/auto_unit_test.hpp> 

代替:

#include <boost/test/unit_test.hpp> 

,也是附加的#include之前:

#define BOOST_AUTO_TEST_MAIN 

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

0

如果你的boost版本比1.33旧,你应该尝试将BOOST_AUTO_TEST_CASE重命名为BOOST_AUTO_UNIT_TEST,它不应该在新版本的boost版本上中断编译。

看到这些如Boost.Test 1.33 Release Notes

BOOST_AUTO_UNIT_TEST更名为 BOOST_AUTO_TEST_CASE。老名字仍然 提供,但不建议使用

0

什么是你的目标平台上boost版本?你在那里使用旧版本吗?由于您使用boost.test(仅包含boost/test/included/unit_test.hpp头文件而不是boost/test/unit_test.hpp文件)的头文件版本,难道您不能只复制工作的boost文件从您的PC安装到目标机器并指示您的编译器使用它?