Update esft_regtest.cpp to trunk HEAD; takes care of 43829, 43856, 44775.

[SVN r47342]
This commit is contained in:
Peter Dimov
2008-07-12 10:45:56 +00:00
parent 774a8d330c
commit 1bc4f16ff8

View File

@ -16,6 +16,7 @@
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>
#include <string>
class X: public boost::enable_shared_from_this< X >
{
@ -65,7 +66,7 @@ public:
int X::instances = 0;
int main()
void test()
{
BOOST_TEST( X::instances == 0 );
@ -131,6 +132,90 @@ int main()
}
BOOST_TEST( X::instances == 0 );
}
struct V: public boost::enable_shared_from_this<V>
{
virtual ~V() {}
std::string m_;
};
struct V2
{
virtual ~V2() {}
std::string m2_;
};
struct W: V2, V
{
};
void test2()
{
boost::shared_ptr<W> p( new W );
}
void test3()
{
V * p = new W;
boost::shared_ptr<void> pv( p );
BOOST_TEST( pv.get() == p );
BOOST_TEST( pv.use_count() == 1 );
}
struct null_deleter
{
void operator()( void const* ) const {}
};
void test4()
{
boost::shared_ptr<V> pv( new V );
boost::shared_ptr<V> pv2( pv.get(), null_deleter() );
BOOST_TEST( pv2.get() == pv.get() );
BOOST_TEST( pv2.use_count() == 1 );
}
void test5()
{
V v;
boost::shared_ptr<V> p1( &v, null_deleter() );
BOOST_TEST( p1.get() == &v );
BOOST_TEST( p1.use_count() == 1 );
try
{
p1->shared_from_this();
}
catch( ... )
{
BOOST_ERROR( "p1->shared_from_this() failed" );
}
p1.reset();
boost::shared_ptr<V> p2( &v, null_deleter() );
BOOST_TEST( p2.get() == &v );
BOOST_TEST( p2.use_count() == 1 );
try
{
p2->shared_from_this();
}
catch( ... )
{
BOOST_ERROR( "p2->shared_from_this() failed" );
}
}
int main()
{
test();
test2();
test3();
test4();
test5();
return boost::report_errors();
}