|
20 | 20 | #include <cstdlib>
|
21 | 21 | #include <fstream>
|
22 | 22 | #include <functional>
|
| 23 | +#include <memory> |
23 | 24 | #include <numeric>
|
24 | 25 | #include <sstream>
|
25 | 26 | #include <vector>
|
@@ -525,22 +526,21 @@ TEST_CASE("mongocxx::gridfs::downloader::read with arbitrary sizes", "[gridfs::d
|
525 | 526 | std::int32_t read_size = 0;
|
526 | 527 |
|
527 | 528 | auto run_test = [&]() {
|
528 | | - REQUIRE(read_size != 0); |
| 529 | + REQUIRE(read_size > 0); |
529 | 530 |
|
530 | 531 | bsoncxx::types::bson_value::view id{bsoncxx::types::b_oid{bsoncxx::oid{}}};
|
531 | 532 | std::vector<std::uint8_t> expected = manual_gridfs_initialize(db, file_length, chunk_size, id);
|
532 | 533 |
|
533 | 534 | // Allocate a buffer large enough to fit the data read from the downloader.
|
534 | | - std::vector<std::uint8_t> buffer; |
535 | | - buffer.reserve(static_cast<std::size_t>(read_size)); |
| 535 | + std::unique_ptr<std::uint8_t[]> buffer{new std::uint8_t[static_cast<std::size_t>(read_size)]}; |
536 | 536 |
|
537 | 537 | std::size_t total_bytes_read = 0;
|
538 | 538 | auto downloader = bucket.open_download_stream(bsoncxx::types::bson_value::view{id});
|
539 | 539 |
|
540 | | - while (std::size_t bytes_read = downloader.read(buffer.data(), static_cast<std::size_t>(read_size))) { |
| 540 | + while (std::size_t bytes_read = downloader.read(buffer.get(), static_cast<std::size_t>(read_size))) { |
541 | 541 | std::vector<std::uint8_t> expected_bytes{
|
542 | 542 | expected.data() + total_bytes_read, expected.data() + total_bytes_read + bytes_read};
|
543 | | - std::vector<std::uint8_t> actual_bytes{buffer.data(), buffer.data() + bytes_read}; |
| 543 | + std::vector<std::uint8_t> actual_bytes{buffer.get(), buffer.get() + bytes_read}; |
544 | 544 |
|
545 | 545 | REQUIRE(expected_bytes == actual_bytes);
|
546 | 546 |
|
|
0 commit comments