Skip to content

Commit

Permalink
STYLE: Improve the JPEG module tests' style
Browse files Browse the repository at this point in the history
Improve the `JPEG` module tests' style:
- Use the `ITK_TRY_EXPECT_NO_EXCEPTION` macro to avoid boilerplate code.
- Use the `ITK_TEST_EXPECT_TRUE` macro to avoid boilerplate code.
- Improve the style to make them more consistent (e.g. input argument
  checking message, endline characters in input argument checking,
  define the image dimensionality constant).
  • Loading branch information
jhlegarreta authored and hjmjohnson committed Dec 28, 2021
1 parent ac7272c commit bc3ac22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
12 changes: 2 additions & 10 deletions Modules/IO/JPEG/test/itkJPEGImageIOCMYKTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ itkJPEGImageIOCMYKTest(int argc, char * argv[])

ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());

if (!(io->GetPixelType() == itk::CommonEnums::IOPixel::RGB))
{
std::cout << "Expected RGB. Test failed" << std::endl;
return EXIT_FAILURE;
}
ITK_TEST_EXPECT_TRUE(io->GetPixelType() == itk::CommonEnums::IOPixel::RGB);
}

{
Expand All @@ -66,11 +62,7 @@ itkJPEGImageIOCMYKTest(int argc, char * argv[])

ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());

if (!(io->GetPixelType() == itk::CommonEnums::IOPixel::VECTOR))
{
std::cout << "Expected VECTOR. Test failed" << std::endl;
return EXIT_FAILURE;
}
ITK_TEST_EXPECT_TRUE(io->GetPixelType() == itk::CommonEnums::IOPixel::VECTOR);
}

std::cout << "Test finished." << std::endl;
Expand Down
23 changes: 10 additions & 13 deletions Modules/IO/JPEG/test/itkJPEGImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,25 @@ itkJPEGImageIOTest(int argc, char * argv[])

if (argc < 3)
{
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " Input Output\n";
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv);
std::cerr << " inputFilename outputFilename" << std::endl;
return EXIT_FAILURE;
}

// ATTENTION THIS IS THE PIXEL TYPE FOR
// THE RESULTING IMAGE
constexpr unsigned int Dimension = 2;
using PixelType = unsigned char;

using myImage = itk::Image<PixelType, 2>;
using myImage = itk::Image<PixelType, Dimension>;

itk::ImageFileReader<myImage>::Pointer reader = itk::ImageFileReader<myImage>::New();

reader->SetFileName(argv[1]);

try
{
reader->Update();
}
catch (const itk::ExceptionObject & e)
{
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());


myImage::Pointer image = reader->GetOutput();

Expand All @@ -67,7 +62,9 @@ itkJPEGImageIOTest(int argc, char * argv[])
writer = itk::ImageFileWriter<myImage>::New();
writer->SetInput(reader->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();

ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update());


return EXIT_SUCCESS;
}

0 comments on commit bc3ac22

Please sign in to comment.