Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
34dca48f
Commit
34dca48f
authored
8 years ago
by
Bienchen
Browse files
Options
Downloads
Patches
Plain Diff
Simple unit test for msgpack
parent
eb26d687
Branches
mmtf
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/io/tests/test_io_msgpack.cc
+42
-0
42 additions, 0 deletions
modules/io/tests/test_io_msgpack.cc
with
42 additions
and
0 deletions
modules/io/tests/test_io_msgpack.cc
+
42
−
0
View file @
34dca48f
...
...
@@ -20,4 +20,46 @@
// the idea of this test is basically to check that we MessagePack is available
// to OST. Real testing of MessagePack should happen in that project itself.
#define BOOST_TEST_DYN_LINK
#include
<boost/test/unit_test.hpp>
#include
<boost/test/auto_unit_test.hpp>
#include
<string>
#include
<ost/string_ref.hh>
#include
<ost/io/msgpack/msgpack.hpp>
using
namespace
ost
;
BOOST_AUTO_TEST_SUITE
(
io
);
BOOST_AUTO_TEST_CASE
(
msgpack_test
)
{
/* just trying if MsgPack works in general, mostly copied from the examples at
http://msgpack.org/index.html */
msgpack
::
type
::
tuple
<
int
,
bool
,
String
>
src
(
1
,
true
,
"example"
);
// Serialize the object into the buffer.
std
::
stringstream
buffer
;
msgpack
::
pack
(
buffer
,
src
);
// send the buffer ...
buffer
.
seekg
(
0
);
// deserialize the buffer into msgpack::object instance.
String
str
(
buffer
.
str
());
msgpack
::
object_handle
oh
=
msgpack
::
unpack
(
str
.
data
(),
str
.
size
());
/* Deserialized object is valid during the msgpack::object_handle instance is
alive. */
msgpack
::
object
deserialized
=
oh
.
get
();
/* Convert msgpack::object instance into the original type.
If the type is mismatched, it throws msgpack::type_error exception. */
msgpack
::
type
::
tuple
<
int
,
bool
,
String
>
dst
;
deserialized
.
convert
(
dst
);
BOOST_CHECK
(
msgpack
::
type
::
get
<
0
>
(
dst
)
==
1
);
BOOST_CHECK
(
msgpack
::
type
::
get
<
1
>
(
dst
)
==
true
);
BOOST_CHECK
(
msgpack
::
type
::
get
<
2
>
(
dst
)
==
"example"
);
}
BOOST_AUTO_TEST_SUITE_END
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment