CppUnit のクックブックを読み、何度もグーグル検索を行った後も、特定のエラーの原因を突き止めることができませんでした。
私は非常に基本的な CppUnit testFixture クラスを持っています -> 私はファイルを持っています - MyTest.h は TestFixture クラス定義だけです。
// MyTest.h
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
class MyTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(MyTest); // Line num 8
CPPUNIT_TEST(TestFailure);
CPPUNIT_TEST_SUITE_END();
public:
void TestFailure()
{
CPPUNIT_ASSERT(false);
}
};
また、この MyTest クラスを駆動するための MyTest.cpp。
// MyTest.cpp
#include "MyTest.h"
次に、ランナーをインスタンス化し、実際のテストケースを実行する main.cpp というファイル。
// main.cpp
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
// In my main, I define a macro ADD_TEST and do #include of file called "testList.h"
// So my testList.h can have any number of ADD_TEST macros.
int main(int argc, char **argv)
{
CppUnit::TextUi::TestRunner runner;
#define ADD_TEST(_testName) \
runner.addTest(_testName::suite());
#include testList.h"
#undef ADD_TEST
runner.run();
return true;
}
これが私のtestList.hです->
#pragma once
#include MyTest.h
ADD_TEST(MyTest)
現在、このファイル構造は Windows セットアップと同様に機能します。Linux では、次の奇妙なエラーが発生します -
MyTest.h: In function 'int main(int, char**)': MyTest.h:8: error: 'main(int, char**)::MyTest' uses local type 'main(int, char**)::MyTest'
MyTest.h:8: error: trying to instantiate 'template<class Fixture> class CppUnit::TestSuiteBuilderContext'
MyTest.h: In static member function 'static void main(int, char**)::MyTest::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&)':
MyTest.h:8: error: cannot convert 'CppUnit::TestSuiteBuilderContextBase' to 'int' in initialization
これは私を完全に混乱させました。MyTest.h の num8 行目をコメント アウトすると、"スイート" 宣言されていないエラーが発生するため、マクロが取得されていることがわかります。しかし、CPPUNIT_TEST_SUITE などのマクロが利用可能ですが、なぜエラーが発生するのでしょうか? -lstc++、-ldl、および -lcppunit フラグを使用してコンパイルしています。
どんな助けでも大歓迎です!
ありがとう!