1 #include "gdcmHeader.h"
5 #include "gdcmDataImages.h"
7 int InternalTest(std::string const & filename, std::string const & referenceFileName )
9 std::cout << " Testing: " << filename << std::endl;
11 gdcmFile* tested = new gdcmFile( filename );
12 if( !tested->GetHeader()->IsReadable() )
14 std::cout << " Image not gdcm compatible:"
15 << filename << std::endl;
22 ////// Check for existence of reference baseline dicom file:
24 FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
29 int testedDataSize = tested->GetImageDataSize();
31 void* testedImageData = tested->GetImageData(); // Kludge
32 tested->WriteDcmExplVR( referenceFileName );
33 std::cerr << " Creating reference baseline file :" << std::endl
34 << " " << referenceFileName
37 delete (char*)testedImageData;
45 ////// When reference file is not gdcm readable test is failed:
47 gdcmFile* reference = new gdcmFile( referenceFileName );
48 if( !reference->GetHeader()->IsReadable() )
50 std::cout << " Reference image " << std::endl
51 << " " << referenceFileName <<std::endl
52 << " is not gdcm compatible." << std::endl;
60 int testedDataSize = tested->GetImageDataSize();
61 void* testedImageData = tested->GetImageData();
63 int referenceDataSize = reference->GetImageDataSize();
64 void* referenceImageData = reference->GetImageData();
66 if (testedDataSize != referenceDataSize)
68 std::cout << " Pixel areas lengths differ: "
69 << testedDataSize << " # " << referenceDataSize
73 delete (char*)testedImageData;
74 delete (char*)referenceImageData;
78 if (int res = memcmp(testedImageData, referenceImageData,
79 testedDataSize) != 0 )
82 std::cout << " Pixel differ (as expanded in memory)."
86 delete (char*)testedImageData;
87 delete (char*)referenceImageData;
90 std::cout << " Passed." << std::endl ;
92 //////////////// Clean up:
95 delete (char*)testedImageData;
96 delete (char*)referenceImageData;
101 int TestAllReadCompareDicom(int argc, char* argv[])
105 // The test is specified a specific filename, use it instead of looping
107 const std::string input = argv[1];
108 const std::string reference = argv[2];
109 return InternalTest( input, reference );
111 else if ( argc > 3 || argc == 2 )
113 std::cerr << " Usage: " << argv[0]
114 << " (no arguments needed)." << std::endl;
115 std::cerr << "or Usage: " << argv[0]
116 << " filename.dcm reference.dcm" << std::endl;
121 std::cout << " Description (Test::TestAllReadCompareDicom): "
123 std::cout << " For all images in gdcmData (and not blacklisted in "
124 "Test/CMakeLists.txt)"
126 std::cout << " apply the following to each filename.xxx: "
128 std::cout << " step 1: parse the image (as gdcmHeader) and call"
131 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
133 << " (with format DICOM V3, explicit Value"
136 std::cout << " step 3a: when image NOT found on step 2, write "
138 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
140 << " (with format DICOM V3, explicit Value"
143 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
145 << " compare it (in memory with memcmp) with the"
147 << " image we are testing (the one of step 1). "
148 << std::endl << std::endl;
151 while( gdcmDataImages[i] != 0 )
153 ////// Check for existence of reference baseline directory
155 std::string baseLineDir = GDCM_DATA_ROOT;
156 baseLineDir += "/BaselineDicom/";
158 FILE* testFILE = fopen( baseLineDir.c_str(), "r" );
161 std::cerr << " The reference baseline directory " << std::endl
163 << baseLineDir << std::endl
164 << " couldn't be opened."
173 ////// Step 1 (see above description):
175 std::string filename = GDCM_DATA_ROOT;
177 filename += gdcmDataImages[i];
179 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
180 std::string::size_type slash_pos = referenceFileName.rfind( "." );
181 if ( slash_pos != std::string::npos )
183 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
186 if( InternalTest( filename, referenceFileName ) != 0 )