Update unit tests for make_shared/allocate_shared for arrays

Before pending refactor of make_shared and allocate_shared for arrays.
This commit is contained in:
Glen Fernandes
2015-11-09 22:35:34 -05:00
parent 7af503d3bb
commit 38b6334e36
13 changed files with 163 additions and 356 deletions

View File

@ -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 <boost/detail/lightweight_test.hpp>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
struct tag { };
template<typename T>
class creator {
public:
typedef T value_type;
creator() {
}
template<typename U>
creator(const creator<U>&) {
}
T* allocate(std::size_t size) {
void* p1 = ::operator new(size * sizeof(T));
return static_cast<T*>(p1);
void* p = ::operator new(size * sizeof(T));
return static_cast<T*>(p);
}
void deallocate(T* memory, std::size_t) {
void* p1 = memory;
::operator delete(p1);
void* p = memory;
::operator delete(p);
}
template<typename U>
void construct(U* memory) {
void* p1 = memory;
::new(p1) U();
void* p = memory;
::new(p) U(tag());
}
template<typename U>
void destroy(U* memory) {
memory->~U();
@ -45,116 +40,88 @@ public:
};
class type {
friend class creator<type>;
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<type[]> a1 = boost::allocate_shared<type[]>(creator<void>(), 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<type[3]> a1 = boost::allocate_shared<type[3]>(creator<void>());
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<type[][2]> a1 = boost::allocate_shared<type[][2]>(creator<void>(), 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<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(creator<void>());
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<const type[]> a1 = boost::allocate_shared<const type[]>(creator<void>(), 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<const type[3]> a1 = boost::allocate_shared<const type[3]>(creator<void>());
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<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(creator<void>(), 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<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(creator<void>());
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

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include <boost/smart_ptr/make_shared.hpp>
class type
: public boost::enable_shared_from_this<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_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
@ -41,7 +39,6 @@ int main() {
BOOST_TEST(type::instances == 3);
}
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
@ -52,6 +49,5 @@ int main() {
BOOST_TEST(type::instances == 3);
}
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
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<int[]> a1 = boost::allocate_shared_noinit<int[]>(std::allocator<int>(), 3);
int* a2 = a1.get();
@ -38,7 +36,6 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::allocate_shared_noinit<int[3]>(std::allocator<int>());
int* a2 = a1.get();
@ -46,19 +43,16 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared_noinit<int[][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared_noinit<int[2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[]> a1 = boost::allocate_shared_noinit<const int[]>(std::allocator<int>(), 3);
const int* a2 = a1.get();
@ -66,7 +60,6 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared_noinit<const int[3]>(std::allocator<int>());
const int* a2 = a1.get();
@ -74,20 +67,16 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared_noinit<const int[][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared_noinit<const int[2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 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<type[3]> a1 = boost::allocate_shared_noinit<type[3]>(std::allocator<type>());
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<type[][2]> a1 = boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 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<type[2][2]> a1 = boost::allocate_shared_noinit<type[2][2]>(std::allocator<type>());
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<const type[]> a1 = boost::allocate_shared_noinit<const type[]>(std::allocator<type>(), 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<const type[3]> a1 = boost::allocate_shared_noinit<const type[3]>(std::allocator<type>());
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<const type[][2]> a1 = boost::allocate_shared_noinit<const type[][2]>(std::allocator<type>(), 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<const type[2][2]> a1 = boost::allocate_shared_noinit<const type[2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
@ -176,6 +151,5 @@ int main() {
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
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<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 3);
int* a2 = a1.get();
@ -41,7 +39,6 @@ int main() {
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::allocate_shared<int[3]>(std::allocator<int>());
int* a2 = a1.get();
@ -52,7 +49,6 @@ int main() {
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 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<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>());
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<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 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<const int[3]> a1 = boost::allocate_shared<const int[3]>(std::allocator<int>());
const int* a2 = a1.get();
@ -94,7 +87,6 @@ int main() {
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 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<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>());
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<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 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<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>());
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<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 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<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>());
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<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 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<const type[3]> a1 = boost::allocate_shared<const type[3]>(std::allocator<type>());
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<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(std::allocator<type>(), 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<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
@ -204,6 +179,5 @@ int main() {
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
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<type[]>(std::allocator<type>(), 6);
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared<type[][2]>(std::allocator<type>(), 3);
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared<type[6]>(std::allocator<type>());
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared<type[3][2]>(std::allocator<type>());
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 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<type[][2]>(std::allocator<type>(), 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<type[6]>(std::allocator<type>());
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared_noinit<type[3][2]>(std::allocator<type>());
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
int main() {
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
int main()
{
{
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 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<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), 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<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 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<const int[4]> a1 = boost::allocate_shared<const int[4]>(std::allocator<int>(), 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();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
int main() {
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
int main()
{
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
@ -18,7 +19,6 @@ int main() {
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 1);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { 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<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 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<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>(), { 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();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
#include <boost/smart_ptr/make_shared.hpp>
class type
: public boost::enable_shared_from_this<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_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
@ -41,7 +39,6 @@ int main() {
BOOST_TEST(type::instances == 3);
}
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
@ -52,6 +49,5 @@ int main() {
BOOST_TEST(type::instances == 3);
}
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
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<int[]> a1 = boost::make_shared_noinit<int[]>(3);
int* a2 = a1.get();
@ -38,7 +36,6 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
int* a2 = a1.get();
@ -46,19 +43,16 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared_noinit<int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::make_shared_noinit<int[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
const int* a2 = a1.get();
@ -66,7 +60,6 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
const int* a2 = a1.get();
@ -74,20 +67,16 @@ int main() {
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::make_shared_noinit<const int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared_noinit<const int[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(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<type[3]> a1 = boost::make_shared_noinit<type[3]>();
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<type[][2]> a1 = boost::make_shared_noinit<type[][2]>(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<type[2][2]> a1 = boost::make_shared_noinit<type[2][2]>();
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<const type[]> a1 = boost::make_shared_noinit<const type[]>(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<const type[3]> a1 = boost::make_shared_noinit<const type[3]>();
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<const type[][2]> a1 = boost::make_shared_noinit<const type[][2]>(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<const type[2][2]> a1 = boost::make_shared_noinit<const type[2][2]>();
BOOST_TEST(a1.get() != 0);
@ -176,6 +151,5 @@ int main() {
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
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<int[]> a1 = boost::make_shared<int[]>(3);
int* a2 = a1.get();
@ -41,7 +39,6 @@ int main() {
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::make_shared<int[3]>();
int* a2 = a1.get();
@ -52,7 +49,6 @@ int main() {
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(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<int[2][2]> a1 = boost::make_shared<int[2][2]>();
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<const int[]> a1 = boost::make_shared<const int[]>(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<const int[3]> a1 = boost::make_shared<const int[3]>();
const int* a2 = a1.get();
@ -94,7 +87,6 @@ int main() {
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(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<const int[2][2]> a1 = boost::make_shared<const int[2][2]>();
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<type[]> a1 = boost::make_shared<type[]>(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<type[3]> a1 = boost::make_shared<type[3]>();
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<type[][2]> a1 = boost::make_shared<type[][2]>(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<type[2][2]> a1 = boost::make_shared<type[2][2]>();
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<const type[]> a1 = boost::make_shared<const type[]>(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<const type[3]> a1 = boost::make_shared<const type[3]>();
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<const type[][2]> a1 = boost::make_shared<const type[][2]>(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<const type[2][2]> a1 = boost::make_shared<const type[2][2]>();
BOOST_TEST(a1.get() != 0);
@ -204,6 +179,5 @@ int main() {
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -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
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
#include <boost/smart_ptr/make_shared.hpp>
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<type[]>(6);
BOOST_ERROR("make_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_shared<type[][2]>(3);
BOOST_ERROR("make_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_shared<type[6]>();
BOOST_ERROR("make_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_shared<type[3][2]>();
BOOST_ERROR("make_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_shared_noinit<type[]>(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<type[][2]>(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<type[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<type[3][2]>();
BOOST_ERROR("make_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
(c) 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
int main() {
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
int main()
{
{
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(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<int[4]> a1 = boost::make_shared<int[4]>(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<const int[]> a1 = boost::make_shared<const int[]>(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<const int[4]> a1 = boost::make_shared<const int[4]>(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();
}

View File

@ -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 <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
int main() {
int main()
{
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
@ -18,7 +19,6 @@ int main() {
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 1);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ 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<const int[][2]> a1 = boost::make_shared<const int[][2]>(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<const int[2][2]> a1 = boost::make_shared<const int[2][2]>({ 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();
}