1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <cstdlib>
#include <boost/json/value.hpp>
#include <boost/json/string.hpp>
#include <boost/json/monotonic_resource.hpp>
#include <boost/json/static_resource.hpp>
using namespace boost::json;
int main()
{
value jv;
// TEST_EXPR( 'jv', 'null' )
jv = true;
// TEST_EXPR( 'jv', 'true' )
jv = false;
// TEST_EXPR( 'jv', 'false' )
jv = 1;
// TEST_EXPR( 'jv', '1' )
jv = 1u;
// TEST_EXPR( 'jv', '1' )
jv = 1.5;
// TEST_EXPR( 'jv', '1.5' )
string js;
// TEST_EXPR( 'js', '""' )
js = "1";
// TEST_EXPR( 'js', '"1"' )
js = "this is a very long string, unusually long even, definitely not short";
// TEST_EXPR( 'js', '"this is a very long string, unusually long even, definitely not short"' )
array ja;
// TEST_EXPR( 'ja', 'array [size=0, capacity=0]' )
ja.push_back("a");
// TEST_EXPR( 'ja', 'array [size=1, capacity=1] = {"a"}' )
ja.push_back(true);
// TEST_EXPR( 'ja', 'array [size=2, capacity=2] = {"a", true}' )
ja.insert(ja.end(), {1, 2, 3, 4});
// TEST_EXPR( 'ja', 'array [size=6, capacity=6] = {"a", true, 1, 2, 3, 4}' )
ja.push_back(5);
// TEST_EXPR( 'ja', 'array [size=7, capacity=9] = {"a", true, 1, 2, 3, 4, 5}' )
ja[ja.size() - 1] = array{1,2,3};
// TEST_EXPR( 'ja', 'array [size=7, capacity=9] = {"a", true, 1, 2, 3, 4, array [size=3, capacity=3] = {1, 2, 3}}' )
object jo;
// TEST_EXPR( 'jo', 'object [size=0, capacity=0]' )
jo["a"] = "b";
// TEST_EXPR( 'jo', 'object [size=1, capacity=1] = {["a"] = "b"}' )
jo["b"] = "c";
// TEST_EXPR( 'jo', 'object [size=2, capacity=2] = {["a"] = "b", ["b"] = "c"}' )
jo.insert({ {"c", "d"}, {"d", "e"} });
// TEST_EXPR( 'jo', 'object [size=4, capacity=4] = {["a"] = "b", ["b"] = "c", ["c"] = "d", ["d"] = "e"}' )
jo["e"] = "f";
// TEST_EXPR( 'jo', 'object [size=5, capacity=6] = {["a"] = "b", ["b"] = "c", ["c"] = "d", ["d"] = "e", ["e"] = "f"}' )
key_value_pair kv = *jo.begin();
(void)kv;
// TEST_EXPR( 'kv', '["a"] = "b"' )
storage_ptr sp = jv.storage();
// TEST_EXPR( 'sp', 'storage_ptr [resource=default]' )
unsigned char buf[1024];
{
static_resource sr(buf);
// TEST_EXPR( 'sr', 'static_resource [buffer={0}, head={0}, free=1024]', '/a &buf' )
sr.allocate(200);
unsigned char* new_head = buf + 200;
(void)new_head;
// TEST_EXPR( 'sr', 'static_resource [buffer={0}, head={1}, free=824]', '/a &buf', '/a new_head' )
sp = &sr;
// TEST_EXPR( 'sp', 'storage_ptr [trivial, resource=static_resource [buffer={0}, head={1}, free=824]]', '/a &buf', '/a new_head' )
sr.release();
}
sp = make_shared_resource<static_resource>(buf);
// TEST_EXPR( 'sp', 'storage_ptr [trivial, shared, refs=1, resource=static_resource [buffer={0}, head={0}, free=1024]]', '/a &buf' )
{
auto sp2 = sp;
// TEST_EXPR( 'sp', 'storage_ptr [trivial, shared, refs=2, resource=static_resource [buffer={0}, head={0}, free=1024]]', '/a &buf' )
(void)sp;
}
{
monotonic_resource mr;
// TEST_EXPR( 'mr', 'monotonic_resource [buffer=0x0, block=0x0, head=0x0, free=0]' )
storage_ptr sp2 = &mr;
// TEST_EXPR( 'sp2', 'storage_ptr [trivial, resource=monotonic_resource [buffer=0x0, block=0x0, head=0x0, free=0]]' )
(void)sp2;
}
monotonic_resource mr(buf, 10, sp);
// TEST_EXPR( 'mr', 'monotonic_resource [buffer={0}, block={0}, head={0}, free=10, upstream=storage_ptr [trivial, shared, refs=2, resource=static_resource [buffer={0}, head={0}, free=1024]]]', '/a &buf' )
mr.allocate(4);
unsigned char* new_head = buf + 4;
(void)new_head;
// TEST_EXPR( 'mr', 'monotonic_resource [buffer={0}, block={0}, head={1}, free=6, upstream=storage_ptr [trivial, shared, refs=2, resource=static_resource [buffer={0}, head={0}, free=1024]]]', '/a &buf', '/a new_head' )
return EXIT_SUCCESS;
}
|