From: frog Date: Tue, 29 Jun 2004 14:00:37 +0000 (+0000) Subject: * Test/TestWriteRead.cxx and TestReadWrite.cxx merged (because of X-Git-Tag: Version0.5.bp~69 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=864a539efcd809529bf7f1d6aad6727fd40ace66;hp=5222e6cd8520ec5cc0247d850982721becf4756a;p=gdcm.git * Test/TestWriteRead.cxx and TestReadWrite.cxx merged (because of redundancy) to added Test/TestReadWriteReadCompare.cxx * Test/CmakeList.txt: because the compare test of Test/TestReadWriteReadCompare.cxx fails, the following images are black listed: - 8BitsUncompressedColor.dcm - OT-PAL-8-face.dcm - US-PAL-8-10x-echo.dcm --- diff --git a/ChangeLog b/ChangeLog index ebd17071..9e9c5b05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ 2004-06-28 Eric Boix + * Test/TestWriteRead.cxx and TestReadWrite.cxx merged (because of + redundancy) to added Test/TestReadWriteReadCompare.cxx + * Test/CmakeList.txt: because the compare test of + Test/TestReadWriteReadCompare.cxx fails, the following images are + black listed: - 8BitsUncompressedColor.dcm + - OT-PAL-8-face.dcm + - US-PAL-8-10x-echo.dcm * src/gdcmDocument.cxx: for broken (non DICOM V3 conformal) images (e.g. gdcm-JPEG-LossLess3a.dcm see comments in gdcm/gdcmPython/testSuite.py for details) ::FindDocLengthOB() had @@ -12,6 +19,7 @@ (because TestWriteRead breaks on it, after a non conformal commit?). ctest now runs properly, except for MakeDicomDir (which was allways broken) and the Python related stuff (still not fixed). + 2004-06-24 Jean-Pierre Roux ADD : Examples/WriteRead, that acts like the former Test/TestWriteRead FIX : Test/TestReadWrite now iterates on all the file names diff --git a/Example/PrintDocument.cxx b/Example/PrintDocument.cxx index 617c8616..940b8166 100644 --- a/Example/PrintDocument.cxx +++ b/Example/PrintDocument.cxx @@ -20,12 +20,12 @@ int main(int argc, char* argv[]) { -// gdcmFile *e2; gdcmHeader *e1; std::string fileName; if (argc != 2) { - std::cout << " usage : PrintDocument fileName" << std::endl; + std::cout << " Usage : " << argv[0] + << " filename." << std::endl; } if (argc > 1) { diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index fe4fa8b1..42ffc05b 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -12,7 +12,7 @@ SET(TEST_SOURCES TestDcm2Acr.cxx TestHash.cxx TestWrite.cxx - TestWriteRead.cxx + TestReadWriteReadCompare.cxx TestWriteSimple.cxx ) @@ -26,7 +26,6 @@ IF (GDCM_DATA_ROOT) TestChangeHeader.cxx TestDicomDir.cxx #require DICOMDIR BuildUpDicomDir.cxx - TestReadWrite.cxx makeDicomDir.cxx ) # add test that require VTK: @@ -114,7 +113,10 @@ SET(BLACK_LIST "irmPhlipsNew1.dcm" #png looks ugly "mriThruVPRO.dcm" #png looks ugly "US.3405.1.dcm" #looks exactly the same as US.1.2.dcm - "8BitsRunLengthColor.dcm" # Write broken + "8BitsRunLengthColor.dcm" # Write dicom broken + "8BitsUncompressedColor.dcm" # Write dicom broken + "OT-PAL-8-face.dcm" # Write dicom broken + "US-PAL-8-10x-echo.dcm" # Write dicom broken ) # gdcm-ACR-LibIDO seems to be cut diff --git a/Testing/TestHash.cxx b/Testing/TestHash.cxx index ffd89540..771b7bba 100644 --- a/Testing/TestHash.cxx +++ b/Testing/TestHash.cxx @@ -1,3 +1,4 @@ +// Checks the basic functionalities of STL . #include #include #include @@ -5,34 +6,46 @@ int TestHash( int, char * [] ) { - typedef std::map dict; - + std::cout << "Test::TestHash : " << std::endl; + std::cout << " Checks that the basic STL functionalities required " + << std::endl + << " by gdcm are operational. " << std::endl; + + typedef std::map dict; dict tb1; + + // Adding entries by key: + dict::iterator im = tb1.find("00380010"); tb1["00100010"] = "Patient Name"; tb1["7fe00010"] = "Pixel Data"; tb1["50000010"] = "Number of points"; tb1["00380010"] = "Admission ID"; - std::cout << "Traversal of dictionary (note the proper ordering on key)." << std::endl; + // Travesing the dictionary: + + std::cout << " Traversal of dictionary (note the proper ordering on key):" + << std::endl; for ( im = tb1.begin(); im != tb1.end(); ++im ) - std::cout << " \"" << im->first << "\" = " << im->second << std::endl; - std::cout << "End of dictionary." << std::endl; + std::cout << " \"" << im->first << "\" = " << im->second + << std::endl; + std::cout << " End of dictionary." << std::endl; + + // Find request. - std::cout << "Find request on key 00380010" << std::endl; + std::cout << " Find request on key 00380010" << std::endl; im = tb1.find("00380010"); - std::cout << " \"" << im->first << "\" = " << im->second << std::endl; + std::cout << " \"" << im->first << "\" = " << im->second << std::endl; + // The following should print in hexadecimal an in decimal the given + // integer as stated by: + // http://www.developer.com/net/cplus/article.php/10919_2119781_3 + // Alas it doesn't work with g++ (at least)... int i = 0x0010; std::cout.setf(std::ios::hex); - std::cout << i << std::endl; + std::cout << "Test::TestHash : hexdecimal output : " << i << std::endl; std::cout.setf(std::ios::dec); - std::cout << i << std::endl; - -// Voir : -//http://www.developer.com/net/cplus/article.php/10919_2119781_3 -// -// dommage que ca ne marche pas ... + std::cout << "Test::TestHash : decimal output : " << i << std::endl; - return 0; + return 0; } diff --git a/Testing/TestReadWriteReadCompare.cxx b/Testing/TestReadWriteReadCompare.cxx new file mode 100644 index 00000000..356ddbd9 --- /dev/null +++ b/Testing/TestReadWriteReadCompare.cxx @@ -0,0 +1,116 @@ +#include "gdcmHeader.h" +#include "gdcmFile.h" + +//Generated file: +#include "gdcmDataImages.h" + +int TestReadWriteReadCompare(int argc, char* argv[]) +{ + if (argc) { + std::cerr << "Test::TestReadWriteReadCompare: Usage: " << argv[0] + << " (no arguments needed)." << std::endl; + } + + std::cout<< "Test::TestReadWriteReadCompare: description " << std::endl; + std::cout << " For all images in gdcmData (and not blacklisted in " + "Test/CMakeLists.txt)" << std::endl; + std::cout << " apply the following multistep test: " << std::endl; + std::cout << " step 1: parse the image (as gdcmHeader) and call" + << " IsReadable(). " << std::endl; + std::cout << " step 2: write the corresponding image in DICOM V3 " + << "with explicit" << std::endl + << " Value Representation in temporary file " + << "TestReadWriteReadCompare.dcm." << std::endl; + std::cout << " step 3: read the image written on step2 and call " + << " IsReadable(). " << std::endl; + std::cout << " step 4: compare (in memory with memcmp) that the two " + << "images " << std::endl + << " match (as expanded by gdcm)." << std::endl; + + int i = 0; + while( gdcmDataImages[i] != 0 ) + { + std::string filename = GDCM_DATA_ROOT; + filename += "/"; //doh! + filename += gdcmDataImages[i++]; + + std::cout << " Testing: " << filename << std::endl; + + //////////////// Step 1 (see above description): + + gdcmHeader *header = new gdcmHeader( filename.c_str(), false, true ); + if( !header->IsReadable() ) + { + std::cerr << "Test::TestReadWriteReadCompare: Image not gdcm compatible:" + << filename << std::endl; + delete header; + return 0; + } + std::cout << " step 1 ..."; + + //////////////// Step 2: + + gdcmFile* file = new gdcmFile( header ); + int dataSize = file->GetImageDataSize(); + void* imageData = file->GetImageData(); //EXTREMELY IMPORTANT + + file->SetImageData(imageData, dataSize); + file->WriteDcmExplVR( "TestReadWriteReadCompare.dcm" ); + std::cout << " 2..."; + + //////////////// Step 3: + + gdcmFile* reread = new gdcmFile( "TestReadWriteReadCompare.dcm", + false, true ); + if( !reread->GetHeader()->IsReadable() ) + { + std::cerr << "Test::TestReadWriteReadCompare: Could not reread image " + << "written:" << filename << std::endl; + delete header; + delete file; + delete reread; + return 1; + } + std::cout << " 3..."; + // For the next step: + int dataSizeWritten = reread->GetImageDataSize(); + void* imageDataWritten = reread->GetImageData(); + + //////////////// Step 4: + + if (dataSize != dataSizeWritten) + { + std::cout << std::endl + << " Pixel areas lengths differ: " + << dataSize << " # " << dataSizeWritten << std::endl; + delete (char*)imageData; + delete (char*)imageDataWritten; + delete header; + delete file; + delete reread; + return 1; + } + + if (int res=memcmp(imageData, imageDataWritten, dataSize) !=0) + { + std::cout << std::endl + << " Pixel differ (as expanded in memory)." << std::endl; + delete (char*)imageData; + delete (char*)imageDataWritten; + delete header; + delete file; + delete reread; + return 1; + } + std::cout << " 4...OK." << std::endl ; + + //////////////// Clean up: + delete (char*)imageData; + delete (char*)imageDataWritten; + delete header; + delete file; + delete reread; + } + + return 0; +}