From fa71fbd8e33f5211e3af7b2da85f2e1b0265c31a Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Fri, 27 Dec 2024 13:54:56 -0800 Subject: [PATCH] Add unit test for HDF5IO::getStorageObjectType --- tests/testHDF5IO.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/testHDF5IO.cpp b/tests/testHDF5IO.cpp index 6fb4d63a..0de57ed4 100644 --- a/tests/testHDF5IO.cpp +++ b/tests/testHDF5IO.cpp @@ -839,6 +839,65 @@ TEST_CASE("HDF5IOI::attributeExists", "[hdf5io]") REQUIRE(hdf5io.attributeExists("/data/existingReferenceAttribute") == true); } + // close file + hdf5io.close(); +} + +TEST_CASE("getStorageObjectType", "[hdf5io]") +{ + // create and open file + std::string filename = getTestFilePath("test_getStorageObjectType.h5"); + IO::HDF5::HDF5IO hdf5io(filename); + hdf5io.open(); + + SECTION("group") + { + hdf5io.createGroup("/testGroup"); + REQUIRE(hdf5io.getStorageObjectType("/testGroup") + == StorageObjectType::Group); + } + + SECTION("dataset") + { + hdf5io.createArrayDataSet( + BaseDataType::I32, SizeArray {0}, SizeArray {1}, "/testDataset"); + REQUIRE(hdf5io.getStorageObjectType("/testDataset") + == StorageObjectType::Dataset); + } + + SECTION("attribute") + { + hdf5io.createGroup("/groupWithAttribute"); + const int data = 1; + hdf5io.createAttribute( + BaseDataType::I32, &data, "/groupWithAttribute", "testAttribute"); + REQUIRE(hdf5io.getStorageObjectType("/groupWithAttribute/testAttribute") + == StorageObjectType::Attribute); + } + + SECTION("non-existing object") + { + REQUIRE(hdf5io.getStorageObjectType("/nonExistingObject") + == StorageObjectType::Undefined); + } + + SECTION("link to group") + { + hdf5io.createGroup("/originalGroup"); + hdf5io.createLink("/linkToGroup", "/originalGroup"); + REQUIRE(hdf5io.getStorageObjectType("/linkToGroup") + == StorageObjectType::Group); + } + + SECTION("link to dataset") + { + hdf5io.createArrayDataSet( + BaseDataType::I32, SizeArray {0}, SizeArray {1}, "/originalDataset"); + hdf5io.createLink("/linkToDataset", "/originalDataset"); + REQUIRE(hdf5io.getStorageObjectType("/linkToDataset") + == StorageObjectType::Dataset); + } + // close file hdf5io.close(); } \ No newline at end of file