From 3f429da7fa3e03f366255fd4b581628b265d8c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sat, 11 Dec 2021 09:50:37 -0500 Subject: [PATCH] STYLE: Use exit return codes consistently in tests Use exit return codes consistently in tests. Use the `ITK_TRY_EXPECT_NO_EXCEPTION` macro where appropriate to avoid boilerplate code. --- Modules/Core/Common/test/itkOctreeTest.cxx | 2 +- .../test/itkBinaryDilateImageFilterTest.cxx | 36 ++--- .../test/itkBinaryErodeImageFilterTest.cxx | 37 ++--- ...tkErodeObjectMorphologyImageFilterTest.cxx | 37 ++--- ...tkNormalizedCorrelationImageFilterTest.cxx | 18 +-- .../test/itkSTAPLEImageFilterTest.cxx | 45 ++---- ...lacianRecursiveGaussianImageFilterTest.cxx | 14 +- ...askNeighborhoodOperatorImageFilterTest.cxx | 17 +-- .../itkChangeInformationImageFilterTest.cxx | 139 +++++++++--------- .../test/itkOrientImageFilterTest.cxx | 4 +- .../test/itkPasteImageFilterTest.cxx | 18 +-- .../test/itkPromoteDimensionImageTest.cxx | 15 +- .../test/itkShiftScaleImageFilterTest.cxx | 15 +- ...ectorIndexSelectionCastImageFilterTest.cxx | 12 +- .../itkGrayscaleDilateImageFilterTest.cxx | 2 +- .../test/itkGrayscaleErodeImageFilterTest.cxx | 2 +- ...GrayscaleFunctionDilateImageFilterTest.cxx | 38 ++--- ...kGrayscaleFunctionErodeImageFilterTest.cxx | 38 ++--- .../itkMapGrayscaleDilateImageFilterTest.cxx | 2 +- .../itkMapGrayscaleErodeImageFilterTest.cxx | 2 +- ...aleMorphologicalClosingImageFilterTest.cxx | 2 +- ...aleMorphologicalOpeningImageFilterTest.cxx | 2 +- .../test/itkMapMaskedRankImageFilterTest.cxx | 2 +- .../test/itkMapRankImageFilterTest.cxx | 2 +- .../test/itkMaskedRankImageFilterTest.cxx | 2 +- .../test/itkRankImageFilterTest.cxx | 2 +- .../test/itkBoxMeanImageFilterTest.cxx | 2 +- .../test/itkBoxSigmaImageFilterTest.cxx | 2 +- ...rsiveGaussianImageFiltersOnTensorsTest.cxx | 14 +- ...eGaussianImageFiltersOnVectorImageTest.cxx | 14 +- .../test/itkNoiseImageFilterTest.cxx | 2 +- ...esolutionPDEDeformableRegistrationTest.cxx | 2 +- ...oldSegmentationLevelSetImageFilterTest.cxx | 16 +- .../itkConfidenceConnectedImageFilterTest.cxx | 16 +- .../itkConnectedThresholdImageFilterTest.cxx | 2 +- .../itkIsolatedConnectedImageFilterTest.cxx | 2 +- ...tkNeighborhoodConnectedImageFilterTest.cxx | 15 +- ...ctorConfidenceConnectedImageFilterTest.cxx | 16 +- 38 files changed, 225 insertions(+), 383 deletions(-) diff --git a/Modules/Core/Common/test/itkOctreeTest.cxx b/Modules/Core/Common/test/itkOctreeTest.cxx index 19edc025613..93c168a8642 100644 --- a/Modules/Core/Common/test/itkOctreeTest.cxx +++ b/Modules/Core/Common/test/itkOctreeTest.cxx @@ -90,7 +90,7 @@ itkOctreeTest(int, char *[]) if (mapped != y) { std::cerr << "Error comparing Input and Output of Octree" << std::endl; - return -1; + return EXIT_FAILURE; } ++ri; ++ri2; diff --git a/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryDilateImageFilterTest.cxx b/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryDilateImageFilterTest.cxx index 8478c04be20..36629b52b56 100644 --- a/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryDilateImageFilterTest.cxx +++ b/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryDilateImageFilterTest.cxx @@ -19,6 +19,7 @@ #include "itkBinaryDilateImageFilter.h" #include "itkBinaryBallStructuringElement.h" #include "itkSimpleFilterWatcher.h" +#include "itkTestingMacros.h" int itkBinaryDilateImageFilterTest(int, char *[]) @@ -143,33 +144,26 @@ itkBinaryDilateImageFilterTest(int, char *[]) std::cout << "filter->GetDilateValue(): " << value << std::endl; // Execute the filter - try - { + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - filter->Update(); - // Create an iterator for going through the image output - myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); - // Print the content of the result image - std::cout << "Result " << std::endl; - i = 0; - while (!it2.IsAtEnd()) - { - std::cout << it2.Get() << " "; - ++it2; + // Create an iterator for going through the image output + myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); + + // Print the content of the result image + std::cout << "Result " << std::endl; + i = 0; + while (!it2.IsAtEnd()) + { + std::cout << it2.Get() << " "; + ++it2; - if (++i % 20 == 0) - { - std::cout << std::endl; - } + if (++i % 20 == 0) + { + std::cout << std::endl; } } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception caught during filter Update\n" << e; - return -1; - } // All objects should be automatically destroyed at this point diff --git a/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryErodeImageFilterTest.cxx b/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryErodeImageFilterTest.cxx index 43547700232..9bcd9cb4875 100644 --- a/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryErodeImageFilterTest.cxx +++ b/Modules/Filtering/BinaryMathematicalMorphology/test/itkBinaryErodeImageFilterTest.cxx @@ -19,6 +19,7 @@ #include "itkBinaryErodeImageFilter.h" #include "itkBinaryBallStructuringElement.h" #include "itkSimpleFilterWatcher.h" +#include "itkTestingMacros.h" int itkBinaryErodeImageFilterTest(int, char *[]) @@ -143,32 +144,24 @@ itkBinaryErodeImageFilterTest(int, char *[]) std::cout << "filter->GetErodeValue(): " << value << std::endl; // Execute the filter - try - { - - filter->Update(); - // Create an iterator for going through the image output - myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - // Print the content of the result image - std::cout << "Result " << std::endl; - i = 0; - while (!it2.IsAtEnd()) - { - std::cout << it2.Get() << " "; - ++it2; - if (++i % 20 == 0) - { - std::cout << std::endl; - } - } - } + // Create an iterator for going through the image output + myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); - catch (const itk::ExceptionObject & e) + // Print the content of the result image + std::cout << "Result " << std::endl; + i = 0; + while (!it2.IsAtEnd()) { - std::cerr << "Exception caught during filter Update\n" << e; - return -1; + std::cout << it2.Get() << " "; + ++it2; + + if (++i % 20 == 0) + { + std::cout << std::endl; + } } // All objects should be automatically destroyed at this point diff --git a/Modules/Filtering/BinaryMathematicalMorphology/test/itkErodeObjectMorphologyImageFilterTest.cxx b/Modules/Filtering/BinaryMathematicalMorphology/test/itkErodeObjectMorphologyImageFilterTest.cxx index 182c53b346e..faf03ea750d 100644 --- a/Modules/Filtering/BinaryMathematicalMorphology/test/itkErodeObjectMorphologyImageFilterTest.cxx +++ b/Modules/Filtering/BinaryMathematicalMorphology/test/itkErodeObjectMorphologyImageFilterTest.cxx @@ -19,6 +19,7 @@ #include "itkErodeObjectMorphologyImageFilter.h" #include "itkBinaryBallStructuringElement.h" #include "itkSimpleFilterWatcher.h" +#include "itkTestingMacros.h" int itkErodeObjectMorphologyImageFilterTest(int, char *[]) @@ -158,31 +159,23 @@ itkErodeObjectMorphologyImageFilterTest(int, char *[]) std::cout << "filter->GetErodeValue(): " << value << std::endl; // Execute the filter - try - { - filter->Update(); - // Create an iterator for going through the image output - myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); - - // Print the content of the result image - std::cout << "Result " << std::endl; - i = 0; - while (!it2.IsAtEnd()) - { - std::cout << it2.Get() << " "; - ++it2; + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - if (++i % 20 == 0) - { - std::cout << std::endl; - } - } - } + // Create an iterator for going through the image output + myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); - catch (const itk::ExceptionObject & e) + // Print the content of the result image + std::cout << "Result " << std::endl; + i = 0; + while (!it2.IsAtEnd()) { - std::cerr << "Exception caught during filter Update\n" << e; - return -1; + std::cout << it2.Get() << " "; + ++it2; + + if (++i % 20 == 0) + { + std::cout << std::endl; + } } // All objects should be automatically destroyed at this point diff --git a/Modules/Filtering/Convolution/test/itkNormalizedCorrelationImageFilterTest.cxx b/Modules/Filtering/Convolution/test/itkNormalizedCorrelationImageFilterTest.cxx index f0c030cd377..131c746e7d3 100644 --- a/Modules/Filtering/Convolution/test/itkNormalizedCorrelationImageFilterTest.cxx +++ b/Modules/Filtering/Convolution/test/itkNormalizedCorrelationImageFilterTest.cxx @@ -33,7 +33,7 @@ itkNormalizedCorrelationImageFilterTest(int argc, char * argv[]) if (argc < 4) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage MaskImage OutputImage\n"; - return -1; + return EXIT_FAILURE; } constexpr unsigned int Dimension = 2; @@ -99,20 +99,8 @@ itkNormalizedCorrelationImageFilterTest(int argc, char * argv[]) writer->SetInput(threshold->GetOutput()); writer->SetFileName(argv[3]); - try - { - writer->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } - catch (...) - { - std::cerr << "Some other exception occurred" << std::endl; - return -2; - } + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); + return EXIT_SUCCESS; } diff --git a/Modules/Filtering/ImageCompare/test/itkSTAPLEImageFilterTest.cxx b/Modules/Filtering/ImageCompare/test/itkSTAPLEImageFilterTest.cxx index 4976254fb82..2aa4a17d8fe 100644 --- a/Modules/Filtering/ImageCompare/test/itkSTAPLEImageFilterTest.cxx +++ b/Modules/Filtering/ImageCompare/test/itkSTAPLEImageFilterTest.cxx @@ -165,33 +165,20 @@ Stapler::Execute() // Set the inputs for (i = 0; i < number_of_files; ++i) { - try - { - reader = itk::ImageFileReader::New(); - reader->SetFileName(m_Files[i].c_str()); - reader->Update(); - m_Stapler->SetInput(itk::Math::CastWithRangeCheck(i), reader->GetOutput()); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << e << std::endl; - return -1; - } - } + reader = itk::ImageFileReader::New(); + reader->SetFileName(m_Files[i].c_str()); - try - { - writer->SetFileName(m_OutputFile.c_str()); - writer->SetInput(m_Stapler->GetOutput()); - writer->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << e << std::endl; - return -2; + ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update()); + + m_Stapler->SetInput(itk::Math::CastWithRangeCheck(i), reader->GetOutput()); } - return 0; + writer->SetFileName(m_OutputFile.c_str()); + writer->SetInput(m_Stapler->GetOutput()); + + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); + + return EXIT_SUCCESS; } @@ -207,7 +194,7 @@ itkSTAPLEImageFilterTest(int argc, char * argv[]) << " file_dimensionality output.mhd foreground_value confidence_weight " "file1 file2 ... fileN" << std::endl; - return -1; + return EXIT_FAILURE; } if (::std::stoi(argv[1]) == 2) @@ -221,7 +208,7 @@ itkSTAPLEImageFilterTest(int argc, char * argv[]) else { std::cerr << "Only 2D and 3D data is currently supported" << std::endl; - return -2; + return EXIT_FAILURE; } for (i = 0; i < argc - 5; ++i) @@ -235,10 +222,10 @@ itkSTAPLEImageFilterTest(int argc, char * argv[]) // Execute the stapler int ret = stapler->Execute(); - if (ret != 0) + if (ret != EXIT_SUCCESS) { - std::cerr << "Stapler failed! Returned error code " << ret << "." << std::endl; - return -3; + std::cerr << "Stapler failed!" << std::endl; + return EXIT_FAILURE; } double avg_p = 0.0; diff --git a/Modules/Filtering/ImageFeature/test/itkLaplacianRecursiveGaussianImageFilterTest.cxx b/Modules/Filtering/ImageFeature/test/itkLaplacianRecursiveGaussianImageFilterTest.cxx index de6b4ce4c2c..5547f219b12 100644 --- a/Modules/Filtering/ImageFeature/test/itkLaplacianRecursiveGaussianImageFilterTest.cxx +++ b/Modules/Filtering/ImageFeature/test/itkLaplacianRecursiveGaussianImageFilterTest.cxx @@ -31,7 +31,7 @@ itkLaplacianRecursiveGaussianImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << std::endl; std::cerr << itkNameOfTestExecutableMacro(argv) << " inputImage outputImage " << std::endl; - return -1; + return EXIT_FAILURE; } const char * inputFilename = argv[1]; @@ -99,16 +99,8 @@ itkLaplacianRecursiveGaussianImageFilterTest(int argc, char * argv[]) bool bNormalizeAcrossScale = lapFilter->GetNormalizeAcrossScale(); std::cout << "lapFilter->GetNormalizeAcrossScale(): " << bNormalizeAcrossScale << std::endl; - try - { - writer->Update(); - } - catch (const itk::ExceptionObject & err) - { - std::cout << "ExceptionObject caught !" << std::endl; - std::cout << err << std::endl; - return -1; - } + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); + return EXIT_SUCCESS; } diff --git a/Modules/Filtering/ImageFilterBase/test/itkMaskNeighborhoodOperatorImageFilterTest.cxx b/Modules/Filtering/ImageFilterBase/test/itkMaskNeighborhoodOperatorImageFilterTest.cxx index 423135d35eb..2689c673ad1 100644 --- a/Modules/Filtering/ImageFilterBase/test/itkMaskNeighborhoodOperatorImageFilterTest.cxx +++ b/Modules/Filtering/ImageFilterBase/test/itkMaskNeighborhoodOperatorImageFilterTest.cxx @@ -30,7 +30,7 @@ itkMaskNeighborhoodOperatorImageFilterTest(int argc, char * argv[]) if (argc < 3) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage OutputImage\n"; - return -1; + return EXIT_FAILURE; } constexpr unsigned int Dimension = 2; @@ -128,20 +128,7 @@ itkMaskNeighborhoodOperatorImageFilterTest(int argc, char * argv[]) writer->SetInput(rescaler->GetOutput()); writer->SetFileName(argv[2]); - try - { - writer->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } - catch (...) - { - std::cerr << "Some other exception occurred" << std::endl; - return -2; - } + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); return EXIT_SUCCESS; } diff --git a/Modules/Filtering/ImageGrid/test/itkChangeInformationImageFilterTest.cxx b/Modules/Filtering/ImageGrid/test/itkChangeInformationImageFilterTest.cxx index 754dbe84571..2af1de0f5b2 100644 --- a/Modules/Filtering/ImageGrid/test/itkChangeInformationImageFilterTest.cxx +++ b/Modules/Filtering/ImageGrid/test/itkChangeInformationImageFilterTest.cxx @@ -18,6 +18,7 @@ #include #include "itkChangeInformationImageFilter.h" +#include "itkTestingMacros.h" constexpr unsigned int ImageDimension = 3; using ImageType = itk::Image; @@ -220,77 +221,71 @@ itkChangeInformationImageFilterTest(int, char *[]) const itk::OffsetValueType * outputOffset = filter->GetOutputOffset().m_InternalArray; std::cout << "filter->GetOutputOffset(): " << outputOffset << std::endl; - // Catch any exceptions - try - { - std::cout << "-----------filter: " << filter << std::endl; - filter->Update(); - std::cout << "-----------Default behavior: " << std::endl; - PrintInformation(inputImage, filter->GetOutput()); - - filter->ChangeAll(); - filter->ChangeRegionOff(); - filter->Update(); - std::cout << "-----------ChangeAll(), ChangeRegionOff(): " << std::endl; - PrintInformation(inputImage, filter->GetOutput()); - - filter->CenterImageOn(); - filter->Update(); - std::cout << "-----------CenterImageOn(): " << std::endl; - PrintInformation(inputImage, filter->GetOutput()); - - filter->CenterImageOn(); - filter->ChangeSpacingOff(); - filter->Update(); - std::cout << "-----------CenterImageOn(), ChangeSpacingOff(): " << std::endl; - PrintInformation(inputImage, filter->GetOutput()); - - filter->CenterImageOn(); - filter->ChangeSpacingOn(); - filter->ChangeOriginOff(); - filter->Update(); - std::cout << "-----------CenterImageOn(), ChangeOriginOff(): " << std::endl; - PrintInformation(inputImage, filter->GetOutput()); - - filter->CenterImageOff(); - filter->ChangeNone(); - filter->Update(); - std::cout << "-----------ChangeNone(): " << std::endl; - PrintInformation(inputImage, filter->GetOutput()); - - filter->CenterImageOff(); - filter->UseReferenceImageOn(); - filter->Update(); - std::cout << "-----------ChangeNone(), UseReferenceOn(): " << std::endl; - PrintInformation3(inputImage, filter->GetOutput(), referenceImage); - - filter->ChangeOriginOn(); - filter->Update(); - std::cout << "-----------ChangeOriginOn(), UseReferenceOn(): " << std::endl; - PrintInformation3(inputImage, filter->GetOutput(), referenceImage); - - filter->ChangeOriginOff(); - filter->ChangeSpacingOn(); - filter->Update(); - std::cout << "-----------ChangeSpacingOn(), UseReferenceOn(): " << std::endl; - PrintInformation3(inputImage, filter->GetOutput(), referenceImage); - - filter->ChangeOriginOff(); - filter->ChangeSpacingOff(); - filter->ChangeDirectionOn(); - filter->Update(); - std::cout << "-----------ChangeDirectionOn(), UseReferenceOn(): " << std::endl; - PrintInformation3(inputImage, filter->GetOutput(), referenceImage); - - filter->ChangeAll(); - filter->UpdateLargestPossibleRegion(); - std::cout << "-----------ChangeAll(), UseReferenceOn(): " << std::endl; - PrintInformation3(inputImage, filter->GetOutput(), referenceImage); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e; - return -1; - } + + std::cout << "-----------filter: " << filter << std::endl; + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------Default behavior: " << std::endl; + PrintInformation(inputImage, filter->GetOutput()); + + filter->ChangeAll(); + filter->ChangeRegionOff(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------ChangeAll(), ChangeRegionOff(): " << std::endl; + PrintInformation(inputImage, filter->GetOutput()); + + filter->CenterImageOn(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------CenterImageOn(): " << std::endl; + PrintInformation(inputImage, filter->GetOutput()); + + filter->CenterImageOn(); + filter->ChangeSpacingOff(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------CenterImageOn(), ChangeSpacingOff(): " << std::endl; + PrintInformation(inputImage, filter->GetOutput()); + + filter->CenterImageOn(); + filter->ChangeSpacingOn(); + filter->ChangeOriginOff(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------CenterImageOn(), ChangeOriginOff(): " << std::endl; + PrintInformation(inputImage, filter->GetOutput()); + + filter->CenterImageOff(); + filter->ChangeNone(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------ChangeNone(): " << std::endl; + PrintInformation(inputImage, filter->GetOutput()); + + filter->CenterImageOff(); + filter->UseReferenceImageOn(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------ChangeNone(), UseReferenceOn(): " << std::endl; + PrintInformation3(inputImage, filter->GetOutput(), referenceImage); + + filter->ChangeOriginOn(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------ChangeOriginOn(), UseReferenceOn(): " << std::endl; + PrintInformation3(inputImage, filter->GetOutput(), referenceImage); + + filter->ChangeOriginOff(); + filter->ChangeSpacingOn(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------ChangeSpacingOn(), UseReferenceOn(): " << std::endl; + PrintInformation3(inputImage, filter->GetOutput(), referenceImage); + + filter->ChangeOriginOff(); + filter->ChangeSpacingOff(); + filter->ChangeDirectionOn(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + std::cout << "-----------ChangeDirectionOn(), UseReferenceOn(): " << std::endl; + PrintInformation3(inputImage, filter->GetOutput(), referenceImage); + + filter->ChangeAll(); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->UpdateLargestPossibleRegion()); + std::cout << "-----------ChangeAll(), UseReferenceOn(): " << std::endl; + PrintInformation3(inputImage, filter->GetOutput(), referenceImage); + + return EXIT_SUCCESS; } diff --git a/Modules/Filtering/ImageGrid/test/itkOrientImageFilterTest.cxx b/Modules/Filtering/ImageGrid/test/itkOrientImageFilterTest.cxx index 30e19242165..dc636aa3e4d 100644 --- a/Modules/Filtering/ImageGrid/test/itkOrientImageFilterTest.cxx +++ b/Modules/Filtering/ImageGrid/test/itkOrientImageFilterTest.cxx @@ -104,7 +104,7 @@ itkOrientImageFilterTest(int, char *[]) ImageType::PixelType orig = randImage->GetPixel(originalIndex); ImageType::PixelType xfrm = IRP->GetPixel(transformedIndex); if (orig != xfrm) - return -1; + return EXIT_FAILURE; } } } @@ -135,7 +135,7 @@ itkOrientImageFilterTest(int, char *[]) ImageType::PixelType orig = randImage->GetPixel(originalIndex); ImageType::PixelType xfrm = LIP->GetPixel(transformedIndex); if (orig != xfrm) - return -1; + return EXIT_FAILURE; } } } diff --git a/Modules/Filtering/ImageGrid/test/itkPasteImageFilterTest.cxx b/Modules/Filtering/ImageGrid/test/itkPasteImageFilterTest.cxx index 0ffd7ec23b1..e8f17b979ab 100644 --- a/Modules/Filtering/ImageGrid/test/itkPasteImageFilterTest.cxx +++ b/Modules/Filtering/ImageGrid/test/itkPasteImageFilterTest.cxx @@ -30,7 +30,7 @@ itkPasteImageFilterTest(int argc, char * argv[]) if (argc < 4) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " DestinationImage SourceImage OutputImage\n"; - return -1; + return EXIT_FAILURE; } constexpr unsigned int Dimension = 2; @@ -92,20 +92,8 @@ itkPasteImageFilterTest(int argc, char * argv[]) streamer->SetNumberOfStreamDivisions(25); streamer->SetRegionSplitter(splitter); - try - { - streamer->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } - catch (...) - { - std::cerr << "Some other exception occurred" << std::endl; - return -2; - } + ITK_TRY_EXPECT_NO_EXCEPTION(streamer->Update()); + // Generate test image itk::ImageFileWriter::Pointer writer; diff --git a/Modules/Filtering/ImageIntensity/test/itkPromoteDimensionImageTest.cxx b/Modules/Filtering/ImageIntensity/test/itkPromoteDimensionImageTest.cxx index 67c066f0498..029e8a3a010 100644 --- a/Modules/Filtering/ImageIntensity/test/itkPromoteDimensionImageTest.cxx +++ b/Modules/Filtering/ImageIntensity/test/itkPromoteDimensionImageTest.cxx @@ -29,7 +29,7 @@ itkPromoteDimensionImageTest(int argc, char * argv[]) { std::cerr << "Usage: " << std::endl; std::cerr << itkNameOfTestExecutableMacro(argv) << " inputImage outputImage " << std::endl; - return -1; + return EXIT_FAILURE; } const char * inputFilename = argv[1]; @@ -75,17 +75,8 @@ itkPromoteDimensionImageTest(int argc, char * argv[]) toChar->SetInput(rescale->GetOutput()); writer->SetInput(toChar->GetOutput()); - try - { - writer->Update(); - // toChar->GetOutput()->Print(std::cout); - } - catch (const itk::ExceptionObject & err) - { - std::cout << "ExceptionObject caught !" << std::endl; - std::cout << err << std::endl; - return -1; - } + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); + return EXIT_SUCCESS; } diff --git a/Modules/Filtering/ImageIntensity/test/itkShiftScaleImageFilterTest.cxx b/Modules/Filtering/ImageIntensity/test/itkShiftScaleImageFilterTest.cxx index 1af40fbf0ed..00ebdf633d1 100644 --- a/Modules/Filtering/ImageIntensity/test/itkShiftScaleImageFilterTest.cxx +++ b/Modules/Filtering/ImageIntensity/test/itkShiftScaleImageFilterTest.cxx @@ -21,8 +21,9 @@ #include "itkShiftScaleImageFilter.h" #include "itkRandomImageSource.h" - #include "itkSimpleFilterWatcher.h" +#include "itkTestingMacros.h" + int itkShiftScaleImageFilterTest(int, char *[]) { @@ -90,15 +91,9 @@ itkShiftScaleImageFilterTest(int, char *[]) filter->SetInput(source->GetOutput()); filter->SetScale(4.0); - try - { - filter->UpdateLargestPossibleRegion(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e; - return -1; - } + + ITK_TRY_EXPECT_NO_EXCEPTION(filter->UpdateLargestPossibleRegion()); + return EXIT_SUCCESS; } diff --git a/Modules/Filtering/ImageIntensity/test/itkVectorIndexSelectionCastImageFilterTest.cxx b/Modules/Filtering/ImageIntensity/test/itkVectorIndexSelectionCastImageFilterTest.cxx index 490a29fde1e..2f1df4f8eca 100644 --- a/Modules/Filtering/ImageIntensity/test/itkVectorIndexSelectionCastImageFilterTest.cxx +++ b/Modules/Filtering/ImageIntensity/test/itkVectorIndexSelectionCastImageFilterTest.cxx @@ -20,8 +20,8 @@ #include "itkImageFileReader.h" #include "itkImageFileWriter.h" - #include "itkVectorIndexSelectionCastImageFilter.h" +#include "itkTestingMacros.h" int itkVectorIndexSelectionCastImageFilterTest(int argc, char * argv[]) @@ -62,15 +62,7 @@ itkVectorIndexSelectionCastImageFilterTest(int argc, char * argv[]) filter->SetIndex(index); - try - { - writer->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e; - return -1; - } + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); std::cout << "Test the exception if the index is too large" << std::endl; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleDilateImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleDilateImageFilterTest.cxx index 08de55868e7..f76ee8e3310 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleDilateImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleDilateImageFilterTest.cxx @@ -34,7 +34,7 @@ itkGrayscaleDilateImageFilterTest(int argc, char * argv[]) if (argc < 6) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl; - return -1; + return EXIT_FAILURE; } unsigned int const dim = 2; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleErodeImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleErodeImageFilterTest.cxx index f371000e96c..1193d3804c9 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleErodeImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleErodeImageFilterTest.cxx @@ -34,7 +34,7 @@ itkGrayscaleErodeImageFilterTest(int argc, char * argv[]) if (argc < 6) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl; - return -1; + return EXIT_FAILURE; } unsigned int const dim = 2; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionDilateImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionDilateImageFilterTest.cxx index 9bee1a3c5f5..511f4ca6051 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionDilateImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionDilateImageFilterTest.cxx @@ -20,6 +20,7 @@ #include "itkBinaryBallStructuringElement.h" #include "itkSimpleFilterWatcher.h" #include "itkImageFileWriter.h" +#include "itkTestingMacros.h" int itkGrayscaleFunctionDilateImageFilterTest(int argc, char * argv[]) @@ -137,34 +138,25 @@ itkGrayscaleFunctionDilateImageFilterTest(int argc, char * argv[]) // Get the Smart Pointer to the Filter Output myImageType::Pointer outputImage = filter->GetOutput(); - // Execute the filter - try - { - - filter->Update(); - // Create an iterator for going through the image output - myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - // Print the content of the result image - std::cout << "Result " << std::endl; - i = 0; - while (!it2.IsAtEnd()) - { - std::cout << it2.Get() << " "; - ++it2; - if (++i % 20 == 0) - { - std::cout << std::endl; - } - } - } + // Create an iterator for going through the image output + myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); - catch (const itk::ExceptionObject & e) + // Print the content of the result image + std::cout << "Result " << std::endl; + i = 0; + while (!it2.IsAtEnd()) { - std::cerr << "Exception caught during filter Update\n" << e; - return -1; + std::cout << it2.Get() << " "; + ++it2; + + if (++i % 20 == 0) + { + std::cout << std::endl; + } } // if there is a file name specified as an argument, write the data diff --git a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionErodeImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionErodeImageFilterTest.cxx index 783d34c05e6..5fa5ffda4bf 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionErodeImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkGrayscaleFunctionErodeImageFilterTest.cxx @@ -20,6 +20,7 @@ #include "itkBinaryBallStructuringElement.h" #include "itkSimpleFilterWatcher.h" #include "itkImageFileWriter.h" +#include "itkTestingMacros.h" int itkGrayscaleFunctionErodeImageFilterTest(int argc, char * argv[]) @@ -137,34 +138,25 @@ itkGrayscaleFunctionErodeImageFilterTest(int argc, char * argv[]) // Get the Smart Pointer to the Filter Output myImageType::Pointer outputImage = filter->GetOutput(); - // Execute the filter - try - { - - filter->Update(); - // Create an iterator for going through the image output - myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - // Print the content of the result image - std::cout << "Result " << std::endl; - i = 0; - while (!it2.IsAtEnd()) - { - std::cout << it2.Get() << " "; - ++it2; - if (++i % 20 == 0) - { - std::cout << std::endl; - } - } - } + // Create an iterator for going through the image output + myIteratorType it2(outputImage, outputImage->GetBufferedRegion()); - catch (const itk::ExceptionObject & e) + // Print the content of the result image + std::cout << "Result " << std::endl; + i = 0; + while (!it2.IsAtEnd()) { - std::cerr << "Exception caught during filter Update\n" << e; - return -1; + std::cout << it2.Get() << " "; + ++it2; + + if (++i % 20 == 0) + { + std::cout << std::endl; + } } if (argc == 2) diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleDilateImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleDilateImageFilterTest.cxx index 41c03a10cf4..3b7b91aa299 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleDilateImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleDilateImageFilterTest.cxx @@ -34,7 +34,7 @@ itkMapGrayscaleDilateImageFilterTest(int argc, char * argv[]) if (argc < 6) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl; - return -1; + return EXIT_FAILURE; } unsigned int const dim = 2; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleErodeImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleErodeImageFilterTest.cxx index 63c599a4bfd..e64e3f7acdb 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleErodeImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleErodeImageFilterTest.cxx @@ -34,7 +34,7 @@ itkMapGrayscaleErodeImageFilterTest(int argc, char * argv[]) if (argc < 6) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl; - return -1; + return EXIT_FAILURE; } unsigned int const dim = 2; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalClosingImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalClosingImageFilterTest.cxx index 78b5c920334..5f38c43d76b 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalClosingImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalClosingImageFilterTest.cxx @@ -35,7 +35,7 @@ itkMapGrayscaleMorphologicalClosingImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder" << std::endl; - return -1; + return EXIT_FAILURE; } unsigned int const dim = 2; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalOpeningImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalOpeningImageFilterTest.cxx index 42a949da713..25e82fa701a 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalOpeningImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMapGrayscaleMorphologicalOpeningImageFilterTest.cxx @@ -35,7 +35,7 @@ itkMapGrayscaleMorphologicalOpeningImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder" << std::endl; - return -1; + return EXIT_FAILURE; } unsigned int const dim = 2; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMapMaskedRankImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMapMaskedRankImageFilterTest.cxx index f46e13cf9e4..074e5593270 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMapMaskedRankImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMapMaskedRankImageFilterTest.cxx @@ -34,7 +34,7 @@ itkMapMaskedRankImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage maskImage BaselineImage radius" << std::endl; - return -1; + return EXIT_FAILURE; } using ImageType = itk::Image; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMapRankImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMapRankImageFilterTest.cxx index 5c1588c2496..6007f3ffc56 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMapRankImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMapRankImageFilterTest.cxx @@ -33,7 +33,7 @@ itkMapRankImageFilterTest(int argc, char * argv[]) if (argc < 4) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage radius" << std::endl; - return -1; + return EXIT_FAILURE; } using ImageType = itk::Image; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkMaskedRankImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkMaskedRankImageFilterTest.cxx index d4881b3dbbf..d2085ad193d 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkMaskedRankImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkMaskedRankImageFilterTest.cxx @@ -34,7 +34,7 @@ itkMaskedRankImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage maskImage BaselineImage radius" << std::endl; - return -1; + return EXIT_FAILURE; } using ImageType = itk::Image; diff --git a/Modules/Filtering/MathematicalMorphology/test/itkRankImageFilterTest.cxx b/Modules/Filtering/MathematicalMorphology/test/itkRankImageFilterTest.cxx index d817780476e..f85fa5d5a3e 100644 --- a/Modules/Filtering/MathematicalMorphology/test/itkRankImageFilterTest.cxx +++ b/Modules/Filtering/MathematicalMorphology/test/itkRankImageFilterTest.cxx @@ -33,7 +33,7 @@ itkRankImageFilterTest(int argc, char * argv[]) if (argc < 4) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage radius" << std::endl; - return -1; + return EXIT_FAILURE; } using ImageType = itk::Image; diff --git a/Modules/Filtering/Smoothing/test/itkBoxMeanImageFilterTest.cxx b/Modules/Filtering/Smoothing/test/itkBoxMeanImageFilterTest.cxx index 2feb3e3bb11..d6b19501f05 100644 --- a/Modules/Filtering/Smoothing/test/itkBoxMeanImageFilterTest.cxx +++ b/Modules/Filtering/Smoothing/test/itkBoxMeanImageFilterTest.cxx @@ -33,7 +33,7 @@ itkBoxMeanImageFilterTest(int argc, char * argv[]) if (argc < 4) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage radius" << std::endl; - return -1; + return EXIT_FAILURE; } using ImageType = itk::Image; diff --git a/Modules/Filtering/Smoothing/test/itkBoxSigmaImageFilterTest.cxx b/Modules/Filtering/Smoothing/test/itkBoxSigmaImageFilterTest.cxx index e597327c874..277d4fec87f 100644 --- a/Modules/Filtering/Smoothing/test/itkBoxSigmaImageFilterTest.cxx +++ b/Modules/Filtering/Smoothing/test/itkBoxSigmaImageFilterTest.cxx @@ -33,7 +33,7 @@ itkBoxSigmaImageFilterTest(int argc, char * argv[]) if (argc < 4) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage radius" << std::endl; - return -1; + return EXIT_FAILURE; } using ImageType = itk::Image; diff --git a/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnTensorsTest.cxx b/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnTensorsTest.cxx index 9e4bcdd0a08..ce1f8264aea 100644 --- a/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnTensorsTest.cxx +++ b/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnTensorsTest.cxx @@ -17,6 +17,7 @@ *=========================================================================*/ #include "itkRecursiveGaussianImageFilter.h" #include "itkSymmetricSecondRankTensor.h" +#include "itkTestingMacros.h" int itkRecursiveGaussianImageFiltersOnTensorsTest(int, char *[]) @@ -91,16 +92,9 @@ itkRecursiveGaussianImageFiltersOnTensorsTest(int, char *[]) filterY->SetInput(filterX->GetOutput()); filterX->SetSigma(sigma); filterY->SetSigma(sigma); - try - { - filterY->Update(); - } - catch (const itk::ExceptionObject & err) - { - std::cout << "ExceptionObject caught a !" << std::endl; - std::cout << err << std::endl; - return -1; - } + + ITK_TRY_EXPECT_NO_EXCEPTION(filterY->Update()); + // Test a few pixels of the fitlered image // diff --git a/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnVectorImageTest.cxx b/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnVectorImageTest.cxx index 2c61e7a49fa..e46081ed848 100644 --- a/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnVectorImageTest.cxx +++ b/Modules/Filtering/Smoothing/test/itkRecursiveGaussianImageFiltersOnVectorImageTest.cxx @@ -17,6 +17,7 @@ *=========================================================================*/ #include "itkRecursiveGaussianImageFilter.h" #include "itkVectorImage.h" +#include "itkTestingMacros.h" int itkRecursiveGaussianImageFiltersOnVectorImageTest(int, char *[]) @@ -90,16 +91,9 @@ itkRecursiveGaussianImageFiltersOnVectorImageTest(int, char *[]) filterY->SetInput(filterX->GetOutput()); filterX->SetSigma(sigma); filterY->SetSigma(sigma); - try - { - filterY->Update(); - } - catch (const itk::ExceptionObject & err) - { - std::cout << "ExceptionObject caught a !" << std::endl; - std::cout << err << std::endl; - return -1; - } + + ITK_TRY_EXPECT_NO_EXCEPTION(filterY->Update()); + // Test a few pixels of the fitlered image // diff --git a/Modules/IO/ImageBase/test/itkNoiseImageFilterTest.cxx b/Modules/IO/ImageBase/test/itkNoiseImageFilterTest.cxx index 8bf571a6aa5..f976b4d1cc3 100644 --- a/Modules/IO/ImageBase/test/itkNoiseImageFilterTest.cxx +++ b/Modules/IO/ImageBase/test/itkNoiseImageFilterTest.cxx @@ -34,7 +34,7 @@ itkNoiseImageFilterTest(int argc, char * argv[]) if (argc < 3) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage\n"; - return -1; + return EXIT_FAILURE; } itk::Size<2> radius; diff --git a/Modules/Registration/PDEDeformable/test/itkMultiResolutionPDEDeformableRegistrationTest.cxx b/Modules/Registration/PDEDeformable/test/itkMultiResolutionPDEDeformableRegistrationTest.cxx index 3939ff79a42..8e1547b1107 100644 --- a/Modules/Registration/PDEDeformable/test/itkMultiResolutionPDEDeformableRegistrationTest.cxx +++ b/Modules/Registration/PDEDeformable/test/itkMultiResolutionPDEDeformableRegistrationTest.cxx @@ -155,7 +155,7 @@ itkMultiResolutionPDEDeformableRegistrationTest(int argc, char * argv[]) if (argc < 2) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " WarpedImage\n"; - return -1; + return EXIT_FAILURE; } //-------------------------------------------------------- diff --git a/Modules/Segmentation/LevelSets/test/itkVectorThresholdSegmentationLevelSetImageFilterTest.cxx b/Modules/Segmentation/LevelSets/test/itkVectorThresholdSegmentationLevelSetImageFilterTest.cxx index b8b171873a1..a965bab0fb4 100644 --- a/Modules/Segmentation/LevelSets/test/itkVectorThresholdSegmentationLevelSetImageFilterTest.cxx +++ b/Modules/Segmentation/LevelSets/test/itkVectorThresholdSegmentationLevelSetImageFilterTest.cxx @@ -34,7 +34,7 @@ itkVectorThresholdSegmentationLevelSetImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputInitialImage InputColorImage BaselineImage threshold curvatureScaling\n"; - return -1; + return EXIT_FAILURE; } constexpr unsigned int Dimension = 2; @@ -102,16 +102,10 @@ itkVectorThresholdSegmentationLevelSetImageFilterTest(int argc, char * argv[]) filter->SetCurvatureScaling(curvatureScaling); - try - { - rgbReader->Update(); - filter->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } + ITK_TRY_EXPECT_NO_EXCEPTION(rgbReader->Update()); + + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + // Test the GetMacros if (itk::Math::NotExactlyEquals(filter->GetThreshold(), threshold)) diff --git a/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx index 01c47849d5a..d8f17420395 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx @@ -33,7 +33,7 @@ itkConfidenceConnectedImageFilterTest(int argc, char * argv[]) if (argc < 5) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage seed_x seed_y\n"; - return -1; + return EXIT_FAILURE; } using PixelType = unsigned char; @@ -68,16 +68,10 @@ itkConfidenceConnectedImageFilterTest(int argc, char * argv[]) } std::cout << std::endl; - try - { - input->Update(); - filter->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } + ITK_TRY_EXPECT_NO_EXCEPTION(input->Update()); + + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + // Test the GetMacros double doubleMultiplier = filter->GetMultiplier(); diff --git a/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx index 34f09d76a45..3f50f048c15 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx @@ -32,7 +32,7 @@ itkConnectedThresholdImageFilterTest(int argc, char * argv[]) << "seed_x seed_y " << "LowerConnectedThreshold UpperConnectedThreshold " << "Connectivity[1=Full,0=Face]" << std::endl; - return -1; + return EXIT_FAILURE; } diff --git a/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx index 50ac20b53a6..902b848c8e6 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx @@ -31,7 +31,7 @@ itkIsolatedConnectedImageFilterTest(int argc, char * argv[]) std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage OutputImage FindUpper(true,false) seed1_x seed1_y seed2_x seed2_y [seed1_x2 seed1_y2 " "seed2_x2 seed2_y2]*\n"; - return -1; + return EXIT_FAILURE; } using PixelType = unsigned char; diff --git a/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx index f08ee2800c4..e45f8db4363 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx @@ -29,7 +29,7 @@ itkNeighborhoodConnectedImageFilterTest(int argc, char * argv[]) if (argc < 5) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage OutputImage seed_x seed_y\n"; - return -1; + return EXIT_FAILURE; } using PixelType = unsigned char; @@ -72,17 +72,10 @@ itkNeighborhoodConnectedImageFilterTest(int argc, char * argv[]) const SizeType & radius2 = filter->GetRadius(); std::cout << "filter->GetRadius(): " << radius2 << std::endl; + ITK_TRY_EXPECT_NO_EXCEPTION(input->Update()); + + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - try - { - input->Update(); - filter->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } // Generate test image itk::ImageFileWriter::Pointer writer; diff --git a/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx index e289cefd95d..4d7ae0254e8 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx @@ -34,7 +34,7 @@ itkVectorConfidenceConnectedImageFilterTest(int argc, char * argv[]) { std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage BaselineImage seed1X seed1Y seed2X seed2Y multiplier iterations\n"; - return -1; + return EXIT_FAILURE; } constexpr unsigned int Dimension = 2; @@ -77,16 +77,10 @@ itkVectorConfidenceConnectedImageFilterTest(int argc, char * argv[]) filter->SetMultiplier(std::stod(argv[7])); filter->SetNumberOfIterations(std::stoi(argv[8])); - try - { - input->Update(); - filter->Update(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << "Exception detected: " << e.GetDescription(); - return -1; - } + ITK_TRY_EXPECT_NO_EXCEPTION(input->Update()); + + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); + // Test the GetMacros double doubleMultiplier = filter->GetMultiplier();