From c6d1194bd74e7ff0baf2e81335178fc47d2d939d Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 27 Nov 2023 20:30:57 +0100 Subject: [PATCH] Improve `details::Boolean` compatibility checks. Instead of comparing values, use `std::memcmp` to compare bytes. --- tests/unit/tests_high_five_base.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/unit/tests_high_five_base.cpp b/tests/unit/tests_high_five_base.cpp index 1ba790b3a..65ac00368 100644 --- a/tests/unit/tests_high_five_base.cpp +++ b/tests/unit/tests_high_five_base.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -2439,10 +2440,24 @@ TEST_CASE("HighFiveReadType") { TEST_CASE("DirectWriteBool") { SECTION("Basic compatibility") { - using IntType = typename std::underlying_type::type; CHECK(sizeof(bool) == sizeof(details::Boolean)); - CHECK(true == static_cast(details::Boolean::HighFiveTrue)); - CHECK(false == static_cast(details::Boolean::HighFiveFalse)); + + auto n_bytes = 2 * sizeof(details::Boolean); + + auto* const enum_ptr = (details::Boolean*) malloc(n_bytes); + memset(enum_ptr, 187, n_bytes); + enum_ptr[0] = details::Boolean::HighFiveTrue; + enum_ptr[1] = details::Boolean::HighFiveFalse; + + auto* const bool_ptr = (bool*) malloc(n_bytes); + memset(bool_ptr, 68, n_bytes); + bool_ptr[0] = true; + bool_ptr[1] = false; + + CHECK(std::memcmp(bool_ptr, enum_ptr, n_bytes) == 0); + + free(enum_ptr); + free(bool_ptr); } auto file = File("rw_bool_from_ptr.h5", File::Truncate);