Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_variant_estimated_size.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE variant
2#include <boost/test/included/unit_test.hpp>
3
7#include <string>
8
9using namespace fc;
10
11BOOST_AUTO_TEST_SUITE(variant_estimated_size_suite)
12BOOST_AUTO_TEST_CASE(null_variant_estimated_size_test)
13{
14 nullptr_t np;
15
16 variant v;
17 variant v_nullptr(np);
18
19 BOOST_CHECK_EQUAL(v.estimated_size(), sizeof(variant));
20 BOOST_CHECK_EQUAL(v_nullptr.estimated_size(), sizeof(variant));
21}
22
23BOOST_AUTO_TEST_CASE(int64_variant_estimated_size_test)
24{
25 int64_t i = 1;
26 int32_t j = 2;
27 int16_t k = 3;
28 int8_t l = 4;
29
30 variant v_int_64(i);
31 variant v_int_32(j);
32 variant v_int_16(k);
33 variant v_int_8(l);
34
35 BOOST_CHECK_EQUAL(v_int_64.estimated_size(), sizeof(variant));
36 BOOST_CHECK_EQUAL(v_int_32.estimated_size(), sizeof(variant));
37 BOOST_CHECK_EQUAL(v_int_16.estimated_size(), sizeof(variant));
38 BOOST_CHECK_EQUAL(v_int_8.estimated_size(), sizeof(variant));
39}
40
41BOOST_AUTO_TEST_CASE(uint64_variant_estimated_size_test)
42{
43 uint64_t i = 1;
44 uint32_t j = 2;
45 uint16_t k = 3;
46 uint8_t l = 4;
47
48 variant v_uint_64(i);
49 variant v_uint_32(j);
50 variant v_uint_16(k);
51 variant v_uint_8(l);
52
53 BOOST_CHECK_EQUAL(v_uint_64.estimated_size(), sizeof(variant));
54 BOOST_CHECK_EQUAL(v_uint_32.estimated_size(), sizeof(variant));
55 BOOST_CHECK_EQUAL(v_uint_16.estimated_size(), sizeof(variant));
56 BOOST_CHECK_EQUAL(v_uint_8.estimated_size(), sizeof(variant));
57}
58
59BOOST_AUTO_TEST_CASE(double_variant_estimated_size_test)
60{
61 float f = 3.14;
62 double d = 12.345;
63
64 variant v_float(f);
65 variant v_double(d);
66
67 BOOST_CHECK_EQUAL(v_float.estimated_size(), sizeof(variant));
68 BOOST_CHECK_EQUAL(v_double.estimated_size(), sizeof(variant));
69}
70
71BOOST_AUTO_TEST_CASE(string_variant_estimated_size_test)
72{
73 char c[] = "Hello World";
74 const char* cc = "Goodbye";
75 wchar_t wc[] = L"0123456789";
76 const wchar_t* cwc = L"foo";
77 string s = "abcdefghijklmnopqrstuvwxyz";
78
79 variant v_char(c);
80 variant v_const_char(cc);
81 variant v_wchar(wc);
82 variant v_const_wchar(cwc);
83 variant v_string(s);
84
85 BOOST_CHECK_EQUAL(v_char.estimated_size(), 11 + sizeof(variant) + sizeof(string));
86 BOOST_CHECK_EQUAL(v_const_char.estimated_size(), 7 + sizeof(variant) + sizeof(string));
87 BOOST_CHECK_EQUAL(v_wchar.estimated_size(), 10 + sizeof(variant) + sizeof(string));
88 BOOST_CHECK_EQUAL(v_const_wchar.estimated_size(), 3 + sizeof(variant) + sizeof(string));
89 BOOST_CHECK_EQUAL(v_string.estimated_size(), 26 + sizeof(variant) + sizeof(string));
90}
91
92BOOST_AUTO_TEST_CASE(blob_variant_estimated_size_test)
93{
94 blob bl;
95 bl.data.push_back('f');
96 bl.data.push_back('o');
97 bl.data.push_back('o');
98
99 variant v_blob(bl);
100
101 BOOST_CHECK_EQUAL(v_blob.estimated_size(), 3 + sizeof(variant) + sizeof(blob));
102}
103
104BOOST_AUTO_TEST_CASE(variant_object_variant_estimated_size_test)
105{
106 string k1 = "key_bool";
107 string k2 = "key_string";
108 string k3 = "key_int16";
109 string k4 = "key_blob"; // 35 + 4 * sizeof(string)
110
111 bool b = false;
112 string s = "HelloWorld"; // 10 + sizeof(string)
113 int16_t i = 123;
114 blob bl;
115 bl.data.push_back('b');
116 bl.data.push_back('a');
117 bl.data.push_back('r'); // 3 + sizeof(blob)
118
119 variant v_bool(b);
120 variant v_string(s);
121 variant v_int16(i);
122 variant v_blob(bl); // + 4 * sizeof(variant)
123
125 mu(k1, b);
126 mu(k2, v_string);
127 mu(k3, v_int16);
128 mu(k4, bl);
129 variant_object vo(mu); // + sizeof(variant_object) + sizeof(std::vector<variant_object::entry>)
130 variant v_vo(vo); // + sizeof(variant)
131
132 BOOST_CHECK_EQUAL(vo.estimated_size(), 48 + 5 * sizeof(string) + sizeof(blob) + 4 * sizeof(variant) +
133 sizeof(variant_object) + sizeof(std::vector<variant_object::entry>));
134 BOOST_CHECK_EQUAL(v_vo.estimated_size(), 48 + 5 * sizeof(string) + sizeof(blob) + 5 * sizeof(variant) +
135 sizeof(variant_object) + sizeof(std::vector<variant_object::entry>));
136}
137
138BOOST_AUTO_TEST_CASE(array_variant_estimated_size_test)
139{
140 bool b = true;
141 wchar_t wc[] = L"Goodbye"; // 7 + sizeof(string)
142 uint32_t i = 54321;
143
144 variant v_bool(b);
145 variant v_wchar(wc);
146 variant v_uint32(i); // + 3 * sizeof(variant)
147
148 variants vs; // + sizeof(variants)
149 vs.push_back(v_bool);
150 vs.push_back(v_wchar);
151 vs.push_back(v_uint32);
152
153 variant v_variants(vs); // + sizeof(variant)
154 BOOST_CHECK_EQUAL(v_variants.estimated_size(), 7 + sizeof(string) + 4 * sizeof(variant) + sizeof(variants));
155}
156
157BOOST_AUTO_TEST_SUITE_END()
An order-preserving dictionary of variants.
An order-preserving dictionary of variants.
size_t estimated_size() const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
size_t estimated_size() const
Definition variant.cpp:575
Defines exception's used by fc.
namespace sysio::chain
Definition authority.cpp:3
std::vector< fc::variant > variants
Definition variant.hpp:173
decltype(nullptr) nullptr_t
Definition utility.hpp:28
signed short int16_t
Definition stdint.h:122
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
signed char int8_t
Definition stdint.h:121
BOOST_AUTO_TEST_CASE(null_variant_estimated_size_test)
CK_ULONG d
char * s
uint16_t j
int l