From 6ab7886cede63947159f7dc94216e4333c464ccf Mon Sep 17 00:00:00 2001 From: malaterre Date: Sat, 31 Jul 2004 23:17:51 +0000 Subject: [PATCH] ENH: Test now support passing argument, thus instead of iterating over all images, you can pass the input dicom images and the reference image. This is pretty usefull in debug time --- Testing/TestAllReadCompareDicom.cxx | 171 ++++++++++++++++------------ 1 file changed, 96 insertions(+), 75 deletions(-) diff --git a/Testing/TestAllReadCompareDicom.cxx b/Testing/TestAllReadCompareDicom.cxx index 386a6ffb..009add40 100644 --- a/Testing/TestAllReadCompareDicom.cxx +++ b/Testing/TestAllReadCompareDicom.cxx @@ -4,73 +4,8 @@ //Generated file: #include "gdcmDataImages.h" -int TestAllReadCompareDicom(int argc, char* argv[]) +int InternalTest(std::string const & filename, std::string const & referenceFileName ) { - if ( argc > 1 ) - { - std::cerr << " Usage: " << argv[0] - << " (no arguments needed)." << std::endl; - return 1; - } - - std::cout << " Description (Test::TestAllReadCompareDicom): " - << std::endl; - std::cout << " For all images in gdcmData (and not blacklisted in " - "Test/CMakeLists.txt)" - << std::endl; - std::cout << " apply the following to each filename.xxx: " - << std::endl; - std::cout << " step 1: parse the image (as gdcmHeader) and call" - << " IsReadable(). " - << std::endl; - std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm" - << std::endl - << " (with format DICOM V3, explicit Value" - << "Representation)" - << std::endl; - std::cout << " step 3a: when image NOT found on step 2, write " - << std::endl - << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm" - << std::endl - << " (with format DICOM V3, explicit Value" - << "Representation)" - << std::endl; - std::cout << " step 3b: when image found on step 2, and when IsReadable()" - << std::endl - << " compare it (in memory with memcmp) with the" - << std::endl - << " image we are testing (the one of step 1). " - << std::endl << std::endl; - - int i = 0; - while( gdcmDataImages[i] != 0 ) - { - ////// Check for existence of reference baseline directory - - std::string baseLineDir = GDCM_DATA_ROOT; - baseLineDir += "/BaselineDicom/"; - - FILE* testFILE = fopen( baseLineDir.c_str(), "r" ); - if (! testFILE ) - { - std::cerr << " The reference baseline directory " << std::endl - << " " - << baseLineDir << std::endl - << " couldn't be opened." - << std::endl; - return 1; - } - else - { - fclose( testFILE ); - } - - ////// Step 1 (see above description): - - std::string filename = GDCM_DATA_ROOT; - filename += "/"; - filename += gdcmDataImages[i]; - std::cout << " Testing: " << filename << std::endl; gdcmFile* tested = new gdcmFile( filename, false ); @@ -86,14 +21,7 @@ int TestAllReadCompareDicom(int argc, char* argv[]) ////// Check for existence of reference baseline dicom file: - std::string referenceFileName = baseLineDir + gdcmDataImages[i++]; - std::string::size_type slash_pos = referenceFileName.rfind( "." ); - if ( slash_pos != std::string::npos ) - { - referenceFileName.replace( slash_pos + 1, 3, "dcm" ); - } - - testFILE = fopen( referenceFileName.c_str(), "r" ); + FILE* testFILE = fopen( referenceFileName.c_str(), "r" ); if (! testFILE ) { ////// Step 3a: @@ -107,7 +35,7 @@ int TestAllReadCompareDicom(int argc, char* argv[]) << std::endl; delete tested; delete (char*)testedImageData; - continue; + //continue; } else { @@ -166,6 +94,99 @@ int TestAllReadCompareDicom(int argc, char* argv[]) delete reference; delete (char*)testedImageData; delete (char*)referenceImageData; + + return 0; +} + +int TestAllReadCompareDicom(int argc, char* argv[]) +{ + if ( argc == 3 ) + { + // The test is specified a specific filename, use it instead of looping + // over all images + const std::string input = argv[1]; + const std::string reference = argv[2]; + return InternalTest( input, reference ); + } + else if ( argc > 3 || argc == 2 ) + { + std::cerr << " Usage: " << argv[0] + << " (no arguments needed)." << std::endl; + std::cerr << "or Usage: " << argv[0] + << " filename.dcm reference.dcm" << std::endl; + return 1; + } + // else other cases: + + std::cout << " Description (Test::TestAllReadCompareDicom): " + << std::endl; + std::cout << " For all images in gdcmData (and not blacklisted in " + "Test/CMakeLists.txt)" + << std::endl; + std::cout << " apply the following to each filename.xxx: " + << std::endl; + std::cout << " step 1: parse the image (as gdcmHeader) and call" + << " IsReadable(). " + << std::endl; + std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm" + << std::endl + << " (with format DICOM V3, explicit Value" + << "Representation)" + << std::endl; + std::cout << " step 3a: when image NOT found on step 2, write " + << std::endl + << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm" + << std::endl + << " (with format DICOM V3, explicit Value" + << "Representation)" + << std::endl; + std::cout << " step 3b: when image found on step 2, and when IsReadable()" + << std::endl + << " compare it (in memory with memcmp) with the" + << std::endl + << " image we are testing (the one of step 1). " + << std::endl << std::endl; + + int i = 0; + while( gdcmDataImages[i] != 0 ) + { + ////// Check for existence of reference baseline directory + + std::string baseLineDir = GDCM_DATA_ROOT; + baseLineDir += "/BaselineDicom/"; + + FILE* testFILE = fopen( baseLineDir.c_str(), "r" ); + if (!testFILE ) + { + std::cerr << " The reference baseline directory " << std::endl + << " " + << baseLineDir << std::endl + << " couldn't be opened." + << std::endl; + return 1; + } + else + { + fclose( testFILE ); + } + + ////// Step 1 (see above description): + + std::string filename = GDCM_DATA_ROOT; + filename += "/"; + filename += gdcmDataImages[i]; + + std::string referenceFileName = baseLineDir + gdcmDataImages[i++]; + std::string::size_type slash_pos = referenceFileName.rfind( "." ); + if ( slash_pos != std::string::npos ) + { + referenceFileName.replace( slash_pos + 1, 3, "dcm" ); + } + + if( InternalTest( filename, referenceFileName ) != 0 ) + { + return 1; + } } return 0; -- 2.45.1