]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/json/test/memory_resource.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / json / test / memory_resource.cpp
CommitLineData
20effc67
TL
1//
2// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// Official repository: https://github.com/boostorg/json
8//
9
10// Test that header file is self-contained.
11#include <boost/json/memory_resource.hpp>
12#include <boost/json/monotonic_resource.hpp>
13#include <boost/json/value.hpp>
20effc67 14#include <boost/container/pmr/vector.hpp>
20effc67
TL
15#include <vector>
16
17#include "test_suite.hpp"
18
19BOOST_JSON_NS_BEGIN
20
21class memory_resource_test
22{
23public:
24 void
25 testBoostPmr()
26 {
20effc67
TL
27 using allocator_type =
28 polymorphic_allocator<value>;
29
30 // pass polymorphic_allocator
31 // where storage_ptr is expected
32 {
33 monotonic_resource mr;
34 value jv( allocator_type{&mr} );
35 object o( allocator_type{&mr} );
36 array a( allocator_type{&mr} );
37 string s( allocator_type{&mr} );
38 }
39 {
40 monotonic_resource mr;
41 allocator_type a(&mr);
42
43 boost::container::pmr::vector<value> v1(a);
44 v1.resize(3);
45 BOOST_TEST(v1[1].storage().get() == &mr);
46
47 std::vector<value, allocator_type> v2(3, {}, a);
48 BOOST_TEST(v2[1].storage().get() == &mr);
49 }
20effc67
TL
50 }
51
52 // These are here instead of the type-specific
53 // test TUs, so that we only need to link to
54 // Boost.Container from one file.
55 void
56 testPmr()
57 {
58 // array
59 {
60 // get_allocator
61 {
62 monotonic_resource mr;
63 array a(&mr);
64 BOOST_TEST(a.get_allocator().resource() == &mr);
65 }
66 }
67
68 // object
69 {
70 // get_allocator
71 {
72 monotonic_resource mr;
73 object o(&mr);
74 BOOST_TEST(o.get_allocator().resource() == &mr);
75 }
76 }
77
78 // string
79 {
80 // get_allocator
81 {
82 monotonic_resource mr;
83 string s(&mr);
84 BOOST_TEST(s.get_allocator().resource() == &mr);
85 }
86 }
87
88 // value
89 {
90 // get_allocator
91 {
92 monotonic_resource mr;
93 value jv(&mr);
94 BOOST_TEST(jv.get_allocator().resource() == &mr);
95 }
96 }
97 }
98
99 void
100 run()
101 {
102 testBoostPmr();
20effc67
TL
103 testPmr();
104 }
105};
106
107TEST_SUITE(memory_resource_test, "boost.json.memory_resource");
108
109BOOST_JSON_NS_END