From f56ea7249e2610846aac2ca372cbc3a1d167e57f Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Fri, 27 Dec 2024 13:39:09 -0800 Subject: [PATCH] Add unit tests for HDF5IO::attributeExists --- tests/testHDF5IO.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/testHDF5IO.cpp b/tests/testHDF5IO.cpp index 3b815a47..2716ecf5 100644 --- a/tests/testHDF5IO.cpp +++ b/tests/testHDF5IO.cpp @@ -757,6 +757,55 @@ TEST_CASE("HDF5IO::objectExists", "[hdf5io]") == false); } + // close file + hdf5io.close(); +} + +TEST_CASE("HDF5IOI::attributeExists", "[hdf5io]") +{ + // create and open file + std::string filename = getTestFilePath("test_attributeExists.h5"); + IO::HDF5::HDF5IO hdf5io(filename); + hdf5io.open(); + + hdf5io.createGroup("/data"); + + SECTION("existing attribute") + { + const int data = 1; + hdf5io.createAttribute( + BaseDataType::I32, &data, "/data", "existingAttribute"); + REQUIRE(hdf5io.attributeExists("/data/existingAttribute") == true); + } + + SECTION("non-existing attribute") + { + REQUIRE(hdf5io.attributeExists("/data/nonExistingAttribute") == false); + } + + SECTION("existing string attribute") + { + const std::string data = "test_string"; + hdf5io.createAttribute(data, "/data", "existingStringAttribute"); + REQUIRE(hdf5io.attributeExists("/data/existingStringAttribute") == true); + } + + SECTION("existing string array attribute") + { + const std::vector data = {"str1", "str2", "str3"}; + hdf5io.createAttribute(data, "/data", "existingStringArrayAttribute"); + REQUIRE(hdf5io.attributeExists("/data/existingStringArrayAttribute") + == true); + } + + SECTION("existing reference attribute") + { + hdf5io.createGroup("/referenceTarget"); + hdf5io.createReferenceAttribute( + "/referenceTarget", "/data", "existingReferenceAttribute"); + REQUIRE(hdf5io.attributeExists("/data/existingReferenceAttribute") == true); + } + // close file hdf5io.close(); } \ No newline at end of file