diff --git a/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp b/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp index 896e8225e5..56f51b17e3 100644 --- a/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp +++ b/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp @@ -385,8 +385,10 @@ TEST_CASE("ITKImageProcessing::ITKImageWriterFilter: RGBA Image Output", "[ITKIm args.insertOrAssign(ITKImageWriterFilter::k_TotalIndexDigits_Key, std::make_any(3)); args.insertOrAssign(ITKImageWriterFilter::k_LeadingDigitCharacter_Key, std::make_any("0")); - SIMPLNX_RESULT_REQUIRE_VALID(filter.preflight(dataStructure, args).outputActions); - SIMPLNX_RESULT_REQUIRE_VALID(filter.execute(dataStructure, args).result); + auto preflightResult = filter.preflight(dataStructure, args).outputActions; + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult); + auto executeResult = filter.execute(dataStructure, args).result; + SIMPLNX_RESULT_REQUIRE_VALID(executeResult); using ImageType = itk::Image, 2>; auto reader = itk::ImageFileReader::New(); diff --git a/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp b/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp index d55c058dae..86fbe0d3cb 100644 --- a/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp +++ b/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp @@ -497,9 +497,11 @@ TEST_CASE("SimplnxCore::KeepRemoveRankedFeaturesFilter: Invariants", "[SimplnxCo // Keeping 2 gives {1, 4}; keeping 3 gives {1, 4, 3}. Compare cell-wise: every cell surviving // under k=2 must also survive under k=3. DataStructure smallDs = BuildFiveFeatureData(); - SIMPLNX_RESULT_REQUIRE_VALID(filter.execute(smallDs, MakeArgs(0ULL, 0ULL, 2ULL)).result); + auto smallDsResult = filter.execute(smallDs, MakeArgs(0ULL, 0ULL, 2ULL)).result; + SIMPLNX_RESULT_REQUIRE_VALID(smallDsResult); DataStructure largeDs = BuildFiveFeatureData(); - SIMPLNX_RESULT_REQUIRE_VALID(filter.execute(largeDs, MakeArgs(0ULL, 0ULL, 3ULL)).result); + auto largeDsResult = filter.execute(largeDs, MakeArgs(0ULL, 0ULL, 3ULL)).result; + SIMPLNX_RESULT_REQUIRE_VALID(largeDsResult); const std::vector smallIds = ReadFeatureIds(smallDs); const std::vector largeIds = ReadFeatureIds(largeDs); diff --git a/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp b/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp index 9cd2106644..7a73d41a84 100644 --- a/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp +++ b/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp @@ -40,6 +40,17 @@ namespace fs = std::filesystem; using namespace nx::core; +namespace nx::core +{ +template +inline constexpr bool IsResult_v = false; + +template +inline constexpr bool IsResult_v> = true; +} // namespace nx::core + +#define NX_IS_LVALUE_RESULT(value) (IsResult_v> && std::is_lvalue_reference_v) + #define SIMPLNX_RESULT_CATCH_PRINT(result) \ for(const auto& warning : (result).warnings()) \ { \ @@ -54,12 +65,20 @@ using namespace nx::core; } #define SIMPLNX_RESULT_REQUIRE_VALID(result) \ - SIMPLNX_RESULT_CATCH_PRINT(result); \ - REQUIRE((result).valid()); + do \ + { \ + static_assert(NX_IS_LVALUE_RESULT(result), "SIMPLNX_RESULT_REQUIRE_VALID requires an lvalue Result"); \ + SIMPLNX_RESULT_CATCH_PRINT(result); \ + REQUIRE((result).valid()); \ + } while(false); #define SIMPLNX_RESULT_REQUIRE_INVALID(result) \ - SIMPLNX_RESULT_CATCH_PRINT(result); \ - REQUIRE((result).invalid()); + do \ + { \ + static_assert(NX_IS_LVALUE_RESULT(result), "SIMPLNX_RESULT_REQUIRE_INVALID requires an lvalue Result"); \ + SIMPLNX_RESULT_CATCH_PRINT(result); \ + REQUIRE((result).invalid()); \ + } while(false); namespace nx::core {