diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 8d22562..ef64f89 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -129,14 +129,16 @@ import testing ; [ compile-fail array_fail_dereference.cpp ] [ compile-fail array_fail_member_access.cpp ] [ compile-fail array_fail_array_access.cpp ] - + [ run make_shared_array_test.cpp ] [ run make_shared_arrays_test.cpp ] + [ run make_shared_array_create_test.cpp ] [ run make_shared_array_throws_test.cpp ] [ run make_shared_array_esft_test.cpp ] [ run make_shared_array_args_test.cpp ] [ run allocate_shared_array_test.cpp ] - [ run allocate_shared_arrays_test.cpp ] + [ run allocate_shared_arrays_test.cpp ] + [ run allocate_shared_array_create_test.cpp ] [ run allocate_shared_array_throws_test.cpp ] [ run allocate_shared_array_esft_test.cpp ] ; diff --git a/test/allocate_shared_array_create_test.cpp b/test/allocate_shared_array_create_test.cpp new file mode 100644 index 0000000..4b45518 --- /dev/null +++ b/test/allocate_shared_array_create_test.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012 Glen Joseph Fernandes + * glenfe at live dot com + * + * Distributed under the Boost Software License, + * Version 1.0. (See accompanying file LICENSE_1_0.txt + * or copy at http://boost.org/LICENSE_1_0.txt) + */ +#include +#include + +class type { +public: + static int instances; + explicit type(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0, int g=0, int h=0, int i=0) + : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i) { + instances++; + } + ~type() { + instances--; + } + const int a; + const int b; + const int c; + const int d; + const int e; + const int f; + const int g; + const int h; + const int i; +private: + type(const type&); + type& operator=(const type&); +}; + +int type::instances = 0; + +int main() { +#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS) + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, 1, 2, 3, 4, 5, 6, 7, 8, 9); + BOOST_TEST(type::instances == 2); + BOOST_TEST(a1[0].a == 1); + BOOST_TEST(a1[0].d == 4); + BOOST_TEST(a1[1].f == 6); + BOOST_TEST(a1[1].i == 9); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, 1, 2, 3, 4, 5, 6, 7); + BOOST_TEST(type::instances == 4); + BOOST_TEST(a1[0][0].a == 1); + BOOST_TEST(a1[0][1].d == 4); + BOOST_TEST(a1[1][0].f == 6); + BOOST_TEST(a1[1][1].i == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, 1, 2, 3, 4, 5); + BOOST_TEST(type::instances == 8); + BOOST_TEST(a1[0][0][0].a == 1); + BOOST_TEST(a1[0][1][0].c == 3); + BOOST_TEST(a1[1][0][1].e == 5); + BOOST_TEST(a1[1][1][1].i == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, 1, 2, 3); + BOOST_TEST(type::instances == 16); + BOOST_TEST(a1[0][0][0][1].a == 1); + BOOST_TEST(a1[0][0][1][0].c == 3); + BOOST_TEST(a1[0][1][0][0].f == 0); + BOOST_TEST(a1[1][0][0][0].i == 0); + } +#endif + return boost::report_errors(); +} diff --git a/test/make_shared_array_create_test.cpp b/test/make_shared_array_create_test.cpp new file mode 100644 index 0000000..6d1ef71 --- /dev/null +++ b/test/make_shared_array_create_test.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012 Glen Joseph Fernandes + * glenfe at live dot com + * + * Distributed under the Boost Software License, + * Version 1.0. (See accompanying file LICENSE_1_0.txt + * or copy at http://boost.org/LICENSE_1_0.txt) + */ +#include +#include + +class type { +public: + static int instances; + explicit type(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0, int g=0, int h=0, int i=0) + : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i) { + instances++; + } + ~type() { + instances--; + } + const int a; + const int b; + const int c; + const int d; + const int e; + const int f; + const int g; + const int h; + const int i; +private: + type(const type&); + type& operator=(const type&); +}; + +int type::instances = 0; + +int main() { +#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS) + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(2, 1, 2, 3, 4, 5, 6, 7, 8, 9); + BOOST_TEST(type::instances == 2); + BOOST_TEST(a1[0].a == 1); + BOOST_TEST(a1[0].d == 4); + BOOST_TEST(a1[1].f == 6); + BOOST_TEST(a1[1].i == 9); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(2, 1, 2, 3, 4, 5, 6, 7); + BOOST_TEST(type::instances == 4); + BOOST_TEST(a1[0][0].a == 1); + BOOST_TEST(a1[0][1].d == 4); + BOOST_TEST(a1[1][0].f == 6); + BOOST_TEST(a1[1][1].i == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(2, 1, 2, 3, 4, 5); + BOOST_TEST(type::instances == 8); + BOOST_TEST(a1[0][0][0].a == 1); + BOOST_TEST(a1[0][1][0].c == 3); + BOOST_TEST(a1[1][0][1].e == 5); + BOOST_TEST(a1[1][1][1].i == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(2, 1, 2, 3); + BOOST_TEST(type::instances == 16); + BOOST_TEST(a1[0][0][0][1].a == 1); + BOOST_TEST(a1[0][0][1][0].c == 3); + BOOST_TEST(a1[0][1][0][0].f == 0); + BOOST_TEST(a1[1][0][0][0].i == 0); + } +#endif + return boost::report_errors(); +}