forked from boostorg/smart_ptr
Add abi_test
This commit is contained in:
16
test/Jamfile
16
test/Jamfile
@ -278,9 +278,25 @@ compile spinlock_windows_h_test.cpp ;
|
||||
compile yield_k_windows_h_test.cpp ;
|
||||
|
||||
lib dll_test : dll_test_lib.cpp : <link>shared:<define>DLL_TEST_DYN_LINK=1 ;
|
||||
explicit dll_test ;
|
||||
|
||||
run dll_test_main.cpp dll_test : : : <link>static : dll_test_static ;
|
||||
run dll_test_main.cpp dll_test : : : <link>shared : dll_test_shared ;
|
||||
|
||||
run make_shared_const_test.cpp ;
|
||||
run make_local_shared_const_test.cpp ;
|
||||
|
||||
lib abi_test_mt : abi_test_lib.cpp : <link>static ;
|
||||
explicit abi_test_mt ;
|
||||
|
||||
obj abi_test_lib_nt : abi_test_lib.cpp : <define>BOOST_DISABLE_THREADS ;
|
||||
explicit abi_test_lib_nt ;
|
||||
|
||||
lib abi_test_nt : abi_test_lib_nt : <link>static ;
|
||||
explicit abi_test_nt ;
|
||||
|
||||
run abi_test_main.cpp abi_test_mt : : : <define>BOOST_DISABLE_THREADS : abi_test_nt_mt ;
|
||||
run abi_test_main.cpp abi_test_nt : : : : abi_test_mt_nt ;
|
||||
|
||||
run abi_test_main.cpp abi_test_mt/<cxxstd>11 : : : <cxxstd>03 : abi_test_03_11 ;
|
||||
run abi_test_main.cpp abi_test_mt/<cxxstd>03 : : : <cxxstd>11 : abi_test_11_03 ;
|
||||
|
31
test/abi_test_lib.cpp
Normal file
31
test/abi_test_lib.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2018 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/shared_ptr.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_DISABLE_THREADS)
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is defined" )
|
||||
#else
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is not defined" )
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_ATOMIC)
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is defined" )
|
||||
#else
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is not defined" )
|
||||
#endif
|
||||
|
||||
void abi_test_1( boost::shared_ptr<void> & p )
|
||||
{
|
||||
p.reset();
|
||||
}
|
||||
|
||||
boost::shared_ptr<void> abi_test_2( boost::shared_ptr<void> const & p )
|
||||
{
|
||||
return p;
|
||||
}
|
71
test/abi_test_main.cpp
Normal file
71
test/abi_test_main.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
// Copyright 2018 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/shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_DISABLE_THREADS)
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is defined" )
|
||||
#else
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is not defined" )
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_ATOMIC)
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is defined" )
|
||||
#else
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is not defined" )
|
||||
#endif
|
||||
|
||||
void abi_test_1( boost::shared_ptr<void> & p );
|
||||
boost::shared_ptr<void> abi_test_2( boost::shared_ptr<void> const & p );
|
||||
|
||||
static int deleter_called;
|
||||
|
||||
void deleter( void* )
|
||||
{
|
||||
++deleter_called;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
deleter_called = 0;
|
||||
|
||||
boost::shared_ptr<void> p( static_cast<void*>( 0 ), deleter );
|
||||
|
||||
BOOST_TEST_EQ( p.use_count(), 1 );
|
||||
|
||||
abi_test_1( p );
|
||||
|
||||
BOOST_TEST_EQ( p.use_count(), 0 );
|
||||
BOOST_TEST_EQ( deleter_called, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
deleter_called = 0;
|
||||
|
||||
boost::shared_ptr<void> p1( static_cast<void*>( 0 ), deleter );
|
||||
|
||||
BOOST_TEST_EQ( p1.use_count(), 1 );
|
||||
|
||||
boost::shared_ptr<void> p2 = abi_test_2( p1 );
|
||||
|
||||
BOOST_TEST_EQ( p1.use_count(), 2 );
|
||||
BOOST_TEST_EQ( p2.use_count(), 2 );
|
||||
|
||||
p1.reset();
|
||||
|
||||
BOOST_TEST_EQ( p2.use_count(), 1 );
|
||||
|
||||
p2.reset();
|
||||
|
||||
BOOST_TEST_EQ( deleter_called, 1 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user