From 324347b9ec5a96339d667e83857087e331d3465b Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 6 Mar 2017 01:18:16 -0500 Subject: [PATCH] Update unit tests for shared array functions --- test/allocate_shared_array_construct_test.cpp | 171 ++++++---- test/allocate_shared_array_esft_test.cpp | 71 +++- test/allocate_shared_array_noinit_test.cpp | 264 ++++++++++----- test/allocate_shared_array_test.cpp | 307 +++++++++++------- test/allocate_shared_array_throws_test.cpp | 75 ++++- test/allocate_shared_array_value_test.cpp | 90 +++-- test/allocate_shared_arrays_test.cpp | 101 ++++-- test/make_shared_array_esft_test.cpp | 32 +- test/make_shared_array_noinit_test.cpp | 220 ++++++++----- test/make_shared_array_test.cpp | 270 ++++++++------- test/make_shared_array_throws_test.cpp | 22 +- test/make_shared_array_value_test.cpp | 53 +-- test/make_shared_arrays_test.cpp | 62 ++-- 13 files changed, 1117 insertions(+), 621 deletions(-) diff --git a/test/allocate_shared_array_construct_test.cpp b/test/allocate_shared_array_construct_test.cpp index 0228275..669e813 100644 --- a/test/allocate_shared_array_construct_test.cpp +++ b/test/allocate_shared_array_construct_test.cpp @@ -1,127 +1,162 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include -struct tag { }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +struct allow { }; -template -class creator { -public: +template +struct creator { typedef T value_type; - creator() { - } - template - creator(const creator&) { - } + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + T* allocate(std::size_t size) { - void* p = ::operator new(size * sizeof(T)); - return static_cast(p); + return static_cast(::operator new(sizeof(T) * size)); } - void deallocate(T* memory, std::size_t) { - void* p = memory; - ::operator delete(p); + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); } - template - void construct(U* memory) { - void* p = memory; - ::new(p) U(tag()); + + template + void construct(U* ptr) { + ::new(static_cast(ptr)) U(allow()); } - template - void destroy(U* memory) { - memory->~U(); + + template + void destroy(U* ptr) { + ptr->~U(); } + }; +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + class type { public: - static unsigned int instances; - explicit type(tag) { - instances++; - } - type(const type&) { - instances++; + static unsigned instances; + + explicit type(allow) { + ++instances; } + ~type() { - instances--; + --instances; } + +private: + type(const type&); + type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; 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::shared_ptr result = + boost::allocate_shared(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator()); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1.get() != 0); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator(), 3); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(creator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); 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 30edfff..0399c1a 100644 --- a/test/allocate_shared_array_esft_test.cpp +++ b/test/allocate_shared_array_esft_test.cpp @@ -1,39 +1,79 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include #include -class type +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + +class type : public boost::enable_shared_from_this { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() { + ++instances; } + ~type() { - instances--; + --instances; } + private: type(const type&); type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); + boost::shared_ptr result = + boost::allocate_shared(creator(), 3); try { - a1[0].shared_from_this(); + result[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); } catch (...) { BOOST_TEST(type::instances == 3); @@ -41,9 +81,10 @@ int main() } BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); + boost::shared_ptr result = + boost::allocate_shared_noinit(creator(), 3); try { - a1[0].shared_from_this(); + result[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); } catch (...) { BOOST_TEST(type::instances == 3); diff --git a/test/allocate_shared_array_noinit_test.cpp b/test/allocate_shared_array_noinit_test.cpp index 83b48ec..f30ee17 100644 --- a/test/allocate_shared_array_noinit_test.cpp +++ b/test/allocate_shared_array_noinit_test.cpp @@ -1,154 +1,250 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ +#include #include #include #include #include +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + class type { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() + : value_(0.0) { + ++instances; } + ~type() { - instances--; + --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 int type::instances = 0; +unsigned type::instances = 0; int main() { { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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::shared_ptr result = + boost::allocate_shared_noinit(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - 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 result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - 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 result = + boost::allocate_shared_noinit(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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 result = + boost::allocate_shared_noinit(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - 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 result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - 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 result = + boost::allocate_shared_noinit(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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::shared_ptr result = + boost::allocate_shared_noinit(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - 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::shared_ptr result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 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 result = + boost::allocate_shared_noinit(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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::shared_ptr result = + boost::allocate_shared_noinit(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - 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::shared_ptr result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 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 result = + boost::allocate_shared_noinit(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared_noinit(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.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 c5a5714..0369631 100644 --- a/test/allocate_shared_array_test.cpp +++ b/test/allocate_shared_array_test.cpp @@ -1,182 +1,265 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ +#include #include #include #include #include +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + class type { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() + : value_(0.0) { + ++instances; } + ~type() { - instances--; + --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 int type::instances = 0; +unsigned type::instances = 0; int main() { { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - 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(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::allocate_shared(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::allocate_shared(std::allocator(), 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_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - 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_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::allocate_shared(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::allocate_shared(std::allocator(), 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::shared_ptr result = + boost::allocate_shared(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr w1 = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - 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::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr w1 = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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::shared_ptr result = + boost::allocate_shared(creator(), 3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - 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::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator(), 2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::allocate_shared(creator()); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.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 e14d984..9857d18 100644 --- a/test/allocate_shared_array_throws_test.cpp +++ b/test/allocate_shared_array_throws_test.cpp @@ -1,79 +1,118 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + class type { public: - static unsigned int instances; - explicit type() { + static unsigned instances; + + type() { if (instances == 5) { throw true; } - instances++; + ++instances; } + ~type() { - instances--; + --instances; } + private: type(const type&); type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { try { - boost::allocate_shared(std::allocator(), 6); + boost::allocate_shared(creator(), 6); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared(std::allocator(), 3); + boost::allocate_shared(creator(), 3); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared(std::allocator()); + boost::allocate_shared(creator()); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared(std::allocator()); + boost::allocate_shared(creator()); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared_noinit(std::allocator(), 6); + boost::allocate_shared_noinit(creator(), 6); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared_noinit(std::allocator(), 3); + boost::allocate_shared_noinit(creator(), 3); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared_noinit(std::allocator()); + boost::allocate_shared_noinit(creator()); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } try { - boost::allocate_shared_noinit(std::allocator()); + boost::allocate_shared_noinit(creator()); BOOST_ERROR("allocate_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); diff --git a/test/allocate_shared_array_value_test.cpp b/test/allocate_shared_array_value_test.cpp index c6f08f9..485c477 100644 --- a/test/allocate_shared_array_value_test.cpp +++ b/test/allocate_shared_array_value_test.cpp @@ -1,43 +1,83 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + int main() { { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 4, 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::allocate_shared(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 a1 = boost::allocate_shared(std::allocator(), 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::allocate_shared(creator(), 1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 4, 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::allocate_shared(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 a1 = boost::allocate_shared(std::allocator(), 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::allocate_shared(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/test/allocate_shared_arrays_test.cpp b/test/allocate_shared_arrays_test.cpp index 7c45e72..a088a22 100644 --- a/test/allocate_shared_arrays_test.cpp +++ b/test/allocate_shared_arrays_test.cpp @@ -1,45 +1,92 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + int main() { -#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, {0, 1}); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::allocate_shared(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 a1 = boost::allocate_shared(std::allocator(), { 0, 1 }); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::allocate_shared(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); } { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, { 0, 1 }); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::allocate_shared(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 a1 = boost::allocate_shared(std::allocator(), { 0, 1 }); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::allocate_shared(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); } -#endif return boost::report_errors(); } +#else +int main() +{ + return 0; +} +#endif diff --git a/test/make_shared_array_esft_test.cpp b/test/make_shared_array_esft_test.cpp index 8429919..f52e3cf 100644 --- a/test/make_shared_array_esft_test.cpp +++ b/test/make_shared_array_esft_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include @@ -13,27 +12,31 @@ http://boost.org/LICENSE_1_0.txt class type : public boost::enable_shared_from_this { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() { + ++instances; } + ~type() { - instances--; + --instances; } + private: type(const type&); type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::make_shared(3); + boost::shared_ptr result = + boost::make_shared(3); try { - a1[0].shared_from_this(); + result[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); } catch (...) { BOOST_TEST(type::instances == 3); @@ -41,9 +44,10 @@ int main() } BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::make_shared_noinit(3); + boost::shared_ptr result = + boost::make_shared_noinit(); try { - a1[0].shared_from_this(); + result[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); } catch (...) { BOOST_TEST(type::instances == 3); diff --git a/test/make_shared_array_noinit_test.cpp b/test/make_shared_array_noinit_test.cpp index 4942569..757e798 100644 --- a/test/make_shared_array_noinit_test.cpp +++ b/test/make_shared_array_noinit_test.cpp @@ -1,11 +1,11 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ +#include #include #include #include @@ -13,142 +13,194 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() + : value_(0.0) { + ++instances; } + ~type() { - instances--; + --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 int type::instances = 0; +unsigned type::instances = 0; 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::shared_ptr result = + boost::make_shared_noinit(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - 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 result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::make_shared_noinit(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::make_shared_noinit(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - 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 result = + boost::make_shared_noinit(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - 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); + boost::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::make_shared_noinit(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - boost::shared_ptr a1 = boost::make_shared_noinit(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); } { - 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::shared_ptr result = + boost::make_shared_noinit(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - 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::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared_noinit(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared_noinit(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); 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::shared_ptr result = + boost::make_shared_noinit(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); 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::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared_noinit(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared_noinit(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared_noinit(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + boost::weak_ptr other = result; + result.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 de74198..c6bac24 100644 --- a/test/make_shared_array_test.cpp +++ b/test/make_shared_array_test.cpp @@ -1,11 +1,11 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ +#include #include #include #include @@ -13,170 +13,216 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() + : value_(0.0) { + ++instances; } + ~type() { - instances--; + --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 int type::instances = 0; +unsigned type::instances = 0; int main() { { - boost::shared_ptr a1 = boost::make_shared(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(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::make_shared(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::make_shared(); - 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(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::make_shared(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::make_shared(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::make_shared(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::make_shared(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_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::make_shared(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::make_shared(); - 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_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + boost::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } { - boost::shared_ptr a1 = boost::make_shared(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::make_shared(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::make_shared(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + boost::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::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 a1 = boost::make_shared(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::shared_ptr result = + boost::make_shared(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr w1 = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(); - 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::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); + boost::weak_ptr w1 = result; + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(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::shared_ptr result = + boost::make_shared(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(); - 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::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } { - boost::shared_ptr a1 = boost::make_shared(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); + boost::shared_ptr result = + boost::make_shared(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result.use_count() == 1); + BOOST_TEST(boost::alignment::is_aligned(result.get(), + boost::alignment_of::value)); BOOST_TEST(type::instances == 4); - a1.reset(); + result.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 56c7372..a754360 100644 --- a/test/make_shared_array_throws_test.cpp +++ b/test/make_shared_array_throws_test.cpp @@ -1,32 +1,34 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include class type { public: - static unsigned int instances; - explicit type() { + static unsigned instances; + + type() { if (instances == 5) { throw true; } - instances++; + ++instances; } + ~type() { - instances--; + --instances; } + private: type(const type&); type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { diff --git a/test/make_shared_array_value_test.cpp b/test/make_shared_array_value_test.cpp index 185605d..44d12d3 100644 --- a/test/make_shared_array_value_test.cpp +++ b/test/make_shared_array_value_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include @@ -12,32 +11,36 @@ http://boost.org/LICENSE_1_0.txt int main() { { - boost::shared_ptr a1 = boost::make_shared(4, 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::make_shared(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 a1 = boost::make_shared(1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::make_shared(1); + BOOST_TEST(result[0] == 1); + BOOST_TEST(result[1] == 1); + BOOST_TEST(result[2] == 1); + BOOST_TEST(result[3] == 1); } { - boost::shared_ptr a1 = boost::make_shared(4, 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::make_shared(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 a1 = boost::make_shared(1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); + boost::shared_ptr result = + boost::make_shared(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/test/make_shared_arrays_test.cpp b/test/make_shared_arrays_test.cpp index 7cd067f..0022e01 100644 --- a/test/make_shared_arrays_test.cpp +++ b/test/make_shared_arrays_test.cpp @@ -1,45 +1,53 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) int main() { -#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { - boost::shared_ptr a1 = boost::make_shared(2, {0, 1}); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::make_shared(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 a1 = boost::make_shared({ 0, 1 }); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::make_shared({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 a1 = boost::make_shared(2, { 0, 1 }); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::make_shared(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 a1 = boost::make_shared({ 0, 1 }); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 1); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 1); + boost::shared_ptr result = + boost::make_shared({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); } -#endif return boost::report_errors(); } +#else +int main() +{ + return 0; +} +#endif