Skip to content

Commit

Permalink
BUG: A temporary work-around for HDF5 testing
Browse files Browse the repository at this point in the history
The HDF5ImageIO objects are single use for writing.  After
the initial use, the WriteImageInformation function is
short circuited, and can not be reset for writing a second image.

This bug was exposed while fixing a problem with the not
throwing an exception when attempting to write to a path
that does not exist.

This temporary work around in the test framework allows fixing
the initial problem without requiring fixing the HDF5ImageIO
re-use issues.

NOTE: Resetting the HDF5ImageIO object at the end of writing
fixes the re-use problem for non-streaming case, but that
causes the streaming tests to fail.
  • Loading branch information
hjmjohnson committed Aug 8, 2022
1 parent bbddf47 commit 2ddf427
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Modules/IO/HDF5/src/itkHDF5ImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,9 @@ HDF5ImageIO ::Write(const void * buffer)
itkExceptionMacro(<< "Unspecified error occured during Write: " << this->GetFileName() << " with "
<< this->GetNameOfClass());
}
// TODO: including this line allows the IO object to be re-used multiple times for writing, but
// but causes the streaming tests for HDF5ImageIO to fail.
// this->ResetToInitialState();
}

//
Expand Down
14 changes: 9 additions & 5 deletions Modules/IO/ImageBase/include/itkIOTestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ class IOTestHelper
const std::string & filename,
typename ImageIOType::Pointer imageio = nullptr)
{
if (imageio.IsNull())
{
imageio = ImageIOType::New();
}
const bool create_local_io_object{ imageio.IsNull() };
using WriterType = itk::ImageFileWriter<ImageType>;
{ // Test valid filename writing
if (create_local_io_object)
{
imageio = ImageIOType::New();
}
auto writer = WriterType::New();
writer->SetImageIO(imageio);
writer->SetFileName(filename);
Expand All @@ -100,7 +101,10 @@ class IOTestHelper
}
}

{ // Test if writing to an invalid location causes exception to be thrown:
{ // Test if writing to an invalid location causes exception to be thrown:
imageio = imageio->Clone(); // A new io object is needed because the HDF5 io object is single use. A new IO
// object is needed to re-intialize the internal state.

const std::string bad_root_path{ "/a_blatantly_obvious/bad_file_path/that/should/never/exist/on/the/computer/" };
const std::string bad_filename{ bad_root_path + filename };
bool exception_correctly_caught = false;
Expand Down

0 comments on commit 2ddf427

Please sign in to comment.