Skip to content
Snippets Groups Projects
Commit 34dca48f authored by Bienchen's avatar Bienchen
Browse files

Simple unit test for msgpack

parent eb26d687
Branches mmtf
No related tags found
No related merge requests found
......@@ -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();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment