]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/enable_shared_from_this_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2002, 2003 Peter Dimov
4 // This file is the adaptation of shared_from_this_test.cpp from smart_ptr library
6 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
7 // Software License, Version 1.0. (See accompanying file
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/interprocess for documentation.
12 //////////////////////////////////////////////////////////////////////////////
13 #include <boost/interprocess/detail/workaround.hpp>
14 #include <boost/interprocess/smart_ptr/enable_shared_from_this.hpp>
15 #include <boost/interprocess/smart_ptr/shared_ptr.hpp>
17 #include <boost/core/lightweight_test.hpp>
18 #include <boost/interprocess/managed_shared_memory.hpp>
19 #include "get_process_id_name.hpp"
23 using namespace boost::interprocess
;
25 typedef allocator
<void, managed_shared_memory::segment_manager
>
30 typedef deleter
<X
, managed_shared_memory::segment_manager
> x_deleter_t
;
33 public enable_shared_from_this
<X
, v_allocator_t
, x_deleter_t
>
37 typedef shared_ptr
<X
, v_allocator_t
, x_deleter_t
> v_shared_ptr
;
40 template<class ManagedMemory
>
41 void test_enable_shared_this(ManagedMemory
&managed_mem
)
43 v_shared_ptr
p(make_managed_shared_ptr
44 (managed_mem
.template construct
<X
>(anonymous_instance
)(), managed_mem
));
46 v_shared_ptr q
= p
->shared_from_this();
48 BOOST_TEST(!(p
< q
) && !(q
< p
));
54 //This should throw bad_weak_ptr
55 v_shared_ptr r
= v2
.shared_from_this();
56 BOOST_ERROR("v2.shared_from_this() failed to throw");
58 catch(boost::interprocess::bad_weak_ptr
const &)
60 //This is the expected path
63 BOOST_ERROR("v2.shared_from_this() threw an unexpected exception");
68 //This should not throw bad_weak_ptr
70 v_shared_ptr r
= p
->shared_from_this();
72 BOOST_TEST(!(p
< r
) && !(r
< p
));
74 catch(boost::interprocess::bad_weak_ptr
const &)
76 BOOST_ERROR("p->shared_from_this() threw bad_weak_ptr after *p = X()");
80 BOOST_ERROR("p->shared_from_this() threw an unexpected exception after *p = X()");
87 std::string process_name
;
88 test::get_process_id_name(process_name
);
89 shared_memory_object::remove(process_name
.c_str());
90 managed_shared_memory
shmem(create_only
, process_name
.c_str(), 65536);
91 test_enable_shared_this(shmem
);
92 shared_memory_object::remove(process_name
.c_str());
93 return boost::report_errors();