forked from boostorg/smart_ptr
Add tests for variadic template constructors overload of array forms of make_shared and allocate_shared for multidimensional arrays and up to 9 constructor arguments.
[SVN r81242]
This commit is contained in:
@ -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 ]
|
||||
;
|
||||
|
78
test/allocate_shared_array_create_test.cpp
Normal file
78
test/allocate_shared_array_create_test.cpp
Normal file
@ -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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
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<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 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<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 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<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 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<type[][2][2][2]> a1 = boost::allocate_shared<type[][2][2][2]>(std::allocator<type>(), 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();
|
||||
}
|
78
test/make_shared_array_create_test.cpp
Normal file
78
test/make_shared_array_create_test.cpp
Normal file
@ -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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
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<type[]> a1 = boost::make_shared<type[]>(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<type[][2]> a1 = boost::make_shared<type[][2]>(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<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(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<type[][2][2][2]> a1 = boost::make_shared<type[][2][2][2]>(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();
|
||||
}
|
Reference in New Issue
Block a user