Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_variant_estimated_size.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <fc/variant_object.hpp>
#include <fc/exception/exception.hpp>
#include <fc/crypto/base64.hpp>
#include <string>
Include dependency graph for test_variant_estimated_size.cpp:

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   variant
 

Functions

 BOOST_AUTO_TEST_CASE (null_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (int64_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (uint64_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (double_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (string_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (blob_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (variant_object_variant_estimated_size_test)
 
 BOOST_AUTO_TEST_CASE (array_variant_estimated_size_test)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   variant

Definition at line 1 of file test_variant_estimated_size.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/8]

BOOST_AUTO_TEST_CASE ( array_variant_estimated_size_test )

Definition at line 138 of file test_variant_estimated_size.cpp.

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}
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
std::vector< fc::variant > variants
Definition variant.hpp:173
unsigned int uint32_t
Definition stdint.h:126
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/8]

BOOST_AUTO_TEST_CASE ( blob_variant_estimated_size_test )

Definition at line 92 of file test_variant_estimated_size.cpp.

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}
static const Reg8 bl(Operand::BL)
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/8]

BOOST_AUTO_TEST_CASE ( double_variant_estimated_size_test )

Definition at line 59 of file test_variant_estimated_size.cpp.

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}
CK_ULONG d
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/8]

BOOST_AUTO_TEST_CASE ( int64_variant_estimated_size_test )

Definition at line 23 of file test_variant_estimated_size.cpp.

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}
signed short int16_t
Definition stdint.h:122
signed __int64 int64_t
Definition stdint.h:135
signed int int32_t
Definition stdint.h:123
signed char int8_t
Definition stdint.h:121
uint16_t j
int l
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/8]

BOOST_AUTO_TEST_CASE ( null_variant_estimated_size_test )

Definition at line 12 of file test_variant_estimated_size.cpp.

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}
size_t estimated_size() const
Definition variant.cpp:575
decltype(nullptr) nullptr_t
Definition utility.hpp:28
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/8]

BOOST_AUTO_TEST_CASE ( string_variant_estimated_size_test )

Definition at line 71 of file test_variant_estimated_size.cpp.

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}
char * s
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/8]

BOOST_AUTO_TEST_CASE ( uint64_variant_estimated_size_test )

Definition at line 41 of file test_variant_estimated_size.cpp.

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}
unsigned short uint16_t
Definition stdint.h:125
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/8]

BOOST_AUTO_TEST_CASE ( variant_object_variant_estimated_size_test )

Definition at line 104 of file test_variant_estimated_size.cpp.

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}
An order-preserving dictionary of variants.
An order-preserving dictionary of variants.
static const Opmask k3(3)
static const Opmask k4(4)
static const Opmask k2(2)
static const Opmask k1(1)
Here is the call graph for this function: