|
Boost Users : |
From: Bill Lear (rael_at_[hidden])
Date: 2005-01-28 22:22:52
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 <boost/test/unit_test.hpp>
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<test_suite> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net