Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@ TEST_CASE("ITKImageProcessing::ITKImageWriterFilter: RGBA Image Output", "[ITKIm
args.insertOrAssign(ITKImageWriterFilter::k_TotalIndexDigits_Key, std::make_any<Int32Parameter::ValueType>(3));
args.insertOrAssign(ITKImageWriterFilter::k_LeadingDigitCharacter_Key, std::make_any<StringParameter::ValueType>("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<itk::RGBAPixel<uint8>, 2>;
auto reader = itk::ImageFileReader<ImageType>::New();
Expand Down
6 changes: 4 additions & 2 deletions src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32> smallIds = ReadFeatureIds(smallDs);
const std::vector<int32> largeIds = ReadFeatureIds(largeDs);
Expand Down
27 changes: 23 additions & 4 deletions test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
namespace fs = std::filesystem;
using namespace nx::core;

namespace nx::core
{
template <class>
inline constexpr bool IsResult_v = false;

template <class T>
inline constexpr bool IsResult_v<Result<T>> = true;
} // namespace nx::core

#define NX_IS_LVALUE_RESULT(value) (IsResult_v<std::remove_cvref_t<decltype(value)>> && std::is_lvalue_reference_v<decltype((value))>)

#define SIMPLNX_RESULT_CATCH_PRINT(result) \
for(const auto& warning : (result).warnings()) \
{ \
Expand All @@ -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<T>"); \
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<T>"); \
SIMPLNX_RESULT_CATCH_PRINT(result); \
REQUIRE((result).invalid()); \
} while(false);

namespace nx::core
{
Expand Down
Loading