From 4d29353599f16dd07e58f992ff41a05a16239242 Mon Sep 17 00:00:00 2001 From: Faruk Eryilmaz Date: Tue, 9 Jan 2024 20:49:37 +0300 Subject: [PATCH] update string unit tests to cover fully filled buffer and buffer_view creation with given void type --- test/string_test.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/string_test.cpp b/test/string_test.cpp index 72685c4..02350a7 100644 --- a/test/string_test.cpp +++ b/test/string_test.cpp @@ -6,28 +6,34 @@ TEST_CASE("String and string view (big-endian)") { std::string str = "Hello World!"; std::string_view str2 = "bytepack library"; + std::string str3 = "bytepack"; - bytepack::binary_stream bstream(1024); + bytepack::binary_stream bstream(43); bstream.write(str); bstream.write(str2); + bstream.write(str3); std::string str_{}; std::string str2_{}; // string_view cannot be read into directly (it's a reference) + std::string str3_{}; auto buffer = bstream.data(); bytepack::binary_stream bstream_(buffer); bstream_.read(str_); bstream_.read(str2_); + bstream_.read(str3_); - // 4 bytes for the size of the string, 12 bytes for the string itself - // 2 bytes for the custom size of the string_view, 16 bytes for the string_view itself - // 34 bytes in total - REQUIRE(34 == buffer.size()); + // 4 bytes for the size of the str, 12 bytes for the string itself + // 2 bytes for the custom size of the str2 string_view, 16 bytes for the string_view itself + // 8 bytes for the size of the str3, 1 byte for the null terminator '\0' + // 43 bytes in total + REQUIRE(43 == buffer.size()); REQUIRE(str == str_); REQUIRE(str2 == str2_); + REQUIRE(str3 == str3_); } TEST_CASE("String and string view (little-endian)") @@ -124,7 +130,8 @@ TEST_CASE("String and string view null terminated (little-endian)") double num1_{}; auto buffer = bstream.data(); - bytepack::binary_stream bstream_(buffer); + auto buff = bytepack::buffer_view(buffer.as(), buffer.size()); + bytepack::binary_stream bstream_(buff); bstream_.read(str_); bstream_.read(num1_);