Skip to content

Commit

Permalink
ENH: Improve itk::DCMTKSeriesFileNames class coverage
Browse files Browse the repository at this point in the history
Improve `itk::DCMTKSeriesFileNames` class coverage:
- Exercise the basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro.
- Use the `ITK_TRY_EXPECT_NO_EXCEPTION` macro when updating the filters.
- Exercise the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro.
- Add arguments to the test to improve the class testing of the additional
  ivars.
  • Loading branch information
jhlegarreta authored and dzenanz committed Sep 4, 2020
1 parent a17edc6 commit ab14339
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Modules/IO/DCMTK/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ itk_add_test(NAME itkDCMTKImageIOTest4 COMMAND ITKIODCMTKTestDriver
itk_add_test(NAME itkDCMTKSeriesReadImageWrite
COMMAND ITKIODCMTKTestDriver itkDCMTKSeriesReadImageWrite
DATA{${ITK_DATA_ROOT}/Input/DicomSeries/,REGEX:Image[0-9]+.dcm}
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesReadImageWrite.vtk)
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesReadImageWrite.vtk 0 0 0)

itk_add_test(NAME itkDCMTKDirCosinesTest
COMMAND ITKIODCMTKTestDriver itkDCMTKSeriesReadImageWrite
DATA{${ITK_DATA_ROOT}/Input/DicomDirectionsTest/,REGEX:1020_[0-9]+.dcm}
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesReadImageWrite.vtk)
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesReadImageWrite.vtk 0 0 0)

set_property(TEST itkDCMTKSeriesReadImageWrite APPEND PROPERTY DEPENDS ITKData)

Expand All @@ -67,7 +67,7 @@ itk_add_test(NAME itkDCMTKSeriesImageOrientationWrite1
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesImageOrientationWrite1.mha
itkDCMTKSeriesReadImageWrite
DATA{${ITK_DATA_ROOT}/Input/DicomImageOrientationTest/,REGEX:ImageOrientation.[0-9]+.dcm}
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesImageOrientationWrite1.mha)
${ITK_TEST_OUTPUT_DIR}/itkDCMTKSeriesImageOrientationWrite1.mha 0 0 0)

itk_add_test(NAME itkDCMTKImageIOOrthoDirTest
COMMAND ITKIODCMTKTestDriver itkDCMTKImageIOOrthoDirTest
Expand Down
47 changes: 25 additions & 22 deletions Modules/IO/DCMTK/test/itkDCMTKSeriesReadImageWrite.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@
#include "itkRescaleIntensityImageFilter.h"
#include "itkDCMTKImageIO.h"
#include "itkDCMTKSeriesFileNames.h"
#include "itkTestingMacros.h"

int
itkDCMTKSeriesReadImageWrite(int argc, char * argv[])
{
if (argc < 3)
if (argc != 6)
{
std::cerr << "Usage: " << argv[0] << " DicomDirectory outputFile" << std::endl;
std::cerr << "Missing arguments." << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << itkNameOfTestExecutableMacro(argv) << " DicomDirectory "
<< " outputFile"
<< " recursive"
<< " loadSequences"
<< " loadPrivateTags" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -46,8 +53,20 @@ itkDCMTKSeriesReadImageWrite(int argc, char * argv[])
ImageIOType::Pointer dcmtkIO = ImageIOType::New();
SeriesFileNames::Pointer it = SeriesFileNames::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(it, DCMTKSeriesFileNames, ProcessObject);


it->SetInputDirectory(argv[1]);

auto recursive = static_cast<bool>(std::stoi(argv[3]);
ITK_TEST_SET_GET_BOOLEAN(it, Recursive, recursive);

auto loadSequences = static_cast<bool>(std::stoi(argv[4]);
ITK_TEST_SET_GET_BOOLEAN(it, LoadSequences, loadSequences);

auto loadPrivateTags = static_cast<bool>(std::stoi(argv[5]);
ITK_TEST_SET_GET_BOOLEAN(it, LoadPrivateTags, loadPrivateTags);

ReaderType::Pointer reader = ReaderType::New();

const ReaderType::FileNamesContainer & fileNames = it->GetInputFileNames();
Expand All @@ -62,34 +81,18 @@ itkDCMTKSeriesReadImageWrite(int argc, char * argv[])
reader->SetFileNames(fileNames);
reader->SetImageIO(dcmtkIO);

try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while writing the image" << std::endl;
std::cerr << excp << std::endl;
ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());

return EXIT_FAILURE;
}

using WriterType = itk::ImageFileWriter<ImageType>;
WriterType::Pointer writer = WriterType::New();

writer->SetFileName(argv[2]);
writer->SetInput(reader->GetOutput());

try
{
writer->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while writing the image" << std::endl;
std::cerr << excp << std::endl;
ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update());

return EXIT_FAILURE;
}

std::cout << "Test finished" << std::endl;
return EXIT_SUCCESS;
}

0 comments on commit ab14339

Please sign in to comment.