diff --git a/test/allocate_shared_array_create_test.cpp b/test/allocate_shared_array_create_test.cpp index 3c18844..2e03be6 100644 --- a/test/allocate_shared_array_create_test.cpp +++ b/test/allocate_shared_array_create_test.cpp @@ -109,22 +109,6 @@ int main() { BOOST_TEST(a1[0][1][0][0].f == 0); BOOST_TEST(a1[1][0][0][0].i == 0); } -#endif -#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 2); - BOOST_TEST(a1[3] == 3); - } - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 2); - BOOST_TEST(a1[3] == 3); - } #endif return boost::report_errors(); } diff --git a/test/allocate_shared_array_esft_test.cpp b/test/allocate_shared_array_esft_test.cpp index 3864b81..2315421 100644 --- a/test/allocate_shared_array_esft_test.cpp +++ b/test/allocate_shared_array_esft_test.cpp @@ -34,7 +34,7 @@ int main() { try { a1[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); - } catch (const boost::bad_weak_ptr&) { + } catch (...) { BOOST_TEST(type::instances == 3); } } diff --git a/test/allocate_shared_array_init_test.cpp b/test/allocate_shared_array_init_test.cpp new file mode 100644 index 0000000..6411aa8 --- /dev/null +++ b/test/allocate_shared_array_init_test.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2012 Glen Joseph Fernandes + * glenfe at live dot com + * + * Distributed under the Boost Software License, + * Version 1.0. (See accompanying file LICENSE_1_0.txt + * or copy at http://boost.org/LICENSE_1_0.txt) + */ +#include +#include + +class type { +public: + type(int value) + : value(value) { + } + const int value; +private: + type& operator=(const type&); +}; + +int main() { +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } +#endif + return boost::report_errors(); +} diff --git a/test/allocate_shared_array_test.cpp b/test/allocate_shared_array_test.cpp index db2cffc..91f3fb5 100644 --- a/test/allocate_shared_array_test.cpp +++ b/test/allocate_shared_array_test.cpp @@ -70,15 +70,53 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); } #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS) BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3, 1, 5); type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1, 5); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3, 1, 5); + const type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1, 5); + const type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); a1.reset(); BOOST_TEST(type::instances == 0); } diff --git a/test/allocate_shared_array_throws_test.cpp b/test/allocate_shared_array_throws_test.cpp index e787000..d52104c 100644 --- a/test/allocate_shared_array_throws_test.cpp +++ b/test/allocate_shared_array_throws_test.cpp @@ -36,5 +36,12 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } + BOOST_TEST(type::instances == 0); + try { + boost::allocate_shared(std::allocator(), 3); + BOOST_ERROR("allocate_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } return boost::report_errors(); } diff --git a/test/allocate_shared_arrays_test.cpp b/test/allocate_shared_arrays_test.cpp index 5bb48e5..ab22c23 100644 --- a/test/allocate_shared_arrays_test.cpp +++ b/test/allocate_shared_arrays_test.cpp @@ -59,6 +59,8 @@ int main() { BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); } #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS) BOOST_TEST(type::instances == 0); @@ -70,6 +72,33 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1, 5); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, 1, 5); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1, 5); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); + } #endif return boost::report_errors(); } diff --git a/test/make_shared_array_create_test.cpp b/test/make_shared_array_create_test.cpp index 1c6ca08..46db862 100644 --- a/test/make_shared_array_create_test.cpp +++ b/test/make_shared_array_create_test.cpp @@ -109,22 +109,6 @@ int main() { BOOST_TEST(a1[0][1][0][0].f == 0); BOOST_TEST(a1[1][0][0][0].i == 0); } -#endif -#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - { - boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 2); - BOOST_TEST(a1[3] == 3); - } - { - boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 2); - BOOST_TEST(a1[3] == 3); - } #endif return boost::report_errors(); } diff --git a/test/make_shared_array_esft_test.cpp b/test/make_shared_array_esft_test.cpp index 3431f23..9d0adb1 100644 --- a/test/make_shared_array_esft_test.cpp +++ b/test/make_shared_array_esft_test.cpp @@ -34,7 +34,7 @@ int main() { try { a1[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); - } catch (const boost::bad_weak_ptr&) { + } catch (...) { BOOST_TEST(type::instances == 3); } } @@ -44,7 +44,7 @@ int main() { try { a1[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); - } catch (const boost::bad_weak_ptr&) { + } catch (...) { BOOST_TEST(type::instances == 3); } } diff --git a/test/make_shared_array_init_test.cpp b/test/make_shared_array_init_test.cpp new file mode 100644 index 0000000..6a4c5d5 --- /dev/null +++ b/test/make_shared_array_init_test.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2012 Glen Joseph Fernandes + * glenfe at live dot com + * + * Distributed under the Boost Software License, + * Version 1.0. (See accompanying file LICENSE_1_0.txt + * or copy at http://boost.org/LICENSE_1_0.txt) + */ +#include +#include + +class type { +public: + type(int value) + : value(value) { + } + const int value; +private: + type& operator=(const type&); +}; + +int main() { +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0].value == 0); + BOOST_TEST(a1[1].value == 1); + BOOST_TEST(a1[2].value == 2); + BOOST_TEST(a1[3].value == 3); + } +#endif + return boost::report_errors(); +} diff --git a/test/make_shared_array_test.cpp b/test/make_shared_array_test.cpp index 6fe2c24..d9b9134 100644 --- a/test/make_shared_array_test.cpp +++ b/test/make_shared_array_test.cpp @@ -70,15 +70,53 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); } #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS) BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(3, 1, 5); type* a2 = a1.get(); - BOOST_TEST(type::instances == 3); + BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(1, 5); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(3, 1, 5); + const type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(1, 5); + const type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); a1.reset(); BOOST_TEST(type::instances == 0); } @@ -86,12 +124,28 @@ int main() { { boost::shared_ptr a1 = boost::make_shared_noinit(3); int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } { boost::shared_ptr a1 = boost::make_shared_noinit(3); const int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + const int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } @@ -99,6 +153,7 @@ int main() { { boost::shared_ptr a1 = boost::make_shared_noinit(3); type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); BOOST_TEST(type::instances == 3); @@ -108,11 +163,37 @@ int main() { } BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::make_shared_noinit(3); - const type* a2 = a1.get(); + boost::shared_ptr a1 = boost::make_shared_noinit(); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared_noinit(3); + const type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + const type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); } return boost::report_errors(); } diff --git a/test/make_shared_array_throws_test.cpp b/test/make_shared_array_throws_test.cpp index 2bac909..7e06d41 100644 --- a/test/make_shared_array_throws_test.cpp +++ b/test/make_shared_array_throws_test.cpp @@ -38,7 +38,21 @@ int main() { } BOOST_TEST(type::instances == 0); try { - boost::shared_ptr a1 = boost::make_shared_noinit(6); + boost::make_shared(3); + BOOST_ERROR("make_shared did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + try { + boost::make_shared_noinit(6); + BOOST_ERROR("make_shared_noinit did not throw"); + } catch (...) { + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + try { + boost::make_shared_noinit(3); BOOST_ERROR("make_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); diff --git a/test/make_shared_arrays_test.cpp b/test/make_shared_arrays_test.cpp index e4c3d48..eb79d4f 100644 --- a/test/make_shared_arrays_test.cpp +++ b/test/make_shared_arrays_test.cpp @@ -59,6 +59,8 @@ int main() { BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); } #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS) BOOST_TEST(type::instances == 0); @@ -70,6 +72,33 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(1, 5); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(2, 1, 5); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(1, 5); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); + } #endif { boost::shared_ptr a1 = boost::make_shared_noinit(2); @@ -115,6 +144,8 @@ int main() { BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); } BOOST_TEST(type::instances == 0); { @@ -122,6 +153,8 @@ int main() { BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(type::instances == 8); + a1.reset(); + BOOST_TEST(type::instances == 0); } return boost::report_errors(); }