1 #include "gdcmHeader.h"
6 #include "gdcmDataImages.h"
8 int InternalTest(std::string const & filename,
9 std::string const & referenceFileName )
11 std::cout << " Testing: " << filename << std::endl;
13 gdcm::File* tested = new gdcm::File( filename );
14 if( !tested->GetHeader()->IsReadable() )
16 std::cout << " Image not gdcm compatible:"
17 << filename << std::endl;
24 ////// Check for existence of reference baseline dicom file:
26 FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
30 uint8_t* testedImageData = tested->GetImageData(); // Kludge
31 tested->WriteDcmExplVR( referenceFileName );
32 std::cerr << " Creating reference baseline file :" << std::endl
33 << " " << referenceFileName
36 //delete (char*)testedImageData;
44 ////// When reference file is not gdcm readable test is failed:
46 gdcm::File* reference = new gdcm::File( referenceFileName );
47 if( !reference->GetHeader()->IsReadable() )
49 std::cout << " Reference image " << std::endl
50 << " " << referenceFileName <<std::endl
51 << " is not gdcm compatible." << std::endl;
59 int testedDataSize = tested->GetImageDataSize();
60 uint8_t* testedImageData = tested->GetImageData();
62 int referenceDataSize = reference->GetImageDataSize();
63 uint8_t* referenceImageData = reference->GetImageData();
65 if (testedDataSize != referenceDataSize)
67 std::cout << " Pixel areas lengths differ: "
68 << testedDataSize << " # " << referenceDataSize
75 if (int res = memcmp(testedImageData, referenceImageData,
76 testedDataSize) != 0 )
79 std::cout << " Pixel differ (as expanded in memory)."
85 std::cout << " Passed..." << std::endl;
87 //////////////// Clean up:
90 std::cout << " Passed clean up." << std::endl ;
95 int TestAllReadCompareDicom(int argc, char* argv[])
99 // The test is specified a specific filename, use it instead of looping
101 const std::string input = argv[1];
102 const std::string reference = argv[2];
103 return InternalTest( input, reference );
105 else if ( argc > 3 || argc == 2 )
107 std::cerr << " Usage: " << argv[0]
108 << " (no arguments needed)." << std::endl;
109 std::cerr << "or Usage: " << argv[0]
110 << " filename.dcm reference.dcm" << std::endl;
115 std::cout << " Description (Test::TestAllReadCompareDicom): "
117 std::cout << " For all images in gdcmData (and not blacklisted in "
118 "Test/CMakeLists.txt)"
120 std::cout << " apply the following to each filename.xxx: "
122 std::cout << " step 1: parse the image (as gdcmHeader) and call"
125 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
127 << " (with format DICOM V3, explicit Value"
130 std::cout << " step 3a: when image NOT found on step 2, write "
132 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
134 << " (with format DICOM V3, explicit Value"
137 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
139 << " compare it (in memory with memcmp) with the"
141 << " image we are testing (the one of step 1). "
142 << std::endl << std::endl;
146 while( gdcmDataImages[i] != 0 )
148 ////// Check for existence of reference baseline directory
150 std::string baseLineDir = GDCM_DATA_ROOT;
151 baseLineDir += "/BaselineDicom/";
153 std::ifstream* testDIR = new std::ifstream(baseLineDir.c_str(), std::ios::in | std::ios::binary);
156 std::cerr << " The reference baseline directory " << std::endl
158 << baseLineDir << std::endl
159 << " couldn't be opened."
168 ////// Step 1 (see above description):
169 std::string filename = GDCM_DATA_ROOT;
171 filename += gdcmDataImages[i];
173 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
174 std::string::size_type slash_pos = referenceFileName.rfind( "." );
175 if ( slash_pos != std::string::npos )
177 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
180 if( InternalTest( filename, referenceFileName ) != 0 )