[auto_ptr][test class]

Hi,

I'm currently writing a test program who test each of the auto_ptr class functions. I have some problem to find a way to test certain functions :
- the copy constructor for another type of auto_ptr ?
- the operator -> ?
- the operator = from another type of auto_ptr ?
- the test conversion function (template <typename Y> operator auto_ptr<Y>() throw();)?

Do you have some test case please?
test those method really worth deep studyding

since c++ provides so many mechanisms.

misusing them could pose potential error.
Hum that's not the kind of answers who help me...
I know that's not easy, but any hints to do that would be appreciated.
the copy constructor for another type of auto_ptr ?

I don't know what you mean by "another type of auto_ptr". If you mean you want to test the copy constructor of auto_ptr? In that case you can test so that the new auto_ptr object created with the copy constructor points to the object and that the old auto_ptr no longer points to anything.

the operator -> ?

You could test that (*p).foo do the same as p->foo

the operator = from another type of auto_ptr ?

This is very similar to the copy constructor so the test will probably be very similar too.

the test conversion function (template <typename Y> operator auto_ptr<Y>() throw();)?

I think this is so that you can convert a auto_ptr<X> to a auto_ptr<Y> where Y is a superclass of X.
I figured out for the first 3 functions thank you.

But the last one, the conversion function, I don't find a way to test it, for the moment I find on internet a test like this (A is a base class and B a derived class) :

template <typename T>
static auto_ptr<T> source()
{
return auto_ptr<T>(new T);
}

template <typename T>
static void drain(auto_ptr<T>)
{}

int
main()
{
drain(source<A>());
drain(source<B>());
}

But it seem that it don't use the "template <typename Y> operator auto_ptr<Y>() throw();" function so it crash.
Topic archived. No new replies allowed.