summaryrefslogtreecommitdiffhomepage
path: root/serialize/binary-serializer.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-17 06:48:48 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-17 23:23:11 +0100
commit34a0239ad6e6d84bd0027d9029d0d74419247d01 (patch)
treeecdd451e6243996e36b6a6af6a2ac3010edfba70 /serialize/binary-serializer.cpp
parent56c15ab0db6c12f34b27325069b2bd97e1db4954 (diff)
serialize/reader: add test
Diffstat (limited to 'serialize/binary-serializer.cpp')
-rw-r--r--serialize/binary-serializer.cpp26
1 files 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<char, 4> 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<char, 4> bytes = { 4, 3, 2, 1 };
auto r = binary_reader(bytes.cbegin(), bytes.cend());
@@ -31,7 +33,7 @@ using test4 = binary_writer<std::array<char, sizeof(int)>::iterator>;
static_assert(std::is_same_v<test4&, decltype( std::declval<test4&>() << int() )>);
[[maybe_unused]]
-static constexpr bool test5()
+constexpr bool test5()
{
std::array<char, 4> 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<char, 5> 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