Skip to content

Commit

Permalink
Test `std::vector<char*>.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed May 11, 2024
1 parent 5afd834 commit 6a95962
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/unit/test_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,31 @@ TEST_CASE("HighFiveReadWriteConsts") {
}
}
}

TEST_CASE("Fixed Length String, array of pointer") {
// Currently, serializing an `std::vector<char*>` as
// fixed length strings doesn't work.
//
// This isn't a test of correctness. Rather it asserts a fact about
// HighFive (that could reasonably 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});
auto datatype = FixedLengthStringType(n_chars, StringPadding::NullTerminated);

auto dset = file.createDataSet("dset", filespace, datatype);
dset.write(strings);
}

0 comments on commit 6a95962

Please sign in to comment.