From 9c6f10d44778c4a41482ed7ea1c6c4262dbd900f Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Fri, 17 Nov 2023 13:33:10 -0500 Subject: [PATCH] Add test for variadic `pack`/`unpack` --- .../test/network/test_message_buffer.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libraries/libfc/test/network/test_message_buffer.cpp b/libraries/libfc/test/network/test_message_buffer.cpp index e3d6164a64..8a6ab2adb6 100644 --- a/libraries/libfc/test/network/test_message_buffer.cpp +++ b/libraries/libfc/test/network/test_message_buffer.cpp @@ -373,6 +373,28 @@ BOOST_AUTO_TEST_CASE(message_buffer_datastream_tuple) { } } +BOOST_AUTO_TEST_CASE(message_buffer_datastream_variadic_pack_unpack) { + using my_message_buffer_t = fc::message_buffer<1024>; + my_message_buffer_t mbuff; + + char buf[1024]; + fc::datastream ds( buf, 1024 ); + + using my_tuple = std::tuple; + my_tuple t(13, 42, "hello"); + fc::raw::pack( ds, std::get<0>(t), std::get<1>(t), std::get<2>(t) ); + + memcpy(mbuff.write_ptr(), buf, 1024); + mbuff.advance_write_ptr(1024); + + for( int i = 0; i < 3; ++i ) { + auto ds2 = mbuff.create_peek_datastream(); + my_tuple t2; + fc::raw::unpack( ds2, std::get<0>(t2), std::get<1>(t2), std::get<2>(t2) ); + BOOST_CHECK( t == t2 ); + } +} + // Make sure that the memory allocation is thread-safe. // A previous version used boost::object_pool without synchronization. BOOST_AUTO_TEST_CASE(test_message_buffer) {