Skip to content

Commit

Permalink
Add unit tests for HDF5IO::attributeExists
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel committed Dec 27, 2024
1 parent 8d08722 commit f56ea72
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/testHDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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();
}

0 comments on commit f56ea72

Please sign in to comment.