On Friday, January 28, 2005 at 16:23:57 (-0600) Bill Lear writes:
I am having trouble working around a problem with inheriting unit
test cases. ...
I have found an answer:
#include <iostream>
#include
using namespace boost::unit_test;
using namespace std;
struct Foo { virtual void foo(string) = 0; };
struct Bar : public Foo { void foo(string n) { cout << "in " << n << "\n"; }};
class CommonTest {
public:
void test_base() {
auto_ptr<Foo> foo(create());
foo->foo("CommonTest");
}
virtual Foo* create() = 0;
};
class ConcreteTest : public CommonTest {
public:
void test_concrete() {
auto_ptr<Foo> foo(create());
foo->foo("ConcreteTest");
}
virtual Foo* create() { return new Bar(); }
};
test_suite* init_unit_test_suite(int, char* []) {
auto_ptr suite(new test_suite());
boost::shared_ptr<CommonTest> common_test(new ConcreteTest());
suite->add(BOOST_CLASS_TEST_CASE(&CommonTest::test_base, common_test));
boost::shared_ptr<ConcreteTest> concrete_test(new ConcreteTest());
suite->add(BOOST_CLASS_TEST_CASE(&ConcreteTest::test_concrete,
concrete_test));
return suite.release();
}
Bill