Skip to content

Commit

Permalink
STYLE: Use the itkNameOfTestExecutableMacro macro in tests
Browse files Browse the repository at this point in the history
Use the `itkNameOfTestExecutableMacro` macro to get the test name and
prevent the test from crashing when `argv[0]` is null.

Use the macro for tests that had the name of the test hard-coded.

Add the input argument check for tests that were missing it.
  • Loading branch information
jhlegarreta authored and hjmjohnson committed Dec 12, 2021
1 parent a10264a commit 7997ef3
Show file tree
Hide file tree
Showing 65 changed files with 146 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#include <fstream>
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkTestingMacros.h"


int
itkSymmetricSecondRankTensorImageReadTest(int ac, char * av[])
{
if (ac < 1)
{
std::cerr << "Usage: " << av[0] << " Input\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " Input\n";
return EXIT_FAILURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <fstream>
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkTestingMacros.h"


// Write a 2D SymmetricSecondRankTensor image to file and read it back again.
Expand All @@ -27,7 +28,7 @@ itkSymmetricSecondRankTensorImageWriteReadTest(int ac, char * av[])
{
if (ac < 1)
{
std::cerr << "Usage: " << av[0] << " Input\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " Input\n";
return EXIT_FAILURE;
}

Expand Down
3 changes: 2 additions & 1 deletion Modules/Core/Mesh/test/itkVTKPolyDataReaderTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/

#include "itkVTKPolyDataReader.h"
#include "itkTestingMacros.h"

#include <iostream>

Expand All @@ -25,7 +26,7 @@ itkVTKPolyDataReaderTest(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage: itkVTKPolyDataReaderTest inputFilename" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " inputFilename" << std::endl;
return EXIT_FAILURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "itkQuadEdgeMesh.h"
#include "itkVTKPolyDataReader.h"
#include "itkVTKPolyDataWriter.h"
#include "itkTestingMacros.h"

#include <iostream>

Expand All @@ -35,7 +36,7 @@ itkVTKPolyDataIOQuadEdgeMeshTest(int argc, char * argv[])

if (argc != 3)
{
std::cerr << "Usage: itkVTKPolyDataReaderTest inputFilename outputFilename" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " inputFilename outputFilename" << std::endl;
return EXIT_FAILURE;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "itkQuadEdgeMesh.h"
#include "itkVTKPolyDataReader.h"
#include "itkTestingMacros.h"

#include <iostream>

Expand All @@ -26,7 +27,7 @@ itkVTKPolyDataReaderQuadEdgeMeshTest(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage: itkVTKPolyDataReaderTest inputFilename" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " inputFilename" << std::endl;
return EXIT_FAILURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkImageFileWriter.h"
#include "itkChangeInformationImageFilter.h"
#include "itkTestingComparisonImageFilter.h"
#include "itkTestingMacros.h"
#include <fstream>

using PixelType = float;
Expand Down Expand Up @@ -68,7 +69,7 @@ itkGradientAnisotropicDiffusionImageFilterTest2(int ac, char * av[])
{
if (ac < 3)
{
std::cerr << "Usage: " << av[0] << " InputImage OutputImage\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage OutputImage\n";
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkNormalizedCorrelationImageFilterTest(int ac, char * av[])
{
if (ac < 4)
{
std::cerr << "Usage: " << av[0] << " InputImage MaskImage OutputImage\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage MaskImage OutputImage\n";
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkBilateralImageFilterTest2(int ac, char * av[])
{
if (ac < 3)
{
std::cerr << "Usage: " << av[0] << " InputImage OutputImage\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage OutputImage\n";
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
#include "itkBilateralImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkTestingMacros.h"


int
itkBilateralImageFilterTest3(int ac, char * av[])
{
if (ac < 3)
{
std::cerr << "Usage: " << av[0] << " InputImage BaselineImage\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BaselineImage\n";
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ itkMaskNeighborhoodOperatorImageFilterTest(int ac, char * av[])
{
if (ac < 3)
{
std::cerr << "Usage: " << av[0] << " InputImage OutputImage\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage OutputImage\n";
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ itkVectorGradientMagnitudeImageFilterTest2(int ac, char * av[])

if (ac < 5)
{
std::cerr << "Usage: " << av[0] << " InputImage OutputImage Mode SliceToExtract\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage OutputImage Mode SliceToExtract\n";
return EXIT_FAILURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ itkVectorGradientMagnitudeImageFilterTest3(int ac, char * av[])

if (ac < 4)
{
std::cerr << "Usage: " << av[0] << " InputImage OutputImage Mode\n";
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage OutputImage Mode\n";
return EXIT_FAILURE;
}

Expand Down
3 changes: 2 additions & 1 deletion Modules/Filtering/ImageGrid/test/itkOrientedImage2DTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

#include "itkImageFileReader.h"
#include "itkCentralDifferenceImageFunction.h"
#include "itkTestingMacros.h"

int
itkOrientedImage2DTest(int ac, char * av[])
{

if (ac < 12)
{
std::cerr << "Usage: " << av[0] << " InputImage "
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage "
<< "corner1x corner1y "
<< "corner2x corner2y "
<< "corner3x corner3y "
Expand Down
3 changes: 2 additions & 1 deletion Modules/Filtering/ImageGrid/test/itkOrientedImage3DTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

#include "itkImageFileReader.h"
#include "itkCentralDifferenceImageFunction.h"
#include "itkTestingMacros.h"

int
itkOrientedImage3DTest(int ac, char * av[])
{

if (ac < 20)
{
std::cerr << "Usage: " << av[0] << " InputImage "
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage "
<< "corner1x corner1y corner1z "
<< "corner2x corner2y corner2z "
<< "corner3x corner3y corner3z "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkGrayscaleDilateImageFilterTest(int ac, char * av[])
Expand All @@ -32,7 +33,7 @@ itkGrayscaleDilateImageFilterTest(int ac, char * av[])

if (ac < 6)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkGrayscaleErodeImageFilterTest(int ac, char * av[])
Expand All @@ -32,7 +33,7 @@ itkGrayscaleErodeImageFilterTest(int ac, char * av[])

if (ac < 6)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkGrayscaleMorphologicalClosingImageFilterTest2(int ac, char * av[])
Expand All @@ -32,7 +33,8 @@ itkGrayscaleMorphologicalClosingImageFilterTest2(int ac, char * av[])

if (ac < 7)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder"
<< std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkGrayscaleMorphologicalOpeningImageFilterTest2(int ac, char * av[])
Expand All @@ -32,7 +33,8 @@ itkGrayscaleMorphologicalOpeningImageFilterTest2(int ac, char * av[])

if (ac < 7)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder"
<< std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkImageFileWriter.h"
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkMapGrayscaleDilateImageFilterTest(int ac, char * av[])
Expand All @@ -32,7 +33,7 @@ itkMapGrayscaleDilateImageFilterTest(int ac, char * av[])

if (ac < 6)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkMapGrayscaleErodeImageFilterTest(int ac, char * av[])
Expand All @@ -32,7 +33,7 @@ itkMapGrayscaleErodeImageFilterTest(int ac, char * av[])

if (ac < 6)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW" << std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkMapGrayscaleMorphologicalClosingImageFilterTest(int ac, char * av[])
Expand All @@ -32,7 +33,8 @@ itkMapGrayscaleMorphologicalClosingImageFilterTest(int ac, char * av[])

if (ac < 7)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder"
<< std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkFlatStructuringElement.h"
#include "itkTestingMacros.h"

int
itkMapGrayscaleMorphologicalOpeningImageFilterTest(int ac, char * av[])
Expand All @@ -32,7 +33,8 @@ itkMapGrayscaleMorphologicalOpeningImageFilterTest(int ac, char * av[])

if (ac < 7)
{
std::cerr << "Usage: " << av[0] << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BASIC HISTO ANCHOR VHGW SafeBorder"
<< std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "itkImageFileWriter.h"
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkMapMaskedRankImageFilterTest(int ac, char * av[])
Expand All @@ -31,7 +32,8 @@ itkMapMaskedRankImageFilterTest(int ac, char * av[])

if (ac < 5)
{
std::cerr << "Usage: " << av[0] << " InputImage maskImage BaselineImage radius" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage maskImage BaselineImage radius"
<< std::endl;
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "itkImageFileWriter.h"
#include "itkTextOutput.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkMapRankImageFilterTest(int ac, char * av[])
Expand All @@ -31,7 +32,7 @@ itkMapRankImageFilterTest(int ac, char * av[])

if (ac < 4)
{
std::cerr << "Usage: " << av[0] << " InputImage BaselineImage radius" << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(av) << " InputImage BaselineImage radius" << std::endl;
return -1;
}

Expand Down
Loading

0 comments on commit 7997ef3

Please sign in to comment.