1 #include "gdcmHeader.h"
5 #include "gdcmDataImages.h"
7 int InternalTest(std::string const & filename,
8 std::string const & referenceFileName )
10 std::cout << " Testing: " << filename << std::endl;
12 gdcm::File* tested = new gdcm::File( filename );
13 if( !tested->GetHeader()->IsReadable() )
15 std::cout << " Image not gdcm compatible:"
16 << filename << std::endl;
23 ////// Check for existence of reference baseline dicom file:
25 FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
30 int testedDataSize = tested->GetImageDataSize();
32 void* testedImageData = tested->GetImageData(); // Kludge
33 tested->WriteDcmExplVR( referenceFileName );
34 std::cerr << " Creating reference baseline file :" << std::endl
35 << " " << referenceFileName
38 delete (char*)testedImageData;
46 ////// When reference file is not gdcm readable test is failed:
48 gdcm::File* reference = new gdcm::File( referenceFileName );
49 if( !reference->GetHeader()->IsReadable() )
51 std::cout << " Reference image " << std::endl
52 << " " << referenceFileName <<std::endl
53 << " is not gdcm compatible." << std::endl;
61 int testedDataSize = tested->GetImageDataSize();
62 void* testedImageData = tested->GetImageData();
64 int referenceDataSize = reference->GetImageDataSize();
65 void* referenceImageData = reference->GetImageData();
67 if (testedDataSize != referenceDataSize)
69 std::cout << " Pixel areas lengths differ: "
70 << testedDataSize << " # " << referenceDataSize
74 delete (char*)testedImageData;
75 delete (char*)referenceImageData;
79 if (int res = memcmp(testedImageData, referenceImageData,
80 testedDataSize) != 0 )
83 std::cout << " Pixel differ (as expanded in memory)."
87 delete (char*)testedImageData;
88 delete (char*)referenceImageData;
91 std::cout << " Passed." << std::endl ;
93 //////////////// Clean up:
96 delete (char*)testedImageData;
97 delete (char*)referenceImageData;
102 int TestAllReadCompareDicom(int argc, char* argv[])
106 // The test is specified a specific filename, use it instead of looping
108 const std::string input = argv[1];
109 const std::string reference = argv[2];
110 return InternalTest( input, reference );
112 else if ( argc > 3 || argc == 2 )
114 std::cerr << " Usage: " << argv[0]
115 << " (no arguments needed)." << std::endl;
116 std::cerr << "or Usage: " << argv[0]
117 << " filename.dcm reference.dcm" << std::endl;
122 std::cout << " Description (Test::TestAllReadCompareDicom): "
124 std::cout << " For all images in gdcmData (and not blacklisted in "
125 "Test/CMakeLists.txt)"
127 std::cout << " apply the following to each filename.xxx: "
129 std::cout << " step 1: parse the image (as gdcmHeader) and call"
132 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
134 << " (with format DICOM V3, explicit Value"
137 std::cout << " step 3a: when image NOT found on step 2, write "
139 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
141 << " (with format DICOM V3, explicit Value"
144 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
146 << " compare it (in memory with memcmp) with the"
148 << " image we are testing (the one of step 1). "
149 << std::endl << std::endl;
153 while( gdcmDataImages[i] != 0 )
155 ////// Check for existence of reference baseline directory
157 std::string baseLineDir = GDCM_DATA_ROOT;
158 baseLineDir += "/BaselineDicom/";
160 std::ifstream* testDIR = new std::ifstream(baseLineDir.c_str(), std::ios::in | std::ios::binary);
163 std::cerr << " The reference baseline directory " << std::endl
165 << baseLineDir << std::endl
166 << " couldn't be opened."
175 /* FILE* testFILE = fopen( baseLineDir.c_str(), "r" );
178 std::cerr << " The reference baseline directory " << std::endl
180 << baseLineDir << std::endl
181 << " couldn't be opened."
190 ////// Step 1 (see above description):
192 std::string filename = GDCM_DATA_ROOT;
194 filename += gdcmDataImages[i];
196 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
197 std::string::size_type slash_pos = referenceFileName.rfind( "." );
198 if ( slash_pos != std::string::npos )
200 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
203 if( InternalTest( filename, referenceFileName ) != 0 )