diff --git a/src/h5cpp/property/file_access.cpp b/src/h5cpp/property/file_access.cpp index 774f696f50..6b610635a7 100644 --- a/src/h5cpp/property/file_access.cpp +++ b/src/h5cpp/property/file_access.cpp @@ -36,7 +36,20 @@ namespace property { std::ostream &operator<<(std::ostream &stream, const LibVersion &version) { switch (version) { case LibVersion::Earliest: return stream << "EARLIEST"; +#if H5_VERSION_LE(1,10,1) + // starting with 1.10.2 "Latest" is mapped to the specific latest version case LibVersion::Latest: return stream << "LATEST"; +#endif +#if H5_VERSION_GE(1,10,2) + case LibVersion::V18: return stream << "V18"; + case LibVersion::V110: return stream << "V110"; +#endif +#if H5_VERSION_GE(1,12,0) + case LibVersion::V112: return stream << "V112"; +#endif +#if H5_VERSION_GE(1,13,0) + case LibVersion::V114: return stream << "V114"; +#endif } return stream; } diff --git a/src/h5cpp/property/file_access.hpp b/src/h5cpp/property/file_access.hpp index 8ffa159ae8..7926a78fa2 100644 --- a/src/h5cpp/property/file_access.hpp +++ b/src/h5cpp/property/file_access.hpp @@ -39,6 +39,16 @@ namespace property { //! enum class LibVersion : std::underlying_type::type { Latest = H5F_LIBVER_LATEST, +#if H5_VERSION_GE(1,10,2) + V18 = H5F_LIBVER_V18, + V110 = H5F_LIBVER_V110, +#endif +#if H5_VERSION_GE(1,12,0) + V112 = H5F_LIBVER_V112, +#endif +#if H5_VERSION_GE(1,13,0) + V114 = H5F_LIBVER_V114, +#endif Earliest = H5F_LIBVER_EARLIEST }; diff --git a/test/property/file_access_test.cpp b/test/property/file_access_test.cpp index d48d9a4a56..8e3050b9a3 100644 --- a/test/property/file_access_test.cpp +++ b/test/property/file_access_test.cpp @@ -35,18 +35,38 @@ #include #include #include +#include #include +#include #include "../utilities.hpp" #include "utilities.hpp" namespace pl = hdf5::property; +// we need to define these test cases outside of any catch2 MACRO as '#if'-directives inside a +// macro are not portable +// tuple contents: (library version enum value, library version string representation) +const std::initializer_list> lib_version_to_strings { +#if H5_VERSION_GE(1,10,2) + {pl::LibVersion::V18, "V18"}, + {pl::LibVersion::V110, "V110"}, +#endif +#if H5_VERSION_GE(1,12,0) + {pl::LibVersion::V112, "V112"}, +#endif +#if H5_VERSION_GE(1,13,0) + {pl::LibVersion::V114, "V114"}, +#endif +#if H5_VERSION_LE(1,10,1) + // starting with 1.10.2 "Latest" is reported as the specific latest version + {pl::LibVersion::Latests, "LATEST"}, +#endif + {pl::LibVersion::Earliest, "EARLIEST"} +}; + SCENARIO("Writing file access associated enumerations to a stream") { GIVEN("library version values") { - using r = std::tuple; - auto versions = GENERATE(table( - {r{pl::LibVersion::Earliest, "EARLIEST"}, - r{pl::LibVersion::Latest, "LATEST"}})); + auto versions = GENERATE(table(lib_version_to_strings)); THEN("writing this to the stream") { std::stringstream s; s << std::get<0>(versions); @@ -103,33 +123,72 @@ SCENARIO("FileAccessList creation") { } } +// we need to define these test cases outside of any catch2 MACRO as '#if'-directives inside a +// macro are not portable +// tuple contents: (lower version number, upper version number, valid) +const std::initializer_list> + lib_version_compatibility_list { + {pl::LibVersion::Earliest, pl::LibVersion::Earliest, false}, +#if H5_VERSION_GE(1,10,2) + {pl::LibVersion::Earliest, pl::LibVersion::V18, true}, + {pl::LibVersion::Earliest, pl::LibVersion::V110, true}, + {pl::LibVersion::V18, pl::LibVersion::Earliest, false}, + {pl::LibVersion::V18, pl::LibVersion::V18, true}, + {pl::LibVersion::V18, pl::LibVersion::V110, true}, + {pl::LibVersion::V110, pl::LibVersion::Earliest, false}, + {pl::LibVersion::V110, pl::LibVersion::V18, false}, + {pl::LibVersion::V110, pl::LibVersion::V110, true}, +#endif +#if H5_VERSION_GE(1,12,0) + {pl::LibVersion::Earliest, pl::LibVersion::V112, true}, + {pl::LibVersion::V18, pl::LibVersion::V112, true}, + {pl::LibVersion::V110, pl::LibVersion::V112, true}, + {pl::LibVersion::V112, pl::LibVersion::Earliest, false}, + {pl::LibVersion::V112, pl::LibVersion::V18, false}, + {pl::LibVersion::V112, pl::LibVersion::V110, false}, + {pl::LibVersion::V112, pl::LibVersion::V112, true}, +#endif +#if H5_VERSION_GE(1,13,0) + {pl::LibVersion::Earliest, pl::LibVersion::V114, true}, + {pl::LibVersion::V18, pl::LibVersion::V114, true}, + {pl::LibVersion::V110, pl::LibVersion::V114, true}, + {pl::LibVersion::V112, pl::LibVersion::V114, true}, + {pl::LibVersion::V114, pl::LibVersion::Earliest, false}, + {pl::LibVersion::V114, pl::LibVersion::V18, false}, + {pl::LibVersion::V114, pl::LibVersion::V110, false}, + {pl::LibVersion::V114, pl::LibVersion::V112, false}, + {pl::LibVersion::V114, pl::LibVersion::V114, true}, +#endif + {pl::LibVersion::Earliest, pl::LibVersion::Latest, true}, + {pl::LibVersion::Latest, pl::LibVersion::Latest, true} +}; + SCENARIO("Setting the library version on a file access property list") { GIVEN("a default constructed file access property list") { pl::FileAccessList fapl; - WHEN("seting thel LATEST, LATEST ") { - REQUIRE_NOTHROW(fapl.library_version_bounds(pl::LibVersion::Latest, - pl::LibVersion::Latest)); - REQUIRE(fapl.library_version_bound_low() == pl::LibVersion::Latest); - REQUIRE(fapl.library_version_bound_high() == pl::LibVersion::Latest); - } - WHEN("seting EARLIEST:LATEST") { - REQUIRE_NOTHROW(fapl.library_version_bounds(pl::LibVersion::Earliest, - pl::LibVersion::Latest)); - REQUIRE(fapl.library_version_bound_low() == pl::LibVersion::Earliest); - REQUIRE(fapl.library_version_bound_high() == pl::LibVersion::Latest); - } - WHEN("setting EARLIEST:EARLIST") { - THEN("the operation must fail") { - REQUIRE_THROWS_AS(fapl.library_version_bounds(pl::LibVersion::Earliest, - pl::LibVersion::Earliest), - std::runtime_error); + + auto versions = + GENERATE(table(lib_version_compatibility_list)); + + const auto lower_ver = std::get<0>(versions); + const auto upper_ver = std::get<1>(versions); + const auto valid_combination = std::get<2>(versions); + + std::stringstream ss; + ss << "setting " << lower_ver << ":" << upper_ver; + + WHEN(ss.str()) { + if(valid_combination){ + REQUIRE_NOTHROW(fapl.library_version_bounds(lower_ver, upper_ver)); + REQUIRE(fapl.library_version_bound_low() == lower_ver); + REQUIRE(fapl.library_version_bound_high() == upper_ver); } - } - WHEN("setting LATEST:EARLIEST") { - THEN("the operation must fail") { - REQUIRE_THROWS_AS(fapl.library_version_bounds(pl::LibVersion::Latest, + else { + THEN("the operation must fail") { + REQUIRE_THROWS_AS(fapl.library_version_bounds(pl::LibVersion::Earliest, pl::LibVersion::Earliest), std::runtime_error); + } } } }