From 576d31f2064e403dc2d92d09f94958c282e2703c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 13 Jan 2025 15:24:45 +0200 Subject: [PATCH] Add sp_ostream_test, ip_ostream_test, lsp_ostream_test --- test/Jamfile | 4 +++ test/ip_ostream_test.cpp | 65 +++++++++++++++++++++++++++++++++++++++ test/lsp_ostream_test.cpp | 24 +++++++++++++++ test/sp_ostream_test.cpp | 24 +++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 test/ip_ostream_test.cpp create mode 100644 test/lsp_ostream_test.cpp create mode 100644 test/sp_ostream_test.cpp diff --git a/test/Jamfile b/test/Jamfile index cf55f05..ea702ac 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/ip_ostream_test.cpp b/test/ip_ostream_test.cpp new file mode 100644 index 0000000..5f38ad3 --- /dev/null +++ b/test/ip_ostream_test.cpp @@ -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 +#include +#include + +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 std::string to_string( T const& t ) +{ + std::ostringstream os; + os << t; + return os.str(); +} + +int main() +{ + boost::intrusive_ptr 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(); +} diff --git a/test/lsp_ostream_test.cpp b/test/lsp_ostream_test.cpp new file mode 100644 index 0000000..8365988 --- /dev/null +++ b/test/lsp_ostream_test.cpp @@ -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 +#include +#include + +template std::string to_string( T const& t ) +{ + std::ostringstream os; + os << t; + return os.str(); +} + +int main() +{ + boost::local_shared_ptr 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(); +} diff --git a/test/sp_ostream_test.cpp b/test/sp_ostream_test.cpp new file mode 100644 index 0000000..3d2092a --- /dev/null +++ b/test/sp_ostream_test.cpp @@ -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 +#include +#include + +template std::string to_string( T const& t ) +{ + std::ostringstream os; + os << t; + return os.str(); +} + +int main() +{ + boost::shared_ptr 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(); +}