Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test `std::vector<char*>. #998

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/unit/test_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,39 @@ TEST_CASE("HighFiveReadWriteConsts") {
}
}
}

TEST_CASE("Array of char pointers") {
// Currently, serializing an `std::vector<char*>` as
// fixed or variable length strings doesn't work.
//
// This isn't a test of correctness. Rather it asserts the fact that
// something doesn't work in HighFive. Knowing it doesn't work is useful
// for developers, but could change in the future.

const std::string file_name = "vector_char_pointer.h5";

File file(file_name, File::Truncate);

size_t n_strings = 3;
size_t n_chars = 4;
char storage[3][4] = {"foo", "bar", "000"};
auto strings = std::vector<char*>(n_strings);

for (size_t i = 0; i < n_strings; ++i) {
strings[i] = static_cast<char*>(storage[i]);
}

auto filespace = DataSpace({n_strings});

SECTION("fixed length") {
auto datatype = FixedLengthStringType(n_chars, StringPadding::NullTerminated);
auto dset = file.createDataSet("dset", filespace, datatype);
REQUIRE_THROWS(dset.write(strings));
}

SECTION("variable length") {
auto datatype = VariableLengthStringType();
auto dset = file.createDataSet("dset", filespace, datatype);
REQUIRE_THROWS(dset.write(strings));
}
}
Loading