在清理阶段从 main 返回时,CPPUNIT 在执行我的程序后崩溃。TestWrapping 的 dtor 调用 TestSuite 的 dtor,然后调用 deleteContents 触发测试用例清理。
奇怪的是 TestSuite 的 dtor 被调用了两次?这是在成功执行 6 个测试用例之后。关于如何避免这种情况的任何想法?
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000000045 in ?? ()
(gdb) bt
#0 0x0000000000000045 in ?? ()
#1 0x0000000000000001 in ?? ()
#2 0x0000000001004f2d in CppUnit::TestSuite::~TestSuite (this=0x7fe7bc005820, __in_chrg=<optimized out>) at TestSuite.cpp:18
#3 0x0000000001004ebd in CppUnit::TestSuite::deleteContents (this=0x7fe7bc001040) at TestSuite.cpp:28
#4 0x000000000100500d in CppUnit::TestSuite::~TestSuite (this=0x7fe7bc005820, __in_chrg=<optimized out>) at TestSuite.cpp:18
#5 0x0000000001004c50 in CppUnit::TestRunner::WrappingSuite::~WrappingSuite (this=0x7fe7bc005820, __in_chrg=<optimized out>) at ../../include/cppunit/TestRunner.h:101
#6 0x000000000040b72a in main (argc=0, argv=0x7fff8198bf08) at /project/EAB3_EMC/BRF/lmcgupe/brf/build/../software/brfc_test/BrfcTestMain.cc:447
Code exercising this:
(from main)
CppUnit::TextUi::TestRunner runner;
CPPUNIT_NS::TestResult controller;
CPPUNIT_NS::TestResultCollector result;
controller.addListener( &result );
// Show a message as each test starts
//
CppUnit::BriefTestProgressListener listener;
runner.eventManager().addListener(&listener);
controller.addListener( &listener );
// Specify XML output and inform the runner of this format
//
std::ofstream xmlout("test_result.xml");
CppUnit::XmlOutputter* outputter = new CppUnit::XmlOutputter(
&result, xmlout);
runner.setOutputter(outputter);
CppUnit::TextOutputter consoleOutputter(&result , std::cout);
runner.addTest(CreateAlarmBackupSuite::suite());
runner.run( controller );
from class CreateAlarmBackupSuite: public CppUnit::TestFixture
static CppUnit::Test *suite()
{
// Create the Test Suite
//
CppUnit::TestSuite *suite = new CppUnit::TestSuite("CreateAlarmBackupSuite");
// Add the test cases
//Crt_Syst_07
suite->addTest(new CppUnit::TestCaller<CreateAlarmBackupSuite>(
"07_Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Persistent_ManualDelNotClear",
&CreateAlarmBackupSuite::Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Persistent_ManualDelNotClear));
//Crt_Syst_09
suite->addTest(new CppUnit::TestCaller<CreateAlarmBackupSuite>(
"09_Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Transient_NoRetry",
&CreateAlarmBackupSuite::Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Transient_NoRetry));
return suite;
}