SetUpTestCase()
共有リソースを割り当てるメソッドを持つテストケースを作成していますが、未定義の参照リンカー エラーが発生しています。
class ParsingEventsTest: public ::testing::Test {
protected:
static xml eventXml;
static void SetUpTestCase() {
ManagedObjectManagerSingleton::GET_SINGLETON().initializeTestEnvironment(PATH_TO_FILE);
eventXml= *ManagerSingleton::GET_SINGLETON().parse(PATH_TO_INPUT_FILES);
}
virtual void SetUp() {}
virtual void TearDown() {}
};
これにより、次のことが発生します。
../test/ParsingEventsTest.o: In function `ParsingEventsTest::SetUpTestCase()':
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xa1): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xb0): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xbd): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xc2): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xce): undefined reference to `ParsingEventsTest::eventXml'
../test/ParsingEventsTest.o:ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xdd): more undefined references to `ParsingEventsTest::eventXml' follow
collect2: ld returned 1 exit status
編集:
これは、int割り当てなどの非常に単純な場合にも機能します
class ParsingEventsTest: public ::testing::Test {
protected:
static int *x;
static void SetUpTestCase() {
x = new int [30];
}
static void TearDownTestCase() {
delete [] x;
}
virtual void SetUp() {}
virtual void TearDown() {}
};