From 34a0239ad6e6d84bd0027d9029d0d74419247d01 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 17 Mar 2023 06:48:48 +0100 Subject: serialize/reader: add test --- serialize/binary-serializer.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/serialize/binary-serializer.cpp b/serialize/binary-serializer.cpp index 351febd0..f145c0b3 100644 --- a/serialize/binary-serializer.cpp +++ b/serialize/binary-serializer.cpp @@ -4,8 +4,10 @@ namespace floormat::Serialize { +namespace { + [[maybe_unused]] -static constexpr bool test1() +constexpr bool test1() { constexpr std::array bytes = { 1, 2, 3, 4 }; auto x = binary_reader(bytes.cbegin(), bytes.cend()); @@ -14,7 +16,7 @@ static constexpr bool test1() static_assert(test1()); [[maybe_unused]] -static constexpr bool test2() +constexpr bool test2() { constexpr std::array bytes = { 4, 3, 2, 1 }; auto r = binary_reader(bytes.cbegin(), bytes.cend()); @@ -31,7 +33,7 @@ using test4 = binary_writer::iterator>; static_assert(std::is_same_v() << int() )>); [[maybe_unused]] -static constexpr bool test5() +constexpr bool test5() { std::array bytes = {}; auto w = binary_writer(bytes.begin()); @@ -43,4 +45,22 @@ static constexpr bool test5() } static_assert(test5()); +[[maybe_unused]] +constexpr bool test6() +{ + std::array bytes = { + 'f', 'o', 'o', '\0', 42, + }; + auto r = binary_reader(bytes.cbegin(), bytes.cend()); + fm_assert(r.read_asciiz_string<4>() == "foo"_s); + unsigned char b = 0; + b << r; + fm_assert(b == 42); + r.assert_end(); + return true; +} +static_assert(test6()); + +} // namespace + } // namespace floormat::Serialize -- cgit v1.2.3