Opened 11 years ago
Closed 10 years ago
#6749 closed Feature Requests (wontfix)
PARAM_TEST_CASE works poorly with abstract objects
Reported by: | Owned by: | Gennadiy Rozental | |
---|---|---|---|
Milestone: | To Be Determined | Component: | test |
Version: | Boost 1.49.0 | Severity: | Cosmetic |
Keywords: | Cc: |
Description
Using abstract classes as arguments to tests works poorly and requires a workaround:
#include <boost/test/included/unit_test.hpp> #include <boost/test/parameterized_test.hpp> #include <boost/test/unit_test_suite.hpp> #include <boost/ptr_container/ptr_vector.hpp> using namespace boost::unit_test; class F { public: virtual void foo()=0; virtual ~F(); }; struct D : public F { void foo() {} }; void test(const F&) {} void test2(const F*) {} test_suite* init_unit_test_suite() { boost::ptr_vector<F> params; params.push_back(new D); // borks // boost::unit_test::framework::master_test_suite(). // add( BOOST_PARAM_TEST_CASE( &test, params.begin(), params.end())); F* f = new D; F* arr[] = {f}; framework::master_test_suite(). add( BOOST_PARAM_TEST_CASE( &test2, arr, arr + 1)); return 0; }
It would be nice this weren't required as it adds the additional burden of maintaining memory on the test author and the tests cases shouldn't be required to work on pointers.
Note:
See TracTickets
for help on using tickets.
Please try new data driven test case feature, which is going to be used from now on to replace parameterized test cases. It is more generic, but require newer compilers. I am notgonna invest time at this point improving old deprecated interface.