diff --git a/components/core/tests/test-BoundedReader.cpp b/components/core/tests/test-BoundedReader.cpp index de489b655..9d1a9d2c0 100644 --- a/components/core/tests/test-BoundedReader.cpp +++ b/components/core/tests/test-BoundedReader.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -9,13 +10,12 @@ #include "../src/clp/StringReader.hpp" TEST_CASE("Test Bounded Reader", "[BoundedReader]") { - constexpr char cTestString[]{"0123456789"}; - constexpr size_t cTestStringLen{std::char_traits::length(cTestString)}; + constexpr std::string_view cTestString{"0123456789"}; SECTION("BoundedReader does not support try_read_to_delimiter") { clp::StringReader string_reader; - string_reader.open(cTestString); - clp::BoundedReader bounded_reader{&string_reader, cTestStringLen}; + string_reader.open(std::string{cTestString}); + clp::BoundedReader bounded_reader{&string_reader, cTestString.size()}; std::string tmp; REQUIRE(clp::ErrorCode_Unsupported == bounded_reader.try_read_to_delimiter('0', false, false, tmp)); @@ -23,24 +23,24 @@ TEST_CASE("Test Bounded Reader", "[BoundedReader]") { SECTION("BoundedReader does not allow reads beyond end of underlying stream.") { clp::StringReader string_reader; - string_reader.open(cTestString); - clp::BoundedReader bounded_reader{&string_reader, cTestStringLen + 1}; - std::array buf{}; + string_reader.open(std::string{cTestString}); + clp::BoundedReader bounded_reader{&string_reader, cTestString.size() + 1}; + std::array buf{}; size_t num_bytes_read{}; - auto rc = bounded_reader.try_read(buf.data(), cTestStringLen + 1, num_bytes_read); + auto rc = bounded_reader.try_read(buf.data(), cTestString.size() + 1, num_bytes_read); REQUIRE(clp::ErrorCode_Success == rc); - REQUIRE(num_bytes_read == cTestStringLen); - REQUIRE(cTestStringLen == string_reader.get_pos()); - REQUIRE(cTestStringLen == bounded_reader.get_pos()); + REQUIRE(num_bytes_read == cTestString.size()); + REQUIRE(cTestString.size() == string_reader.get_pos()); + REQUIRE(cTestString.size() == bounded_reader.get_pos()); } SECTION("BoundedReader does not allow reads beyond checkpoint.") { clp::StringReader string_reader; - string_reader.open(cTestString); + string_reader.open(std::string{cTestString}); clp::BoundedReader bounded_reader{&string_reader, 1}; - std::array buf{}; + std::array buf{}; size_t num_bytes_read{}; - auto rc = bounded_reader.try_read(buf.data(), cTestStringLen, num_bytes_read); + auto rc = bounded_reader.try_read(buf.data(), cTestString.size(), num_bytes_read); REQUIRE(clp::ErrorCode_Success == rc); REQUIRE(1 == num_bytes_read); REQUIRE(1 == string_reader.get_pos()); @@ -54,7 +54,7 @@ TEST_CASE("Test Bounded Reader", "[BoundedReader]") { SECTION("BoundedReader does allow reads before checkpoint.") { clp::StringReader string_reader; - string_reader.open(cTestString); + string_reader.open(std::string{cTestString}); clp::BoundedReader bounded_reader{&string_reader, 1}; char buf{}; size_t num_bytes_read{}; @@ -67,20 +67,20 @@ TEST_CASE("Test Bounded Reader", "[BoundedReader]") { SECTION("BoundedReader does not allow seeks beyond end of underlying stream.") { clp::StringReader string_reader; - string_reader.open(cTestString); - clp::BoundedReader bounded_reader{&string_reader, cTestStringLen + 1}; - auto rc = bounded_reader.try_seek_from_begin(cTestStringLen + 1); + string_reader.open(std::string{cTestString}); + clp::BoundedReader bounded_reader{&string_reader, cTestString.size() + 1}; + auto rc = bounded_reader.try_seek_from_begin(cTestString.size() + 1); REQUIRE(clp::ErrorCode_EndOfFile == rc); - REQUIRE(cTestStringLen == string_reader.get_pos()); - REQUIRE(cTestStringLen == bounded_reader.get_pos()); + REQUIRE(cTestString.size() == string_reader.get_pos()); + REQUIRE(cTestString.size() == bounded_reader.get_pos()); } SECTION("BoundedReader does not allow seeks beyond checkpoint.") { clp::StringReader string_reader; - string_reader.open(cTestString); + string_reader.open(std::string{cTestString}); clp::BoundedReader bounded_reader{&string_reader, 1}; size_t num_bytes_read{}; - auto rc = bounded_reader.try_seek_from_begin(cTestStringLen); + auto rc = bounded_reader.try_seek_from_begin(cTestString.size()); REQUIRE(clp::ErrorCode_EndOfFile == rc); REQUIRE(1 == string_reader.get_pos()); REQUIRE(1 == bounded_reader.get_pos()); @@ -88,7 +88,7 @@ TEST_CASE("Test Bounded Reader", "[BoundedReader]") { SECTION("BoundedReader does allow seeks before checkpoint.") { clp::StringReader string_reader; - string_reader.open(cTestString); + string_reader.open(std::string{cTestString}); clp::BoundedReader bounded_reader{&string_reader, 2}; size_t num_bytes_read{}; auto rc = bounded_reader.try_seek_from_begin(1);