]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/interprocess/test/intrusive_ptr_test.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / interprocess / test / intrusive_ptr_test.cpp
index d5293a3ad4ec8145fbdc382e339b96410af7d704..f3e481251d3a0d9b53aa4e40d8356daad36a2f2d 100644 (file)
 #include <boost/core/lightweight_test.hpp>
 #include <boost/config.hpp>
 #include <boost/move/adl_move_swap.hpp>
+#include <boost/move/core.hpp>
 #include <functional>
 
 typedef boost::interprocess::offset_ptr<void> VP;
 
+namespace {
+    int addref_release_calls = 0;
+}
+
 namespace N
 {
 
@@ -52,11 +57,13 @@ class base
 
    void add_ref()
    {
+      ++addref_release_calls;
       ++use_count_;
    }
 
    void release()
    {
+      ++addref_release_calls;
       if(--use_count_ == 0) delete this;
    }
 };
@@ -189,11 +196,30 @@ void copy_constructor()
    }
 }
 
+void move_constructor()
+{
+   {
+      int prev_addref_release_calls = addref_release_calls;
+      X* x = new X();
+      boost::interprocess::intrusive_ptr<X, VP> px(x);
+      BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
+
+      //static_assert(std::is_nothrow_move_constructible< boost::interprocess::intrusive_ptr<X, VP> >::value, "test instrusive_ptr is nothrow move constructible");
+
+      boost::interprocess::intrusive_ptr<X, VP> px2(boost::move(px));
+      BOOST_TEST(px2.get() == x);
+      BOOST_TEST(!px.get());
+      BOOST_TEST(px2->use_count() == 1);
+      BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
+   }
+}
+
 void test()
 {
    default_constructor();
    pointer_constructor();
    copy_constructor();
+   move_constructor();
 }
 
 } // namespace n_constructors
@@ -223,6 +249,26 @@ void copy_assignment()
 {
 }
 
+void move_assignment()
+{
+   {      
+      int prev_addref_release_calls = addref_release_calls;
+      X* x = new X();
+      boost::interprocess::intrusive_ptr<X, VP> px(x);
+      BOOST_TEST(px->use_count() == 1);
+      BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
+
+      //static_assert(std::is_nothrow_move_assignable< boost::interprocess::intrusive_ptr<X, VP> >::value, "test if nothrow move assignable ");
+
+      boost::interprocess::intrusive_ptr<X, VP> px2;
+      px2 = boost::move(px);
+      BOOST_TEST(px2.get() == x);
+      BOOST_TEST(!px.get());
+      BOOST_TEST(px2->use_count() == 1);
+      BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
+   }
+}
+
 void conversion_assignment()
 {
 }
@@ -236,6 +282,7 @@ void test()
    copy_assignment();
    conversion_assignment();
    pointer_assignment();
+   move_assignment();
 }
 
 } // namespace n_assignment