diff --git a/src/include/test/unit_tdb_io.cc b/src/include/test/unit_tdb_io.cc index 193eef5be..c6dcafa36 100644 --- a/src/include/test/unit_tdb_io.cc +++ b/src/include/test/unit_tdb_io.cc @@ -291,17 +291,31 @@ TEST_CASE("read vector slices", "[tdb_io]") { std::iota(begin(vector), end(vector), 0); write_vector(ctx, vector, uri); - auto result = read_vector(ctx, uri); - CHECK(vector == result); - - std::vector> slices; - slices.push_back({0, 1}); // 2 elements. - slices.push_back({3, 3}); // 1 element. - slices.push_back({50, 60}); // 11 elements - size_t total_slices_size = 14; - - auto result_slice = read_vector(ctx, uri, slices, total_slices_size); - auto expected = - std::vector{0, 1, 3, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}; - CHECK(result_slice == expected); + // We can read the entire vector. + { + auto result = read_vector(ctx, uri); + CHECK(vector == result); + } + + // We can read slices of the vector. + { + std::vector> slices; + slices.push_back({0, 1}); // 2 elements. + slices.push_back({3, 3}); // 1 element. + slices.push_back({50, 60}); // 11 elements + size_t total_slices_size = 14; + + auto result_slice = read_vector(ctx, uri, slices, total_slices_size); + auto expected = + std::vector{0, 1, 3, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}; + CHECK(result_slice == expected); + } + + // We don't crash with empty slices. + { + std::vector> slices; + size_t total_slices_size = 0; + auto result_slice = read_vector(ctx, uri, slices, total_slices_size); + CHECK(result_slice.empty()); + } }