diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/smart_ptr | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/smart_ptr')
269 files changed, 33310 insertions, 0 deletions
diff --git a/src/boost/libs/smart_ptr/CMakeLists.txt b/src/boost/libs/smart_ptr/CMakeLists.txt new file mode 100644 index 00000000..e3acea06 --- /dev/null +++ b/src/boost/libs/smart_ptr/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright 2018 Mike Dev +# 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 + +# Partial (add_subdirectory only) and experimental CMake support +# Subject to change; please do not rely on the contents of this file yet + +cmake_minimum_required(VERSION 3.5) +project(BoostSmartPtr LANGUAGES CXX) + +add_library(boost_smart_ptr INTERFACE) +add_library(Boost::smart_ptr ALIAS boost_smart_ptr) + +target_include_directories(boost_smart_ptr INTERFACE include) + +target_link_libraries(boost_smart_ptr + INTERFACE + Boost::assert + Boost::config + Boost::core + Boost::move + Boost::predef + Boost::static_assert + Boost::throw_exception + Boost::type_traits +) diff --git a/src/boost/libs/smart_ptr/README.md b/src/boost/libs/smart_ptr/README.md new file mode 100644 index 00000000..1301e79c --- /dev/null +++ b/src/boost/libs/smart_ptr/README.md @@ -0,0 +1,6 @@ +# Boost.SmartPtr + +Branch | Travis | Appveyor +---------|--------|--------- +Develop | [![Build Status](https://travis-ci.org/boostorg/smart_ptr.svg?branch=develop)](https://travis-ci.org/boostorg/smart_ptr) | [![Build Status](https://ci.appveyor.com/api/projects/status/github/boostorg/smart_ptr?branch=develop&svg=true)](https://ci.appveyor.com/project/pdimov/smart-ptr) +Master | [![Build Status](https://travis-ci.org/boostorg/smart_ptr.svg?branch=master)](https://travis-ci.org/boostorg/smart_ptr) | [![Build Status](https://ci.appveyor.com/api/projects/status/github/boostorg/smart_ptr?branch=master&svg=true)](https://ci.appveyor.com/project/pdimov/smart-ptr) diff --git a/src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp b/src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp new file mode 100644 index 00000000..3dcfbb1f --- /dev/null +++ b/src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp @@ -0,0 +1,23 @@ +// Boost scoped_ptr_example implementation file -----------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "scoped_ptr_example.hpp" +#include <iostream> + +class example::implementation +{ + public: + ~implementation() { std::cout << "destroying implementation\n"; } +}; + +example::example() : _imp( new implementation ) {} + +void example::do_something() { std::cout << "did something\n"; } + +example::~example() {} diff --git a/src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp b/src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp new file mode 100644 index 00000000..0d9c603e --- /dev/null +++ b/src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp @@ -0,0 +1,29 @@ +// Boost scoped_ptr_example header file ------------------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include <boost/utility.hpp> +#include <boost/scoped_ptr.hpp> + +// The point of this example is to prove that even though +// example::implementation is an incomplete type in translation units using +// this header, scoped_ptr< implementation > is still valid because the type +// is complete where it counts - in the inplementation translation unit where +// destruction is actually instantiated. + +class example : private boost::noncopyable +{ + public: + example(); + ~example(); + void do_something(); + private: + class implementation; + boost::scoped_ptr< implementation > _imp; // hide implementation details +}; + diff --git a/src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp b/src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp new file mode 100644 index 00000000..26b3a181 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp @@ -0,0 +1,17 @@ +// Boost scoped_ptr_example_test main program -------------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "scoped_ptr_example.hpp" + +int main() +{ + example my_example; + my_example.do_something(); + return 0; +} diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example.cpp b/src/boost/libs/smart_ptr/example/shared_ptr_example.cpp new file mode 100644 index 00000000..c3b1f3b4 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example.cpp @@ -0,0 +1,95 @@ +// Boost shared_ptr_example.cpp --------------------------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +// Revision History +// 21 May 01 Initial complete version (Beman Dawes) + +// The original code for this example appeared in the shared_ptr documentation. +// Ray Gallimore pointed out that foo_set was missing a Compare template +// argument, so would not work as intended. At that point the code was +// turned into an actual .cpp file so it could be compiled and tested. + +#include <vector> +#include <set> +#include <iostream> +#include <algorithm> +#include <boost/shared_ptr.hpp> + +// The application will produce a series of +// objects of type Foo which later must be +// accessed both by occurrence (std::vector) +// and by ordering relationship (std::set). + +struct Foo +{ + Foo( int _x ) : x(_x) {} + ~Foo() { std::cout << "Destructing a Foo with x=" << x << "\n"; } + int x; + /* ... */ +}; + +typedef boost::shared_ptr<Foo> FooPtr; + +struct FooPtrOps +{ + bool operator()( const FooPtr & a, const FooPtr & b ) + { return a->x > b->x; } + void operator()( const FooPtr & a ) + { std::cout << a->x << "\n"; } +}; + +int main() +{ + std::vector<FooPtr> foo_vector; + std::set<FooPtr,FooPtrOps> foo_set; // NOT multiset! + + FooPtr foo_ptr( new Foo( 2 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + foo_ptr.reset( new Foo( 1 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + foo_ptr.reset( new Foo( 3 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + foo_ptr.reset ( new Foo( 2 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + std::cout << "foo_vector:\n"; + std::for_each( foo_vector.begin(), foo_vector.end(), FooPtrOps() ); + + std::cout << "\nfoo_set:\n"; + std::for_each( foo_set.begin(), foo_set.end(), FooPtrOps() ); + std::cout << "\n"; + +// Expected output: +// +// foo_vector: +// 2 +// 1 +// 3 +// 2 +// +// foo_set: +// 3 +// 2 +// 1 +// +// Destructing a Foo with x=2 +// Destructing a Foo with x=1 +// Destructing a Foo with x=3 +// Destructing a Foo with x=2 + + return 0; +} + diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp b/src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp new file mode 100644 index 00000000..fdefc8d9 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp @@ -0,0 +1,22 @@ +// Boost shared_ptr_example2 implementation file -----------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "shared_ptr_example2.hpp" +#include <iostream> + +class example::implementation +{ + public: + ~implementation() { std::cout << "destroying implementation\n"; } +}; + +example::example() : _imp( new implementation ) {} + +void example::do_something() + { std::cout << "use_count() is " << _imp.use_count() << "\n"; } diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp b/src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp new file mode 100644 index 00000000..5ca7a07d --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp @@ -0,0 +1,31 @@ +// Boost shared_ptr_example2 header file -----------------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include <boost/shared_ptr.hpp> + +// This example demonstrates the handle/body idiom (also called pimpl and +// several other names). It separates the interface (in this header file) +// from the implementation (in shared_ptr_example2.cpp). + +// Note that even though example::implementation is an incomplete type in +// some translation units using this header, shared_ptr< implementation > +// is still valid because the type is complete where it counts - in the +// shared_ptr_example2.cpp translation unit where functions requiring a +// complete type are actually instantiated. + +class example +{ +public: + example(); + void do_something(); +private: + class implementation; + boost::shared_ptr< implementation > _imp; // hide implementation details +}; + diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp b/src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp new file mode 100644 index 00000000..2702cb87 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp @@ -0,0 +1,22 @@ +// Boost shared_ptr_example2_test main program ------------------------------// + +// Copyright Beman Dawes 2001. 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) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "shared_ptr_example2.hpp" + +int main() +{ + example a; + a.do_something(); + example b(a); + b.do_something(); + example c; + c = a; + c.do_something(); + return 0; +} diff --git a/src/boost/libs/smart_ptr/extras/src/sp_collector.cpp b/src/boost/libs/smart_ptr/extras/src/sp_collector.cpp new file mode 100644 index 00000000..bb69ae88 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/src/sp_collector.cpp @@ -0,0 +1,270 @@ +// +// sp_collector.cpp +// +// Copyright (c) 2002, 2003 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) +// + +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) + +#include <boost/assert.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_mutex.hpp> +#include <cstdlib> +#include <map> +#include <deque> +#include <iostream> + +typedef std::map< void const *, std::pair<void *, size_t> > map_type; + +static map_type & get_map() +{ + static map_type m; + return m; +} + +typedef boost::detail::lightweight_mutex mutex_type; + +static mutex_type & get_mutex() +{ + static mutex_type m; + return m; +} + +static void * init_mutex_before_main = &get_mutex(); + +namespace +{ + class X; + + struct count_layout + { + boost::detail::sp_counted_base * pi; + int id; + }; + + struct shared_ptr_layout + { + X * px; + count_layout pn; + }; +} + +// assume 4 byte alignment for pointers when scanning +size_t const pointer_align = 4; + +typedef std::map<void const *, long> map2_type; + +static void scan_and_count(void const * area, size_t size, map_type const & m, map2_type & m2) +{ + unsigned char const * p = static_cast<unsigned char const *>(area); + + for(size_t n = 0; n + sizeof(shared_ptr_layout) <= size; p += pointer_align, n += pointer_align) + { + shared_ptr_layout const * q = reinterpret_cast<shared_ptr_layout const *>(p); + + if(q->pn.id == boost::detail::shared_count_id && q->pn.pi != 0 && m.count(q->pn.pi) != 0) + { + ++m2[q->pn.pi]; + } + } +} + +typedef std::deque<void const *> open_type; + +static void scan_and_mark(void const * area, size_t size, map2_type & m2, open_type & open) +{ + unsigned char const * p = static_cast<unsigned char const *>(area); + + for(size_t n = 0; n + sizeof(shared_ptr_layout) <= size; p += pointer_align, n += pointer_align) + { + shared_ptr_layout const * q = reinterpret_cast<shared_ptr_layout const *>(p); + + if(q->pn.id == boost::detail::shared_count_id && q->pn.pi != 0 && m2.count(q->pn.pi) != 0) + { + open.push_back(q->pn.pi); + m2.erase(q->pn.pi); + } + } +} + +static void find_unreachable_objects_impl(map_type const & m, map2_type & m2) +{ + // scan objects for shared_ptr members, compute internal counts + + { + std::cout << "... " << m.size() << " objects in m.\n"; + + for(map_type::const_iterator i = m.begin(); i != m.end(); ++i) + { + boost::detail::sp_counted_base const * p = static_cast<boost::detail::sp_counted_base const *>(i->first); + + BOOST_ASSERT(p->use_count() != 0); // there should be no inactive counts in the map + + m2[ i->first ]; + + scan_and_count(i->second.first, i->second.second, m, m2); + } + + std::cout << "... " << m2.size() << " objects in m2.\n"; + } + + // mark reachable objects + + { + open_type open; + + for(map2_type::iterator i = m2.begin(); i != m2.end(); ++i) + { + boost::detail::sp_counted_base const * p = static_cast<boost::detail::sp_counted_base const *>(i->first); + if(p->use_count() != i->second) open.push_back(p); + } + + std::cout << "... " << open.size() << " objects in open.\n"; + + for(open_type::iterator j = open.begin(); j != open.end(); ++j) + { + m2.erase(*j); + } + + while(!open.empty()) + { + void const * p = open.front(); + open.pop_front(); + + map_type::const_iterator i = m.find(p); + BOOST_ASSERT(i != m.end()); + + scan_and_mark(i->second.first, i->second.second, m2, open); + } + } + + // m2 now contains the unreachable objects +} + +std::size_t find_unreachable_objects(bool report) +{ + map2_type m2; + +#ifdef BOOST_HAS_THREADS + + // This will work without the #ifdef, but some compilers warn + // that lock is not referenced + + mutex_type::scoped_lock lock(get_mutex()); + +#endif + + map_type const & m = get_map(); + + find_unreachable_objects_impl(m, m2); + + if(report) + { + for(map2_type::iterator j = m2.begin(); j != m2.end(); ++j) + { + map_type::const_iterator i = m.find(j->first); + BOOST_ASSERT(i != m.end()); + std::cout << "Unreachable object at " << i->second.first << ", " << i->second.second << " bytes long.\n"; + } + } + + return m2.size(); +} + +typedef std::deque< boost::shared_ptr<X> > free_list_type; + +static void scan_and_free(void * area, size_t size, map2_type const & m2, free_list_type & free) +{ + unsigned char * p = static_cast<unsigned char *>(area); + + for(size_t n = 0; n + sizeof(shared_ptr_layout) <= size; p += pointer_align, n += pointer_align) + { + shared_ptr_layout * q = reinterpret_cast<shared_ptr_layout *>(p); + + if(q->pn.id == boost::detail::shared_count_id && q->pn.pi != 0 && m2.count(q->pn.pi) != 0 && q->px != 0) + { + boost::shared_ptr<X> * ppx = reinterpret_cast< boost::shared_ptr<X> * >(p); + free.push_back(*ppx); + ppx->reset(); + } + } +} + +void free_unreachable_objects() +{ + free_list_type free; + + { + map2_type m2; + +#ifdef BOOST_HAS_THREADS + + mutex_type::scoped_lock lock(get_mutex()); + +#endif + + map_type const & m = get_map(); + + find_unreachable_objects_impl(m, m2); + + for(map2_type::iterator j = m2.begin(); j != m2.end(); ++j) + { + map_type::const_iterator i = m.find(j->first); + BOOST_ASSERT(i != m.end()); + scan_and_free(i->second.first, i->second.second, m2, free); + } + } + + std::cout << "... about to free " << free.size() << " objects.\n"; +} + +// debug hooks + +namespace boost +{ + +void sp_scalar_constructor_hook(void *) +{ +} + +void sp_scalar_constructor_hook(void * px, std::size_t size, void * pn) +{ +#ifdef BOOST_HAS_THREADS + + mutex_type::scoped_lock lock(get_mutex()); + +#endif + + get_map()[pn] = std::make_pair(px, size); +} + +void sp_scalar_destructor_hook(void *) +{ +} + +void sp_scalar_destructor_hook(void *, std::size_t, void * pn) +{ +#ifdef BOOST_HAS_THREADS + + mutex_type::scoped_lock lock(get_mutex()); + +#endif + + get_map().erase(pn); +} + +void sp_array_constructor_hook(void *) +{ +} + +void sp_array_destructor_hook(void *) +{ +} + +} // namespace boost + +#endif // defined(BOOST_SP_ENABLE_DEBUG_HOOKS) diff --git a/src/boost/libs/smart_ptr/extras/src/sp_debug_hooks.cpp b/src/boost/libs/smart_ptr/extras/src/sp_debug_hooks.cpp new file mode 100644 index 00000000..31939363 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/src/sp_debug_hooks.cpp @@ -0,0 +1,243 @@ +// +// sp_debug_hooks.cpp +// +// Copyright (c) 2002, 2003 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) +// + +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) + +#include <boost/assert.hpp> +#include <new> +#include <cstdlib> + +int const m = 2; // m * sizeof(int) must be aligned appropriately + +// magic values to mark heap blocks with + +int const allocated_scalar = 0x1234560C; +int const allocated_array = 0x1234560A; +int const adopted_scalar = 0x0567890C; +int const adopted_array = 0x0567890A; +int const deleted = 0x498769DE; + +using namespace std; // for compilers where things aren't in std + +// operator new + +static new_handler get_new_handler() +{ + new_handler p = set_new_handler(0); + set_new_handler(p); + return p; +} + +static void * allocate(size_t n, int mark) +{ + int * pm; + + for(;;) + { + pm = static_cast<int*>(malloc(n + m * sizeof(int))); + + if(pm != 0) break; + + if(new_handler pnh = get_new_handler()) + { + pnh(); + } + else + { + return 0; + } + } + + *pm = mark; + + return pm + m; +} + +void * operator new(size_t n) throw(bad_alloc) +{ + void * p = allocate(n, allocated_scalar); + +#if !defined(BOOST_NO_EXCEPTIONS) + + if(p == 0) throw bad_alloc(); + +#endif + + return p; +} + +#if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551) + +void * operator new(size_t n, nothrow_t const &) throw() +{ + return allocate(n, allocated_scalar); +} + +#endif + +void * operator new[](size_t n) throw(bad_alloc) +{ + void * p = allocate(n, allocated_array); + +#if !defined(BOOST_NO_EXCEPTIONS) + + if(p == 0) throw bad_alloc(); + +#endif + + return p; +} + +#if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551) + +void * operator new[](size_t n, nothrow_t const &) throw() +{ + return allocate(n, allocated_array); +} + +#endif + +// debug hooks + +namespace boost +{ + +void sp_scalar_constructor_hook(void * p) +{ + if(p == 0) return; + + int * pm = static_cast<int*>(p); + pm -= m; + + BOOST_ASSERT(*pm != adopted_scalar); // second smart pointer to the same address + BOOST_ASSERT(*pm != allocated_array); // allocated with new[] + BOOST_ASSERT(*pm == allocated_scalar); // not allocated with new + + *pm = adopted_scalar; +} + +void sp_scalar_constructor_hook(void * px, std::size_t, void *) +{ + sp_scalar_constructor_hook(px); +} + +void sp_scalar_destructor_hook(void * p) +{ + if(p == 0) return; + + int * pm = static_cast<int*>(p); + pm -= m; + + BOOST_ASSERT(*pm == adopted_scalar); // attempt to destroy nonmanaged block + + *pm = allocated_scalar; +} + +void sp_scalar_destructor_hook(void * px, std::size_t, void *) +{ + sp_scalar_destructor_hook(px); +} + +// It is not possible to handle the array hooks in a portable manner. +// The implementation typically reserves a bit of storage for the number +// of objects in the array, and the argument of the array hook isn't +// equal to the return value of operator new[]. + +void sp_array_constructor_hook(void * /* p */) +{ +/* + if(p == 0) return; + + // adjust p depending on the implementation + + int * pm = static_cast<int*>(p); + pm -= m; + + BOOST_ASSERT(*pm != adopted_array); // second smart array pointer to the same address + BOOST_ASSERT(*pm != allocated_scalar); // allocated with new + BOOST_ASSERT(*pm == allocated_array); // not allocated with new[] + + *pm = adopted_array; +*/ +} + +void sp_array_destructor_hook(void * /* p */) +{ +/* + if(p == 0) return; + + // adjust p depending on the implementation + + int * pm = static_cast<int*>(p); + pm -= m; + + BOOST_ASSERT(*pm == adopted_array); // attempt to destroy nonmanaged block + + *pm = allocated_array; +*/ +} + +} // namespace boost + +// operator delete + +void operator delete(void * p) throw() +{ + if(p == 0) return; + + int * pm = static_cast<int*>(p); + pm -= m; + + BOOST_ASSERT(*pm != deleted); // double delete + BOOST_ASSERT(*pm != adopted_scalar); // delete p.get(); + BOOST_ASSERT(*pm != allocated_array); // allocated with new[] + BOOST_ASSERT(*pm == allocated_scalar); // not allocated with new + + *pm = deleted; + + free(pm); +} + +#if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551) + +void operator delete(void * p, nothrow_t const &) throw() +{ + ::operator delete(p); +} + +#endif + +void operator delete[](void * p) throw() +{ + if(p == 0) return; + + int * pm = static_cast<int*>(p); + pm -= m; + + BOOST_ASSERT(*pm != deleted); // double delete + BOOST_ASSERT(*pm != adopted_scalar); // delete p.get(); + BOOST_ASSERT(*pm != allocated_scalar); // allocated with new + BOOST_ASSERT(*pm == allocated_array); // not allocated with new[] + + *pm = deleted; + + free(pm); +} + +#if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551) + +void operator delete[](void * p, nothrow_t const &) throw() +{ + ::operator delete[](p); +} + +#endif + +#endif // defined(BOOST_SP_ENABLE_DEBUG_HOOKS) diff --git a/src/boost/libs/smart_ptr/extras/test/shared_ptr_mt_test.cpp b/src/boost/libs/smart_ptr/extras/test/shared_ptr_mt_test.cpp new file mode 100644 index 00000000..8a504256 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/test/shared_ptr_mt_test.cpp @@ -0,0 +1,82 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// shared_ptr_mt_test.cpp - tests shared_ptr with multiple threads +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2008 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 <boost/shared_ptr.hpp> +#include <boost/bind.hpp> + +#include <vector> + +#include <cstdio> +#include <ctime> + +#include <boost/detail/lightweight_thread.hpp> + +// + +int const n = 1024 * 1024; + +void test( boost::shared_ptr<int> const & pi ) +{ + std::vector< boost::shared_ptr<int> > v; + + for( int i = 0; i < n; ++i ) + { + v.push_back( pi ); + } +} + +int const m = 16; // threads + +#if defined( BOOST_HAS_PTHREADS ) + +char const * thmodel = "POSIX"; + +#else + +char const * thmodel = "Windows"; + +#endif + +int main() +{ + using namespace std; // printf, clock_t, clock + + printf( "Using %s threads: %d threads, %d iterations: ", thmodel, m, n ); + + boost::shared_ptr<int> pi( new int(42) ); + + clock_t t = clock(); + + boost::detail::lw_thread_t a[ m ]; + + for( int i = 0; i < m; ++i ) + { + boost::detail::lw_thread_create( a[ i ], boost::bind( test, pi ) ); + } + + for( int j = 0; j < m; ++j ) + { + boost::detail::lw_thread_join( a[j] ); + } + + t = clock() - t; + + printf( "\n\n%.3f seconds.\n", static_cast<double>(t) / CLOCKS_PER_SEC ); + + return 0; +} diff --git a/src/boost/libs/smart_ptr/extras/test/shared_ptr_timing_test.cpp b/src/boost/libs/smart_ptr/extras/test/shared_ptr_timing_test.cpp new file mode 100644 index 00000000..79e62ff4 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/test/shared_ptr_timing_test.cpp @@ -0,0 +1,46 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// shared_ptr_timing_test.cpp - use to evaluate the impact of thread safety +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// 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 <boost/shared_ptr.hpp> +#include <iostream> +#include <vector> +#include <ctime> + +int const n = 8 * 1024 * 1024; + +int main() +{ + using namespace std; + + std::vector< boost::shared_ptr<int> > v; + boost::shared_ptr<int> pi(new int); + + clock_t t = clock(); + + for(int i = 0; i < n; ++i) + { + v.push_back(pi); + } + + t = clock() - t; + + std::cout << static_cast<double>(t) / CLOCKS_PER_SEC << '\n'; + + return 0; +} diff --git a/src/boost/libs/smart_ptr/extras/test/sp_atomic_mt2_test.cpp b/src/boost/libs/smart_ptr/extras/test/sp_atomic_mt2_test.cpp new file mode 100644 index 00000000..750b0b26 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/test/sp_atomic_mt2_test.cpp @@ -0,0 +1,247 @@ + +// Copyright (c) 2008 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 <boost/config.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/bind.hpp> + +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/locks.hpp> + +#include <boost/detail/lightweight_mutex.hpp> +#include <boost/detail/lightweight_thread.hpp> + +#include <vector> +#include <numeric> +#include <cstdio> +#include <cstdlib> +#include <cstddef> +#include <ctime> + +// + +static void next_value( unsigned & v ) +{ + v = v % 2? 3 * v + 1: v / 2; +} + +struct X +{ + std::vector<unsigned> v_; + + explicit X( std::size_t n ): v_( n ) + { + for( std::size_t i = 0; i < n; ++i ) + { + v_[ i ] = i; + } + } + + unsigned get() const + { + return std::accumulate( v_.begin(), v_.end(), 0 ); + } + + void set() + { + std::for_each( v_.begin(), v_.end(), next_value ); + } +}; + +static boost::shared_ptr<X> ps; + +static boost::detail::lightweight_mutex lm; +static boost::shared_mutex rw; + +enum prim_type +{ + pt_mutex, + pt_rwlock, + pt_atomics +}; + +int read_access( prim_type pt ) +{ + switch( pt ) + { + case pt_mutex: + { + boost::detail::lightweight_mutex::scoped_lock lock( lm ); + return ps->get(); + } + + case pt_rwlock: + { + boost::shared_lock<boost::shared_mutex> lock( rw ); + return ps->get(); + } + + case pt_atomics: + { + boost::shared_ptr<X> p2 = boost::atomic_load( &ps ); + return p2->get(); + } + } +} + +void write_access( prim_type pt ) +{ + switch( pt ) + { + case pt_mutex: + { + boost::detail::lightweight_mutex::scoped_lock lock( lm ); + ps->set(); + } + break; + + case pt_rwlock: + { + boost::unique_lock<boost::shared_mutex> lock( rw ); + ps->set(); + } + break; + + case pt_atomics: + { + boost::shared_ptr<X> p1 = boost::atomic_load( &ps ); + + for( ;; ) + { + boost::shared_ptr<X> p2( new X( *p1 ) ); + p2->set(); + + if( boost::atomic_compare_exchange( &ps, &p1, p2 ) ) break; + } + } + break; + } +} + +void worker( int k, prim_type pt, int n, int r ) +{ + ++r; + + unsigned s = 0, nr = 0, nw = 0; + + for( int i = 0; i < n; ++i ) + { + if( i % r ) + { + s += read_access( pt ); + ++nr; + } + else + { + write_access( pt ); + ++s; + ++nw; + } + } + + printf( "Worker %2d: %u:%u, %10u\n", k, nr, nw, s ); +} + +#if defined( BOOST_HAS_PTHREADS ) + char const * thmodel = "POSIX"; +#else + char const * thmodel = "Windows"; +#endif + +char const * pt_to_string( prim_type pt ) +{ + switch( pt ) + { + case pt_mutex: + + return "mutex"; + + case pt_rwlock: + + return "rwlock"; + + case pt_atomics: + + return "atomics"; + } +} + +static void handle_pt_option( std::string const & opt, prim_type & pt, prim_type pt2 ) +{ + if( opt == pt_to_string( pt2 ) ) + { + pt = pt2; + } +} + +static void handle_int_option( std::string const & opt, std::string const & prefix, int & k, int kmin, int kmax ) +{ + if( opt.substr( 0, prefix.size() ) == prefix ) + { + int v = atoi( opt.substr( prefix.size() ).c_str() ); + + if( v >= kmin && v <= kmax ) + { + k = v; + } + } +} + +int main( int ac, char const * av[] ) +{ + using namespace std; // printf, clock_t, clock + + int m = 4; // threads + int n = 10000; // vector size + int k = 1000000; // iterations + int r = 100; // read/write ratio, r:1 + + prim_type pt = pt_atomics; + + for( int i = 1; i < ac; ++i ) + { + handle_pt_option( av[i], pt, pt_mutex ); + handle_pt_option( av[i], pt, pt_rwlock ); + handle_pt_option( av[i], pt, pt_atomics ); + + handle_int_option( av[i], "n=", n, 1, INT_MAX ); + handle_int_option( av[i], "size=", n, 1, INT_MAX ); + + handle_int_option( av[i], "k=", k, 1, INT_MAX ); + handle_int_option( av[i], "iterations=", k, 1, INT_MAX ); + + handle_int_option( av[i], "m=", m, 1, INT_MAX ); + handle_int_option( av[i], "threads=", m, 1, INT_MAX ); + + handle_int_option( av[i], "r=", r, 1, INT_MAX ); + handle_int_option( av[i], "ratio=", r, 1, INT_MAX ); + } + + printf( "%s: threads=%d size=%d iterations=%d ratio=%d %s\n\n", thmodel, m, n, k, r, pt_to_string( pt ) ); + + ps.reset( new X( n ) ); + + clock_t t = clock(); + + std::vector<boost::detail::lw_thread_t> a( m ); + + for( int i = 0; i < m; ++i ) + { + boost::detail::lw_thread_create( a[ i ], boost::bind( worker, i, pt, k, r ) ); + } + + for( int j = 0; j < m; ++j ) + { + boost::detail::lw_thread_join( a[ j ] ); + } + + t = clock() - t; + + double ts = static_cast<double>( t ) / CLOCKS_PER_SEC; + printf( "%.3f seconds, %.3f accesses per microsecond.\n", ts, m * k / ts / 1e+6 ); +} diff --git a/src/boost/libs/smart_ptr/extras/test/sp_atomic_mt_test.cpp b/src/boost/libs/smart_ptr/extras/test/sp_atomic_mt_test.cpp new file mode 100644 index 00000000..32c76c51 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/test/sp_atomic_mt_test.cpp @@ -0,0 +1,191 @@ + +// Copyright (c) 2008 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 + +//#define USE_MUTEX +//#define USE_RWLOCK + +#include <boost/config.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/bind.hpp> + +#if defined( USE_RWLOCK ) +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/locks.hpp> +#endif + +#include <boost/detail/lightweight_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/detail/lightweight_thread.hpp> + +#include <cstdio> +#include <ctime> + +// + +int const n = 1024 * 1024; + +struct X +{ + int v_; // version + + unsigned a_; + unsigned b_; + + X(): v_( 0 ), a_( 1 ), b_( 1 ) + { + } + + int get() const + { + return a_ * 7 + b_ * 11; + } + + void set() + { + int tmp = get(); + + b_ = a_; + a_ = tmp; + + ++v_; + } +}; + +static boost::shared_ptr<X> ps( new X ); + +static boost::detail::lightweight_mutex lm; + +#if defined( USE_RWLOCK ) +static boost::shared_mutex rw; +#endif + +static int tr = 0; + +void reader( int r ) +{ + int k = 0; + unsigned s = 0; + + for( int i = 0; i < n; ++k ) + { +#if defined( USE_MUTEX ) + + boost::detail::lightweight_mutex::scoped_lock lock( lm ); + + s += ps->get(); + + BOOST_TEST( ps->v_ >= i ); + i = ps->v_; + +#elif defined( USE_RWLOCK ) + + boost::shared_lock<boost::shared_mutex> lock( rw ); + + s += ps->get(); + + BOOST_TEST( ps->v_ >= i ); + i = ps->v_; + +#else + + boost::shared_ptr<X> p2 = boost::atomic_load( &ps ); + + s += p2->get(); + + BOOST_TEST( p2->v_ >= i ); + i = p2->v_; + +#endif + } + + printf( "Reader %d: %9d iterations (%6.3fx), %u\n", r, k, (double)k / n, s ); + + boost::detail::lightweight_mutex::scoped_lock lock( lm ); + tr += k; +} + +void writer() +{ + for( int i = 0; i < n; ++i ) + { +#if defined( USE_MUTEX ) + + boost::detail::lightweight_mutex::scoped_lock lock( lm ); + + BOOST_TEST( ps->v_ == i ); + ps->set(); + +#elif defined( USE_RWLOCK ) + + boost::unique_lock<boost::shared_mutex> lock( rw ); + + BOOST_TEST( ps->v_ == i ); + ps->set(); + +#else + + boost::shared_ptr<X> p2( new X( *ps ) ); + + BOOST_TEST( p2->v_ == i ); + p2->set(); + + boost::atomic_store( &ps, p2 ); + +#endif + } +} + +#if defined( BOOST_HAS_PTHREADS ) + char const * thmodel = "POSIX"; +#else + char const * thmodel = "Windows"; +#endif + +int const mr = 8; // reader threads +int const mw = 1; // writer thread + +#if defined( USE_MUTEX ) + char const * prim = "mutex"; +#elif defined( USE_RWLOCK ) + char const * prim = "rwlock"; +#else + char const * prim = "atomics"; +#endif + +int main() +{ + using namespace std; // printf, clock_t, clock + + printf( "Using %s threads: %dR + %dW threads, %d iterations, %s\n\n", thmodel, mr, mw, n, prim ); + + clock_t t = clock(); + + boost::detail::lw_thread_t a[ mr+mw ]; + + for( int i = 0; i < mr; ++i ) + { + boost::detail::lw_thread_create( a[ i ], boost::bind( reader, i ) ); + } + + for( int i = mr; i < mr+mw; ++i ) + { + boost::detail::lw_thread_create( a[ i ], writer ); + } + + for( int j = 0; j < mr+mw; ++j ) + { + boost::detail::lw_thread_join( a[ j ] ); + } + + t = clock() - t; + + double ts = static_cast<double>( t ) / CLOCKS_PER_SEC; + printf( "%.3f seconds, %.3f reads per microsecond.\n", ts, tr / ts / 1e+6 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/extras/test/weak_ptr_mt_test.cpp b/src/boost/libs/smart_ptr/extras/test/weak_ptr_mt_test.cpp new file mode 100644 index 00000000..5b11ff9c --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/test/weak_ptr_mt_test.cpp @@ -0,0 +1,122 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// weak_ptr_mt_test.cpp +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright 2005, 2008 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/bind.hpp> + +#include <vector> + +#include <cstdio> +#include <ctime> +#include <cstdlib> + +#include <boost/detail/lightweight_thread.hpp> + +// + +int const n = 16384; +int const k = 512; // vector size +int const m = 16; // threads + +void test( std::vector< boost::shared_ptr<int> > & v ) +{ + using namespace std; // printf, rand + + std::vector< boost::weak_ptr<int> > w( v.begin(), v.end() ); + + int s = 0, f = 0, r = 0; + + for( int i = 0; i < n; ++i ) + { + // randomly kill a pointer + + v[ rand() % k ].reset(); + ++s; + + for( int j = 0; j < k; ++j ) + { + if( boost::shared_ptr<int> px = w[ j ].lock() ) + { + ++s; + + if( rand() & 4 ) + { + continue; + } + + // rebind anyway with prob. 50% for add_ref_lock() against weak_release() contention + ++f; + } + else + { + ++r; + } + + w[ j ] = v[ rand() % k ]; + } + } + + printf( "\n%d locks, %d forced rebinds, %d normal rebinds.", s, f, r ); +} + +#if defined( BOOST_HAS_PTHREADS ) + +char const * thmodel = "POSIX"; + +#else + +char const * thmodel = "Windows"; + +#endif + +int main() +{ + using namespace std; // printf, clock_t, clock + + printf("Using %s threads: %d threads, %d * %d iterations: ", thmodel, m, n, k ); + + std::vector< boost::shared_ptr<int> > v( k ); + + for( int i = 0; i < k; ++i ) + { + v[ i ].reset( new int( 0 ) ); + } + + clock_t t = clock(); + + boost::detail::lw_thread_t a[ m ]; + + for( int i = 0; i < m; ++i ) + { + boost::detail::lw_thread_create( a[ i ], boost::bind( test, v ) ); + } + + v.resize( 0 ); // kill original copies + + for( int j = 0; j < m; ++j ) + { + boost::detail::lw_thread_join( a[j] ); + } + + t = clock() - t; + + printf("\n\n%.3f seconds.\n", static_cast<double>(t) / CLOCKS_PER_SEC); + + return 0; +} diff --git a/src/boost/libs/smart_ptr/extras/test/weak_ptr_timing_test.cpp b/src/boost/libs/smart_ptr/extras/test/weak_ptr_timing_test.cpp new file mode 100644 index 00000000..1c24b0a3 --- /dev/null +++ b/src/boost/libs/smart_ptr/extras/test/weak_ptr_timing_test.cpp @@ -0,0 +1,85 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// weak_ptr_timing_test.cpp +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright 2005 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +#include <vector> +#include <cstdio> +#include <ctime> +#include <cstdlib> + +// + +int const n = 29000; +int const k = 2048; + +void test( std::vector< boost::shared_ptr<int> > & v ) +{ + using namespace std; // printf, rand + + std::vector< boost::weak_ptr<int> > w( v.begin(), v.end() ); + + int s = 0, r = 0; + + for( int i = 0; i < n; ++i ) + { + // randomly kill a pointer + + v[ rand() % k ].reset(); + + for( int j = 0; j < k; ++j ) + { + if( boost::shared_ptr<int> px = w[ j ].lock() ) + { + ++s; + } + else + { + ++r; + w[ j ] = v[ rand() % k ]; + } + } + } + + printf( "\n%d locks, %d rebinds.", s, r ); +} + +int main() +{ + using namespace std; // printf, clock_t, clock + + std::vector< boost::shared_ptr<int> > v( k ); + + for( int i = 0; i < k; ++i ) + { + v[ i ].reset( new int( 0 ) ); + } + + clock_t t = clock(); + + test( v ); + + t = clock() - t; + + printf( "\n\n%.3f seconds.\n", static_cast<double>( t ) / CLOCKS_PER_SEC ); + + return 0; +} diff --git a/src/boost/libs/smart_ptr/index.html b/src/boost/libs/smart_ptr/index.html new file mode 100644 index 00000000..7afe6646 --- /dev/null +++ b/src/boost/libs/smart_ptr/index.html @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="refresh" content="0; URL=doc/html/smart_ptr.html"> +</head> +<body> +<p> +Automatic redirection failed, please go to +<a href="doc/html/smart_ptr.html">doc/html/smart_ptr.html</a>. +</p> +</body> +</html> +<!-- + (C) Copyright Beman Dawes, 2001 + 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 +--> diff --git a/src/boost/libs/smart_ptr/meta/libraries.json b/src/boost/libs/smart_ptr/meta/libraries.json new file mode 100644 index 00000000..8a027f73 --- /dev/null +++ b/src/boost/libs/smart_ptr/meta/libraries.json @@ -0,0 +1,21 @@ +{ + "key": "smart_ptr", + "name": "Smart Ptr", + "authors": [ + "Greg Colvin", + "Beman Dawes", + "Peter Dimov", + "Darin Adler", + "Glen Fernandes" + ], + "description": "Smart pointer class templates.", + "std": [ + "tr1" + ], + "category": [ + "Memory" + ], + "maintainers": [ + "Peter Dimov <pdimov -at- pdimov.com>" + ] +} diff --git a/src/boost/libs/smart_ptr/test/Jamfile b/src/boost/libs/smart_ptr/test/Jamfile new file mode 100644 index 00000000..4e9e62e2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/Jamfile @@ -0,0 +1,335 @@ +# Boost.SmartPtr Library test Jamfile +# +# Copyright (c) 2003-2018 Peter Dimov +# Copyright (c) 2003 Dave Abrahams +# +# 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) + +import testing ; + +project + : requirements + <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor + <toolset>gcc:<cxxflags>-Wno-deprecated-declarations + #<toolset>gcc:<cxxflags>-Wno-delete-non-virtual-dtor (not in 4.4/4.6) + ; + +# quick test (for CI) +run quick.cpp ; + +# full test suite +run smart_ptr_test.cpp ; +run shared_ptr_basic_test.cpp ; +run shared_ptr_test.cpp ; +run weak_ptr_test.cpp ; +run weak_ptr_move_test.cpp ; +run shared_from_this_test.cpp ; +run get_deleter_test.cpp ; +run intrusive_ptr_test.cpp ; +run intrusive_ptr_move_test.cpp ; +run intrusive_ref_counter_test.cpp ; +run atomic_count_test.cpp ; +run lw_mutex_test.cpp ; +run lw_mutex_test.cpp : : : <define>BOOST_USE_WINDOWS_H : lw_mutex_test.win_h ; +compile-fail shared_ptr_assign_fail.cpp ; +compile-fail shared_ptr_delete_fail.cpp ; +compile-fail shared_ptr_compare_fail.cpp ; +run shared_ptr_alloc2_test.cpp ; +run pointer_cast_test.cpp ; +run cpp11_pointer_cast_test.cpp ; +compile pointer_to_other_test.cpp ; +run auto_ptr_rv_test.cpp ; +run shared_ptr_alias_test.cpp ; +run shared_ptr_rv_test.cpp ; +run shared_ptr_rv_pointer_cast_test.cpp ; +run shared_ptr_move_test.cpp ; +run shared_ptr_alias_move_test.cpp ; +run shared_ptr_reinterpret_pointer_cast_test.cpp ; +compile-fail shared_ptr_pv_fail.cpp ; +run sp_unary_addr_test.cpp ; +compile-fail scoped_ptr_eq_fail.cpp ; +compile-fail scoped_array_eq_fail.cpp ; +run esft_regtest.cpp ; +run yield_k_test.cpp ; +run yield_k_test.cpp : : : <threading>multi : yield_k_test.mt ; +run spinlock_test.cpp ; +run spinlock_try_test.cpp ; +run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ; +run spinlock_pool_test.cpp : : : + # msvc-8.0, 9.0 optimizer codegen bug for `x % 41` + <toolset>msvc-8.0,<variant>release:<build>no + <toolset>msvc-9.0,<variant>release:<build>no ; + +run make_shared_test.cpp ; +run make_shared_move_emulation_test.cpp ; +run make_shared_perfect_forwarding_test.cpp ; +run shared_ptr_convertible_test.cpp ; +run wp_convertible_test.cpp ; +run ip_convertible_test.cpp ; +run allocate_shared_test.cpp ; +run sp_atomic_test.cpp ; +run esft_void_test.cpp ; +run esft_second_ptr_test.cpp ; +run make_shared_esft_test.cpp ; +run allocate_shared_esft_test.cpp ; +run sp_recursive_assign_test.cpp ; +run sp_recursive_assign2_test.cpp ; +run sp_recursive_assign_rv_test.cpp ; +run sp_recursive_assign2_rv_test.cpp ; +compile-fail auto_ptr_lv_fail.cpp : <toolset>gcc-4.4.7:<build>no ; +run atomic_count_test2.cpp ; +run sp_typeinfo_test.cpp ; +compile make_shared_fp_test.cpp ; +run sp_hash_test.cpp ; +run get_deleter_array_test.cpp ; +run ip_hash_test.cpp ; +run owner_less_test.cpp ; +run sp_unique_ptr_test.cpp ; +run sp_array_test.cpp ; +compile sp_array_cv_test.cpp ; +run sp_convertible_test.cpp ; +run sp_array_n_test.cpp ; +run sp_array_cast_test.cpp ; +run sp_zero_compare_test.cpp ; +run sp_nullptr_test.cpp ; +run sa_nullptr_test.cpp ; +run shared_ptr_alloc3_test.cpp ; +run shared_ptr_alloc11_test.cpp ; +run shared_ptr_alloc_construct11_test.cpp ; +run allocate_shared_alloc11_test.cpp ; +run allocate_shared_construct11_test.cpp ; +run sp_interlocked_test.cpp ; + +compile-fail array_fail_spa_sp_c.cpp ; +compile-fail array_fail_sp_spa_c.cpp ; +compile-fail array_fail_spa_spa_c.cpp ; +compile-fail array_fail_spa_wp_c.cpp ; +compile-fail array_fail_sp_wpa_c.cpp ; +compile-fail array_fail_spa_wpa_c.cpp ; +compile-fail array_fail_wpa_wp_c.cpp ; +compile-fail array_fail_wp_wpa_c.cpp ; +compile-fail array_fail_wpa_wpa_c.cpp ; +compile-fail array_fail_ap_spa_c.cpp ; +compile-fail array_fail_upa_sp_c.cpp ; +compile-fail array_fail_up_spa_c.cpp ; + +compile-fail array_fail_spa_sp_mc.cpp ; +compile-fail array_fail_sp_spa_mc.cpp ; +compile-fail array_fail_spa_spa_mc.cpp ; +compile-fail array_fail_spa_wp_mc.cpp ; +compile-fail array_fail_sp_wpa_mc.cpp ; +compile-fail array_fail_spa_wpa_mc.cpp ; +compile-fail array_fail_wpa_wp_mc.cpp ; +compile-fail array_fail_wp_wpa_mc.cpp ; +compile-fail array_fail_wpa_wpa_mc.cpp ; +compile-fail array_fail_ap_spa_mc.cpp ; +compile-fail array_fail_upa_sp_mc.cpp ; +compile-fail array_fail_up_spa_mc.cpp ; + +compile-fail array_fail_spa_sp_a.cpp ; +compile-fail array_fail_sp_spa_a.cpp ; +compile-fail array_fail_spa_spa_a.cpp ; +compile-fail array_fail_spa_wp_a.cpp ; +compile-fail array_fail_sp_wpa_a.cpp ; +compile-fail array_fail_spa_wpa_a.cpp ; +compile-fail array_fail_wpa_wp_a.cpp ; +compile-fail array_fail_wp_wpa_a.cpp ; +compile-fail array_fail_wpa_wpa_a.cpp ; +compile-fail array_fail_ap_spa_a.cpp ; +compile-fail array_fail_upa_sp_a.cpp ; +compile-fail array_fail_up_spa_a.cpp ; + +compile-fail array_fail_spa_sp_ma.cpp ; +compile-fail array_fail_sp_spa_ma.cpp ; +compile-fail array_fail_spa_spa_ma.cpp ; +compile-fail array_fail_spa_wp_ma.cpp ; +compile-fail array_fail_sp_wpa_ma.cpp ; +compile-fail array_fail_spa_wpa_ma.cpp ; +compile-fail array_fail_wpa_wp_ma.cpp ; +compile-fail array_fail_wp_wpa_ma.cpp ; +compile-fail array_fail_wpa_wpa_ma.cpp ; +compile-fail array_fail_ap_spa_ma.cpp ; +compile-fail array_fail_upa_sp_ma.cpp ; +compile-fail array_fail_up_spa_ma.cpp ; + +compile-fail array_fail_dereference.cpp ; +compile-fail array_fail_member_access.cpp ; +compile-fail array_fail_array_access.cpp ; + +run make_shared_array_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run make_shared_arrays_test.cpp ; # <cxxflags>-fno-deduce-init-list no longer needed for gcc-4.6 +run make_shared_array_throws_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run make_shared_array_esft_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run make_shared_array_noinit_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run make_shared_array_value_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run allocate_shared_array_test.cpp ; +run allocate_shared_arrays_test.cpp ; # <cxxflags>-fno-deduce-init-list no longer needed for gcc-4.6 +run allocate_shared_array_throws_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run allocate_shared_array_esft_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run allocate_shared_array_noinit_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run allocate_shared_array_value_test.cpp : : : <toolset>msvc-8.0:<build>no ; +run allocate_shared_array_construct_test.cpp ; + +run make_unique_test.cpp ; +run make_unique_args_test.cpp ; +run make_unique_value_test.cpp : : : <toolset>gcc-4.6:<cxxflags>-fno-deduce-init-list ; +run make_unique_noinit_test.cpp ; +run make_unique_throws_test.cpp ; +run make_unique_array_test.cpp ; +run make_unique_array_noinit_test.cpp ; +run make_unique_array_throws_test.cpp ; + +run shared_from_raw_test.cpp ; +run shared_from_raw_test2.cpp ; +run shared_from_raw_test3.cpp ; +run shared_from_raw_test4.cpp ; +run shared_from_raw_test5.cpp ; +run shared_from_raw_test6.cpp ; + +run weak_from_raw_test.cpp ; +run weak_from_raw_test2.cpp ; +run weak_from_raw_test3.cpp ; +run weak_from_raw_test4.cpp ; +run weak_from_raw_test5.cpp ; + +compile sp_explicit_inst_test.cpp ; + +run weak_from_this_test.cpp ; +run weak_from_this_test2.cpp ; + +run sp_bml_unique_ptr_test.cpp ; + +run sp_hash_test2.cpp ; +run sp_hash_test3.cpp ; + +run pointer_cast_test2.cpp ; + +compile-fail pointer_cast_st_fail.cpp ; +compile-fail pointer_cast_st_fail2.cpp ; +compile-fail pointer_cast_st_fail3.cpp ; + +compile-fail pointer_cast_co_fail.cpp ; +compile-fail pointer_cast_co_fail2.cpp ; +compile-fail pointer_cast_co_fail3.cpp ; + +compile-fail pointer_cast_dy_fail.cpp ; +compile-fail pointer_cast_dy_fail2.cpp ; +compile-fail pointer_cast_dy_fail3.cpp ; + +run sp_nothrow_test.cpp ; + +compile make_shared_msvc_test.cpp ; + +compile lwm_win32_cs_test.cpp ; + +run atomic_sp_test.cpp ; + +run sp_constexpr_test.cpp ; +run sp_constexpr_test2.cpp ; + +run atomic_sp_constexpr_test.cpp ; + +run shared_ptr_fn_test.cpp ; + +run get_deleter_test2.cpp ; +run get_deleter_test3.cpp ; +run get_deleter_array_test2.cpp ; +run get_deleter_array_test3.cpp : : : <toolset>msvc-8.0:<build>no ; + +run sp_convertible_test2.cpp ; + +run local_sp_test.cpp ; +run lsp_array_test.cpp ; +run lsp_array_n_test.cpp ; +run lsp_array_cv_test.cpp ; +run lsp_array_cast_test.cpp ; + +run get_local_deleter_test.cpp ; +run get_local_deleter_test2.cpp ; +run get_local_deleter_test3.cpp ; +run get_local_deleter_array_test.cpp ; +run get_local_deleter_array_test2.cpp ; + +run make_local_shared_test.cpp ; +run make_local_shared_esft_test.cpp ; +run allocate_local_shared_test.cpp ; +run allocate_local_shared_esft_test.cpp ; + +run make_local_shared_array_test.cpp ; +run make_local_shared_arrays_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ; +run make_local_shared_array_throws_test.cpp ; +run make_local_shared_array_esft_test.cpp ; +run make_local_shared_array_noinit_test.cpp ; +run make_local_shared_array_value_test.cpp ; +run allocate_local_shared_array_test.cpp ; +run allocate_local_shared_arrays_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ; +run allocate_local_shared_array_throws_test.cpp ; +run allocate_local_shared_array_esft_test.cpp ; +run allocate_local_shared_array_noinit_test.cpp ; +run allocate_local_shared_array_value_test.cpp ; +run allocate_local_shared_array_construct_test.cpp ; + +run local_sp_fn_test.cpp ; +run lsp_convertible_test.cpp ; +run lsp_convertible_test2.cpp ; + +run make_shared_array_tmp_test.cpp : : : <toolset>msvc-8.0:<build>no ; + +run lw_thread_test.cpp : : : <threading>multi ; + +compile sp_windows_h_test.cpp ; +compile spinlock_windows_h_test.cpp ; +compile yield_k_windows_h_test.cpp ; + +lib dll_test : dll_test_lib.cpp : <link>shared:<define>DLL_TEST_DYN_LINK=1 ; +explicit dll_test ; + +run dll_test_main.cpp dll_test : : : <link>static : dll_test_static ; +run dll_test_main.cpp dll_test : : : <link>shared : dll_test_shared ; + +run make_shared_const_test.cpp ; +run make_local_shared_const_test.cpp ; + +lib abi_test_mt : abi_test_lib.cpp : <link>static ; +explicit abi_test_mt ; + +obj abi_test_lib_nt : abi_test_lib.cpp : <define>BOOST_DISABLE_THREADS ; +explicit abi_test_lib_nt ; + +lib abi_test_nt : abi_test_lib_nt : <link>static ; +explicit abi_test_nt ; + +run abi_test_main.cpp abi_test_mt : : : <define>BOOST_DISABLE_THREADS : abi_test_nt_mt ; +run abi_test_main.cpp abi_test_nt : : : : abi_test_mt_nt ; + +run abi_test_main.cpp abi_test_mt/<cxxstd>0x : : : <cxxstd>98 : abi_test_03_11 ; +run abi_test_main.cpp abi_test_mt/<cxxstd>98 : : : <cxxstd>0x : abi_test_11_03 ; + +run weak_ptr_alias_test.cpp ; +run weak_ptr_alias_move_test.cpp ; + +run sp_typeinfo_test.cpp : : : <rtti>off : sp_typeinfo_test_no_rtti ; + +run get_deleter_test.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test_no_rtti ; +run get_deleter_test2.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test2_no_rtti ; +run get_deleter_test3.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test3_no_rtti ; + +run shared_from_test.cpp ; +run weak_from_test.cpp ; +run weak_from_test2.cpp ; + +run allocate_unique_aggregate_test.cpp ; +run allocate_unique_args_test.cpp ; +run allocate_unique_array_construct_test.cpp ; +run allocate_unique_array_noinit_test.cpp ; +run allocate_unique_arrays_test.cpp ; +run allocate_unique_array_test.cpp ; +run allocate_unique_array_throws_test.cpp ; +run allocate_unique_array_value_test.cpp ; +run allocate_unique_construct_test.cpp ; +run allocate_unique_noinit_test.cpp ; +run allocate_unique_test.cpp ; +run allocate_unique_throws_test.cpp ; +run allocate_unique_value_test.cpp ; diff --git a/src/boost/libs/smart_ptr/test/abi_test_lib.cpp b/src/boost/libs/smart_ptr/test/abi_test_lib.cpp new file mode 100644 index 00000000..4cb2150f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/abi_test_lib.cpp @@ -0,0 +1,43 @@ +// Copyright 2018 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 <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/config/pragma_message.hpp> + +#if defined(BOOST_DISABLE_THREADS) +BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is defined" ) +#else +BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is not defined" ) +#endif + +#if defined(BOOST_NO_CXX11_HDR_ATOMIC) +BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is defined" ) +#else +BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is not defined" ) +#endif + +void abi_test_1( boost::shared_ptr<void> & p ) +{ + BOOST_TEST_EQ( p.use_count(), 1 ); + + p.reset(); + + BOOST_TEST_EQ( p.use_count(), 0 ); +} + +boost::shared_ptr<void> abi_test_2( boost::shared_ptr<void> const & p ) +{ + BOOST_TEST_EQ( p.use_count(), 1 ); + + return p; +} + +boost::shared_ptr<void> abi_test_3() +{ + return boost::shared_ptr<void>( static_cast<int*>( 0 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/abi_test_main.cpp b/src/boost/libs/smart_ptr/test/abi_test_main.cpp new file mode 100644 index 00000000..2fb6a8c1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/abi_test_main.cpp @@ -0,0 +1,82 @@ +// Copyright 2018 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 <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/config/pragma_message.hpp> + +#if defined(BOOST_DISABLE_THREADS) +BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is defined" ) +#else +BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is not defined" ) +#endif + +#if defined(BOOST_NO_CXX11_HDR_ATOMIC) +BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is defined" ) +#else +BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is not defined" ) +#endif + +void abi_test_1( boost::shared_ptr<void> & p ); +boost::shared_ptr<void> abi_test_2( boost::shared_ptr<void> const & p ); +boost::shared_ptr<void> abi_test_3(); + +static int deleter_called; + +void deleter( void* ) +{ + ++deleter_called; +} + +int main() +{ + { + deleter_called = 0; + + boost::shared_ptr<void> p( static_cast<void*>( 0 ), deleter ); + + BOOST_TEST_EQ( p.use_count(), 1 ); + + abi_test_1( p ); + + BOOST_TEST_EQ( p.use_count(), 0 ); + BOOST_TEST_EQ( deleter_called, 1 ); + } + + { + deleter_called = 0; + + boost::shared_ptr<void> p1( static_cast<void*>( 0 ), deleter ); + + BOOST_TEST_EQ( p1.use_count(), 1 ); + + boost::shared_ptr<void> p2 = abi_test_2( p1 ); + + BOOST_TEST_EQ( p1.use_count(), 2 ); + BOOST_TEST_EQ( p2.use_count(), 2 ); + + p1.reset(); + + BOOST_TEST_EQ( p2.use_count(), 1 ); + + p2.reset(); + + BOOST_TEST_EQ( deleter_called, 1 ); + } + + { + boost::shared_ptr<void> p = abi_test_3(); + + BOOST_TEST_EQ( p.use_count(), 1 ); + + p.reset(); + + BOOST_TEST_EQ( p.use_count(), 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_array_construct_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_construct_test.cpp new file mode 100644 index 00000000..0f8bc1b8 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_construct_test.cpp @@ -0,0 +1,165 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ + !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +struct allow { }; + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + template<class U> + void construct(U* ptr) { + ::new(static_cast<void*>(ptr)) U(allow()); + } + + template<class U> + void destroy(U* ptr) { + ptr->~U(); + } + +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + explicit type(allow) { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::local_shared_ptr<type[]> result = + boost::allocate_local_shared<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[3]> result = + boost::allocate_local_shared<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[][2]> result = + boost::allocate_local_shared<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[2][2]> result = + boost::allocate_local_shared<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[]> result = + boost::allocate_local_shared<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[3]> result = + boost::allocate_local_shared<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[][2]> result = + boost::allocate_local_shared<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[2][2]> result = + boost::allocate_local_shared<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_array_esft_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_esft_test.cpp new file mode 100644 index 00000000..7138745b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_esft_test.cpp @@ -0,0 +1,103 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/enable_shared_from_this.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type + : public boost::enable_shared_from_this<type> { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + { + boost::local_shared_ptr<type[]> result = + boost::allocate_local_shared<type[]>(creator<type>(), 3); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + BOOST_TEST(type::instances == 0); + { + boost::local_shared_ptr<type[]> result = + boost::allocate_local_shared_noinit<type[]>(creator<>(), 3); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_array_noinit_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_noinit_test.cpp new file mode 100644 index 00000000..e2e16194 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_noinit_test.cpp @@ -0,0 +1,254 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::local_shared_ptr<int[]> result = + boost::allocate_local_shared_noinit<int[]>(creator<int>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<int[3]> result = + boost::allocate_local_shared_noinit<int[3]>(creator<int>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<int[][2]> result = + boost::allocate_local_shared_noinit<int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<int[2][2]> result = + boost::allocate_local_shared_noinit<int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[]> result = + boost::allocate_local_shared_noinit<const int[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[3]> result = + boost::allocate_local_shared_noinit<const int[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[][2]> result = + boost::allocate_local_shared_noinit<const int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[2][2]> result = + boost::allocate_local_shared_noinit<const int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<type[]> result = + boost::allocate_local_shared_noinit<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[3]> result = + boost::allocate_local_shared_noinit<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[][2]> result = + boost::allocate_local_shared_noinit<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[2][2]> result = + boost::allocate_local_shared_noinit<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[]> result = + boost::allocate_local_shared_noinit<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[3]> result = + boost::allocate_local_shared_noinit<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[][2]> result = + boost::allocate_local_shared_noinit<const + type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[2][2]> result = + boost::allocate_local_shared_noinit<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_array_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_test.cpp new file mode 100644 index 00000000..34f3d42f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_test.cpp @@ -0,0 +1,275 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::local_shared_ptr<int[]> result = + boost::allocate_local_shared<int[]>(creator<int>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<int[3]> result = + boost::allocate_local_shared<int[3]>(creator<int>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<int[][2]> result = + boost::allocate_local_shared<int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<int[2][2]> result = + boost::allocate_local_shared<int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<const int[]> result = + boost::allocate_local_shared<const int[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<const int[3]> result = + boost::allocate_local_shared<const int[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<const int[][2]> result = + boost::allocate_local_shared<const int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<const int[2][2]> result = + boost::allocate_local_shared<const int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<type[]> result = + boost::allocate_local_shared<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[3]> result = + boost::allocate_local_shared<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[][2]> result = + boost::allocate_local_shared<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[2][2]> result = + boost::allocate_local_shared<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[]> result = + boost::allocate_local_shared<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[3]> result = + boost::allocate_local_shared<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[][2]> result = + boost::allocate_local_shared<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[2][2]> result = + boost::allocate_local_shared<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_array_throws_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_throws_test.cpp new file mode 100644 index 00000000..78ae6b6a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_throws_test.cpp @@ -0,0 +1,130 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() { + if (instances == 5) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + try { + boost::allocate_local_shared<type[]>(creator<type>(), 6); + BOOST_ERROR("allocate_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared<type[][2]>(creator<type>(), 3); + BOOST_ERROR("allocate_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared<type[6]>(creator<>()); + BOOST_ERROR("allocate_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared<type[3][2]>(creator<>()); + BOOST_ERROR("allocate_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared_noinit<type[]>(creator<>(), 6); + BOOST_ERROR("allocate_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared_noinit<type[][2]>(creator<>(), 3); + BOOST_ERROR("allocate_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared_noinit<type[6]>(creator<>()); + BOOST_ERROR("allocate_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_local_shared_noinit<type[3][2]>(creator<>()); + BOOST_ERROR("allocate_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_array_value_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_value_test.cpp new file mode 100644 index 00000000..7d9c35f0 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_array_value_test.cpp @@ -0,0 +1,92 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + { + boost::local_shared_ptr<int[]> result = + boost::allocate_local_shared<int[]>(creator<int>(), 4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::local_shared_ptr<int[4]> result = + boost::allocate_local_shared<int[4]>(creator<int>(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::local_shared_ptr<const int[]> result = + boost::allocate_local_shared<const int[]>(creator<>(), 4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::local_shared_ptr<const int[4]> result = + boost::allocate_local_shared<const int[4]>(creator<>(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_arrays_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_arrays_test.cpp new file mode 100644 index 00000000..d45a6861 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_arrays_test.cpp @@ -0,0 +1,93 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ + !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + { + boost::local_shared_ptr<int[][2]> result = + boost::allocate_local_shared<int[][2]>(creator<int>(), 2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::local_shared_ptr<int[2][2]> result = + boost::allocate_local_shared<int[2][2]>(creator<int>(), {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::local_shared_ptr<const int[][2]> result = + boost::allocate_local_shared<const int[][2]>(creator<>(), 2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::local_shared_ptr<const int[2][2]> result = + boost::allocate_local_shared<const int[2][2]>(creator<>(), {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_esft_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_esft_test.cpp new file mode 100644 index 00000000..65349c53 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_esft_test.cpp @@ -0,0 +1,298 @@ +// allocate_local_shared_esft_test.cpp +// +// Copyright 2007-2009, 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <memory> + +class X: public boost::enable_shared_from_this<X> +{ +private: + + X( X const & ); + X & operator=( X const & ); + +public: + + static int instances; + + explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>() ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared_noinit< X >( std::allocator<void>() ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + BOOST_TEST_EQ( X::instances, 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST_EQ( px, qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST_EQ( X::instances, 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST_EQ( X::instances, 0 ); + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_local_shared_test.cpp b/src/boost/libs/smart_ptr/test/allocate_local_shared_test.cpp new file mode 100644 index 00000000..fa53dc06 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_local_shared_test.cpp @@ -0,0 +1,235 @@ +// allocate_local_shared_test.cpp +// +// Copyright 2007-2009, 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + // lack of this definition causes link errors on Comeau C++ + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + // lack of this definition causes link errors on MSVC + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::local_shared_ptr< int > pi = boost::allocate_local_shared< int >( std::allocator<int>() ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 0 ); + } + + { + boost::local_shared_ptr< int > pi = boost::allocate_local_shared_noinit< int >( std::allocator<int>() ); + + BOOST_TEST( pi.get() != 0 ); + } + + { + boost::local_shared_ptr< int > pi = boost::allocate_local_shared< int >( std::allocator<int>(), 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>() ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared_noinit< X >( std::allocator<void>() ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_alloc11_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_alloc11_test.cpp new file mode 100644 index 00000000..bf2a402e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_alloc11_test.cpp @@ -0,0 +1,241 @@ +// allocate_shared_alloc11_test.cpp +// +// allocate_shared with a minimal C++11 allocator +// +// Copyright 2007-2009, 2014 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/config.hpp> +#include <cstddef> + +#if !defined( BOOST_NO_CXX11_ALLOCATOR ) + +template< class T > class cxx11_allocator +{ +public: + + typedef T value_type; + + cxx11_allocator() + { + } + + template< class Y > cxx11_allocator( cxx11_allocator<Y> const & ) + { + } + + T * allocate( std::size_t n ) + { + return static_cast< T* >( ::operator new( n * sizeof( T ) ) ); + } + + void deallocate( T * p, std::size_t n ) + { + ::operator delete( p ); + } +}; + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_ptr< int > pi = boost::allocate_shared< int >( cxx11_allocator<int>() ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 0 ); + } + + { + boost::shared_ptr< int > pi = boost::allocate_shared< int >( cxx11_allocator<int>(), 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>() ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} + +#else // !defined( BOOST_NO_CXX11_ALLOCATOR ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_array_construct_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_array_construct_test.cpp new file mode 100644 index 00000000..ef0dc958 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_array_construct_test.cpp @@ -0,0 +1,163 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +struct allow { }; + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + template<class U> + void construct(U* ptr) { + ::new(static_cast<void*>(ptr)) U(allow()); + } + + template<class U> + void destroy(U* ptr) { + ptr->~U(); + } + +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + explicit type(allow) { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::shared_ptr<type[]> result = + boost::allocate_shared<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[3]> result = + boost::allocate_shared<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[][2]> result = + boost::allocate_shared<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[2][2]> result = + boost::allocate_shared<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[]> result = + boost::allocate_shared<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[3]> result = + boost::allocate_shared<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[][2]> result = + boost::allocate_shared<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[2][2]> result = + boost::allocate_shared<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp new file mode 100644 index 00000000..1e0afaf6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp @@ -0,0 +1,94 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/enable_shared_from_this.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type + : public boost::enable_shared_from_this<type> { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr<type[]> result = + boost::allocate_shared<type[]>(creator<type>(), 3); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr<type[]> result = + boost::allocate_shared_noinit<type[]>(creator<>(), 3); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_array_noinit_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_array_noinit_test.cpp new file mode 100644 index 00000000..910d8f73 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_array_noinit_test.cpp @@ -0,0 +1,245 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::shared_ptr<int[]> result = + boost::allocate_shared_noinit<int[]>(creator<int>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<int[3]> result = + boost::allocate_shared_noinit<int[3]>(creator<int>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<int[][2]> result = + boost::allocate_shared_noinit<int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<int[2][2]> result = + boost::allocate_shared_noinit<int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[]> result = + boost::allocate_shared_noinit<const int[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[3]> result = + boost::allocate_shared_noinit<const int[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[][2]> result = + boost::allocate_shared_noinit<const int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[2][2]> result = + boost::allocate_shared_noinit<const int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<type[]> result = + boost::allocate_shared_noinit<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[3]> result = + boost::allocate_shared_noinit<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[][2]> result = + boost::allocate_shared_noinit<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[2][2]> result = + boost::allocate_shared_noinit<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[]> result = + boost::allocate_shared_noinit<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[3]> result = + boost::allocate_shared_noinit<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[][2]> result = + boost::allocate_shared_noinit<const + type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[2][2]> result = + boost::allocate_shared_noinit<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_array_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_array_test.cpp new file mode 100644 index 00000000..d2854f9c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_array_test.cpp @@ -0,0 +1,266 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::shared_ptr<int[]> result = + boost::allocate_shared<int[]>(creator<int>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<int[3]> result = + boost::allocate_shared<int[3]>(creator<int>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<int[][2]> result = + boost::allocate_shared<int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<int[2][2]> result = + boost::allocate_shared<int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<const int[]> result = + boost::allocate_shared<const int[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<const int[3]> result = + boost::allocate_shared<const int[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<const int[][2]> result = + boost::allocate_shared<const int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<const int[2][2]> result = + boost::allocate_shared<const int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<type[]> result = + boost::allocate_shared<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[3]> result = + boost::allocate_shared<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[][2]> result = + boost::allocate_shared<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[2][2]> result = + boost::allocate_shared<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[]> result = + boost::allocate_shared<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[3]> result = + boost::allocate_shared<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[][2]> result = + boost::allocate_shared<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[2][2]> result = + boost::allocate_shared<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_array_throws_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_array_throws_test.cpp new file mode 100644 index 00000000..dd674bbc --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_array_throws_test.cpp @@ -0,0 +1,121 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() { + if (instances == 5) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + try { + boost::allocate_shared<type[]>(creator<type>(), 6); + BOOST_ERROR("allocate_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared<type[][2]>(creator<type>(), 3); + BOOST_ERROR("allocate_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared<type[6]>(creator<>()); + BOOST_ERROR("allocate_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared<type[3][2]>(creator<>()); + BOOST_ERROR("allocate_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared_noinit<type[]>(creator<>(), 6); + BOOST_ERROR("allocate_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared_noinit<type[][2]>(creator<>(), 3); + BOOST_ERROR("allocate_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared_noinit<type[6]>(creator<>()); + BOOST_ERROR("allocate_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_shared_noinit<type[3][2]>(creator<>()); + BOOST_ERROR("allocate_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_array_value_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_array_value_test.cpp new file mode 100644 index 00000000..c0d67b9e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_array_value_test.cpp @@ -0,0 +1,83 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + { + boost::shared_ptr<int[]> result = + boost::allocate_shared<int[]>(creator<int>(), 4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::shared_ptr<int[4]> result = + boost::allocate_shared<int[4]>(creator<int>(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::shared_ptr<const int[]> result = + boost::allocate_shared<const int[]>(creator<>(), 4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::shared_ptr<const int[4]> result = + boost::allocate_shared<const int[4]>(creator<>(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_arrays_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_arrays_test.cpp new file mode 100644 index 00000000..a23930c7 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_arrays_test.cpp @@ -0,0 +1,91 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + { + boost::shared_ptr<int[][2]> result = + boost::allocate_shared<int[][2]>(creator<int>(), 2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::shared_ptr<int[2][2]> result = + boost::allocate_shared<int[2][2]>(creator<int>(), {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::shared_ptr<const int[][2]> result = + boost::allocate_shared<const int[][2]>(creator<>(), 2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::shared_ptr<const int[2][2]> result = + boost::allocate_shared<const int[2][2]>(creator<>(), {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_construct11_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_construct11_test.cpp new file mode 100644 index 00000000..131b4cba --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_construct11_test.cpp @@ -0,0 +1,240 @@ +// allocate_shared_construct11_test.cpp +// +// Test whether allocate_shared uses construct/destroy in C++11 +// +// Copyright 2007-2009, 2014 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +#if !defined( BOOST_NO_CXX11_ALLOCATOR ) + +template< class T > class cxx11_allocator +{ +public: + + typedef T value_type; + + cxx11_allocator() + { + } + + template< class Y > cxx11_allocator( cxx11_allocator<Y> const & ) + { + } + + T * allocate( std::size_t n ) + { + return static_cast< T* >( ::operator new( n * sizeof( T ) ) ); + } + + void deallocate( T * p, std::size_t n ) + { + ::operator delete( p ); + } + + template<class... Args> void construct( T * p, Args&&... args ) + { + ::new( static_cast< void* >( p ) ) T( std::forward<Args>( args )... ); + } + + void destroy( T * p ) + { + p->~T(); + } +}; + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + +protected: + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } + + friend class cxx11_allocator<X>; +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>() ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} + +#else // !defined( BOOST_NO_CXX11_ALLOCATOR ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_esft_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_esft_test.cpp new file mode 100644 index 00000000..7902313d --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_esft_test.cpp @@ -0,0 +1,286 @@ +// allocate_shared_esft_test.cpp +// +// Copyright 2007-2009 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <memory> + +class X: public boost::enable_shared_from_this<X> +{ +private: + + X( X const & ); + X & operator=( X const & ); + +public: + + static int instances; + + explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>() ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared_noinit< X >( std::allocator<void>() ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_shared_test.cpp b/src/boost/libs/smart_ptr/test/allocate_shared_test.cpp new file mode 100644 index 00000000..31dcc7bb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_shared_test.cpp @@ -0,0 +1,223 @@ +// allocate_shared_test.cpp +// +// Copyright 2007-2009 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + // lack of this definition causes link errors on Comeau C++ + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + // lack of this definition causes link errors on MSVC + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>() ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 0 ); + } + + { + boost::shared_ptr< int > pi = boost::allocate_shared_noinit< int >( std::allocator<int>() ); + + BOOST_TEST( pi.get() != 0 ); + } + + { + boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>(), 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>() ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared_noinit< X >( std::allocator<void>() ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_aggregate_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_aggregate_test.cpp new file mode 100644 index 00000000..f1c558c2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_aggregate_test.cpp @@ -0,0 +1,84 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 46000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) && \ + !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +struct type { + int x; + int y; +}; + +int main() +{ + { + std::unique_ptr<type, + boost::alloc_deleter<type, creator<type> > > result = + boost::allocate_unique<type>(creator<type>(), { 1, 2 }); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 1); + BOOST_TEST(result->y == 2); + } + { + std::unique_ptr<const type, + boost::alloc_deleter<const type, creator<> > > result = + boost::allocate_unique<const type>(creator<>(), { 1, 2 }); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 1); + BOOST_TEST(result->y == 2); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_args_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_args_test.cpp new file mode 100644 index 00000000..aafbc3df --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_args_test.cpp @@ -0,0 +1,111 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 46000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type(int v1, int v2, int v3, int v4, int v5) + : sum_(v1 + v2 + v3 + v4 + v5) { + ++instances; + } + + ~type() { + --instances; + } + + int sum() const { + return sum_; + } + +private: + int sum_; + + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type, + boost::alloc_deleter<type, creator<type> > > result = + boost::allocate_unique<type>(creator<type>(), 1, 2, 3, 4, 5); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 15); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type, + boost::alloc_deleter<const type, creator<> > > result = + boost::allocate_unique<const type>(creator<>(), 1, 2, 3, 4, 5); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 15); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_array_construct_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_array_construct_test.cpp new file mode 100644 index 00000000..80b9f870 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_array_construct_test.cpp @@ -0,0 +1,166 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 48000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) && \ + !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +struct allow { }; + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + template<class U> + void construct(U* ptr) { + ::new(static_cast<void*>(ptr)) U(allow()); + } + + template<class U> + void destroy(U* ptr) { + ptr->~U(); + } + +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + explicit type(allow) { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<type[], + boost::alloc_deleter<type[], creator<type> > > result = + boost::allocate_unique<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[], + boost::alloc_deleter<type[3], creator<type> > > result = + boost::allocate_unique<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[][2], + boost::alloc_deleter<type[][2], creator<> > > result = + boost::allocate_unique<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[][2], + boost::alloc_deleter<type[2][2], creator<> > > result = + boost::allocate_unique<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[], + boost::alloc_deleter<const type[], creator<> > > result = + boost::allocate_unique<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[], + boost::alloc_deleter<const type[3], creator<> > > result = + boost::allocate_unique<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[][2], + boost::alloc_deleter<const type[][2], creator<> > > result = + boost::allocate_unique<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[][2], + boost::alloc_deleter<const type[2][2], creator<> > > result = + boost::allocate_unique<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_array_noinit_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_array_noinit_test.cpp new file mode 100644 index 00000000..7c9c122e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_array_noinit_test.cpp @@ -0,0 +1,228 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 48000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int[], + boost::alloc_deleter<int[], + boost::noinit_adaptor<creator<int> > > > result = + boost::allocate_unique_noinit<int[]>(creator<int>(), 3); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<int[], + boost::alloc_deleter<int[3], + boost::noinit_adaptor<creator<int> > > > result = + boost::allocate_unique_noinit<int[3]>(creator<int>()); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<int[][2], + boost::alloc_deleter<int[][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<int[][2], + boost::alloc_deleter<int[2][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<const int[], + boost::alloc_deleter<const int[], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const int[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<const int[], + boost::alloc_deleter<const int[3], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const int[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<const int[][2], + boost::alloc_deleter<const int[][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<const int[][2], + boost::alloc_deleter<const int[2][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<type[], + boost::alloc_deleter<type[], + boost::noinit_adaptor<creator<type> > > > result = + boost::allocate_unique_noinit<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[], + boost::alloc_deleter<type[3], + boost::noinit_adaptor<creator<type> > > > result = + boost::allocate_unique_noinit<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[][2], + boost::alloc_deleter<type[][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[][2], + boost::alloc_deleter<type[2][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[], + boost::alloc_deleter<const type[], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[], + boost::alloc_deleter<const type[3], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[][2], + boost::alloc_deleter<const type[][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[][2], + boost::alloc_deleter<const type[2][2], + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_array_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_array_test.cpp new file mode 100644 index 00000000..5901245b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_array_test.cpp @@ -0,0 +1,240 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 48000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int[], + boost::alloc_deleter<int[], creator<int> > > result = + boost::allocate_unique<int[]>(creator<int>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + std::unique_ptr<int[], + boost::alloc_deleter<int[3], creator<int> > > result = + boost::allocate_unique<int[3]>(creator<int>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + std::unique_ptr<int[][2], + boost::alloc_deleter<int[][2], creator<> > > result = + boost::allocate_unique<int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + std::unique_ptr<int[][2], + boost::alloc_deleter<int[2][2], creator<> > > result = + boost::allocate_unique<int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + std::unique_ptr<const int[], + boost::alloc_deleter<const int[], creator<> > > result = + boost::allocate_unique<const int[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + std::unique_ptr<const int[], + boost::alloc_deleter<const int[3], creator<> > > result = + boost::allocate_unique<const int[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + std::unique_ptr<const int[][2], + boost::alloc_deleter<const int[][2], creator<> > > result = + boost::allocate_unique<const int[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + std::unique_ptr<const int[][2], + boost::alloc_deleter<const int[2][2], creator<> > > result = + boost::allocate_unique<const int[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + std::unique_ptr<type[], + boost::alloc_deleter<type[], creator<type> > > result = + boost::allocate_unique<type[]>(creator<type>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[], + boost::alloc_deleter<type[3], creator<type> > > result = + boost::allocate_unique<type[3]>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[][2], + boost::alloc_deleter<type[][2], creator<> > > result = + boost::allocate_unique<type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<type[][2], + boost::alloc_deleter<type[2][2], creator<> > > result = + boost::allocate_unique<type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[], + boost::alloc_deleter<const type[], creator<> > > result = + boost::allocate_unique<const type[]>(creator<>(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[], + boost::alloc_deleter<const type[3], creator<> > > result = + boost::allocate_unique<const type[3]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[][2], + boost::alloc_deleter<const type[][2], creator<> > > result = + boost::allocate_unique<const type[][2]>(creator<>(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type[][2], + boost::alloc_deleter<const type[2][2], creator<> > > result = + boost::allocate_unique<const type[2][2]>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_array_throws_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_array_throws_test.cpp new file mode 100644 index 00000000..64670bb9 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_array_throws_test.cpp @@ -0,0 +1,132 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 48000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() { + if (instances == 5) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + try { + boost::allocate_unique<type[]>(creator<type>(), 6); + BOOST_ERROR("allocate_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique<type[][2]>(creator<type>(), 3); + BOOST_ERROR("allocate_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique<type[6]>(creator<>()); + BOOST_ERROR("allocate_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique<type[3][2]>(creator<>()); + BOOST_ERROR("allocate_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique_noinit<type[]>(creator<>(), 6); + BOOST_ERROR("allocate_unique_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique_noinit<type[][2]>(creator<>(), 3); + BOOST_ERROR("allocate_unique_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique_noinit<type[6]>(creator<>()); + BOOST_ERROR("allocate_unique_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique_noinit<type[3][2]>(creator<>()); + BOOST_ERROR("allocate_unique_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_array_value_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_array_value_test.cpp new file mode 100644 index 00000000..256b4924 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_array_value_test.cpp @@ -0,0 +1,98 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 48000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + { + std::unique_ptr<int[], + boost::alloc_deleter<int[], creator<int> > > result = + boost::allocate_unique<int[]>(creator<int>(), 4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + std::unique_ptr<int[], + boost::alloc_deleter<int[4], creator<int> > > result = + boost::allocate_unique<int[4]>(creator<int>(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + std::unique_ptr<const int[], + boost::alloc_deleter<const int[], creator<> > > result = + boost::allocate_unique<const int[]>(creator<>(), 4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + std::unique_ptr<const int[], + boost::alloc_deleter<const int[4], creator<> > > result = + boost::allocate_unique<const int[4]>(creator<>(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_arrays_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_arrays_test.cpp new file mode 100644 index 00000000..43354f07 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_arrays_test.cpp @@ -0,0 +1,99 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 48000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) && \ + !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + { + std::unique_ptr<int[][2], + boost::alloc_deleter<int[][2], creator<int> > > result = + boost::allocate_unique<int[][2]>(creator<int>(), 2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + std::unique_ptr<int[][2], + boost::alloc_deleter<int[2][2], creator<int> > > result = + boost::allocate_unique<int[2][2]>(creator<int>(), {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + std::unique_ptr<const int[][2], + boost::alloc_deleter<const int[][2], creator<> > > result = + boost::allocate_unique<const int[][2]>(creator<>(), 2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + std::unique_ptr<const int[][2], + boost::alloc_deleter<const int[2][2], creator<> > > result = + boost::allocate_unique<const int[2][2]>(creator<>(), {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_construct_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_construct_test.cpp new file mode 100644 index 00000000..5abba996 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_construct_test.cpp @@ -0,0 +1,109 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +struct allow { }; + +template<class T = void> +struct creator { + typedef T value_type; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + template<class U> + void construct(U* ptr) { + ::new(static_cast<void*>(ptr)) U(allow()); + } + + template<class U> + void destroy(U* ptr) { + ptr->~U(); + } + +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + explicit type(allow) { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<type, + boost::alloc_deleter<type, creator<type> > > result = + boost::allocate_unique<type>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type, + boost::alloc_deleter<const type, creator<> > > result = + boost::allocate_unique<const type>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_noinit_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_noinit_test.cpp new file mode 100644 index 00000000..d20c1065 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_noinit_test.cpp @@ -0,0 +1,126 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 46000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int, + boost::alloc_deleter<int, + boost::noinit_adaptor<creator<int> > > > result = + boost::allocate_unique_noinit<int>(creator<int>()); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<const int, + boost::alloc_deleter<const int, + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const int>(creator<>()); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<type, + boost::alloc_deleter<type, + boost::noinit_adaptor<creator<type> > > > result = + boost::allocate_unique_noinit<type>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + std::unique_ptr<const type, + boost::alloc_deleter<const type, + boost::noinit_adaptor<creator<> > > > result = + boost::allocate_unique_noinit<const type>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_test.cpp new file mode 100644 index 00000000..862bf97a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_test.cpp @@ -0,0 +1,115 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 46000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int, + boost::alloc_deleter<int, creator<int> > > result = + boost::allocate_unique<int>(creator<int>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 0); + } + { + std::unique_ptr<const int, + boost::alloc_deleter<const int, creator<> > > result = + boost::allocate_unique<const int>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type, + boost::alloc_deleter<type, creator<type> > > result = + boost::allocate_unique<type>(creator<type>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type, + boost::alloc_deleter<const type, creator<> > > result = + boost::allocate_unique<const type>(creator<>()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_throws_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_throws_test.cpp new file mode 100644 index 00000000..7d2d047e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_throws_test.cpp @@ -0,0 +1,96 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 46000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + static unsigned instances; + + type() { + if (instances == 0) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + try { + boost::allocate_unique<type>(creator<type>()); + BOOST_ERROR("allocate_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::allocate_unique<const type>(creator<>()); + BOOST_ERROR("allocate_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/allocate_unique_value_test.cpp b/src/boost/libs/smart_ptr/test/allocate_unique_value_test.cpp new file mode 100644 index 00000000..153e731b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/allocate_unique_value_test.cpp @@ -0,0 +1,103 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if (!defined(BOOST_LIBSTDCXX_VERSION) || \ + BOOST_LIBSTDCXX_VERSION >= 46000) && \ + !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/smart_ptr/allocate_unique.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T = void> +struct creator { + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +class type { +public: + type(int x, int y) + : value_(x + y) { } + + int sum() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + { + std::unique_ptr<int, + boost::alloc_deleter<int, creator<int> > > result = + boost::allocate_unique<int>(creator<int>(), 1); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 1); + } + { + std::unique_ptr<const int, + boost::alloc_deleter<const int, creator<> > > result = + boost::allocate_unique<const int>(creator<>(), 1); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 1); + } + { + std::unique_ptr<type, + boost::alloc_deleter<type, creator<type> > > result = + boost::allocate_unique<type>(creator<type>(), type(1, 2)); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->sum() == 3); + } + { + std::unique_ptr<const type, + boost::alloc_deleter<const type, creator<> > > result = + boost::allocate_unique<const type>(creator<>(), type(1, 2)); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->sum() == 3); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/array_fail_ap_spa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_a.cpp new file mode 100644 index 00000000..05248270 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + std::auto_ptr<X> px; + boost::shared_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_ap_spa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_c.cpp new file mode 100644 index 00000000..bc76316f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + std::auto_ptr<X> px; + boost::shared_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_ap_spa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_ma.cpp new file mode 100644 index 00000000..e26a548e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2; px2 = std::auto_ptr<X>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_ap_spa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_mc.cpp new file mode 100644 index 00000000..d53eeff6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_ap_spa_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2(( std::auto_ptr<X>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_array_access.cpp b/src/boost/libs/smart_ptr/test/array_fail_array_access.cpp new file mode 100644 index 00000000..4f4e3f8c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_array_access.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +template<class T> void f( T & /*t*/ ) +{ +} + +int main() +{ + boost::shared_ptr<X> px( new X ); + f( px[ 0 ] ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_dereference.cpp b/src/boost/libs/smart_ptr/test/array_fail_dereference.cpp new file mode 100644 index 00000000..081d5b40 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_dereference.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px( new X[ 1 ] ); + *px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_member_access.cpp b/src/boost/libs/smart_ptr/test/array_fail_member_access.cpp new file mode 100644 index 00000000..8051ad14 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_member_access.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ + int m; +}; + +int main() +{ + boost::shared_ptr<X[]> px( new X[ 1 ] ); + px->m = 0; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_spa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_a.cpp new file mode 100644 index 00000000..e1e2bb6c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px; + boost::shared_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_spa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_c.cpp new file mode 100644 index 00000000..c65df88c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px; + boost::shared_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_spa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_ma.cpp new file mode 100644 index 00000000..a1253a0b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2; px2 = boost::shared_ptr<X>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_spa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_mc.cpp new file mode 100644 index 00000000..75c014cb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_spa_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2(( boost::shared_ptr<X>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_a.cpp new file mode 100644 index 00000000..8b885126 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px; + boost::weak_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_c.cpp new file mode 100644 index 00000000..fc7cd5b1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px; + boost::weak_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_ma.cpp new file mode 100644 index 00000000..578e10b9 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2; px2 = boost::shared_ptr<X>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_mc.cpp new file mode 100644 index 00000000..ca62eaf6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_sp_wpa_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2(( boost::shared_ptr<X>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_sp_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_a.cpp new file mode 100644 index 00000000..4d6d3237 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px; + boost::shared_ptr<X> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_sp_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_c.cpp new file mode 100644 index 00000000..9015483e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px; + boost::shared_ptr<X> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_sp_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_ma.cpp new file mode 100644 index 00000000..65118872 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px2; px2 = boost::shared_ptr<X[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_sp_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_mc.cpp new file mode 100644 index 00000000..46f6e302 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_sp_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px2(( boost::shared_ptr<X[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_spa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_a.cpp new file mode 100644 index 00000000..edb248d7 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_a.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr<Y[]> px; + boost::shared_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_spa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_c.cpp new file mode 100644 index 00000000..a1833ee7 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_c.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr<Y[]> px; + boost::shared_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_spa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_ma.cpp new file mode 100644 index 00000000..8c816931 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_ma.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2; px2 = boost::shared_ptr<Y[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_spa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_mc.cpp new file mode 100644 index 00000000..606d9375 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_spa_mc.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2(( boost::shared_ptr<Y[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wp_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_a.cpp new file mode 100644 index 00000000..14c122e0 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px; + boost::weak_ptr<X> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wp_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_c.cpp new file mode 100644 index 00000000..9c22a5ba --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px; + boost::weak_ptr<X> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wp_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_ma.cpp new file mode 100644 index 00000000..49c1eb0b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X> px2; px2 = boost::shared_ptr<X[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wp_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_mc.cpp new file mode 100644 index 00000000..738946c6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wp_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X> px2(( boost::shared_ptr<X[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_a.cpp new file mode 100644 index 00000000..9c65f1ca --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_a.cpp @@ -0,0 +1,24 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr<Y[]> px; + boost::weak_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_c.cpp new file mode 100644 index 00000000..ff2ae227 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_c.cpp @@ -0,0 +1,24 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr<Y[]> px; + boost::weak_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_ma.cpp new file mode 100644 index 00000000..cb2725eb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_ma.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2; px2 = boost::shared_ptr<Y[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_mc.cpp new file mode 100644 index 00000000..9b07933e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_spa_wpa_mc.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2(( boost::shared_ptr<Y[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_up_spa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_up_spa_a.cpp new file mode 100644 index 00000000..8b9f2462 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_up_spa_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + std::unique_ptr<X> px; + boost::shared_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_up_spa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_up_spa_c.cpp new file mode 100644 index 00000000..1bbc5c0b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_up_spa_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + std::unique_ptr<X> px; + boost::shared_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_up_spa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_up_spa_ma.cpp new file mode 100644 index 00000000..fcd612d3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_up_spa_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2; px2 = std::unique_ptr<X>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_up_spa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_up_spa_mc.cpp new file mode 100644 index 00000000..6a20d6e9 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_up_spa_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X[]> px2(( std::unique_ptr<X>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_upa_sp_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_a.cpp new file mode 100644 index 00000000..4d87fdd4 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + std::unique_ptr<X[]> px; + boost::shared_ptr<X> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_upa_sp_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_c.cpp new file mode 100644 index 00000000..259fda05 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + std::unique_ptr<X[]> px; + boost::shared_ptr<X> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_upa_sp_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_ma.cpp new file mode 100644 index 00000000..1b2a2b2a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px2; px2 = std::unique_ptr<X[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_upa_sp_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_mc.cpp new file mode 100644 index 00000000..d314a01b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_upa_sp_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + boost::shared_ptr<X> px2(( std::unique_ptr<X[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_a.cpp new file mode 100644 index 00000000..ea82eb91 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X> px; + boost::weak_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_c.cpp new file mode 100644 index 00000000..9f5609cb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X> px; + boost::weak_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_ma.cpp new file mode 100644 index 00000000..79af4d7d --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2; px2 = boost::weak_ptr<X>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_mc.cpp new file mode 100644 index 00000000..18a9d8a1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wp_wpa_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2(( boost::weak_ptr<X>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_a.cpp new file mode 100644 index 00000000..19d0026a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px; + boost::weak_ptr<X> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_c.cpp new file mode 100644 index 00000000..d4b75dda --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px; + boost::weak_ptr<X> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_ma.cpp new file mode 100644 index 00000000..5c33c8b9 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X> px2; px2 = boost::weak_ptr<X[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_mc.cpp new file mode 100644 index 00000000..8375e6bd --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wp_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +int main() +{ + boost::weak_ptr<X> px2(( boost::weak_ptr<X[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_a.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_a.cpp new file mode 100644 index 00000000..29aeaa62 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_a.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr<Y[]> px; + boost::weak_ptr<X[]> px2; px2 = px; +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_c.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_c.cpp new file mode 100644 index 00000000..98a574e3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_c.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr<Y[]> px; + boost::weak_ptr<X[]> px2( px ); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_ma.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_ma.cpp new file mode 100644 index 00000000..eb638de1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_ma.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2; px2 = boost::weak_ptr<Y[]>(); +} diff --git a/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_mc.cpp b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_mc.cpp new file mode 100644 index 00000000..77d4f751 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/array_fail_wpa_wpa_mc.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 <boost/weak_ptr.hpp> + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr<X[]> px2(( boost::weak_ptr<Y[]>() )); +} diff --git a/src/boost/libs/smart_ptr/test/atomic_count_test.cpp b/src/boost/libs/smart_ptr/test/atomic_count_test.cpp new file mode 100644 index 00000000..ecc24c01 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/atomic_count_test.cpp @@ -0,0 +1,40 @@ +// +// atomic_count_test.cpp +// +// Copyright 2005 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 <boost/detail/atomic_count.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::detail::atomic_count n( 4 ); + + BOOST_TEST( n == 4L ); + + ++n; + + BOOST_TEST( n == 5L ); + BOOST_TEST( --n != 0L ); + + boost::detail::atomic_count m( 0 ); + + BOOST_TEST( m == 0 ); + + ++m; + + BOOST_TEST( m == 1 ); + + ++m; + + BOOST_TEST( m == 2 ); + BOOST_TEST( --m != 0 ); + BOOST_TEST( --m == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/atomic_count_test2.cpp b/src/boost/libs/smart_ptr/test/atomic_count_test2.cpp new file mode 100644 index 00000000..7e6dd973 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/atomic_count_test2.cpp @@ -0,0 +1,55 @@ +// +// atomic_count_test2.cpp +// +// Copyright 2009 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 <boost/detail/atomic_count.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::detail::atomic_count n( 4 ); + + BOOST_TEST( n == 4 ); + + BOOST_TEST( ++n == 5 ); + BOOST_TEST( ++n == 6 ); + + BOOST_TEST( n == 6 ); + + BOOST_TEST( --n == 5 ); + BOOST_TEST( --n == 4 ); + + BOOST_TEST( n == 4 ); + + boost::detail::atomic_count m( 0 ); + + BOOST_TEST( m == 0 ); + + BOOST_TEST( ++m == 1 ); + BOOST_TEST( ++m == 2 ); + + BOOST_TEST( m == 2 ); + + BOOST_TEST( --m == 1 ); + BOOST_TEST( --m == 0 ); + + BOOST_TEST( m == 0 ); + + BOOST_TEST( --m == -1 ); + BOOST_TEST( --m == -2 ); + + BOOST_TEST( m == -2 ); + + BOOST_TEST( ++m == -1 ); + BOOST_TEST( ++m == 0 ); + + BOOST_TEST( m == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/atomic_sp_constexpr_test.cpp b/src/boost/libs/smart_ptr/test/atomic_sp_constexpr_test.cpp new file mode 100644 index 00000000..ea373bf3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/atomic_sp_constexpr_test.cpp @@ -0,0 +1,77 @@ +// +// atomic_sp_constexpr_test.cpp +// +// Copyright 2017, 2018 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 <boost/config.hpp> +#include <boost/config/workaround.hpp> +#include <boost/config/pragma_message.hpp> +#include <boost/config/helper_macros.hpp> + +#if defined( BOOST_NO_CXX11_CONSTEXPR ) + +BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_CONSTEXPR") +int main() {} + +#elif BOOST_WORKAROUND( BOOST_MSVC, < 1930 ) + +// MSVC does not implement static initialization for constexpr constructors +BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_MSVC < 1930") +int main() {} + +#elif defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) + +// Clang only implements static initialization for constexpr in C++14 mode +BOOST_PRAGMA_MESSAGE("Skipping test due to __clang__ and BOOST_NO_CXX14_CONSTEXPR") +int main() {} + +#elif defined( _LIBCPP_VERSION ) && ( _LIBCPP_VERSION < 6000 ) + +// in libc++, atomic_flag has a non-constexpr constructor from bool +BOOST_PRAGMA_MESSAGE("Skipping test due to _LIBCPP_VERSION " BOOST_STRINGIZE(_LIBCPP_VERSION)) +int main() {} + +#elif defined( BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX ) + +BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX") +int main() {} + +#else + +#include <boost/smart_ptr/atomic_shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct X +{ +}; + +struct Z +{ + Z(); +}; + +static Z z; + +static boost::atomic_shared_ptr<X> p1; + +Z::Z() +{ + p1 = boost::shared_ptr<X>( new X ); +} + +int main() +{ + boost::shared_ptr<X> p2 = p1; + + BOOST_TEST( p2.get() != 0 ); + BOOST_TEST_EQ( p2.use_count(), 2 ); + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/atomic_sp_test.cpp b/src/boost/libs/smart_ptr/test/atomic_sp_test.cpp new file mode 100644 index 00000000..1b0b8398 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/atomic_sp_test.cpp @@ -0,0 +1,325 @@ +#include <boost/config.hpp> + +// atomic_sp_test.cpp +// +// Copyright 2008, 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 <boost/smart_ptr/atomic_shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/memory_order.hpp> + +// + +struct X +{ +}; + +#define BOOST_TEST_SP_EQ( p, q ) BOOST_TEST( p == q && !( p < q ) && !( q < p ) ) + +int main() +{ + // default constructor + + { + boost::atomic_shared_ptr<X> apx; + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( p2.get(), (X*)0 ); + BOOST_TEST_EQ( p2.use_count(), 0 ); + } + + // shared_ptr constructor + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // shared_ptr assignment + + { + boost::shared_ptr<X> px0( new X ); + boost::atomic_shared_ptr<X> apx( px0 ); + + boost::shared_ptr<X> px( new X ); + apx = px; + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // load, w/ mo + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> p2 = apx.load( boost::memory_order_acquire ); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // operator shared_ptr + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> p2 = apx; + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // store + + { + boost::shared_ptr<X> px0( new X ); + boost::atomic_shared_ptr<X> apx( px0 ); + + boost::shared_ptr<X> px( new X ); + apx.store( px ); + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // store, w/ mo + + { + boost::shared_ptr<X> px0( new X ); + boost::atomic_shared_ptr<X> apx( px0 ); + + boost::shared_ptr<X> px( new X ); + apx.store( px, boost::memory_order_release ); + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // exchange + + { + boost::shared_ptr<X> px0( new X ); + boost::atomic_shared_ptr<X> apx( px0 ); + + boost::shared_ptr<X> px( new X ); + boost::shared_ptr<X> p1 = apx.exchange( px ); + + BOOST_TEST_EQ( px0, p1 ); + BOOST_TEST_EQ( px0.use_count(), 2 ); + BOOST_TEST_EQ( p1.use_count(), 2 ); + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // exchange, w/ mo + + { + boost::shared_ptr<X> px0( new X ); + boost::atomic_shared_ptr<X> apx( px0 ); + + boost::shared_ptr<X> px( new X ); + boost::shared_ptr<X> p1 = apx.exchange( px, boost::memory_order_acq_rel ); + + BOOST_TEST_EQ( px0, p1 ); + BOOST_TEST_EQ( px0.use_count(), 2 ); + BOOST_TEST_EQ( p1.use_count(), 2 ); + + boost::shared_ptr<X> p2 = apx.load(); + + BOOST_TEST_EQ( px, p2 ); + BOOST_TEST_EQ( px.use_count(), 3 ); + BOOST_TEST_EQ( p2.use_count(), 3 ); + } + + // compare_exchange_weak + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> px2( new X ); + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_weak( cmp, px2 ); + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_weak( cmp, px2 ); + BOOST_TEST( r ); + BOOST_TEST_SP_EQ( apx.load(), px2 ); + } + + // compare_exchange_weak, w/ mo + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> px2( new X ); + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_weak( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_weak( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + BOOST_TEST( r ); + BOOST_TEST_SP_EQ( apx.load(), px2 ); + } + + // compare_exchange_weak, rv + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>() ); + + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>() ); + + BOOST_TEST( r ); + BOOST_TEST( apx.load().get() == 0 ); + BOOST_TEST( apx.load().use_count() == 0 ); + } + + // compare_exchange_weak, rv, w/ mo + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + + BOOST_TEST( r ); + BOOST_TEST( apx.load().get() == 0 ); + BOOST_TEST( apx.load().use_count() == 0 ); + } + + // compare_exchange_strong + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> px2( new X ); + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_strong( cmp, px2 ); + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_strong( cmp, px2 ); + BOOST_TEST( r ); + BOOST_TEST_SP_EQ( apx.load(), px2 ); + } + + // compare_exchange_strong, w/ mo + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> px2( new X ); + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_strong( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_strong( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + BOOST_TEST( r ); + BOOST_TEST_SP_EQ( apx.load(), px2 ); + } + + // compare_exchange_strong, rv + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>() ); + + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>() ); + + BOOST_TEST( r ); + BOOST_TEST( apx.load().get() == 0 ); + BOOST_TEST( apx.load().use_count() == 0 ); + } + + // compare_exchange_strong, rv, w/ mo + + { + boost::shared_ptr<X> px( new X ); + boost::atomic_shared_ptr<X> apx( px ); + + boost::shared_ptr<X> cmp; + + bool r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( apx.load(), px ); + BOOST_TEST_SP_EQ( cmp, px ); + + r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst ); + + BOOST_TEST( r ); + BOOST_TEST( apx.load().get() == 0 ); + BOOST_TEST( apx.load().use_count() == 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/auto_ptr_lv_fail.cpp b/src/boost/libs/smart_ptr/test/auto_ptr_lv_fail.cpp new file mode 100644 index 00000000..b86832e3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/auto_ptr_lv_fail.cpp @@ -0,0 +1,32 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// auto_ptr_lv_fail.cpp - a negative test for converting an auto_ptr to shared_ptr +// +// Copyright 2009 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 <boost/shared_ptr.hpp> +#include <memory> + +void f( boost::shared_ptr<int> ) +{ +} + +int main() +{ + std::auto_ptr<int> p; + f( p ); // must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/auto_ptr_rv_test.cpp b/src/boost/libs/smart_ptr/test/auto_ptr_rv_test.cpp new file mode 100644 index 00000000..5123439c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/auto_ptr_rv_test.cpp @@ -0,0 +1,123 @@ +#include <boost/config.hpp> + +// +// auto_ptr_rv_test.cpp +// +// Copyright (c) 2006 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 +// + +#if defined( BOOST_NO_AUTO_PTR ) + +int main() +{ +} + +#else + +#include <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + static std::auto_ptr<X> create() + { + return std::auto_ptr<X>( new X ); + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +long X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X const> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<void> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<void const> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_AUTO_PTR ) diff --git a/src/boost/libs/smart_ptr/test/cmake_subdir_test/CMakeLists.txt b/src/boost/libs/smart_ptr/test/cmake_subdir_test/CMakeLists.txt new file mode 100644 index 00000000..3e94729d --- /dev/null +++ b/src/boost/libs/smart_ptr/test/cmake_subdir_test/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright 2018, 2019 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 + +cmake_minimum_required(VERSION 3.5) + +project(cmake_subdir_test LANGUAGES CXX) + +add_subdirectory(../.. boostorg/smart_ptr) +add_subdirectory(../../../assert boostorg/assert) +add_subdirectory(../../../config boostorg/config) +add_subdirectory(../../../core boostorg/core) +add_subdirectory(../../../move boostorg/move) +add_subdirectory(../../../predef boostorg/predef) +add_subdirectory(../../../static_assert boostorg/static_assert) +add_subdirectory(../../../throw_exception boostorg/throw_exception) +add_subdirectory(../../../type_traits boostorg/type_traits) + +add_executable(quick ../quick.cpp) +target_link_libraries(quick Boost::smart_ptr Boost::core) + +enable_testing() +add_test(quick quick) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>) diff --git a/src/boost/libs/smart_ptr/test/collector_test.cpp b/src/boost/libs/smart_ptr/test/collector_test.cpp new file mode 100644 index 00000000..062b5578 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/collector_test.cpp @@ -0,0 +1,99 @@ +// +// collector_test.cpp +// +// Copyright (c) 2003 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 <boost/shared_ptr.hpp> +#include <vector> +#include <iostream> +#include <cstdlib> +#include <ctime> + +// sp_collector.cpp exported functions + +std::size_t find_unreachable_objects(bool report); +void free_unreachable_objects(); + +struct X +{ + void* fill[32]; + boost::shared_ptr<X> p; +}; + +void report() +{ + std::cout << "Calling find_unreachable_objects:\n"; + + std::clock_t t = std::clock(); + + std::size_t n = find_unreachable_objects(false); + + t = std::clock() - t; + + std::cout << n << " unreachable objects.\n"; + std::cout << " " << static_cast<double>(t) / CLOCKS_PER_SEC << " seconds.\n"; +} + +void free() +{ + std::cout << "Calling free_unreachable_objects:\n"; + + std::clock_t t = std::clock(); + + free_unreachable_objects(); + + t = std::clock() - t; + + std::cout << " " << static_cast<double>(t) / CLOCKS_PER_SEC << " seconds.\n"; +} + +int main() +{ + std::vector< boost::shared_ptr<X> > v1, v2; + + int const n = 256 * 1024; + + std::cout << "Filling v1 and v2\n"; + + for(int i = 0; i < n; ++i) + { + v1.push_back(boost::shared_ptr<X>(new X)); + v2.push_back(boost::shared_ptr<X>(new X)); + } + + report(); + + std::cout << "Creating the cycles\n"; + + for(int i = 0; i < n - 1; ++i) + { + v2[i]->p = v2[i+1]; + } + + v2[n-1]->p = v2[0]; + + report(); + + std::cout << "Resizing v2 to size of 1\n"; + + v2.resize(1); + report(); + + std::cout << "Clearing v2\n"; + + v2.clear(); + report(); + + std::cout << "Clearing v1\n"; + + v1.clear(); + report(); + + free(); + report(); +} diff --git a/src/boost/libs/smart_ptr/test/cpp11_pointer_cast_test.cpp b/src/boost/libs/smart_ptr/test/cpp11_pointer_cast_test.cpp new file mode 100644 index 00000000..a9361c31 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/cpp11_pointer_cast_test.cpp @@ -0,0 +1,224 @@ +// +// cpp11_pointer_cast_test.cpp - a test for boost/pointer_cast.hpp with std::shared_ptr and std::unique_ptr +// +// Copyright (c) 2016 Karolin Varner +// +// 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 <boost/pointer_cast.hpp> + +#include <boost/config.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/get_pointer.hpp> +#include <boost/shared_ptr.hpp> + +#include <memory> +#include <utility> +#include <functional> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) \ + || defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) \ + || defined( BOOST_NO_CXX11_HDR_UTILITY ) \ + || defined( BOOST_NO_CXX11_LAMBDAS ) \ + || defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +// We expect all the features or none of the features to be +// available, since we should be on C++11 +int main() { return 0; } + +#else + +namespace +{ + +// Let's create these inheritance relationship: +// +// base base2 +// | | +// derived +// | +// derived_derived +// + +class base +{ + public: + virtual ~base(){} + int filler [5]; +}; + +class base2 +{ +public: + + virtual ~base2(){} + int filler [5]; +}; + +class derived + : public base, public base2 +{ + int filler [5]; +}; + +class derived_derived + : public derived +{ + int filler [5]; +}; + +// And now some simple check functions + +#if !defined( BOOST_NO_RTTI ) + +template <class BasePtr> +bool check_dynamic_pointer_cast(const BasePtr &ptr) +{ + //Check that dynamic_pointer_cast versus dynamic_cast + return + //Correct cast with dynamic_pointer_cast + boost::get_pointer(boost::dynamic_pointer_cast<derived>(ptr)) == + //Correct cast with dynamic_cast + dynamic_cast<derived*>(boost::get_pointer(ptr)) + && + //Incorrect cast with dynamic_pointer_cast + boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>(ptr)) == + //Incorrect cast with dynamic_cast + dynamic_cast<derived_derived*>(boost::get_pointer(ptr)); +} + +#endif + +template <class BasePtr> +bool check_static_pointer_cast(const BasePtr &ptr) +{ + return + //Cast base -> derived -> base2 using static_pointer_cast + boost::get_pointer( + boost::static_pointer_cast<base2>( + boost::static_pointer_cast<derived>(ptr))) == + //Now the same with static_cast + static_cast<base2*>(static_cast<derived*>(boost::get_pointer(ptr))); +} + +template <class BasePtr> +bool check_const_pointer_cast(const BasePtr &ptr) +{ + return + //Unconst and const again using const_pointer_cast + boost::get_pointer( + boost::const_pointer_cast<const base> + (boost::const_pointer_cast<base>(ptr))) == + //Now the same with const_cast + const_cast<const base*>(const_cast<base*>(boost::get_pointer(ptr))); +} + +template <class BasePtr> +void check_all_copy_casts(const BasePtr &ptr) +{ +#if !defined( BOOST_NO_RTTI ) + BOOST_TEST( check_dynamic_pointer_cast( ptr ) ); +#endif + BOOST_TEST( check_static_pointer_cast( ptr ) ); + BOOST_TEST( check_const_pointer_cast( ptr ) ); +} + + +#if !defined( BOOST_NO_RTTI ) + +template <class BasePtr> +bool check_dynamic_moving_pointer_cast(std::function<BasePtr()> f) +{ + BasePtr smart1 = f(), smart2 = f(); + derived* expect1 = dynamic_cast<derived*>(boost::get_pointer(smart1)); + derived_derived* expect2 = dynamic_cast<derived_derived*>(boost::get_pointer(smart2)); + //Check that dynamic_pointer_cast versus dynamic_cast + return + //Correct cast with dynamic_pointer_cast + boost::get_pointer(boost::dynamic_pointer_cast<derived>( std::move(smart1) )) == expect1 + && + //Incorrect cast with dynamic_pointer_cast + boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>( std::move(smart2) )) == expect2; +} + +#endif + +template <class BasePtr> +bool check_static_moving_pointer_cast(std::function<BasePtr()> f) +{ + BasePtr smart = f(); + base2 *expect = static_cast<base2*>(static_cast<derived*>(boost::get_pointer(smart))); + + return + //Cast base -> derived -> base2 using static_pointer_cast + boost::get_pointer( + boost::static_pointer_cast<base2>( + boost::static_pointer_cast<derived>( std::move(smart) ))) == + //Now the same with static_cast + expect; +} + +template <class BasePtr> +bool check_const_moving_pointer_cast(std::function<BasePtr()> f) +{ + BasePtr smart = f(); + const base *expect = const_cast<const base*>(const_cast<base*>(boost::get_pointer(smart))); + return + //Unconst and const again using const_pointer_cast + boost::get_pointer( + boost::const_pointer_cast<const base> + (boost::const_pointer_cast<base>( std::move(smart) ))) == + //Now the same with const_cast + expect; +} + +template <class BasePtr> +void check_all_moving_casts(std::function<BasePtr()> f) { +#if !defined( BOOST_NO_RTTI ) + BOOST_TEST( check_dynamic_moving_pointer_cast( f ) ); +#endif + BOOST_TEST( check_static_moving_pointer_cast( f ) ); + BOOST_TEST( check_const_moving_pointer_cast( f ) ); +} + +} + +int main() +{ + + std::shared_ptr<base> std_shared(new derived); + boost::shared_ptr<base> boost_shared(new derived); + base *plain = boost_shared.get(); + + // plain & boost::shared_ptr moving pointer_cast checks; there + // is no specific handleing for those types at the moment; this + // test just makes sure they won't break when std::move() is used + // in generic code + + check_all_moving_casts<boost::shared_ptr<base>>([&boost_shared]() { + return boost_shared; + }); + + check_all_moving_casts<base*>([plain]() { + return plain; + }); + + // std::shared_ptr casts + + check_all_copy_casts(std_shared); + check_all_moving_casts<std::shared_ptr<base>>([&std_shared]() { + return std_shared; + }); + + // std::unique_ptr casts + + check_all_moving_casts<std::unique_ptr<base>>([]() { + return std::unique_ptr<base>(new derived); + }); + + return boost::report_errors(); +} +#endif diff --git a/src/boost/libs/smart_ptr/test/dll_test_lib.cpp b/src/boost/libs/smart_ptr/test/dll_test_lib.cpp new file mode 100644 index 00000000..e253fca2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/dll_test_lib.cpp @@ -0,0 +1,42 @@ +// Copyright 2018 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 <boost/shared_ptr.hpp> +#include <boost/make_shared.hpp> +#include <boost/config.hpp> +#include <memory> + +#if defined(DLL_TEST_DYN_LINK) +# define EXPORT BOOST_SYMBOL_EXPORT +#else +# define EXPORT +#endif + +EXPORT boost::shared_ptr<int> dll_test_41() +{ + return boost::shared_ptr<int>( new int( 41 ) ); +} + +EXPORT boost::shared_ptr<int> dll_test_42() +{ + return boost::make_shared<int>( 42 ); +} + +EXPORT boost::shared_ptr<int> dll_test_43() +{ + return boost::allocate_shared<int>( std::allocator<int>(), 43 ); +} + +EXPORT boost::shared_ptr<int[]> dll_test_44() +{ + return boost::make_shared<int[1]>( 44 ); +} + +EXPORT boost::shared_ptr<int[]> dll_test_45() +{ + return boost::allocate_shared<int[1]>( std::allocator<int>(), 45 ); +} diff --git a/src/boost/libs/smart_ptr/test/dll_test_main.cpp b/src/boost/libs/smart_ptr/test/dll_test_main.cpp new file mode 100644 index 00000000..2034f32f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/dll_test_main.cpp @@ -0,0 +1,45 @@ +// Copyright 2018 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 <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +boost::shared_ptr<int> dll_test_41(); +boost::shared_ptr<int> dll_test_42(); +boost::shared_ptr<int> dll_test_43(); +boost::shared_ptr<int[]> dll_test_44(); +boost::shared_ptr<int[]> dll_test_45(); + +int main() +{ + { + boost::shared_ptr<int> p = dll_test_41(); + BOOST_TEST_EQ( *p, 41 ); + } + + { + boost::shared_ptr<int> p = dll_test_42(); + BOOST_TEST_EQ( *p, 42 ); + } + + { + boost::shared_ptr<int> p = dll_test_43(); + BOOST_TEST_EQ( *p, 43 ); + } + + { + boost::shared_ptr<int[]> p = dll_test_44(); + BOOST_TEST_EQ( p[0], 44 ); + } + + { + boost::shared_ptr<int[]> p = dll_test_45(); + BOOST_TEST_EQ( p[0], 45 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/esft_regtest.cpp b/src/boost/libs/smart_ptr/test/esft_regtest.cpp new file mode 100644 index 00000000..baa5ef2c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/esft_regtest.cpp @@ -0,0 +1,226 @@ +// +// esft_regtest.cpp +// +// A regression test for enable_shared_from_this +// +// Copyright (c) 2008 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 <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/config.hpp> +#include <memory> +#include <string> + +class X: public boost::enable_shared_from_this< X > +{ +private: + + int destroyed_; + int deleted_; + int expected_; + +private: + + X( X const& ); + X& operator=( X const& ); + +public: + + static int instances; + +public: + + explicit X( int expected ): destroyed_( 0 ), deleted_( 0 ), expected_( expected ) + { + ++instances; + } + + ~X() + { + BOOST_TEST( deleted_ == expected_ ); + BOOST_TEST( destroyed_ == 0 ); + ++destroyed_; + --instances; + } + + typedef void (*deleter_type)( X* ); + + static void deleter( X * px ) + { + ++px->deleted_; + } + + static void deleter2( X * px ) + { + ++px->deleted_; + delete px; + } +}; + +int X::instances = 0; + +void test() +{ + BOOST_TEST( X::instances == 0 ); + + { + X x( 0 ); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + +#if !defined( BOOST_NO_AUTO_PTR ) + + { + std::auto_ptr<X> px( new X( 0 ) ); + BOOST_TEST( X::instances == 1 ); + } + +#endif + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> px( new X( 0 ) ); + BOOST_TEST( X::instances == 1 ); + + boost::weak_ptr<X> wp( px ); + BOOST_TEST( !wp.expired() ); + + px.reset(); + + BOOST_TEST( wp.expired() ); + } + + BOOST_TEST( X::instances == 0 ); + + { + X x( 1 ); + boost::shared_ptr<X> px( &x, X::deleter ); + BOOST_TEST( X::instances == 1 ); + + X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px ); + BOOST_TEST( pd != 0 && *pd == X::deleter ); + + boost::weak_ptr<X> wp( px ); + BOOST_TEST( !wp.expired() ); + + px.reset(); + + BOOST_TEST( wp.expired() ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> px( new X( 1 ), X::deleter2 ); + BOOST_TEST( X::instances == 1 ); + + X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px ); + BOOST_TEST( pd != 0 && *pd == X::deleter2 ); + + boost::weak_ptr<X> wp( px ); + BOOST_TEST( !wp.expired() ); + + px.reset(); + + BOOST_TEST( wp.expired() ); + } + + 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(); +} diff --git a/src/boost/libs/smart_ptr/test/esft_second_ptr_test.cpp b/src/boost/libs/smart_ptr/test/esft_second_ptr_test.cpp new file mode 100644 index 00000000..06006671 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/esft_second_ptr_test.cpp @@ -0,0 +1,51 @@ +// +// esft_second_ptr_test.cpp +// +// This test has been extracted from a real +// scenario that occurs in Boost.Python +// +// Copyright 2009 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 <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X: public boost::enable_shared_from_this<X> +{ +}; + +void null_deleter( void const* ) +{ +} + +int main() +{ + boost::shared_ptr<X> px( new X ); + + { + boost::shared_ptr<X> px2( px.get(), null_deleter ); + BOOST_TEST( px == px2 ); + } + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/esft_void_test.cpp b/src/boost/libs/smart_ptr/test/esft_void_test.cpp new file mode 100644 index 00000000..b28c669e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/esft_void_test.cpp @@ -0,0 +1,41 @@ +// +// esft_void_test.cpp +// +// Copyright 2009 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 <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X: public boost::enable_shared_from_this<X> +{ +}; + +int main() +{ + boost::shared_ptr< void const volatile > pv( new X ); + boost::shared_ptr< void > pv2 = boost::const_pointer_cast< void >( pv ); + boost::shared_ptr< X > px = boost::static_pointer_cast< X >( pv2 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_deleter_array_test.cpp b/src/boost/libs/smart_ptr/test/get_deleter_array_test.cpp new file mode 100644 index 00000000..f6d25000 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_deleter_array_test.cpp @@ -0,0 +1,95 @@ +// +// get_deleter_array_test.cpp +// +// Copyright (c) 2002, 2011 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 <boost/shared_array.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct deleter +{ + int data; + + deleter(): data(0) + { + } + + void operator()(void *) + { + BOOST_TEST(data == 17041); + } +}; + +struct deleter2 +{ +}; + +struct X +{ +}; + +int main() +{ + { + boost::shared_array<X> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::shared_array<X> p(new X[1]); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + X x[1]; + boost::shared_array<X> p(x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_deleter_array_test2.cpp b/src/boost/libs/smart_ptr/test/get_deleter_array_test2.cpp new file mode 100644 index 00000000..473aac21 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_deleter_array_test2.cpp @@ -0,0 +1,151 @@ +// +// get_deleter_array_test2.cpp +// +// Copyright 2002, 2011, 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 <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ + int data; + + deleter(): data(0) + { + } + + void operator()(void *) + { + BOOST_TEST(data == 17041); + } +}; + +struct deleter2 +{ +}; + +struct X +{ +}; + +int main() +{ + { + boost::shared_ptr<X[]> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::shared_ptr<X[1]> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::shared_ptr<X[]> p(new X[1]); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::shared_ptr<X[1]> p(new X[1]); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + X x[1]; + boost::shared_ptr<X[]> p(x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + { + X x[1]; + boost::shared_ptr<X[1]> p(x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_deleter_array_test3.cpp b/src/boost/libs/smart_ptr/test/get_deleter_array_test3.cpp new file mode 100644 index 00000000..7a33eeac --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_deleter_array_test3.cpp @@ -0,0 +1,62 @@ +// +// get_deleter_test3.cpp +// +// Copyright 2002, 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 <boost/shared_ptr.hpp> +#include <boost/make_shared.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ +}; + +struct deleter2; + +struct X +{ +}; + +int main() +{ + { + boost::shared_ptr<X[]> p = boost::make_shared<X[]>( 1 ); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::shared_ptr<X[1]> p = boost::make_shared<X[1]>(); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + return boost::report_errors(); +} + +struct deleter2 +{ +}; diff --git a/src/boost/libs/smart_ptr/test/get_deleter_test.cpp b/src/boost/libs/smart_ptr/test/get_deleter_test.cpp new file mode 100644 index 00000000..8bed3793 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_deleter_test.cpp @@ -0,0 +1,95 @@ +// +// get_deleter_test.cpp +// +// Copyright (c) 2002 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct deleter +{ + int data; + + deleter(): data(0) + { + } + + void operator()(void *) + { + BOOST_TEST(data == 17041); + } +}; + +struct deleter2 +{ +}; + +struct X +{ +}; + +int main() +{ + { + boost::shared_ptr<X> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::shared_ptr<X> p(new X); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + X x; + boost::shared_ptr<X> p(&x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_deleter_test2.cpp b/src/boost/libs/smart_ptr/test/get_deleter_test2.cpp new file mode 100644 index 00000000..4ddc65e5 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_deleter_test2.cpp @@ -0,0 +1,37 @@ +// +// get_deleter_test2.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 <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter; + +struct X +{ +}; + +static void test_get_deleter( boost::shared_ptr<X> const & p ) +{ + BOOST_TEST( boost::get_deleter<deleter>( p ) != 0 ); +} + +struct deleter +{ + void operator()( X const * p ) { delete p; } +}; + +int main() +{ + boost::shared_ptr<X> p( new X, deleter() ); + + test_get_deleter( p ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_deleter_test3.cpp b/src/boost/libs/smart_ptr/test/get_deleter_test3.cpp new file mode 100644 index 00000000..c42643b3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_deleter_test3.cpp @@ -0,0 +1,47 @@ +// +// get_deleter_test3.cpp +// +// Copyright 2002, 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 <boost/shared_ptr.hpp> +#include <boost/make_shared.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ +}; + +struct deleter2; + +struct X +{ +}; + +int main() +{ + { + boost::shared_ptr<X> p = boost::make_shared<X>(); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + return boost::report_errors(); +} + +struct deleter2 +{ +}; diff --git a/src/boost/libs/smart_ptr/test/get_local_deleter_array_test.cpp b/src/boost/libs/smart_ptr/test/get_local_deleter_array_test.cpp new file mode 100644 index 00000000..3a8351bc --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_local_deleter_array_test.cpp @@ -0,0 +1,151 @@ +// +// get_local_deleter_array_test2.cpp +// +// Copyright 2002, 2011, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ + int data; + + deleter(): data(0) + { + } + + void operator()(void *) + { + BOOST_TEST(data == 17041); + } +}; + +struct deleter2 +{ +}; + +struct X +{ +}; + +int main() +{ + { + boost::local_shared_ptr<X[]> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::local_shared_ptr<X[1]> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::local_shared_ptr<X[]> p(new X[1]); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::local_shared_ptr<X[1]> p(new X[1]); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + X x[1]; + boost::local_shared_ptr<X[]> p(x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + { + X x[1]; + boost::local_shared_ptr<X[1]> p(x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_local_deleter_array_test2.cpp b/src/boost/libs/smart_ptr/test/get_local_deleter_array_test2.cpp new file mode 100644 index 00000000..999fffe7 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_local_deleter_array_test2.cpp @@ -0,0 +1,74 @@ +// +// get_local_deleter_test2.cpp +// +// Copyright 2002, 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ +}; + +struct deleter2; + +struct X +{ +}; + +int main() +{ + { + boost::local_shared_ptr<X[]> p = boost::make_local_shared<X[]>( 1 ); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::local_shared_ptr<X[1]> p = boost::make_local_shared<X[1]>(); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + return boost::report_errors(); +} + +struct deleter2 +{ +}; + +#endif diff --git a/src/boost/libs/smart_ptr/test/get_local_deleter_test.cpp b/src/boost/libs/smart_ptr/test/get_local_deleter_test.cpp new file mode 100644 index 00000000..8c45af72 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_local_deleter_test.cpp @@ -0,0 +1,95 @@ +// +// get_local_deleter_test.cpp +// +// Copyright 2002, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ + int data; + + deleter(): data(0) + { + } + + void operator()(void *) + { + BOOST_TEST(data == 17041); + } +}; + +struct deleter2 +{ +}; + +struct X +{ +}; + +int main() +{ + { + boost::local_shared_ptr<X> p; + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + boost::local_shared_ptr<X> p(new X); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + { + X x; + boost::local_shared_ptr<X> p(&x, deleter()); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + + deleter * q = boost::get_deleter<deleter>(p); + + BOOST_TEST(q != 0); + BOOST_TEST(q->data == 0); + + q->data = 17041; + + deleter const * r = boost::get_deleter<deleter const>(p); + + BOOST_TEST(r == q); + BOOST_TEST(r->data == 17041); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_local_deleter_test2.cpp b/src/boost/libs/smart_ptr/test/get_local_deleter_test2.cpp new file mode 100644 index 00000000..a0023a96 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_local_deleter_test2.cpp @@ -0,0 +1,43 @@ +// +// get_local_deleter_test2.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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter; + +struct X +{ +}; + +static void test_lsp_get_deleter( boost::local_shared_ptr<X> const & p ) +{ + BOOST_TEST( boost::get_deleter<deleter>( p ) != 0 ); +} + +static void test_sp_get_deleter( boost::shared_ptr<X> const & p ) +{ + BOOST_TEST( boost::get_deleter<deleter>( p ) != 0 ); +} + +struct deleter +{ + void operator()( X const * p ) { delete p; } +}; + +int main() +{ + boost::local_shared_ptr<X> p( new X, deleter() ); + + test_lsp_get_deleter( p ); + test_sp_get_deleter( p ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/get_local_deleter_test3.cpp b/src/boost/libs/smart_ptr/test/get_local_deleter_test3.cpp new file mode 100644 index 00000000..655c7fc3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/get_local_deleter_test3.cpp @@ -0,0 +1,59 @@ +// +// get_local_deleter_test3.cpp +// +// Copyright 2002, 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/core/lightweight_test.hpp> + +struct deleter +{ +}; + +struct deleter2; + +struct X +{ +}; + +int main() +{ + { + boost::local_shared_ptr<X> p = boost::make_local_shared<X>(); + + BOOST_TEST(boost::get_deleter<void>(p) == 0); + BOOST_TEST(boost::get_deleter<void const>(p) == 0); + BOOST_TEST(boost::get_deleter<int>(p) == 0); + BOOST_TEST(boost::get_deleter<int const>(p) == 0); + BOOST_TEST(boost::get_deleter<X>(p) == 0); + BOOST_TEST(boost::get_deleter<X const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter const>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2>(p) == 0); + BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0); + } + + return boost::report_errors(); +} + +struct deleter2 +{ +}; + +#endif diff --git a/src/boost/libs/smart_ptr/test/intrusive_ptr_move_test.cpp b/src/boost/libs/smart_ptr/test/intrusive_ptr_move_test.cpp new file mode 100644 index 00000000..9079c880 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/intrusive_ptr_move_test.cpp @@ -0,0 +1,274 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#pragma warning(disable: 4355) // 'this' : used in base member initializer list +#pragma warning(disable: 4511) // copy constructor could not be generated +#pragma warning(disable: 4512) // assignment operator could not be generated + +#if (BOOST_MSVC >= 1310) +#pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +// +// intrusive_ptr_move_test.cpp +// +// Copyright (c) 2002-2005 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 <boost/detail/lightweight_test.hpp> +#include <boost/intrusive_ptr.hpp> +#include <boost/detail/atomic_count.hpp> +#include <boost/config.hpp> +#include <utility> + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +namespace N +{ + +class base +{ +private: + + mutable boost::detail::atomic_count use_count_; + + base(base const &); + base & operator=(base const &); + +protected: + + base(): use_count_(0) + { + ++instances; + } + + virtual ~base() + { + --instances; + } + +public: + + static long instances; + + long use_count() const + { + return use_count_; + } + +#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + + inline friend void intrusive_ptr_add_ref(base const * p) + { + ++p->use_count_; + } + + inline friend void intrusive_ptr_release(base const * p) + { + if(--p->use_count_ == 0) delete p; + } + +#else + + void add_ref() const + { + ++use_count_; + } + + void release() const + { + if(--use_count_ == 0) delete this; + } + +#endif +}; + +long base::instances = 0; + +} // namespace N + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + +namespace boost +{ + +inline void intrusive_ptr_add_ref(N::base const * p) +{ + p->add_ref(); +} + +inline void intrusive_ptr_release(N::base const * p) +{ + p->release(); +} + +} // namespace boost + +#endif + +// + +struct X: public virtual N::base +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> p( new X ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> p2( std::move( p ) ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr<Y> p( new Y ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> p2( std::move( p ) ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr<X> p( new X ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> p2; + p2 = std::move( p ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr<X> p( new X ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> p2( new X ); + BOOST_TEST( N::base::instances == 2 ); + p2 = std::move( p ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr<Y> p( new Y ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> p2; + p2 = std::move( p ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr<Y> p( new Y ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> p2( new X ); + BOOST_TEST( N::base::instances == 2 ); + p2 = std::move( p ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr<X> px( new Y ); + + X * px2 = px.get(); + + boost::intrusive_ptr<Y> py = boost::static_pointer_cast<Y>( std::move( px ) ); + BOOST_TEST( py.get() == px2 ); + BOOST_TEST( px.get() == 0 ); + BOOST_TEST( py->use_count() == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X const> px( new X ); + + X const * px2 = px.get(); + + boost::intrusive_ptr<X> px3 = boost::const_pointer_cast<X>( std::move( px ) ); + BOOST_TEST( px3.get() == px2 ); + BOOST_TEST( px.get() == 0 ); + BOOST_TEST( px3->use_count() == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new Y ); + + X * px2 = px.get(); + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( std::move( px ) ); + BOOST_TEST( py.get() == px2 ); + BOOST_TEST( px.get() == 0 ); + BOOST_TEST( py->use_count() == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + + X * px2 = px.get(); + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( std::move( px ) ); + BOOST_TEST( py.get() == 0 ); + BOOST_TEST( px.get() == px2 ); + BOOST_TEST( px->use_count() == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + return boost::report_errors(); +} + +#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/intrusive_ptr_test.cpp b/src/boost/libs/smart_ptr/test/intrusive_ptr_test.cpp new file mode 100644 index 00000000..475428f2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/intrusive_ptr_test.cpp @@ -0,0 +1,1108 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#pragma warning(disable: 4355) // 'this' : used in base member initializer list +#pragma warning(disable: 4511) // copy constructor could not be generated +#pragma warning(disable: 4512) // assignment operator could not be generated + +#if (BOOST_MSVC >= 1310) +#pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +// +// intrusive_ptr_test.cpp +// +// Copyright (c) 2002-2005 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 <boost/detail/lightweight_test.hpp> +#include <boost/intrusive_ptr.hpp> +#include <boost/detail/atomic_count.hpp> +#include <boost/config.hpp> +#include <algorithm> +#include <functional> + +// + +namespace N +{ + +class base +{ +private: + + mutable boost::detail::atomic_count use_count_; + + base(base const &); + base & operator=(base const &); + +protected: + + base(): use_count_(0) + { + ++instances; + } + + virtual ~base() + { + --instances; + } + +public: + + static long instances; + + long use_count() const + { + return use_count_; + } + +#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + + inline friend void intrusive_ptr_add_ref(base const * p) + { + ++p->use_count_; + } + + inline friend void intrusive_ptr_release(base const * p) + { + if(--p->use_count_ == 0) delete p; + } + +#else + + void add_ref() const + { + ++use_count_; + } + + void release() const + { + if(--use_count_ == 0) delete this; + } + +#endif +}; + +long base::instances = 0; + +} // namespace N + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + +namespace boost +{ + +inline void intrusive_ptr_add_ref(N::base const * p) +{ + p->add_ref(); +} + +inline void intrusive_ptr_release(N::base const * p) +{ + p->release(); +} + +} // namespace boost + +#endif + +// + +struct X: public virtual N::base +{ +}; + +struct Y: public X +{ +}; + +// + +namespace n_element_type +{ + +void f(X &) +{ +} + +void test() +{ + typedef boost::intrusive_ptr<X>::element_type T; + T t; + f(t); +} + +} // namespace n_element_type + +namespace n_constructors +{ + +void default_constructor() +{ + boost::intrusive_ptr<X> px; + BOOST_TEST(px.get() == 0); +} + +void pointer_constructor() +{ + { + boost::intrusive_ptr<X> px(0); + BOOST_TEST(px.get() == 0); + } + + { + boost::intrusive_ptr<X> px(0, false); + BOOST_TEST(px.get() == 0); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + X * p = new X; + BOOST_TEST(p->use_count() == 0); + + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> px(p); + BOOST_TEST(px.get() == p); + BOOST_TEST(px->use_count() == 1); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + X * p = new X; + BOOST_TEST(p->use_count() == 0); + + BOOST_TEST( N::base::instances == 1 ); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::intrusive_ptr_add_ref; +#endif + intrusive_ptr_add_ref(p); + BOOST_TEST(p->use_count() == 1); + + boost::intrusive_ptr<X> px(p, false); + BOOST_TEST(px.get() == p); + BOOST_TEST(px->use_count() == 1); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +void copy_constructor() +{ + { + boost::intrusive_ptr<X> px; + boost::intrusive_ptr<X> px2(px); + BOOST_TEST(px2.get() == px.get()); + } + + { + boost::intrusive_ptr<Y> py; + boost::intrusive_ptr<X> px(py); + BOOST_TEST(px.get() == py.get()); + } + + { + boost::intrusive_ptr<X> px(0); + boost::intrusive_ptr<X> px2(px); + BOOST_TEST(px2.get() == px.get()); + } + + { + boost::intrusive_ptr<Y> py(0); + boost::intrusive_ptr<X> px(py); + BOOST_TEST(px.get() == py.get()); + } + + { + boost::intrusive_ptr<X> px(0, false); + boost::intrusive_ptr<X> px2(px); + BOOST_TEST(px2.get() == px.get()); + } + + { + boost::intrusive_ptr<Y> py(0, false); + boost::intrusive_ptr<X> px(py); + BOOST_TEST(px.get() == py.get()); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px(new X); + boost::intrusive_ptr<X> px2(px); + BOOST_TEST( px2.get() == px.get() ); + + BOOST_TEST( N::base::instances == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<Y> py(new Y); + boost::intrusive_ptr<X> px(py); + BOOST_TEST( px.get() == py.get() ); + + BOOST_TEST( N::base::instances == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +void test() +{ + default_constructor(); + pointer_constructor(); + copy_constructor(); +} + +} // namespace n_constructors + +namespace n_destructor +{ + +void test() +{ + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px(new X); + BOOST_TEST(px->use_count() == 1); + + BOOST_TEST( N::base::instances == 1 ); + + { + boost::intrusive_ptr<X> px2(px); + BOOST_TEST(px->use_count() == 2); + } + + BOOST_TEST(px->use_count() == 1); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +} // namespace n_destructor + +namespace n_assignment +{ + +void copy_assignment() +{ + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> p1; + + p1 = p1; + + BOOST_TEST(p1 == p1); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::intrusive_ptr<X> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::intrusive_ptr<X> p3(p1); + + p1 = p3; + + BOOST_TEST(p1 == p3); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + BOOST_TEST(N::base::instances == 0); + + boost::intrusive_ptr<X> p4(new X); + + BOOST_TEST(N::base::instances == 1); + + p1 = p4; + + BOOST_TEST(N::base::instances == 1); + + BOOST_TEST(p1 == p4); + + BOOST_TEST(p1->use_count() == 2); + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(N::base::instances == 1); + + p4 = p3; + + BOOST_TEST(p4 == p3); + BOOST_TEST(N::base::instances == 0); + } +} + +void conversion_assignment() +{ + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> p1; + + boost::intrusive_ptr<Y> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + BOOST_TEST(N::base::instances == 0); + + boost::intrusive_ptr<Y> p4(new Y); + + BOOST_TEST(N::base::instances == 1); + BOOST_TEST(p4->use_count() == 1); + + boost::intrusive_ptr<X> p5(p4); + BOOST_TEST(p4->use_count() == 2); + + p1 = p4; + + BOOST_TEST(N::base::instances == 1); + + BOOST_TEST(p1 == p4); + + BOOST_TEST(p1->use_count() == 3); + BOOST_TEST(p4->use_count() == 3); + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(N::base::instances == 1); + BOOST_TEST(p4->use_count() == 2); + + p4 = p2; + p5 = p2; + + BOOST_TEST(p4 == p2); + BOOST_TEST(N::base::instances == 0); + } +} + +void pointer_assignment() +{ + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> p1; + + p1 = p1.get(); + + BOOST_TEST(p1 == p1); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::intrusive_ptr<X> p2; + + p1 = p2.get(); + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::intrusive_ptr<X> p3(p1); + + p1 = p3.get(); + + BOOST_TEST(p1 == p3); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + BOOST_TEST(N::base::instances == 0); + + boost::intrusive_ptr<X> p4(new X); + + BOOST_TEST(N::base::instances == 1); + + p1 = p4.get(); + + BOOST_TEST(N::base::instances == 1); + + BOOST_TEST(p1 == p4); + + BOOST_TEST(p1->use_count() == 2); + + p1 = p2.get(); + + BOOST_TEST(p1 == p2); + BOOST_TEST(N::base::instances == 1); + + p4 = p3.get(); + + BOOST_TEST(p4 == p3); + BOOST_TEST(N::base::instances == 0); + } + + { + boost::intrusive_ptr<X> p1; + + boost::intrusive_ptr<Y> p2; + + p1 = p2.get(); + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + BOOST_TEST(N::base::instances == 0); + + boost::intrusive_ptr<Y> p4(new Y); + + BOOST_TEST(N::base::instances == 1); + BOOST_TEST(p4->use_count() == 1); + + boost::intrusive_ptr<X> p5(p4); + BOOST_TEST(p4->use_count() == 2); + + p1 = p4.get(); + + BOOST_TEST(N::base::instances == 1); + + BOOST_TEST(p1 == p4); + + BOOST_TEST(p1->use_count() == 3); + BOOST_TEST(p4->use_count() == 3); + + p1 = p2.get(); + + BOOST_TEST(p1 == p2); + BOOST_TEST(N::base::instances == 1); + BOOST_TEST(p4->use_count() == 2); + + p4 = p2.get(); + p5 = p2.get(); + + BOOST_TEST(p4 == p2); + BOOST_TEST(N::base::instances == 0); + } +} + +void test() +{ + copy_assignment(); + conversion_assignment(); + pointer_assignment(); +} + +} // namespace n_assignment + +namespace n_reset +{ + +void test() +{ + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px; + BOOST_TEST( px.get() == 0 ); + + px.reset(); + BOOST_TEST( px.get() == 0 ); + + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + BOOST_TEST( N::base::instances == 1 ); + + px.reset( p ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + + px.reset(); + BOOST_TEST( px.get() == 0 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + BOOST_TEST( N::base::instances == 1 ); + + px.reset( 0 ); + BOOST_TEST( px.get() == 0 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + BOOST_TEST( N::base::instances == 1 ); + + px.reset( 0, false ); + BOOST_TEST( px.get() == 0 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + BOOST_TEST( N::base::instances == 1 ); + + px.reset( 0, true ); + BOOST_TEST( px.get() == 0 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr<X> px; + BOOST_TEST( px.get() == 0 ); + + px.reset( p, true ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + + BOOST_TEST( N::base::instances == 1 ); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::intrusive_ptr_add_ref; +#endif + intrusive_ptr_add_ref( p ); + BOOST_TEST( p->use_count() == 1 ); + + boost::intrusive_ptr<X> px; + BOOST_TEST( px.get() == 0 ); + + px.reset( p, false ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + BOOST_TEST( px.get() != 0 ); + BOOST_TEST( px->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 1 ); + + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + + BOOST_TEST( N::base::instances == 2 ); + + px.reset( p ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + BOOST_TEST( px.get() != 0 ); + BOOST_TEST( px->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 1 ); + + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + + BOOST_TEST( N::base::instances == 2 ); + + px.reset( p, true ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px( new X ); + BOOST_TEST( px.get() != 0 ); + BOOST_TEST( px->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 1 ); + + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::intrusive_ptr_add_ref; +#endif + intrusive_ptr_add_ref( p ); + BOOST_TEST( p->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 2 ); + + px.reset( p, false ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + + BOOST_TEST( N::base::instances == 1 ); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +} // namespace n_reset + +namespace n_access +{ + +void test() +{ + { + boost::intrusive_ptr<X> px; + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + boost::intrusive_ptr<X> px(0); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + boost::intrusive_ptr<X> px(new X); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(&*px == px.get()); + BOOST_TEST(px.operator ->() == px.get()); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + boost::intrusive_ptr<X> px; + X* detached = px.detach(); + BOOST_TEST( px.get() == 0 ); + BOOST_TEST( detached == 0 ); + } + + { + X * p = new X; + BOOST_TEST( p->use_count() == 0 ); + + boost::intrusive_ptr<X> px( p ); + BOOST_TEST( px.get() == p ); + BOOST_TEST( px->use_count() == 1 ); + + X * detached = px.detach(); + BOOST_TEST( px.get() == 0 ); + + BOOST_TEST( detached == p ); + BOOST_TEST( detached->use_count() == 1 ); + + delete detached; + } +} + +} // namespace n_access + +namespace n_swap +{ + +void test() +{ + { + boost::intrusive_ptr<X> px; + boost::intrusive_ptr<X> px2; + + px.swap(px2); + + BOOST_TEST(px.get() == 0); + BOOST_TEST(px2.get() == 0); + + using std::swap; + swap(px, px2); + + BOOST_TEST(px.get() == 0); + BOOST_TEST(px2.get() == 0); + } + + { + X * p = new X; + boost::intrusive_ptr<X> px; + boost::intrusive_ptr<X> px2(p); + boost::intrusive_ptr<X> px3(px2); + + px.swap(px2); + + BOOST_TEST(px.get() == p); + BOOST_TEST(px->use_count() == 2); + BOOST_TEST(px2.get() == 0); + BOOST_TEST(px3.get() == p); + BOOST_TEST(px3->use_count() == 2); + + using std::swap; + swap(px, px2); + + BOOST_TEST(px.get() == 0); + BOOST_TEST(px2.get() == p); + BOOST_TEST(px2->use_count() == 2); + BOOST_TEST(px3.get() == p); + BOOST_TEST(px3->use_count() == 2); + } + + { + X * p1 = new X; + X * p2 = new X; + boost::intrusive_ptr<X> px(p1); + boost::intrusive_ptr<X> px2(p2); + boost::intrusive_ptr<X> px3(px2); + + px.swap(px2); + + BOOST_TEST(px.get() == p2); + BOOST_TEST(px->use_count() == 2); + BOOST_TEST(px2.get() == p1); + BOOST_TEST(px2->use_count() == 1); + BOOST_TEST(px3.get() == p2); + BOOST_TEST(px3->use_count() == 2); + + using std::swap; + swap(px, px2); + + BOOST_TEST(px.get() == p1); + BOOST_TEST(px->use_count() == 1); + BOOST_TEST(px2.get() == p2); + BOOST_TEST(px2->use_count() == 2); + BOOST_TEST(px3.get() == p2); + BOOST_TEST(px3->use_count() == 2); + } +} + +} // namespace n_swap + +namespace n_comparison +{ + +template<class T, class U> void test2(boost::intrusive_ptr<T> const & p, boost::intrusive_ptr<U> const & q) +{ + BOOST_TEST((p == q) == (p.get() == q.get())); + BOOST_TEST((p != q) == (p.get() != q.get())); +} + +template<class T> void test3(boost::intrusive_ptr<T> const & p, boost::intrusive_ptr<T> const & q) +{ + BOOST_TEST((p == q) == (p.get() == q.get())); + BOOST_TEST((p.get() == q) == (p.get() == q.get())); + BOOST_TEST((p == q.get()) == (p.get() == q.get())); + BOOST_TEST((p != q) == (p.get() != q.get())); + BOOST_TEST((p.get() != q) == (p.get() != q.get())); + BOOST_TEST((p != q.get()) == (p.get() != q.get())); + + // 'less' moved here as a g++ 2.9x parse error workaround + std::less<T*> less; + BOOST_TEST((p < q) == less(p.get(), q.get())); +} + +void test() +{ + { + boost::intrusive_ptr<X> px; + test3(px, px); + + boost::intrusive_ptr<X> px2; + test3(px, px2); + + boost::intrusive_ptr<X> px3(px); + test3(px3, px3); + test3(px, px3); + } + + { + boost::intrusive_ptr<X> px; + + boost::intrusive_ptr<X> px2(new X); + test3(px, px2); + test3(px2, px2); + + boost::intrusive_ptr<X> px3(new X); + test3(px2, px3); + + boost::intrusive_ptr<X> px4(px2); + test3(px2, px4); + test3(px4, px4); + } + + { + boost::intrusive_ptr<X> px(new X); + + boost::intrusive_ptr<Y> py(new Y); + test2(px, py); + + boost::intrusive_ptr<X> px2(py); + test2(px2, py); + test3(px, px2); + test3(px2, px2); + } +} + +} // namespace n_comparison + +namespace n_static_cast +{ + +void test() +{ + { + boost::intrusive_ptr<X> px(new Y); + + boost::intrusive_ptr<Y> py = boost::static_pointer_cast<Y>(px); + BOOST_TEST(px.get() == py.get()); + BOOST_TEST(px->use_count() == 2); + BOOST_TEST(py->use_count() == 2); + + boost::intrusive_ptr<X> px2(py); + BOOST_TEST(px2.get() == px.get()); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<Y> py = boost::static_pointer_cast<Y>( boost::intrusive_ptr<X>(new Y) ); + BOOST_TEST(py.get() != 0); + BOOST_TEST(py->use_count() == 1); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +} // namespace n_static_cast + +namespace n_const_cast +{ + +void test() +{ + { + boost::intrusive_ptr<X const> px; + + boost::intrusive_ptr<X> px2 = boost::const_pointer_cast<X>(px); + BOOST_TEST(px2.get() == 0); + } + + { + boost::intrusive_ptr<X> px2 = boost::const_pointer_cast<X>( boost::intrusive_ptr<X const>() ); + BOOST_TEST(px2.get() == 0); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X const> px(new X); + + boost::intrusive_ptr<X> px2 = boost::const_pointer_cast<X>(px); + BOOST_TEST(px2.get() == px.get()); + BOOST_TEST(px2->use_count() == 2); + BOOST_TEST(px->use_count() == 2); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px = boost::const_pointer_cast<X>( boost::intrusive_ptr<X const>(new X) ); + BOOST_TEST(px.get() != 0); + BOOST_TEST(px->use_count() == 1); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +} // namespace n_const_cast + +namespace n_dynamic_cast +{ + +void test() +{ + { + boost::intrusive_ptr<X> px; + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == 0); + } + + { + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( boost::intrusive_ptr<X>() ); + BOOST_TEST(py.get() == 0); + } + + { + boost::intrusive_ptr<X> px(static_cast<X*>(0)); + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == 0); + } + + { + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( boost::intrusive_ptr<X>(static_cast<X*>(0)) ); + BOOST_TEST(py.get() == 0); + } + + { + boost::intrusive_ptr<X> px(new X); + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == 0); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( boost::intrusive_ptr<X>(new X) ); + BOOST_TEST(py.get() == 0); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px(new Y); + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == px.get()); + BOOST_TEST(py->use_count() == 2); + BOOST_TEST(px->use_count() == 2); + } + + BOOST_TEST( N::base::instances == 0 ); + + { + boost::intrusive_ptr<X> px(new Y); + + boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( boost::intrusive_ptr<X>(new Y) ); + BOOST_TEST(py.get() != 0); + BOOST_TEST(py->use_count() == 1); + } + + BOOST_TEST( N::base::instances == 0 ); +} + +} // namespace n_dynamic_cast + +namespace n_transitive +{ + +struct X: public N::base +{ + boost::intrusive_ptr<X> next; +}; + +void test() +{ + boost::intrusive_ptr<X> p(new X); + p->next = boost::intrusive_ptr<X>(new X); + BOOST_TEST(!p->next->next); + p = p->next; + BOOST_TEST(!p->next); +} + +} // namespace n_transitive + +namespace n_report_1 +{ + +class foo: public N::base +{ +public: + + foo(): m_self(this) + { + } + + void suicide() + { + m_self = 0; + } + +private: + + boost::intrusive_ptr<foo> m_self; +}; + +void test() +{ + foo * foo_ptr = new foo; + foo_ptr->suicide(); +} + +} // namespace n_report_1 + +int main() +{ + n_element_type::test(); + n_constructors::test(); + n_destructor::test(); + n_assignment::test(); + n_reset::test(); + n_access::test(); + n_swap::test(); + n_comparison::test(); + n_static_cast::test(); + n_const_cast::test(); + n_dynamic_cast::test(); + + n_transitive::test(); + n_report_1::test(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/intrusive_ref_counter_test.cpp b/src/boost/libs/smart_ptr/test/intrusive_ref_counter_test.cpp new file mode 100644 index 00000000..53d0bd37 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/intrusive_ref_counter_test.cpp @@ -0,0 +1,156 @@ +/* + * Copyright Andrey Semashev 2013. + * 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) + */ +/*! + * \file intrusive_ref_counter_test.cpp + * \author Andrey Semashev + * \date 31.08.2013 + * + * This file contains tests for the \c intrusive_ref_counter base class. + */ + +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#pragma warning(disable: 4355) // 'this' : used in base member initializer list +#pragma warning(disable: 4511) // copy constructor could not be generated +#pragma warning(disable: 4512) // assignment operator could not be generated + +#if (BOOST_MSVC >= 1310) +#pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +#include <cstddef> +#include <boost/smart_ptr/intrusive_ref_counter.hpp> +#include <boost/intrusive_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +namespace N1 { + +class my_class : + public boost::intrusive_ref_counter< my_class > +{ +public: + static unsigned int destructor_count; + + ~my_class() + { + ++destructor_count; + } +}; + +unsigned int my_class::destructor_count = 0; + +} // namespace N1 + +namespace N2 { + +class my_class : + public boost::intrusive_ref_counter< my_class, boost::thread_unsafe_counter > +{ +public: + static unsigned int destructor_count; + + ~my_class() + { + ++destructor_count; + } +}; + +unsigned int my_class::destructor_count = 0; + +} // namespace N2 + +namespace N3 { + +struct root : + public boost::intrusive_ref_counter< root > +{ + virtual ~root() {} +}; + +} // namespace N3 + +namespace N4 { + +struct X : + public virtual N3::root +{ +}; + +} // namespace N4 + +namespace N5 { + +struct Y : + public virtual N3::root +{ +}; + +} // namespace N5 + +namespace N6 { + +struct Z : + public N4::X, + public N5::Y +{ + static unsigned int destructor_count; + + ~Z() + { + ++destructor_count; + } +}; + +unsigned int Z::destructor_count = 0; + +} // namespace N6 + + +int main() +{ + // The test check that ADL works + { + boost::intrusive_ptr< N1::my_class > p = new N1::my_class(); + p = NULL; + BOOST_TEST(N1::my_class::destructor_count == 1); + } + { + boost::intrusive_ptr< N2::my_class > p = new N2::my_class(); + p = NULL; + BOOST_TEST(N2::my_class::destructor_count == 1); + } + { + N1::my_class* p = new N1::my_class(); + intrusive_ptr_add_ref(p); + intrusive_ptr_release(p); + BOOST_TEST(N1::my_class::destructor_count == 2); + } + + // The test checks that destroying through the base class works + { + boost::intrusive_ptr< N6::Z > p1 = new N6::Z(); + BOOST_TEST(p1->use_count() == 1); + BOOST_TEST(N6::Z::destructor_count == 0); + boost::intrusive_ptr< N3::root > p2 = p1; + BOOST_TEST(p1->use_count() == 2); + BOOST_TEST(N6::Z::destructor_count == 0); + p1 = NULL; + BOOST_TEST(N6::Z::destructor_count == 0); + p2 = NULL; + BOOST_TEST(N6::Z::destructor_count == 1); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/ip_convertible_test.cpp b/src/boost/libs/smart_ptr/test/ip_convertible_test.cpp new file mode 100644 index 00000000..081f7b0f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/ip_convertible_test.cpp @@ -0,0 +1,54 @@ +#include <boost/config.hpp> + +// wp_convertible_test.cpp +// +// Copyright (c) 2008 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 <boost/detail/lightweight_test.hpp> +#include <boost/intrusive_ptr.hpp> + +// + +struct W +{ +}; + +void intrusive_ptr_add_ref( W* ) +{ +} + +void intrusive_ptr_release( W* ) +{ +} + +struct X: public virtual W +{ +}; + +struct Y: public virtual W +{ +}; + +struct Z: public X +{ +}; + +int f( boost::intrusive_ptr<X> ) +{ + return 1; +} + +int f( boost::intrusive_ptr<Y> ) +{ + return 2; +} + +int main() +{ + BOOST_TEST( 1 == f( boost::intrusive_ptr<Z>() ) ); + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/ip_hash_test.cpp b/src/boost/libs/smart_ptr/test/ip_hash_test.cpp new file mode 100644 index 00000000..be38b3d6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/ip_hash_test.cpp @@ -0,0 +1,75 @@ +// +// ip_hash_test.cpp +// +// Copyright 2011 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 <boost/intrusive_ptr.hpp> +#include <boost/functional/hash.hpp> +#include <boost/detail/lightweight_test.hpp> + +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 +{ +}; + +int main() +{ + boost::hash< boost::intrusive_ptr<X> > hasher; + + boost::intrusive_ptr<X> p1, p2( p1 ), p3( new X ), p4( p3 ), p5( new X ); + + BOOST_TEST_EQ( p1, p2 ); + BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) ); + + BOOST_TEST_NE( p1, p3 ); + BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) ); + + BOOST_TEST_EQ( p3, p4 ); + BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) ); + + BOOST_TEST_NE( p3, p5 ); + BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/local_sp_fn_test.cpp b/src/boost/libs/smart_ptr/test/local_sp_fn_test.cpp new file mode 100644 index 00000000..f2a355af --- /dev/null +++ b/src/boost/libs/smart_ptr/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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +static void f() +{ +} + +struct null_deleter +{ + template<class Y> void operator()( Y* ) {} +}; + +int main() +{ + boost::local_shared_ptr<void()> pf( f, null_deleter() ); + + BOOST_TEST( pf.get() == f ); + BOOST_TEST_EQ( pf.local_use_count(), 1 ); + BOOST_TEST( boost::get_deleter<null_deleter>( pf ) != 0 ); + + boost::weak_ptr<void()> 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(); +} diff --git a/src/boost/libs/smart_ptr/test/local_sp_test.cpp b/src/boost/libs/smart_ptr/test/local_sp_test.cpp new file mode 100644 index 00000000..dc0e316e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/local_sp_test.cpp @@ -0,0 +1,2531 @@ +// +// local_sp_test.cpp +// +// Copyright 2002, 2003, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/smart_ptr/shared_ptr.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +long X::instances = 0; + +class incomplete; + +// default constructor + +static void default_constructor() +{ + { + boost::local_shared_ptr<int> p; + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + + { + boost::local_shared_ptr<void> p; + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + + { + boost::local_shared_ptr<incomplete> p; + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr<X> p; + + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } +} + +// nullptr_constructor + +static void nullptr_constructor() +{ +#if !defined( BOOST_NO_CXX11_NULLPTR ) + + { + boost::local_shared_ptr<int> p( nullptr ); + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + + { + boost::local_shared_ptr<void> p( nullptr ); + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + + { + boost::local_shared_ptr<incomplete> p( nullptr ); + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr<X> p( nullptr ); + + BOOST_TEST( X::instances == 0 ); + + + BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p.local_use_count(), 0 ); + } + +#endif +} + +// pointer constructor + +template<class T, class U> static void pc0_test_() +{ + boost::local_shared_ptr<T> p( static_cast<U*>( 0 ) ); + + BOOST_TEST( p? false: true ); + BOOST_TEST( !p ); + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.local_use_count() == 1 ); +} + +template<class T> static void pc0_test() +{ + pc0_test_<T, T>(); + pc0_test_<T const, T const>(); + pc0_test_<T volatile, T volatile>(); + pc0_test_<T const volatile, T const volatile>(); + + pc0_test_<T const, T>(); + pc0_test_<T volatile, T>(); + pc0_test_<T const volatile, T>(); + + pc0_test_<void, T>(); + pc0_test_<void const, T>(); + pc0_test_<void volatile, T>(); + pc0_test_<void const volatile, T>(); +} + +template<class T, class U> static void pc1_test_() +{ + boost::local_shared_ptr<T> p( new U() ); + + BOOST_TEST( p? true: false ); + BOOST_TEST( !!p ); + BOOST_TEST( p.get() != 0 ); + BOOST_TEST( p.local_use_count() == 1 ); +} + +template<class T> static void pc1_test() +{ + pc1_test_<T, T>(); + pc1_test_<T const, T const>(); + pc1_test_<T volatile, T volatile>(); + pc1_test_<T const volatile, T const volatile>(); + + pc1_test_<T const, T>(); + pc1_test_<T volatile, T>(); + pc1_test_<T const volatile, T>(); + + pc1_test_<void, T>(); + pc1_test_<void const, T>(); + pc1_test_<void volatile, T>(); + pc1_test_<void const volatile, T>(); +} + +static void pointer_constructor() +{ + pc0_test<int>(); + pc0_test<X>(); + + pc1_test<int>(); + + BOOST_TEST( X::instances == 0 ); + + pc1_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// deleter constructor + +int m = 0; + +void deleter2( int * p ) +{ + BOOST_TEST( p == &m ); + ++*p; +} + +template<class T> static void deleter2_test_() +{ + { + m = 0; + boost::local_shared_ptr<T> p( &m, deleter2 ); + + BOOST_TEST( p? true: false ); + BOOST_TEST( !!p ); + BOOST_TEST( p.get() == &m ); + BOOST_TEST( p.local_use_count() == 1 ); + } + + BOOST_TEST( m == 1 ); +} + +static void deleter_constructor() +{ + deleter2_test_<int>(); + deleter2_test_<int const>(); + deleter2_test_<int volatile>(); + deleter2_test_<int const volatile>(); + + deleter2_test_<void>(); + deleter2_test_<void const>(); + deleter2_test_<void volatile>(); + deleter2_test_<void const volatile>(); +} + +// nullptr_deleter_constructor + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + +void deleter3( boost::detail::sp_nullptr_t ) +{ + ++m; +} + +template<class T> static void deleter3_test_() +{ + { + m = 0; + boost::local_shared_ptr<T> p( nullptr, deleter3 ); + + BOOST_TEST( !p ); + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.local_use_count() == 1 ); + } + + BOOST_TEST( m == 1 ); +} + +static void nullptr_deleter_constructor() +{ + deleter3_test_<int>(); + deleter3_test_<int const>(); + deleter3_test_<int volatile>(); + deleter3_test_<int const volatile>(); + + deleter3_test_<void>(); + deleter3_test_<void const>(); + deleter3_test_<void volatile>(); + deleter3_test_<void const volatile>(); +} + +#else + +static void nullptr_deleter_constructor() +{ +} + +#endif + +// allocator constructor + +template<class T> static void allocator_test_() +{ + { + m = 0; + boost::local_shared_ptr<T> p( &m, deleter2, std::allocator<void>() ); + + BOOST_TEST( p? true: false ); + BOOST_TEST( !!p ); + BOOST_TEST( p.get() == &m ); + BOOST_TEST( p.local_use_count() == 1 ); + } + + BOOST_TEST( m == 1 ); +} + +static void allocator_constructor() +{ + allocator_test_<int>(); + allocator_test_<int const>(); + allocator_test_<int volatile>(); + allocator_test_<int const volatile>(); + + allocator_test_<void>(); + allocator_test_<void const>(); + allocator_test_<void volatile>(); + allocator_test_<void const volatile>(); +} + +// nullptr_allocator_constructor + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + +template<class T> static void allocator3_test_() +{ + { + m = 0; + boost::local_shared_ptr<T> p( nullptr, deleter3, std::allocator<void>() ); + + BOOST_TEST( !p ); + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.local_use_count() == 1 ); + } + + BOOST_TEST( m == 1 ); +} + +static void nullptr_allocator_constructor() +{ + allocator3_test_<int>(); + allocator3_test_<int const>(); + allocator3_test_<int volatile>(); + allocator3_test_<int const volatile>(); + + allocator3_test_<void>(); + allocator3_test_<void const>(); + allocator3_test_<void volatile>(); + allocator3_test_<void const volatile>(); +} + +#else + +static void nullptr_allocator_constructor() +{ +} + +#endif + +// copy constructor + +template<class T> static void empty_copy_test() +{ + boost::local_shared_ptr<T> p1; + + BOOST_TEST_EQ( p1.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p1.local_use_count(), 0 ); + + boost::local_shared_ptr<T> p2( p1 ); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( p1 ); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( p1 ); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( p3 ); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_copy( boost::local_shared_ptr<U> const & p1 ) +{ + long k = p1.local_use_count(); + + { + boost::local_shared_ptr<T> p2( p1 ); + + BOOST_TEST( p2.get() == p1.get() ); + BOOST_TEST( p2.local_use_count() == p1.local_use_count() ); + BOOST_TEST( p2.local_use_count() == k + 1 ); + } + + BOOST_TEST( p1.local_use_count() == k ); +} + +template<class T> static void null_copy_test() +{ + boost::local_shared_ptr<T> p1( static_cast<T*>(0) ); + + test_nonempty_copy<T>( p1 ); + test_nonempty_copy<T const>( p1 ); + test_nonempty_copy<T volatile>( p1 ); + test_nonempty_copy<T const volatile>( p1 ); + test_nonempty_copy<void>( p1 ); + test_nonempty_copy<void const>( p1 ); + test_nonempty_copy<void volatile>( p1 ); + test_nonempty_copy<void const volatile>( p1 ); +} + +template<class T> static void new_copy_test() +{ + boost::local_shared_ptr<T> p1( new T() ); + + test_nonempty_copy<T>( p1 ); + test_nonempty_copy<T const>( p1 ); + test_nonempty_copy<T volatile>( p1 ); + test_nonempty_copy<T const volatile>( p1 ); + test_nonempty_copy<void>( p1 ); + test_nonempty_copy<void const>( p1 ); + test_nonempty_copy<void volatile>( p1 ); + test_nonempty_copy<void const volatile>( p1 ); +} + +static void copy_constructor() +{ + empty_copy_test<int>(); + empty_copy_test<incomplete>(); + empty_copy_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_copy_test<int>(); + null_copy_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_copy_test<int>(); + new_copy_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// move constructor + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +template<class T> static void empty_move_test() +{ + boost::local_shared_ptr<T> p2(( boost::local_shared_ptr<T>() )); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3(( boost::local_shared_ptr<T>() )); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4(( boost::local_shared_ptr<T>() )); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( std::move(p3) ); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_move( boost::local_shared_ptr<U> && p1 ) +{ + U* q = p1.get(); + long k = p1.local_use_count(); + + boost::local_shared_ptr<T> p2( std::move(p1) ); + + BOOST_TEST( p2.get() == q ); + BOOST_TEST( p2.local_use_count() == k ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST( p1.local_use_count() == 0 ); +} + +template<class T> static void null_move_test() +{ + test_nonempty_move<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<T const>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<T volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<T const volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<void>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<void const>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<void volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move<void const volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_move_test() +{ + test_nonempty_move<T>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<T const>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<T volatile>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<T const volatile>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<void>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<void const>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<void volatile>( boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move<void const volatile>( boost::local_shared_ptr<T>( new T() ) ); +} + +static void move_constructor() +{ + empty_move_test<int>(); + empty_move_test<incomplete>(); + empty_move_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_move_test<int>(); + null_move_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_move_test<int>(); + new_move_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +#else + +static void move_constructor() +{ +} + +#endif + +// aliasing constructor + +template<class T, class U> void test_aliasing_( boost::local_shared_ptr<T> const & p1, U * p2 ) +{ + boost::local_shared_ptr<U> p3( p1, p2 ); + + BOOST_TEST( p3.get() == p2 ); + BOOST_TEST( p3.local_use_count() == p1.local_use_count() ); + BOOST_TEST( !p3.owner_before( p1 ) && !p1.owner_before( p3 ) ); +} + +template<class T, class U> void test_01_aliasing_() +{ + U u; + boost::local_shared_ptr<T> p1; + + test_aliasing_( p1, &u ); +} + +template<class T, class U> void test_01_aliasing() +{ + test_01_aliasing_<T, U>(); + test_01_aliasing_<T const, U>(); + test_01_aliasing_<T volatile, U>(); + test_01_aliasing_<T const volatile, U>(); + + test_01_aliasing_<T, U volatile>(); + test_01_aliasing_<T const, U volatile>(); + test_01_aliasing_<T volatile, U volatile>(); + test_01_aliasing_<T const volatile, U volatile>(); +} + +template<class T, class U> void test_10_aliasing_() +{ + boost::local_shared_ptr<T> p1( new T() ); + test_aliasing_( p1, static_cast<U*>(0) ); +} + +template<class T, class U> void test_10_aliasing() +{ + test_10_aliasing_<T, U>(); + test_10_aliasing_<T const, U>(); + test_10_aliasing_<T volatile, U>(); + test_10_aliasing_<T const volatile, U>(); + + test_10_aliasing_<T, U const>(); + test_10_aliasing_<T const, U const>(); + test_10_aliasing_<T volatile, U const>(); + test_10_aliasing_<T const volatile, U const>(); + + test_10_aliasing_<T, U volatile>(); + test_10_aliasing_<T const, U volatile>(); + test_10_aliasing_<T volatile, U volatile>(); + test_10_aliasing_<T const volatile, U volatile>(); + + test_10_aliasing_<T, U const volatile>(); + test_10_aliasing_<T const, U const volatile>(); + test_10_aliasing_<T volatile, U const volatile>(); + test_10_aliasing_<T const volatile, U const volatile>(); +} + +template<class T, class U> void test_11_aliasing_() +{ + U u; + boost::local_shared_ptr<T> p1( new T() ); + + test_aliasing_( p1, &u ); +} + +template<class T, class U> void test_11_aliasing() +{ + test_11_aliasing_<T, U>(); + test_11_aliasing_<T const, U>(); + test_11_aliasing_<T volatile, U>(); + test_11_aliasing_<T const volatile, U>(); + + test_11_aliasing_<T, U volatile>(); + test_11_aliasing_<T const, U volatile>(); + test_11_aliasing_<T volatile, U volatile>(); + test_11_aliasing_<T const volatile, U volatile>(); +} + +static void aliasing_constructor() +{ + test_01_aliasing<int, int>(); + test_10_aliasing<int, int>(); + test_11_aliasing<int, int>(); + + test_01_aliasing<void, int>(); + + test_10_aliasing<int, void>(); + + test_10_aliasing<int, incomplete>(); + + test_01_aliasing<X, X>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing<X, X>(); + BOOST_TEST( X::instances == 0 ); + + test_11_aliasing<X, X>(); + BOOST_TEST( X::instances == 0 ); + + test_01_aliasing<int, X>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing<int, X>(); + BOOST_TEST( X::instances == 0 ); + + test_11_aliasing<int, X>(); + BOOST_TEST( X::instances == 0 ); + + test_01_aliasing<X, int>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing<X, int>(); + BOOST_TEST( X::instances == 0 ); + + test_11_aliasing<X, int>(); + BOOST_TEST( X::instances == 0 ); + + test_01_aliasing<void, X>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing<X, void>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing<X, incomplete>(); + BOOST_TEST( X::instances == 0 ); +} + +// shared_ptr copy constructor + +template<class T> static void empty_shared_ptr_copy_test() +{ + boost::shared_ptr<T> p1; + + boost::local_shared_ptr<T> p2( p1 ); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( p1 ); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( p1 ); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( p3 ); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_shared_ptr_copy( boost::shared_ptr<U> const & p1 ) +{ + long k = p1.use_count(); + + { + boost::local_shared_ptr<T> p2( p1 ); + + BOOST_TEST( p2.get() == p1.get() ); + BOOST_TEST( p2.local_use_count() == 1 ); + + BOOST_TEST( p1.use_count() == k + 1 ); + } + + BOOST_TEST( p1.use_count() == k ); +} + +template<class T> static void null_shared_ptr_copy_test() +{ + boost::shared_ptr<T> p1( static_cast<T*>(0) ); + + test_nonempty_shared_ptr_copy<T>( p1 ); + test_nonempty_shared_ptr_copy<T const>( p1 ); + test_nonempty_shared_ptr_copy<T volatile>( p1 ); + test_nonempty_shared_ptr_copy<T const volatile>( p1 ); + test_nonempty_shared_ptr_copy<void>( p1 ); + test_nonempty_shared_ptr_copy<void const>( p1 ); + test_nonempty_shared_ptr_copy<void volatile>( p1 ); + test_nonempty_shared_ptr_copy<void const volatile>( p1 ); +} + +template<class T> static void new_shared_ptr_copy_test() +{ + boost::shared_ptr<T> p1( new T() ); + + test_nonempty_shared_ptr_copy<T>( p1 ); + test_nonempty_shared_ptr_copy<T const>( p1 ); + test_nonempty_shared_ptr_copy<T volatile>( p1 ); + test_nonempty_shared_ptr_copy<T const volatile>( p1 ); + test_nonempty_shared_ptr_copy<void>( p1 ); + test_nonempty_shared_ptr_copy<void const>( p1 ); + test_nonempty_shared_ptr_copy<void volatile>( p1 ); + test_nonempty_shared_ptr_copy<void const volatile>( p1 ); +} + +static void shared_ptr_copy_constructor() +{ + empty_shared_ptr_copy_test<int>(); + empty_shared_ptr_copy_test<incomplete>(); + empty_shared_ptr_copy_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_shared_ptr_copy_test<int>(); + null_shared_ptr_copy_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_shared_ptr_copy_test<int>(); + new_shared_ptr_copy_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// shared_ptr_move constructor + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +template<class T> static void empty_shared_ptr_move_test() +{ + boost::local_shared_ptr<T> p2(( boost::shared_ptr<T>() )); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3(( boost::shared_ptr<T>() )); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4(( boost::shared_ptr<T>() )); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( std::move(p3) ); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_shared_ptr_move( boost::shared_ptr<U> && p1 ) +{ + U* q = p1.get(); + + boost::local_shared_ptr<T> p2( std::move(p1) ); + + BOOST_TEST( p2.get() == q ); + BOOST_TEST( p2.local_use_count() == 1 ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST( p1.use_count() == 0 ); +} + +template<class T> static void null_shared_ptr_move_test() +{ + test_nonempty_shared_ptr_move<T>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<T const>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<T volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<T const volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<void>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<void const>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<void volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move<void const volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_shared_ptr_move_test() +{ + test_nonempty_shared_ptr_move<T>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<T const>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<T volatile>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<T const volatile>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<void>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<void const>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<void volatile>( boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move<void const volatile>( boost::shared_ptr<T>( new T() ) ); +} + +static void shared_ptr_move_constructor() +{ + empty_shared_ptr_move_test<int>(); + empty_shared_ptr_move_test<incomplete>(); + empty_shared_ptr_move_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_shared_ptr_move_test<int>(); + null_shared_ptr_move_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_shared_ptr_move_test<int>(); + new_shared_ptr_move_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +#else + +static void shared_ptr_move_constructor() +{ +} + +#endif + +// unique_ptr_constructor + +#if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +template<class T, class U> static void test_null_unique_ptr( std::unique_ptr<U> && p1 ) +{ + boost::local_shared_ptr<T> p2( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2.local_use_count() == 0 ); +} + +template<class T> static void null_unique_ptr_test() +{ + test_null_unique_ptr<T>( std::unique_ptr<T>() ); + + test_null_unique_ptr<T const>( std::unique_ptr<T>() ); + test_null_unique_ptr<T volatile>( std::unique_ptr<T>() ); + test_null_unique_ptr<T const volatile>( std::unique_ptr<T>() ); + + test_null_unique_ptr<T const>( std::unique_ptr<T const>() ); + test_null_unique_ptr<T volatile>( std::unique_ptr<T volatile>() ); + test_null_unique_ptr<T const volatile>( std::unique_ptr<T const volatile>() ); + + test_null_unique_ptr<void>( std::unique_ptr<T>() ); + + test_null_unique_ptr<void const>( std::unique_ptr<T>() ); + test_null_unique_ptr<void volatile>( std::unique_ptr<T>() ); + test_null_unique_ptr<void const volatile>( std::unique_ptr<T>() ); + + test_null_unique_ptr<void const>( std::unique_ptr<T const>() ); + test_null_unique_ptr<void volatile>( std::unique_ptr<T volatile>() ); + test_null_unique_ptr<void const volatile>( std::unique_ptr<T const volatile>() ); +} + +template<class T, class U, class D> static void test_nonempty_unique_ptr( std::unique_ptr<U, D> && p1 ) +{ + U * q = p1.get(); + + boost::local_shared_ptr<T> p2( std::move(p1) ); + + BOOST_TEST( p2.get() == q ); + BOOST_TEST( p2.local_use_count() == 1 ); + + BOOST_TEST( p1.get() == 0 ); +} + +template<class T> static void new_unique_ptr_test() +{ + test_nonempty_unique_ptr<T>( std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr<T const>( std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr<T volatile>( std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr<T const volatile>( std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr<T const>( std::unique_ptr<T const>( new T() ) ); + test_nonempty_unique_ptr<T volatile>( std::unique_ptr<T volatile>( new T() ) ); + test_nonempty_unique_ptr<T const volatile>( std::unique_ptr<T const volatile>( new T() ) ); + + test_nonempty_unique_ptr<void>( std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr<void const>( std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr<void volatile>( std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr<void const volatile>( std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr<void const>( std::unique_ptr<T const>( new T() ) ); + test_nonempty_unique_ptr<void volatile>( std::unique_ptr<T volatile>( new T() ) ); + test_nonempty_unique_ptr<void const volatile>( std::unique_ptr<T const volatile>( new T() ) ); +} + +template<class T> static void test_deleter_unique_ptr() +{ + m = 0; + + test_nonempty_unique_ptr<T>( std::unique_ptr<int, void(*)(int*)>( &m, deleter2 ) ); + + BOOST_TEST( m == 1 ); +} + +template<class T> static void deleter_unique_ptr_test() +{ + test_deleter_unique_ptr<T>(); + test_deleter_unique_ptr<T const>(); + test_deleter_unique_ptr<T volatile>(); + test_deleter_unique_ptr<T const volatile>(); +} + +static void unique_ptr_constructor() +{ + null_unique_ptr_test<int>(); + null_unique_ptr_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_unique_ptr_test<int>(); + new_unique_ptr_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + deleter_unique_ptr_test<int>(); + deleter_unique_ptr_test<void>(); +} + +#else + +static void unique_ptr_constructor() +{ +} + +#endif + +// copy assignment + +template<class T> static void empty_copy_assign_test() +{ + boost::local_shared_ptr<T> p1; + + BOOST_TEST_EQ( p1.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p1.local_use_count(), 0 ); + + boost::local_shared_ptr<T> p2; + + p2 = p1; + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3; + + p3 = p1; + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4; + + p4 = p1; + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5; + + p5 = p3; + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T> static void empty_copy_assign_test_() +{ + boost::local_shared_ptr<T> p1; + + BOOST_TEST_EQ( p1.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p1.local_use_count(), 0 ); + + boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); + + p2 = p1; + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); + + p3 = p1; + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); + + p4 = p1; + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); + + p5 = p3; + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_copy_assign( boost::local_shared_ptr<T> p2, boost::local_shared_ptr<U> const & p1 ) +{ + long k = p1.local_use_count(); + + p2 = p1; + + BOOST_TEST( p2.get() == p1.get() ); + BOOST_TEST( p2.local_use_count() == p1.local_use_count() ); + BOOST_TEST( p2.local_use_count() == k + 1 ); + + p2.reset(); + + BOOST_TEST( p1.local_use_count() == k ); +} + +template<class T> static void null_copy_assign_test() +{ + boost::local_shared_ptr<T> p1( static_cast<T*>(0) ); + + test_nonempty_copy_assign( boost::local_shared_ptr<T>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); + + test_nonempty_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); + + test_nonempty_copy_assign( boost::local_shared_ptr<void>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<void const>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); +} + +template<class T> static void new_copy_assign_test() +{ + boost::local_shared_ptr<T> p1( new T() ); + + test_nonempty_copy_assign( boost::local_shared_ptr<T>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); + + test_nonempty_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); + + test_nonempty_copy_assign( boost::local_shared_ptr<T>( new T() ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const>( new T const() ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), p1 ); + + test_nonempty_copy_assign( boost::local_shared_ptr<void>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<void const>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); + test_nonempty_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); +} + +static void copy_assignment() +{ + empty_copy_assign_test<incomplete>(); + empty_copy_assign_test<int>(); + empty_copy_assign_test_<int>(); + empty_copy_assign_test<X>(); + empty_copy_assign_test_<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_copy_assign_test<int>(); + null_copy_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_copy_assign_test<int>(); + new_copy_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// move assignment + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +template<class T> static void empty_move_assign_test() +{ + boost::local_shared_ptr<T> p2; + + p2 = boost::local_shared_ptr<T>(); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3; + + p3 = boost::local_shared_ptr<T>(); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4; + + p4 = boost::local_shared_ptr<T>(); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5; + + p5 = std::move( p3 ); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T> static void empty_move_assign_test_() +{ + boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); + + p2 = boost::local_shared_ptr<T>(); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); + + p3 = boost::local_shared_ptr<T>(); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); + + p4 = boost::local_shared_ptr<T>(); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); + + p5 = std::move( p3 ); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_move_assign( boost::local_shared_ptr<T> p2, boost::local_shared_ptr<U> && p1 ) +{ + U* q = p1.get(); + long k = p1.local_use_count(); + + p2 = std::move( p1 ); + + BOOST_TEST( p2.get() == q ); + BOOST_TEST( p2.local_use_count() == k ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST( p1.local_use_count() == 0 ); +} + +template<class T> static void null_move_assign_test() +{ + test_nonempty_move_assign( boost::local_shared_ptr<T>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + + test_nonempty_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + + test_nonempty_move_assign( boost::local_shared_ptr<void>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<void const>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<void volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_move_assign( boost::local_shared_ptr<void const volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_move_assign_test() +{ + test_nonempty_move_assign( boost::local_shared_ptr<T>(), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const>(), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T volatile>(), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>(), boost::local_shared_ptr<T>( new T() ) ); + + test_nonempty_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::local_shared_ptr<T>( new T() ) ); + + test_nonempty_move_assign( boost::local_shared_ptr<T>( new T() ), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const>( new T const() ), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), boost::local_shared_ptr<T>( new T() ) ); + + test_nonempty_move_assign( boost::local_shared_ptr<void>(), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<void const>(), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<void volatile>(), boost::local_shared_ptr<T>( new T() ) ); + test_nonempty_move_assign( boost::local_shared_ptr<void const volatile>(), boost::local_shared_ptr<T>( new T() ) ); +} + +static void move_assignment() +{ + empty_move_assign_test<incomplete>(); + empty_move_assign_test<int>(); + empty_move_assign_test_<int>(); + empty_move_assign_test<X>(); + empty_move_assign_test_<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_move_assign_test<int>(); + null_move_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_move_assign_test<int>(); + new_move_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +#else + +static void move_assignment() +{ +} + +#endif + +// nullptr assignment + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + +template<class T> static void test_nullptr_assign( boost::local_shared_ptr<T> p1 ) +{ + p1 = nullptr; + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST( p1.local_use_count() == 0 ); +} + +template<class T> static void empty_nullptr_assign_test() +{ + test_nullptr_assign( boost::local_shared_ptr<T>() ); + test_nullptr_assign( boost::local_shared_ptr<T const>() ); + test_nullptr_assign( boost::local_shared_ptr<T volatile>() ); + test_nullptr_assign( boost::local_shared_ptr<T const volatile>() ); +} + +template<class T> static void null_nullptr_assign_test() +{ + test_nullptr_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_nullptr_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ) ); + test_nullptr_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ) ); + test_nullptr_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ) ); +} + +template<class T> static void new_nullptr_assign_test() +{ + test_nullptr_assign( boost::local_shared_ptr<T>( new T() ) ); + test_nullptr_assign( boost::local_shared_ptr<T const>( new T const() ) ); + test_nullptr_assign( boost::local_shared_ptr<T volatile>( new T volatile() ) ); + test_nullptr_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ) ); +} + +static void nullptr_assignment() +{ + empty_nullptr_assign_test<incomplete>(); + empty_nullptr_assign_test<void>(); + empty_nullptr_assign_test<int>(); + empty_nullptr_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_nullptr_assign_test<int>(); + null_nullptr_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_nullptr_assign_test<int>(); + new_nullptr_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +#else + +static void nullptr_assignment() +{ +} + +#endif + +// default_reset + +template<class T> static void test_default_reset( boost::local_shared_ptr<T> p1 ) +{ + p1.reset(); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST( p1.local_use_count() == 0 ); +} + +template<class T> static void empty_default_reset_test() +{ + test_default_reset( boost::local_shared_ptr<T>() ); + test_default_reset( boost::local_shared_ptr<T const>() ); + test_default_reset( boost::local_shared_ptr<T volatile>() ); + test_default_reset( boost::local_shared_ptr<T const volatile>() ); +} + +template<class T> static void null_default_reset_test() +{ + test_default_reset( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_default_reset( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ) ); + test_default_reset( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ) ); + test_default_reset( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ) ); +} + +template<class T> static void new_default_reset_test() +{ + test_default_reset( boost::local_shared_ptr<T>( new T() ) ); + test_default_reset( boost::local_shared_ptr<T const>( new T const() ) ); + test_default_reset( boost::local_shared_ptr<T volatile>( new T volatile() ) ); + test_default_reset( boost::local_shared_ptr<T const volatile>( new T const volatile() ) ); +} + +static void default_reset() +{ + empty_default_reset_test<incomplete>(); + empty_default_reset_test<void>(); + empty_default_reset_test<int>(); + empty_default_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_default_reset_test<int>(); + null_default_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_default_reset_test<int>(); + new_default_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// shared_ptr copy assignment + +template<class T> static void empty_shared_ptr_copy_assign_test() +{ + boost::shared_ptr<T> sp1; + + BOOST_TEST_EQ( sp1.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( sp1.use_count(), 0 ); + + boost::local_shared_ptr<T> p2; + + p2 = sp1; + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3; + + p3 = sp1; + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4; + + p4 = sp1; + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::shared_ptr<T const> sp2( sp1 ); + boost::local_shared_ptr<void const> p5; + + p5 = sp2; + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T> static void empty_shared_ptr_copy_assign_test_() +{ + boost::shared_ptr<T> sp1; + + BOOST_TEST_EQ( sp1.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( sp1.use_count(), 0 ); + + boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); + + p2 = sp1; + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); + + p3 = sp1; + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); + + p4 = sp1; + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::shared_ptr<T const> sp2( sp1 ); + boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); + + p5 = sp2; + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T> p2, boost::shared_ptr<U> const & p1 ) +{ + long k = p1.use_count(); + + p2 = p1; + + BOOST_TEST( p2.get() == p1.get() ); + BOOST_TEST( p2.local_use_count() == 1 ); + BOOST_TEST( p1.use_count() == k + 1 ); + + p2.reset(); + + BOOST_TEST( p1.use_count() == k ); +} + +template<class T> static void null_shared_ptr_copy_assign_test() +{ + boost::shared_ptr<T> p1( static_cast<T*>(0) ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); +} + +template<class T> static void new_shared_ptr_copy_assign_test() +{ + boost::shared_ptr<T> p1( new T() ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>( new T() ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>( new T const() ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), p1 ); + + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); + test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); +} + +static void shared_ptr_copy_assignment() +{ + empty_shared_ptr_copy_assign_test<incomplete>(); + empty_shared_ptr_copy_assign_test<int>(); + empty_shared_ptr_copy_assign_test_<int>(); + empty_shared_ptr_copy_assign_test<X>(); + empty_shared_ptr_copy_assign_test_<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_shared_ptr_copy_assign_test<int>(); + null_shared_ptr_copy_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_shared_ptr_copy_assign_test<int>(); + new_shared_ptr_copy_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// shared_ptr_move assignment + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +template<class T> static void empty_shared_ptr_move_assign_test() +{ + boost::local_shared_ptr<T> p2; + + p2 = boost::shared_ptr<T>(); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3; + + p3 = boost::shared_ptr<T>(); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4; + + p4 = boost::shared_ptr<T>(); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5; + + p5 = boost::shared_ptr<T const>(); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T> static void empty_shared_ptr_move_assign_test_() +{ + boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); + + p2 = boost::shared_ptr<T>(); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); + + p3 = boost::shared_ptr<T>(); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); + + p4 = boost::shared_ptr<T>(); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); + + p5 = boost::shared_ptr<T const>(); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U> static void test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T> p2, boost::shared_ptr<U> && p1 ) +{ + U* q = p1.get(); + long k = p1.use_count(); + + p2 = std::move( p1 ); + + BOOST_TEST_EQ( p2.get(), q ); + BOOST_TEST_EQ( p2.local_use_count(), 1 ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST( p1.use_count() == 0 ); + + boost::shared_ptr<T> p3( p2 ); + + BOOST_TEST_EQ( p3.get(), q ); + BOOST_TEST_EQ( p3.use_count(), k + 1 ); +} + +template<class T> static void null_shared_ptr_move_assign_test() +{ + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_shared_ptr_move_assign_test() +{ + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>(), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>(), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>(), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>(), boost::shared_ptr<T>( new T() ) ); + + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::shared_ptr<T>( new T() ) ); + + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>( new T() ), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>( new T const() ), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), boost::shared_ptr<T>( new T() ) ); + + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void>(), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const>(), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void volatile>(), boost::shared_ptr<T>( new T() ) ); + test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const volatile>(), boost::shared_ptr<T>( new T() ) ); +} + +static void shared_ptr_move_assignment() +{ + empty_shared_ptr_move_assign_test<incomplete>(); + empty_shared_ptr_move_assign_test<int>(); + empty_shared_ptr_move_assign_test_<int>(); + empty_shared_ptr_move_assign_test<X>(); + empty_shared_ptr_move_assign_test_<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_shared_ptr_move_assign_test<int>(); + null_shared_ptr_move_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_shared_ptr_move_assign_test<int>(); + new_shared_ptr_move_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +#else + +static void shared_ptr_move_assignment() +{ +} + +#endif + +// unique_ptr assignment + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) && !defined( BOOST_NO_CXX11_SMART_PTR ) + +template<class T> static void empty_unique_ptr_assign_test() +{ + boost::local_shared_ptr<T> p2; + + p2 = std::unique_ptr<T>(); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3; + + p3 = std::unique_ptr<T>(); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4; + + p4 = std::unique_ptr<T>(); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5; + + p5 = std::unique_ptr<T const>(); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T> static void empty_unique_ptr_assign_test_() +{ + boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); + + p2 = std::unique_ptr<T>(); + + BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p2.local_use_count(), 0 ); + + boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); + + p3 = std::unique_ptr<T>(); + + BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p3.local_use_count(), 0 ); + + boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); + + p4 = std::unique_ptr<T>(); + + BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p4.local_use_count(), 0 ); + + boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); + + p5 = std::unique_ptr<T const>(); + + BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); + BOOST_TEST_EQ( p5.local_use_count(), 0 ); +} + +template<class T, class U, class D> static void test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T> p2, std::unique_ptr<U, D> && p1 ) +{ + U* q = p1.get(); + + p2 = std::move( p1 ); + + BOOST_TEST_EQ( p2.get(), q ); + BOOST_TEST_EQ( p2.local_use_count(), 1 ); + + BOOST_TEST( p1.get() == 0 ); +} + +template<class T> static void new_unique_ptr_assign_test() +{ + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>(), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>(), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>(), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>(), std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( new T() ), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( new T const() ), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), std::unique_ptr<T>( new T() ) ); + + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void>(), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const>(), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void volatile>(), std::unique_ptr<T>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const volatile>(), std::unique_ptr<T>( new T() ) ); +} + +template<class T> static void del_unique_ptr_assign_test() +{ + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( new T() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( new T const() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); + test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); +} + +static void unique_ptr_assignment() +{ + empty_unique_ptr_assign_test<int>(); + empty_unique_ptr_assign_test_<int>(); + empty_unique_ptr_assign_test<X>(); + empty_unique_ptr_assign_test_<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_unique_ptr_assign_test<int>(); + new_unique_ptr_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + del_unique_ptr_assign_test<int>(); + del_unique_ptr_assign_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +#else + +static void unique_ptr_assignment() +{ +} + +#endif + +// pointer reset + +template<class T, class U> static void test_pointer_reset( boost::local_shared_ptr<U> p2 ) +{ + T * q = new T(); + + p2.reset( q ); + + BOOST_TEST_EQ( p2.get(), q ); + BOOST_TEST_EQ( p2.local_use_count(), 1 ); +} + +template<class T> static void empty_pointer_reset_test() +{ + test_pointer_reset<T>( boost::local_shared_ptr<T>() ); + test_pointer_reset<T>( boost::local_shared_ptr<T const>() ); + test_pointer_reset<T>( boost::local_shared_ptr<T volatile>() ); + test_pointer_reset<T>( boost::local_shared_ptr<T const volatile>() ); + + test_pointer_reset<T>( boost::local_shared_ptr<void>() ); + test_pointer_reset<T>( boost::local_shared_ptr<void const>() ); + test_pointer_reset<T>( boost::local_shared_ptr<void volatile>() ); + test_pointer_reset<T>( boost::local_shared_ptr<void const volatile>() ); +} + +template<class T> static void null_pointer_reset_test() +{ + test_pointer_reset<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_pointer_reset<T>( boost::local_shared_ptr<T const>( static_cast<T*>(0) ) ); + test_pointer_reset<T>( boost::local_shared_ptr<T volatile>( static_cast<T*>(0) ) ); + test_pointer_reset<T>( boost::local_shared_ptr<T const volatile>( static_cast<T*>(0) ) ); + + test_pointer_reset<T>( boost::local_shared_ptr<void>( static_cast<T*>(0) ) ); + test_pointer_reset<T>( boost::local_shared_ptr<void const>( static_cast<T*>(0) ) ); + test_pointer_reset<T>( boost::local_shared_ptr<void volatile>( static_cast<T*>(0) ) ); + test_pointer_reset<T>( boost::local_shared_ptr<void const volatile>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_pointer_reset_test() +{ + test_pointer_reset<T>( boost::local_shared_ptr<T>( new T() ) ); + test_pointer_reset<T>( boost::local_shared_ptr<T const>( new T() ) ); + test_pointer_reset<T>( boost::local_shared_ptr<T volatile>( new T() ) ); + test_pointer_reset<T>( boost::local_shared_ptr<T const volatile>( new T() ) ); + + test_pointer_reset<T>( boost::local_shared_ptr<void>( new T() ) ); + test_pointer_reset<T>( boost::local_shared_ptr<void const>( new T() ) ); + test_pointer_reset<T>( boost::local_shared_ptr<void volatile>( new T() ) ); + test_pointer_reset<T>( boost::local_shared_ptr<void const volatile>( new T() ) ); +} + +static void pointer_reset() +{ + empty_pointer_reset_test<int>(); + empty_pointer_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_pointer_reset_test<int>(); + null_pointer_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_pointer_reset_test<int>(); + new_pointer_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// deleter reset + +template<class T> class deleter +{ +private: + + bool * called_; + +public: + + explicit deleter( bool * called ): called_( called ) {} + void operator()( T * p ) { *called_ = true; delete p; } +}; + +template<class T, class U> static void test_deleter_reset( boost::local_shared_ptr<U> p2 ) +{ + T * q = new T(); + + bool called = false; + + p2.reset( q, deleter<T>( &called ) ); + + BOOST_TEST_EQ( p2.get(), q ); + BOOST_TEST_EQ( p2.local_use_count(), 1 ); + + boost::shared_ptr<U> p3( p2 ); + + BOOST_TEST( boost::get_deleter< deleter<T> >( p3 ) != 0 ); + + p3.reset(); + BOOST_TEST( !called ); + + p2.reset(); + BOOST_TEST( called ); +} + +template<class T> static void empty_deleter_reset_test() +{ + test_deleter_reset<T>( boost::local_shared_ptr<T>() ); + test_deleter_reset<T>( boost::local_shared_ptr<T const>() ); + test_deleter_reset<T>( boost::local_shared_ptr<T volatile>() ); + test_deleter_reset<T>( boost::local_shared_ptr<T const volatile>() ); + + test_deleter_reset<T>( boost::local_shared_ptr<void>() ); + test_deleter_reset<T>( boost::local_shared_ptr<void const>() ); + test_deleter_reset<T>( boost::local_shared_ptr<void volatile>() ); + test_deleter_reset<T>( boost::local_shared_ptr<void const volatile>() ); +} + +template<class T> static void null_deleter_reset_test() +{ + test_deleter_reset<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_deleter_reset<T>( boost::local_shared_ptr<T const>( static_cast<T*>(0) ) ); + test_deleter_reset<T>( boost::local_shared_ptr<T volatile>( static_cast<T*>(0) ) ); + test_deleter_reset<T>( boost::local_shared_ptr<T const volatile>( static_cast<T*>(0) ) ); + + test_deleter_reset<T>( boost::local_shared_ptr<void>( static_cast<T*>(0) ) ); + test_deleter_reset<T>( boost::local_shared_ptr<void const>( static_cast<T*>(0) ) ); + test_deleter_reset<T>( boost::local_shared_ptr<void volatile>( static_cast<T*>(0) ) ); + test_deleter_reset<T>( boost::local_shared_ptr<void const volatile>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_deleter_reset_test() +{ + test_deleter_reset<T>( boost::local_shared_ptr<T>( new T() ) ); + test_deleter_reset<T>( boost::local_shared_ptr<T const>( new T() ) ); + test_deleter_reset<T>( boost::local_shared_ptr<T volatile>( new T() ) ); + test_deleter_reset<T>( boost::local_shared_ptr<T const volatile>( new T() ) ); + + test_deleter_reset<T>( boost::local_shared_ptr<void>( new T() ) ); + test_deleter_reset<T>( boost::local_shared_ptr<void const>( new T() ) ); + test_deleter_reset<T>( boost::local_shared_ptr<void volatile>( new T() ) ); + test_deleter_reset<T>( boost::local_shared_ptr<void const volatile>( new T() ) ); +} + +static void deleter_reset() +{ + empty_deleter_reset_test<int>(); + empty_deleter_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_deleter_reset_test<int>(); + null_deleter_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_deleter_reset_test<int>(); + new_deleter_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// allocator reset + +template<class T, class U> static void test_allocator_reset( boost::local_shared_ptr<U> p2 ) +{ + T * q = new T(); + + bool called = false; + + p2.reset( q, deleter<T>( &called ), std::allocator<T>() ); + + BOOST_TEST_EQ( p2.get(), q ); + BOOST_TEST_EQ( p2.local_use_count(), 1 ); + + boost::shared_ptr<U> p3( p2 ); + + BOOST_TEST( boost::get_deleter< deleter<T> >( p3 ) != 0 ); + + p3.reset(); + BOOST_TEST( !called ); + + p2.reset(); + BOOST_TEST( called ); +} + +template<class T> static void empty_allocator_reset_test() +{ + test_allocator_reset<T>( boost::local_shared_ptr<T>() ); + test_allocator_reset<T>( boost::local_shared_ptr<T const>() ); + test_allocator_reset<T>( boost::local_shared_ptr<T volatile>() ); + test_allocator_reset<T>( boost::local_shared_ptr<T const volatile>() ); + + test_allocator_reset<T>( boost::local_shared_ptr<void>() ); + test_allocator_reset<T>( boost::local_shared_ptr<void const>() ); + test_allocator_reset<T>( boost::local_shared_ptr<void volatile>() ); + test_allocator_reset<T>( boost::local_shared_ptr<void const volatile>() ); +} + +template<class T> static void null_allocator_reset_test() +{ + test_allocator_reset<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); + test_allocator_reset<T>( boost::local_shared_ptr<T const>( static_cast<T*>(0) ) ); + test_allocator_reset<T>( boost::local_shared_ptr<T volatile>( static_cast<T*>(0) ) ); + test_allocator_reset<T>( boost::local_shared_ptr<T const volatile>( static_cast<T*>(0) ) ); + + test_allocator_reset<T>( boost::local_shared_ptr<void>( static_cast<T*>(0) ) ); + test_allocator_reset<T>( boost::local_shared_ptr<void const>( static_cast<T*>(0) ) ); + test_allocator_reset<T>( boost::local_shared_ptr<void volatile>( static_cast<T*>(0) ) ); + test_allocator_reset<T>( boost::local_shared_ptr<void const volatile>( static_cast<T*>(0) ) ); +} + +template<class T> static void new_allocator_reset_test() +{ + test_allocator_reset<T>( boost::local_shared_ptr<T>( new T() ) ); + test_allocator_reset<T>( boost::local_shared_ptr<T const>( new T() ) ); + test_allocator_reset<T>( boost::local_shared_ptr<T volatile>( new T() ) ); + test_allocator_reset<T>( boost::local_shared_ptr<T const volatile>( new T() ) ); + + test_allocator_reset<T>( boost::local_shared_ptr<void>( new T() ) ); + test_allocator_reset<T>( boost::local_shared_ptr<void const>( new T() ) ); + test_allocator_reset<T>( boost::local_shared_ptr<void volatile>( new T() ) ); + test_allocator_reset<T>( boost::local_shared_ptr<void const volatile>( new T() ) ); +} + +static void allocator_reset() +{ + empty_allocator_reset_test<int>(); + empty_allocator_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + null_allocator_reset_test<int>(); + null_allocator_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_allocator_reset_test<int>(); + new_allocator_reset_test<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// aliasing reset + +struct null_deleter +{ + void operator()( void const volatile* ) {} +}; + +template<class T, class U> void test_aliasing_reset_( boost::local_shared_ptr<T> const & p1, U * p2 ) +{ + boost::local_shared_ptr<U> p3( static_cast<U*>(0), null_deleter() ); + + p3.reset( p1, p2 ); + + BOOST_TEST( p3.get() == p2 ); + BOOST_TEST( p3.local_use_count() == p1.local_use_count() ); + BOOST_TEST( !p3.owner_before( p1 ) && !p1.owner_before( p3 ) ); +} + +template<class T, class U> void test_01_aliasing_reset_() +{ + U u; + boost::local_shared_ptr<T> p1; + + test_aliasing_reset_( p1, &u ); +} + +template<class T, class U> void test_01_aliasing_reset() +{ + test_01_aliasing_reset_<T, U>(); + test_01_aliasing_reset_<T const, U>(); + test_01_aliasing_reset_<T volatile, U>(); + test_01_aliasing_reset_<T const volatile, U>(); + + test_01_aliasing_reset_<T, U volatile>(); + test_01_aliasing_reset_<T const, U volatile>(); + test_01_aliasing_reset_<T volatile, U volatile>(); + test_01_aliasing_reset_<T const volatile, U volatile>(); +} + +template<class T, class U> void test_10_aliasing_reset_() +{ + boost::local_shared_ptr<T> p1( new T() ); + test_aliasing_reset_( p1, static_cast<U*>(0) ); +} + +template<class T, class U> void test_10_aliasing_reset() +{ + test_10_aliasing_reset_<T, U>(); + test_10_aliasing_reset_<T const, U>(); + test_10_aliasing_reset_<T volatile, U>(); + test_10_aliasing_reset_<T const volatile, U>(); + + test_10_aliasing_reset_<T, U const>(); + test_10_aliasing_reset_<T const, U const>(); + test_10_aliasing_reset_<T volatile, U const>(); + test_10_aliasing_reset_<T const volatile, U const>(); + + test_10_aliasing_reset_<T, U volatile>(); + test_10_aliasing_reset_<T const, U volatile>(); + test_10_aliasing_reset_<T volatile, U volatile>(); + test_10_aliasing_reset_<T const volatile, U volatile>(); + + test_10_aliasing_reset_<T, U const volatile>(); + test_10_aliasing_reset_<T const, U const volatile>(); + test_10_aliasing_reset_<T volatile, U const volatile>(); + test_10_aliasing_reset_<T const volatile, U const volatile>(); +} + +template<class T, class U> void test_11_aliasing_reset_() +{ + U u; + boost::local_shared_ptr<T> p1( new T() ); + + test_aliasing_reset_( p1, &u ); +} + +template<class T, class U> void test_11_aliasing_reset() +{ + test_11_aliasing_reset_<T, U>(); + test_11_aliasing_reset_<T const, U>(); + test_11_aliasing_reset_<T volatile, U>(); + test_11_aliasing_reset_<T const volatile, U>(); + + test_11_aliasing_reset_<T, U volatile>(); + test_11_aliasing_reset_<T const, U volatile>(); + test_11_aliasing_reset_<T volatile, U volatile>(); + test_11_aliasing_reset_<T const volatile, U volatile>(); +} + +static void aliasing_reset() +{ + test_01_aliasing_reset<int, int>(); + test_10_aliasing_reset<int, int>(); + test_11_aliasing_reset<int, int>(); + + test_01_aliasing_reset<void, int>(); + + test_10_aliasing_reset<int, void>(); + + test_10_aliasing_reset<int, incomplete>(); + + test_01_aliasing_reset<X, X>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing_reset<X, X>(); + BOOST_TEST( X::instances == 0 ); + + test_11_aliasing_reset<X, X>(); + BOOST_TEST( X::instances == 0 ); + + test_01_aliasing_reset<int, X>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing_reset<int, X>(); + BOOST_TEST( X::instances == 0 ); + + test_11_aliasing_reset<int, X>(); + BOOST_TEST( X::instances == 0 ); + + test_01_aliasing_reset<X, int>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing_reset<X, int>(); + BOOST_TEST( X::instances == 0 ); + + test_11_aliasing_reset<X, int>(); + BOOST_TEST( X::instances == 0 ); + + test_01_aliasing_reset<void, X>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing_reset<X, void>(); + BOOST_TEST( X::instances == 0 ); + + test_10_aliasing_reset<X, incomplete>(); + BOOST_TEST( X::instances == 0 ); +} + +// element access + +template<class T> static void empty_element_access_() +{ + boost::local_shared_ptr<T> p1; + + BOOST_TEST_EQ( p1.operator->(), static_cast<T*>(0) ); + BOOST_TEST_EQ( p1.get(), static_cast<T*>(0) ); + BOOST_TEST( p1? false: true ); + BOOST_TEST( !p1 ); + BOOST_TEST_EQ( p1.local_use_count(), 0 ); +} + +template<class T> static void empty_element_access() +{ + empty_element_access_<T>(); + empty_element_access_<T const>(); + empty_element_access_<T volatile>(); + empty_element_access_<T const volatile>(); +} + +template<class T> static void new_element_access_() +{ + { + T * p0 = new T(); + boost::local_shared_ptr<T> p1( p0 ); + + BOOST_TEST_EQ( p1.operator->(), p0 ); + BOOST_TEST_EQ( p1.get(), p0 ); + BOOST_TEST_EQ( &*p1, p0 ); + BOOST_TEST( p1? true: false ); + BOOST_TEST_NOT( !p1 ); + BOOST_TEST_EQ( p1.local_use_count(), 1 ); + } + + { + T * p0 = new T[3](); + boost::local_shared_ptr<T[]> p1( p0 ); + + BOOST_TEST_EQ( p1.get(), p0 ); + + BOOST_TEST_EQ( &p1[0], &p0[0] ); + BOOST_TEST_EQ( &p1[1], &p0[1] ); + BOOST_TEST_EQ( &p1[2], &p0[2] ); + + BOOST_TEST( p1? true: false ); + BOOST_TEST_NOT( !p1 ); + BOOST_TEST_EQ( p1.local_use_count(), 1 ); + } + + { + T * p0 = new T[3](); + boost::local_shared_ptr<T[3]> p1( p0 ); + + BOOST_TEST_EQ( p1.get(), p0 ); + + BOOST_TEST_EQ( &p1[0], &p0[0] ); + BOOST_TEST_EQ( &p1[1], &p0[1] ); + BOOST_TEST_EQ( &p1[2], &p0[2] ); + + BOOST_TEST( p1? true: false ); + BOOST_TEST_NOT( !p1 ); + BOOST_TEST_EQ( p1.local_use_count(), 1 ); + } +} + +template<class T> static void new_element_access() +{ + new_element_access_<T>(); + new_element_access_<T const>(); + new_element_access_<T volatile>(); + new_element_access_<T const volatile>(); +} + +static void element_access() +{ + empty_element_access<int>(); + empty_element_access<X>(); + + BOOST_TEST( X::instances == 0 ); + + empty_element_access<incomplete>(); + empty_element_access<void>(); + + new_element_access<int>(); + new_element_access<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// shared_ptr conversion + +template<class T, class U> static void empty_shared_ptr_conversion_() +{ + boost::local_shared_ptr<T> p1; + boost::shared_ptr<U> p2( p1 ); + + BOOST_TEST_EQ( p2.get(), static_cast<U*>(0) ); + BOOST_TEST_EQ( p2.use_count(), 0 ); +} + +template<class T> static void empty_shared_ptr_conversion() +{ + empty_shared_ptr_conversion_<T, T>(); + empty_shared_ptr_conversion_<T, T const>(); + empty_shared_ptr_conversion_<T, T volatile>(); + empty_shared_ptr_conversion_<T, T const volatile>(); + + empty_shared_ptr_conversion_<T const, T const>(); + empty_shared_ptr_conversion_<T volatile, T volatile>(); + empty_shared_ptr_conversion_<T const volatile, T const volatile>(); + + empty_shared_ptr_conversion_<T, void>(); + empty_shared_ptr_conversion_<T, void const>(); + empty_shared_ptr_conversion_<T, void volatile>(); + empty_shared_ptr_conversion_<T, void const volatile>(); + + empty_shared_ptr_conversion_<T const, void const>(); + empty_shared_ptr_conversion_<T volatile, void volatile>(); + empty_shared_ptr_conversion_<T const volatile, void const volatile>(); +} + +template<class T, class U> static void new_shared_ptr_conversion_() +{ + boost::local_shared_ptr<T> p1( new T() ); + boost::shared_ptr<U> p2( p1 ); + + BOOST_TEST_EQ( p2.get(), p1.get() ); + BOOST_TEST_EQ( p2.use_count(), 2 ); + + boost::shared_ptr<U> p3( p1 ); + + BOOST_TEST_EQ( p3.get(), p1.get() ); + BOOST_TEST_EQ( p3.use_count(), 3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + BOOST_TEST_EQ( p1.local_use_count(), 1 ); + + p1.reset(); + + BOOST_TEST_EQ( p2.use_count(), 2 ); + BOOST_TEST_EQ( p3.use_count(), 2 ); +} + +template<class T> static void new_shared_ptr_conversion() +{ + new_shared_ptr_conversion_<T, T>(); + new_shared_ptr_conversion_<T, T const>(); + new_shared_ptr_conversion_<T, T volatile>(); + new_shared_ptr_conversion_<T, T const volatile>(); + + new_shared_ptr_conversion_<T const, T const>(); + new_shared_ptr_conversion_<T volatile, T volatile>(); + new_shared_ptr_conversion_<T const volatile, T const volatile>(); + + new_shared_ptr_conversion_<T, void>(); + new_shared_ptr_conversion_<T, void const>(); + new_shared_ptr_conversion_<T, void volatile>(); + new_shared_ptr_conversion_<T, void const volatile>(); + + new_shared_ptr_conversion_<T const, void const>(); + new_shared_ptr_conversion_<T volatile, void volatile>(); + new_shared_ptr_conversion_<T const volatile, void const volatile>(); +} + +static void shared_ptr_conversion() +{ + empty_shared_ptr_conversion<void>(); + empty_shared_ptr_conversion<incomplete>(); + empty_shared_ptr_conversion<int>(); + empty_shared_ptr_conversion<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_shared_ptr_conversion<int>(); + new_shared_ptr_conversion<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// weak_ptr conversion + +template<class T, class U> static void empty_weak_ptr_conversion_() +{ + boost::local_shared_ptr<T> p1; + boost::weak_ptr<U> p2( p1 ); + + BOOST_TEST_EQ( p2.lock().get(), static_cast<U*>(0) ); + BOOST_TEST_EQ( p2.use_count(), 0 ); +} + +template<class T> static void empty_weak_ptr_conversion() +{ + empty_weak_ptr_conversion_<T, T>(); + empty_weak_ptr_conversion_<T, T const>(); + empty_weak_ptr_conversion_<T, T volatile>(); + empty_weak_ptr_conversion_<T, T const volatile>(); + + empty_weak_ptr_conversion_<T const, T const>(); + empty_weak_ptr_conversion_<T volatile, T volatile>(); + empty_weak_ptr_conversion_<T const volatile, T const volatile>(); + + empty_weak_ptr_conversion_<T, void>(); + empty_weak_ptr_conversion_<T, void const>(); + empty_weak_ptr_conversion_<T, void volatile>(); + empty_weak_ptr_conversion_<T, void const volatile>(); + + empty_weak_ptr_conversion_<T const, void const>(); + empty_weak_ptr_conversion_<T volatile, void volatile>(); + empty_weak_ptr_conversion_<T const volatile, void const volatile>(); +} + +template<class T, class U> static void new_weak_ptr_conversion_() +{ + boost::local_shared_ptr<T> p1( new T() ); + boost::weak_ptr<U> p2( p1 ); + + BOOST_TEST_EQ( p2.lock().get(), p1.get() ); + BOOST_TEST_EQ( p2.use_count(), 1 ); + + boost::weak_ptr<U> p3( p1 ); + + BOOST_TEST_EQ( p3.lock().get(), p1.get() ); + BOOST_TEST_EQ( p3.use_count(), 1 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + BOOST_TEST_EQ( p1.local_use_count(), 1 ); + + p1.reset(); + + BOOST_TEST_EQ( p2.use_count(), 0 ); + BOOST_TEST_EQ( p3.use_count(), 0 ); +} + +template<class T> static void new_weak_ptr_conversion() +{ + new_weak_ptr_conversion_<T, T>(); + new_weak_ptr_conversion_<T, T const>(); + new_weak_ptr_conversion_<T, T volatile>(); + new_weak_ptr_conversion_<T, T const volatile>(); + + new_weak_ptr_conversion_<T const, T const>(); + new_weak_ptr_conversion_<T volatile, T volatile>(); + new_weak_ptr_conversion_<T const volatile, T const volatile>(); + + new_weak_ptr_conversion_<T, void>(); + new_weak_ptr_conversion_<T, void const>(); + new_weak_ptr_conversion_<T, void volatile>(); + new_weak_ptr_conversion_<T, void const volatile>(); + + new_weak_ptr_conversion_<T const, void const>(); + new_weak_ptr_conversion_<T volatile, void volatile>(); + new_weak_ptr_conversion_<T const volatile, void const volatile>(); +} + +static void weak_ptr_conversion() +{ + empty_weak_ptr_conversion<void>(); + empty_weak_ptr_conversion<incomplete>(); + empty_weak_ptr_conversion<int>(); + empty_weak_ptr_conversion<X>(); + + BOOST_TEST( X::instances == 0 ); + + new_weak_ptr_conversion<int>(); + new_weak_ptr_conversion<X>(); + + BOOST_TEST( X::instances == 0 ); +} + +// main + +int main() +{ + default_constructor(); + nullptr_constructor(); + pointer_constructor(); + deleter_constructor(); + copy_constructor(); + move_constructor(); + aliasing_constructor(); + nullptr_deleter_constructor(); + allocator_constructor(); + nullptr_allocator_constructor(); + shared_ptr_copy_constructor(); + shared_ptr_move_constructor(); + unique_ptr_constructor(); + + copy_assignment(); + move_assignment(); + nullptr_assignment(); + shared_ptr_copy_assignment(); + shared_ptr_move_assignment(); + unique_ptr_assignment(); + + default_reset(); + pointer_reset(); + deleter_reset(); + allocator_reset(); + aliasing_reset(); + + element_access(); + shared_ptr_conversion(); + weak_ptr_conversion(); + // swap_test(); + // owner_before_test(); + // equal_test(); + // operator< ? + // casts + // get_pointer + // operator<< + // hash + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lsp_array_cast_test.cpp b/src/boost/libs/smart_ptr/test/lsp_array_cast_test.cpp new file mode 100644 index 00000000..183cddc0 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lsp_array_cast_test.cpp @@ -0,0 +1,202 @@ +// +// lsp_array_cast_test.cpp +// +// Copyright 2012, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct X +{ +}; + +void static_cast_test() +{ + { + boost::local_shared_ptr<void> pv; + + boost::local_shared_ptr<int[]> pi = boost::static_pointer_cast<int[]>( pv ); + BOOST_TEST( pi.get() == 0 ); + + boost::local_shared_ptr<int[3]> pi2 = boost::static_pointer_cast<int[3]>( pv ); + BOOST_TEST( pi2.get() == 0 ); + + boost::local_shared_ptr<X[]> px = boost::static_pointer_cast<X[]>( pv ); + BOOST_TEST( px.get() == 0 ); + + boost::local_shared_ptr<X[5]> px2 = boost::static_pointer_cast<X[5]>( pv ); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::local_shared_ptr<int[]> pi( new int[2] ); + boost::local_shared_ptr<void> pv( pi ); + + boost::local_shared_ptr<int[]> pi2 = boost::static_pointer_cast<int[]>( pv ); + BOOST_TEST(pi.get() == pi2.get()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); + + boost::local_shared_ptr<int[2]> pi3 = boost::static_pointer_cast<int[2]>( pv ); + BOOST_TEST(pi.get() == pi3.get()); + BOOST_TEST(!(pi < pi3 || pi3 < pi)); + + boost::local_shared_ptr<void> pv2( pi3 ); + + boost::local_shared_ptr<int[]> pi4 = boost::static_pointer_cast<int[]>( pv2 ); + BOOST_TEST(pi.get() == pi4.get()); + BOOST_TEST(!(pi < pi4 || pi4 < pi)); + } + + { + boost::local_shared_ptr<X[]> px( new X[4] ); + boost::local_shared_ptr<void> pv( px ); + + boost::local_shared_ptr<X[]> px2 = boost::static_pointer_cast<X[]>( pv ); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + + boost::local_shared_ptr<X[4]> px3 = boost::static_pointer_cast<X[4]>( pv ); + BOOST_TEST(px.get() == px3.get()); + BOOST_TEST(!(px < px3 || px3 < px)); + + boost::local_shared_ptr<void> pv2( px3 ); + + boost::local_shared_ptr<X[]> px4 = boost::static_pointer_cast<X[]>( pv2 ); + BOOST_TEST(px.get() == px4.get()); + BOOST_TEST(!(px < px4 || px4 < px)); + } +} + +void const_cast_test() +{ + { + boost::local_shared_ptr<int const volatile[]> px; + + boost::local_shared_ptr<int[]> px2 = boost::const_pointer_cast<int[]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::local_shared_ptr<int const volatile[2]> px; + + boost::local_shared_ptr<int[2]> px2 = boost::const_pointer_cast<int[2]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::local_shared_ptr<X const volatile[]> px; + + boost::local_shared_ptr<X[]> px2 = boost::const_pointer_cast<X[]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::local_shared_ptr<X const volatile[5]> px; + + boost::local_shared_ptr<X[5]> px2 = boost::const_pointer_cast<X[5]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::local_shared_ptr<int const volatile[]> px( new int[3] ); + + boost::local_shared_ptr<int[]> px2 = boost::const_pointer_cast<int[]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::local_shared_ptr<int const volatile[3]> px( new int[3] ); + + boost::local_shared_ptr<int[3]> px2 = boost::const_pointer_cast<int[3]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::local_shared_ptr<X const volatile[]> px( new X[4] ); + + boost::local_shared_ptr<X[]> px2 = boost::const_pointer_cast<X[]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::local_shared_ptr<X const volatile[4]> px( new X[4] ); + + boost::local_shared_ptr<X[4]> px2 = boost::const_pointer_cast<X[4]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } +} + +void reinterpret_cast_test() +{ + { + boost::local_shared_ptr<int[]> pi; + BOOST_TEST( pi.get() == 0 ); + + boost::local_shared_ptr<int[3]> pi2 = boost::reinterpret_pointer_cast<int[3]>( pi ); + BOOST_TEST( pi2.get() == 0 ); + + boost::local_shared_ptr<int[6]> pi3 = boost::reinterpret_pointer_cast<int[6]>( pi2 ); + BOOST_TEST( pi3.get() == 0 ); + } + + { + boost::local_shared_ptr<X[]> px; + BOOST_TEST( px.get() == 0 ); + + boost::local_shared_ptr<X[5]> px2 = boost::reinterpret_pointer_cast<X[5]>( px ); + BOOST_TEST( px2.get() == 0 ); + + boost::local_shared_ptr<X[9]> px3 = boost::reinterpret_pointer_cast<X[9]>( px2 ); + BOOST_TEST( px3.get() == 0 ); + } + + { + boost::local_shared_ptr<int[]> pi( new int[2] ); + + boost::local_shared_ptr<int[2]> pi2 = boost::reinterpret_pointer_cast<int[2]>( pi ); + BOOST_TEST(pi.get() == pi2.get()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); + + boost::local_shared_ptr<int[1]> pi3 = boost::reinterpret_pointer_cast<int[1]>( pi2 ); + BOOST_TEST(pi.get() == pi3.get()); + BOOST_TEST(!(pi < pi3 || pi3 < pi)); + + boost::local_shared_ptr<int[]> pi4 = boost::reinterpret_pointer_cast<int[]>( pi3 ); + BOOST_TEST(pi.get() == pi4.get()); + BOOST_TEST(!(pi < pi4 || pi4 < pi)); + } + + { + boost::local_shared_ptr<X[]> px( new X[4] ); + + boost::local_shared_ptr<X[7]> px2 = boost::reinterpret_pointer_cast<X[7]>( px ); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + + boost::local_shared_ptr<X[4]> px3 = boost::reinterpret_pointer_cast<X[4]>( px2 ); + BOOST_TEST(px.get() == px3.get()); + BOOST_TEST(!(px < px3 || px3 < px)); + + boost::local_shared_ptr<X[]> px4 = boost::reinterpret_pointer_cast<X[]>( px3 ); + BOOST_TEST(px.get() == px4.get()); + BOOST_TEST(!(px < px4 || px4 < px)); + } +} + +int main() +{ + static_cast_test(); + const_cast_test(); + reinterpret_cast_test(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lsp_array_cv_test.cpp b/src/boost/libs/smart_ptr/test/lsp_array_cv_test.cpp new file mode 100644 index 00000000..869d2067 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lsp_array_cv_test.cpp @@ -0,0 +1,60 @@ +// +// lsp_array_cv_test.cpp +// +// Copyright 2012, 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 <boost/smart_ptr/local_shared_ptr.hpp> + +struct X +{ +}; + +class B +{ +}; + +class D: public B +{ +}; + +#define TEST_CONV( T, U ) \ + { \ + boost::local_shared_ptr< T > p1; \ + boost::local_shared_ptr< U > p2( p1 ); \ + p2 = p1; \ + boost::local_shared_ptr< U > p3 = boost::local_shared_ptr< T >(); \ + p3 = boost::local_shared_ptr< T >(); \ + } + +#define TEST_CV_TRUE( T, U ) \ + TEST_CONV( T, U ) \ + TEST_CONV( T, const U ) \ + TEST_CONV( T, volatile U ) \ + TEST_CONV( T, const volatile U ) \ + TEST_CONV( const T, const U ) \ + TEST_CONV( const T, const volatile U ) \ + TEST_CONV( volatile T, volatile U ) \ + TEST_CONV( volatile T, const volatile U ) \ + TEST_CONV( const volatile T, const volatile U ) + +int main() +{ + TEST_CV_TRUE( X, X ) + TEST_CV_TRUE( X, void ) + TEST_CV_TRUE( D, B ) + + TEST_CV_TRUE( X[], X[] ) + TEST_CV_TRUE( X[3], X[3] ) + + TEST_CV_TRUE( X[3], X[] ) + + TEST_CV_TRUE( X[], void ) + TEST_CV_TRUE( X[3], void ) + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/lsp_array_n_test.cpp b/src/boost/libs/smart_ptr/test/lsp_array_n_test.cpp new file mode 100644 index 00000000..a31e2646 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lsp_array_n_test.cpp @@ -0,0 +1,248 @@ +// +// lsp_array_n_test.cpp +// +// Copyright 2012, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> +#include <utility> + +class X: public boost::enable_shared_from_this< X > +{ +public: + + static int allocations; + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + void* operator new[]( std::size_t n ) + { + ++allocations; + return ::operator new[]( n ); + } + + void operator delete[]( void* p ) + { + --allocations; + ::operator delete[]( p ); + } + +private: + + X( X const& ); + X& operator=( X const& ); +}; + +int X::allocations = 0; +int X::instances = 0; + +template< class T> class array_deleter +{ +public: + + static int calls; + + void operator()( T * p ) const + { + ++calls; + delete[] p; + } + +private: + + template< class Y > void operator()( Y * p ) const; +}; + +template< class T > int array_deleter< T >::calls = 0; + +int main() +{ + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr<X[3]> px; + BOOST_TEST( !px ); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + boost::local_shared_ptr<X[3]> px2( new X[ 3 ] ); + BOOST_TEST( px2 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + { + X & rx = px2[ 0 ]; + BOOST_TEST( &rx == px2.get() ); + } + + boost::local_shared_ptr<X const[3]> px3( px2 ); + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + { + X const & rx = px3[ 1 ]; + BOOST_TEST( &rx == px3.get() + 1 ); + } + + px3.reset(); + px3 = px2; + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + boost::local_shared_ptr<X volatile[3]> px4( px2 ); + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + { + X volatile & rx = px4[ 2 ]; + BOOST_TEST( &rx == px4.get() + 2 ); + } + + px4.reset(); + px4 = px2; + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + boost::local_shared_ptr<void> px5( px2 ); + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + px5.reset(); + px5 = px2; + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + boost::weak_ptr<X[3]> wp( px ); + BOOST_TEST( wp.lock() == px ); + + boost::weak_ptr<X[3]> wp2( px2 ); + BOOST_TEST( wp2.lock() == px2 ); + + wp2.reset(); + wp2 = px2; + BOOST_TEST( wp2.lock() == px2 ); + + boost::weak_ptr<X const[3]> wp3( px2 ); + BOOST_TEST( wp3.lock() == px2 ); + + wp3.reset(); + wp3 = px2; + BOOST_TEST( wp3.lock() == px2 ); + + boost::weak_ptr<X volatile[3]> wp4( px2 ); + BOOST_TEST( wp4.lock() == px2 ); + + wp4.reset(); + wp4 = px2; + BOOST_TEST( wp4.lock() == px2 ); + + boost::weak_ptr<void> wp5( px2 ); + BOOST_TEST( wp5.lock() == px2 ); + + wp5.reset(); + wp5 = px2; + BOOST_TEST( wp5.lock() == px2 ); + + px2.reset(); + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + px3.reset(); + px4.reset(); + px5.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( wp2.lock() == 0 ); + BOOST_TEST( wp3.lock() == 0 ); + BOOST_TEST( wp4.lock() == 0 ); + BOOST_TEST( wp5.lock() == 0 ); + } + + { + boost::local_shared_ptr<X[5]> px( new X[ 5 ], array_deleter< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 5 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 1 ); + } + + { + boost::local_shared_ptr<X[6]> px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 6 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 2 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lsp_array_test.cpp b/src/boost/libs/smart_ptr/test/lsp_array_test.cpp new file mode 100644 index 00000000..77728ea2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lsp_array_test.cpp @@ -0,0 +1,311 @@ +// +// lsp_array_test.cpp +// +// Copyright 2012, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> +#include <utility> + +class X: public boost::enable_shared_from_this< X > +{ +public: + + static int allocations; + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + void* operator new[]( std::size_t n ) + { + ++allocations; + return ::operator new[]( n ); + } + + void operator delete[]( void* p ) + { + --allocations; + ::operator delete[]( p ); + } + +private: + + X( X const& ); + X& operator=( X const& ); +}; + +int X::allocations = 0; +int X::instances = 0; + +template< class T> class array_deleter +{ +public: + + static int calls; + + void operator()( T * p ) const + { + ++calls; + delete[] p; + } + +private: + + template< class Y > void operator()( Y * p ) const; +}; + +template< class T > int array_deleter< T >::calls = 0; + +int main() +{ + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr<X[]> px; + BOOST_TEST( !px ); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + boost::local_shared_ptr<X[]> px2( new X[ 3 ] ); + BOOST_TEST( px2 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + { + X & rx = px2[ 0 ]; + BOOST_TEST( &rx == px2.get() ); + } + + boost::local_shared_ptr<X const[]> px3( px2 ); + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + { + X const & rx = px3[ 1 ]; + BOOST_TEST( &rx == px3.get() + 1 ); + } + + px3.reset(); + px3 = px2; + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + boost::local_shared_ptr<X volatile[]> px4( px2 ); + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + { + X volatile & rx = px4[ 2 ]; + BOOST_TEST( &rx == px4.get() + 2 ); + } + + px4.reset(); + px4 = px2; + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + boost::local_shared_ptr<void> px5( px2 ); + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + px5.reset(); + px5 = px2; + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + boost::weak_ptr<X[]> wp( px ); + BOOST_TEST( wp.lock() == px ); + + boost::weak_ptr<X[]> wp2( px2 ); + BOOST_TEST( wp2.lock() == px2 ); + + wp2.reset(); + wp2 = px2; + BOOST_TEST( wp2.lock() == px2 ); + + boost::weak_ptr<X const[]> wp3( px2 ); + BOOST_TEST( wp3.lock() == px2 ); + + wp3.reset(); + wp3 = px2; + BOOST_TEST( wp3.lock() == px2 ); + + boost::weak_ptr<X volatile[]> wp4( px2 ); + BOOST_TEST( wp4.lock() == px2 ); + + wp4.reset(); + wp4 = px2; + BOOST_TEST( wp4.lock() == px2 ); + + boost::weak_ptr<void> wp5( px2 ); + BOOST_TEST( wp5.lock() == px2 ); + + wp5.reset(); + wp5 = px2; + BOOST_TEST( wp5.lock() == px2 ); + + px2.reset(); + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + px3.reset(); + px4.reset(); + px5.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( wp2.lock() == 0 ); + BOOST_TEST( wp3.lock() == 0 ); + BOOST_TEST( wp4.lock() == 0 ); + BOOST_TEST( wp5.lock() == 0 ); + } + +#if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + + { + std::unique_ptr<X[]> px( new X[ 4 ] ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + + boost::local_shared_ptr<X[]> px2( std::move( px ) ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + BOOST_TEST( px.get() == 0 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px2.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + } + + { + std::unique_ptr<X[]> px( new X[ 4 ] ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + + boost::local_shared_ptr<X[]> px2; + px2 = std::move( px ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + BOOST_TEST( px.get() == 0 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px2.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + } + +#endif + + { + boost::local_shared_ptr<X[]> px( new X[ 5 ], array_deleter< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 5 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 1 ); + } + + { + boost::local_shared_ptr<X[]> px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 6 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 2 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lsp_convertible_test.cpp b/src/boost/libs/smart_ptr/test/lsp_convertible_test.cpp new file mode 100644 index 00000000..4f5017a6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lsp_convertible_test.cpp @@ -0,0 +1,108 @@ +#include <boost/config.hpp> + +// lsp_convertible_test.cpp +// +// Copyright 2012, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/type_traits/is_convertible.hpp> + +// + +class X; + +class B +{ +}; + +class D: public B +{ +}; + +using boost::is_convertible; + +#define TEST_CV_TRUE_( S1, T, S2, U ) \ + BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == true )); + +#define TEST_CV_FALSE_( S1, T, S2, U ) \ + BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == false )); + +using boost::local_shared_ptr; +using boost::shared_ptr; +using boost::weak_ptr; + +#define TEST_CV_TRUE( T, U ) \ + TEST_CV_TRUE_( local_shared_ptr, T, local_shared_ptr, U ) \ + TEST_CV_TRUE_( shared_ptr, T, local_shared_ptr, U ) + +#define TEST_CV_FALSE( T, U ) \ + TEST_CV_FALSE_( local_shared_ptr, T, local_shared_ptr, U ) \ + TEST_CV_FALSE_( shared_ptr, T, local_shared_ptr, U ) + +int main() +{ +#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) + + TEST_CV_TRUE( X, X ) + TEST_CV_TRUE( X, void ) + TEST_CV_FALSE( void, X ) + TEST_CV_TRUE( D, B ) + TEST_CV_FALSE( B, D ) + + TEST_CV_TRUE( X[], X[] ) + TEST_CV_FALSE( D[], B[] ) + + TEST_CV_TRUE( X[3], X[3] ) + TEST_CV_FALSE( X[3], X[4] ) + TEST_CV_FALSE( D[3], B[3] ) + + TEST_CV_TRUE( X[3], X[] ) + TEST_CV_FALSE( X[], X[3] ) + + TEST_CV_TRUE( X[], void ) + TEST_CV_FALSE( void, X[] ) + + TEST_CV_TRUE( X[3], void ) + TEST_CV_FALSE( void, X[3] ) + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lsp_convertible_test2.cpp b/src/boost/libs/smart_ptr/test/lsp_convertible_test2.cpp new file mode 100644 index 00000000..2104b4e6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lsp_convertible_test2.cpp @@ -0,0 +1,108 @@ +#include <boost/config.hpp> + +// lsp_convertible_test.cpp +// +// Copyright 2012, 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 <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/type_traits/is_convertible.hpp> + +// + +class X; + +class B +{ +}; + +class D: public B +{ +}; + +using boost::is_convertible; + +#define TEST_CV_TRUE_( S1, T, S2, U ) \ + BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == true )); + +#define TEST_CV_FALSE_( S1, T, S2, U ) \ + BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == false )); + +using boost::local_shared_ptr; +using boost::shared_ptr; +using boost::weak_ptr; + +#define TEST_CV_TRUE( T, U ) \ + TEST_CV_TRUE_( local_shared_ptr, T, shared_ptr, U ) \ + TEST_CV_TRUE_( local_shared_ptr, T, weak_ptr, U ) + +#define TEST_CV_FALSE( T, U ) \ + TEST_CV_FALSE_( local_shared_ptr, T, shared_ptr, U ) \ + TEST_CV_FALSE_( local_shared_ptr, T, weak_ptr, U ) + +int main() +{ +#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) + + TEST_CV_TRUE( X, X ) + TEST_CV_TRUE( X, void ) + TEST_CV_FALSE( void, X ) + TEST_CV_TRUE( D, B ) + TEST_CV_FALSE( B, D ) + + TEST_CV_TRUE( X[], X[] ) + TEST_CV_FALSE( D[], B[] ) + + TEST_CV_TRUE( X[3], X[3] ) + TEST_CV_FALSE( X[3], X[4] ) + TEST_CV_FALSE( D[3], B[3] ) + + TEST_CV_TRUE( X[3], X[] ) + TEST_CV_FALSE( X[], X[3] ) + + TEST_CV_TRUE( X[], void ) + TEST_CV_FALSE( void, X[] ) + + TEST_CV_TRUE( X[3], void ) + TEST_CV_FALSE( void, X[3] ) + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lw_mutex_test.cpp b/src/boost/libs/smart_ptr/test/lw_mutex_test.cpp new file mode 100644 index 00000000..a47ac1e9 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lw_mutex_test.cpp @@ -0,0 +1,28 @@ +// +// lw_mutex_test.cpp +// +// Copyright 2005 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 <boost/detail/lightweight_mutex.hpp> + +// Sanity check only + +boost::detail::lightweight_mutex m1; + +int main() +{ + boost::detail::lightweight_mutex::scoped_lock lock1( m1 ); + + boost::detail::lightweight_mutex m2; + boost::detail::lightweight_mutex m3; + + boost::detail::lightweight_mutex::scoped_lock lock2( m2 ); + boost::detail::lightweight_mutex::scoped_lock lock3( m3 ); + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/lw_thread_test.cpp b/src/boost/libs/smart_ptr/test/lw_thread_test.cpp new file mode 100644 index 00000000..1fe22749 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lw_thread_test.cpp @@ -0,0 +1,36 @@ + +// lw_thread_test.cpp +// +// Copyright 2018 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. + +#include <boost/detail/lightweight_thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/detail/atomic_count.hpp> + +boost::detail::atomic_count count( 0 ); + +void f() +{ + ++count; +} + +int main() +{ + int const N = 4; + boost::detail::lw_thread_t th[ N ] = {}; + + for( int i = 0; i < N; ++i ) + { + boost::detail::lw_thread_create( th[ i ], f ); + } + + for( int i = 0; i < N; ++i ) + { + boost::detail::lw_thread_join( th[ i ] ); + } + + BOOST_TEST_EQ( count, N ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/lwm_win32_cs_test.cpp b/src/boost/libs/smart_ptr/test/lwm_win32_cs_test.cpp new file mode 100644 index 00000000..cd8be86b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/lwm_win32_cs_test.cpp @@ -0,0 +1,18 @@ +// +// lwm_win32_cs_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) +// + +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# include <windows.h> +# include <boost/smart_ptr/detail/lwm_win32_cs.hpp> +#endif + +int main() +{ +} diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_array_esft_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_array_esft_test.cpp new file mode 100644 index 00000000..5106f39e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_array_esft_test.cpp @@ -0,0 +1,66 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/enable_shared_from_this.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +class type + : public boost::enable_shared_from_this<type> { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + { + boost::local_shared_ptr<type[]> result = + boost::make_local_shared<type[]>(3); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + BOOST_TEST(type::instances == 0); + { + boost::local_shared_ptr<type[3]> result = + boost::make_local_shared_noinit<type[3]>(); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_array_noinit_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_array_noinit_test.cpp new file mode 100644 index 00000000..f4a07a2f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_array_noinit_test.cpp @@ -0,0 +1,216 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::local_shared_ptr<int[]> result = + boost::make_local_shared_noinit<int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<int[3]> result = + boost::make_local_shared_noinit<int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<int[][2]> result = + boost::make_local_shared_noinit<int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<int[2][2]> result = + boost::make_local_shared_noinit<int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[]> result = + boost::make_local_shared_noinit<const int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[3]> result = + boost::make_local_shared_noinit<const int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[][2]> result = + boost::make_local_shared_noinit<const int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<const int[2][2]> result = + boost::make_local_shared_noinit<const int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::local_shared_ptr<type[]> result = + boost::make_local_shared_noinit<type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[3]> result = + boost::make_local_shared_noinit<type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[][2]> result = + boost::make_local_shared_noinit<type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[2][2]> result = + boost::make_local_shared_noinit<type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[]> result = + boost::make_local_shared_noinit<const type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[3]> result = + boost::make_local_shared_noinit<const type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[][2]> result = + boost::make_local_shared_noinit<const type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[2][2]> result = + boost::make_local_shared_noinit<const type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_array_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_array_test.cpp new file mode 100644 index 00000000..2781763c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_array_test.cpp @@ -0,0 +1,238 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::local_shared_ptr<int[]> result = + boost::make_local_shared<int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<int[3]> result = + boost::make_local_shared<int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<int[][2]> result = + boost::make_local_shared<int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<int[2][2]> result = + boost::make_local_shared<int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<const int[]> result = + boost::make_local_shared<const int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<const int[3]> result = + boost::make_local_shared<const int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::local_shared_ptr<const int[][2]> result = + boost::make_local_shared<const int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<const int[2][2]> result = + boost::make_local_shared<const int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::local_shared_ptr<type[]> result = + boost::make_local_shared<type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[3]> result = + boost::make_local_shared<type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[][2]> result = + boost::make_local_shared<type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<type[2][2]> result = + boost::make_local_shared<type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[]> result = + boost::make_local_shared<const type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[3]> result = + boost::make_local_shared<const type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[][2]> result = + boost::make_local_shared<const type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::local_shared_ptr<const type[2][2]> result = + boost::make_local_shared<const type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.local_use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_array_throws_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_array_throws_test.cpp new file mode 100644 index 00000000..e1841dff --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_array_throws_test.cpp @@ -0,0 +1,93 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +class type { +public: + static unsigned instances; + + type() { + if (instances == 5) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + try { + boost::make_local_shared<type[]>(6); + BOOST_ERROR("make_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared<type[][2]>(3); + BOOST_ERROR("make_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared<type[6]>(); + BOOST_ERROR("make_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared<type[3][2]>(); + BOOST_ERROR("make_local_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared_noinit<type[]>(6); + BOOST_ERROR("make_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared_noinit<type[][2]>(3); + BOOST_ERROR("make_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared_noinit<type[6]>(); + BOOST_ERROR("make_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_local_shared_noinit<type[3][2]>(); + BOOST_ERROR("make_local_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_array_value_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_array_value_test.cpp new file mode 100644 index 00000000..ab074601 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_array_value_test.cpp @@ -0,0 +1,55 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +int main() +{ + { + boost::local_shared_ptr<int[]> result = + boost::make_local_shared<int[]>(4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::local_shared_ptr<int[4]> result = + boost::make_local_shared<int[4]>(1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::local_shared_ptr<const int[]> result = + boost::make_local_shared<const int[]>(4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::local_shared_ptr<const int[4]> result = + boost::make_local_shared<const int[4]>(1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_arrays_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_arrays_test.cpp new file mode 100644 index 00000000..986b88f6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_arrays_test.cpp @@ -0,0 +1,56 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ + !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> + +int main() +{ + { + boost::local_shared_ptr<int[][2]> result = + boost::make_local_shared<int[][2]>(2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::local_shared_ptr<int[2][2]> result = + boost::make_local_shared<int[2][2]>({0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::local_shared_ptr<const int[][2]> result = + boost::make_local_shared<const int[][2]>(2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::local_shared_ptr<const int[2][2]> result = + boost::make_local_shared<const int[2][2]>({0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_const_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_const_test.cpp new file mode 100644 index 00000000..a57577e2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_const_test.cpp @@ -0,0 +1,262 @@ +// make_local_shared_const_test.cpp +// +// Copyright 2007-2009, 2017, 2018 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + // lack of this definition causes link errors on Comeau C++ + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + // lack of this definition causes link errors on MSVC + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +template<class T> static long use_count( boost::local_shared_ptr<T> const & p ) +{ + return boost::shared_ptr<T>( p ).use_count() - 1; +} + +int main() +{ + { + boost::local_shared_ptr<int const> pi = boost::make_local_shared<int const>(); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + + BOOST_TEST( *pi == 0 ); + } + + { + boost::local_shared_ptr<int const> pi = boost::make_local_shared<int const>( 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>(); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared_noinit<X const>(); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3, 4 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3, 4, 5 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr<X const> pi = boost::make_local_shared<X const>( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_esft_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_esft_test.cpp new file mode 100644 index 00000000..b5e130ee --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_esft_test.cpp @@ -0,0 +1,308 @@ +// make_local_shared_esft_test.cpp +// +// Copyright 2007-2009, 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> + +class X: public boost::enable_shared_from_this<X> +{ +private: + + X( X const & ); + X & operator=( X const & ); + +public: + + static int instances; + + explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >(); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared_noinit< X >(); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3, 4 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3, 4, 5 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6, 7 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/make_local_shared_test.cpp b/src/boost/libs/smart_ptr/test/make_local_shared_test.cpp new file mode 100644 index 00000000..e972c0d1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_local_shared_test.cpp @@ -0,0 +1,268 @@ +// make_local_shared_test.cpp +// +// Copyright 2007-2009, 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) + +int main() +{ +} + +#else + +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_local_shared.hpp> +#include <boost/smart_ptr/local_shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + // lack of this definition causes link errors on Comeau C++ + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + // lack of this definition causes link errors on MSVC + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +template<class T> static long use_count( boost::local_shared_ptr<T> const & p ) +{ + return boost::shared_ptr<T>( p ).use_count() - 1; +} + +int main() +{ + { + boost::local_shared_ptr< int > pi = boost::make_local_shared< int >(); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + + BOOST_TEST( *pi == 0 ); + } + + { + boost::local_shared_ptr< int > pi = boost::make_local_shared_noinit< int >(); + + BOOST_TEST( pi.get() != 0 ); + } + + { + boost::local_shared_ptr< int > pi = boost::make_local_shared< int >( 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >(); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared_noinit< X >(); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3, 4 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3, 4, 5 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::local_shared_ptr< X > pi = boost::make_local_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.local_use_count() == 1 ); + BOOST_TEST( use_count( pi ) == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/make_shared_array_esft_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_array_esft_test.cpp new file mode 100644 index 00000000..f52e3cfd --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_array_esft_test.cpp @@ -0,0 +1,57 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/enable_shared_from_this.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +class type + : public boost::enable_shared_from_this<type> { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr<type[]> result = + boost::make_shared<type[]>(3); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr<type[3]> result = + boost::make_shared_noinit<type[3]>(); + try { + result[0].shared_from_this(); + BOOST_ERROR("shared_from_this did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 3); + } + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_array_noinit_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_array_noinit_test.cpp new file mode 100644 index 00000000..757e7987 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_array_noinit_test.cpp @@ -0,0 +1,207 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::shared_ptr<int[]> result = + boost::make_shared_noinit<int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<int[3]> result = + boost::make_shared_noinit<int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<int[][2]> result = + boost::make_shared_noinit<int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<int[2][2]> result = + boost::make_shared_noinit<int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[]> result = + boost::make_shared_noinit<const int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[3]> result = + boost::make_shared_noinit<const int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[][2]> result = + boost::make_shared_noinit<const int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<const int[2][2]> result = + boost::make_shared_noinit<const int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + } + { + boost::shared_ptr<type[]> result = + boost::make_shared_noinit<type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[3]> result = + boost::make_shared_noinit<type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[][2]> result = + boost::make_shared_noinit<type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[2][2]> result = + boost::make_shared_noinit<type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[]> result = + boost::make_shared_noinit<const type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[3]> result = + boost::make_shared_noinit<const type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<const type[3]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[][2]> result = + boost::make_shared_noinit<const type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[2][2]> result = + boost::make_shared_noinit<const type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + boost::weak_ptr<const type[2][2]> other = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_array_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_array_test.cpp new file mode 100644 index 00000000..c6bac243 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_array_test.cpp @@ -0,0 +1,229 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/smart_ptr/weak_ptr.hpp> +#include <boost/type_traits/alignment_of.hpp> + +class type { +public: + static unsigned instances; + + type() + : value_(0.0) { + ++instances; + } + + ~type() { + --instances; + } + + void set(long double value) { + value_ = value; + } + + long double get() const { + return value_; + } + +private: + type(const type&); + type& operator=(const type&); + + long double value_; +}; + +unsigned type::instances = 0; + +int main() +{ + { + boost::shared_ptr<int[]> result = + boost::make_shared<int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<int[3]> result = + boost::make_shared<int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<int[][2]> result = + boost::make_shared<int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<int[2][2]> result = + boost::make_shared<int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<const int[]> result = + boost::make_shared<const int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<const int[3]> result = + boost::make_shared<const int[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + boost::shared_ptr<const int[][2]> result = + boost::make_shared<const int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<const int[2][2]> result = + boost::make_shared<const int[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<int>::value)); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + boost::shared_ptr<type[]> result = + boost::make_shared<type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[3]> result = + boost::make_shared<type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + boost::weak_ptr<type[3]> w1 = result; + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[][2]> result = + boost::make_shared<type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<type[2][2]> result = + boost::make_shared<type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[]> result = + boost::make_shared<const type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[3]> result = + boost::make_shared<const type[3]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[][2]> result = + boost::make_shared<const type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + { + boost::shared_ptr<const type[2][2]> result = + boost::make_shared<const type[2][2]>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of<type>::value)); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_array_throws_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_array_throws_test.cpp new file mode 100644 index 00000000..a7543600 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_array_throws_test.cpp @@ -0,0 +1,84 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +class type { +public: + static unsigned instances; + + type() { + if (instances == 5) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + try { + boost::make_shared<type[]>(6); + BOOST_ERROR("make_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared<type[][2]>(3); + BOOST_ERROR("make_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared<type[6]>(); + BOOST_ERROR("make_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared<type[3][2]>(); + BOOST_ERROR("make_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared_noinit<type[]>(6); + BOOST_ERROR("make_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared_noinit<type[][2]>(3); + BOOST_ERROR("make_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared_noinit<type[6]>(); + BOOST_ERROR("make_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + try { + boost::make_shared_noinit<type[3][2]>(); + BOOST_ERROR("make_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_array_tmp_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_array_tmp_test.cpp new file mode 100644 index 00000000..6e776bbb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_array_tmp_test.cpp @@ -0,0 +1,43 @@ +// make_shared_array_tmp_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 <boost/make_shared.hpp> +#include <boost/core/lightweight_test.hpp> + +struct X +{ + static int destroyed; + + ~X() + { + ++destroyed; + } +}; + +int X::destroyed = 0; + +int main() +{ + { + X::destroyed = 0; + + boost::make_shared< X[3] >(); + + BOOST_TEST_EQ( X::destroyed, 3 ); + } + + { + X::destroyed = 0; + + boost::make_shared< X[] >( 3 ); + + BOOST_TEST_EQ( X::destroyed, 3 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_array_value_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_array_value_test.cpp new file mode 100644 index 00000000..44d12d3d --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_array_value_test.cpp @@ -0,0 +1,46 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +int main() +{ + { + boost::shared_ptr<int[]> result = + boost::make_shared<int[]>(4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::shared_ptr<int[4]> result = + boost::make_shared<int[4]>(1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::shared_ptr<const int[]> result = + boost::make_shared<const int[]>(4, 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + { + boost::shared_ptr<const int[4]> result = + boost::make_shared<const int[4]>(1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_arrays_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_arrays_test.cpp new file mode 100644 index 00000000..598b9742 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_arrays_test.cpp @@ -0,0 +1,54 @@ +/* +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +int main() +{ + { + boost::shared_ptr<int[][2]> result = + boost::make_shared<int[][2]>(2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::shared_ptr<int[2][2]> result = + boost::make_shared<int[2][2]>({0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::shared_ptr<const int[][2]> result = + boost::make_shared<const int[][2]>(2, {0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + { + boost::shared_ptr<const int[2][2]> result = + boost::make_shared<const int[2][2]>({0, 1}); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 1); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 1); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_shared_const_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_const_test.cpp new file mode 100644 index 00000000..1802bd28 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_const_test.cpp @@ -0,0 +1,232 @@ +// make_shared_const_test.cpp +// +// Copyright 2007-2009, 2018 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 <boost/core/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + // lack of this definition causes link errors on Comeau C++ + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + // lack of this definition causes link errors on MSVC + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_ptr<int const> pi = boost::make_shared<int const>(); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + + BOOST_TEST( *pi == 0 ); + } + + { + boost::shared_ptr<int const> pi = boost::make_shared<int const>( 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>(); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared_noinit<X const>(); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3, 4 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3, 4, 5 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X const> pi = boost::make_shared<X const>( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X const> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_esft_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_esft_test.cpp new file mode 100644 index 00000000..71b29122 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_esft_test.cpp @@ -0,0 +1,296 @@ +// make_shared_esft_test.cpp +// +// Copyright 2007-2009 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> + +class X: public boost::enable_shared_from_this<X> +{ +private: + + X( X const & ); + X & operator=( X const & ); + +public: + + static int instances; + + explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >(); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared_noinit< X >(); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + + try + { + boost::shared_ptr< X > qx = px->shared_from_this(); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + + px.reset(); + BOOST_TEST( X::instances == 1 ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "px->shared_from_this() failed" ); + } + } + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_fp_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_fp_test.cpp new file mode 100644 index 00000000..f443d346 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_fp_test.cpp @@ -0,0 +1,19 @@ +// +// make_shared_fp_test.cpp +// +// Copyright 2010 Georg Fritzsche +// +// 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 <boost/shared_ptr.hpp> +#include <boost/make_shared.hpp> + +int main() +{ + typedef boost::shared_ptr<int>(*FP)(); + FP fp = boost::make_shared<int>; +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_move_emulation_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_move_emulation_test.cpp new file mode 100644 index 00000000..c607e051 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_move_emulation_test.cpp @@ -0,0 +1,81 @@ +// make_shared_move_emulation_test.cpp - a test of make_shared +// semi-perfect forwarding of constructor arguments when using a C++03 +// compiler with move emulation. +// Note the "semi": it means moving temporaries (real r-values) doesn't work. +// +// Copyright 2016 Giel van Schijndel +// +// 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/move/core.hpp> +#include <boost/move/utility_core.hpp> +#include <boost/shared_ptr.hpp> + +class movearg +{ +private: + BOOST_MOVABLE_BUT_NOT_COPYABLE(movearg) +public: + movearg() + {} + movearg(BOOST_RV_REF(movearg)) + {} + movearg& operator=(BOOST_RV_REF(movearg)) + { + return *this; + } +}; + +class ByVal +{ +public: + ByVal(movearg) {} +}; + +class ByRef +{ +public: + enum constructor_id + { + move_constructor, + const_ref_constructor + }; + + ByRef(BOOST_RV_REF(movearg)): constructed_by_(move_constructor) + {} + ByRef(const movearg &arg): constructed_by_(const_ref_constructor) + {} + + constructor_id constructed_by_; +}; + +int main() +{ + { + movearg a; + boost::shared_ptr< ByVal > x = boost::make_shared< ByVal >(boost::move(a)); + } + { + movearg a; + boost::shared_ptr< ByRef > x = boost::make_shared< ByRef >(boost::move(a)); + BOOST_TEST( x->constructed_by_ == ByRef::move_constructor); + } +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + { + boost::shared_ptr< ByVal > x = boost::make_shared< ByVal >(movearg()); + boost::shared_ptr< ByRef > y = boost::make_shared< ByRef >(movearg()); + BOOST_TEST( y->constructed_by_ == ByRef::move_constructor); + } +#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + { + const movearg ca; + boost::shared_ptr< ByRef > x = boost::make_shared< ByRef >(ca); + BOOST_TEST( x->constructed_by_ == ByRef::const_ref_constructor); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_msvc_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_msvc_test.cpp new file mode 100644 index 00000000..84de4a50 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_msvc_test.cpp @@ -0,0 +1,19 @@ +// +// make_shared_msvc_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 +// + +template<class T> struct value +{ +}; + +#include <boost/make_shared.hpp> + +int main() +{ +} diff --git a/src/boost/libs/smart_ptr/test/make_shared_perfect_forwarding_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_perfect_forwarding_test.cpp new file mode 100644 index 00000000..b7ad05dd --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_perfect_forwarding_test.cpp @@ -0,0 +1,98 @@ +// make_shared_perfect_forwarding_test.cpp - a test of make_shared +// perfect forwarding of constructor arguments when using a C++0x +// compiler. +// +// Copyright 2009 Frank Mori Hess +// +// 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> + +#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#else // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +class myarg +{ +public: + myarg() + {} +private: + myarg(myarg && other) + {} + myarg& operator=(myarg && other) + { + return *this; + } + myarg(const myarg & other) + {} + myarg& operator=(const myarg & other) + { + return *this; + } +}; + +class X +{ +public: + enum constructor_id + { + move_constructor, + const_ref_constructor, + ref_constructor + }; + + X(myarg &&arg): constructed_by_(move_constructor) + {} + X(const myarg &arg): constructed_by_(const_ref_constructor) + {} + X(myarg &arg): constructed_by_(ref_constructor) + {} + + constructor_id constructed_by_; +}; + +struct Y +{ + Y(int &value): ref(value) + {} + int &ref; +}; + +int main() +{ + { + myarg a; + boost::shared_ptr< X > x = boost::make_shared< X >(a); + BOOST_TEST( x->constructed_by_ == X::ref_constructor); + } + { + const myarg ca; + boost::shared_ptr< X > x = boost::make_shared< X >(ca); + BOOST_TEST( x->constructed_by_ == X::const_ref_constructor); + } + { + boost::shared_ptr< X > x = boost::make_shared< X >(myarg()); + BOOST_TEST( x->constructed_by_ == X::move_constructor); + } + { + int value = 1; + boost::shared_ptr< Y > y = boost::make_shared< Y >(value); + BOOST_TEST( y->ref == 1 && value == y->ref ); + ++y->ref; + BOOST_TEST( value == y->ref ); + } + + return boost::report_errors(); +} + +#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) diff --git a/src/boost/libs/smart_ptr/test/make_shared_test.cpp b/src/boost/libs/smart_ptr/test/make_shared_test.cpp new file mode 100644 index 00000000..9e3cdd3f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_shared_test.cpp @@ -0,0 +1,239 @@ +// make_shared_test.cpp +// +// Copyright 2007-2009 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 <boost/detail/lightweight_test.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <cstddef> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + + void * operator new( std::size_t n ) + { + // lack of this definition causes link errors on Comeau C++ + BOOST_ERROR( "private X::new called" ); + return ::operator new( n ); + } + + void operator delete( void * p ) + { + // lack of this definition causes link errors on MSVC + BOOST_ERROR( "private X::delete called" ); + ::operator delete( p ); + } + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_ptr< int > pi = boost::make_shared< int >(); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + + BOOST_TEST( *pi == 0 ); + } + + { + boost::shared_ptr< int > pi = boost::make_shared_noinit< int >(); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + } + + { + boost::shared_ptr< int > pi = boost::make_shared< int >( 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > pi = boost::make_shared< X >(); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared_noinit< X >(); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr<X> wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi.use_count() == 1 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/make_unique_args_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_args_test.cpp new file mode 100644 index 00000000..6e466126 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_args_test.cpp @@ -0,0 +1,155 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type(int v1 = 0, + int v2 = 0, + int v3 = 0, + int v4 = 0, + int v5 = 0, + int v6 = 0, + int v7 = 0, + int v8 = 0, + int v9 = 0) + : sum_(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) { + ++instances; + } + + ~type() { + --instances; + } + + int sum() const { + return sum_; + } + +private: + int sum_; + + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type> result = boost::make_unique<type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 0); + result.reset(); + BOOST_TEST(type::instances == 0); + } + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + { + std::unique_ptr<type> result = boost::make_unique<type>(1); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = boost::make_unique<type>(1, 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3, 4); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3, 4, 5); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3, 4, 5, 6); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); + result.reset(); + BOOST_TEST(type::instances == 0); + } + + { + std::unique_ptr<type> result = + boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); + result.reset(); + BOOST_TEST(type::instances == 0); + } +#endif + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_array_noinit_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_array_noinit_test.cpp new file mode 100644 index 00000000..44ac66ed --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_array_noinit_test.cpp @@ -0,0 +1,87 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int[]> result = + boost::make_unique_noinit<int[]>(3); + BOOST_TEST(result.get() != 0); + } + { + std::unique_ptr<int[][2]> result = + boost::make_unique_noinit<int[][2]>(2); + BOOST_TEST(result.get() != 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type[]> result = + boost::make_unique_noinit<type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type[][2]> result = + boost::make_unique_noinit<type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type[]> result = + boost::make_unique_noinit<const type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type[][2]> result = + boost::make_unique_noinit<const type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_array_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_array_test.cpp new file mode 100644 index 00000000..447f79d8 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_array_test.cpp @@ -0,0 +1,110 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int[]> result = boost::make_unique<int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + std::unique_ptr<int[][2]> result = + boost::make_unique<int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + { + std::unique_ptr<const int[]> result = + boost::make_unique<const int[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); + } + { + std::unique_ptr<const int[][2]> result = + boost::make_unique<const int[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type[]> result = + boost::make_unique<type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type[][2]> result = + boost::make_unique<type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type[]> result = + boost::make_unique<const type[]>(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 3); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type[][2]> result = + boost::make_unique<const type[][2]>(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 4); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_array_throws_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_array_throws_test.cpp new file mode 100644 index 00000000..df4ab26c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_array_throws_test.cpp @@ -0,0 +1,72 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type() { + if (instances == 5) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + try { + boost::make_unique<type[]>(6); + BOOST_ERROR("make_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + try { + boost::make_unique<type[][2]>(3); + BOOST_ERROR("make_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + try { + boost::make_unique_noinit<type[]>(6); + BOOST_ERROR("make_unique_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + try { + boost::make_unique_noinit<type[][2]>(3); + BOOST_ERROR("make_unique_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_noinit_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_noinit_test.cpp new file mode 100644 index 00000000..a7cd828a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_noinit_test.cpp @@ -0,0 +1,63 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int> result = boost::make_unique_noinit<int>(); + BOOST_TEST(result.get() != 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type> result = + boost::make_unique_noinit<type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type> result = + boost::make_unique_noinit<const type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_test.cpp new file mode 100644 index 00000000..74c6033b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_test.cpp @@ -0,0 +1,70 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type() { + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + { + std::unique_ptr<int> result = boost::make_unique<int>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 0); + } + { + std::unique_ptr<const int> result = + boost::make_unique<const int>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<type> result = + boost::make_unique<type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + std::unique_ptr<const type> result = + boost::make_unique<const type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(type::instances == 1); + result.reset(); + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_throws_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_throws_test.cpp new file mode 100644 index 00000000..2032a2e6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_throws_test.cpp @@ -0,0 +1,51 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +class type { +public: + static unsigned instances; + + type() { + if (instances == 0) { + throw true; + } + ++instances; + } + + ~type() { + --instances; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::instances = 0; + +int main() +{ + BOOST_TEST(type::instances == 0); + try { + boost::make_unique<type>(); + BOOST_ERROR("make_unique did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/make_unique_value_test.cpp b/src/boost/libs/smart_ptr/test/make_unique_value_test.cpp new file mode 100644 index 00000000..c7af67f3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/make_unique_value_test.cpp @@ -0,0 +1,56 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_SMART_PTR) +#include <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/make_unique.hpp> + +struct type { + int x; + int y; +}; + +int main() +{ + { + std::unique_ptr<type> result = boost::make_unique<type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 0); + BOOST_TEST(result->y == 0); + } + { + std::unique_ptr<const type> result = + boost::make_unique<const type>(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 0); + BOOST_TEST(result->y == 0); + } +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + std::unique_ptr<type> result = + boost::make_unique<type>({ 1, 2 }); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 1); + BOOST_TEST(result->y == 2); + } + { + std::unique_ptr<const type> result = + boost::make_unique<const type>({ 1, 2 }); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 1); + BOOST_TEST(result->y == 2); + } +#endif + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/owner_less_test.cpp b/src/boost/libs/smart_ptr/test/owner_less_test.cpp new file mode 100644 index 00000000..572b72b3 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/owner_less_test.cpp @@ -0,0 +1,67 @@ +// +// owner_less_test.cpp +// +// A regression test for owner_less +// +// Copyright (c) 2008 Frank Mori Hess +// +// 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 <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/owner_less.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +int main() +{ + boost::owner_less<boost::shared_ptr<int> > comp; + { + boost::shared_ptr<int> x; + boost::shared_ptr<int> y; + boost::weak_ptr<int> w; + BOOST_TEST(!(comp(x, w) || comp(w, x))); + } + { + boost::shared_ptr<int> z((int*)0); + boost::weak_ptr<int> w; + BOOST_TEST(comp(z, w) || comp(w, z)); + { + boost::shared_ptr<int> zz(z); + w = boost::weak_ptr<int>(zz); + BOOST_TEST(!(comp(z, zz) || comp(z, zz))); + BOOST_TEST(!(comp(z, w) || comp(z, w))); + } + BOOST_TEST(!(comp(z, w) || comp(w, z))); + } + { + boost::shared_ptr<int> x; + boost::shared_ptr<int> z((int*)0); + BOOST_TEST(comp(x, z) || comp(z, x)); + } + { + boost::shared_ptr<int> a((int*)0); + boost::shared_ptr<int> b((int*)0); + BOOST_TEST(comp(a, b) || comp(b, a)); + boost::weak_ptr<int> w(a); + BOOST_TEST(!(comp(a, w) || comp(w, a))); + BOOST_TEST(comp(b, w) || comp(w, b)); + } + + boost::owner_less<boost::weak_ptr<int> > weak_comp; + { + boost::shared_ptr<int> a((int*)0); + boost::weak_ptr<int> wa(a); + boost::shared_ptr<int> b((int*)0); + boost::weak_ptr<int> wb(b); + BOOST_TEST(!(weak_comp(a, wa) || weak_comp(wa, a))); + BOOST_TEST(!(weak_comp(b, wb) || weak_comp(wb, b))); + BOOST_TEST(weak_comp(wa, wb) || weak_comp(wb, wa)); + BOOST_TEST(weak_comp(wa, b) || weak_comp(b, wa)); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_co_fail.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_co_fail.cpp new file mode 100644 index 00000000..d8960b28 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_co_fail.cpp @@ -0,0 +1,18 @@ +// +// A negative test for unique_ptr const_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +int main() +{ + std::unique_ptr<int> p1( new int ); + std::unique_ptr<int[]> p2 = boost::const_pointer_cast<int[]>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_co_fail2.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_co_fail2.cpp new file mode 100644 index 00000000..7fa8e189 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_co_fail2.cpp @@ -0,0 +1,18 @@ +// +// A negative test for unique_ptr const_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +int main() +{ + std::unique_ptr<int[]> p1( new int[ 1 ] ); + std::unique_ptr<int> p2 = boost::const_pointer_cast<int>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_co_fail3.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_co_fail3.cpp new file mode 100644 index 00000000..d8872c87 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_co_fail3.cpp @@ -0,0 +1,29 @@ +// +// A negative test for unique_ptr const_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +struct B +{ + virtual ~B() + { + } +}; + +struct D: B +{ +}; + +int main() +{ + std::unique_ptr<D[]> p1( new D[ 1 ] ); + std::unique_ptr<B[]> p2 = boost::const_pointer_cast<B[]>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail.cpp new file mode 100644 index 00000000..c6df69d6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail.cpp @@ -0,0 +1,25 @@ +// +// A negative test for unique_ptr dynamic_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +struct B +{ + virtual ~B() + { + } +}; + +int main() +{ + std::unique_ptr<B> p1( new B ); + std::unique_ptr<B[]> p2 = boost::dynamic_pointer_cast<B[]>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail2.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail2.cpp new file mode 100644 index 00000000..223977a0 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail2.cpp @@ -0,0 +1,25 @@ +// +// A negative test for unique_ptr dynamic_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +struct B +{ + virtual ~B() + { + } +}; + +int main() +{ + std::unique_ptr<B[]> p1( new B[ 1 ] ); + std::unique_ptr<B> p2 = boost::dynamic_pointer_cast<B>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail3.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail3.cpp new file mode 100644 index 00000000..1ac52e70 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_dy_fail3.cpp @@ -0,0 +1,29 @@ +// +// A negative test for unique_ptr dynamic_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +struct B +{ + virtual ~B() + { + } +}; + +struct D: B +{ +}; + +int main() +{ + std::unique_ptr<D[]> p1( new D[ 1 ] ); + std::unique_ptr<B[]> p2 = boost::dynamic_pointer_cast<B[]>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_st_fail.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_st_fail.cpp new file mode 100644 index 00000000..0fcf8c19 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_st_fail.cpp @@ -0,0 +1,18 @@ +// +// A negative test for unique_ptr static_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +int main() +{ + std::unique_ptr<int> p1( new int ); + std::unique_ptr<int[]> p2 = boost::static_pointer_cast<int[]>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_st_fail2.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_st_fail2.cpp new file mode 100644 index 00000000..3b227b99 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_st_fail2.cpp @@ -0,0 +1,18 @@ +// +// A negative test for unique_ptr static_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +int main() +{ + std::unique_ptr<int[]> p1( new int[ 1 ] ); + std::unique_ptr<int> p2 = boost::static_pointer_cast<int>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_st_fail3.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_st_fail3.cpp new file mode 100644 index 00000000..4ca6a89a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_st_fail3.cpp @@ -0,0 +1,29 @@ +// +// A negative test for unique_ptr static_cast +// +// Copyright 2016 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 <boost/pointer_cast.hpp> +#include <memory> + +struct B +{ + virtual ~B() + { + } +}; + +struct D: B +{ +}; + +int main() +{ + std::unique_ptr<D[]> p1( new D[ 1 ] ); + std::unique_ptr<B[]> p2 = boost::static_pointer_cast<B[]>( std::move( p1 ) ); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_test.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_test.cpp new file mode 100644 index 00000000..ae036fb1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_test.cpp @@ -0,0 +1,128 @@ +// +// pointer_cast_test.cpp - a test for boost/pointer_cast.hpp +// +// Copyright (c) 2005 Ion Gaztanaga +// Copyright (c) 2005 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 <boost/config.hpp> + +#include <boost/pointer_cast.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/scoped_ptr.hpp> +#include <boost/get_pointer.hpp> + +#include <boost/detail/lightweight_test.hpp> + +namespace +{ + +// Let's create these inheritance relationship: +// +// base base2 +// | | +// derived +// | +// derived_derived +// + +class base +{ + public: + virtual ~base(){} + int filler [5]; +}; + +class base2 +{ +public: + + virtual ~base2(){} + int filler [5]; +}; + +class derived + : public base, public base2 +{ + int filler [5]; +}; + +class derived_derived + : public derived +{ + int filler [5]; +}; + +// And now some simple check functions + +#if !defined( BOOST_NO_RTTI ) + +template <class BasePtr> +bool check_dynamic_pointer_cast(const BasePtr &ptr) +{ + //Check that dynamic_pointer_cast versus dynamic_cast + return + //Correct cast with dynamic_pointer_cast + boost::get_pointer(boost::dynamic_pointer_cast<derived>(ptr)) == + //Correct cast with dynamic_cast + dynamic_cast<derived*>(boost::get_pointer(ptr)) + && + //Incorrect cast with dynamic_pointer_cast + boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>(ptr)) == + //Incorrect cast with dynamic_cast + dynamic_cast<derived_derived*>(boost::get_pointer(ptr)); +} + +#endif + +template <class BasePtr> +bool check_static_pointer_cast(const BasePtr &ptr) +{ + return + //Cast base -> derived -> base2 using static_pointer_cast + boost::get_pointer( + boost::static_pointer_cast<base2>( + boost::static_pointer_cast<derived>(ptr))) == + //Now the same with static_cast + static_cast<base2*>(static_cast<derived*>(boost::get_pointer(ptr))); +} + +template <class BasePtr> +bool check_const_pointer_cast(const BasePtr &ptr) +{ + return + //Unconst and const again using const_pointer_cast + boost::get_pointer( + boost::const_pointer_cast<const base> + (boost::const_pointer_cast<base>(ptr))) == + //Now the same with const_cast + const_cast<const base*>(const_cast<base*>(boost::get_pointer(ptr))); +} + +template <class BasePtr> +void check_all_casts(const BasePtr &ptr) +{ +#if !defined( BOOST_NO_RTTI ) + BOOST_TEST( check_dynamic_pointer_cast( ptr ) ); +#endif + BOOST_TEST( check_static_pointer_cast( ptr ) ); + BOOST_TEST( check_const_pointer_cast( ptr ) ); +} + +} + +int main() +{ + boost::shared_ptr<base> boost_shared(new derived); + base *plain = boost_shared.get(); + + check_all_casts(boost_shared); + check_all_casts(plain); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/pointer_cast_test2.cpp b/src/boost/libs/smart_ptr/test/pointer_cast_test2.cpp new file mode 100644 index 00000000..fd1d63e8 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_cast_test2.cpp @@ -0,0 +1,247 @@ +// +// pointer_cast_test2.cpp - a test for unique_ptr casts +// +// Copyright 2016 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_SMART_PTR ) + +int main() +{ + return 0; +} + +#else + +#include <boost/pointer_cast.hpp> +#include <boost/core/lightweight_test.hpp> +#include <memory> + +struct B1 +{ +}; + +struct D1: B1 +{ + ~D1() + { + } +}; + +static void test_static_cast() +{ + { + std::unique_ptr<int> p1( new int ); + int * q1 = p1.get(); + + std::unique_ptr<int> p2 = boost::static_pointer_cast<int>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } + + { + std::unique_ptr<int> p1( new int ); + int * q1 = p1.get(); + + std::unique_ptr<int const> p2 = boost::static_pointer_cast<int const>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } + + { + std::unique_ptr<int[]> p1( new int[ 1 ] ); + int * q1 = p1.get(); + + std::unique_ptr<int[]> p2 = boost::static_pointer_cast<int[]>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } + + { + std::unique_ptr<int[]> p1( new int[ 1 ] ); + int * q1 = p1.get(); + + std::unique_ptr<int const[]> p2 = boost::static_pointer_cast<int const[]>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } + + { + std::unique_ptr<D1> p1( new D1 ); + D1 * q1 = p1.get(); + + std::unique_ptr<B1> p2 = boost::static_pointer_cast<B1>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + + std::unique_ptr<D1> p3 = boost::static_pointer_cast<D1>( std::move( p2 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p3.get(), q1 ); + } +} + +static void test_const_cast() +{ + { + std::unique_ptr<int> p1( new int ); + int * q1 = p1.get(); + + std::unique_ptr<int const> p2 = boost::const_pointer_cast<int const>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + + std::unique_ptr<int> p3 = boost::const_pointer_cast<int>( std::move( p2 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p3.get(), q1 ); + } + + { + std::unique_ptr<int[]> p1( new int[ 1 ] ); + int * q1 = p1.get(); + + std::unique_ptr<int const[]> p2 = boost::const_pointer_cast<int const[]>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + + std::unique_ptr<int[]> p3 = boost::const_pointer_cast<int[]>( std::move( p2 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p3.get(), q1 ); + } +} + +struct B2 +{ + virtual ~B2() + { + } +}; + +struct C2 +{ + virtual ~C2() + { + } +}; + +struct D2: B2, C2 +{ +}; + +static void test_dynamic_cast() +{ + { + std::unique_ptr<D2> p1( new D2 ); + D2 * q1 = p1.get(); + + std::unique_ptr<B2> p2 = boost::dynamic_pointer_cast<B2>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } + + { + std::unique_ptr<B2> p1( new D2 ); + B2 * q1 = p1.get(); + + std::unique_ptr<D2> p2 = boost::dynamic_pointer_cast<D2>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } + + { + std::unique_ptr<B2> p1( new B2 ); + B2 * q1 = p1.get(); + + std::unique_ptr<D2> p2 = boost::dynamic_pointer_cast<D2>( std::move( p1 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p1.get(), q1 ); + } + + { + D2 * q1 = new D2; + std::unique_ptr<B2> p1( q1 ); + + std::unique_ptr<C2> p2 = boost::dynamic_pointer_cast<C2>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + } +} + +static void test_reinterpret_cast() +{ + { + std::unique_ptr<int> p1( new int ); + void * q1 = p1.get(); + + std::unique_ptr<char> p2 = boost::reinterpret_pointer_cast<char>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + + p1 = boost::reinterpret_pointer_cast<int>( std::move( p2 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p1.get(), q1 ); + } + + { + std::unique_ptr<int> p1( new int ); + void * q1 = p1.get(); + + std::unique_ptr<char[]> p2 = boost::reinterpret_pointer_cast<char[]>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + + p1 = boost::reinterpret_pointer_cast<int>( std::move( p2 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p1.get(), q1 ); + } + + { + std::unique_ptr<int[]> p1( new int[ 1 ] ); + void * q1 = p1.get(); + + std::unique_ptr<char[]> p2 = boost::reinterpret_pointer_cast<char[]>( std::move( p1 ) ); + + BOOST_TEST( p1.get() == 0 ); + BOOST_TEST_EQ( p2.get(), q1 ); + + p1 = boost::reinterpret_pointer_cast<int[]>( std::move( p2 ) ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST_EQ( p1.get(), q1 ); + } +} + +int main() +{ + test_static_cast(); + test_const_cast(); + test_dynamic_cast(); + test_reinterpret_cast(); + + return boost::report_errors(); +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/pointer_to_other_test.cpp b/src/boost/libs/smart_ptr/test/pointer_to_other_test.cpp new file mode 100644 index 00000000..f1c6091f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/pointer_to_other_test.cpp @@ -0,0 +1,81 @@ +// +// pointer_to_other_test.cpp - a test for boost/pointer_to_other.hpp +// +// Copyright (c) 2005 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 <boost/pointer_to_other.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/shared_array.hpp> +#include <boost/scoped_ptr.hpp> +#include <boost/scoped_array.hpp> +#include <boost/intrusive_ptr.hpp> + +#include <boost/config.hpp> + +#include <memory> + + +template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 ) +{ + pt = pu; +} + +struct X; +struct Y; + +int main() +{ + // shared_ptr + + assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, Y >::type, boost::shared_ptr<Y> >(); + assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, void >::type, boost::shared_ptr<void> >(); + assert_same_type< boost::pointer_to_other< boost::shared_ptr<void>, Y >::type, boost::shared_ptr<Y> >(); + + // shared_array + + assert_same_type< boost::pointer_to_other< boost::shared_array<X>, Y >::type, boost::shared_array<Y> >(); + assert_same_type< boost::pointer_to_other< boost::shared_array<X>, void >::type, boost::shared_array<void> >(); + assert_same_type< boost::pointer_to_other< boost::shared_array<void>, Y >::type, boost::shared_array<Y> >(); + + // scoped_ptr + + assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, Y >::type, boost::scoped_ptr<Y> >(); + assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, void >::type, boost::scoped_ptr<void> >(); + assert_same_type< boost::pointer_to_other< boost::scoped_ptr<void>, Y >::type, boost::scoped_ptr<Y> >(); + + // scoped_array + + assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, Y >::type, boost::scoped_array<Y> >(); + assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, void >::type, boost::scoped_array<void> >(); + assert_same_type< boost::pointer_to_other< boost::scoped_array<void>, Y >::type, boost::scoped_array<Y> >(); + + // intrusive_ptr + + assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, Y >::type, boost::intrusive_ptr<Y> >(); + assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >(); + assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >(); + +#if !defined( BOOST_NO_AUTO_PTR ) + + // auto_ptr + + assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >(); + assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >(); + assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >(); + +#endif + + // raw pointer + + assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >(); + assert_same_type< boost::pointer_to_other< X *, void >::type, void * >(); + assert_same_type< boost::pointer_to_other< void *, Y >::type, Y * >(); + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/quick.cpp b/src/boost/libs/smart_ptr/test/quick.cpp new file mode 100644 index 00000000..06230949 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/quick.cpp @@ -0,0 +1,80 @@ +// +// quick.cpp - a quick (CI) test for Boost.SmartPtr +// +// 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 <boost/smart_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + +public: + + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_ptr<X> p1( new X ); + BOOST_TEST_EQ( X::instances, 1 ); + BOOST_TEST_EQ( p1.use_count(), 1 ); + + boost::shared_ptr<X> p2( p1 ); + BOOST_TEST_EQ( p2.use_count(), 2 ); + + boost::weak_ptr<X> wp( p1 ); + BOOST_TEST_EQ( wp.use_count(), 2 ); + + p1.reset(); + BOOST_TEST_EQ( wp.use_count(), 1 ); + + p2.reset(); + BOOST_TEST_EQ( wp.use_count(), 0 ); + BOOST_TEST_EQ( X::instances, 0 ); + } + + { + boost::shared_ptr<X> p1 = boost::make_shared<X>(); + BOOST_TEST_EQ( X::instances, 1 ); + BOOST_TEST_EQ( p1.use_count(), 1 ); + + boost::shared_ptr<X> p2( p1 ); + BOOST_TEST_EQ( p2.use_count(), 2 ); + + boost::weak_ptr<X> wp( p1 ); + BOOST_TEST_EQ( wp.use_count(), 2 ); + + p1.reset(); + BOOST_TEST_EQ( wp.use_count(), 1 ); + + p2.reset(); + BOOST_TEST_EQ( wp.use_count(), 0 ); + BOOST_TEST_EQ( X::instances, 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sa_nullptr_test.cpp b/src/boost/libs/smart_ptr/test/sa_nullptr_test.cpp new file mode 100644 index 00000000..a051d322 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sa_nullptr_test.cpp @@ -0,0 +1,112 @@ +// +// shared_array nullptr test +// +// Copyright 2012, 2013 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 <boost/shared_array.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <cstddef> +#include <memory> + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + +struct X +{ + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_array<int> p( nullptr ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + { + boost::shared_array<int> p( new int[ 1 ] ); + + BOOST_TEST( p.get() != 0 ); + BOOST_TEST( p.use_count() == 1 ); + + BOOST_TEST( p != nullptr ); + BOOST_TEST( nullptr != p ); + BOOST_TEST( !( p == nullptr ) ); + BOOST_TEST( !( nullptr == p ) ); + + p = nullptr; + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + { + BOOST_TEST( X::instances == 0 ); + + boost::shared_array<X> p( new X[ 2 ] ); + BOOST_TEST( X::instances == 2 ); + + BOOST_TEST( p.get() != 0 ); + BOOST_TEST( p.use_count() == 1 ); + + BOOST_TEST( p != nullptr ); + BOOST_TEST( nullptr != p ); + BOOST_TEST( !( p == nullptr ) ); + BOOST_TEST( !( nullptr == p ) ); + + p = nullptr; + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + return boost::report_errors(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/scoped_array_eq_fail.cpp b/src/boost/libs/smart_ptr/test/scoped_array_eq_fail.cpp new file mode 100644 index 00000000..6c7f214d --- /dev/null +++ b/src/boost/libs/smart_ptr/test/scoped_array_eq_fail.cpp @@ -0,0 +1,27 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// scoped_array_eq_fail.cpp - a negative test for "p == q" +// +// Copyright (c) 2008 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 <boost/scoped_array.hpp> + +int main() +{ + boost::scoped_array<int> p, q; + p == q; // must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/scoped_ptr_eq_fail.cpp b/src/boost/libs/smart_ptr/test/scoped_ptr_eq_fail.cpp new file mode 100644 index 00000000..0d6ade40 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/scoped_ptr_eq_fail.cpp @@ -0,0 +1,27 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// scoped_ptr_eq_fail.cpp - a negative test for "p == q" +// +// Copyright (c) 2008 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 <boost/scoped_ptr.hpp> + +int main() +{ + boost::scoped_ptr<int> p, q; + p == q; // must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_raw_test.cpp b/src/boost/libs/smart_ptr/test/shared_from_raw_test.cpp new file mode 100644 index 00000000..d6688c38 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_raw_test.cpp @@ -0,0 +1,174 @@ +// +// shared_from_raw_test - based on shared_from_this_test +// +// Copyright (c) 2002, 2003, 2014 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 +// + +#if defined(__GNUC__) && __GNUC__ > 4 +# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" +#endif + +#include <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/shared_ptr.hpp> + +#include <boost/detail/lightweight_test.hpp> + +// + +class X +{ +public: + + virtual void f() = 0; + +protected: + + ~X() {} +}; + +class Y +{ +public: + + virtual boost::shared_ptr<X> getX() = 0; + +protected: + + ~Y() {} +}; + +boost::shared_ptr<Y> createY(); + +void test() +{ + boost::shared_ptr<Y> py = createY(); + BOOST_TEST(py.get() != 0); + BOOST_TEST(py.use_count() == 1); + + try + { + boost::shared_ptr<X> px = py->getX(); + BOOST_TEST(px.get() != 0); + BOOST_TEST(py.use_count() == 2); + + px->f(); + +#if !defined( BOOST_NO_RTTI ) + boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == py2.get()); + BOOST_TEST(!(py < py2 || py2 < py)); + BOOST_TEST(py.use_count() == 3); +#endif + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "py->getX() failed" ); + } +} + +void test2(); +void test3(); + +int main() +{ + test(); + test2(); + test3(); + return boost::report_errors(); +} + +// virtual inheritance to stress the implementation +// (prevents Y* -> impl*, enable_shared_from_raw* -> impl* casts) + +class impl: public X, public virtual Y, public virtual boost::enable_shared_from_raw +{ +public: + + virtual void f() + { + } + + virtual boost::shared_ptr<X> getX() + { + boost::shared_ptr<impl> pi = boost::shared_from_raw( this ); + BOOST_TEST( pi.get() == this ); + return pi; + } +}; + +// intermediate impl2 to stress the implementation + +class impl2: public impl +{ +}; + +boost::shared_ptr<Y> createY() +{ + boost::shared_ptr<Y> pi(new impl2); + return pi; +} + +void test2() +{ + boost::shared_ptr<Y> pi(static_cast<impl2*>(0)); +} + +// + +struct V: public boost::enable_shared_from_raw +{ +}; + +void test3() +{ + boost::shared_ptr<V> p( new V ); + + try + { + boost::shared_ptr<V> q = boost::shared_from_raw( p.get() ); + BOOST_TEST( p == q ); + BOOST_TEST( !(p < q) && !(q < p) ); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR( "shared_from_this( p.get() ) failed" ); + } + + V v2( *p ); + + try + { + // shared_from_raw differs from shared_from_this; + // it will not throw here and will create a shared_ptr + + boost::shared_ptr<V> r = boost::shared_from_raw( &v2 ); + + // check if the shared_ptr is correct and that it does + // not share ownership with p + + BOOST_TEST( r.get() == &v2 ); + BOOST_TEST( p != r ); + BOOST_TEST( (p < r) || (r < p) ); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR("shared_from_raw( &v2 ) failed"); + } + + try + { + *p = V(); + boost::shared_ptr<V> r = boost::shared_from_raw( p.get() ); + BOOST_TEST( p == r ); + BOOST_TEST( !(p < r) && !(r < p) ); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR("shared_from_raw( p.get() ) threw bad_weak_ptr after *p = V()"); + } +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_raw_test2.cpp b/src/boost/libs/smart_ptr/test/shared_from_raw_test2.cpp new file mode 100644 index 00000000..2a33637a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_raw_test2.cpp @@ -0,0 +1,224 @@ +// +// shared_from_raw_test2.cpp - based on esft_regtest.cpp +// +// Copyright (c) 2008, 2014 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/config.hpp> +#include <memory> +#include <string> + +class X: public boost::enable_shared_from_raw +{ +private: + + int destroyed_; + int deleted_; + int expected_; + +private: + + X( X const& ); + X& operator=( X const& ); + +public: + + static int instances; + +public: + + explicit X( int expected ): destroyed_( 0 ), deleted_( 0 ), expected_( expected ) + { + ++instances; + } + + ~X() + { + BOOST_TEST( deleted_ == expected_ ); + BOOST_TEST( destroyed_ == 0 ); + ++destroyed_; + --instances; + } + + typedef void (*deleter_type)( X* ); + + static void deleter( X * px ) + { + ++px->deleted_; + } + + static void deleter2( X * px ) + { + ++px->deleted_; + delete px; + } +}; + +int X::instances = 0; + +void test() +{ + BOOST_TEST( X::instances == 0 ); + + { + X x( 0 ); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + +#if !defined( BOOST_NO_AUTO_PTR ) + + { + std::auto_ptr<X> px( new X( 0 ) ); + BOOST_TEST( X::instances == 1 ); + } + +#endif + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> px( new X( 0 ) ); + BOOST_TEST( X::instances == 1 ); + + boost::weak_ptr<X> wp( px ); + BOOST_TEST( !wp.expired() ); + + px.reset(); + + BOOST_TEST( wp.expired() ); + } + + BOOST_TEST( X::instances == 0 ); + + { + X x( 1 ); + boost::shared_ptr<X> px( &x, X::deleter ); + BOOST_TEST( X::instances == 1 ); + + X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px ); + BOOST_TEST( pd != 0 && *pd == X::deleter ); + + boost::weak_ptr<X> wp( px ); + BOOST_TEST( !wp.expired() ); + + px.reset(); + + BOOST_TEST( wp.expired() ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> px( new X( 1 ), X::deleter2 ); + BOOST_TEST( X::instances == 1 ); + + X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px ); + BOOST_TEST( pd != 0 && *pd == X::deleter2 ); + + boost::weak_ptr<X> wp( px ); + BOOST_TEST( !wp.expired() ); + + px.reset(); + + BOOST_TEST( wp.expired() ); + } + + BOOST_TEST( X::instances == 0 ); +} + +struct V: public boost::enable_shared_from_raw +{ + 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 + { + boost::shared_from_raw( p1.get() ); + } + catch( ... ) + { + BOOST_ERROR( "shared_from_raw( p1.get() ) failed" ); + } + + p1.reset(); + + boost::shared_ptr<V> p2( &v, null_deleter() ); + BOOST_TEST( p2.get() == &v ); + BOOST_TEST( p2.use_count() == 1 ); + + try + { + boost::shared_from_raw( p2.get() ); + } + catch( ... ) + { + BOOST_ERROR( "shared_from_raw( p2.get() ) failed" ); + } +} + +int main() +{ + test(); + test2(); + test3(); + test4(); + test5(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_raw_test3.cpp b/src/boost/libs/smart_ptr/test/shared_from_raw_test3.cpp new file mode 100644 index 00000000..8c3adaff --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_raw_test3.cpp @@ -0,0 +1,52 @@ +// +// shared_from_raw_test3 - based on esft_second_ptr_test.cpp +// +// This test has been extracted from a real +// scenario that occurs in Boost.Python +// +// Copyright 2009, 2014 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X: public boost::enable_shared_from_raw +{ +}; + +void null_deleter( void const* ) +{ +} + +int main() +{ + boost::shared_ptr<X> px( new X ); + + { + boost::shared_ptr<X> px2( px.get(), null_deleter ); + BOOST_TEST( px == px2 ); + } + + try + { + boost::shared_ptr< X > qx = boost::shared_from_raw( px.get() ); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "shared_from_raw( px.get() ) failed" ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_raw_test4.cpp b/src/boost/libs/smart_ptr/test/shared_from_raw_test4.cpp new file mode 100644 index 00000000..ab0658e5 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_raw_test4.cpp @@ -0,0 +1,56 @@ +// +// shared_from_raw_test4 - based on esft_void_test.cpp +// +// Copyright 2009, 2014 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X: public boost::enable_shared_from_raw +{ +}; + +int main() +{ + boost::shared_ptr< void const volatile > pv( new X ); + boost::shared_ptr< void > pv2 = boost::const_pointer_cast< void >( pv ); + boost::shared_ptr< X > px = boost::static_pointer_cast< X >( pv2 ); + + try + { + boost::shared_ptr< X > qx = boost::shared_from_raw( px.get() ); + + BOOST_TEST( px == qx ); + BOOST_TEST( !( px < qx ) && !( qx < px ) ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "shared_from_this( px.get() ) failed" ); + } + + boost::shared_ptr< X const volatile > px2( px ); + + try + { + boost::shared_ptr< X const volatile > qx2 = boost::shared_from_raw( px2.get() ); + + BOOST_TEST( px2 == qx2 ); + BOOST_TEST( !( px2 < qx2 ) && !( qx2 < px2 ) ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "shared_from_this( px2.get() ) failed" ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_raw_test5.cpp b/src/boost/libs/smart_ptr/test/shared_from_raw_test5.cpp new file mode 100644 index 00000000..fcf4e816 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_raw_test5.cpp @@ -0,0 +1,168 @@ +// +// shared_from_raw_test5.cpp - was esft_constructor_test.cpp +// +// A test for calling shared_from_raw from constructors +// (that is, prior to the object's ownership being passed to +// an external shared_ptr). +// +// Copyright (c) 2008 Frank Mori Hess +// Copyright (c) 2008 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> + +class X: public boost::enable_shared_from_raw +{ +private: + + int destroyed_; + int deleted_; + int expected_; + +private: + + X( X const& ); + X& operator=( X const& ); + +public: + + static int instances; + +public: + + explicit X( int expected, boost::shared_ptr<X> *early_px = 0 ): destroyed_( 0 ), deleted_( 0 ), expected_( expected ) + { + ++instances; + if( early_px ) *early_px = shared_from_raw(this); + } + + ~X() + { + BOOST_TEST( deleted_ == expected_ ); + BOOST_TEST( destroyed_ == 0 ); + ++destroyed_; + --instances; + } + + typedef void (*deleter_type)( X* ); + + static void deleter( X * px ) + { + ++px->deleted_; + } + + static void deleter2( X * px ) + { + ++px->deleted_; + delete px; + } +}; + +int X::instances = 0; + +template<typename T, typename U> +bool are_shared_owners(const boost::shared_ptr<T> &a, const boost::shared_ptr<U> &b) +{ + return !(a < b) && !(b < a); +} + +struct Y: public boost::enable_shared_from_raw +{}; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> early_px; + X* x = new X( 1, &early_px ); + BOOST_TEST( early_px.use_count() > 0 ); + BOOST_TEST( boost::get_deleter<X::deleter_type>(early_px) == 0 ); + BOOST_TEST( early_px.get() == x ); + boost::shared_ptr<X> px( x, &X::deleter2 ); + BOOST_TEST( early_px.use_count() == 2 && px.use_count() == 2 ); + BOOST_TEST(are_shared_owners(early_px, px)); + px.reset(); + BOOST_TEST( early_px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + X::deleter_type *pd = boost::get_deleter<X::deleter_type>(early_px); + BOOST_TEST(pd && *pd == &X::deleter2 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> early_px; + X* x = new X( 1, &early_px ); + boost::weak_ptr<X> early_weak_px = early_px; + early_px.reset(); + BOOST_TEST( !early_weak_px.expired() ); + boost::shared_ptr<X> px( x, &X::deleter2 ); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST(are_shared_owners(early_weak_px.lock(), px)); + px.reset(); + BOOST_TEST( early_weak_px.expired() ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> early_px; + X x( 2, &early_px ); + BOOST_TEST( early_px.use_count() > 0 ); + boost::shared_ptr<X> px( &x, &X::deleter ); + BOOST_TEST( early_px.use_count() == 2 && px.use_count() == 2 ); + early_px.reset(); + BOOST_TEST( px.use_count() == 1 ); + BOOST_TEST( X::instances == 1 ); + px.reset(); + // test reinitialization after all shared_ptr have expired + early_px = shared_from_raw(&x); + px.reset( &x, &X::deleter ); + BOOST_TEST(are_shared_owners(early_px, px)); + early_px.reset(); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::weak_ptr<X> early_weak_px; + { + boost::shared_ptr<X> early_px; + X x( 0, &early_px ); + early_weak_px = early_px; + early_px.reset(); + BOOST_TEST( !early_weak_px.expired() ); + BOOST_TEST( X::instances == 1 ); + } + BOOST_TEST( early_weak_px.expired() ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<Y> px(new Y()); + Y y(*px); + px.reset(); + try + { + shared_from_raw(&y); + } + catch( const boost::bad_weak_ptr & ) + { + BOOST_ERROR("y threw bad_weak_ptr"); + } + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_raw_test6.cpp b/src/boost/libs/smart_ptr/test/shared_from_raw_test6.cpp new file mode 100644 index 00000000..d1941c6b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_raw_test6.cpp @@ -0,0 +1,52 @@ +// +// shared_from_raw_test6 +// +// Tests that dangling shared_ptr instances are caught by +// the BOOST_ASSERT in ~enable_shared_from_raw +// +// Copyright 2014 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 +// + +#define BOOST_ENABLE_ASSERT_HANDLER +#include <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <stdio.h> + +static int assertion_failed_ = 0; + +namespace boost +{ + +void assertion_failed( char const * expr, char const * function, char const * file, long line ) +{ + printf( "Assertion '%s' failed in function '%s', file '%s', line %ld\n", expr, function, file, line ); + ++assertion_failed_; +} + +} // namespace boost + +class X: public boost::enable_shared_from_raw +{ +}; + +int main() +{ + boost::shared_ptr<X> px; + + { + X x; + px = boost::shared_from_raw( &x ); + } + + BOOST_TEST_EQ( assertion_failed_, 1 ); + + // px is a dangling pointer here + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_test.cpp b/src/boost/libs/smart_ptr/test/shared_from_test.cpp new file mode 100644 index 00000000..47e29051 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_test.cpp @@ -0,0 +1,102 @@ + +// shared_from_test.cpp +// +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/smart_ptr/enable_shared_from.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +// + +class X +{ +private: + + int m_; + +public: + + X(): m_() {} +}; + +class Y: public boost::enable_shared_from +{ +}; + +class Z: public X, public Y +{ +public: + + boost::shared_ptr<Z> shared_from_this() + { + return boost::shared_from( this ); + } +}; + +void null_deleter( void const* ) +{ +} + +int main() +{ + boost::shared_ptr<Z> p( new Z ); + + try + { + boost::shared_ptr<Z> q = p->shared_from_this(); + + BOOST_TEST_EQ( p, q ); + BOOST_TEST( !( p < q ) && !( q < p ) ); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR( "p->shared_from_this() failed" ); + } + + Z v2( *p ); + + try + { + boost::shared_ptr<Z> q = v2.shared_from_this(); + BOOST_ERROR( "v2.shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const & ) + { + } + + *p = Z(); + + try + { + boost::shared_ptr<Z> q = p->shared_from_this(); + + BOOST_TEST_EQ( p, q ); + BOOST_TEST( !( p < q ) && !( q < p ) ); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR( "p->shared_from_this() threw bad_weak_ptr after *p = Z()" ); + } + + { + boost::shared_ptr<Z> p2( p.get(), null_deleter ); + } + + try + { + boost::shared_ptr<Z> q = p->shared_from_this(); + + BOOST_TEST_EQ( p, q ); + BOOST_TEST( !( p < q ) && !( q < p ) ); + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "p->shared_from_this() failed" ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_from_this_test.cpp b/src/boost/libs/smart_ptr/test/shared_from_this_test.cpp new file mode 100644 index 00000000..52c8b988 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_from_this_test.cpp @@ -0,0 +1,173 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +#if defined(__GNUC__) && __GNUC__ > 4 +# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" +#endif + +// +// shared_from_this_test.cpp +// +// Copyright (c) 2002, 2003 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 <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> + +#include <boost/detail/lightweight_test.hpp> + +// + +class X +{ +public: + + virtual void f() = 0; + +protected: + + ~X() {} +}; + +class Y +{ +public: + + virtual boost::shared_ptr<X> getX() = 0; + +protected: + + ~Y() {} +}; + +boost::shared_ptr<Y> createY(); + +void test() +{ + boost::shared_ptr<Y> py = createY(); + BOOST_TEST(py.get() != 0); + BOOST_TEST(py.use_count() == 1); + + try + { + boost::shared_ptr<X> px = py->getX(); + BOOST_TEST(px.get() != 0); + BOOST_TEST(py.use_count() == 2); + + px->f(); + +#if !defined( BOOST_NO_RTTI ) + boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == py2.get()); + BOOST_TEST(!(py < py2 || py2 < py)); + BOOST_TEST(py.use_count() == 3); +#endif + } + catch( boost::bad_weak_ptr const& ) + { + BOOST_ERROR( "py->getX() failed" ); + } +} + +void test2(); +void test3(); + +int main() +{ + test(); + test2(); + test3(); + return boost::report_errors(); +} + +// virtual inheritance to stress the implementation +// (prevents Y* -> impl*, enable_shared_from_this<impl>* -> impl* casts) + +class impl: public X, public virtual Y, public virtual boost::enable_shared_from_this<impl> +{ +public: + + virtual void f() + { + } + + virtual boost::shared_ptr<X> getX() + { + boost::shared_ptr<impl> pi = shared_from_this(); + BOOST_TEST(pi.get() == this); + return pi; + } +}; + +// intermediate impl2 to stress the implementation + +class impl2: public impl +{ +}; + +boost::shared_ptr<Y> createY() +{ + boost::shared_ptr<Y> pi(new impl2); + return pi; +} + +void test2() +{ + boost::shared_ptr<Y> pi(static_cast<impl2*>(0)); +} + +// + +struct V: public boost::enable_shared_from_this<V> +{ +}; + +void test3() +{ + boost::shared_ptr<V> p(new V); + + try + { + boost::shared_ptr<V> q = p->shared_from_this(); + BOOST_TEST(p == q); + BOOST_TEST(!(p < q) && !(q < p)); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR( "p->shared_from_this() failed" ); + } + + V v2(*p); + + try + { + boost::shared_ptr<V> r = v2.shared_from_this(); + BOOST_ERROR("v2.shared_from_this() failed to throw"); + } + catch( boost::bad_weak_ptr const & ) + { + } + + try + { + *p = V(); + boost::shared_ptr<V> r = p->shared_from_this(); + BOOST_TEST(p == r); + BOOST_TEST(!(p < r) && !(r < p)); + } + catch( boost::bad_weak_ptr const & ) + { + BOOST_ERROR("p->shared_from_this() threw bad_weak_ptr after *p = V()"); + } +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alias_move_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alias_move_test.cpp new file mode 100644 index 00000000..972f24bd --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alias_move_test.cpp @@ -0,0 +1,255 @@ +#include <boost/config.hpp> + +// shared_ptr_alias_move_test.cpp +// +// Copyright (c) 2007 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> +#include <utility> + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +class incomplete; + +struct X +{ + static long instances; + + int v_; + + explicit X( int v ): v_( v ) + { + ++instances; + } + + ~X() + { + v_ = 0; + --instances; + } + +private: + X( X const & ); + X & operator=( X const & ); +}; + +long X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + int m = 0; + boost::shared_ptr< int > p; + boost::shared_ptr< int > p2( std::move( p ), &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == 0 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + p2.reset( std::move( p ), 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == 0 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + } + + { + int m = 0; + boost::shared_ptr< int > p( new int ); + boost::shared_ptr< int const > p2( std::move( p ), &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == 1 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + boost::shared_ptr< int volatile > p3; + p2.reset( std::move( p3 ), 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == 0 ); + + BOOST_TEST( p3.get() == 0 ); + BOOST_TEST( p3.use_count() == 0 ); + + boost::shared_ptr< int const volatile > p4( new int ); + p2.reset( std::move( p4 ), &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2.use_count() == 1 ); + + BOOST_TEST( p4.get() == 0 ); + BOOST_TEST( p4.use_count() == 0 ); + } + + { + boost::shared_ptr< int > p( new int ); + boost::shared_ptr< void const > p2( std::move( p ), 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == 1 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + int m = 0; + boost::shared_ptr< void volatile > p3; + + p2.reset( std::move( p3 ), &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == 0 ); + + BOOST_TEST( p3.get() == 0 ); + BOOST_TEST( p3.use_count() == 0 ); + + boost::shared_ptr< void const volatile > p4( new int ); + p2.reset( std::move( p4 ), 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2.use_count() == 1 ); + + BOOST_TEST( p4.get() == 0 ); + BOOST_TEST( p4.use_count() == 0 ); + } + + { + boost::shared_ptr< incomplete > p; + boost::shared_ptr< incomplete > p2( std::move( p ), 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == 0 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + p2.reset( std::move( p ), 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == 0 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + } + + { + boost::shared_ptr< X > p( new X( 5 ) ), q( p ); + boost::shared_ptr< int const > p2( std::move( q ), &q->v_ ); + + BOOST_TEST( p2.get() == &p->v_ ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + + BOOST_TEST( q.get() == 0 ); + BOOST_TEST( q.use_count() == 0 ); + + p.reset(); + BOOST_TEST( *p2 == 5 ); + + boost::shared_ptr< X const > p3( new X( 8 ) ), q3( p3 ); + p2.reset( std::move( q3 ), &q3->v_ ); + + BOOST_TEST( p2.get() == &p3->v_ ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p3.use_count() ); + BOOST_TEST( !( p3 < p2 ) && !( p2 < p3 ) ); + + BOOST_TEST( q3.get() == 0 ); + BOOST_TEST( q3.use_count() == 0 ); + + p3.reset(); + BOOST_TEST( *p2 == 8 ); + } + + { + boost::shared_ptr< X > p( new X( 5 ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.unique() ); + BOOST_TEST( p->v_ == 5 ); + + boost::shared_ptr< X > p2( std::move( p ), p.get() ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p2.unique() ); + BOOST_TEST( p2->v_ == 5 ); + + boost::shared_ptr< int const > p3( std::move( p2 ), &p2->v_ ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p3.unique() ); + BOOST_TEST( *p3 == 5 ); + + p3.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > p( new X( 5 ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.unique() ); + BOOST_TEST( p->v_ == 5 ); + + { + boost::shared_ptr< X > p2(p); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == p2.get() ); + BOOST_TEST( p.use_count() == 2 ); + BOOST_TEST( p2.use_count() == 2 ); + + boost::shared_ptr< int const > p3( std::move( p2 ), &p2->v_ ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.use_count() == 2 ); + BOOST_TEST( p2.use_count() == 0 ); + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p3.use_count() == 2 ); + BOOST_TEST( p3.get() == &p->v_ ); + } + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.unique() ); + BOOST_TEST( p->v_ == 5 ); + } + + return boost::report_errors(); +} + +#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alias_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alias_test.cpp new file mode 100644 index 00000000..83d866fc --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alias_test.cpp @@ -0,0 +1,146 @@ +#include <boost/config.hpp> + +// shared_ptr_alias_test.cpp +// +// Copyright (c) 2007 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> +#include <memory> +#include <cstddef> + +// + +class incomplete; + +struct X +{ + int v_; + + explicit X( int v ): v_( v ) + { + } + + ~X() + { + v_ = 0; + } +}; + +int main() +{ + { + int m = 0; + boost::shared_ptr< int > p; + boost::shared_ptr< int > p2( p, &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + + p2.reset( p, 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + } + + { + int m = 0; + boost::shared_ptr< int > p( new int ); + boost::shared_ptr< int const > p2( p, &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + + boost::shared_ptr< int volatile > p3; + p2.reset( p3, 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == p3.use_count() ); + BOOST_TEST( !( p3 < p2 ) && !( p2 < p3 ) ); + } + + { + boost::shared_ptr< int > p( new int ); + boost::shared_ptr< void const > p2( p, 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + + int m = 0; + boost::shared_ptr< void volatile > p3; + + p2.reset( p3, &m ); + + BOOST_TEST( p2.get() == &m ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p3.use_count() ); + BOOST_TEST( !( p3 < p2 ) && !( p2 < p3 ) ); + } + + { + boost::shared_ptr< incomplete > p; + boost::shared_ptr< incomplete > p2( p, 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + + p2.reset( p, 0 ); + + BOOST_TEST( p2.get() == 0 ); + BOOST_TEST( p2? false: true ); + BOOST_TEST( !p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + } + + { + boost::shared_ptr< X > p( new X( 5 ) ); + boost::shared_ptr< int const > p2( p, &p->v_ ); + + BOOST_TEST( p2.get() == &p->v_ ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( !( p < p2 ) && !( p2 < p ) ); + + p.reset(); + BOOST_TEST( *p2 == 5 ); + + boost::shared_ptr< X const > p3( new X( 8 ) ); + p2.reset( p3, &p3->v_ ); + + BOOST_TEST( p2.get() == &p3->v_ ); + BOOST_TEST( p2? true: false ); + BOOST_TEST( !!p2 ); + BOOST_TEST( p2.use_count() == p3.use_count() ); + BOOST_TEST( !( p3 < p2 ) && !( p2 < p3 ) ); + + p3.reset(); + BOOST_TEST( *p2 == 8 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alloc11_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alloc11_test.cpp new file mode 100644 index 00000000..c2b7d6aa --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alloc11_test.cpp @@ -0,0 +1,116 @@ +#include <boost/config.hpp> + +// shared_ptr_alloc11_test.cpp +// +// Test the allocator constructor with a C++11 minimal allocator +// +// Copyright (c) 2005, 2014 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> +#include <memory> +#include <cstddef> + +#if !defined( BOOST_NO_CXX11_ALLOCATOR ) + +template< class T > class cxx11_allocator +{ +public: + + typedef T value_type; + + cxx11_allocator() + { + } + + template< class Y > cxx11_allocator( cxx11_allocator<Y> const & ) + { + } + + T * allocate( std::size_t n ) + { + return static_cast< T* >( ::operator new( n * sizeof( T ) ) ); + } + + void deallocate( T * p, std::size_t n ) + { + ::operator delete( p ); + } +}; + +// + +struct D; + +struct X +{ + static int instances; + + X(): deleted_( false ) + { + ++instances; + } + + ~X() + { + BOOST_TEST( deleted_ ); + --instances; + } + +private: + + friend struct D; + + bool deleted_; + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +struct D +{ + void operator()( X * px ) const + { + px->deleted_ = true; + delete px; + } +}; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr<void> pv( new X, D(), cxx11_allocator<X>() ); + + BOOST_TEST( X::instances == 1 ); + + pv.reset(); + + BOOST_TEST( X::instances == 0 ); + + pv.reset( new X, D(), cxx11_allocator<void>() ); + + BOOST_TEST( X::instances == 1 ); + + pv.reset(); + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} + +#else // !defined( BOOST_NO_CXX11_ALLOCATOR ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alloc2_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alloc2_test.cpp new file mode 100644 index 00000000..89a44bbc --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alloc2_test.cpp @@ -0,0 +1,224 @@ +#include <boost/config.hpp> + +// shared_ptr_alloc2_test.cpp +// +// Copyright (c) 2005 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> +#include <memory> +#include <cstddef> + +// test_allocator + +struct test_allocator_base +{ + int id_; + + static int last_global_id_; + static int count_; + + explicit test_allocator_base( int id ): id_( id ) + { + } +}; + +int test_allocator_base::last_global_id_ = 0; +int test_allocator_base::count_ = 0; + +template<class T> class test_allocator: public test_allocator_base +{ +public: + + typedef T * pointer; + typedef T const * const_pointer; + typedef T & reference; + typedef T const & const_reference; + typedef T value_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + +private: + + static T * last_pointer_; + static std::size_t last_n_; + static int last_id_; + +public: + + template<class U> struct rebind + { + typedef test_allocator<U> other; + }; + + pointer address( reference r ) const + { + return &r; + } + + const_pointer address( const_reference s ) const + { + return &s; + } + + explicit test_allocator( int id = 0 ): test_allocator_base( id ) + { + } + + template<class U> test_allocator( test_allocator<U> const & r ): test_allocator_base( r ) + { + } + + template<class U> test_allocator & operator=( test_allocator<U> const & r ) + { + test_allocator_base::operator=( r ); + return *this; + } + + void deallocate( pointer p, size_type n ) + { + BOOST_TEST( p == last_pointer_ ); + BOOST_TEST( n == last_n_ ); + BOOST_TEST( id_ == last_id_ ); + + --count_; + + ::operator delete( p ); + } + + pointer allocate( size_type n, void const * = 0 ) + { + T * p = static_cast< T* >( ::operator new( n * sizeof( T ) ) ); + + last_pointer_ = p; + last_n_ = n; + last_id_ = id_; + + last_global_id_ = id_; + ++count_; + + return p; + } + + void construct( pointer p, T const & t ) + { + ::new( p ) T( t ); + } + + void destroy( pointer p ) + { + p->~T(); + } + + size_type max_size() const + { + return size_type( -1 ) / sizeof( T ); + } +}; + +template<class T> T * test_allocator<T>::last_pointer_ = 0; +template<class T> std::size_t test_allocator<T>::last_n_ = 0; +template<class T> int test_allocator<T>::last_id_ = 0; + +template<class T, class U> inline bool operator==( test_allocator<T> const & a1, test_allocator<U> const & a2 ) +{ + return a1.id_ == a2.id_; +} + +template<class T, class U> inline bool operator!=( test_allocator<T> const & a1, test_allocator<U> const & a2 ) +{ + return a1.id_ != a2.id_; +} + +template<> class test_allocator<void>: public test_allocator_base +{ +public: + + typedef void * pointer; + typedef void const * const_pointer; + typedef void value_type; + + template<class U> struct rebind + { + typedef test_allocator<U> other; + }; + + explicit test_allocator( int id = 0 ): test_allocator_base( id ) + { + } + + template<class U> test_allocator( test_allocator<U> const & r ): test_allocator_base( r ) + { + } + + template<class U> test_allocator & operator=( test_allocator<U> const & r ) + { + test_allocator_base::operator=( r ); + return *this; + } +}; + +// + +struct X +{ + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr<void> pv( new X, boost::checked_deleter<X>(), std::allocator<X>() ); + + BOOST_TEST( X::instances == 1 ); + + pv.reset( new X, boost::checked_deleter<X>(), test_allocator<float>( 42 ) ); + + BOOST_TEST( X::instances == 1 ); + + BOOST_TEST( test_allocator_base::last_global_id_ == 42 ); + BOOST_TEST( test_allocator_base::count_ > 0 ); + + pv.reset(); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( test_allocator_base::count_ == 0 ); + + pv.reset( new X, boost::checked_deleter<X>(), test_allocator<void>( 43 ) ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( test_allocator_base::last_global_id_ == 43 ); + + pv.reset( new X, boost::checked_deleter<X>(), std::allocator<void>() ); + + BOOST_TEST( X::instances == 1 ); + + pv.reset(); + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alloc3_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alloc3_test.cpp new file mode 100644 index 00000000..011e9cfa --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alloc3_test.cpp @@ -0,0 +1,78 @@ +#include <boost/config.hpp> + +// shared_ptr_alloc3_test.cpp +// +// Copyright (c) 2005, 2014 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> +#include <memory> +#include <cstddef> + +// + +struct D; + +struct X +{ + static int instances; + + X(): deleted_( false ) + { + ++instances; + } + + ~X() + { + BOOST_TEST( deleted_ ); + --instances; + } + +private: + + friend struct D; + + bool deleted_; + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +struct D +{ + void operator()( X * px ) const + { + px->deleted_ = true; + delete px; + } +}; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr<void> pv( new X, D(), std::allocator<X>() ); + + BOOST_TEST( X::instances == 1 ); + + pv.reset(); + + BOOST_TEST( X::instances == 0 ); + + pv.reset( new X, D(), std::allocator<void>() ); + + BOOST_TEST( X::instances == 1 ); + + pv.reset(); + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alloc_construct11_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alloc_construct11_test.cpp new file mode 100644 index 00000000..3ddabc85 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alloc_construct11_test.cpp @@ -0,0 +1,128 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/lightweight_test.hpp> +#include <boost/make_shared.hpp> + +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +struct counters { + unsigned allocate; + unsigned construct; +}; + +template<class T = void> +class creator { +public: + typedef T value_type; + + creator(counters* state) + : state_(state) { } + + template<class U> + creator(const creator<U>& other) + : state_(other.state()) { } + + T* allocate(std::size_t size) { + void* ptr = ::operator new(sizeof(T) * size); + ++state_->allocate; + return static_cast<T*>(ptr); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + --state_->allocate; + } + + template<class... Args> + void construct(T* ptr, Args&&... args) { + ::new(static_cast<void*>(ptr)) T(std::forward<Args>(args)...); + ++state_->construct; + } + + void destroy(T* ptr) { + ptr->~T(); + --state_->construct; + } + + counters* state() const { + return state_; + } + +private: + counters* state_; +}; + +template<class T, class U> +inline bool +operator==(const creator<T>& lhs, const creator<U>& rhs) +{ + return lhs.state() == rhs.state(); +} + +template<class T, class U> +inline bool +operator!=(const creator<T>& lhs, const creator<U>& rhs) +{ + return !(lhs == rhs); +} + +struct deleter { + template<class U> + void operator()(U ptr) const { + delete ptr; + } +}; + +int main() +{ + { + counters state = { }; + boost::shared_ptr<int> pointer(new int(), deleter(), + creator<int>(&state)); + BOOST_TEST(state.allocate == 1); + BOOST_TEST(state.construct == 0); + pointer.reset(); + BOOST_TEST(state.allocate == 0); + } + { + counters state = { }; + boost::shared_ptr<int> pointer = + boost::allocate_shared<int>(creator<int>(&state)); + BOOST_TEST(state.allocate == 1); + BOOST_TEST(state.construct == 1); + pointer.reset(); + BOOST_TEST(state.allocate == 0); + BOOST_TEST(state.construct == 0); + } + { + counters state = { }; + boost::shared_ptr<int[]> pointer = + boost::allocate_shared<int[]>(creator<>(&state), 5); + BOOST_TEST(state.allocate == 1); + BOOST_TEST(state.construct == 5); + pointer.reset(); + BOOST_TEST(state.allocate == 0); + BOOST_TEST(state.construct == 0); + } + { + counters state = { }; + boost::shared_ptr<int[5]> pointer = + boost::allocate_shared<int[5]>(creator<>(&state)); + BOOST_TEST(state.allocate == 1); + BOOST_TEST(state.construct == 5); + pointer.reset(); + BOOST_TEST(state.allocate == 0); + BOOST_TEST(state.construct == 0); + } + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_alloc_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_alloc_test.cpp new file mode 100644 index 00000000..0dedc37f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_alloc_test.cpp @@ -0,0 +1,166 @@ +// +// shared_ptr_alloc_test.cpp - use to evaluate the impact of count allocations +// +// Copyright (c) 2002, 2003 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 <boost/shared_ptr.hpp> +#include <boost/config.hpp> +#include <boost/detail/quick_allocator.hpp> + +#include <iostream> +#include <vector> +#include <ctime> +#include <cstddef> +#include <memory> + +int const n = 1024 * 1024; + +template<class T> void test(T * = 0) +{ + std::clock_t t = std::clock(); + std::clock_t t2; + + { + std::vector< boost::shared_ptr<T> > v; + + for(int i = 0; i < n; ++i) + { + boost::shared_ptr<T> pi(new T(i)); + v.push_back(pi); + } + + t2 = std::clock(); + } + + std::clock_t t3 = std::clock(); + + std::cout << " " << static_cast<double>(t3 - t) / CLOCKS_PER_SEC << " seconds, " << static_cast<double>(t2 - t) / CLOCKS_PER_SEC << " + " << static_cast<double>(t3 - t2) / CLOCKS_PER_SEC << ".\n"; +} + +class X +{ +public: + + explicit X(int n): n_(n) + { + } + + void * operator new(std::size_t) + { + return std::allocator<X>().allocate(1, static_cast<X*>(0)); + } + + void operator delete(void * p) + { + std::allocator<X>().deallocate(static_cast<X*>(p), 1); + } + +private: + + X(X const &); + X & operator=(X const &); + + int n_; +}; + +class Y +{ +public: + + explicit Y(int n): n_(n) + { + } + + void * operator new(std::size_t n) + { + return boost::detail::quick_allocator<Y>::alloc(n); + } + + void operator delete(void * p, std::size_t n) + { + boost::detail::quick_allocator<Y>::dealloc(p, n); + } + +private: + + Y(Y const &); + Y & operator=(Y const &); + + int n_; +}; + +class Z: public Y +{ +public: + + explicit Z(int n): Y(n), m_(n + 1) + { + } + +private: + + Z(Z const &); + Z & operator=(Z const &); + + int m_; +}; + +int main() +{ + std::cout << BOOST_COMPILER "\n"; + std::cout << BOOST_PLATFORM "\n"; + std::cout << BOOST_STDLIB "\n"; + +#if defined(BOOST_HAS_THREADS) + std::cout << "BOOST_HAS_THREADS: (defined)\n"; +#else + std::cout << "BOOST_HAS_THREADS: (not defined)\n"; +#endif + +#if defined(BOOST_SP_USE_STD_ALLOCATOR) + std::cout << "BOOST_SP_USE_STD_ALLOCATOR: (defined)\n"; +#else + std::cout << "BOOST_SP_USE_STD_ALLOCATOR: (not defined)\n"; +#endif + +#if defined(BOOST_SP_USE_QUICK_ALLOCATOR) + std::cout << "BOOST_SP_USE_QUICK_ALLOCATOR: (defined)\n"; +#else + std::cout << "BOOST_SP_USE_QUICK_ALLOCATOR: (not defined)\n"; +#endif + +#if defined(BOOST_QA_PAGE_SIZE) + std::cout << "BOOST_QA_PAGE_SIZE: " << BOOST_QA_PAGE_SIZE << "\n"; +#else + std::cout << "BOOST_QA_PAGE_SIZE: (not defined)\n"; +#endif + + std::cout << n << " shared_ptr<int> allocations + deallocations:\n"; + + test<int>(); + test<int>(); + test<int>(); + + std::cout << n << " shared_ptr<X> allocations + deallocations:\n"; + + test<X>(); + test<X>(); + test<X>(); + + std::cout << n << " shared_ptr<Y> allocations + deallocations:\n"; + + test<Y>(); + test<Y>(); + test<Y>(); + + std::cout << n << " shared_ptr<Z> allocations + deallocations:\n"; + + test<Z>(); + test<Z>(); + test<Z>(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_assign_fail.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_assign_fail.cpp new file mode 100644 index 00000000..c2820e0c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_assign_fail.cpp @@ -0,0 +1,32 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// shared_ptr_assign_fail.cpp - a negative test for shared_ptr assignment +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// 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 <boost/shared_ptr.hpp> + +bool boost_error(char const *, char const *, char const *, long) +{ + return true; +} + +int main() +{ + boost::shared_ptr<int> p; + p = new int(42); // assignment must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_basic_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_basic_test.cpp new file mode 100644 index 00000000..3fc636a5 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_basic_test.cpp @@ -0,0 +1,315 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#pragma warning(disable: 4355) // 'this' : used in base member initializer list + +#if (BOOST_MSVC >= 1310) +#pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +#if defined(__GNUC__) && __GNUC__ > 4 +# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" +#endif + +// +// shared_ptr_basic_test.cpp +// +// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. +// +// 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 <boost/detail/lightweight_test.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +int cnt = 0; + +struct X +{ + X() + { + ++cnt; + } + + ~X() // virtual destructor deliberately omitted + { + --cnt; + } + + virtual int id() const + { + return 1; + } + +private: + + X(X const &); + X & operator= (X const &); +}; + +struct Y: public X +{ + Y() + { + ++cnt; + } + + ~Y() + { + --cnt; + } + + virtual int id() const + { + return 2; + } + +private: + + Y(Y const &); + Y & operator= (Y const &); +}; + +int * get_object() +{ + ++cnt; + return &cnt; +} + +void release_object(int * p) +{ + BOOST_TEST(p == &cnt); + --cnt; +} + +template<class T> void test_is_X(boost::shared_ptr<T> const & p) +{ + BOOST_TEST(p->id() == 1); + BOOST_TEST((*p).id() == 1); +} + +template<class T> void test_is_X(boost::weak_ptr<T> const & p) +{ + BOOST_TEST(p.get() != 0); + BOOST_TEST(p.get()->id() == 1); +} + +template<class T> void test_is_Y(boost::shared_ptr<T> const & p) +{ + BOOST_TEST(p->id() == 2); + BOOST_TEST((*p).id() == 2); +} + +template<class T> void test_is_Y(boost::weak_ptr<T> const & p) +{ + boost::shared_ptr<T> q = p.lock(); + BOOST_TEST(q.get() != 0); + BOOST_TEST(q->id() == 2); +} + +template<class T> void test_eq(T const & a, T const & b) +{ + BOOST_TEST(a == b); + BOOST_TEST(!(a != b)); + BOOST_TEST(!(a < b)); + BOOST_TEST(!(b < a)); +} + +template<class T> void test_ne(T const & a, T const & b) +{ + BOOST_TEST(!(a == b)); + BOOST_TEST(a != b); + BOOST_TEST(a < b || b < a); + BOOST_TEST(!(a < b && b < a)); +} + +template<class T, class U> void test_shared(boost::weak_ptr<T> const & a, boost::weak_ptr<U> const & b) +{ + BOOST_TEST(!(a < b)); + BOOST_TEST(!(b < a)); +} + +template<class T, class U> void test_nonshared(boost::weak_ptr<T> const & a, boost::weak_ptr<U> const & b) +{ + BOOST_TEST(a < b || b < a); + BOOST_TEST(!(a < b && b < a)); +} + +template<class T, class U> void test_eq2(T const & a, U const & b) +{ + BOOST_TEST(a == b); + BOOST_TEST(!(a != b)); +} + +template<class T, class U> void test_ne2(T const & a, U const & b) +{ + BOOST_TEST(!(a == b)); + BOOST_TEST(a != b); +} + +template<class T> void test_is_zero(boost::shared_ptr<T> const & p) +{ + BOOST_TEST(!p); + BOOST_TEST(p.get() == 0); +} + +template<class T> void test_is_nonzero(boost::shared_ptr<T> const & p) +{ + // p? true: false is used to test p in a boolean context. + // BOOST_TEST(p) is not guaranteed to test the conversion, + // as the macro might test !!p instead. + BOOST_TEST(p? true: false); + BOOST_TEST(p.get() != 0); +} + +int main() +{ + using namespace boost; + + { + shared_ptr<X> p(new Y); + shared_ptr<X> p2(new X); + + test_is_nonzero(p); + test_is_nonzero(p2); + test_is_Y(p); + test_is_X(p2); + test_ne(p, p2); + + { + shared_ptr<X> q(p); + test_eq(p, q); + } + +#if !defined( BOOST_NO_RTTI ) + shared_ptr<Y> p3 = dynamic_pointer_cast<Y>(p); + shared_ptr<Y> p4 = dynamic_pointer_cast<Y>(p2); + + test_is_nonzero(p3); + test_is_zero(p4); + + BOOST_TEST(p.use_count() == 2); + BOOST_TEST(p2.use_count() == 1); + BOOST_TEST(p3.use_count() == 2); + + test_is_Y(p3); + test_eq2(p, p3); + test_ne2(p2, p4); +#endif + + shared_ptr<void> p5(p); + + test_is_nonzero(p5); + test_eq2(p, p5); + + weak_ptr<X> wp1(p2); + + BOOST_TEST(!wp1.expired()); + BOOST_TEST(wp1.use_count() != 0); + + p.reset(); + p2.reset(); +#if !defined( BOOST_NO_RTTI ) + p3.reset(); + p4.reset(); +#endif + + test_is_zero(p); + test_is_zero(p2); +#if !defined( BOOST_NO_RTTI ) + test_is_zero(p3); + test_is_zero(p4); +#endif + + BOOST_TEST(p5.use_count() == 1); + + BOOST_TEST(wp1.expired()); + BOOST_TEST(wp1.use_count() == 0); + + try + { + shared_ptr<X> sp1(wp1); + BOOST_ERROR("shared_ptr<X> sp1(wp1) failed to throw"); + } + catch(boost::bad_weak_ptr const &) + { + } + + test_is_zero(wp1.lock()); + + weak_ptr<X> wp2 = static_pointer_cast<X>(p5); + + BOOST_TEST(wp2.use_count() == 1); + test_is_Y(wp2); + test_nonshared(wp1, wp2); + + // Scoped to not affect the subsequent use_count() tests. + { + shared_ptr<X> sp2(wp2); + test_is_nonzero(wp2.lock()); + } + +#if !defined( BOOST_NO_RTTI ) + weak_ptr<Y> wp3 = dynamic_pointer_cast<Y>(wp2.lock()); + + BOOST_TEST(wp3.use_count() == 1); + test_shared(wp2, wp3); + + weak_ptr<X> wp4(wp3); + + BOOST_TEST(wp4.use_count() == 1); + test_shared(wp2, wp4); +#endif + + wp1 = p2; + test_is_zero(wp1.lock()); + +#if !defined( BOOST_NO_RTTI ) + wp1 = p4; + wp1 = wp3; +#endif + wp1 = wp2; + + BOOST_TEST(wp1.use_count() == 1); + test_shared(wp1, wp2); + + weak_ptr<X> wp5; + + bool b1 = wp1 < wp5; + bool b2 = wp5 < wp1; + + p5.reset(); + + BOOST_TEST(wp1.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); +#if !defined( BOOST_NO_RTTI ) + BOOST_TEST(wp3.use_count() == 0); +#endif + + // Test operator< stability for std::set< weak_ptr<> > + // Thanks to Joe Gottman for pointing this out + + BOOST_TEST(b1 == (wp1 < wp5)); + BOOST_TEST(b2 == (wp5 < wp1)); + + { + // note that both get_object and release_object deal with int* + shared_ptr<void> p6(get_object(), release_object); + } + } + + BOOST_TEST(cnt == 0); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_compare_fail.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_compare_fail.cpp new file mode 100644 index 00000000..296af145 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_compare_fail.cpp @@ -0,0 +1,27 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// shared_ptr_compare_fail.cpp - a negative test for "p > q" +// +// Copyright 2006 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 <boost/shared_ptr.hpp> + +int main() +{ + boost::shared_ptr<int> p, q; + p > q; // must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_convertible_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_convertible_test.cpp new file mode 100644 index 00000000..7f49e1fb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_convertible_test.cpp @@ -0,0 +1,71 @@ +#include <boost/config.hpp> + +// sp_convertible_test.cpp +// +// Copyright (c) 2008 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> + +// + +class incomplete; + +struct X +{ +}; + +struct Y +{ +}; + +struct Z: public X +{ +}; + +int f( boost::shared_ptr<void const> ) +{ + return 1; +} + +int f( boost::shared_ptr<int> ) +{ + return 2; +} + +int f( boost::shared_ptr<incomplete> ) +{ + return 3; +} + +int g( boost::shared_ptr<X> ) +{ + return 4; +} + +int g( boost::shared_ptr<Y> ) +{ + return 5; +} + +int g( boost::shared_ptr<incomplete> ) +{ + return 6; +} + +int main() +{ + boost::shared_ptr<double> p1; + BOOST_TEST( 1 == f( p1 ) ); + BOOST_TEST( 1 == f( boost::shared_ptr<double>() ) ); + + boost::shared_ptr<Z> p2; + BOOST_TEST( 4 == g( p2 ) ); + BOOST_TEST( 4 == g( boost::shared_ptr<Z>() ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_delete_fail.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_delete_fail.cpp new file mode 100644 index 00000000..66cfafef --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_delete_fail.cpp @@ -0,0 +1,27 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// shared_ptr_delete_fail.cpp - a negative test for "delete sp;" +// +// Copyright 2005 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 <boost/shared_ptr.hpp> + +int main() +{ + boost::shared_ptr<int> p; + delete p; // must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_fn_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_fn_test.cpp new file mode 100644 index 00000000..dfbdf189 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_fn_test.cpp @@ -0,0 +1,43 @@ +// +// shared_ptr_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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +static void f() +{ +} + +struct null_deleter +{ + template<class Y> void operator()( Y* ) {} +}; + +int main() +{ + boost::shared_ptr<void()> pf( f, null_deleter() ); + + BOOST_TEST( pf.get() == f ); + BOOST_TEST_EQ( pf.use_count(), 1 ); + BOOST_TEST( boost::get_deleter<null_deleter>( pf ) != 0 ); + + boost::weak_ptr<void()> 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(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_move_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_move_test.cpp new file mode 100644 index 00000000..e659b247 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_move_test.cpp @@ -0,0 +1,107 @@ +// +// shared_ptr_move_test.cpp +// +// Copyright (c) 2007 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <utility> + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +long X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X> p2( std::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<void> p3( std::move( p2 ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p2.get() == 0 ); + + p3.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X> p2; + p2 = std::move( p ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<void> p3; + p3 = std::move( p2 ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p2.get() == 0 ); + + p3.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X> p2( new X ); + BOOST_TEST( X::instances == 2 ); + p2 = std::move( p ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<void> p3( new X ); + BOOST_TEST( X::instances == 2 ); + p3 = std::move( p2 ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p2.get() == 0 ); + + p3.reset(); + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} + +#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_pv_fail.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_pv_fail.cpp new file mode 100644 index 00000000..924e6578 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_pv_fail.cpp @@ -0,0 +1,31 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// shared_ptr_pv_fail.cpp - a negative test for converting a shared_ptr to void* +// +// Copyright 2007 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 <boost/shared_ptr.hpp> + +void f( void* ) +{ +} + +int main() +{ + boost::shared_ptr<int> p; + f( p ); // must fail + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_reinterpret_pointer_cast_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_reinterpret_pointer_cast_test.cpp new file mode 100644 index 00000000..e7076df9 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_reinterpret_pointer_cast_test.cpp @@ -0,0 +1,55 @@ +// +// shared_pointer_reinterpret_pointer_cast_test.cpp +// +// Copyright (c) 2016 Chris Glover +// +// 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct X +{}; + +int main() +{ + { + boost::shared_ptr<char> pc; + + boost::shared_ptr<int> pi = boost::reinterpret_pointer_cast<int>(pc); + BOOST_TEST(pi.get() == 0); + + boost::shared_ptr<X> px = boost::reinterpret_pointer_cast<X>(pc); + BOOST_TEST(px.get() == 0); + } + + { + boost::shared_ptr<int> pi(new int); + boost::shared_ptr<char> pc = boost::reinterpret_pointer_cast<char>(pi); + + boost::shared_ptr<int> pi2 = boost::reinterpret_pointer_cast<int>(pc); + BOOST_TEST(pi.get() == pi2.get()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); + BOOST_TEST(pi.use_count() == 3); + BOOST_TEST(pc.use_count() == 3); + BOOST_TEST(pi2.use_count() == 3); + } + + { + boost::shared_ptr<X> px(new X); + boost::shared_ptr<char> pc = boost::reinterpret_pointer_cast<char>(px); + + boost::shared_ptr<X> px2 = boost::reinterpret_pointer_cast<X>(pc); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + BOOST_TEST(px.use_count() == 3); + BOOST_TEST(pc.use_count() == 3); + BOOST_TEST(px2.use_count() == 3); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_rv_pointer_cast_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_rv_pointer_cast_test.cpp new file mode 100644 index 00000000..c471bdab --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_rv_pointer_cast_test.cpp @@ -0,0 +1,106 @@ +// +// shared_ptr_rv_pointer_cast_test.cpp +// +// Copyright (c) 2016 Chris Glover +// +// 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +struct X +{}; + +struct Y: public X +{}; + +struct U +{ + virtual ~U() {} +}; + +struct V: public U +{}; + +struct W : public U +{}; + +int main() +{ + { + boost::shared_ptr<X> px(new Y); + + boost::shared_ptr<Y> py1 = boost::static_pointer_cast<Y>(px); + boost::shared_ptr<Y> py2 = boost::static_pointer_cast<Y>(std::move(px)); + BOOST_TEST(!px); + BOOST_TEST(px.use_count() == 0); + BOOST_TEST(py1.get() == py2.get()); + BOOST_TEST(!(py1 < py2 || py2 < py1)); + BOOST_TEST(py1.use_count() == 2); + BOOST_TEST(py2.use_count() == 2); + } + + { + boost::shared_ptr<int const volatile> px(new int); + + boost::shared_ptr<int> px2 = boost::const_pointer_cast<int>(px); + boost::shared_ptr<int> px3 = boost::const_pointer_cast<int>(std::move(px)); + BOOST_TEST(!px); + BOOST_TEST(px.use_count() == 0); + BOOST_TEST(px2.get() == px3.get()); + BOOST_TEST(!(px2 < px3 || px2 < px3)); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(px3.use_count() == 2); + } + + { + boost::shared_ptr<char> pv(reinterpret_cast<char*>(new Y)); + + boost::shared_ptr<Y> py1 = boost::reinterpret_pointer_cast<Y>(pv); + boost::shared_ptr<Y> py2 = boost::reinterpret_pointer_cast<Y>(std::move(pv)); + BOOST_TEST(!pv); + BOOST_TEST(pv.use_count() == 0); + BOOST_TEST(py1.get() == py2.get()); + BOOST_TEST(!(py1 < py2 || py2 < py1)); + BOOST_TEST(py1.use_count() == 2); + BOOST_TEST(py2.use_count() == 2); + } + +#if !defined( BOOST_NO_RTTI ) + { + boost::shared_ptr<U> pu(new V); + + boost::shared_ptr<V> pv1 = boost::dynamic_pointer_cast<V>(pu); + boost::shared_ptr<V> pv2 = boost::dynamic_pointer_cast<V>(std::move(pu)); + BOOST_TEST(!pu); + BOOST_TEST(pu.use_count() == 0); + BOOST_TEST(pv1.get() == pv2.get()); + BOOST_TEST(!(pv1 < pv2 || pv2 < pv1)); + BOOST_TEST(pv1.use_count() == 2); + BOOST_TEST(pv2.use_count() == 2); + } + + { + boost::shared_ptr<U> pu(new V); + boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(std::move(pu)); + BOOST_TEST(!pw); + BOOST_TEST(pu); + } +#endif // !defined( BOOST_NO_RTTI ) + + return boost::report_errors(); +} + +#else // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_rv_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_rv_test.cpp new file mode 100644 index 00000000..fe77259b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_rv_test.cpp @@ -0,0 +1,110 @@ +// +// shared_ptr_rv_test.cpp +// +// Copyright (c) 2007 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + static boost::shared_ptr<X> create() + { + return boost::shared_ptr<X>( new X ); + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +long X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X const> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<void> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<void const> p( X::create() ); + BOOST_TEST( X::instances == 1 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + + p.reset(); + BOOST_TEST( X::instances == 0 ); + + p = X::create(); + BOOST_TEST( X::instances == 1 ); + } + + BOOST_TEST( X::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/shared_ptr_test.cpp b/src/boost/libs/smart_ptr/test/shared_ptr_test.cpp new file mode 100644 index 00000000..b76f954c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/shared_ptr_test.cpp @@ -0,0 +1,3400 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#pragma warning(disable: 4355) // 'this' : used in base member initializer list + +#if (BOOST_MSVC >= 1310) +#pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +#if defined(__GNUC__) && __GNUC__ > 4 +# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" +#endif + +// +// shared_ptr_test.cpp +// +// Copyright (c) 2002, 2003 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 <boost/detail/lightweight_test.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +#include <map> +#include <vector> + +// + +namespace n_element_type +{ + +void f(int &) +{ +} + +void test() +{ + typedef boost::shared_ptr<int>::element_type T; + T t; + f(t); +} + +} // namespace n_element_type + +namespace n_constructors +{ + +class incomplete; + +void default_constructor() +{ + { + boost::shared_ptr<int> pi; + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 0); + } + + { + boost::shared_ptr<void> pv; + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 0); + } + + { + boost::shared_ptr<incomplete> px; + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 0); + } +} + +struct A +{ + int dummy; +}; + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X(X const &); + X & operator= (X const &); +}; + +long X::instances = 0; + +// virtual inheritance stresses the implementation + +struct Y: public A, public virtual X +{ + static long instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y(Y const &); + Y & operator= (Y const &); +}; + +long Y::instances = 0; + +template<class T> void pc0_test(T * p) +{ + BOOST_TEST(p == 0); + boost::shared_ptr<T> pt(p); + BOOST_TEST(pt? false: true); + BOOST_TEST(!pt); + BOOST_TEST(pt.get() == 0); + BOOST_TEST(pt.use_count() == 1); + BOOST_TEST(pt.unique()); +} + +void pointer_constructor() +{ + pc0_test(static_cast<int*>(0)); + +#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300) + + pc0_test(static_cast<int const*>(0)); + pc0_test(static_cast<int volatile*>(0)); + pc0_test(static_cast<int const volatile*>(0)); + +#endif + + { + boost::shared_ptr<int const> pi(static_cast<int*>(0)); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + } + + { + boost::shared_ptr<int volatile> pi(static_cast<int*>(0)); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + } + + { + boost::shared_ptr<void> pv(static_cast<int*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + boost::shared_ptr<void const> pv(static_cast<int*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + pc0_test(static_cast<X*>(0)); + pc0_test(static_cast<X const*>(0)); + pc0_test(static_cast<X volatile*>(0)); + pc0_test(static_cast<X const volatile*>(0)); + + { + boost::shared_ptr<X const> px(static_cast<X*>(0)); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + } + + { + boost::shared_ptr<X> px(static_cast<Y*>(0)); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + } + + { + boost::shared_ptr<X const> px(static_cast<Y*>(0)); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + } + + { + boost::shared_ptr<void> pv(static_cast<X*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + boost::shared_ptr<void const> pv(static_cast<X*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + int * p = new int(7); + boost::shared_ptr<int> pi(p); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == p); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + BOOST_TEST(*pi == 7); + } + + { + int * p = new int(7); + boost::shared_ptr<int const> pi(p); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == p); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + BOOST_TEST(*pi == 7); + } + + { + int * p = new int(7); + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == p); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + int * p = new int(7); + boost::shared_ptr<void const> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == p); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + BOOST_TEST(X::instances == 0); + + { + X * p = new X; + boost::shared_ptr<X> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + } + + BOOST_TEST(X::instances == 0); + + { + X * p = new X; + boost::shared_ptr<X const> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + } + + BOOST_TEST(X::instances == 0); + + { + X * p = new X; + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == p); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 1); + } + + BOOST_TEST(X::instances == 0); + + { + X * p = new X; + boost::shared_ptr<void const> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == p); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 1); + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + { + Y * p = new Y; + boost::shared_ptr<X> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + { + Y * p = new Y; + boost::shared_ptr<X const> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); +} + +int m = 0; + +void deleter(int * p) +{ + BOOST_TEST(p == 0); +} + +void deleter2(int * p) +{ + BOOST_TEST(p == &m); + ++*p; +} + +struct deleter3 +{ + void operator()(incomplete * p) + { + BOOST_TEST(p == 0); + } +}; + +// Borland C++ 5.5.1 fails on static_cast<incomplete*>(0) + +incomplete * p0 = 0; + +void deleter_constructor() +{ + { + boost::shared_ptr<int> pi(static_cast<int*>(0), deleter); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + } + + { + boost::shared_ptr<void> pv(static_cast<int*>(0), &deleter); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + boost::shared_ptr<void const> pv(static_cast<int*>(0), deleter); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + boost::shared_ptr<incomplete> px(p0, deleter3()); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + } + + { + boost::shared_ptr<void> pv(p0, deleter3()); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + { + boost::shared_ptr<void const> pv(p0, deleter3()); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + BOOST_TEST(m == 0); + + { + boost::shared_ptr<int> pi(&m, deleter2); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == &m); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + } + + BOOST_TEST(m == 1); + + { + boost::shared_ptr<int const> pi(&m, &deleter2); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == &m); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + } + + BOOST_TEST(m == 2); + + { + boost::shared_ptr<void> pv(&m, deleter2); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == &m); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + BOOST_TEST(m == 3); + + { + boost::shared_ptr<void const> pv(&m, &deleter2); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == &m); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + } + + BOOST_TEST(m == 4); +} + +void copy_constructor() +{ + { + boost::shared_ptr<int> pi; + + boost::shared_ptr<int> pi2(pi); + BOOST_TEST(pi2 == pi); + BOOST_TEST(pi2? false: true); + BOOST_TEST(!pi2); + BOOST_TEST(pi2.get() == 0); + BOOST_TEST(pi2.use_count() == pi.use_count()); + + boost::shared_ptr<void> pi3(pi); + BOOST_TEST(pi3 == pi); + BOOST_TEST(pi3? false: true); + BOOST_TEST(!pi3); + BOOST_TEST(pi3.get() == 0); + BOOST_TEST(pi3.use_count() == pi.use_count()); + + boost::shared_ptr<void> pi4(pi3); + BOOST_TEST(pi4 == pi3); + BOOST_TEST(pi4? false: true); + BOOST_TEST(!pi4); + BOOST_TEST(pi4.get() == 0); + BOOST_TEST(pi4.use_count() == pi3.use_count()); + } + + { + boost::shared_ptr<void> pv; + + boost::shared_ptr<void> pv2(pv); + BOOST_TEST(pv2 == pv); + BOOST_TEST(pv2? false: true); + BOOST_TEST(!pv2); + BOOST_TEST(pv2.get() == 0); + BOOST_TEST(pv2.use_count() == pv.use_count()); + } + + { + boost::shared_ptr<incomplete> px; + + boost::shared_ptr<incomplete> px2(px); + BOOST_TEST(px2 == px); + BOOST_TEST(px2? false: true); + BOOST_TEST(!px2); + BOOST_TEST(px2.get() == 0); + BOOST_TEST(px2.use_count() == px.use_count()); + + boost::shared_ptr<void> px3(px); + BOOST_TEST(px3 == px); + BOOST_TEST(px3? false: true); + BOOST_TEST(!px3); + BOOST_TEST(px3.get() == 0); + BOOST_TEST(px3.use_count() == px.use_count()); + } + + { + boost::shared_ptr<int> pi(static_cast<int*>(0)); + + boost::shared_ptr<int> pi2(pi); + BOOST_TEST(pi2 == pi); + BOOST_TEST(pi2? false: true); + BOOST_TEST(!pi2); + BOOST_TEST(pi2.get() == 0); + BOOST_TEST(pi2.use_count() == 2); + BOOST_TEST(!pi2.unique()); + BOOST_TEST(pi2.use_count() == pi.use_count()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); // shared ownership test + + boost::shared_ptr<void> pi3(pi); + BOOST_TEST(pi3 == pi); + BOOST_TEST(pi3? false: true); + BOOST_TEST(!pi3); + BOOST_TEST(pi3.get() == 0); + BOOST_TEST(pi3.use_count() == 3); + BOOST_TEST(!pi3.unique()); + BOOST_TEST(pi3.use_count() == pi.use_count()); + BOOST_TEST(!(pi < pi3 || pi3 < pi)); // shared ownership test + + boost::shared_ptr<void> pi4(pi2); + BOOST_TEST(pi4 == pi2); + BOOST_TEST(pi4? false: true); + BOOST_TEST(!pi4); + BOOST_TEST(pi4.get() == 0); + BOOST_TEST(pi4.use_count() == 4); + BOOST_TEST(!pi4.unique()); + BOOST_TEST(pi4.use_count() == pi2.use_count()); + BOOST_TEST(!(pi2 < pi4 || pi4 < pi2)); // shared ownership test + + BOOST_TEST(pi3.use_count() == pi4.use_count()); + BOOST_TEST(!(pi3 < pi4 || pi4 < pi3)); // shared ownership test + } + + { + boost::shared_ptr<X> px(static_cast<X*>(0)); + + boost::shared_ptr<X> px2(px); + BOOST_TEST(px2 == px); + BOOST_TEST(px2? false: true); + BOOST_TEST(!px2); + BOOST_TEST(px2.get() == 0); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(!px2.unique()); + BOOST_TEST(px2.use_count() == px.use_count()); + BOOST_TEST(!(px < px2 || px2 < px)); // shared ownership test + + boost::shared_ptr<void> px3(px); + BOOST_TEST(px3 == px); + BOOST_TEST(px3? false: true); + BOOST_TEST(!px3); + BOOST_TEST(px3.get() == 0); + BOOST_TEST(px3.use_count() == 3); + BOOST_TEST(!px3.unique()); + BOOST_TEST(px3.use_count() == px.use_count()); + BOOST_TEST(!(px < px3 || px3 < px)); // shared ownership test + + boost::shared_ptr<void> px4(px2); + BOOST_TEST(px4 == px2); + BOOST_TEST(px4? false: true); + BOOST_TEST(!px4); + BOOST_TEST(px4.get() == 0); + BOOST_TEST(px4.use_count() == 4); + BOOST_TEST(!px4.unique()); + BOOST_TEST(px4.use_count() == px2.use_count()); + BOOST_TEST(!(px2 < px4 || px4 < px2)); // shared ownership test + + BOOST_TEST(px3.use_count() == px4.use_count()); + BOOST_TEST(!(px3 < px4 || px4 < px3)); // shared ownership test + } + + { + int * p = new int(7); + boost::shared_ptr<int> pi(p); + + boost::shared_ptr<int> pi2(pi); + BOOST_TEST(pi2 == pi); + BOOST_TEST(pi2? true: false); + BOOST_TEST(!!pi2); + BOOST_TEST(pi2.get() == p); + BOOST_TEST(pi2.use_count() == 2); + BOOST_TEST(!pi2.unique()); + BOOST_TEST(*pi2 == 7); + BOOST_TEST(pi2.use_count() == pi.use_count()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); // shared ownership test + } + + { + int * p = new int(7); + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv.get() == p); + + boost::shared_ptr<void> pv2(pv); + BOOST_TEST(pv2 == pv); + BOOST_TEST(pv2? true: false); + BOOST_TEST(!!pv2); + BOOST_TEST(pv2.get() == p); + BOOST_TEST(pv2.use_count() == 2); + BOOST_TEST(!pv2.unique()); + BOOST_TEST(pv2.use_count() == pv.use_count()); + BOOST_TEST(!(pv < pv2 || pv2 < pv)); // shared ownership test + } + + BOOST_TEST(X::instances == 0); + + { + X * p = new X; + boost::shared_ptr<X> px(p); + BOOST_TEST(px.get() == p); + + boost::shared_ptr<X> px2(px); + BOOST_TEST(px2 == px); + BOOST_TEST(px2? true: false); + BOOST_TEST(!!px2); + BOOST_TEST(px2.get() == p); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(!px2.unique()); + + BOOST_TEST(X::instances == 1); + + BOOST_TEST(px2.use_count() == px.use_count()); + BOOST_TEST(!(px < px2 || px2 < px)); // shared ownership test + + boost::shared_ptr<void> px3(px); + BOOST_TEST(px3 == px); + BOOST_TEST(px3? true: false); + BOOST_TEST(!!px3); + BOOST_TEST(px3.get() == p); + BOOST_TEST(px3.use_count() == 3); + BOOST_TEST(!px3.unique()); + BOOST_TEST(px3.use_count() == px.use_count()); + BOOST_TEST(!(px < px3 || px3 < px)); // shared ownership test + + boost::shared_ptr<void> px4(px2); + BOOST_TEST(px4 == px2); + BOOST_TEST(px4? true: false); + BOOST_TEST(!!px4); + BOOST_TEST(px4.get() == p); + BOOST_TEST(px4.use_count() == 4); + BOOST_TEST(!px4.unique()); + BOOST_TEST(px4.use_count() == px2.use_count()); + BOOST_TEST(!(px2 < px4 || px4 < px2)); // shared ownership test + + BOOST_TEST(px3.use_count() == px4.use_count()); + BOOST_TEST(!(px3 < px4 || px4 < px3)); // shared ownership test + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + { + Y * p = new Y; + boost::shared_ptr<Y> py(p); + BOOST_TEST(py.get() == p); + + boost::shared_ptr<X> px(py); + BOOST_TEST(px == py); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(!px.unique()); + BOOST_TEST(px.use_count() == py.use_count()); + BOOST_TEST(!(px < py || py < px)); // shared ownership test + + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + + boost::shared_ptr<void const> pv(px); + BOOST_TEST(pv == px); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == px.get()); + BOOST_TEST(pv.use_count() == 3); + BOOST_TEST(!pv.unique()); + BOOST_TEST(pv.use_count() == px.use_count()); + BOOST_TEST(!(px < pv || pv < px)); // shared ownership test + + boost::shared_ptr<void const> pv2(py); + BOOST_TEST(pv2 == py); + BOOST_TEST(pv2? true: false); + BOOST_TEST(!!pv2); + BOOST_TEST(pv2.get() == py.get()); + BOOST_TEST(pv2.use_count() == 4); + BOOST_TEST(!pv2.unique()); + BOOST_TEST(pv2.use_count() == py.use_count()); + BOOST_TEST(!(py < pv2 || pv2 < py)); // shared ownership test + + BOOST_TEST(pv.use_count() == pv2.use_count()); + BOOST_TEST(!(pv < pv2 || pv2 < pv)); // shared ownership test + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); +} + +void weak_ptr_constructor() +{ + { + boost::weak_ptr<Y> wp; + BOOST_TEST(wp.use_count() == 0); + + try + { + boost::shared_ptr<Y> p2(wp); + BOOST_ERROR("shared_ptr<Y> p2(wp) failed to throw"); + } + catch(boost::bad_weak_ptr const&) + { + } + + try + { + boost::shared_ptr<X> p3(wp); + BOOST_ERROR("shared_ptr<X> p3(wp) failed to throw"); + } + catch(boost::bad_weak_ptr const&) + { + } + } + + { + boost::shared_ptr<Y> p; + boost::weak_ptr<Y> wp(p); + + if(wp.use_count() != 0) // 0 allowed but not required + { + boost::shared_ptr<Y> p2(wp); + BOOST_TEST(p2.use_count() == wp.use_count()); + BOOST_TEST(p2.get() == 0); + + boost::shared_ptr<X> p3(wp); + BOOST_TEST(p3.use_count() == wp.use_count()); + BOOST_TEST(p3.get() == 0); + } + } + + { + boost::shared_ptr<Y> p(new Y); + boost::weak_ptr<Y> wp(p); + + { + boost::shared_ptr<Y> p2(wp); + BOOST_TEST(p2? true: false); + BOOST_TEST(!!p2); + BOOST_TEST(p2.get() == p.get()); + BOOST_TEST(p2.use_count() == 2); + BOOST_TEST(!p2.unique()); + BOOST_TEST(p2.use_count() == wp.use_count()); + + BOOST_TEST(p.use_count() == p2.use_count()); + BOOST_TEST(!(p < p2 || p2 < p)); // shared ownership test + + boost::shared_ptr<X> p3(wp); + BOOST_TEST(p3? true: false); + BOOST_TEST(!!p3); + BOOST_TEST(p3.get() == p.get()); + BOOST_TEST(p3.use_count() == 3); + BOOST_TEST(!p3.unique()); + BOOST_TEST(p3.use_count() == wp.use_count()); + + BOOST_TEST(p.use_count() == p3.use_count()); + } + + p.reset(); + BOOST_TEST(wp.use_count() == 0); + + try + { + boost::shared_ptr<Y> p2(wp); + BOOST_ERROR("shared_ptr<Y> p2(wp) failed to throw"); + } + catch(boost::bad_weak_ptr const&) + { + } + + try + { + boost::shared_ptr<X> p3(wp); + BOOST_ERROR("shared_ptr<X> p3(wp) failed to throw"); + } + catch(boost::bad_weak_ptr const&) + { + } + } +} + +#if defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB < 306) +# define BOOST_OLD_AUTO_PTR +#endif + +void auto_ptr_constructor() +{ +#if !defined( BOOST_NO_AUTO_PTR ) + + { + std::auto_ptr<int> p; + boost::shared_ptr<int> pi(p); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<int> p; + boost::shared_ptr<int const> pi(p); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<int> p; + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<int> p; + boost::shared_ptr<void const> pv(p); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<X> p; + boost::shared_ptr<X> px(p); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<X> p; + boost::shared_ptr<X const> px(p); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<Y> p; + boost::shared_ptr<X> px(p); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<Y> p; + boost::shared_ptr<X const> px(p); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<Y> p; + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<Y> p; + boost::shared_ptr<void const> pv(p); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(p.get() == 0); + } + + { + std::auto_ptr<int> p(new int(7)); + int * q = p.get(); + boost::shared_ptr<int> pi(p); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == q); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + BOOST_TEST(*pi == 7); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + { + std::auto_ptr<int> p(new int(7)); + int * q = p.get(); + boost::shared_ptr<int const> pi(p); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == q); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + BOOST_TEST(*pi == 7); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + { + std::auto_ptr<int> p(new int(7)); + int * q = p.get(); + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == q); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + { + std::auto_ptr<int> p(new int(7)); + int * q = p.get(); + boost::shared_ptr<void const> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == q); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + + { + std::auto_ptr<X> p(new X); + X * q = p.get(); + boost::shared_ptr<X> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == q); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + + { + std::auto_ptr<X> p(new X); + X * q = p.get(); + boost::shared_ptr<X const> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == q); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + + { + std::auto_ptr<X> p(new X); + X * q = p.get(); + boost::shared_ptr<void> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == q); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + + { + std::auto_ptr<X> p(new X); + X * q = p.get(); + boost::shared_ptr<void const> pv(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == q); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + { + std::auto_ptr<Y> p(new Y); + Y * q = p.get(); + boost::shared_ptr<X> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == q); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + { + std::auto_ptr<Y> p(new Y); + Y * q = p.get(); + boost::shared_ptr<X const> px(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == q); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p.get() == 0); +#endif + } + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + +#endif // #if !defined( BOOST_NO_AUTO_PTR ) +} + +void test() +{ + default_constructor(); + pointer_constructor(); + deleter_constructor(); + copy_constructor(); + weak_ptr_constructor(); + auto_ptr_constructor(); +} + +} // namespace n_constructors + +namespace n_assignment +{ + +class incomplete; + +struct A +{ + int dummy; +}; + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X(X const &); + X & operator= (X const &); +}; + +long X::instances = 0; + +struct Y: public A, public virtual X +{ + static long instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y(Y const &); + Y & operator= (Y const &); +}; + +long Y::instances = 0; + +void copy_assignment() +{ + { + boost::shared_ptr<incomplete> p1; + + p1 = p1; + + BOOST_TEST(p1 == p1); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<incomplete> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<incomplete> p3(p1); + + p1 = p3; + + BOOST_TEST(p1 == p3); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + } + + { + boost::shared_ptr<void> p1; + + p1 = p1; + + BOOST_TEST(p1 == p1); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<void> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<void> p3(p1); + + p1 = p3; + + BOOST_TEST(p1 == p3); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<void> p4(new int); + BOOST_TEST(p4.use_count() == 1); + + p1 = p4; + + BOOST_TEST(p1 == p4); + BOOST_TEST(!(p1 < p4 || p4 < p1)); + BOOST_TEST(p1.use_count() == 2); + BOOST_TEST(p4.use_count() == 2); + + p1 = p3; + + BOOST_TEST(p1 == p3); + BOOST_TEST(p4.use_count() == 1); + } + + { + boost::shared_ptr<X> p1; + + p1 = p1; + + BOOST_TEST(p1 == p1); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<X> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<X> p3(p1); + + p1 = p3; + + BOOST_TEST(p1 == p3); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + BOOST_TEST(X::instances == 0); + + boost::shared_ptr<X> p4(new X); + + BOOST_TEST(X::instances == 1); + + p1 = p4; + + BOOST_TEST(X::instances == 1); + + BOOST_TEST(p1 == p4); + BOOST_TEST(!(p1 < p4 || p4 < p1)); + + BOOST_TEST(p1.use_count() == 2); + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(X::instances == 1); + + p4 = p3; + + BOOST_TEST(p4 == p3); + BOOST_TEST(X::instances == 0); + } +} + +void conversion_assignment() +{ + { + boost::shared_ptr<void> p1; + + boost::shared_ptr<incomplete> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + boost::shared_ptr<int> p4(new int); + BOOST_TEST(p4.use_count() == 1); + + boost::shared_ptr<void> p5(p4); + BOOST_TEST(p4.use_count() == 2); + + p1 = p4; + + BOOST_TEST(p1 == p4); + BOOST_TEST(!(p1 < p5 || p5 < p1)); + BOOST_TEST(p1.use_count() == 3); + BOOST_TEST(p4.use_count() == 3); + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p4.use_count() == 2); + } + + { + boost::shared_ptr<X> p1; + + boost::shared_ptr<Y> p2; + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + boost::shared_ptr<Y> p4(new Y); + + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + BOOST_TEST(p4.use_count() == 1); + + boost::shared_ptr<X> p5(p4); + BOOST_TEST(p4.use_count() == 2); + + p1 = p4; + + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + + BOOST_TEST(p1 == p4); + BOOST_TEST(!(p1 < p5 || p5 < p1)); + + BOOST_TEST(p1.use_count() == 3); + BOOST_TEST(p4.use_count() == 3); + + p1 = p2; + + BOOST_TEST(p1 == p2); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + BOOST_TEST(p4.use_count() == 2); + + p4 = p2; + p5 = p2; + + BOOST_TEST(p4 == p2); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + } +} + +void auto_ptr_assignment() +{ +#if !defined( BOOST_NO_AUTO_PTR ) + + { + boost::shared_ptr<int> p1; + + std::auto_ptr<int> p2; + + p1 = p2; + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + BOOST_TEST(p1.use_count() == 1); + + int * p = new int; + std::auto_ptr<int> p3(p); + + p1 = p3; + BOOST_TEST(p1.get() == p); + BOOST_TEST(p1.use_count() == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p3.get() == 0); +#endif + + p1 = p2; + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + BOOST_TEST(p1.use_count() == 1); + } + + { + boost::shared_ptr<void> p1; + + std::auto_ptr<int> p2; + + p1 = p2; + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + BOOST_TEST(p1.use_count() == 1); + + int * p = new int; + std::auto_ptr<int> p3(p); + + p1 = p3; + BOOST_TEST(p1.get() == p); + BOOST_TEST(p1.use_count() == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p3.get() == 0); +#endif + + p1 = p2; + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + BOOST_TEST(p1.use_count() == 1); + } + + + { + boost::shared_ptr<X> p1; + + std::auto_ptr<Y> p2; + + p1 = p2; + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + BOOST_TEST(p1.use_count() == 1); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + Y * p = new Y; + std::auto_ptr<Y> p3(p); + + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + + p1 = p3; + BOOST_TEST(p1.get() == p); + BOOST_TEST(p1.use_count() == 1); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + +#if !defined(BOOST_OLD_AUTO_PTR) + BOOST_TEST(p3.get() == 0); +#endif + + p1 = p2; + BOOST_TEST(p1? false: true); + BOOST_TEST(!p1); + BOOST_TEST(p1.get() == 0); + BOOST_TEST(p1.use_count() == 1); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + } + +#endif // #if !defined( BOOST_NO_AUTO_PTR ) +} + +void test() +{ + copy_assignment(); + conversion_assignment(); + auto_ptr_assignment(); +} + +} // namespace n_assignment + +namespace n_reset +{ + +class incomplete; + +incomplete * p0 = 0; + +void deleter(incomplete *) +{ +} + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X(X const &); + X & operator= (X const &); +}; + +long X::instances = 0; + +void plain_reset() +{ + { + boost::shared_ptr<int> pi; + pi.reset(); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 0); + } + + { + boost::shared_ptr<int> pi(static_cast<int*>(0)); + pi.reset(); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 0); + } + + { + boost::shared_ptr<int> pi(new int); + pi.reset(); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 0); + } + + { + boost::shared_ptr<incomplete> px; + px.reset(); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 0); + } + + { + boost::shared_ptr<incomplete> px(p0, deleter); + px.reset(); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 0); + } + + { + boost::shared_ptr<X> px; + px.reset(); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 0); + } + + { + BOOST_TEST(X::instances == 0); + boost::shared_ptr<X> px(new X); + BOOST_TEST(X::instances == 1); + px.reset(); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 0); + BOOST_TEST(X::instances == 0); + } + + { + boost::shared_ptr<void> pv; + pv.reset(); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 0); + } + + { + BOOST_TEST(X::instances == 0); + boost::shared_ptr<void> pv(new X); + BOOST_TEST(X::instances == 1); + pv.reset(); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 0); + BOOST_TEST(X::instances == 0); + } +} + +struct A +{ + int dummy; +}; + +struct Y: public A, public virtual X +{ + static long instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y(Y const &); + Y & operator= (Y const &); +}; + +long Y::instances = 0; + +void pointer_reset() +{ + { + boost::shared_ptr<int> pi; + + pi.reset(static_cast<int*>(0)); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + + int * p = new int; + pi.reset(p); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == p); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + + pi.reset(static_cast<int*>(0)); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + } + + { + boost::shared_ptr<X> px; + + px.reset(static_cast<X*>(0)); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 0); + + X * p = new X; + px.reset(p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + + px.reset(static_cast<X*>(0)); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + Y * q = new Y; + px.reset(q); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == q); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + + px.reset(static_cast<Y*>(0)); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + } + + { + boost::shared_ptr<void> pv; + + pv.reset(static_cast<X*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 0); + + X * p = new X; + pv.reset(p); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == p); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 1); + + pv.reset(static_cast<X*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + + Y * q = new Y; + pv.reset(q); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == q); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 1); + BOOST_TEST(Y::instances == 1); + + pv.reset(static_cast<Y*>(0)); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + BOOST_TEST(X::instances == 0); + BOOST_TEST(Y::instances == 0); + } +} + +void * deleted = 0; + +void deleter2(void * p) +{ + deleted = p; +} + +void deleter_reset() +{ + { + boost::shared_ptr<int> pi; + + pi.reset(static_cast<int*>(0), deleter2); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + + deleted = π + + int m = 0; + pi.reset(&m, deleter2); + BOOST_TEST(deleted == 0); + BOOST_TEST(pi? true: false); + BOOST_TEST(!!pi); + BOOST_TEST(pi.get() == &m); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + + pi.reset(static_cast<int*>(0), deleter2); + BOOST_TEST(deleted == &m); + BOOST_TEST(pi? false: true); + BOOST_TEST(!pi); + BOOST_TEST(pi.get() == 0); + BOOST_TEST(pi.use_count() == 1); + BOOST_TEST(pi.unique()); + + pi.reset(); + BOOST_TEST(deleted == 0); + } + + { + boost::shared_ptr<X> px; + + px.reset(static_cast<X*>(0), deleter2); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + deleted = &px; + + X x; + px.reset(&x, deleter2); + BOOST_TEST(deleted == 0); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == &x); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + px.reset(static_cast<X*>(0), deleter2); + BOOST_TEST(deleted == &x); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + Y y; + px.reset(&y, deleter2); + BOOST_TEST(deleted == 0); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(px.get() == &y); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + px.reset(static_cast<Y*>(0), deleter2); + BOOST_TEST(deleted == &y); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + px.reset(); + BOOST_TEST(deleted == 0); + } + + { + boost::shared_ptr<void> pv; + + pv.reset(static_cast<X*>(0), deleter2); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + + deleted = &pv; + + X x; + pv.reset(&x, deleter2); + BOOST_TEST(deleted == 0); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == &x); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + + pv.reset(static_cast<X*>(0), deleter2); + BOOST_TEST(deleted == &x); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + + Y y; + pv.reset(&y, deleter2); + BOOST_TEST(deleted == 0); + BOOST_TEST(pv? true: false); + BOOST_TEST(!!pv); + BOOST_TEST(pv.get() == &y); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + + pv.reset(static_cast<Y*>(0), deleter2); + BOOST_TEST(deleted == &y); + BOOST_TEST(pv? false: true); + BOOST_TEST(!pv); + BOOST_TEST(pv.get() == 0); + BOOST_TEST(pv.use_count() == 1); + BOOST_TEST(pv.unique()); + + pv.reset(); + BOOST_TEST(deleted == 0); + } + + { + boost::shared_ptr<incomplete> px; + + px.reset(p0, deleter2); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + deleted = &px; + px.reset(p0, deleter2); + BOOST_TEST(deleted == 0); + } +} + +void test() +{ + plain_reset(); + pointer_reset(); + deleter_reset(); +} + +} // namespace n_reset + +namespace n_access +{ + +struct X +{ +}; + +void test() +{ + { + boost::shared_ptr<X> px; + BOOST_TEST(px.get() == 0); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + boost::shared_ptr<X> px(static_cast<X*>(0)); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + boost::shared_ptr<X> px(static_cast<X*>(0), boost::checked_deleter<X>()); + BOOST_TEST(px.get() == 0); + BOOST_TEST(px? false: true); + BOOST_TEST(!px); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + X * p = new X; + boost::shared_ptr<X> px(p); + BOOST_TEST(px.get() == p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(&*px == px.get()); + BOOST_TEST(px.operator ->() == px.get()); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } + + { + X * p = new X; + boost::shared_ptr<X> px(p, boost::checked_deleter<X>()); + BOOST_TEST(px.get() == p); + BOOST_TEST(px? true: false); + BOOST_TEST(!!px); + BOOST_TEST(&*px == px.get()); + BOOST_TEST(px.operator ->() == px.get()); + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + using boost::get_pointer; +#endif + + BOOST_TEST(get_pointer(px) == px.get()); + } +} + +} // namespace n_access + +namespace n_use_count +{ + +struct X +{ +}; + +void test() +{ + { + boost::shared_ptr<X> px(static_cast<X*>(0)); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + boost::shared_ptr<X> px2(px); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(!px2.unique()); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(!px.unique()); + } + + { + boost::shared_ptr<X> px(new X); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + boost::shared_ptr<X> px2(px); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(!px2.unique()); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(!px.unique()); + } + + { + boost::shared_ptr<X> px(new X, boost::checked_deleter<X>()); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px.unique()); + + boost::shared_ptr<X> px2(px); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(!px2.unique()); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(!px.unique()); + } +} + +} // namespace n_use_count + +namespace n_swap +{ + +struct X +{ +}; + +void test() +{ + { + boost::shared_ptr<X> px; + boost::shared_ptr<X> px2; + + px.swap(px2); + + BOOST_TEST(px.get() == 0); + BOOST_TEST(px2.get() == 0); + + using std::swap; + swap(px, px2); + + BOOST_TEST(px.get() == 0); + BOOST_TEST(px2.get() == 0); + } + + { + X * p = new X; + boost::shared_ptr<X> px; + boost::shared_ptr<X> px2(p); + boost::shared_ptr<X> px3(px2); + + px.swap(px2); + + BOOST_TEST(px.get() == p); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(px2.get() == 0); + BOOST_TEST(px3.get() == p); + BOOST_TEST(px3.use_count() == 2); + + using std::swap; + swap(px, px2); + + BOOST_TEST(px.get() == 0); + BOOST_TEST(px2.get() == p); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(px3.get() == p); + BOOST_TEST(px3.use_count() == 2); + } + + { + X * p1 = new X; + X * p2 = new X; + boost::shared_ptr<X> px(p1); + boost::shared_ptr<X> px2(p2); + boost::shared_ptr<X> px3(px2); + + px.swap(px2); + + BOOST_TEST(px.get() == p2); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(px2.get() == p1); + BOOST_TEST(px2.use_count() == 1); + BOOST_TEST(px3.get() == p2); + BOOST_TEST(px3.use_count() == 2); + + using std::swap; + swap(px, px2); + + BOOST_TEST(px.get() == p1); + BOOST_TEST(px.use_count() == 1); + BOOST_TEST(px2.get() == p2); + BOOST_TEST(px2.use_count() == 2); + BOOST_TEST(px3.get() == p2); + BOOST_TEST(px3.use_count() == 2); + } +} + +} // namespace n_swap + +namespace n_comparison +{ + +struct X +{ + int dummy; +}; + +struct Y +{ + int dummy2; +}; + +struct Z: public X, public virtual Y +{ +}; + +void test() +{ + { + boost::shared_ptr<X> px; + BOOST_TEST(px == px); + BOOST_TEST(!(px != px)); + BOOST_TEST(!(px < px)); + + boost::shared_ptr<X> px2; + + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(px == px2); + BOOST_TEST(!(px != px2)); + BOOST_TEST(!(px < px2 && px2 < px)); + } + + { + boost::shared_ptr<X> px; + boost::shared_ptr<X> px2(px); + + BOOST_TEST(px2 == px2); + BOOST_TEST(!(px2 != px2)); + BOOST_TEST(!(px2 < px2)); + + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(px == px2); + BOOST_TEST(!(px != px2)); + BOOST_TEST(!(px < px2 && px2 < px)); + } + + { + boost::shared_ptr<X> px; + boost::shared_ptr<X> px2(new X); + + BOOST_TEST(px2 == px2); + BOOST_TEST(!(px2 != px2)); + BOOST_TEST(!(px2 < px2)); + + BOOST_TEST(px.get() != px2.get()); + BOOST_TEST(px != px2); + BOOST_TEST(!(px == px2)); + BOOST_TEST(px < px2 || px2 < px); + BOOST_TEST(!(px < px2 && px2 < px)); + } + + { + boost::shared_ptr<X> px(new X); + boost::shared_ptr<X> px2(new X); + + BOOST_TEST(px.get() != px2.get()); + BOOST_TEST(px != px2); + BOOST_TEST(!(px == px2)); + BOOST_TEST(px < px2 || px2 < px); + BOOST_TEST(!(px < px2 && px2 < px)); + } + + { + boost::shared_ptr<X> px(new X); + boost::shared_ptr<X> px2(px); + + BOOST_TEST(px2 == px2); + BOOST_TEST(!(px2 != px2)); + BOOST_TEST(!(px2 < px2)); + + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(px == px2); + BOOST_TEST(!(px != px2)); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::shared_ptr<X> px(new X); + boost::shared_ptr<Y> py(new Y); + boost::shared_ptr<Z> pz(new Z); + + BOOST_TEST(px.get() != pz.get()); + BOOST_TEST(px != pz); + BOOST_TEST(!(px == pz)); + + BOOST_TEST(py.get() != pz.get()); + BOOST_TEST(py != pz); + BOOST_TEST(!(py == pz)); + + BOOST_TEST(px < py || py < px); + BOOST_TEST(px < pz || pz < px); + BOOST_TEST(py < pz || pz < py); + + BOOST_TEST(!(px < py && py < px)); + BOOST_TEST(!(px < pz && pz < px)); + BOOST_TEST(!(py < pz && pz < py)); + + boost::shared_ptr<void> pvx(px); + + BOOST_TEST(pvx == pvx); + BOOST_TEST(!(pvx != pvx)); + BOOST_TEST(!(pvx < pvx)); + + boost::shared_ptr<void> pvy(py); + boost::shared_ptr<void> pvz(pz); + + BOOST_TEST(pvx < pvy || pvy < pvx); + BOOST_TEST(pvx < pvz || pvz < pvx); + BOOST_TEST(pvy < pvz || pvz < pvy); + + BOOST_TEST(!(pvx < pvy && pvy < pvx)); + BOOST_TEST(!(pvx < pvz && pvz < pvx)); + BOOST_TEST(!(pvy < pvz && pvz < pvy)); + } + + { + boost::shared_ptr<Z> pz(new Z); + boost::shared_ptr<X> px(pz); + + BOOST_TEST(px == px); + BOOST_TEST(!(px != px)); + BOOST_TEST(!(px < px)); + + boost::shared_ptr<Y> py(pz); + + BOOST_TEST(px.get() == pz.get()); + BOOST_TEST(px == pz); + BOOST_TEST(!(px != pz)); + + BOOST_TEST(py.get() == pz.get()); + BOOST_TEST(py == pz); + BOOST_TEST(!(py != pz)); + + BOOST_TEST(!(px < py || py < px)); + BOOST_TEST(!(px < pz || pz < px)); + BOOST_TEST(!(py < pz || pz < py)); + + boost::shared_ptr<void> pvx(px); + boost::shared_ptr<void> pvy(py); + boost::shared_ptr<void> pvz(pz); + + // pvx and pvy aren't equal... + BOOST_TEST(pvx.get() != pvy.get()); + BOOST_TEST(pvx != pvy); + BOOST_TEST(!(pvx == pvy)); + + // ... but they share ownership ... + BOOST_TEST(!(pvx < pvy || pvy < pvx)); + + // ... with pvz + BOOST_TEST(!(pvx < pvz || pvz < pvx)); + BOOST_TEST(!(pvy < pvz || pvz < pvy)); + } +} + +} // namespace n_comparison + +namespace n_static_cast +{ + +struct X +{ +}; + +struct Y: public X +{ +}; + +void test() +{ + { + boost::shared_ptr<void> pv; + + boost::shared_ptr<int> pi = boost::static_pointer_cast<int>(pv); + BOOST_TEST(pi.get() == 0); + + boost::shared_ptr<X> px = boost::static_pointer_cast<X>(pv); + BOOST_TEST(px.get() == 0); + } + + { + boost::shared_ptr<int> pi(new int); + boost::shared_ptr<void> pv(pi); + + boost::shared_ptr<int> pi2 = boost::static_pointer_cast<int>(pv); + BOOST_TEST(pi.get() == pi2.get()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); + BOOST_TEST(pi.use_count() == 3); + BOOST_TEST(pv.use_count() == 3); + BOOST_TEST(pi2.use_count() == 3); + } + + { + boost::shared_ptr<X> px(new X); + boost::shared_ptr<void> pv(px); + + boost::shared_ptr<X> px2 = boost::static_pointer_cast<X>(pv); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + BOOST_TEST(px.use_count() == 3); + BOOST_TEST(pv.use_count() == 3); + BOOST_TEST(px2.use_count() == 3); + } + + { + boost::shared_ptr<X> px(new Y); + + boost::shared_ptr<Y> py = boost::static_pointer_cast<Y>(px); + BOOST_TEST(px.get() == py.get()); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(py.use_count() == 2); + + boost::shared_ptr<X> px2(py); + BOOST_TEST(!(px < px2 || px2 < px)); + } +} + +} // namespace n_static_cast + +namespace n_const_cast +{ + +struct X; + +void test() +{ + { + boost::shared_ptr<void const volatile> px; + + boost::shared_ptr<void> px2 = boost::const_pointer_cast<void>(px); + BOOST_TEST(px2.get() == 0); + } + + { + boost::shared_ptr<int const volatile> px; + + boost::shared_ptr<int> px2 = boost::const_pointer_cast<int>(px); + BOOST_TEST(px2.get() == 0); + } + + { + boost::shared_ptr<X const volatile> px; + + boost::shared_ptr<X> px2 = boost::const_pointer_cast<X>(px); + BOOST_TEST(px2.get() == 0); + } + + { + boost::shared_ptr<void const volatile> px(new int); + + boost::shared_ptr<void> px2 = boost::const_pointer_cast<void>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(px2.use_count() == 2); + } + + { + boost::shared_ptr<int const volatile> px(new int); + + boost::shared_ptr<int> px2 = boost::const_pointer_cast<int>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + BOOST_TEST(px.use_count() == 2); + BOOST_TEST(px2.use_count() == 2); + } +} + +} // namespace n_const_cast + +#if !defined( BOOST_NO_RTTI ) + +namespace n_dynamic_cast +{ + +struct V +{ + virtual ~V() {} +}; + +struct W: public V +{ +}; + +void test() +{ + { + boost::shared_ptr<V> pv; + boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(pv); + BOOST_TEST(pw.get() == 0); + } + + { + boost::shared_ptr<V> pv(static_cast<V*>(0)); + + boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(pv); + BOOST_TEST(pw.get() == 0); + + boost::shared_ptr<V> pv2(pw); + BOOST_TEST(pv < pv2 || pv2 < pv); + } + + { + boost::shared_ptr<V> pv(static_cast<W*>(0)); + + boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(pv); + BOOST_TEST(pw.get() == 0); + + boost::shared_ptr<V> pv2(pw); + BOOST_TEST(pv < pv2 || pv2 < pv); + } + + { + boost::shared_ptr<V> pv(new V); + + boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(pv); + BOOST_TEST(pw.get() == 0); + + boost::shared_ptr<V> pv2(pw); + BOOST_TEST(pv < pv2 || pv2 < pv); + } + + { + boost::shared_ptr<V> pv(new W); + + boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(pv); + BOOST_TEST(pw.get() == pv.get()); + BOOST_TEST(pv.use_count() == 2); + BOOST_TEST(pw.use_count() == 2); + + boost::shared_ptr<V> pv2(pw); + BOOST_TEST(!(pv < pv2 || pv2 < pv)); + } +} + +} // namespace n_dynamic_cast + +#endif + +namespace n_map +{ + +struct X +{ +}; + +void test() +{ + std::vector< boost::shared_ptr<int> > vi; + + { + boost::shared_ptr<int> pi1(new int); + boost::shared_ptr<int> pi2(new int); + boost::shared_ptr<int> pi3(new int); + + vi.push_back(pi1); + vi.push_back(pi1); + vi.push_back(pi1); + vi.push_back(pi2); + vi.push_back(pi1); + vi.push_back(pi2); + vi.push_back(pi1); + vi.push_back(pi3); + vi.push_back(pi3); + vi.push_back(pi2); + vi.push_back(pi1); + } + + std::vector< boost::shared_ptr<X> > vx; + + { + boost::shared_ptr<X> px1(new X); + boost::shared_ptr<X> px2(new X); + boost::shared_ptr<X> px3(new X); + + vx.push_back(px2); + vx.push_back(px2); + vx.push_back(px1); + vx.push_back(px2); + vx.push_back(px1); + vx.push_back(px1); + vx.push_back(px1); + vx.push_back(px2); + vx.push_back(px1); + vx.push_back(px3); + vx.push_back(px2); + } + + std::map< boost::shared_ptr<void>, long > m; + + { + for(std::vector< boost::shared_ptr<int> >::iterator i = vi.begin(); i != vi.end(); ++i) + { + ++m[*i]; + } + } + + { + for(std::vector< boost::shared_ptr<X> >::iterator i = vx.begin(); i != vx.end(); ++i) + { + ++m[*i]; + } + } + + { + for(std::map< boost::shared_ptr<void>, long >::iterator i = m.begin(); i != m.end(); ++i) + { + BOOST_TEST(i->first.use_count() == i->second + 1); + } + } +} + +} // namespace n_map + +namespace n_transitive +{ + +struct X +{ + X(): next() {} + boost::shared_ptr<X> next; +}; + +void test() +{ + boost::shared_ptr<X> p(new X); + p->next = boost::shared_ptr<X>(new X); + BOOST_TEST(!p->next->next); + p = p->next; + BOOST_TEST(!p->next); +} + +} // namespace n_transitive + +namespace n_report_1 +{ + +class foo +{ +public: + + foo(): m_self(this) + { + } + + void suicide() + { + m_self.reset(); + } + +private: + + boost::shared_ptr<foo> m_self; +}; + +void test() +{ + foo * foo_ptr = new foo; + foo_ptr->suicide(); +} + +} // namespace n_report_1 + +// Test case by Per Kristensen +namespace n_report_2 +{ + +class foo +{ +public: + + void setWeak(boost::shared_ptr<foo> s) + { + w = s; + } + +private: + + boost::weak_ptr<foo> w; +}; + +class deleter +{ +public: + + deleter(): lock(0) + { + } + + ~deleter() + { + BOOST_TEST(lock == 0); + } + + void operator() (foo * p) + { + ++lock; + delete p; + --lock; + } + +private: + + int lock; +}; + +void test() +{ + boost::shared_ptr<foo> s(new foo, deleter()); + s->setWeak(s); + s.reset(); +} + +} // namespace n_report_2 + +namespace n_spt_incomplete +{ + +class file; + +boost::shared_ptr<file> fopen(char const * name, char const * mode); +void fread(boost::shared_ptr<file> f, void * data, long size); + +int file_instances = 0; + +void test() +{ + BOOST_TEST(file_instances == 0); + + { + boost::shared_ptr<file> pf = fopen("name", "mode"); + BOOST_TEST(file_instances == 1); + fread(pf, 0, 17041); + } + + BOOST_TEST(file_instances == 0); +} + +} // namespace n_spt_incomplete + +namespace n_spt_pimpl +{ + +class file +{ +private: + + class impl; + boost::shared_ptr<impl> pimpl_; + +public: + + file(char const * name, char const * mode); + + // compiler generated members are fine and useful + + void read(void * data, long size); + + long total_size() const; +}; + +int file_instances = 0; + +void test() +{ + BOOST_TEST(file_instances == 0); + + { + file f("name", "mode"); + BOOST_TEST(file_instances == 1); + f.read(0, 152); + + file f2(f); + BOOST_TEST(file_instances == 1); + f2.read(0, 894); + + BOOST_TEST(f.total_size() == 152+894); + + { + file f3("name2", "mode2"); + BOOST_TEST(file_instances == 2); + } + + BOOST_TEST(file_instances == 1); + } + + BOOST_TEST(file_instances == 0); +} + +} // namespace n_spt_pimpl + +namespace n_spt_abstract +{ + +class X +{ +public: + + virtual void f(int) = 0; + virtual int g() = 0; + +protected: + + ~X() {} +}; + +boost::shared_ptr<X> createX(); + +int X_instances = 0; + +void test() +{ + BOOST_TEST(X_instances == 0); + + { + boost::shared_ptr<X> px = createX(); + + BOOST_TEST(X_instances == 1); + + px->f(18); + px->f(152); + + BOOST_TEST(px->g() == 170); + } + + BOOST_TEST(X_instances == 0); +} + +} // namespace n_spt_abstract + +namespace n_spt_preventing_delete +{ + +int X_instances = 0; + +class X +{ +private: + + X() + { + ++X_instances; + } + + ~X() + { + --X_instances; + } + + class deleter; + friend class deleter; + + class deleter + { + public: + + void operator()(X * p) { delete p; } + }; + +public: + + static boost::shared_ptr<X> create() + { + boost::shared_ptr<X> px(new X, X::deleter()); + return px; + } +}; + +void test() +{ + BOOST_TEST(X_instances == 0); + + { + boost::shared_ptr<X> px = X::create(); + BOOST_TEST(X_instances == 1); + } + + BOOST_TEST(X_instances == 0); +} + +} // namespace n_spt_preventing_delete + +namespace n_spt_array +{ + +int X_instances = 0; + +struct X +{ + X() + { + ++X_instances; + } + + ~X() + { + --X_instances; + } +}; + +void test() +{ + BOOST_TEST(X_instances == 0); + + { + boost::shared_ptr<X> px(new X[4], boost::checked_array_deleter<X>()); + BOOST_TEST(X_instances == 4); + } + + BOOST_TEST(X_instances == 0); +} + +} // namespace n_spt_array + +namespace n_spt_static +{ + +class X +{ +public: + + X() + { + } + +private: + + void operator delete(void *) + { + // Comeau 4.3.0.1 wants a definition + BOOST_ERROR("n_spt_static::X::operator delete() called."); + } +}; + +struct null_deleter +{ + void operator()(void const *) const + { + } +}; + +static X x; + +void test() +{ + boost::shared_ptr<X> px(&x, null_deleter()); +} + +} // namespace n_spt_static + +namespace n_spt_intrusive +{ + +int X_instances = 0; + +struct X +{ + long count; + + X(): count(0) + { + ++X_instances; + } + + ~X() + { + --X_instances; + } +}; + +void intrusive_ptr_add_ref(X * p) +{ + ++p->count; +} + +void intrusive_ptr_release(X * p) +{ + if(--p->count == 0) delete p; +} + +template<class T> struct intrusive_deleter +{ + void operator()(T * p) + { + if(p != 0) intrusive_ptr_release(p); + } +}; + +boost::shared_ptr<X> make_shared_from_intrusive(X * p) +{ + if(p != 0) intrusive_ptr_add_ref(p); + boost::shared_ptr<X> px(p, intrusive_deleter<X>()); + return px; +} + +void test() +{ + BOOST_TEST(X_instances == 0); + + { + X * p = new X; + BOOST_TEST(X_instances == 1); + BOOST_TEST(p->count == 0); + boost::shared_ptr<X> px = make_shared_from_intrusive(p); + BOOST_TEST(px.get() == p); + BOOST_TEST(p->count == 1); + boost::shared_ptr<X> px2(px); + BOOST_TEST(px2.get() == p); + BOOST_TEST(p->count == 1); + } + + BOOST_TEST(X_instances == 0); +} + +} // namespace n_spt_intrusive + +namespace n_spt_another_sp +{ + +template<class T> class another_ptr: private boost::shared_ptr<T> +{ +private: + + typedef boost::shared_ptr<T> base_type; + +public: + + explicit another_ptr(T * p = 0): base_type(p) + { + } + + void reset() + { + base_type::reset(); + } + + T * get() const + { + return base_type::get(); + } +}; + +class event_handler +{ +public: + + virtual ~event_handler() {} + virtual void begin() = 0; + virtual void handle(int event) = 0; + virtual void end() = 0; +}; + +int begin_called = 0; +int handle_called = 0; +int end_called = 0; + +class event_handler_impl: public event_handler +{ +public: + + virtual void begin() + { + ++begin_called; + } + + virtual void handle(int event) + { + handle_called = event; + } + + virtual void end() + { + ++end_called; + } +}; + +another_ptr<event_handler> get_event_handler() +{ + another_ptr<event_handler> p(new event_handler_impl); + return p; +} + +boost::shared_ptr<event_handler> current_handler; + +void install_event_handler(boost::shared_ptr<event_handler> p) +{ + p->begin(); + current_handler = p; +} + +void handle_event(int event) +{ + current_handler->handle(event); +} + +void remove_event_handler() +{ + current_handler->end(); + current_handler.reset(); +} + +template<class P> class smart_pointer_deleter +{ +private: + + P p_; + +public: + + smart_pointer_deleter(P const & p): p_(p) + { + } + + void operator()(void const *) + { + p_.reset(); + } +}; + +void test() +{ + another_ptr<event_handler> p = get_event_handler(); + + boost::shared_ptr<event_handler> q(p.get(), smart_pointer_deleter< another_ptr<event_handler> >(p)); + + p.reset(); + + BOOST_TEST(begin_called == 0); + + install_event_handler(q); + + BOOST_TEST(begin_called == 1); + + BOOST_TEST(handle_called == 0); + + handle_event(17041); + + BOOST_TEST(handle_called == 17041); + + BOOST_TEST(end_called == 0); + + remove_event_handler(); + + BOOST_TEST(end_called == 1); +} + +} // namespace n_spt_another_sp + +namespace n_spt_shared_from_this +{ + +class X +{ +public: + + virtual void f() = 0; + +protected: + + ~X() {} +}; + +class Y +{ +public: + + virtual boost::shared_ptr<X> getX() = 0; + +protected: + + ~Y() {} +}; + +class impl: public X, public Y +{ +private: + + boost::weak_ptr<impl> weak_this; + + impl(impl const &); + impl & operator=(impl const &); + + impl() {} + +public: + + static boost::shared_ptr<impl> create() + { + boost::shared_ptr<impl> pi(new impl); + pi->weak_this = pi; + return pi; + } + + virtual void f() {} + + virtual boost::shared_ptr<X> getX() + { + boost::shared_ptr<X> px = weak_this.lock(); + return px; + } +}; + +void test() +{ + boost::shared_ptr<Y> py = impl::create(); + BOOST_TEST(py.get() != 0); + BOOST_TEST(py.use_count() == 1); + + boost::shared_ptr<X> px = py->getX(); + BOOST_TEST(px.get() != 0); + BOOST_TEST(py.use_count() == 2); + +#if !defined( BOOST_NO_RTTI ) + boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px); + BOOST_TEST(py.get() == py2.get()); + BOOST_TEST(!(py < py2 || py2 < py)); + BOOST_TEST(py.use_count() == 3); +#endif +} + +} // namespace n_spt_shared_from_this + +namespace n_spt_wrap +{ + +void test() +{ +} + +} // namespace n_spt_wrap + +int main() +{ + n_element_type::test(); + n_constructors::test(); + n_assignment::test(); + n_reset::test(); + n_access::test(); + n_use_count::test(); + n_swap::test(); + n_comparison::test(); + n_static_cast::test(); + n_const_cast::test(); +#if !defined( BOOST_NO_RTTI ) + n_dynamic_cast::test(); +#endif + + n_map::test(); + + n_transitive::test(); + n_report_1::test(); + n_report_2::test(); + + n_spt_incomplete::test(); + n_spt_pimpl::test(); + n_spt_abstract::test(); + n_spt_preventing_delete::test(); + n_spt_array::test(); + n_spt_static::test(); + n_spt_intrusive::test(); + n_spt_another_sp::test(); + n_spt_shared_from_this::test(); + n_spt_wrap::test(); + + return boost::report_errors(); +} + +namespace n_spt_incomplete +{ + +class file +{ +public: + + file(): fread_called(false) + { + ++file_instances; + } + + ~file() + { + BOOST_TEST(fread_called); + --file_instances; + } + + bool fread_called; +}; + +boost::shared_ptr<file> fopen(char const *, char const *) +{ + boost::shared_ptr<file> pf(new file); + return pf; +} + +void fread(boost::shared_ptr<file> pf, void *, long) +{ + pf->fread_called = true; +} + +} // namespace n_spt_incomplete + +namespace n_spt_pimpl +{ + +class file::impl +{ +private: + + impl(impl const &); + impl & operator=(impl const &); + + long total_size_; + +public: + + impl(char const *, char const *): total_size_(0) + { + ++file_instances; + } + + ~impl() + { + --file_instances; + } + + void read(void *, long size) + { + total_size_ += size; + } + + long total_size() const + { + return total_size_; + } +}; + +file::file(char const * name, char const * mode): pimpl_(new impl(name, mode)) +{ +} + +void file::read(void * data, long size) +{ + pimpl_->read(data, size); +} + +long file::total_size() const +{ + return pimpl_->total_size(); +} + +} // namespace n_spt_pimpl + +namespace n_spt_abstract +{ + +class X_impl: public X +{ +private: + + X_impl(X_impl const &); + X_impl & operator=(X_impl const &); + + int n_; + +public: + + X_impl(): n_(0) + { + ++X_instances; + } + + ~X_impl() + { + --X_instances; + } + + virtual void f(int n) + { + n_ += n; + } + + virtual int g() + { + return n_; + } +}; + +boost::shared_ptr<X> createX() +{ + boost::shared_ptr<X> px(new X_impl); + return px; +} + +} // namespace n_spt_abstract diff --git a/src/boost/libs/smart_ptr/test/smart_ptr_test.cpp b/src/boost/libs/smart_ptr/test/smart_ptr_test.cpp new file mode 100644 index 00000000..12120edb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/smart_ptr_test.cpp @@ -0,0 +1,307 @@ +// smart pointer test program ----------------------------------------------// + +// Copyright Beman Dawes 1998, 1999. 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) + +// See http://www.boost.org/libs/smart_ptr for documentation. + +// Revision History +// 24 May 01 use Boost test library for error detection, reporting, add tests +// for operations on incomplete types (Beman Dawes) +// 29 Nov 99 added std::swap and associative container tests (Darin Adler) +// 25 Sep 99 added swap tests +// 20 Jul 99 header name changed to .hpp +// 20 Apr 99 additional error tests added. + +#define _CRT_SECURE_NO_WARNINGS + +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +# pragma warning(disable: 4786) // identifier truncated in debug info +# pragma warning(disable: 4710) // function not inlined +# pragma warning(disable: 4711) // function selected for automatic inline expansion +# pragma warning(disable: 4514) // unreferenced inline removed + +#if (BOOST_MSVC >= 1310) +# pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +#ifdef __BORLANDC__ +# pragma warn -8092 // template argument passed to 'find' is not an iterator +#endif + +#include <boost/smart_ptr.hpp> + +#include <boost/detail/lightweight_test.hpp> + +#include <iostream> +#include <set> +#include <string.h> + +class Incomplete; + +Incomplete * get_ptr( boost::shared_ptr<Incomplete>& incomplete ) +{ + return incomplete.get(); +} + +template<class T> +void ck( const T* v1, T v2 ) { BOOST_TEST( *v1 == v2 ); } + +namespace { + int UDT_use_count; // independent of pointer maintained counts + } + +// user defined type -------------------------------------------------------// + +class UDT { + long value_; + public: + explicit UDT( long value=0 ) : value_(value) { ++UDT_use_count; } + ~UDT() { + --UDT_use_count; + std::cout << "UDT with value " << value_ << " being destroyed\n"; + } + long value() const { return value_; } + void value( long v ) { value_ = v;; } + }; // UDT + +// tests on incomplete types -----------------------------------------------// + +// Certain smart pointer operations are specified to work on incomplete types, +// and some uses depend upon this feature. These tests verify compilation +// only - the functions aren't actually invoked. + +class Incomplete; + +Incomplete * check_incomplete( boost::scoped_ptr<Incomplete>& incomplete ) +{ + return incomplete.get(); +} + +Incomplete * check_incomplete( boost::shared_ptr<Incomplete>& incomplete, + boost::shared_ptr<Incomplete>& i2 ) +{ + incomplete.swap(i2); + std::cout << incomplete.use_count() << ' ' << incomplete.unique() << '\n'; + return incomplete.get(); +} + +// This isn't a very systematic test; it just hits some of the basics. + +void test() +{ + BOOST_TEST( UDT_use_count == 0 ); // reality check + + // test scoped_ptr with a built-in type + long * lp = new long; + boost::scoped_ptr<long> sp ( lp ); + BOOST_TEST( sp.get() == lp ); + BOOST_TEST( lp == sp.get() ); + BOOST_TEST( &*sp == lp ); + + *sp = 1234568901L; + BOOST_TEST( *sp == 1234568901L ); + BOOST_TEST( *lp == 1234568901L ); + ck( static_cast<long*>(sp.get()), 1234568901L ); + ck( lp, *sp ); + + sp.reset(); + BOOST_TEST( sp.get() == 0 ); + + // test scoped_ptr with a user defined type + boost::scoped_ptr<UDT> udt_sp ( new UDT( 999888777 ) ); + BOOST_TEST( udt_sp->value() == 999888777 ); + udt_sp.reset(); + udt_sp.reset( new UDT( 111222333 ) ); + BOOST_TEST( udt_sp->value() == 111222333 ); + udt_sp.reset( new UDT( 333222111 ) ); + BOOST_TEST( udt_sp->value() == 333222111 ); + + // test scoped_array with a build-in type + char * sap = new char [ 100 ]; + boost::scoped_array<char> sa ( sap ); + BOOST_TEST( sa.get() == sap ); + BOOST_TEST( sap == sa.get() ); + + strcpy( sa.get(), "Hot Dog with mustard and relish" ); + BOOST_TEST( strcmp( sa.get(), "Hot Dog with mustard and relish" ) == 0 ); + BOOST_TEST( strcmp( sap, "Hot Dog with mustard and relish" ) == 0 ); + + BOOST_TEST( sa[0] == 'H' ); + BOOST_TEST( sa[30] == 'h' ); + + sa[0] = 'N'; + sa[4] = 'd'; + BOOST_TEST( strcmp( sap, "Not dog with mustard and relish" ) == 0 ); + + sa.reset(); + BOOST_TEST( sa.get() == 0 ); + + // test shared_ptr with a built-in type + int * ip = new int; + boost::shared_ptr<int> cp ( ip ); + BOOST_TEST( ip == cp.get() ); + BOOST_TEST( cp.use_count() == 1 ); + + *cp = 54321; + BOOST_TEST( *cp == 54321 ); + BOOST_TEST( *ip == 54321 ); + ck( static_cast<int*>(cp.get()), 54321 ); + ck( static_cast<int*>(ip), *cp ); + + boost::shared_ptr<int> cp2 ( cp ); + BOOST_TEST( ip == cp2.get() ); + BOOST_TEST( cp.use_count() == 2 ); + BOOST_TEST( cp2.use_count() == 2 ); + + BOOST_TEST( *cp == 54321 ); + BOOST_TEST( *cp2 == 54321 ); + ck( static_cast<int*>(cp2.get()), 54321 ); + ck( static_cast<int*>(ip), *cp2 ); + + boost::shared_ptr<int> cp3 ( cp ); + BOOST_TEST( cp.use_count() == 3 ); + BOOST_TEST( cp2.use_count() == 3 ); + BOOST_TEST( cp3.use_count() == 3 ); + cp.reset(); + BOOST_TEST( cp2.use_count() == 2 ); + BOOST_TEST( cp3.use_count() == 2 ); + cp.reset( new int ); + *cp = 98765; + BOOST_TEST( *cp == 98765 ); + *cp3 = 87654; + BOOST_TEST( *cp3 == 87654 ); + BOOST_TEST( *cp2 == 87654 ); + cp.swap( cp3 ); + BOOST_TEST( *cp == 87654 ); + BOOST_TEST( *cp2 == 87654 ); + BOOST_TEST( *cp3 == 98765 ); + cp.swap( cp3 ); + BOOST_TEST( *cp == 98765 ); + BOOST_TEST( *cp2 == 87654 ); + BOOST_TEST( *cp3 == 87654 ); + cp2 = cp2; + BOOST_TEST( cp2.use_count() == 2 ); + BOOST_TEST( *cp2 == 87654 ); + cp = cp2; + BOOST_TEST( cp2.use_count() == 3 ); + BOOST_TEST( *cp2 == 87654 ); + BOOST_TEST( cp.use_count() == 3 ); + BOOST_TEST( *cp == 87654 ); + +#if defined( BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP ) + using boost::swap; +#endif + + boost::shared_ptr<int> cp4; + swap( cp2, cp4 ); + BOOST_TEST( cp4.use_count() == 3 ); + BOOST_TEST( *cp4 == 87654 ); + BOOST_TEST( cp2.get() == 0 ); + + std::set< boost::shared_ptr<int> > scp; + scp.insert(cp4); + BOOST_TEST( scp.find(cp4) != scp.end() ); + BOOST_TEST( scp.find(cp4) == scp.find( boost::shared_ptr<int>(cp4) ) ); + + // test shared_array with a built-in type + char * cap = new char [ 100 ]; + boost::shared_array<char> ca ( cap ); + BOOST_TEST( ca.get() == cap ); + BOOST_TEST( cap == ca.get() ); + BOOST_TEST( &ca[0] == cap ); + + strcpy( ca.get(), "Hot Dog with mustard and relish" ); + BOOST_TEST( strcmp( ca.get(), "Hot Dog with mustard and relish" ) == 0 ); + BOOST_TEST( strcmp( cap, "Hot Dog with mustard and relish" ) == 0 ); + + BOOST_TEST( ca[0] == 'H' ); + BOOST_TEST( ca[30] == 'h' ); + + boost::shared_array<char> ca2 ( ca ); + boost::shared_array<char> ca3 ( ca2 ); + + ca[0] = 'N'; + ca[4] = 'd'; + BOOST_TEST( strcmp( ca.get(), "Not dog with mustard and relish" ) == 0 ); + BOOST_TEST( strcmp( ca2.get(), "Not dog with mustard and relish" ) == 0 ); + BOOST_TEST( strcmp( ca3.get(), "Not dog with mustard and relish" ) == 0 ); + BOOST_TEST( ca.use_count() == 3 ); + BOOST_TEST( ca2.use_count() == 3 ); + BOOST_TEST( ca3.use_count() == 3 ); + ca2.reset(); + BOOST_TEST( ca.use_count() == 2 ); + BOOST_TEST( ca3.use_count() == 2 ); + BOOST_TEST( ca2.use_count() == 0 ); + + ca.reset(); + BOOST_TEST( ca.get() == 0 ); + + boost::shared_array<char> ca4; + swap( ca3, ca4 ); + BOOST_TEST( ca4.use_count() == 1 ); + BOOST_TEST( strcmp( ca4.get(), "Not dog with mustard and relish" ) == 0 ); + BOOST_TEST( ca3.get() == 0 ); + + std::set< boost::shared_array<char> > sca; + sca.insert(ca4); + BOOST_TEST( sca.find(ca4) != sca.end() ); + BOOST_TEST( sca.find(ca4) == sca.find( boost::shared_array<char>(ca4) ) ); + + // test shared_array with user defined type + boost::shared_array<UDT> udta ( new UDT[3] ); + + udta[0].value( 111 ); + udta[1].value( 222 ); + udta[2].value( 333 ); + boost::shared_array<UDT> udta2 ( udta ); + + BOOST_TEST( udta[0].value() == 111 ); + BOOST_TEST( udta[1].value() == 222 ); + BOOST_TEST( udta[2].value() == 333 ); + BOOST_TEST( udta2[0].value() == 111 ); + BOOST_TEST( udta2[1].value() == 222 ); + BOOST_TEST( udta2[2].value() == 333 ); + udta2.reset(); + BOOST_TEST( udta2.get() == 0 ); + BOOST_TEST( udta.use_count() == 1 ); + BOOST_TEST( udta2.use_count() == 0 ); + + BOOST_TEST( UDT_use_count == 4 ); // reality check + + // test shared_ptr with a user defined type + UDT * up = new UDT; + boost::shared_ptr<UDT> sup ( up ); + BOOST_TEST( up == sup.get() ); + BOOST_TEST( sup.use_count() == 1 ); + + sup->value( 54321 ) ; + BOOST_TEST( sup->value() == 54321 ); + BOOST_TEST( up->value() == 54321 ); + + boost::shared_ptr<UDT> sup2; + sup2 = sup; + BOOST_TEST( sup2->value() == 54321 ); + BOOST_TEST( sup.use_count() == 2 ); + BOOST_TEST( sup2.use_count() == 2 ); + sup2 = sup2; + BOOST_TEST( sup2->value() == 54321 ); + BOOST_TEST( sup.use_count() == 2 ); + BOOST_TEST( sup2.use_count() == 2 ); + + std::cout << "OK\n"; + + new char[12345]; // deliberate memory leak to verify leaks detected +} + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_array_cast_test.cpp b/src/boost/libs/smart_ptr/test/sp_array_cast_test.cpp new file mode 100644 index 00000000..5af7eb59 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_array_cast_test.cpp @@ -0,0 +1,202 @@ +// +// sp_array_cast_test.cpp +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct X +{ +}; + +void static_cast_test() +{ + { + boost::shared_ptr<void> pv; + + boost::shared_ptr<int[]> pi = boost::static_pointer_cast<int[]>( pv ); + BOOST_TEST( pi.get() == 0 ); + + boost::shared_ptr<int[3]> pi2 = boost::static_pointer_cast<int[3]>( pv ); + BOOST_TEST( pi2.get() == 0 ); + + boost::shared_ptr<X[]> px = boost::static_pointer_cast<X[]>( pv ); + BOOST_TEST( px.get() == 0 ); + + boost::shared_ptr<X[5]> px2 = boost::static_pointer_cast<X[5]>( pv ); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::shared_ptr<int[]> pi( new int[2] ); + boost::shared_ptr<void> pv( pi ); + + boost::shared_ptr<int[]> pi2 = boost::static_pointer_cast<int[]>( pv ); + BOOST_TEST(pi.get() == pi2.get()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); + + boost::shared_ptr<int[2]> pi3 = boost::static_pointer_cast<int[2]>( pv ); + BOOST_TEST(pi.get() == pi3.get()); + BOOST_TEST(!(pi < pi3 || pi3 < pi)); + + boost::shared_ptr<void> pv2( pi3 ); + + boost::shared_ptr<int[]> pi4 = boost::static_pointer_cast<int[]>( pv2 ); + BOOST_TEST(pi.get() == pi4.get()); + BOOST_TEST(!(pi < pi4 || pi4 < pi)); + } + + { + boost::shared_ptr<X[]> px( new X[4] ); + boost::shared_ptr<void> pv( px ); + + boost::shared_ptr<X[]> px2 = boost::static_pointer_cast<X[]>( pv ); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + + boost::shared_ptr<X[4]> px3 = boost::static_pointer_cast<X[4]>( pv ); + BOOST_TEST(px.get() == px3.get()); + BOOST_TEST(!(px < px3 || px3 < px)); + + boost::shared_ptr<void> pv2( px3 ); + + boost::shared_ptr<X[]> px4 = boost::static_pointer_cast<X[]>( pv2 ); + BOOST_TEST(px.get() == px4.get()); + BOOST_TEST(!(px < px4 || px4 < px)); + } +} + +void const_cast_test() +{ + { + boost::shared_ptr<int const volatile[]> px; + + boost::shared_ptr<int[]> px2 = boost::const_pointer_cast<int[]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::shared_ptr<int const volatile[2]> px; + + boost::shared_ptr<int[2]> px2 = boost::const_pointer_cast<int[2]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::shared_ptr<X const volatile[]> px; + + boost::shared_ptr<X[]> px2 = boost::const_pointer_cast<X[]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::shared_ptr<X const volatile[5]> px; + + boost::shared_ptr<X[5]> px2 = boost::const_pointer_cast<X[5]>(px); + BOOST_TEST( px2.get() == 0 ); + } + + { + boost::shared_ptr<int const volatile[]> px( new int[3] ); + + boost::shared_ptr<int[]> px2 = boost::const_pointer_cast<int[]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::shared_ptr<int const volatile[3]> px( new int[3] ); + + boost::shared_ptr<int[3]> px2 = boost::const_pointer_cast<int[3]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::shared_ptr<X const volatile[]> px( new X[4] ); + + boost::shared_ptr<X[]> px2 = boost::const_pointer_cast<X[]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } + + { + boost::shared_ptr<X const volatile[4]> px( new X[4] ); + + boost::shared_ptr<X[4]> px2 = boost::const_pointer_cast<X[4]>(px); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + } +} + +void reinterpret_cast_test() +{ + { + boost::shared_ptr<int[]> pi; + BOOST_TEST( pi.get() == 0 ); + + boost::shared_ptr<int[3]> pi2 = boost::reinterpret_pointer_cast<int[3]>( pi ); + BOOST_TEST( pi2.get() == 0 ); + + boost::shared_ptr<int[6]> pi3 = boost::reinterpret_pointer_cast<int[6]>( pi2 ); + BOOST_TEST( pi3.get() == 0 ); + } + + { + boost::shared_ptr<X[]> px; + BOOST_TEST( px.get() == 0 ); + + boost::shared_ptr<X[5]> px2 = boost::reinterpret_pointer_cast<X[5]>( px ); + BOOST_TEST( px2.get() == 0 ); + + boost::shared_ptr<X[9]> px3 = boost::reinterpret_pointer_cast<X[9]>( px2 ); + BOOST_TEST( px3.get() == 0 ); + } + + { + boost::shared_ptr<int[]> pi( new int[2] ); + + boost::shared_ptr<int[2]> pi2 = boost::reinterpret_pointer_cast<int[2]>( pi ); + BOOST_TEST(pi.get() == pi2.get()); + BOOST_TEST(!(pi < pi2 || pi2 < pi)); + + boost::shared_ptr<int[1]> pi3 = boost::reinterpret_pointer_cast<int[1]>( pi2 ); + BOOST_TEST(pi.get() == pi3.get()); + BOOST_TEST(!(pi < pi3 || pi3 < pi)); + + boost::shared_ptr<int[]> pi4 = boost::reinterpret_pointer_cast<int[]>( pi3 ); + BOOST_TEST(pi.get() == pi4.get()); + BOOST_TEST(!(pi < pi4 || pi4 < pi)); + } + + { + boost::shared_ptr<X[]> px( new X[4] ); + + boost::shared_ptr<X[7]> px2 = boost::reinterpret_pointer_cast<X[7]>( px ); + BOOST_TEST(px.get() == px2.get()); + BOOST_TEST(!(px < px2 || px2 < px)); + + boost::shared_ptr<X[4]> px3 = boost::reinterpret_pointer_cast<X[4]>( px2 ); + BOOST_TEST(px.get() == px3.get()); + BOOST_TEST(!(px < px3 || px3 < px)); + + boost::shared_ptr<X[]> px4 = boost::reinterpret_pointer_cast<X[]>( px3 ); + BOOST_TEST(px.get() == px4.get()); + BOOST_TEST(!(px < px4 || px4 < px)); + } +} + +int main() +{ + static_cast_test(); + const_cast_test(); + reinterpret_cast_test(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_array_cv_test.cpp b/src/boost/libs/smart_ptr/test/sp_array_cv_test.cpp new file mode 100644 index 00000000..8618fb08 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_array_cv_test.cpp @@ -0,0 +1,60 @@ +// +// sp_array_cv_test.cpp +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> + +struct X +{ +}; + +class B +{ +}; + +class D: public B +{ +}; + +#define TEST_CONV( T, U ) \ + { \ + boost::shared_ptr< T > p1; \ + boost::shared_ptr< U > p2( p1 ); \ + p2 = p1; \ + boost::shared_ptr< U > p3 = boost::shared_ptr< T >(); \ + p3 = boost::shared_ptr< T >(); \ + } + +#define TEST_CV_TRUE( T, U ) \ + TEST_CONV( T, U ) \ + TEST_CONV( T, const U ) \ + TEST_CONV( T, volatile U ) \ + TEST_CONV( T, const volatile U ) \ + TEST_CONV( const T, const U ) \ + TEST_CONV( const T, const volatile U ) \ + TEST_CONV( volatile T, volatile U ) \ + TEST_CONV( volatile T, const volatile U ) \ + TEST_CONV( const volatile T, const volatile U ) + +int main() +{ + TEST_CV_TRUE( X, X ) + TEST_CV_TRUE( X, void ) + TEST_CV_TRUE( D, B ) + + TEST_CV_TRUE( X[], X[] ) + TEST_CV_TRUE( X[3], X[3] ) + + TEST_CV_TRUE( X[3], X[] ) + + TEST_CV_TRUE( X[], void ) + TEST_CV_TRUE( X[3], void ) + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/sp_array_n_test.cpp b/src/boost/libs/smart_ptr/test/sp_array_n_test.cpp new file mode 100644 index 00000000..ccbcc26c --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_array_n_test.cpp @@ -0,0 +1,248 @@ +// +// sp_array_n_test.cpp +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> +#include <utility> + +class X: public boost::enable_shared_from_this< X > +{ +public: + + static int allocations; + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + void* operator new[]( std::size_t n ) + { + ++allocations; + return ::operator new[]( n ); + } + + void operator delete[]( void* p ) + { + --allocations; + ::operator delete[]( p ); + } + +private: + + X( X const& ); + X& operator=( X const& ); +}; + +int X::allocations = 0; +int X::instances = 0; + +template< class T> class array_deleter +{ +public: + + static int calls; + + void operator()( T * p ) const + { + ++calls; + delete[] p; + } + +private: + + template< class Y > void operator()( Y * p ) const; +}; + +template< class T > int array_deleter< T >::calls = 0; + +int main() +{ + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X[3]> px; + BOOST_TEST( !px ); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr<X[3]> px2( new X[ 3 ] ); + BOOST_TEST( px2 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + { + X & rx = px2[ 0 ]; + BOOST_TEST( &rx == px2.get() ); + } + + boost::shared_ptr<X const[3]> px3( px2 ); + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + { + X const & rx = px3[ 1 ]; + BOOST_TEST( &rx == px3.get() + 1 ); + } + + px3.reset(); + px3 = px2; + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + boost::shared_ptr<X volatile[3]> px4( px2 ); + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + { + X volatile & rx = px4[ 2 ]; + BOOST_TEST( &rx == px4.get() + 2 ); + } + + px4.reset(); + px4 = px2; + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + boost::shared_ptr<void> px5( px2 ); + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + px5.reset(); + px5 = px2; + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + boost::weak_ptr<X[3]> wp( px ); + BOOST_TEST( wp.lock() == px ); + + boost::weak_ptr<X[3]> wp2( px2 ); + BOOST_TEST( wp2.lock() == px2 ); + + wp2.reset(); + wp2 = px2; + BOOST_TEST( wp2.lock() == px2 ); + + boost::weak_ptr<X const[3]> wp3( px2 ); + BOOST_TEST( wp3.lock() == px2 ); + + wp3.reset(); + wp3 = px2; + BOOST_TEST( wp3.lock() == px2 ); + + boost::weak_ptr<X volatile[3]> wp4( px2 ); + BOOST_TEST( wp4.lock() == px2 ); + + wp4.reset(); + wp4 = px2; + BOOST_TEST( wp4.lock() == px2 ); + + boost::weak_ptr<void> wp5( px2 ); + BOOST_TEST( wp5.lock() == px2 ); + + wp5.reset(); + wp5 = px2; + BOOST_TEST( wp5.lock() == px2 ); + + px2.reset(); + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + px3.reset(); + px4.reset(); + px5.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( wp2.lock() == 0 ); + BOOST_TEST( wp3.lock() == 0 ); + BOOST_TEST( wp4.lock() == 0 ); + BOOST_TEST( wp5.lock() == 0 ); + } + + { + boost::shared_ptr<X[5]> px( new X[ 5 ], array_deleter< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 5 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 1 ); + } + + { + boost::shared_ptr<X[6]> px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 6 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 2 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_array_test.cpp b/src/boost/libs/smart_ptr/test/sp_array_test.cpp new file mode 100644 index 00000000..d508d531 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_array_test.cpp @@ -0,0 +1,311 @@ +// +// sp_array_test.cpp +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> +#include <utility> + +class X: public boost::enable_shared_from_this< X > +{ +public: + + static int allocations; + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + void* operator new[]( std::size_t n ) + { + ++allocations; + return ::operator new[]( n ); + } + + void operator delete[]( void* p ) + { + --allocations; + ::operator delete[]( p ); + } + +private: + + X( X const& ); + X& operator=( X const& ); +}; + +int X::allocations = 0; +int X::instances = 0; + +template< class T> class array_deleter +{ +public: + + static int calls; + + void operator()( T * p ) const + { + ++calls; + delete[] p; + } + +private: + + template< class Y > void operator()( Y * p ) const; +}; + +template< class T > int array_deleter< T >::calls = 0; + +int main() +{ + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X[]> px; + BOOST_TEST( !px ); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr<X[]> px2( new X[ 3 ] ); + BOOST_TEST( px2 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + { + X & rx = px2[ 0 ]; + BOOST_TEST( &rx == px2.get() ); + } + + boost::shared_ptr<X const[]> px3( px2 ); + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + { + X const & rx = px3[ 1 ]; + BOOST_TEST( &rx == px3.get() + 1 ); + } + + px3.reset(); + px3 = px2; + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + boost::shared_ptr<X volatile[]> px4( px2 ); + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + { + X volatile & rx = px4[ 2 ]; + BOOST_TEST( &rx == px4.get() + 2 ); + } + + px4.reset(); + px4 = px2; + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + boost::shared_ptr<void> px5( px2 ); + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + px5.reset(); + px5 = px2; + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + boost::weak_ptr<X[]> wp( px ); + BOOST_TEST( wp.lock() == px ); + + boost::weak_ptr<X[]> wp2( px2 ); + BOOST_TEST( wp2.lock() == px2 ); + + wp2.reset(); + wp2 = px2; + BOOST_TEST( wp2.lock() == px2 ); + + boost::weak_ptr<X const[]> wp3( px2 ); + BOOST_TEST( wp3.lock() == px2 ); + + wp3.reset(); + wp3 = px2; + BOOST_TEST( wp3.lock() == px2 ); + + boost::weak_ptr<X volatile[]> wp4( px2 ); + BOOST_TEST( wp4.lock() == px2 ); + + wp4.reset(); + wp4 = px2; + BOOST_TEST( wp4.lock() == px2 ); + + boost::weak_ptr<void> wp5( px2 ); + BOOST_TEST( wp5.lock() == px2 ); + + wp5.reset(); + wp5 = px2; + BOOST_TEST( wp5.lock() == px2 ); + + px2.reset(); + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + px3.reset(); + px4.reset(); + px5.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( wp2.lock() == 0 ); + BOOST_TEST( wp3.lock() == 0 ); + BOOST_TEST( wp4.lock() == 0 ); + BOOST_TEST( wp5.lock() == 0 ); + } + +#if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + + { + std::unique_ptr<X[]> px( new X[ 4 ] ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + + boost::shared_ptr<X[]> px2( std::move( px ) ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + BOOST_TEST( px.get() == 0 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px2.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + } + + { + std::unique_ptr<X[]> px( new X[ 4 ] ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + + boost::shared_ptr<X[]> px2; + px2 = std::move( px ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + BOOST_TEST( px.get() == 0 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px2.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + } + +#endif + + { + boost::shared_ptr<X[]> px( new X[ 5 ], array_deleter< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 5 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 1 ); + } + + { + boost::shared_ptr<X[]> px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 6 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + catch( ... ) + { + BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" ); + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 2 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_atomic_test.cpp b/src/boost/libs/smart_ptr/test/sp_atomic_test.cpp new file mode 100644 index 00000000..3201c499 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_atomic_test.cpp @@ -0,0 +1,88 @@ +#include <boost/config.hpp> + +// sp_atomic_test.cpp +// +// Copyright (c) 2008 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 <boost/detail/lightweight_test.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/memory_order.hpp> + +// + +struct X +{ +}; + +#define BOOST_TEST_SP_EQ( p, q ) BOOST_TEST( p == q && !( p < q ) && !( q < p ) ) + +int main() +{ + boost::shared_ptr<X> px( new X ); + + { + boost::shared_ptr<X> p2 = boost::atomic_load( &px ); + BOOST_TEST_SP_EQ( p2, px ); + + boost::shared_ptr<X> px2( new X ); + boost::atomic_store( &px, px2 ); + BOOST_TEST_SP_EQ( px, px2 ); + + p2 = boost::atomic_load( &px ); + BOOST_TEST_SP_EQ( p2, px ); + BOOST_TEST_SP_EQ( p2, px2 ); + + boost::shared_ptr<X> px3( new X ); + boost::shared_ptr<X> p3 = boost::atomic_exchange( &px, px3 ); + BOOST_TEST_SP_EQ( p3, px2 ); + BOOST_TEST_SP_EQ( px, px3 ); + + boost::shared_ptr<X> px4( new X ); + boost::shared_ptr<X> cmp; + + bool r = boost::atomic_compare_exchange( &px, &cmp, px4 ); + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( px, px3 ); + BOOST_TEST_SP_EQ( cmp, px3 ); + + r = boost::atomic_compare_exchange( &px, &cmp, px4 ); + BOOST_TEST( r ); + BOOST_TEST_SP_EQ( px, px4 ); + } + + // + + px.reset(); + + { + boost::shared_ptr<X> p2 = boost::atomic_load_explicit( &px, boost::memory_order_acquire ); + BOOST_TEST_SP_EQ( p2, px ); + + boost::shared_ptr<X> px2( new X ); + boost::atomic_store_explicit( &px, px2, boost::memory_order_release ); + BOOST_TEST_SP_EQ( px, px2 ); + + boost::shared_ptr<X> p3 = boost::atomic_exchange_explicit( &px, boost::shared_ptr<X>(), boost::memory_order_acq_rel ); + BOOST_TEST_SP_EQ( p3, px2 ); + BOOST_TEST_SP_EQ( px, p2 ); + + boost::shared_ptr<X> px4( new X ); + boost::shared_ptr<X> cmp( px2 ); + + bool r = boost::atomic_compare_exchange_explicit( &px, &cmp, px4, boost::memory_order_acquire, boost::memory_order_relaxed ); + BOOST_TEST( !r ); + BOOST_TEST_SP_EQ( px, p2 ); + BOOST_TEST_SP_EQ( cmp, p2 ); + + r = boost::atomic_compare_exchange_explicit( &px, &cmp, px4, boost::memory_order_release, boost::memory_order_acquire ); + BOOST_TEST( r ); + BOOST_TEST_SP_EQ( px, px4 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_bml_unique_ptr_test.cpp b/src/boost/libs/smart_ptr/test/sp_bml_unique_ptr_test.cpp new file mode 100644 index 00000000..e4145529 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_bml_unique_ptr_test.cpp @@ -0,0 +1,294 @@ +// +// sp_bml_unique_ptr_test.cpp +// +// Copyright (c) 2012, 2015 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 <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/move/unique_ptr.hpp> +#include <boost/type_traits/remove_reference.hpp> +#include <memory> +#include <utility> + +struct X: public boost::enable_shared_from_this< X > +{ + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +struct Y +{ + static int instances; + + bool deleted_; + + Y(): deleted_( false ) + { + ++instances; + } + + ~Y() + { + BOOST_TEST( deleted_ ); + --instances; + } + +private: + + Y( Y const & ); + Y & operator=( Y const & ); +}; + +int Y::instances = 0; + +struct YD +{ + void operator()( Y* p ) const + { + if( p ) + { + p->deleted_ = true; + delete p; + } + else + { + BOOST_ERROR( "YD::operator()(0) called" ); + } + } +}; + +template<class U, class T, class D> static void test_null_unique_ptr( boost::movelib::unique_ptr<T, D> p1, boost::movelib::unique_ptr<T, D> p2 ) +{ + BOOST_TEST( T::instances == 0 ); + + boost::shared_ptr<U> sp( boost::move( p1 ) ); + + BOOST_TEST( sp.get() == 0 ); + BOOST_TEST( sp.use_count() == 0 ); + + sp.reset( new T, typename boost::remove_reference<D>::type() ); + + BOOST_TEST( sp.get() != 0 ); + BOOST_TEST( sp.use_count() == 1 ); + + BOOST_TEST( T::instances == 1 ); + + sp = boost::move( p2 ); + + BOOST_TEST( sp.get() == 0 ); + BOOST_TEST( sp.use_count() == 0 ); + + BOOST_TEST( T::instances == 0 ); +} + +int main() +{ + { + BOOST_TEST( X::instances == 0 ); + + boost::movelib::unique_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X> p2( boost::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<X> p3 = p2->shared_from_this(); + BOOST_TEST( p2 == p3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + p2.reset(); + p3.reset(); + BOOST_TEST( X::instances == 0 ); + + p2 = boost::movelib::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2 = boost::movelib::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p3 = p2->shared_from_this(); + BOOST_TEST( p2 == p3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + p2.reset(); + p3.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + BOOST_TEST( X::instances == 0 ); + + boost::movelib::unique_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X const> p2( boost::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<X const> p3 = p2->shared_from_this(); + BOOST_TEST( p2 == p3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + p2.reset(); + p3.reset(); + BOOST_TEST( X::instances == 0 ); + + p2 = boost::movelib::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2 = boost::movelib::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p3 = p2->shared_from_this(); + BOOST_TEST( p2 == p3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + p2.reset(); + p3.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + BOOST_TEST( X::instances == 0 ); + + boost::movelib::unique_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<void> p2( boost::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); + + p2 = boost::movelib::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2 = boost::movelib::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + BOOST_TEST( Y::instances == 0 ); + + boost::movelib::unique_ptr<Y, YD> p( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + boost::shared_ptr<Y> p2( boost::move( p ) ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + + p2 = boost::movelib::unique_ptr<Y, YD>( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + p2 = boost::movelib::unique_ptr<Y, YD>( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + } + + { + BOOST_TEST( Y::instances == 0 ); + + YD yd; + + boost::movelib::unique_ptr<Y, YD&> p( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + boost::shared_ptr<Y> p2( boost::move( p ) ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + + p2 = boost::movelib::unique_ptr<Y, YD&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2 = boost::movelib::unique_ptr<Y, YD&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + } + + { + BOOST_TEST( Y::instances == 0 ); + + YD yd; + + boost::movelib::unique_ptr<Y, YD const&> p( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + boost::shared_ptr<Y> p2( boost::move( p ) ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + + p2 = boost::movelib::unique_ptr<Y, YD const&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2 = boost::movelib::unique_ptr<Y, YD const&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + } + + { + test_null_unique_ptr<X>( boost::movelib::unique_ptr<X>(), boost::movelib::unique_ptr<X>() ); + test_null_unique_ptr<X const>( boost::movelib::unique_ptr<X>(), boost::movelib::unique_ptr<X>() ); + test_null_unique_ptr<void>( boost::movelib::unique_ptr<X>(), boost::movelib::unique_ptr<X>() ); + test_null_unique_ptr<void const>( boost::movelib::unique_ptr<X>(), boost::movelib::unique_ptr<X>() ); + } + + { + test_null_unique_ptr<Y>( boost::movelib::unique_ptr<Y, YD>( 0, YD() ), boost::movelib::unique_ptr<Y, YD>( 0, YD() ) ); + test_null_unique_ptr<Y const>( boost::movelib::unique_ptr<Y, YD>( 0, YD() ), boost::movelib::unique_ptr<Y, YD>( 0, YD() ) ); + test_null_unique_ptr<void>( boost::movelib::unique_ptr<Y, YD>( 0, YD() ), boost::movelib::unique_ptr<Y, YD>( 0, YD() ) ); + test_null_unique_ptr<void const>( boost::movelib::unique_ptr<Y, YD>( 0, YD() ), boost::movelib::unique_ptr<Y, YD>( 0, YD() ) ); + } + + { + YD yd; + + test_null_unique_ptr<Y>( boost::movelib::unique_ptr<Y, YD&>( 0, yd ), boost::movelib::unique_ptr<Y, YD&>( 0, yd ) ); + test_null_unique_ptr<Y const>( boost::movelib::unique_ptr<Y, YD&>( 0, yd ), boost::movelib::unique_ptr<Y, YD&>( 0, yd ) ); + test_null_unique_ptr<void>( boost::movelib::unique_ptr<Y, YD&>( 0, yd ), boost::movelib::unique_ptr<Y, YD&>( 0, yd ) ); + test_null_unique_ptr<void const>( boost::movelib::unique_ptr<Y, YD&>( 0, yd ), boost::movelib::unique_ptr<Y, YD&>( 0, yd ) ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_constexpr_test.cpp b/src/boost/libs/smart_ptr/test/sp_constexpr_test.cpp new file mode 100644 index 00000000..4de43dd5 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_constexpr_test.cpp @@ -0,0 +1,86 @@ +// +// sp_constexpr_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 <boost/config.hpp> +#include <boost/detail/workaround.hpp> + +#define HAVE_CONSTEXPR_INIT + +#if defined( BOOST_NO_CXX11_CONSTEXPR ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if BOOST_WORKAROUND( BOOST_MSVC, < 1930 ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if !defined( HAVE_CONSTEXPR_INIT ) + +int main() +{ +} + +#else + +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/core/lightweight_test.hpp> + +struct X: public boost::enable_shared_from_this<X> +{ +}; + +struct Z +{ + Z(); +}; + +static Z z; + +static boost::shared_ptr<X> p1; +static boost::weak_ptr<X> p2; + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + static boost::shared_ptr<X> p3( nullptr ); +#endif + +Z::Z() +{ + p1.reset( new X ); + p2 = p1; +#if !defined( BOOST_NO_CXX11_NULLPTR ) + p3.reset( new X ); +#endif +} + +int main() +{ + BOOST_TEST( p1.get() != 0 ); + BOOST_TEST_EQ( p1.use_count(), 1 ); + + BOOST_TEST_EQ( p2.use_count(), 1 ); + BOOST_TEST_EQ( p2.lock(), p1 ); + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + + BOOST_TEST( p3.get() != 0 ); + BOOST_TEST_EQ( p3.use_count(), 1 ); + +#endif + + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_CXX11_CONSEXPR ) diff --git a/src/boost/libs/smart_ptr/test/sp_constexpr_test2.cpp b/src/boost/libs/smart_ptr/test/sp_constexpr_test2.cpp new file mode 100644 index 00000000..d4926a86 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_constexpr_test2.cpp @@ -0,0 +1,68 @@ +// +// sp_constexpr_test2.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 <boost/config.hpp> +#include <boost/detail/workaround.hpp> + +#define HAVE_CONSTEXPR_INIT + +#if defined( BOOST_NO_CXX11_CONSTEXPR ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if BOOST_WORKAROUND( BOOST_MSVC, < 1930 ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if !defined( HAVE_CONSTEXPR_INIT ) + +int main() +{ +} + +#else + +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/core/lightweight_test.hpp> + +struct X: public boost::enable_shared_from_this<X> +{ + int v_; + + constexpr X() BOOST_NOEXCEPT: v_( 1 ) + { + } +}; + +struct Z +{ + Z(); +}; + +static Z z; +static X x; + +Z::Z() +{ + BOOST_TEST_EQ( x.v_, 1 ); +} + +int main() +{ + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_CXX11_CONSEXPR ) diff --git a/src/boost/libs/smart_ptr/test/sp_convertible_test.cpp b/src/boost/libs/smart_ptr/test/sp_convertible_test.cpp new file mode 100644 index 00000000..05b15c1e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_convertible_test.cpp @@ -0,0 +1,93 @@ +#include <boost/config.hpp> + +// sp_convertible_test.cpp +// +// Copyright (c) 2012 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 <boost/detail/lightweight_test.hpp> +#include <boost/smart_ptr/detail/sp_convertible.hpp> + +// + +class X; + +class B +{ +}; + +class D: public B +{ +}; + +#define TEST_CV_TRUE( T, U ) \ + BOOST_TEST(( sp_convertible< T, U >::value == true )); \ + BOOST_TEST(( sp_convertible< T, const U >::value == true )); \ + BOOST_TEST(( sp_convertible< T, volatile U >::value == true )); \ + BOOST_TEST(( sp_convertible< T, const volatile U >::value == true )); \ + BOOST_TEST(( sp_convertible< const T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< const T, const U >::value == true )); \ + BOOST_TEST(( sp_convertible< const T, volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< const T, const volatile U >::value == true )); \ + BOOST_TEST(( sp_convertible< volatile T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< volatile T, const U >::value == false )); \ + BOOST_TEST(( sp_convertible< volatile T, volatile U >::value == true )); \ + BOOST_TEST(( sp_convertible< volatile T, const volatile U >::value == true )); \ + BOOST_TEST(( sp_convertible< const volatile T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, const U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, const volatile U >::value == true )); + +#define TEST_CV_FALSE( T, U ) \ + BOOST_TEST(( sp_convertible< T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< T, const U >::value == false )); \ + BOOST_TEST(( sp_convertible< T, volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< T, const volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< const T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< const T, const U >::value == false )); \ + BOOST_TEST(( sp_convertible< const T, volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< const T, const volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< volatile T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< volatile T, const U >::value == false )); \ + BOOST_TEST(( sp_convertible< volatile T, volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< volatile T, const volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, const U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, volatile U >::value == false )); \ + BOOST_TEST(( sp_convertible< const volatile T, const volatile U >::value == false )); + +int main() +{ +#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) + + using boost::detail::sp_convertible; + + TEST_CV_TRUE( X, X ) + TEST_CV_TRUE( X, void ) + TEST_CV_FALSE( void, X ) + TEST_CV_TRUE( D, B ) + TEST_CV_FALSE( B, D ) + + TEST_CV_TRUE( X[], X[] ) + TEST_CV_FALSE( D[], B[] ) + + TEST_CV_TRUE( X[3], X[3] ) + TEST_CV_FALSE( X[3], X[4] ) + TEST_CV_FALSE( D[3], B[3] ) + + TEST_CV_TRUE( X[3], X[] ) + TEST_CV_FALSE( X[], X[3] ) + + TEST_CV_TRUE( X[], void ) + TEST_CV_FALSE( void, X[] ) + + TEST_CV_TRUE( X[3], void ) + TEST_CV_FALSE( void, X[3] ) + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_convertible_test2.cpp b/src/boost/libs/smart_ptr/test/sp_convertible_test2.cpp new file mode 100644 index 00000000..7635d827 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_convertible_test2.cpp @@ -0,0 +1,108 @@ +#include <boost/config.hpp> + +// sp_convertible_test2.cpp +// +// Copyright 2012, 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 <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/type_traits/is_convertible.hpp> + +// + +class X; + +class B +{ +}; + +class D: public B +{ +}; + +using boost::is_convertible; + +#define TEST_CV_TRUE_( S1, T, S2, U ) \ + BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == true )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == true )); + +#define TEST_CV_FALSE_( S1, T, S2, U ) \ + BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \ + BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == false )); + +using boost::shared_ptr; +using boost::weak_ptr; + +#define TEST_CV_TRUE( T, U ) \ + TEST_CV_TRUE_( shared_ptr, T, shared_ptr, U ) \ + TEST_CV_TRUE_( shared_ptr, T, weak_ptr, U ) \ + TEST_CV_TRUE_( weak_ptr, T, weak_ptr, U ) + +#define TEST_CV_FALSE( T, U ) \ + TEST_CV_FALSE_( shared_ptr, T, shared_ptr, U ) \ + TEST_CV_FALSE_( shared_ptr, T, weak_ptr, U ) \ + TEST_CV_FALSE_( weak_ptr, T, weak_ptr, U ) + +int main() +{ +#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) + + TEST_CV_TRUE( X, X ) + TEST_CV_TRUE( X, void ) + TEST_CV_FALSE( void, X ) + TEST_CV_TRUE( D, B ) + TEST_CV_FALSE( B, D ) + + TEST_CV_TRUE( X[], X[] ) + TEST_CV_FALSE( D[], B[] ) + + TEST_CV_TRUE( X[3], X[3] ) + TEST_CV_FALSE( X[3], X[4] ) + TEST_CV_FALSE( D[3], B[3] ) + + TEST_CV_TRUE( X[3], X[] ) + TEST_CV_FALSE( X[], X[3] ) + + TEST_CV_TRUE( X[], void ) + TEST_CV_FALSE( void, X[] ) + + TEST_CV_TRUE( X[3], void ) + TEST_CV_FALSE( void, X[3] ) + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_explicit_inst_test.cpp b/src/boost/libs/smart_ptr/test/sp_explicit_inst_test.cpp new file mode 100644 index 00000000..d8de782e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_explicit_inst_test.cpp @@ -0,0 +1,23 @@ +// +// Explicit instantiations are reported to exist in user code +// +// Copyright (c) 2014 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 <boost/shared_ptr.hpp> + +template class boost::shared_ptr< int >; + +struct X +{ +}; + +template class boost::shared_ptr< X >; + +int main() +{ +} diff --git a/src/boost/libs/smart_ptr/test/sp_hash_test.cpp b/src/boost/libs/smart_ptr/test/sp_hash_test.cpp new file mode 100644 index 00000000..b67f547a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_hash_test.cpp @@ -0,0 +1,34 @@ +// +// sp_hash_test.cpp +// +// Copyright 2011 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 <boost/shared_ptr.hpp> +#include <boost/functional/hash.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::hash< boost::shared_ptr<int> > hasher; + + boost::shared_ptr< int > p1, p2( p1 ), p3( new int ), p4( p3 ), p5( new int ); + + BOOST_TEST_EQ( p1, p2 ); + BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) ); + + BOOST_TEST_NE( p1, p3 ); + BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) ); + + BOOST_TEST_EQ( p3, p4 ); + BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) ); + + BOOST_TEST_NE( p3, p5 ); + BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_hash_test2.cpp b/src/boost/libs/smart_ptr/test/sp_hash_test2.cpp new file mode 100644 index 00000000..c1cbf709 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_hash_test2.cpp @@ -0,0 +1,34 @@ +// +// sp_hash_test2.cpp +// +// Copyright 2011, 2015 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 <boost/shared_ptr.hpp> +#include <boost/functional/hash.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::hash< boost::shared_ptr<int[]> > hasher; + + boost::shared_ptr< int[] > p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] ); + + BOOST_TEST_EQ( p1, p2 ); + BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) ); + + BOOST_TEST_NE( p1, p3 ); + BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) ); + + BOOST_TEST_EQ( p3, p4 ); + BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) ); + + BOOST_TEST_NE( p3, p5 ); + BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_hash_test3.cpp b/src/boost/libs/smart_ptr/test/sp_hash_test3.cpp new file mode 100644 index 00000000..4d4acad6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_hash_test3.cpp @@ -0,0 +1,34 @@ +// +// sp_hash_test3.cpp +// +// Copyright 2011, 2015 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 <boost/shared_ptr.hpp> +#include <boost/functional/hash.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::hash< boost::shared_ptr<int[1]> > hasher; + + boost::shared_ptr< int[1] > p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] ); + + BOOST_TEST_EQ( p1, p2 ); + BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) ); + + BOOST_TEST_NE( p1, p3 ); + BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) ); + + BOOST_TEST_EQ( p3, p4 ); + BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) ); + + BOOST_TEST_NE( p3, p5 ); + BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_interlocked_test.cpp b/src/boost/libs/smart_ptr/test/sp_interlocked_test.cpp new file mode 100644 index 00000000..73a57f63 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_interlocked_test.cpp @@ -0,0 +1,71 @@ +// +// sp_interlocked_test.cpp +// +// Copyright 2014 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 +// + +#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) + +#include <boost/smart_ptr/detail/sp_interlocked.hpp> +#include <boost/detail/lightweight_test.hpp> + +#ifndef __LP64__ + +typedef long long_type; + +#else + +// On Cygwin 64, long is 64 bit +typedef int long_type; + +#endif + +int main() +{ + long_type x = 0, r; + + r = BOOST_SP_INTERLOCKED_INCREMENT( &x ); + + BOOST_TEST( x == 1 ); + BOOST_TEST( r == 1 ); + + r = BOOST_SP_INTERLOCKED_DECREMENT( &x ); + + BOOST_TEST( x == 0 ); + BOOST_TEST( r == 0 ); + + r = BOOST_SP_INTERLOCKED_EXCHANGE( &x, 3 ); + + BOOST_TEST( x == 3 ); + BOOST_TEST( r == 0 ); + + r = BOOST_SP_INTERLOCKED_EXCHANGE_ADD( &x, 2 ); + + BOOST_TEST( x == 5 ); + BOOST_TEST( r == 3 ); + + r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 3 ); + + BOOST_TEST( x == 5 ); + BOOST_TEST( r == 5 ); + + r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 5 ); + + BOOST_TEST( x == 0 ); + BOOST_TEST( r == 5 ); + + return boost::report_errors(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/sp_nothrow_test.cpp b/src/boost/libs/smart_ptr/test/sp_nothrow_test.cpp new file mode 100644 index 00000000..156e72e8 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_nothrow_test.cpp @@ -0,0 +1,96 @@ +// +// sp_nothrow_test.cpp +// +// Copyright 2016 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 <boost/config.hpp> + +#if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS ) + +int main() +{ +} + +#else + +#include <boost/shared_ptr.hpp> +#include <boost/shared_array.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/scoped_ptr.hpp> +#include <boost/scoped_array.hpp> +#include <boost/intrusive_ptr.hpp> +#include <boost/core/lightweight_test_trait.hpp> +#include <type_traits> + +template<class T> void test_copy() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_constructible<T> )); + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_assignable<T> )); +} + +template<class T> void test_move() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<T> )); + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<T> )); +} + +template<class T> void test_default() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_default_constructible<T> )); +} + +template<class T> void test_destroy() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_destructible<T> )); +} + +template<class T> void test_cmd() +{ + test_copy<T>(); + test_move<T>(); + test_default<T>(); +} + +struct X +{ +}; + +struct Y: public boost::enable_shared_from_this<Y> +{ +}; + +int main() +{ + test_cmd< boost::shared_ptr<X> >(); + test_cmd< boost::shared_array<X> >(); + test_cmd< boost::weak_ptr<X> >(); + + test_copy< Y >(); + test_default< Y >(); + test_destroy< Y >(); + + // test_move< Y >(); + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<Y> )); + +#if !( defined( BOOST_MSVC ) && BOOST_MSVC == 1700 ) + + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<Y> )); + +#endif + + test_default< boost::scoped_ptr<X> >(); + test_default< boost::scoped_array<X> >(); + + test_move< boost::intrusive_ptr<X> >(); + test_default< boost::intrusive_ptr<X> >(); + + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS ) diff --git a/src/boost/libs/smart_ptr/test/sp_nullptr_test.cpp b/src/boost/libs/smart_ptr/test/sp_nullptr_test.cpp new file mode 100644 index 00000000..1b3965c4 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_nullptr_test.cpp @@ -0,0 +1,141 @@ +// +// sp_nullptr_test.cpp +// +// Copyright 2012 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 <boost/shared_ptr.hpp> +#include <boost/smart_ptr/detail/sp_nullptr_t.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <cstddef> +#include <memory> + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + +struct X +{ + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +void f( boost::detail::sp_nullptr_t ) +{ +} + +int main() +{ + { + boost::shared_ptr<void> p( nullptr ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + { + boost::shared_ptr<int> p( nullptr, f ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 1 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + { + boost::shared_ptr<int> p( nullptr, f, std::allocator<int>() ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 1 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + { + boost::shared_ptr<int> p( new int ); + + BOOST_TEST( p.get() != 0 ); + BOOST_TEST( p.use_count() == 1 ); + + BOOST_TEST( p != nullptr ); + BOOST_TEST( nullptr != p ); + BOOST_TEST( !( p == nullptr ) ); + BOOST_TEST( !( nullptr == p ) ); + + p = nullptr; + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + { + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + BOOST_TEST( p.get() != 0 ); + BOOST_TEST( p.use_count() == 1 ); + + BOOST_TEST( p != nullptr ); + BOOST_TEST( nullptr != p ); + BOOST_TEST( !( p == nullptr ) ); + BOOST_TEST( !( nullptr == p ) ); + + p = nullptr; + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( p.get() == 0 ); + BOOST_TEST( p.use_count() == 0 ); + + BOOST_TEST( p == nullptr ); + BOOST_TEST( nullptr == p ); + BOOST_TEST( !( p != nullptr ) ); + BOOST_TEST( !( nullptr != p ) ); + } + + return boost::report_errors(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/sp_recursive_assign2_rv_test.cpp b/src/boost/libs/smart_ptr/test/sp_recursive_assign2_rv_test.cpp new file mode 100644 index 00000000..e450c72b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_recursive_assign2_rv_test.cpp @@ -0,0 +1,114 @@ +// +// sp_recursive_assign2_rv_test.cpp +// +// Copyright 2009 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X +{ +public: + + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const& ); +}; + +int X::instances = 0; + +class Y +{ +public: + + static int instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y( Y const& ); +}; + +int Y::instances = 0; + +static boost::shared_ptr<void> s_pv; + +class Z +{ +public: + + static int instances; + + Z() + { + ++instances; + } + + ~Z() + { + --instances; + s_pv = boost::shared_ptr<Y>( new Y ); + } + +private: + + Z( Z const& ); +}; + +int Z::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + s_pv = boost::shared_ptr<Z>( new Z ); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 1 ); + + s_pv = boost::shared_ptr<X>( new X ); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( Z::instances == 0 ); + + s_pv = boost::shared_ptr<Y>(); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_recursive_assign2_test.cpp b/src/boost/libs/smart_ptr/test/sp_recursive_assign2_test.cpp new file mode 100644 index 00000000..ef6fa520 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_recursive_assign2_test.cpp @@ -0,0 +1,122 @@ +// +// sp_recursive_assign2_test.cpp +// +// Copyright 2009 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X +{ +public: + + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const& ); +}; + +int X::instances = 0; + +class Y +{ +public: + + static int instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y( Y const& ); +}; + +int Y::instances = 0; + +static boost::shared_ptr<void> s_pv; + +class Z +{ +public: + + static int instances; + + Z() + { + ++instances; + } + + ~Z() + { + --instances; + + boost::shared_ptr<Y> pv( new Y ); + s_pv = pv; + } + +private: + + Z( Z const& ); +}; + +int Z::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + { + boost::shared_ptr<Z> pv( new Z ); + s_pv = pv; + } + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 1 ); + + { + boost::shared_ptr<X> pv( new X ); + s_pv = pv; + } + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( Z::instances == 0 ); + + s_pv.reset(); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_recursive_assign_rv_test.cpp b/src/boost/libs/smart_ptr/test/sp_recursive_assign_rv_test.cpp new file mode 100644 index 00000000..8d80e724 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_recursive_assign_rv_test.cpp @@ -0,0 +1,114 @@ +// +// sp_recursive_assign_rv_test.cpp +// +// Copyright 2009 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X +{ +public: + + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const& ); +}; + +int X::instances = 0; + +class Y +{ +public: + + static int instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y( Y const& ); +}; + +int Y::instances = 0; + +static boost::shared_ptr<void> s_pv; + +class Z +{ +public: + + static int instances; + + Z() + { + ++instances; + } + + ~Z() + { + --instances; + s_pv = boost::shared_ptr<void>( new Y ); + } + +private: + + Z( Z const& ); +}; + +int Z::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + s_pv = boost::shared_ptr<void>( new Z ); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 1 ); + + s_pv = boost::shared_ptr<void>( new X ); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( Z::instances == 0 ); + + s_pv = boost::shared_ptr<void>(); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_recursive_assign_test.cpp b/src/boost/libs/smart_ptr/test/sp_recursive_assign_test.cpp new file mode 100644 index 00000000..0f368913 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_recursive_assign_test.cpp @@ -0,0 +1,122 @@ +// +// sp_recursive_assign_test.cpp +// +// Copyright 2009 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +// + +class X +{ +public: + + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const& ); +}; + +int X::instances = 0; + +class Y +{ +public: + + static int instances; + + Y() + { + ++instances; + } + + ~Y() + { + --instances; + } + +private: + + Y( Y const& ); +}; + +int Y::instances = 0; + +static boost::shared_ptr<void> s_pv; + +class Z +{ +public: + + static int instances; + + Z() + { + ++instances; + } + + ~Z() + { + --instances; + + boost::shared_ptr<void> pv( new Y ); + s_pv = pv; + } + +private: + + Z( Z const& ); +}; + +int Z::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + { + boost::shared_ptr<void> pv( new Z ); + s_pv = pv; + } + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 1 ); + + { + boost::shared_ptr<void> pv( new X ); + s_pv = pv; + } + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( Z::instances == 0 ); + + s_pv.reset(); + + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( Y::instances == 0 ); + BOOST_TEST( Z::instances == 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_typeinfo_test.cpp b/src/boost/libs/smart_ptr/test/sp_typeinfo_test.cpp new file mode 100644 index 00000000..120c5bfb --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_typeinfo_test.cpp @@ -0,0 +1,51 @@ +// +// sp_typeinfo_test.cpp +// +// Copyright (c) 2009 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 <boost/smart_ptr/detail/sp_typeinfo_.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> + +int main() +{ + BOOST_TEST( BOOST_SP_TYPEID_( int ) == BOOST_SP_TYPEID_( int ) ); + BOOST_TEST( BOOST_SP_TYPEID_( int ) != BOOST_SP_TYPEID_( long ) ); + BOOST_TEST( BOOST_SP_TYPEID_( int ) != BOOST_SP_TYPEID_( void ) ); + + boost::detail::sp_typeinfo_ const & ti = BOOST_SP_TYPEID_( int ); + + boost::detail::sp_typeinfo_ const * pti = &BOOST_SP_TYPEID_( int ); + BOOST_TEST( *pti == ti ); + + BOOST_TEST( ti == ti ); + BOOST_TEST( !( ti != ti ) ); + BOOST_TEST( !ti.before( ti ) ); + + char const * nti = ti.name(); + std::cout << nti << std::endl; + + boost::detail::sp_typeinfo_ const & tv = BOOST_SP_TYPEID_( void ); + + boost::detail::sp_typeinfo_ const * ptv = &BOOST_SP_TYPEID_( void ); + BOOST_TEST( *ptv == tv ); + + BOOST_TEST( tv == tv ); + BOOST_TEST( !( tv != tv ) ); + BOOST_TEST( !tv.before( tv ) ); + + char const * ntv = tv.name(); + std::cout << ntv << std::endl; + + BOOST_TEST( ti != tv ); + BOOST_TEST( !( ti == tv ) ); + + BOOST_TEST( ti.before( tv ) != tv.before( ti ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_unary_addr_test.cpp b/src/boost/libs/smart_ptr/test/sp_unary_addr_test.cpp new file mode 100644 index 00000000..a4007a26 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_unary_addr_test.cpp @@ -0,0 +1,67 @@ +// +// sp_unary_addr_test.cpp +// +// Copyright (c) 2007 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 <boost/shared_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <memory> + +struct deleter +{ +private: + + void operator& (); + void operator& () const; + +public: + + int data; + + deleter(): data( 17041 ) + { + } + + void operator()( void * ) + { + } +}; + +struct X +{ +}; + +int main() +{ + X x; + + { + boost::shared_ptr<X> p( &x, deleter() ); + + deleter * q = boost::get_deleter<deleter>( p ); + + BOOST_TEST( q != 0 ); + BOOST_TEST( q != 0 && q->data == 17041 ); + } + +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) +#else + + { + boost::shared_ptr<X> p( &x, deleter(), std::allocator<X>() ); + + deleter * q = boost::get_deleter<deleter>( p ); + + BOOST_TEST( q != 0 ); + BOOST_TEST( q != 0 && q->data == 17041 ); + } + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/sp_unique_ptr_test.cpp b/src/boost/libs/smart_ptr/test/sp_unique_ptr_test.cpp new file mode 100644 index 00000000..8e829592 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_unique_ptr_test.cpp @@ -0,0 +1,294 @@ +// +// sp_unique_ptr_test.cpp +// +// Copyright (c) 2012 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 <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/type_traits/remove_reference.hpp> +#include <memory> +#include <utility> + +#if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +struct X: public boost::enable_shared_from_this< X > +{ + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +struct Y +{ + static int instances; + + bool deleted_; + + Y(): deleted_( false ) + { + ++instances; + } + + ~Y() + { + BOOST_TEST( deleted_ ); + --instances; + } + +private: + + Y( Y const & ); + Y & operator=( Y const & ); +}; + +int Y::instances = 0; + +struct YD +{ + void operator()( Y* p ) const + { + if( p ) + { + p->deleted_ = true; + delete p; + } + else + { + BOOST_ERROR( "YD::operator()(0) called" ); + } + } +}; + +template<class U, class T, class D> static void test_null_unique_ptr( std::unique_ptr<T, D> p1, std::unique_ptr<T, D> p2 ) +{ + BOOST_TEST( T::instances == 0 ); + + boost::shared_ptr<U> sp( std::move( p1 ) ); + + BOOST_TEST( sp.get() == 0 ); + BOOST_TEST( sp.use_count() == 0 ); + + sp.reset( new T, typename boost::remove_reference<D>::type() ); + + BOOST_TEST( sp.get() != 0 ); + BOOST_TEST( sp.use_count() == 1 ); + + BOOST_TEST( T::instances == 1 ); + + sp = std::move( p2 ); + + BOOST_TEST( sp.get() == 0 ); + BOOST_TEST( sp.use_count() == 0 ); + + BOOST_TEST( T::instances == 0 ); +} + +int main() +{ + { + BOOST_TEST( X::instances == 0 ); + + std::unique_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X> p2( std::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<X> p3 = p2->shared_from_this(); + BOOST_TEST( p2 == p3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + p2.reset(); + p3.reset(); + BOOST_TEST( X::instances == 0 ); + + p2 = std::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2 = std::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + BOOST_TEST( X::instances == 0 ); + + std::unique_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<X const> p2( std::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + boost::shared_ptr<X const> p3 = p2->shared_from_this(); + BOOST_TEST( p2 == p3 ); + BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); + + p2.reset(); + p3.reset(); + BOOST_TEST( X::instances == 0 ); + + p2 = std::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2 = std::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + BOOST_TEST( X::instances == 0 ); + + std::unique_ptr<X> p( new X ); + BOOST_TEST( X::instances == 1 ); + + boost::shared_ptr<void> p2( std::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); + + p2 = std::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2 = std::unique_ptr<X>( new X ); + BOOST_TEST( X::instances == 1 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); + } + + { + BOOST_TEST( Y::instances == 0 ); + + std::unique_ptr<Y, YD> p( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + boost::shared_ptr<Y> p2( std::move( p ) ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + + p2 = std::unique_ptr<Y, YD>( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + p2 = std::unique_ptr<Y, YD>( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + } + + { + BOOST_TEST( Y::instances == 0 ); + + YD yd; + + std::unique_ptr<Y, YD&> p( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + boost::shared_ptr<Y> p2( std::move( p ) ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + + p2 = std::unique_ptr<Y, YD&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2 = std::unique_ptr<Y, YD&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + } + + { + BOOST_TEST( Y::instances == 0 ); + + YD yd; + + std::unique_ptr<Y, YD const&> p( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + boost::shared_ptr<Y> p2( std::move( p ) ); + BOOST_TEST( Y::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + + p2 = std::unique_ptr<Y, YD const&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2 = std::unique_ptr<Y, YD const&>( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); + } + + { + test_null_unique_ptr<X>( std::unique_ptr<X>(), std::unique_ptr<X>() ); + test_null_unique_ptr<X const>( std::unique_ptr<X>(), std::unique_ptr<X>() ); + test_null_unique_ptr<void>( std::unique_ptr<X>(), std::unique_ptr<X>() ); + test_null_unique_ptr<void const>( std::unique_ptr<X>(), std::unique_ptr<X>() ); + } + + { + test_null_unique_ptr<Y>( std::unique_ptr<Y, YD>( 0, YD() ), std::unique_ptr<Y, YD>( 0, YD() ) ); + test_null_unique_ptr<Y const>( std::unique_ptr<Y, YD>( 0, YD() ), std::unique_ptr<Y, YD>( 0, YD() ) ); + test_null_unique_ptr<void>( std::unique_ptr<Y, YD>( 0, YD() ), std::unique_ptr<Y, YD>( 0, YD() ) ); + test_null_unique_ptr<void const>( std::unique_ptr<Y, YD>( 0, YD() ), std::unique_ptr<Y, YD>( 0, YD() ) ); + } + + { + YD yd; + + test_null_unique_ptr<Y>( std::unique_ptr<Y, YD&>( 0, yd ), std::unique_ptr<Y, YD&>( 0, yd ) ); + test_null_unique_ptr<Y const>( std::unique_ptr<Y, YD&>( 0, yd ), std::unique_ptr<Y, YD&>( 0, yd ) ); + test_null_unique_ptr<void>( std::unique_ptr<Y, YD&>( 0, yd ), std::unique_ptr<Y, YD&>( 0, yd ) ); + test_null_unique_ptr<void const>( std::unique_ptr<Y, YD&>( 0, yd ), std::unique_ptr<Y, YD&>( 0, yd ) ); + } + + return boost::report_errors(); +} + +#else // !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/sp_windows_h_test.cpp b/src/boost/libs/smart_ptr/test/sp_windows_h_test.cpp new file mode 100644 index 00000000..b4df1325 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_windows_h_test.cpp @@ -0,0 +1,11 @@ +// Copyright 2018 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. + +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# include <windows.h> +# include <boost/shared_ptr.hpp> +#endif + +int main() +{ +} diff --git a/src/boost/libs/smart_ptr/test/sp_zero_compare_test.cpp b/src/boost/libs/smart_ptr/test/sp_zero_compare_test.cpp new file mode 100644 index 00000000..e326d345 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/sp_zero_compare_test.cpp @@ -0,0 +1,78 @@ +// +// sp_zero_compare_test.cpp - == 0, != 0 +// +// Copyright 2012 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 <boost/scoped_ptr.hpp> +#include <boost/scoped_array.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/shared_array.hpp> +#include <boost/intrusive_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct W +{ +}; + +void intrusive_ptr_add_ref( W* ) +{ +} + +void intrusive_ptr_release( W* ) +{ +} + +int main() +{ + { + boost::scoped_ptr<int> p; + + BOOST_TEST( p == 0 ); + BOOST_TEST( 0 == p ); + BOOST_TEST( !( p != 0 ) ); + BOOST_TEST( !( 0 != p ) ); + } + + { + boost::scoped_array<int> p; + + BOOST_TEST( p == 0 ); + BOOST_TEST( 0 == p ); + BOOST_TEST( !( p != 0 ) ); + BOOST_TEST( !( 0 != p ) ); + } + + { + boost::shared_ptr<int> p; + + BOOST_TEST( p == 0 ); + BOOST_TEST( 0 == p ); + BOOST_TEST( !( p != 0 ) ); + BOOST_TEST( !( 0 != p ) ); + } + + { + boost::shared_array<int> p; + + BOOST_TEST( p == 0 ); + BOOST_TEST( 0 == p ); + BOOST_TEST( !( p != 0 ) ); + BOOST_TEST( !( 0 != p ) ); + } + + { + boost::intrusive_ptr<W> p; + + BOOST_TEST( p == 0 ); + BOOST_TEST( 0 == p ); + BOOST_TEST( !( p != 0 ) ); + BOOST_TEST( !( 0 != p ) ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/spinlock_pool_test.cpp b/src/boost/libs/smart_ptr/test/spinlock_pool_test.cpp new file mode 100644 index 00000000..53f61ca6 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/spinlock_pool_test.cpp @@ -0,0 +1,30 @@ +// +// spinlock_pool_test.cpp +// +// Copyright 2008 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 <boost/smart_ptr/detail/spinlock_pool.hpp> + +// Sanity check only + +int main() +{ + int x = 0; + + { + boost::detail::spinlock_pool<0>::scoped_lock lock( &x ); + ++x; + } + + { + boost::detail::spinlock_pool<1>::scoped_lock lock( &x ); + boost::detail::spinlock_pool<2>::scoped_lock lock2( &x ); + } + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/spinlock_test.cpp b/src/boost/libs/smart_ptr/test/spinlock_test.cpp new file mode 100644 index 00000000..d2c66c00 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/spinlock_test.cpp @@ -0,0 +1,31 @@ +// +// spinlock_test.cpp +// +// Copyright 2008 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 <boost/smart_ptr/detail/spinlock.hpp> + +// Sanity check only + +static boost::detail::spinlock sp = BOOST_DETAIL_SPINLOCK_INIT; +static boost::detail::spinlock sp2 = BOOST_DETAIL_SPINLOCK_INIT; + +int main() +{ + sp.lock(); + sp2.lock(); + sp.unlock(); + sp2.unlock(); + + { + boost::detail::spinlock::scoped_lock lock( sp ); + boost::detail::spinlock::scoped_lock lock2( sp2 ); + } + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/spinlock_try_test.cpp b/src/boost/libs/smart_ptr/test/spinlock_try_test.cpp new file mode 100644 index 00000000..008b60e1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/spinlock_try_test.cpp @@ -0,0 +1,46 @@ +// +// spinlock_try_test.cpp +// +// Copyright 2008 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 <boost/smart_ptr/detail/spinlock.hpp> +#include <boost/detail/lightweight_test.hpp> + +// Sanity check only + +static boost::detail::spinlock sp = BOOST_DETAIL_SPINLOCK_INIT; +static boost::detail::spinlock sp2 = BOOST_DETAIL_SPINLOCK_INIT; + +int main() +{ + BOOST_TEST( sp.try_lock() ); + BOOST_TEST( !sp.try_lock() ); + BOOST_TEST( sp2.try_lock() ); + BOOST_TEST( !sp.try_lock() ); + BOOST_TEST( !sp2.try_lock() ); + sp.unlock(); + sp2.unlock(); + + sp.lock(); + BOOST_TEST( !sp.try_lock() ); + sp2.lock(); + BOOST_TEST( !sp.try_lock() ); + BOOST_TEST( !sp2.try_lock() ); + sp.unlock(); + sp2.unlock(); + + { + boost::detail::spinlock::scoped_lock lock( sp ); + BOOST_TEST( !sp.try_lock() ); + boost::detail::spinlock::scoped_lock lock2( sp2 ); + BOOST_TEST( !sp.try_lock() ); + BOOST_TEST( !sp2.try_lock() ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/spinlock_windows_h_test.cpp b/src/boost/libs/smart_ptr/test/spinlock_windows_h_test.cpp new file mode 100644 index 00000000..68a87810 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/spinlock_windows_h_test.cpp @@ -0,0 +1,11 @@ +// Copyright 2018 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. + +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# include <windows.h> +# include <boost/smart_ptr/detail/spinlock.hpp> +#endif + +int main() +{ +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_raw_test.cpp b/src/boost/libs/smart_ptr/test/weak_from_raw_test.cpp new file mode 100644 index 00000000..34d21eb2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_raw_test.cpp @@ -0,0 +1,38 @@ +#include <boost/config.hpp> + +// +// weak_from_raw_test.cpp +// +// Copyright (c) 2009 Frank Mori Hess +// +// 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/detail/lightweight_test.hpp> + + +struct X: public boost::enable_shared_from_raw +{}; + +void basic_weak_from_raw_test() +{ + X *p(new X); + boost::weak_ptr<X> weak = boost::weak_from_raw(p); + BOOST_TEST(!weak.expired()); + boost::shared_ptr<X> shared(p); + weak = boost::weak_from_raw(p); + BOOST_TEST(weak.expired() == false); + boost::shared_ptr<X> shared2(weak); + BOOST_TEST((shared < shared2 || shared2 < shared) == false); + BOOST_TEST(shared.get() == p); +} + +int main() +{ + basic_weak_from_raw_test(); + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_raw_test2.cpp b/src/boost/libs/smart_ptr/test/weak_from_raw_test2.cpp new file mode 100644 index 00000000..c1da6f0a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_raw_test2.cpp @@ -0,0 +1,67 @@ +// +// weak_from_raw_test2.cpp +// +// Test that weak_from_raw returns consistent values +// throughout the object lifetime +// +// Copyright (c) 2014 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X; + +static boost::weak_ptr< X > r_; + +void register_( boost::weak_ptr< X > const & r ) +{ + r_ = r; +} + +void check_( boost::weak_ptr< X > const & r ) +{ + BOOST_TEST( !( r < r_ ) && !( r_ < r ) ); +} + +void unregister_( boost::weak_ptr< X > const & r ) +{ + BOOST_TEST( !( r < r_ ) && !( r_ < r ) ); + r_.reset(); +} + +class X: public boost::enable_shared_from_raw +{ +public: + + X() + { + register_( boost::shared_from_raw( this ) ); + } + + ~X() + { + unregister_( boost::weak_from_raw( this ) ); + } + + void check() + { + check_( boost::weak_from_raw( this ) ); + } +}; + +int main() +{ + { + boost::shared_ptr< X > px( new X ); + px->check(); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_raw_test3.cpp b/src/boost/libs/smart_ptr/test/weak_from_raw_test3.cpp new file mode 100644 index 00000000..ee73b4c8 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_raw_test3.cpp @@ -0,0 +1,46 @@ +// +// weak_from_raw_test3.cpp +// +// Test that weak_from_raw and shared_from_raw +// return consistent values from a constructor +// +// Copyright (c) 2015 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X: public boost::enable_shared_from_raw +{ +public: + + X() + { + boost::weak_ptr<X> p1 = boost::weak_from_raw( this ); + BOOST_TEST( !p1.expired() ); + + boost::weak_ptr<X> p2 = boost::weak_from_raw( this ); + BOOST_TEST( !p2.expired() ); + BOOST_TEST( !( p1 < p2 ) && !( p2 < p1 ) ); + + boost::weak_ptr<X> p3 = boost::shared_from_raw( this ); + BOOST_TEST( !( p1 < p3 ) && !( p3 < p1 ) ); + + boost::weak_ptr<X> p4 = boost::weak_from_raw( this ); + BOOST_TEST( !p4.expired() ); + BOOST_TEST( !( p3 < p4 ) && !( p4 < p3 ) ); + BOOST_TEST( !( p1 < p4 ) && !( p4 < p1 ) ); + } +}; + +int main() +{ + boost::shared_ptr< X > px( new X ); + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_raw_test4.cpp b/src/boost/libs/smart_ptr/test/weak_from_raw_test4.cpp new file mode 100644 index 00000000..2408f009 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_raw_test4.cpp @@ -0,0 +1,67 @@ +// +// weak_from_raw_test4.cpp +// +// As weak_from_raw_test2.cpp, but uses weak_from_raw +// in the constructor +// +// Copyright (c) 2014, 2015 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X; + +static boost::weak_ptr< X > r_; + +void register_( boost::weak_ptr< X > const & r ) +{ + r_ = r; +} + +void check_( boost::weak_ptr< X > const & r ) +{ + BOOST_TEST( !( r < r_ ) && !( r_ < r ) ); +} + +void unregister_( boost::weak_ptr< X > const & r ) +{ + BOOST_TEST( !( r < r_ ) && !( r_ < r ) ); + r_.reset(); +} + +class X: public boost::enable_shared_from_raw +{ +public: + + X() + { + register_( boost::weak_from_raw( this ) ); + } + + ~X() + { + unregister_( boost::weak_from_raw( this ) ); + } + + void check() + { + check_( boost::weak_from_raw( this ) ); + } +}; + +int main() +{ + { + boost::shared_ptr< X > px( new X ); + px->check(); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_raw_test5.cpp b/src/boost/libs/smart_ptr/test/weak_from_raw_test5.cpp new file mode 100644 index 00000000..5425c27a --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_raw_test5.cpp @@ -0,0 +1,45 @@ +// +// weak_from_raw_test5.cpp +// +// Tests whether pointers returned from weak_from_raw +// expire properly +// +// Copyright 2015 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 <boost/smart_ptr/enable_shared_from_raw.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X: public boost::enable_shared_from_raw +{ +public: + + explicit X( boost::weak_ptr< X > & r ) + { + r = boost::weak_from_raw( this ); + } +}; + +int main() +{ + boost::weak_ptr<X> p1, p2; + + { + boost::shared_ptr< X > px( new X( p1 ) ); + p2 = boost::weak_from_raw( px.get() ); + + BOOST_TEST( !p1.expired() ); + BOOST_TEST( !p2.expired() ); + } + + BOOST_TEST( p1.expired() ); + BOOST_TEST( p2.expired() ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_test.cpp b/src/boost/libs/smart_ptr/test/weak_from_test.cpp new file mode 100644 index 00000000..eda15588 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_test.cpp @@ -0,0 +1,97 @@ + +// weak_from_test.cpp +// +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/smart_ptr/enable_shared_from.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +// + +class X +{ +private: + + int m_; + +public: + + X(): m_() {} +}; + +class Y: public boost::enable_shared_from +{ +}; + +class Z: public X, public Y +{ +public: + + boost::weak_ptr<Z> weak_from_this() + { + return boost::weak_from( this ); + } +}; + +void null_deleter( void const* ) +{ +} + +int main() +{ + boost::shared_ptr<Z> sp( new Z ); + boost::weak_ptr<Z> p( sp ); + + { + boost::weak_ptr<Z> q = sp->weak_from_this(); + + BOOST_TEST_EQ( p.lock(), q.lock() ); + BOOST_TEST( !( p < q ) && !( q < p ) ); + } + + Z v2( *sp ); + + { + boost::weak_ptr<Z> q = v2.weak_from_this(); + BOOST_TEST( q.expired() ); + } + + *sp = Z(); + + { + boost::weak_ptr<Z> q = sp->weak_from_this(); + + BOOST_TEST_EQ( p.lock(), q.lock() ); + BOOST_TEST( !( p < q ) && !( q < p ) ); + } + + { + boost::shared_ptr<Z> sp2( sp.get(), null_deleter ); + } + + { + boost::weak_ptr<Z> q = sp->weak_from_this(); + + BOOST_TEST_EQ( p.lock(), q.lock() ); + BOOST_TEST( !( p < q ) && !( q < p ) ); + } + + { + boost::weak_ptr<Z> p2 = sp->weak_from_this(); + + BOOST_TEST( !p.expired() ); + BOOST_TEST( !p2.expired() ); + + sp.reset(); + + BOOST_TEST( p.expired() ); + BOOST_TEST( p2.expired() ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_test2.cpp b/src/boost/libs/smart_ptr/test/weak_from_test2.cpp new file mode 100644 index 00000000..19314a92 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_test2.cpp @@ -0,0 +1,57 @@ + +// weak_from_test2.cpp +// +// Tests weak_from in a destructor +// +// Copyright 2014, 2015, 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include <boost/smart_ptr/enable_shared_from.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X: public boost::enable_shared_from +{ +private: + + boost::weak_ptr<X> px_; + +public: + + X() + { + boost::weak_ptr<X> p1 = weak_from( this ); + BOOST_TEST( p1._empty() ); + BOOST_TEST( p1.expired() ); + } + + void check() + { + boost::weak_ptr<X> p2 = weak_from( this ); + BOOST_TEST( !p2.expired() ); + + BOOST_TEST( p2.lock().get() == this ); + + px_ = p2; + } + + ~X() + { + boost::weak_ptr<X> p3 = weak_from( this ); + BOOST_TEST( p3.expired() ); + + BOOST_TEST( !(px_ < p3) && !(p3 < px_) ); + } +}; + +int main() +{ + { + boost::shared_ptr< X > px( new X ); + px->check(); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_this_test.cpp b/src/boost/libs/smart_ptr/test/weak_from_this_test.cpp new file mode 100644 index 00000000..b090cbc0 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_this_test.cpp @@ -0,0 +1,52 @@ +#include <boost/config.hpp> + +// +// weak_from_this_test.cpp +// +// Copyright (c) 2002, 2003, 2015 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 <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> + +class V: public boost::enable_shared_from_this<V> +{ +}; + +void test() +{ + boost::shared_ptr<V> p( new V ); + + boost::weak_ptr<V> q = p; + BOOST_TEST( !q.expired() ); + + boost::weak_ptr<V> q2 = p->weak_from_this(); + BOOST_TEST( !q2.expired() ); + BOOST_TEST( !(q < q2) && !(q2 < q) ); + + V v2( *p ); + + boost::weak_ptr<V> q3 = v2.weak_from_this(); + BOOST_TEST( q3.expired() ); + + *p = V(); + + boost::weak_ptr<V> q4 = p->weak_from_this(); + BOOST_TEST( !q4.expired() ); + BOOST_TEST( !(q < q4) && !(q4 < q) ); + BOOST_TEST( !(q2 < q4) && !(q4 < q2) ); +} + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_from_this_test2.cpp b/src/boost/libs/smart_ptr/test/weak_from_this_test2.cpp new file mode 100644 index 00000000..05f3df2e --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_from_this_test2.cpp @@ -0,0 +1,60 @@ +// +// weak_from_this_test2.cpp +// +// Tests weak_from_this in a destructor +// +// Copyright (c) 2014, 2015 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 <boost/smart_ptr/enable_shared_from_this.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/core/lightweight_test.hpp> + +class X: public boost::enable_shared_from_this< X > +{ +private: + + boost::weak_ptr<X> px_; + +public: + + X() + { + boost::weak_ptr<X> p1 = weak_from_this(); + BOOST_TEST( p1._empty() ); + BOOST_TEST( p1.expired() ); + } + + void check() + { + boost::weak_ptr<X> p2 = weak_from_this(); + BOOST_TEST( !p2.expired() ); + + BOOST_TEST( p2.lock().get() == this ); + + px_ = p2; + } + + ~X() + { + boost::weak_ptr<X> p3 = weak_from_this(); + BOOST_TEST( p3.expired() ); + + BOOST_TEST( !(px_ < p3) && !(p3 < px_) ); + } +}; + +int main() +{ + { + boost::shared_ptr< X > px( new X ); + px->check(); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_ptr_alias_move_test.cpp b/src/boost/libs/smart_ptr/test/weak_ptr_alias_move_test.cpp new file mode 100644 index 00000000..57a71435 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_ptr_alias_move_test.cpp @@ -0,0 +1,97 @@ + +// weak_ptr_alias_move_test.cpp +// +// Copyright 2007, 2019 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 <boost/core/lightweight_test.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/config.hpp> +#include <memory> +#include <cstddef> + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +class incomplete; + +struct X +{ + int v_; + + explicit X( int v ): v_( v ) + { + } + + ~X() + { + v_ = 0; + } +}; + +template<class P1, class P2> bool share_ownership( P1 const& p1, P2 const& p2 ) +{ + return !p1.owner_before( p2 ) && !p2.owner_before( p1 ); +} + +int main() +{ + { + boost::shared_ptr<float> p( new float ); + boost::weak_ptr<float> p2( p ); + + int m2 = 0; + boost::weak_ptr<int const volatile> p3( std::move( p2 ), &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + + BOOST_TEST( p2.empty() ); + } + + { + boost::shared_ptr<incomplete> p; + boost::weak_ptr<incomplete> p2( p ); + + int m2 = 0; + boost::weak_ptr<int const volatile> p3( std::move( p2 ), &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + + BOOST_TEST( p2.empty() ); + } + + { + boost::shared_ptr<X> p( new X( 5 ) ); + boost::weak_ptr<X> p2( p ); + + boost::weak_ptr<int const volatile> p3( std::move( p2 ), &p2.lock()->v_ ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == &p->v_ ); + + BOOST_TEST( p2.empty() ); + + p.reset(); + BOOST_TEST( p3.expired() ); + } + + return boost::report_errors(); +} + +#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/weak_ptr_alias_test.cpp b/src/boost/libs/smart_ptr/test/weak_ptr_alias_test.cpp new file mode 100644 index 00000000..39dd30e1 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_ptr_alias_test.cpp @@ -0,0 +1,203 @@ + +// weak_ptr_alias_test.cpp +// +// Copyright 2007, 2019 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 <boost/core/lightweight_test.hpp> +#include <boost/weak_ptr.hpp> +#include <boost/shared_ptr.hpp> +#include <memory> +#include <cstddef> + +// + +class incomplete; + +struct X +{ + int v_; + + explicit X( int v ): v_( v ) + { + } + + ~X() + { + v_ = 0; + } +}; + +template<class P1, class P2> bool share_ownership( P1 const& p1, P2 const& p2 ) +{ + return !p1.owner_before( p2 ) && !p2.owner_before( p1 ); +} + +int main() +{ + { + boost::shared_ptr<double> p( new double ); + + float m = 0; + boost::weak_ptr<float> p2( p, &m ); + + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p2 ) ); + BOOST_TEST( p2.lock().get() == &m ); + + { + int m2 = 0; + boost::weak_ptr<int> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + + { + int m2 = 0; + boost::weak_ptr<int const> p3( p, &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + + { + int m2 = 0; + boost::weak_ptr<int volatile> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + + { + int m2 = 0; + boost::weak_ptr<void> p3( p, &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + + { + int m2 = 0; + boost::weak_ptr<void> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + + { + int m2 = 0; + boost::weak_ptr<void const volatile> p3( p, &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + + { + int m2 = 0; + boost::weak_ptr<void const volatile> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == &m2 ); + } + } + + { + boost::shared_ptr<incomplete> p; + + float m = 0; + boost::weak_ptr<float> p2( p, &m ); + + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p2 ) ); + + { + int m2 = 0; + boost::weak_ptr<int> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + + { + int m2 = 0; + boost::weak_ptr<int const> p3( p, &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + + { + int m2 = 0; + boost::weak_ptr<int volatile> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + + { + int m2 = 0; + boost::weak_ptr<void> p3( p, &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + + { + int m2 = 0; + boost::weak_ptr<void> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + + { + int m2 = 0; + boost::weak_ptr<void const volatile> p3( p, &m2 ); + + BOOST_TEST( p3.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + + { + int m2 = 0; + boost::weak_ptr<void const volatile> p3( p2, &m2 ); + + BOOST_TEST( p3.use_count() == p2.use_count() ); + BOOST_TEST( share_ownership( p2, p3 ) ); + BOOST_TEST( p3.lock().get() == 0 ); + } + } + + { + boost::shared_ptr<X> p( new X( 5 ) ); + + boost::weak_ptr<int const> p2( p, &p->v_ ); + + BOOST_TEST( p2.use_count() == p.use_count() ); + BOOST_TEST( share_ownership( p, p2 ) ); + BOOST_TEST( p2.lock().get() == &p->v_ ); + + p.reset(); + BOOST_TEST( p2.expired() ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/weak_ptr_move_test.cpp b/src/boost/libs/smart_ptr/test/weak_ptr_move_test.cpp new file mode 100644 index 00000000..dbf2629f --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_ptr_move_test.cpp @@ -0,0 +1,122 @@ +// +// weak_ptr_move_test.cpp +// +// Copyright (c) 2007 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 <boost/weak_ptr.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <utility> + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +struct X +{ + static long instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +long X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr<X> p_( new X ); + boost::weak_ptr<X> p( p_ ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.use_count() == 1 ); + + boost::weak_ptr<X> p2( std::move( p ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p2.use_count() == 1 ); + BOOST_TEST( p.expired() ); + + boost::weak_ptr<void> p3( std::move( p2 ) ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p3.use_count() == 1 ); + BOOST_TEST( p2.expired() ); + + p_.reset(); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( p3.expired() ); + } + + { + boost::shared_ptr<X> p_( new X ); + boost::weak_ptr<X> p( p_ ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.use_count() == 1 ); + + boost::weak_ptr<X> p2; + p2 = static_cast< boost::weak_ptr<X> && >( p ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p2.use_count() == 1 ); + BOOST_TEST( p.expired() ); + + boost::weak_ptr<void> p3; + p3 = std::move( p2 ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p3.use_count() == 1 ); + BOOST_TEST( p2.expired() ); + + p_.reset(); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( p3.expired() ); + } + + { + boost::shared_ptr<X> p_( new X ); + boost::weak_ptr<X> p( p_ ); + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( p.use_count() == 1 ); + + boost::shared_ptr<X> p_2( new X ); + boost::weak_ptr<X> p2( p_2 ); + BOOST_TEST( X::instances == 2 ); + p2 = std::move( p ); + BOOST_TEST( X::instances == 2 ); + BOOST_TEST( p2.use_count() == 1 ); + BOOST_TEST( p.expired() ); + BOOST_TEST( p2.lock() != p_2 ); + + boost::shared_ptr<void> p_3( new X ); + boost::weak_ptr<void> p3( p_3 ); + BOOST_TEST( X::instances == 3 ); + p3 = std::move( p2 ); + BOOST_TEST( X::instances == 3 ); + BOOST_TEST( p3.use_count() == 1 ); + BOOST_TEST( p2.expired() ); + BOOST_TEST( p3.lock() != p_3 ); + } + + return boost::report_errors(); +} + +#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/smart_ptr/test/weak_ptr_test.cpp b/src/boost/libs/smart_ptr/test/weak_ptr_test.cpp new file mode 100644 index 00000000..a4ad766d --- /dev/null +++ b/src/boost/libs/smart_ptr/test/weak_ptr_test.cpp @@ -0,0 +1,1365 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) + +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#pragma warning(disable: 4355) // 'this' : used in base member initializer list + +#if (BOOST_MSVC >= 1310) +#pragma warning(disable: 4675) // resolved overload found with Koenig lookup +#endif + +#endif + +// +// weak_ptr_test.cpp +// +// Copyright (c) 2002-2005 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 <boost/detail/lightweight_test.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + +#include <map> +#include <vector> + +// + +namespace n_element_type +{ + +void f(int &) +{ +} + +void test() +{ + typedef boost::weak_ptr<int>::element_type T; + T t; + f(t); +} + +} // namespace n_element_type + +class incomplete; + +boost::shared_ptr<incomplete> create_incomplete(); + +struct X +{ + int dummy; +}; + +struct Y +{ + int dummy2; +}; + +struct Z: public X, public virtual Y +{ +}; + +namespace n_constructors +{ + +void default_constructor() +{ + { + boost::weak_ptr<int> wp; + BOOST_TEST(wp.use_count() == 0); + } + + { + boost::weak_ptr<void> wp; + BOOST_TEST(wp.use_count() == 0); + } + + { + boost::weak_ptr<incomplete> wp; + BOOST_TEST(wp.use_count() == 0); + } +} + +void shared_ptr_constructor() +{ + { + boost::shared_ptr<int> sp; + + boost::weak_ptr<int> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + + boost::weak_ptr<void> wp2(sp); + BOOST_TEST(wp2.use_count() == sp.use_count()); + } + + { + boost::shared_ptr<int> sp(static_cast<int*>(0)); + + { + boost::weak_ptr<int> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<int> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + + { + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<void> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + } + + { + boost::shared_ptr<int> sp(new int); + + { + boost::weak_ptr<int> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<int> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + + { + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<void> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + } + + { + boost::shared_ptr<void> sp; + + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + } + + { + boost::shared_ptr<void> sp(static_cast<int*>(0)); + + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<void> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + + { + boost::shared_ptr<void> sp(new int); + + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<void> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + + { + boost::shared_ptr<incomplete> sp; + + boost::weak_ptr<incomplete> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + + boost::weak_ptr<void> wp2(sp); + BOOST_TEST(wp2.use_count() == sp.use_count()); + } + + { + boost::shared_ptr<incomplete> sp = create_incomplete(); + + { + boost::weak_ptr<incomplete> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<incomplete> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + + { + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<void> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } + } + + { + boost::shared_ptr<void> sp = create_incomplete(); + + boost::weak_ptr<void> wp(sp); + BOOST_TEST(wp.use_count() == sp.use_count()); + BOOST_TEST(wp.use_count() == 1); + boost::shared_ptr<void> sp2(wp); + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!(sp < sp2 || sp2 < sp)); + } +} + +void copy_constructor() +{ + { + boost::weak_ptr<int> wp; + boost::weak_ptr<int> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 0); + } + + { + boost::weak_ptr<void> wp; + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 0); + } + + { + boost::weak_ptr<incomplete> wp; + boost::weak_ptr<incomplete> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 0); + } + + { + boost::shared_ptr<int> sp(static_cast<int*>(0)); + boost::weak_ptr<int> wp(sp); + + boost::weak_ptr<int> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<int> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<int> sp(new int); + boost::weak_ptr<int> wp(sp); + + boost::weak_ptr<int> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<int> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<void> sp(static_cast<int*>(0)); + boost::weak_ptr<void> wp(sp); + + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<void> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<void> sp(new int); + boost::weak_ptr<void> wp(sp); + + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<void> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<incomplete> sp = create_incomplete(); + boost::weak_ptr<incomplete> wp(sp); + + boost::weak_ptr<incomplete> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<incomplete> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } +} + +void conversion_constructor() +{ + { + boost::weak_ptr<int> wp; + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 0); + } + + { + boost::weak_ptr<incomplete> wp; + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 0); + } + + { + boost::weak_ptr<Z> wp; + + boost::weak_ptr<X> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 0); + + boost::weak_ptr<Y> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + } + + { + boost::shared_ptr<int> sp(static_cast<int*>(0)); + boost::weak_ptr<int> wp(sp); + + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<void> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<int> sp(new int); + boost::weak_ptr<int> wp(sp); + + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<void> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<incomplete> sp = create_incomplete(); + boost::weak_ptr<incomplete> wp(sp); + + boost::weak_ptr<void> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<void> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<Z> sp(static_cast<Z*>(0)); + boost::weak_ptr<Z> wp(sp); + + boost::weak_ptr<X> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<X> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<Z> sp(static_cast<Z*>(0)); + boost::weak_ptr<Z> wp(sp); + + boost::weak_ptr<Y> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<Y> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<Z> sp(new Z); + boost::weak_ptr<Z> wp(sp); + + boost::weak_ptr<X> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<X> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } + + { + boost::shared_ptr<Z> sp(new Z); + boost::weak_ptr<Z> wp(sp); + + boost::weak_ptr<Y> wp2(wp); + BOOST_TEST(wp2.use_count() == wp.use_count()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + sp.reset(); + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + + boost::weak_ptr<Y> wp3(wp); + BOOST_TEST(wp3.use_count() == wp.use_count()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + } +} + +void test() +{ + default_constructor(); + shared_ptr_constructor(); + copy_constructor(); + conversion_constructor(); +} + +} // namespace n_constructors + +namespace n_assignment +{ + +template<class T> void copy_assignment(boost::shared_ptr<T> & sp) +{ + BOOST_TEST(sp.unique()); + + boost::weak_ptr<T> p1; + + p1 = p1; + BOOST_TEST(p1.use_count() == 0); + + boost::weak_ptr<T> p2; + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + + boost::weak_ptr<T> p3(p1); + + p1 = p3; + BOOST_TEST(p1.use_count() == 0); + + boost::weak_ptr<T> p4(sp); + + p4 = p4; + BOOST_TEST(p4.use_count() == 1); + + p1 = p4; + BOOST_TEST(p1.use_count() == 1); + + p4 = p2; + BOOST_TEST(p4.use_count() == 0); + + sp.reset(); + + p1 = p1; + BOOST_TEST(p1.use_count() == 0); + + p4 = p1; + BOOST_TEST(p4.use_count() == 0); +} + +void conversion_assignment() +{ + { + boost::weak_ptr<void> p1; + + boost::weak_ptr<incomplete> p2; + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + + boost::shared_ptr<incomplete> sp = create_incomplete(); + boost::weak_ptr<incomplete> p3(sp); + + p1 = p3; + BOOST_TEST(p1.use_count() == 1); + + sp.reset(); + + p1 = p3; + BOOST_TEST(p1.use_count() == 0); + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + } + + { + boost::weak_ptr<X> p1; + + boost::weak_ptr<Z> p2; + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + + boost::shared_ptr<Z> sp(new Z); + boost::weak_ptr<Z> p3(sp); + + p1 = p3; + BOOST_TEST(p1.use_count() == 1); + + sp.reset(); + + p1 = p3; + BOOST_TEST(p1.use_count() == 0); + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + } + + { + boost::weak_ptr<Y> p1; + + boost::weak_ptr<Z> p2; + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + + boost::shared_ptr<Z> sp(new Z); + boost::weak_ptr<Z> p3(sp); + + p1 = p3; + BOOST_TEST(p1.use_count() == 1); + + sp.reset(); + + p1 = p3; + BOOST_TEST(p1.use_count() == 0); + + p1 = p2; + BOOST_TEST(p1.use_count() == 0); + } +} + +template<class T, class U> void shared_ptr_assignment(boost::shared_ptr<U> & sp, T * = 0) +{ + BOOST_TEST(sp.unique()); + + boost::weak_ptr<T> p1; + boost::weak_ptr<T> p2(p1); + boost::weak_ptr<T> p3(sp); + boost::weak_ptr<T> p4(p3); + + p1 = sp; + BOOST_TEST(p1.use_count() == 1); + + p2 = sp; + BOOST_TEST(p2.use_count() == 1); + + p3 = sp; + BOOST_TEST(p3.use_count() == 1); + + p4 = sp; + BOOST_TEST(p4.use_count() == 1); + + sp.reset(); + + BOOST_TEST(p1.use_count() == 0); + BOOST_TEST(p2.use_count() == 0); + BOOST_TEST(p3.use_count() == 0); + BOOST_TEST(p4.use_count() == 0); + + p1 = sp; +} + +void test() +{ + { + boost::shared_ptr<int> p( new int ); + copy_assignment( p ); + } + + { + boost::shared_ptr<X> p( new X ); + copy_assignment( p ); + } + + { + boost::shared_ptr<void> p( new int ); + copy_assignment( p ); + } + + { + boost::shared_ptr<incomplete> p = create_incomplete(); + copy_assignment( p ); + } + + conversion_assignment(); + + { + boost::shared_ptr<int> p( new int ); + shared_ptr_assignment<int>( p ); + } + + { + boost::shared_ptr<int> p( new int ); + shared_ptr_assignment<void>( p ); + } + + { + boost::shared_ptr<X> p( new X ); + shared_ptr_assignment<X>( p ); + } + + { + boost::shared_ptr<X> p( new X ); + shared_ptr_assignment<void>( p ); + } + + { + boost::shared_ptr<void> p( new int ); + shared_ptr_assignment<void>( p ); + } + + { + boost::shared_ptr<incomplete> p = create_incomplete(); + shared_ptr_assignment<incomplete>( p ); + } + + { + boost::shared_ptr<incomplete> p = create_incomplete(); + shared_ptr_assignment<void>( p ); + } +} + +} // namespace n_assignment + +namespace n_reset +{ + +template<class T, class U> void test2( boost::shared_ptr<U> & sp, T * = 0 ) +{ + BOOST_TEST(sp.unique()); + + boost::weak_ptr<T> p1; + boost::weak_ptr<T> p2(p1); + boost::weak_ptr<T> p3(sp); + boost::weak_ptr<T> p4(p3); + boost::weak_ptr<T> p5(sp); + boost::weak_ptr<T> p6(p5); + + p1.reset(); + BOOST_TEST(p1.use_count() == 0); + + p2.reset(); + BOOST_TEST(p2.use_count() == 0); + + p3.reset(); + BOOST_TEST(p3.use_count() == 0); + + p4.reset(); + BOOST_TEST(p4.use_count() == 0); + + sp.reset(); + + p5.reset(); + BOOST_TEST(p5.use_count() == 0); + + p6.reset(); + BOOST_TEST(p6.use_count() == 0); +} + +void test() +{ + { + boost::shared_ptr<int> p( new int ); + test2<int>( p ); + } + + { + boost::shared_ptr<int> p( new int ); + test2<void>( p ); + } + + { + boost::shared_ptr<X> p( new X ); + test2<X>( p ); + } + + { + boost::shared_ptr<X> p( new X ); + test2<void>( p ); + } + + { + boost::shared_ptr<void> p( new int ); + test2<void>( p ); + } + + { + boost::shared_ptr<incomplete> p = create_incomplete(); + test2<incomplete>( p ); + } + + { + boost::shared_ptr<incomplete> p = create_incomplete(); + test2<void>( p ); + } +} + +} // namespace n_reset + +namespace n_use_count +{ + +void test() +{ + { + boost::weak_ptr<X> wp; + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp.expired()); + + boost::weak_ptr<X> wp2; + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp.expired()); + + boost::weak_ptr<X> wp3(wp); + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp.expired()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(wp3.expired()); + } + + { + boost::shared_ptr<X> sp(static_cast<X*>(0)); + + boost::weak_ptr<X> wp(sp); + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(!wp.expired()); + + boost::weak_ptr<X> wp2(sp); + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(!wp.expired()); + + boost::weak_ptr<X> wp3(wp); + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(!wp.expired()); + BOOST_TEST(wp3.use_count() == 1); + BOOST_TEST(!wp3.expired()); + + boost::shared_ptr<X> sp2(sp); + + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!wp.expired()); + BOOST_TEST(wp2.use_count() == 2); + BOOST_TEST(!wp2.expired()); + BOOST_TEST(wp3.use_count() == 2); + BOOST_TEST(!wp3.expired()); + + boost::shared_ptr<void> sp3(sp); + + BOOST_TEST(wp.use_count() == 3); + BOOST_TEST(!wp.expired()); + BOOST_TEST(wp2.use_count() == 3); + BOOST_TEST(!wp2.expired()); + BOOST_TEST(wp3.use_count() == 3); + BOOST_TEST(!wp3.expired()); + + sp.reset(); + + BOOST_TEST(wp.use_count() == 2); + BOOST_TEST(!wp.expired()); + BOOST_TEST(wp2.use_count() == 2); + BOOST_TEST(!wp2.expired()); + BOOST_TEST(wp3.use_count() == 2); + BOOST_TEST(!wp3.expired()); + + sp2.reset(); + + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(!wp.expired()); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!wp2.expired()); + BOOST_TEST(wp3.use_count() == 1); + BOOST_TEST(!wp3.expired()); + + sp3.reset(); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp.expired()); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(wp2.expired()); + BOOST_TEST(wp3.use_count() == 0); + BOOST_TEST(wp3.expired()); + } +} + +} // namespace n_use_count + +namespace n_swap +{ + +void test() +{ + { + boost::weak_ptr<X> wp; + boost::weak_ptr<X> wp2; + + wp.swap(wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); + + using std::swap; + swap(wp, wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); + } + + { + boost::shared_ptr<X> sp(new X); + boost::weak_ptr<X> wp; + boost::weak_ptr<X> wp2(sp); + boost::weak_ptr<X> wp3(sp); + + wp.swap(wp2); + + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + + using std::swap; + swap(wp, wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + + sp.reset(); + + wp.swap(wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + + swap(wp, wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + } + + { + boost::shared_ptr<X> sp(new X); + boost::shared_ptr<X> sp2(new X); + boost::weak_ptr<X> wp(sp); + boost::weak_ptr<X> wp2(sp2); + boost::weak_ptr<X> wp3(sp2); + + wp.swap(wp2); + + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + + using std::swap; + swap(wp, wp2); + + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + + sp.reset(); + + wp.swap(wp2); + + BOOST_TEST(wp.use_count() == 1); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + + swap(wp, wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 1); + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + + sp2.reset(); + + wp.swap(wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + + swap(wp, wp2); + + BOOST_TEST(wp.use_count() == 0); + BOOST_TEST(wp2.use_count() == 0); + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + } +} + +} // namespace n_swap + +namespace n_comparison +{ + +void test() +{ + { + boost::weak_ptr<X> wp; + BOOST_TEST(!(wp < wp)); + + boost::weak_ptr<X> wp2; + BOOST_TEST(!(wp < wp2 && wp2 < wp)); + + boost::weak_ptr<X> wp3(wp); + BOOST_TEST(!(wp3 < wp3)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + } + + { + boost::shared_ptr<X> sp(new X); + + boost::weak_ptr<X> wp(sp); + BOOST_TEST(!(wp < wp)); + + boost::weak_ptr<X> wp2; + BOOST_TEST(wp < wp2 || wp2 < wp); + BOOST_TEST(!(wp < wp2 && wp2 < wp)); + + bool b1 = wp < wp2; + bool b2 = wp2 < wp; + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(wp2 < wp3 || wp3 < wp2); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(wp4 < wp3 || wp3 < wp4); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + + sp.reset(); + + BOOST_TEST(b1 == (wp < wp2)); + BOOST_TEST(b2 == (wp2 < wp)); + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(wp2 < wp3 || wp3 < wp2); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(wp4 < wp3 || wp3 < wp4); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + } + + { + boost::shared_ptr<X> sp(new X); + boost::shared_ptr<X> sp2(new X); + + boost::weak_ptr<X> wp(sp); + boost::weak_ptr<X> wp2(sp2); + + BOOST_TEST(wp < wp2 || wp2 < wp); + BOOST_TEST(!(wp < wp2 && wp2 < wp)); + + bool b1 = wp < wp2; + bool b2 = wp2 < wp; + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(wp2 < wp3 || wp3 < wp2); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(wp4 < wp3 || wp3 < wp4); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + + sp.reset(); + + BOOST_TEST(b1 == (wp < wp2)); + BOOST_TEST(b2 == (wp2 < wp)); + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(wp2 < wp3 || wp3 < wp2); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(wp4 < wp3 || wp3 < wp4); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + + sp2.reset(); + + BOOST_TEST(b1 == (wp < wp2)); + BOOST_TEST(b2 == (wp2 < wp)); + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(wp2 < wp3 || wp3 < wp2); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(wp4 < wp3 || wp3 < wp4); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + } + + { + boost::shared_ptr<X> sp(new X); + boost::shared_ptr<X> sp2(sp); + + boost::weak_ptr<X> wp(sp); + boost::weak_ptr<X> wp2(sp2); + + BOOST_TEST(!(wp < wp2 || wp2 < wp)); + BOOST_TEST(!(wp < wp2 && wp2 < wp)); + + bool b1 = wp < wp2; + bool b2 = wp2 < wp; + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(!(wp4 < wp3 || wp3 < wp4)); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + + sp.reset(); + sp2.reset(); + + BOOST_TEST(b1 == (wp < wp2)); + BOOST_TEST(b2 == (wp2 < wp)); + + { + boost::weak_ptr<X> wp3(wp); + + BOOST_TEST(!(wp < wp3 || wp3 < wp)); + BOOST_TEST(!(wp < wp3 && wp3 < wp)); + + BOOST_TEST(!(wp2 < wp3 || wp3 < wp2)); + BOOST_TEST(!(wp2 < wp3 && wp3 < wp2)); + + boost::weak_ptr<X> wp4(wp2); + + BOOST_TEST(!(wp4 < wp3 || wp3 < wp4)); + BOOST_TEST(!(wp4 < wp3 && wp3 < wp4)); + } + } + + { + boost::shared_ptr<X> spx(new X); + boost::shared_ptr<Y> spy(new Y); + boost::shared_ptr<Z> spz(new Z); + + boost::weak_ptr<X> px(spx); + boost::weak_ptr<Y> py(spy); + boost::weak_ptr<Z> pz(spz); + + BOOST_TEST(px < py || py < px); + BOOST_TEST(px < pz || pz < px); + BOOST_TEST(py < pz || pz < py); + + BOOST_TEST(!(px < py && py < px)); + BOOST_TEST(!(px < pz && pz < px)); + BOOST_TEST(!(py < pz && pz < py)); + + boost::weak_ptr<void> pvx(px); + BOOST_TEST(!(pvx < pvx)); + + boost::weak_ptr<void> pvy(py); + BOOST_TEST(!(pvy < pvy)); + + boost::weak_ptr<void> pvz(pz); + BOOST_TEST(!(pvz < pvz)); + + BOOST_TEST(pvx < pvy || pvy < pvx); + BOOST_TEST(pvx < pvz || pvz < pvx); + BOOST_TEST(pvy < pvz || pvz < pvy); + + BOOST_TEST(!(pvx < pvy && pvy < pvx)); + BOOST_TEST(!(pvx < pvz && pvz < pvx)); + BOOST_TEST(!(pvy < pvz && pvz < pvy)); + + spx.reset(); + spy.reset(); + spz.reset(); + + BOOST_TEST(px < py || py < px); + BOOST_TEST(px < pz || pz < px); + BOOST_TEST(py < pz || pz < py); + + BOOST_TEST(!(px < py && py < px)); + BOOST_TEST(!(px < pz && pz < px)); + BOOST_TEST(!(py < pz && pz < py)); + + BOOST_TEST(!(pvx < pvx)); + BOOST_TEST(!(pvy < pvy)); + BOOST_TEST(!(pvz < pvz)); + + BOOST_TEST(pvx < pvy || pvy < pvx); + BOOST_TEST(pvx < pvz || pvz < pvx); + BOOST_TEST(pvy < pvz || pvz < pvy); + + BOOST_TEST(!(pvx < pvy && pvy < pvx)); + BOOST_TEST(!(pvx < pvz && pvz < pvx)); + BOOST_TEST(!(pvy < pvz && pvz < pvy)); + } + + { + boost::shared_ptr<Z> spz(new Z); + boost::shared_ptr<X> spx(spz); + + boost::weak_ptr<Z> pz(spz); + boost::weak_ptr<X> px(spx); + boost::weak_ptr<Y> py(spz); + + BOOST_TEST(!(px < px)); + BOOST_TEST(!(py < py)); + + BOOST_TEST(!(px < py || py < px)); + BOOST_TEST(!(px < pz || pz < px)); + BOOST_TEST(!(py < pz || pz < py)); + + boost::weak_ptr<void> pvx(px); + boost::weak_ptr<void> pvy(py); + boost::weak_ptr<void> pvz(pz); + + BOOST_TEST(!(pvx < pvy || pvy < pvx)); + BOOST_TEST(!(pvx < pvz || pvz < pvx)); + BOOST_TEST(!(pvy < pvz || pvz < pvy)); + + spx.reset(); + spz.reset(); + + BOOST_TEST(!(px < px)); + BOOST_TEST(!(py < py)); + + BOOST_TEST(!(px < py || py < px)); + BOOST_TEST(!(px < pz || pz < px)); + BOOST_TEST(!(py < pz || pz < py)); + + BOOST_TEST(!(pvx < pvy || pvy < pvx)); + BOOST_TEST(!(pvx < pvz || pvz < pvx)); + BOOST_TEST(!(pvy < pvz || pvz < pvy)); + } +} + +} // namespace n_comparison + +namespace n_lock +{ + +void test() +{ +} + +} // namespace n_lock + +namespace n_map +{ + +void test() +{ + std::vector< boost::shared_ptr<int> > vi; + + { + boost::shared_ptr<int> pi1(new int); + boost::shared_ptr<int> pi2(new int); + boost::shared_ptr<int> pi3(new int); + + vi.push_back(pi1); + vi.push_back(pi1); + vi.push_back(pi1); + vi.push_back(pi2); + vi.push_back(pi1); + vi.push_back(pi2); + vi.push_back(pi1); + vi.push_back(pi3); + vi.push_back(pi3); + vi.push_back(pi2); + vi.push_back(pi1); + } + + std::vector< boost::shared_ptr<X> > vx; + + { + boost::shared_ptr<X> px1(new X); + boost::shared_ptr<X> px2(new X); + boost::shared_ptr<X> px3(new X); + + vx.push_back(px2); + vx.push_back(px2); + vx.push_back(px1); + vx.push_back(px2); + vx.push_back(px1); + vx.push_back(px1); + vx.push_back(px1); + vx.push_back(px2); + vx.push_back(px1); + vx.push_back(px3); + vx.push_back(px2); + } + + std::map< boost::weak_ptr<void>, long > m; + + { + for(std::vector< boost::shared_ptr<int> >::iterator i = vi.begin(); i != vi.end(); ++i) + { + ++m[*i]; + } + } + + { + for(std::vector< boost::shared_ptr<X> >::iterator i = vx.begin(); i != vx.end(); ++i) + { + ++m[*i]; + } + } + + { + for(std::map< boost::weak_ptr<void>, long >::iterator i = m.begin(); i != m.end(); ++i) + { + BOOST_TEST(i->first.use_count() == i->second); + } + } +} + +} // namespace n_map + +int main() +{ + n_element_type::test(); + n_constructors::test(); + n_assignment::test(); + n_reset::test(); + n_use_count::test(); + n_swap::test(); + n_comparison::test(); + n_lock::test(); + + n_map::test(); + + return boost::report_errors(); +} + +class incomplete +{ +}; + +boost::shared_ptr<incomplete> create_incomplete() +{ + boost::shared_ptr<incomplete> px(new incomplete); + return px; +} diff --git a/src/boost/libs/smart_ptr/test/wp_convertible_test.cpp b/src/boost/libs/smart_ptr/test/wp_convertible_test.cpp new file mode 100644 index 00000000..cceacda2 --- /dev/null +++ b/src/boost/libs/smart_ptr/test/wp_convertible_test.cpp @@ -0,0 +1,68 @@ +#include <boost/config.hpp> + +// wp_convertible_test.cpp +// +// Copyright (c) 2008 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 <boost/detail/lightweight_test.hpp> +#include <boost/weak_ptr.hpp> + +// + +class incomplete; + +struct X +{ +}; + +struct Y +{ +}; + +struct Z: public X +{ +}; + +int f( boost::weak_ptr<void const> ) +{ + return 1; +} + +int f( boost::weak_ptr<int> ) +{ + return 2; +} + +int f( boost::weak_ptr<incomplete> ) +{ + return 3; +} + +int g( boost::weak_ptr<X> ) +{ + return 4; +} + +int g( boost::weak_ptr<Y> ) +{ + return 5; +} + +int g( boost::weak_ptr<incomplete> ) +{ + return 6; +} + +int main() +{ + BOOST_TEST( 1 == f( boost::weak_ptr<double>() ) ); + BOOST_TEST( 1 == f( boost::shared_ptr<double>() ) ); + BOOST_TEST( 4 == g( boost::weak_ptr<Z>() ) ); + BOOST_TEST( 4 == g( boost::shared_ptr<Z>() ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/smart_ptr/test/yield_k_test.cpp b/src/boost/libs/smart_ptr/test/yield_k_test.cpp new file mode 100644 index 00000000..593c13dc --- /dev/null +++ b/src/boost/libs/smart_ptr/test/yield_k_test.cpp @@ -0,0 +1,23 @@ +// +// yield_k_test.cpp +// +// Copyright 2008 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 <boost/smart_ptr/detail/yield_k.hpp> + +// Sanity check only + +int main() +{ + for( unsigned k = 0; k < 256; ++k ) + { + boost::detail::yield( k ); + } + + return 0; +} diff --git a/src/boost/libs/smart_ptr/test/yield_k_windows_h_test.cpp b/src/boost/libs/smart_ptr/test/yield_k_windows_h_test.cpp new file mode 100644 index 00000000..c2f88b8b --- /dev/null +++ b/src/boost/libs/smart_ptr/test/yield_k_windows_h_test.cpp @@ -0,0 +1,11 @@ +// Copyright 2018 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. + +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# include <windows.h> +# include <boost/smart_ptr/detail/yield_k.hpp> +#endif + +int main() +{ +} |