diff --git a/repertory/repertory_test/src/providers_test.cpp b/repertory/repertory_test/src/providers_test.cpp index dc5f2f83..5c5974a4 100644 --- a/repertory/repertory_test/src/providers_test.cpp +++ b/repertory/repertory_test/src/providers_test.cpp @@ -173,6 +173,35 @@ const auto decrypt_parts = [](const repertory::app_config &cfg, path = repertory::utils::string::join(parts, '/'); } }; + +[[nodiscard]] auto read_all_plain(const std::string &path) -> std::string { + repertory::utils::file::file file{path}; + auto data = file.read_all(); + EXPECT_TRUE(data.has_value()); + return data.value_or(std::string{}); +} + +[[nodiscard]] auto chunked_read_bytes(repertory::i_provider &provider, + const std::string &api_path, + std::uint64_t total) -> std::string { + std::string out{}; + std::uint64_t off = 0U; + static constexpr std::uint64_t chunks[] = {1U, 7U, 64U, 3U, 1024U, 5U}; + std::size_t idx = 0U; + + while (off < total) { + const auto want = + std::min(chunks[idx % std::size(chunks)], total - off); + std::string part{}; + EXPECT_EQ(api_error::success, + provider.read_file_bytes(api_path, off, want, part)); + EXPECT_EQ(want, static_cast(part.size())); + out.append(part); + off += want; + ++idx; + } + return out; +} } // namespace namespace repertory { @@ -1139,7 +1168,7 @@ static void get_pinned_files(i_provider &provider) { app_config::get_provider_name(provider.get_provider_type()), __FUNCTION__); if (provider.is_read_only()) { - auto pinned= provider.get_pinned_files()); + auto pinned = provider.get_pinned_files(); EXPECT_TRUE(pinned.empty()); return; } @@ -1306,14 +1335,12 @@ static void get_used_drive_space(i_provider &provider) { sum_sizes += size; } - std::uint64_t used{}; - EXPECT_EQ(api_error::success, provider.get_used_drive_space(used)); + std::uint64_t used{provider.get_used_drive_space()}; EXPECT_EQ(sum_sizes, used); return; } - std::uint64_t before{}; - EXPECT_EQ(api_error::success, provider.get_used_drive_space(before)); + std::uint64_t before{provider.get_used_drive_space()}; auto &file1 = test::create_random_file(96U); auto &file2 = test::create_random_file(128U); @@ -1339,15 +1366,13 @@ static void get_used_drive_space(i_provider &provider) { provider.set_item_meta(api_path2, META_SIZE, std::to_string(*file2.size()))); - std::uint64_t mid{}; - EXPECT_EQ(api_error::success, provider.get_used_drive_space(mid)); + std::uint64_t mid{provider.get_used_drive_space()}; EXPECT_EQ(before + *file1.size() + *file2.size(), mid); EXPECT_EQ(api_error::success, provider.remove_file(api_path1)); EXPECT_EQ(api_error::success, provider.remove_file(api_path2)); - std::uint64_t after{}; - EXPECT_EQ(api_error::success, provider.get_used_drive_space(after)); + std::uint64_t after{provider.get_used_drive_space()}; EXPECT_EQ(before, after); } @@ -1360,8 +1385,7 @@ static void get_total_drive_space(i_provider &provider) { auto res_total = provider.get_total_drive_space(total); EXPECT_EQ(api_error::success, res_total); - std::uint64_t used{}; - EXPECT_EQ(api_error::success, provider.get_used_drive_space(used)); + std::uint64_t used{provider.get_used_drive_space(used)}; if (total != 0U) { EXPECT_GE(total, used);