Skip to content

Commit

Permalink
Add test for variadic pack/unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Nov 17, 2023
1 parent 1203afb commit 9c6f10d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libraries/libfc/test/network/test_message_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*> ds( buf, 1024 );

using my_tuple = std::tuple<int, int, std::string>;
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) {
Expand Down

0 comments on commit 9c6f10d

Please sign in to comment.