diff --git a/modules/io/tests/test_io_msgpack.cc b/modules/io/tests/test_io_msgpack.cc index 60503c4dd9eeb2444b132777c1d27517ecf60751..d0451e4af1834539edd9b8d430d830fd53f96abe 100644 --- a/modules/io/tests/test_io_msgpack.cc +++ b/modules/io/tests/test_io_msgpack.cc @@ -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();