From 4e5d067ba8c24710703314027482ed3826b910f7 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 20 Jun 2017 22:26:07 +0300 Subject: [PATCH] Add local_sp_fn_test --- test/Jamfile.v2 | 2 ++ test/local_sp_fn_test.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/local_sp_fn_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 879a1b2..134642d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -241,5 +241,7 @@ import testing ; [ run make_local_shared_esft_test.cpp ] [ run allocate_local_shared_test.cpp ] [ run allocate_local_shared_esft_test.cpp ] + + [ run local_sp_fn_test.cpp ] ; } diff --git a/test/local_sp_fn_test.cpp b/test/local_sp_fn_test.cpp new file mode 100644 index 0000000..f2a355a --- /dev/null +++ b/test/local_sp_fn_test.cpp @@ -0,0 +1,43 @@ +// +// local_sp_fn_test.cpp +// +// Copyright 2017 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include +#include +#include + +static void f() +{ +} + +struct null_deleter +{ + template void operator()( Y* ) {} +}; + +int main() +{ + boost::local_shared_ptr pf( f, null_deleter() ); + + BOOST_TEST( pf.get() == f ); + BOOST_TEST_EQ( pf.local_use_count(), 1 ); + BOOST_TEST( boost::get_deleter( pf ) != 0 ); + + boost::weak_ptr wp( pf ); + + BOOST_TEST( wp.lock().get() == f ); + BOOST_TEST_EQ( wp.use_count(), 1 ); + + pf.reset(); + + BOOST_TEST( wp.lock().get() == 0 ); + BOOST_TEST_EQ( wp.use_count(), 0 ); + + return boost::report_errors(); +}