diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-20 10:17:42 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-21 14:46:30 +0100 |
commit | 5979976e6ac3d64263e306d3c253d54f0b6748fd (patch) | |
tree | a0bd6b2ad251a7bece95a7dcb51cfdcbf3403227 /test/utils/cpp/incremental_reader.test.cpp | |
parent | 86eb98393ab87989cc9752506adba9786c635c5a (diff) | |
download | justbuild-5979976e6ac3d64263e306d3c253d54f0b6748fd.tar.gz |
IncrementalReader: Test reading from memory
Diffstat (limited to 'test/utils/cpp/incremental_reader.test.cpp')
-rw-r--r-- | test/utils/cpp/incremental_reader.test.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/utils/cpp/incremental_reader.test.cpp b/test/utils/cpp/incremental_reader.test.cpp index 4f362351..96c4bcb5 100644 --- a/test/utils/cpp/incremental_reader.test.cpp +++ b/test/utils/cpp/incremental_reader.test.cpp @@ -93,6 +93,32 @@ TEST_CASE("IncrementalReader", "[incremental_reader]") { REQUIRE(result.size() == file_content->size()); REQUIRE(result == *file_content); } + SECTION("Memory") { + auto reader = + IncrementalReader::FromMemory(kChunkWithRemainder, &*file_content); + REQUIRE(reader.has_value()); + + std::string result; + result.reserve(reader->GetContentSize()); + for (auto chunk : *reader) { + REQUIRE(chunk.has_value()); + result.append(*chunk); + } + REQUIRE(result.size() == file_content->size()); + REQUIRE(result == *file_content); + + reader = IncrementalReader::FromMemory(kChunkWithoutRemainder, + &*file_content); + REQUIRE(reader.has_value()); + + result.clear(); + for (auto chunk : *reader) { + REQUIRE(chunk.has_value()); + result.append(*chunk); + } + REQUIRE(result.size() == file_content->size()); + REQUIRE(result == *file_content); + } } TEST_CASE("IncrementalReader - Empty", "[incremental_reader]") { @@ -122,4 +148,20 @@ TEST_CASE("IncrementalReader - Empty", "[incremental_reader]") { REQUIRE(result.has_value()); REQUIRE(result->empty()); } + SECTION("Memory") { + std::string const empty; + auto const reader = IncrementalReader::FromMemory(kChunkSize, &empty); + REQUIRE(reader.has_value()); + + std::optional<std::string> result; + for (auto chunk : *reader) { + REQUIRE(chunk.has_value()); + if (not result.has_value()) { + result = std::string{}; + } + result->append(*chunk); + } + REQUIRE(result.has_value()); + REQUIRE(result->empty()); + } } |