FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
msgpack-c/test/zone.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
/
zone.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
95 lines (76 loc) · 2.29 KB
Breadcrumbs
msgpack-c
/
test
/
zone.cpp
Copy path
File metadata and controls
95 lines (76 loc) · 2.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
#
include
<
msgpack.hpp
>
#
define
BOOST_TEST_MODULE
zone
#
include
<
boost/test/unit_test.hpp
>
BOOST_AUTO_TEST_CASE
(allocate_align)
{
msgpack::zone z;
char
* start = (
char
*)z.
allocate_align
(
1
);
BOOST_CHECK_EQUAL
(
0ul
,
reinterpret_cast
<std::
size_t
>(start) %
sizeof
(
int
));
for
(std::
size_t
s =
1
; s <
sizeof
(
int
); s <<=
1
) {
z.
allocate_no_align
(s);
char
* buf_a = (
char
*)z.
allocate_align
(
1
);
BOOST_CHECK_EQUAL
(
0ul
,
reinterpret_cast
<std::
size_t
>(buf_a) %
sizeof
(
int
));
}
}
BOOST_AUTO_TEST_CASE
(allocate_align_custom)
{
msgpack::zone z;
for
(std::
size_t
align =
1
; align <
64
; align <<=
1
) {
char
* start = (
char
*)z.
allocate_align
(
1
, align);
BOOST_CHECK_EQUAL
(
0ul
,
reinterpret_cast
<std::
size_t
>(start) % align);
for
(std::
size_t
s =
1
; s < align; s <<=
1
) {
z.
allocate_no_align
(s);
char
* buf_a = (
char
*)z.
allocate_align
(
1
, align);
BOOST_CHECK_EQUAL
(
0ul
,
reinterpret_cast
<std::
size_t
>(buf_a) % align);
}
}
}
class
myclass
{
public:
myclass
() : num(
0
), str(
"
default
"
) { }
myclass
(
int
num,
const
std::string& str) :
num
(num), str(str) { }
~myclass
() { }
int
num;
std::string str;
private:
myclass
(
const
myclass&);
};
BOOST_AUTO_TEST_CASE
(allocate)
{
msgpack::zone z;
myclass* m = z.
allocate
<myclass>();
BOOST_CHECK_EQUAL
(m->
num
,
0
);
BOOST_CHECK_EQUAL
(m->
str
,
"
default
"
);
}
BOOST_AUTO_TEST_CASE
(allocate_constructor)
{
msgpack::zone z;
myclass* m = z.
allocate
<myclass>(
7
,
"
msgpack
"
);
BOOST_CHECK_EQUAL
(m->
num
,
7
);
BOOST_CHECK_EQUAL
(m->
str
,
"
msgpack
"
);
}
static
void
custom_finalizer_func
(
void
* user)
{
myclass* m = (myclass*)user;
delete
m;
}
BOOST_AUTO_TEST_CASE
(push_finalizer)
{
msgpack::zone z;
myclass* m =
new
myclass
();
z.
push_finalizer
(custom_finalizer_func, (
void
*)m);
}
BOOST_AUTO_TEST_CASE
(push_finalizer_unique_ptr)
{
msgpack::zone z;
msgpack::unique_ptr<myclass>
am
(
new
myclass
());
z.
push_finalizer
(
msgpack::move
(am));
}
BOOST_AUTO_TEST_CASE
(allocate_no_align)
{
msgpack::zone z;
char
* buf1 =
reinterpret_cast
<
char
*>(z.
allocate_no_align
(
4
));
char
* buf2 =
reinterpret_cast
<
char
*>(z.
allocate_no_align
(
4
));
BOOST_CHECK_EQUAL
(
reinterpret_cast
<
void
*>(buf1+
4
),
reinterpret_cast
<
void
*>(buf2));
}
Back
|
FazBrowse Home
|
New Git URL