]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/outcome/test/tests/swap.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / outcome / test / tests / swap.cpp
index cd62d3483908480537d3bf372a0e58afd9ada5df..0bcba38026b67e9c730d0400a8f5fa4ceb729e40 100644 (file)
@@ -1,5 +1,5 @@
 /* Unit testing for outcomes
-(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
+(C) 2013-2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
 
 
 Boost Software License - Version 1.0 - August 17th, 2003
@@ -31,6 +31,61 @@ DEALINGS IN THE SOFTWARE.
 #include <boost/test/unit_test.hpp>
 #include <boost/test/unit_test_monitor.hpp>
 
+/* Should be this:
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+*/
+
 #ifndef BOOST_NO_EXCEPTIONS
 #ifdef _MSC_VER
 #pragma warning(push)
@@ -59,9 +114,10 @@ template <bool mc, bool ma> struct Throwy
   {
     if(mc)
     {
-      std::cout << id << " move constructor count = " << count << std::endl;
+      std::cout << "   " << id << " move constructor count = " << count << std::endl;
       if(!count)
       {
+        std::cout << "      " << id << " move constructor throws!" << std::endl;
         throw std::bad_alloc();
       }
     }
@@ -74,9 +130,10 @@ template <bool mc, bool ma> struct Throwy
     count = o.count - o.inc;
     if(ma)
     {
-      std::cout << o.id << " move assignment count = " << count << std::endl;
+      std::cout << "   " << o.id << " move assignment count = " << count << std::endl;
       if(!count)
       {
+        std::cout << "      " << o.id << " move assignment throws!" << std::endl;
         throw std::bad_alloc();
       }
     }
@@ -168,6 +225,7 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
 
     static_assert(!detail::is_nothrow_swappable<throwy_t>::value, "is_nothrow_swappable is not correct!");
 
+    std::cout << "Result value first swap succeeds, second swap second move assignment throws:" << std::endl;
     {
       throwy a(3, 78), b(4, 65);
       a.swap(b);
@@ -187,7 +245,7 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
       BOOST_CHECK(!a.has_lost_consistency());
       BOOST_CHECK(!b.has_lost_consistency());
     }
-    std::cout << std::endl;
+    std::cout << "\nResult value second move assignment throws, on recover second move assignment throws:" << std::endl;
     {
       throwy a(2, 78), b(3, 65);  // fails on second assignment, cannot restore
       try
@@ -201,8 +259,8 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
         BOOST_CHECK(b.has_lost_consistency());
       }
     }
-    std::cout << std::endl;
   }
+  std::cout << "\nResult error first swap succeeds, second swap first move assignment throws:" << std::endl;
   {  // Does swap implement the strong guarantee?
     using throwy_t = Throwy<true, true>;
     using throwy = resulty2<true, true>;
@@ -232,7 +290,7 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
       BOOST_CHECK(!a.has_lost_consistency());
       BOOST_CHECK(!b.has_lost_consistency());
     }
-    std::cout << std::endl;
+    std::cout << "\nResult error second move assignment throws, on recover second move assignment throws:" << std::endl;
     {
       throwy a(2, 78), b(3, 65);  // fails on second assignment, cannot restore
       try
@@ -246,7 +304,6 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
         BOOST_CHECK(b.has_lost_consistency());
       }
     }
-    std::cout << std::endl;
   }
 
   {  // Is noexcept propagated?
@@ -280,6 +337,7 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
     static_assert(noexcept(a.swap(b)), "type has a throwing swap!");
   }
 
+  std::cout << "\n\nOutcome value first swap succeeds, second swap first move assignment throws:" << std::endl;
   {  // Does swap implement the strong guarantee?
     using throwy_t = Throwy<true, true>;
     using throwy = outcomey1<true, true>;
@@ -309,7 +367,7 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
       BOOST_CHECK(!a.has_lost_consistency());
       BOOST_CHECK(!b.has_lost_consistency());
     }
-    std::cout << std::endl;
+    std::cout << "\nOutcome value second move assignment throws, on recover second move assignment throws:" << std::endl;
     {
       throwy a(2, 78), b(3, 65);  // fails on second assignment, cannot restore
       try
@@ -323,8 +381,8 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
         BOOST_CHECK(b.has_lost_consistency());
       }
     }
-    std::cout << std::endl;
   }
+  std::cout << "\nOutcome error first swap succeeds, second swap first move assignment throws:" << std::endl;
   {  // Does swap implement the strong guarantee?
     using throwy_t = Throwy<true, true>;
     using throwy = outcomey2<true, true>;
@@ -354,7 +412,7 @@ BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_swap, "Tests that the outcome swaps a
       BOOST_CHECK(!a.has_lost_consistency());
       BOOST_CHECK(!b.has_lost_consistency());
     }
-    std::cout << std::endl;
+    std::cout << "\nOutcome error second move assignment throws, on recover second move assignment throws:" << std::endl;
     {
       throwy a(2, 78), b(3, 65);  // fails on second assignment, cannot restore
       try