1

boost.testブースト 1.33.1を使用してリモート システムで使用しようとしています。私のPCでは、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が存在しません。私のPCでは、ファイル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.testを使用しているため(boost / test / include / unit_test.hppヘッダーを含め、boost / test / unit_test.hppは含めない)、PCから動作中のブーストインストールをコピーすることはできません。ターゲットマシンに接続し、コンパイラにそれを使用するように指示しますか?

于 2010-12-06T18:14:25.387 に答える
0

ブーストのバージョンが 1.33 より古い場合は、名前を に変更BOOST_AUTO_TEST_CASEしてみBOOST_AUTO_UNIT_TESTてください。これにより、新しいバージョンのブーストでコンパイルが中断されることはありません。

これらの Boost.Test 1.33 リリース ノートを参照してください。

BOOST_AUTO_UNIT_TEST の名前が BOOST_AUTO_TEST_CASE に変更されました。古い名前はまだ提供されていますが非推奨です

于 2010-12-06T18:07:40.680 に答える