FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
msgpack-c/test/reference_cpp11.cpp at cpp_master · msgpack/msgpack-c · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
msgpack
/
msgpack-c
Public
Notifications
You must be signed in to change notification settings
Fork
936
Star
3.3k
Code
Issues
92
Pull requests
11
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
msgpack-c
/
test
/
reference_cpp11.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
234 lines (194 loc) · 6.29 KB
Breadcrumbs
msgpack-c
/
test
/
reference_cpp11.cpp
Copy path
File metadata and controls
234 lines (194 loc) · 6.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#
include
<
msgpack.hpp
>
#
define
BOOST_TEST_MODULE
reference
#
include
<
boost/test/unit_test.hpp
>
#
if
!defined(MSGPACK_USE_CPP03)
BOOST_AUTO_TEST_CASE
(unpack_int)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
1
);
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced);
BOOST_CHECK
(!referenced);
}
BOOST_AUTO_TEST_CASE
(unpack_string)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
std::string
(
"
abcdefg
"
));
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced);
BOOST_CHECK
(!referenced);
}
BOOST_AUTO_TEST_CASE
(unpack_bin)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
c[] = {
1
,
2
,
3
,
4
,
5
,
6
};
packer.
pack_bin
(
sizeof
(c));
packer.
pack_bin_body
(c,
sizeof
(c));
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced);
BOOST_CHECK
(!referenced);
}
BOOST_AUTO_TEST_CASE
(unpack_ext)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
const
buf [] = {
2
};
packer.
pack_ext
(
sizeof
(buf),
1
);
packer.
pack_ext_body
(buf,
sizeof
(buf));
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced);
BOOST_CHECK
(!referenced);
}
bool
never_called
(msgpack::type::object_type, std::
size_t
,
void
*)
{
BOOST_CHECK
(
false
);
return
false
;
}
bool
always_reference
(msgpack::type::object_type, std::
size_t
,
void
*)
{
return
true
;
}
BOOST_AUTO_TEST_CASE
(unpack_int_ref)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
1
);
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, never_called);
BOOST_CHECK
(!referenced);
}
BOOST_AUTO_TEST_CASE
(unpack_string_ref)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
std::string
(
"
abcdefg
"
));
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, always_reference);
BOOST_CHECK
(referenced);
}
BOOST_AUTO_TEST_CASE
(unpack_bin_ref)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
c[] = {
1
,
2
,
3
,
4
,
5
,
6
};
packer.
pack_bin
(
sizeof
(c));
packer.
pack_bin_body
(c,
sizeof
(c));
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, always_reference);
BOOST_CHECK
(referenced);
}
BOOST_AUTO_TEST_CASE
(unpack_ext_ref)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
const
buf [] = {
2
};
packer.
pack_ext
(
sizeof
(buf),
1
);
packer.
pack_ext_body
(buf,
sizeof
(buf));
bool
referenced;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, always_reference);
BOOST_CHECK
(referenced);
}
static
void
* s_p;
bool
sized_reference
(msgpack::type::object_type t, std::
size_t
s,
void
* p)
{
s_p = p;
switch
(t) {
case
msgpack::type::
STR
:
if
(s >=
5
)
return
true
;
break
;
case
msgpack::type::
BIN
:
if
(s >=
6
)
return
true
;
break
;
case
msgpack::type::
EXT
:
if
(s >=
7
)
return
true
;
break
;
default
:
BOOST_CHECK
(
false
);
}
return
false
;
}
BOOST_AUTO_TEST_CASE
(unpack_int_sized_ref)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
1
);
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, never_called, &sbuf);
BOOST_CHECK
(!referenced);
BOOST_CHECK_EQUAL
(
MSGPACK_NULLPTR
, s_p);
}
BOOST_AUTO_TEST_CASE
(unpack_string_sized_ref_4)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
std::string
(
"
1234
"
));
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
//
the last argument sbuf is any pointer as a user data.
//
That is stored to s_p in sized_reference
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, sized_reference, &sbuf);
BOOST_CHECK
(!referenced);
//
compare the passed argument with stored s_p.
BOOST_CHECK_EQUAL
(&sbuf, s_p);
}
BOOST_AUTO_TEST_CASE
(unpack_string_sized_ref_5)
{
msgpack::sbuffer sbuf;
msgpack::pack
(sbuf,
std::string
(
"
12345
"
));
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, sized_reference, &sbuf);
BOOST_CHECK
(referenced);
BOOST_CHECK_EQUAL
(&sbuf, s_p);
}
BOOST_AUTO_TEST_CASE
(unpack_bin_sized_ref_5)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
c[] = {
1
,
2
,
3
,
4
,
5
};
packer.
pack_bin
(
sizeof
(c));
packer.
pack_bin_body
(c,
sizeof
(c));
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, sized_reference, &sbuf);
BOOST_CHECK
(!referenced);
BOOST_CHECK_EQUAL
(&sbuf, s_p);
}
BOOST_AUTO_TEST_CASE
(unpack_bin_sized_ref_6)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
c[] = {
1
,
2
,
3
,
4
,
5
,
6
};
packer.
pack_bin
(
sizeof
(c));
packer.
pack_bin_body
(c,
sizeof
(c));
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, sized_reference, &sbuf);
BOOST_CHECK
(referenced);
BOOST_CHECK_EQUAL
(&sbuf, s_p);
}
BOOST_AUTO_TEST_CASE
(unpack_ext_sized_ref_6)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
const
buf [] = {
1
,
2
,
3
,
4
,
5
};
packer.
pack_ext
(
sizeof
(buf),
1
);
//
5 + 1(type) = 6
packer.
pack_ext_body
(buf,
sizeof
(buf));
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, sized_reference, &sbuf);
BOOST_CHECK
(!referenced);
BOOST_CHECK_EQUAL
(&sbuf, s_p);
}
BOOST_AUTO_TEST_CASE
(unpack_ext_sized_ref_7)
{
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer>
packer
(sbuf);
char
const
buf [] = {
1
,
2
,
3
,
4
,
5
,
6
};
packer.
pack_ext
(
sizeof
(buf),
1
);
//
6 + 1(type) = 7
packer.
pack_ext_body
(buf,
sizeof
(buf));
bool
referenced;
s_p =
MSGPACK_NULLPTR
;
msgpack::object_handle oh =
msgpack::unpack
(sbuf.
data
(), sbuf.
size
(), referenced, sized_reference, &sbuf);
BOOST_CHECK
(referenced);
BOOST_CHECK_EQUAL
(&sbuf, s_p);
}
#
endif
//
!defined(MSGPACK_USE_CPP03)
Back
|
FazBrowse Home
|
New Git URL