mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-29 20:37:13 +02:00
Add sp_ostream_test, ip_ostream_test, lsp_ostream_test
This commit is contained in:
@ -424,3 +424,7 @@ run sp_is_bounded_array_test.cpp ;
|
||||
run sp_is_unbounded_array_test.cpp ;
|
||||
run sp_type_identity_test.cpp ;
|
||||
run sp_type_with_alignment_test.cpp ;
|
||||
|
||||
run sp_ostream_test.cpp ;
|
||||
run ip_ostream_test.cpp ;
|
||||
run lsp_ostream_test.cpp ;
|
||||
|
65
test/ip_ostream_test.cpp
Normal file
65
test/ip_ostream_test.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright 2011, 2025 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
|
||||
class base
|
||||
{
|
||||
private:
|
||||
|
||||
int use_count_;
|
||||
|
||||
base(base const &);
|
||||
base & operator=(base const &);
|
||||
|
||||
protected:
|
||||
|
||||
base(): use_count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~base()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
long use_count() const
|
||||
{
|
||||
return use_count_;
|
||||
}
|
||||
|
||||
inline friend void intrusive_ptr_add_ref(base * p)
|
||||
{
|
||||
++p->use_count_;
|
||||
}
|
||||
|
||||
inline friend void intrusive_ptr_release(base * p)
|
||||
{
|
||||
if(--p->use_count_ == 0) delete p;
|
||||
}
|
||||
};
|
||||
|
||||
struct X: public base
|
||||
{
|
||||
};
|
||||
|
||||
template<class T> std::string to_string( T const& t )
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << t;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::intrusive_ptr<X> p1, p2( new X );
|
||||
|
||||
BOOST_TEST_EQ( to_string( p1 ), to_string( p1.get() ) );
|
||||
BOOST_TEST_EQ( to_string( p2 ), to_string( p2.get() ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
24
test/lsp_ostream_test.cpp
Normal file
24
test/lsp_ostream_test.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2025 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/smart_ptr/local_shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
|
||||
template<class T> std::string to_string( T const& t )
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << t;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::local_shared_ptr<int> p1, p2( new int );
|
||||
|
||||
BOOST_TEST_EQ( to_string( p1 ), to_string( p1.get() ) );
|
||||
BOOST_TEST_EQ( to_string( p2 ), to_string( p2.get() ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
24
test/sp_ostream_test.cpp
Normal file
24
test/sp_ostream_test.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2025 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
|
||||
template<class T> std::string to_string( T const& t )
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << t;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<int> p1, p2( new int );
|
||||
|
||||
BOOST_TEST_EQ( to_string( p1 ), to_string( p1.get() ) );
|
||||
BOOST_TEST_EQ( to_string( p2 ), to_string( p2.get() ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user