Skip to content

Commit

Permalink
Add sp_ostream_test, ip_ostream_test, lsp_ostream_test
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jan 13, 2025
1 parent 1b89a64 commit 576d31f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 65 additions & 0 deletions test/ip_ostream_test.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions test/lsp_ostream_test.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions test/sp_ostream_test.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 576d31f

Please sign in to comment.