mirror of
https://github.com/boostorg/core.git
synced 2025-11-29 13:50:10 +01:00
Add more checked_delete tests, a visit_each test.
This commit is contained in:
58
test/checked_delete_test.cpp
Normal file
58
test/checked_delete_test.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
// Boost checked_delete test program
|
||||
|
||||
// Copyright Beman Dawes 2001. Copyright 2014 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/core/checked_delete.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
X()
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
X( X const & );
|
||||
X & operator=( X const & );
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
X * p = new X;
|
||||
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
|
||||
boost::checked_delete( p );
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
X * p = new X[ 3 ];
|
||||
|
||||
BOOST_TEST( X::instances == 3 );
|
||||
|
||||
boost::checked_array_delete( p );
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user