]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/beast/test/beast/http/fields.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / beast / test / beast / http / fields.cpp
index 6abdcd8bd285c4963ff200e3567b8616794a8d83..f4c8694d7fb4175d0633d6cc78aa225740994d25 100644 (file)
@@ -21,11 +21,65 @@ namespace boost {
 namespace beast {
 namespace http {
 
-BOOST_STATIC_ASSERT(is_fields<fields>::value);
-
 class fields_test : public beast::unit_test::suite
 {
 public:
+    template<class T>
+    class test_allocator
+    {
+    public:
+        using value_type = T;
+
+        test_allocator() noexcept(false) {}
+
+        template<class U, class = typename
+            std::enable_if<!std::is_same<test_allocator, U>::value>::type>
+        test_allocator(test_allocator<U> const&) noexcept {}
+
+        value_type*
+        allocate(std::size_t n)
+        {
+            return static_cast<value_type*>(::operator new (n*sizeof(value_type)));
+        }
+
+        void
+        deallocate(value_type* p, std::size_t) noexcept
+        {
+            ::operator delete(p);
+        }
+
+        template<class U>
+        friend
+        bool
+        operator==(test_allocator<T> const&, test_allocator<U> const&) noexcept
+        {
+            return true;
+        }
+
+        template<class U>
+        friend
+        bool
+        operator!=(test_allocator<T> const& x, test_allocator<U> const& y) noexcept
+        {
+            return !(x == y);
+        }
+    };
+
+    using test_fields = basic_fields<test_allocator<char>>;
+
+    BOOST_STATIC_ASSERT(is_fields<fields>::value);
+    BOOST_STATIC_ASSERT(is_fields<test_fields>::value);
+
+    // std::allocator is noexcept movable, fields should satisfy
+    // these constraints as well.
+    BOOST_STATIC_ASSERT(std::is_nothrow_move_constructible<fields>::value);
+    BOOST_STATIC_ASSERT(std::is_nothrow_move_assignable<fields>::value);
+
+    // Check if basic_fields respects throw-constructibility and
+    // propagate_on_container_move_assignment of the allocator.
+    BOOST_STATIC_ASSERT(std::is_nothrow_move_constructible<test_fields>::value);
+    BOOST_STATIC_ASSERT(!std::is_nothrow_move_assignable<test_fields>::value);
+
     template<class Allocator>
     using fa_t = basic_fields<Allocator>;
 
@@ -334,6 +388,20 @@ public:
         BEAST_EXPECT(size(f) == 2);
     }
 
+    void testIteratorErase()
+    {
+        f_t f;
+        f.insert("a", "x");
+        f.insert("b", "y");
+        f.insert("c", "z");
+        BEAST_EXPECT(size(f) == 3);
+        f_t::const_iterator i = std::next(f.begin());
+        f.erase(i);
+        BEAST_EXPECT(size(f) == 2);
+        BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "a");
+        BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "c");
+    }
+
     void
     testContainer()
     {
@@ -926,6 +994,7 @@ public:
         testHeaders();
         testRFC2616();
         testErase();
+        testIteratorErase();
         testContainer();
         testPreparePayload();