Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81226 - trunk/libs/smart_ptr/test
From: pdimov_at_[hidden]
Date: 2012-11-06 12:31:16


Author: pdimov
Date: 2012-11-06 12:31:15 EST (Tue, 06 Nov 2012)
New Revision: 81226
URL: http://svn.boost.org/trac/boost/changeset/81226

Log:
Add make_shared_array_args_test.cpp.
Added:
   trunk/libs/smart_ptr/test/make_shared_array_args_test.cpp (contents, props changed)
Text files modified:
   trunk/libs/smart_ptr/test/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: trunk/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- trunk/libs/smart_ptr/test/Jamfile.v2 (original)
+++ trunk/libs/smart_ptr/test/Jamfile.v2 2012-11-06 12:31:15 EST (Tue, 06 Nov 2012)
@@ -132,6 +132,7 @@
           [ run make_shared_array_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_array_throws_test.cpp ]
           [ run allocate_shared_array_esft_test.cpp ]

Added: trunk/libs/smart_ptr/test/make_shared_array_args_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/smart_ptr/test/make_shared_array_args_test.cpp 2012-11-06 12:31:15 EST (Tue, 06 Nov 2012)
@@ -0,0 +1,172 @@
+// make_shared_array_args_test.cpp
+//
+// Copyright 2007-2009, 2012 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/shared_ptr.hpp>
+#include <cstddef>
+
+class X
+{
+private:
+
+ X( X const & );
+ X & operator=( X const & );
+
+ void * operator new[]( std::size_t n );
+ void operator delete[]( void * p );
+
+public:
+
+ static int instances;
+
+ int v;
+
+ explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 )
+ {
+ ++instances;
+ }
+
+ ~X()
+ {
+ --instances;
+ }
+};
+
+int X::instances = 0;
+
+int main()
+{
+ BOOST_TEST( X::instances == 0 );
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 0 );
+ BOOST_TEST( px[1].v == 0 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1 );
+ BOOST_TEST( px[1].v == 1 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2 );
+ BOOST_TEST( px[1].v == 1+2 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3 );
+ BOOST_TEST( px[1].v == 1+2+3 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3+4 );
+ BOOST_TEST( px[1].v == 1+2+3+4 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3+4+5 );
+ BOOST_TEST( px[1].v == 1+2+3+4+5 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3+4+5+6 );
+ BOOST_TEST( px[1].v == 1+2+3+4+5+6 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3+4+5+6+7 );
+ BOOST_TEST( px[1].v == 1+2+3+4+5+6+7 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7, 8 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8 );
+ BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 );
+
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8+9 );
+ BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8+9 );
+
+ px.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+#endif
+
+ return boost::report_errors();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk