Skip to content

Commit

Permalink
Add HDF5IO::readAttriute unit test for reading attribute from a dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel committed Dec 28, 2024
1 parent 2b26343 commit 85cdf23
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/testHDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,33 @@ TEST_CASE("readAttribute", "[hdf5io]")
H5Gclose(ref_group_id);
}

// TODO: Does not compile
SECTION("read attribute from dataset")
{
// Define the dimensions and chunking for the dataset
SizeArray dims = {10};
SizeArray chunking = {10};

// Create the dataset using createArrayDataSet
auto dataset = hdf5io.createArrayDataSet(
BaseDataType::I32, dims, chunking, "/data/dataset");

// Define and create the attribute
const int32_t writeData = 123;
hdf5io.createAttribute(
BaseDataType::I32, &writeData, "/data/dataset", "datasetAttribute");

// Read the attribute
auto readDataGeneric =
hdf5io.readAttribute("/data/dataset/datasetAttribute");
auto readData = IO::DataBlock<int32_t>::fromGeneric(readDataGeneric);

// Verify the attribute data
REQUIRE(readData.shape.empty()); // Scalar attribute
REQUIRE(readData.data.size() == 1);
REQUIRE(readData.data[0] == writeData);
}

SECTION("read non-existent attribute")
{
REQUIRE_THROWS_AS(hdf5io.readAttribute("/data/nonExistentAttribute"),
Expand Down

0 comments on commit 85cdf23

Please sign in to comment.