[Cppunit-devel] Bug in TestSuiteBuilerContextBase
Brought to you by:
blep
|
From: <Pau...@Pr...> - 2004-05-25 12:38:44
|
TestSuiteBuilerContextBase needs a copy constructor that does a deep copy,
not a shallow copy. I tracked down this problem in the following example.
void CAppProjectApp::RunUnitTests()
{ // TestDLL_1 and TestDLL_2 are MFC extension DLLs.
if (AfxLoadLibrary("TestDLL_1.dll") &&
AfxLoadLibrary("TestDLL_2.dll"))
{
CppUnit::MfcUi::TestRunner runner;
// Tell the Test Runner to do its thing.
CppUnit::TestFactoryRegistry ®istry =
CppUnit::TestFactoryRegistry::getRegistry();
CppUnit::Test *pSuite = registry.makeTest(); // This is
causing an exception.
if (pSuite != 0)
{
runner.addTest(pSuite);
runner.run();
}
}
else
{ // Bad load.
ASSERT(FALSE);
}
}
Test *
TestFactoryRegistry::makeTest()
{
TestSuite *suite = new TestSuite( m_name );
addTestToSuite( suite );
return suite;
}
void
TestFactoryRegistry::addTestToSuite( TestSuite *suite )
{
for ( Factories::iterator it = m_factories.begin();
it != m_factories.end();
++it )
{
TestFactory *factory = *it;
suite->addTest( factory->makeTest() );
}
}
template<class TestCaseType>
class TestSuiteFactory : public TestFactory
{
public:
virtual Test *makeTest()
{
return TestCaseType::suite();
}
};
The defs for the tests:
class _impexp_testdll1_ CTestClass_1 : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(CTestClass_1); // this crashes
CPPUNIT_TEST(TestOperation1);
CPPUNIT_TEST(TestOperation2);
CPPUNIT_TEST(TestOperation3);
CPPUNIT_TEST_SUITE_END();
// Factory
public:
CTestClass_1();
virtual ~CTestClass_1();
// Test Operations
public:
void setUp();
protected:
void TestOperation1();
void TestOperation2();
void TestOperation3();
};
In the CPPUNIT_TEST_SUITE macro:
#define CPPUNIT_TEST_SUITE(...)
...
static void addTestsToSuite(CPPUNIT_NS::TestSuiteBuilderContextBase
&baseContext)
{
TestSuiteBuilderContextType context(baseContext); // this
copy ctor invocation crashes
....
|