From b7c5028daf5ae90542a55a91936450a4319edc9a Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 2 Jan 2024 15:45:54 -0500 Subject: [PATCH] add missing forward declaration for packing/unpacking dynamic_bitset; add tests --- libraries/libfc/include/fc/io/raw.hpp | 2 ++ libraries/libfc/test/CMakeLists.txt | 1 + libraries/libfc/test/io/test_raw.cpp | 38 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 libraries/libfc/test/io/test_raw.cpp diff --git a/libraries/libfc/include/fc/io/raw.hpp b/libraries/libfc/include/fc/io/raw.hpp index 171d8f97f0..f63bcfa2f1 100644 --- a/libraries/libfc/include/fc/io/raw.hpp +++ b/libraries/libfc/include/fc/io/raw.hpp @@ -35,6 +35,8 @@ namespace fc { template void unpack( Stream& s, Int<256>& n ); template void pack( Stream& s, const boost::multiprecision::number& n ); template void unpack( Stream& s, boost::multiprecision::number& n ); + template void pack( Stream& s, const boost::dynamic_bitset& bs ); + template void unpack( Stream& s, boost::dynamic_bitset& bs ); template inline void pack( Stream& s, const Arg0& a0, const Args&... args ) { diff --git a/libraries/libfc/test/CMakeLists.txt b/libraries/libfc/test/CMakeLists.txt index 0c33b8fab9..205ebffc7b 100644 --- a/libraries/libfc/test/CMakeLists.txt +++ b/libraries/libfc/test/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable( test_fc crypto/test_webauthn.cpp io/test_cfile.cpp io/test_json.cpp + io/test_raw.cpp io/test_tracked_storage.cpp network/test_message_buffer.cpp scoped_exit/test_scoped_exit.cpp diff --git a/libraries/libfc/test/io/test_raw.cpp b/libraries/libfc/test/io/test_raw.cpp new file mode 100644 index 0000000000..0ff902a97a --- /dev/null +++ b/libraries/libfc/test/io/test_raw.cpp @@ -0,0 +1,38 @@ +#include +#include + +#include +#include + +using namespace fc; + +BOOST_AUTO_TEST_SUITE(raw_test_suite) + + +BOOST_AUTO_TEST_CASE(dynamic_bitset_test) +{ + constexpr uint8_t bits = 0b00011110; + boost::dynamic_bitset bs1(8, bits); // bit set size 8 + + char buff[4]; + datastream ds(buff, sizeof(buff)); + + fc::raw::pack( ds, bs1 ); + + boost::dynamic_bitset bs2(8); + ds.seekp(0); + fc::raw::unpack( ds, bs2 ); + + // 0b00011110 + BOOST_CHECK(!bs2.test(0)); + BOOST_CHECK(bs2.test(1)); + BOOST_CHECK(bs2.test(2)); + BOOST_CHECK(bs2.test(2)); + BOOST_CHECK(bs2.test(3)); + BOOST_CHECK(bs2.test(4)); + BOOST_CHECK(!bs2.test(5)); + BOOST_CHECK(!bs2.test(6)); + BOOST_CHECK(!bs2.test(7)); +} + +BOOST_AUTO_TEST_SUITE_END()