|
Boost : |
From: rogeeff (rogeeff_at_[hidden])
Date: 2001-12-21 13:03:04
--- In boost_at_y..., "Fernando Cacciola" <fcacciola_at_g...> wrote:
> > > This should be properly documented.
> >
> > >From the documentation:
> >
> > "The class_test_case is responsible for the creation and the
> > destroying of the user's test class instance. It's recommended to
use
> > the class_test_case *only* if you can't implement a test logic in
a
> > free function."
> >
> I see.
> Then this paragraph should be referenced in
Sorry. I did not get. Where?
[...]
> > In reality usage of class_test_case is limited to the situations
> > where you for any reason need to share information between test
> > cases. The instance of user class is just a storage for this
> > information. As an example let say you are testing very heavy
class
> > A. So you have test_construction test case and test_access test
case.
> > You could want to use preconstructed object in a test_access and
> > construct it in test_construction.
> >
> Could you give a concrete example?
struct test_A {
A a;
void test_constructor() {
a.add( part );
a.add( part );
a.add( part );
// validate a is properly constructed
}
void test_access() {
BOOST_CHECK_EQUAL( a.get( key ), value );
...
}
}
[...]
> >
> The problem is that I need to transfer information from the command
line
> into the test case.
> How can I do that with a free function?
>
> (of course I could use gobal static data, but I was hoping that no
to be
> necessary)
Good catch. Right away you should be able to use an extention and
bind needed argument to the free function with arguments, like this
void foo( char const* arg )
{
...
}
test->add( BOOST_TEST_CASE( boost::bind( foo, _1, argv[2] );
Hopefully bind will take care about lifetime of arguments. Is it,
Piter?
Though the problem seems to be pretty generic and worth adding to the
base implementation. I could add an ability for the user to specify a
ninstance of user test case as an optional argument to
BOOST_TEST_CASE like this:
BOOST_TEST_CASE(( &A::foo )); // here framework will create an
instance
A* a = new A(...)
BOOST_TEST_CASE(( &A::foo, a )); // here framework will use the
instance provided and DESTROY it at the end.
How about this?
>
> Thanks,
>
> Fernando Cacciola
> Sierra s.r.l.
> fcacciola_at_g...
> www.gosierra.com
Gennadiy.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk