From 38b6334e36831092e42a1553a297aa7cec106bcf Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 9 Nov 2015 22:35:34 -0500 Subject: [PATCH] Update unit tests for make_shared/allocate_shared for arrays Before pending refactor of make_shared and allocate_shared for arrays. --- test/allocate_shared_array_construct_test.cpp | 111 ++++++------------ test/allocate_shared_array_esft_test.cpp | 26 ++-- test/allocate_shared_array_noinit_test.cpp | 48 ++------ test/allocate_shared_array_test.cpp | 48 ++------ test/allocate_shared_array_throws_test.cpp | 40 ++----- test/allocate_shared_array_value_test.cpp | 25 ++-- test/allocate_shared_arrays_test.cpp | 25 ++-- test/make_shared_array_esft_test.cpp | 26 ++-- test/make_shared_array_noinit_test.cpp | 48 ++------ test/make_shared_array_test.cpp | 48 ++------ test/make_shared_array_throws_test.cpp | 38 ++---- test/make_shared_array_value_test.cpp | 25 ++-- test/make_shared_arrays_test.cpp | 11 +- 13 files changed, 163 insertions(+), 356 deletions(-) diff --git a/test/allocate_shared_array_construct_test.cpp b/test/allocate_shared_array_construct_test.cpp index fe9fe3f..0228275 100644 --- a/test/allocate_shared_array_construct_test.cpp +++ b/test/allocate_shared_array_construct_test.cpp @@ -1,43 +1,38 @@ /* - * Copyright (c) 2012-2014 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 -#if !defined(BOOST_NO_CXX11_ALLOCATOR) -#include +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include + +struct tag { }; template class creator { public: typedef T value_type; - creator() { } - template creator(const creator&) { } - T* allocate(std::size_t size) { - void* p1 = ::operator new(size * sizeof(T)); - return static_cast(p1); + void* p = ::operator new(size * sizeof(T)); + return static_cast(p); } - void deallocate(T* memory, std::size_t) { - void* p1 = memory; - ::operator delete(p1); + void* p = memory; + ::operator delete(p); } - template void construct(U* memory) { - void* p1 = memory; - ::new(p1) U(); + void* p = memory; + ::new(p) U(tag()); } - template void destroy(U* memory) { memory->~U(); @@ -45,116 +40,88 @@ public: }; class type { - friend class creator; - public: static unsigned int instances; - static const type object; - -protected: - explicit type() { + explicit type(tag) { instances++; } - type(const type&) { instances++; } - ~type() { instances--; } }; -unsigned int type::instances; -const type type::object; +unsigned int type::instances = 0; -int main() { - BOOST_TEST(type::instances == 1); +int main() +{ +#if !defined(BOOST_NO_CXX11_ALLOCATOR) { boost::shared_ptr a1 = boost::allocate_shared(creator(), 3); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.get() != 0); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.get() != 0); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator(), 2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator(), 3); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator(), 2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - +#endif return boost::report_errors(); } -#else - -int main() { - return 0; -} - -#endif diff --git a/test/allocate_shared_array_esft_test.cpp b/test/allocate_shared_array_esft_test.cpp index b342366..30edfff 100644 --- a/test/allocate_shared_array_esft_test.cpp +++ b/test/allocate_shared_array_esft_test.cpp @@ -1,28 +1,25 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include #include +#include class type : public boost::enable_shared_from_this { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); @@ -41,7 +39,6 @@ int main() { BOOST_TEST(type::instances == 3); } } - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); @@ -52,6 +49,5 @@ int main() { BOOST_TEST(type::instances == 3); } } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_noinit_test.cpp b/test/allocate_shared_array_noinit_test.cpp index 6c8ff3d..83b48ec 100644 --- a/test/allocate_shared_array_noinit_test.cpp +++ b/test/allocate_shared_array_noinit_test.cpp @@ -1,28 +1,25 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include #include #include class type { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); int* a2 = a1.get(); @@ -38,7 +36,6 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); int* a2 = a1.get(); @@ -46,19 +43,16 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); const int* a2 = a1.get(); @@ -66,7 +60,6 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); const int* a2 = a1.get(); @@ -74,20 +67,16 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); type* a2 = a1.get(); @@ -99,8 +88,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); type* a2 = a1.get(); @@ -112,8 +99,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); BOOST_TEST(a1.get() != 0); @@ -122,8 +107,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); BOOST_TEST(a1.get() != 0); @@ -132,8 +115,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); const type* a2 = a1.get(); @@ -144,8 +125,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); const type* a2 = a1.get(); @@ -156,8 +135,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); BOOST_TEST(a1.get() != 0); @@ -166,8 +143,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); BOOST_TEST(a1.get() != 0); @@ -176,6 +151,5 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_test.cpp b/test/allocate_shared_array_test.cpp index 43715a7..c5a5714 100644 --- a/test/allocate_shared_array_test.cpp +++ b/test/allocate_shared_array_test.cpp @@ -1,28 +1,25 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include #include #include class type { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); int* a2 = a1.get(); @@ -41,7 +39,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); int* a2 = a1.get(); @@ -52,7 +49,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); BOOST_TEST(a1.get() != 0); @@ -62,7 +58,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); BOOST_TEST(a1.get() != 0); @@ -72,7 +67,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); const int* a2 = a1.get(); @@ -83,7 +77,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); const int* a2 = a1.get(); @@ -94,7 +87,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); BOOST_TEST(a1.get() != 0); @@ -104,7 +96,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); BOOST_TEST(a1.get() != 0); @@ -114,8 +105,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); type* a2 = a1.get(); @@ -127,8 +116,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); type* a2 = a1.get(); @@ -140,8 +127,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); BOOST_TEST(a1.get() != 0); @@ -150,8 +135,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); BOOST_TEST(a1.get() != 0); @@ -160,8 +143,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); const type* a2 = a1.get(); @@ -172,8 +153,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); const type* a2 = a1.get(); @@ -184,8 +163,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); BOOST_TEST(a1.get() != 0); @@ -194,8 +171,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); BOOST_TEST(a1.get() != 0); @@ -204,6 +179,5 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_throws_test.cpp b/test/allocate_shared_array_throws_test.cpp index 71a3ce9..e14d984 100644 --- a/test/allocate_shared_array_throws_test.cpp +++ b/test/allocate_shared_array_throws_test.cpp @@ -1,29 +1,26 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include class type { public: static unsigned int instances; - explicit type() { if (instances == 5) { throw true; } instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -31,70 +28,55 @@ private: unsigned int type::instances = 0; -int main() { - BOOST_TEST(type::instances == 0); +int main() +{ try { boost::allocate_shared(std::allocator(), 6); BOOST_ERROR("allocate_shared did not throw"); } 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); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator()); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator()); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator(), 6); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator(), 3); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator()); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator()); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_value_test.cpp b/test/allocate_shared_array_value_test.cpp index c1b8b7c..c6f08f9 100644 --- a/test/allocate_shared_array_value_test.cpp +++ b/test/allocate_shared_array_value_test.cpp @@ -1,15 +1,16 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + -int main() { +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include + +int main() +{ { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 4, 1); BOOST_TEST(a1[0] == 1); @@ -17,7 +18,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1); BOOST_TEST(a1[0] == 1); @@ -25,7 +25,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 4, 1); BOOST_TEST(a1[0] == 1); @@ -33,7 +32,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1); BOOST_TEST(a1[0] == 1); @@ -41,6 +39,5 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - return boost::report_errors(); } diff --git a/test/allocate_shared_arrays_test.cpp b/test/allocate_shared_arrays_test.cpp index 9dfc866..7c45e72 100644 --- a/test/allocate_shared_arrays_test.cpp +++ b/test/allocate_shared_arrays_test.cpp @@ -1,15 +1,16 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + -int main() { +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include + +int main() +{ #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, {0, 1}); @@ -18,7 +19,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -26,7 +26,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -34,7 +33,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -43,6 +41,5 @@ int main() { BOOST_TEST(a1[1][1] == 1); } #endif - return boost::report_errors(); } diff --git a/test/make_shared_array_esft_test.cpp b/test/make_shared_array_esft_test.cpp index a93f760..8429919 100644 --- a/test/make_shared_array_esft_test.cpp +++ b/test/make_shared_array_esft_test.cpp @@ -1,28 +1,25 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include #include -#include +#include class type : public boost::enable_shared_from_this { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(3); @@ -41,7 +39,6 @@ int main() { BOOST_TEST(type::instances == 3); } } - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(3); @@ -52,6 +49,5 @@ int main() { BOOST_TEST(type::instances == 3); } } - return boost::report_errors(); } diff --git a/test/make_shared_array_noinit_test.cpp b/test/make_shared_array_noinit_test.cpp index 98bd450..4942569 100644 --- a/test/make_shared_array_noinit_test.cpp +++ b/test/make_shared_array_noinit_test.cpp @@ -1,28 +1,25 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include #include #include class type { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::make_shared_noinit(3); int* a2 = a1.get(); @@ -38,7 +36,6 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::make_shared_noinit(); int* a2 = a1.get(); @@ -46,19 +43,16 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::make_shared_noinit(2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - { boost::shared_ptr a1 = boost::make_shared_noinit(); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - { boost::shared_ptr a1 = boost::make_shared_noinit(3); const int* a2 = a1.get(); @@ -66,7 +60,6 @@ int main() { 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(); @@ -74,20 +67,16 @@ int main() { BOOST_TEST(a2 != 0); BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); } - { boost::shared_ptr a1 = boost::make_shared_noinit(2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - { boost::shared_ptr a1 = boost::make_shared_noinit(); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(3); type* a2 = a1.get(); @@ -99,8 +88,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(); type* a2 = a1.get(); @@ -112,8 +99,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(2); BOOST_TEST(a1.get() != 0); @@ -122,8 +107,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(); BOOST_TEST(a1.get() != 0); @@ -132,8 +115,6 @@ int main() { 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(); @@ -144,8 +125,6 @@ int main() { 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(); @@ -156,8 +135,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(2); BOOST_TEST(a1.get() != 0); @@ -166,8 +143,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(); BOOST_TEST(a1.get() != 0); @@ -176,6 +151,5 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } diff --git a/test/make_shared_array_test.cpp b/test/make_shared_array_test.cpp index ebb76c7..de74198 100644 --- a/test/make_shared_array_test.cpp +++ b/test/make_shared_array_test.cpp @@ -1,28 +1,25 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include #include #include class type { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::make_shared(3); int* a2 = a1.get(); @@ -41,7 +39,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); int* a2 = a1.get(); @@ -52,7 +49,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(2); BOOST_TEST(a1.get() != 0); @@ -62,7 +58,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -72,7 +67,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::make_shared(3); const int* a2 = a1.get(); @@ -83,7 +77,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); const int* a2 = a1.get(); @@ -94,7 +87,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(2); BOOST_TEST(a1.get() != 0); @@ -104,7 +96,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -114,8 +105,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(3); type* a2 = a1.get(); @@ -127,8 +116,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); type* a2 = a1.get(); @@ -140,8 +127,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(2); BOOST_TEST(a1.get() != 0); @@ -150,8 +135,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -160,8 +143,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(3); const type* a2 = a1.get(); @@ -172,8 +153,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); const type* a2 = a1.get(); @@ -184,8 +163,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(2); BOOST_TEST(a1.get() != 0); @@ -194,8 +171,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -204,6 +179,5 @@ int main() { 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 151ab31..56c7372 100644 --- a/test/make_shared_array_throws_test.cpp +++ b/test/make_shared_array_throws_test.cpp @@ -1,29 +1,26 @@ /* - * Copyright (c) 2012-2014 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) - */ +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include -#include +#include class type { public: static unsigned int instances; - explicit type() { if (instances == 5) { throw true; } instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -31,70 +28,55 @@ private: unsigned int type::instances = 0; -int main() { - BOOST_TEST(type::instances == 0); +int main() +{ try { boost::make_shared(6); BOOST_ERROR("make_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { 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(); BOOST_ERROR("make_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared(); 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); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared_noinit(); BOOST_ERROR("make_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared_noinit(); BOOST_ERROR("make_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } diff --git a/test/make_shared_array_value_test.cpp b/test/make_shared_array_value_test.cpp index f042ede..185605d 100644 --- a/test/make_shared_array_value_test.cpp +++ b/test/make_shared_array_value_test.cpp @@ -1,15 +1,16 @@ /* - * Copyright (c) 2012-2014 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 +(c) 2012-2015 Glen Joseph Fernandes + -int main() { +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include + +int main() +{ { boost::shared_ptr a1 = boost::make_shared(4, 1); BOOST_TEST(a1[0] == 1); @@ -17,7 +18,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::make_shared(1); BOOST_TEST(a1[0] == 1); @@ -25,7 +25,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::make_shared(4, 1); BOOST_TEST(a1[0] == 1); @@ -33,7 +32,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::make_shared(1); BOOST_TEST(a1[0] == 1); @@ -41,6 +39,5 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - return boost::report_errors(); } diff --git a/test/make_shared_arrays_test.cpp b/test/make_shared_arrays_test.cpp index b905a83..6c02db7 100644 --- a/test/make_shared_arrays_test.cpp +++ b/test/make_shared_arrays_test.cpp @@ -6,10 +6,11 @@ * Version 1.0. (See accompanying file LICENSE_1_0.txt * or copy at http://boost.org/LICENSE_1_0.txt) */ -#include -#include +#include +#include -int main() { +int main() +{ #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { boost::shared_ptr a1 = boost::make_shared(2, {0, 1}); @@ -18,7 +19,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::make_shared({ 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -26,7 +26,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::make_shared(2, { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -34,7 +33,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::make_shared({ 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -43,6 +41,5 @@ int main() { BOOST_TEST(a1[1][1] == 1); } #endif - return boost::report_errors(); }