|
Boost Users : |
From: Stephen Torri (storri_at_[hidden])
Date: 2007-01-23 19:13:56
I have the following code for a sample test. I was wondering how I can
move code that is common to a long off different test files to a common
location and use inheritance? In the code below I can do two things. If
its indeed generic I can encapsulate it in a common class used in the
tests. Secondly I could put test_one and test_two in a class and inherit
from the parent generic class. What is the best solution for what I am
trying to do?
Stephen
----------CODE--------------
#include <boost/test/unit_test.hpp>
#include <fstream>
using namespace boost::unit_test;
using namespace boost::unit_test_framework;
class A {}
class B {}
A*
helper_run_test ( B& target_ref,
std::string target_file )
{
... do work on B and return A* result
}
void test_one ()
{
B& b_ref;
A* helper_run_test ( b, "Apple" );
.. perform a BOOST_CHECK_EQUAL
}
void test_two ()
{
B& b_ref;
A* helper_run_test ( b, "Peach" );
.. perform a BOOST_CHECK_EQUAL
}
test_suite*
init_unit_test_suite ( int, char**)
{
test_suite* test = BOOST_TEST_SUITE ("My test suite");
test->add ( BOOST_TEST_CASE ( &test_one ) );
test->add ( BOOST_TEST_CASE ( &test_two ) );
return test;
}
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