From d1249e8bb14c38b82b4f5591c34203b23b0b48e8 Mon Sep 17 00:00:00 2001 From: jpr Date: Wed, 26 Jan 2005 16:43:10 +0000 Subject: [PATCH] Renaming some local variables + test coverage improvement --- Testing/TestCopyDicom.cxx | 12 +++---- Testing/TestCopyRescaleDicom.cxx | 62 ++++++++++++++++---------------- Testing/TestDicomDir.cxx | 26 +++++++------- Testing/TestDicomDirElement.cxx | 14 +++++--- Testing/TestDict.cxx | 30 ++++++++++++++-- Testing/TestWriteSimple.cxx | 54 ++++++++++++++-------------- 6 files changed, 114 insertions(+), 84 deletions(-) diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index 1dfd328e..8c3ad749 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 15:44:22 $ - Version: $Revision: 1.36 $ + Date: $Date: 2005/01/26 16:43:10 $ + Version: $Revision: 1.37 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -74,7 +74,7 @@ int CopyDicom(std::string const & filename, gdcm::File *originalH = new gdcm::File( filename ); gdcm::File *copyH = new gdcm::File( ); - //First of all copy the header field by field + //First of all copy the file, field by field //////////////// Step 2: std::cout << "2..."; @@ -107,8 +107,8 @@ int CopyDicom(std::string const & filename, size_t dataSize = original->GetImageDataSize(); uint8_t* imageData = original->GetImageData(); - // Useless to set the image datas, because it's already made when - // copying the corresponding BinEntry that contains the pixel datas + // Useless to set the image data, because it's already made when + // copying the corresponding BinEntry that contains the pixel data copy->SetImageData(imageData, dataSize); //////////////// Step 3: @@ -220,7 +220,7 @@ int TestCopyDicom(int argc, char* argv[]) << "GetImageDataSize() " << std::endl; std::cout << " step 2: create a copy of the readed file and the new" - << " pixel datas are set to the copy" + << " pixel data are set to the copy" << std::endl; std::cout << " step 3: write the copy of the image" << std::endl; diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index 3400ec86..dc9b2a92 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyRescaleDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 15:44:22 $ - Version: $Revision: 1.11 $ + Date: $Date: 2005/01/26 16:43:10 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,26 +43,26 @@ int CopyRescaleDicom(std::string const & filename, //////////////// Step 1: std::cout << " 1..."; - gdcm::File *originalH = new gdcm::File( filename ); - gdcm::File *copyH = new gdcm::File( ); + gdcm::File *originalF = new gdcm::File( filename ); + gdcm::File *copyF = new gdcm::File( ); - //First of all copy the header field by field + //First of all copy the file, field by field //////////////// Step 2: std::cout << "2..."; // Copy of the header content - gdcm::DocEntry* d = originalH->GetFirstEntry(); + gdcm::DocEntry* d = originalF->GetFirstEntry(); while(d) { if ( gdcm::BinEntry* b = dynamic_cast(d) ) { - copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(), + copyF->InsertBinEntry( b->GetBinArea(),b->GetLength(), b->GetGroup(),b->GetElement(), b->GetVR() ); } else if ( gdcm::ValEntry* v = dynamic_cast(d) ) { - copyH->InsertValEntry( v->GetValue(), + copyF->InsertValEntry( v->GetValue(), v->GetGroup(),v->GetElement(), v->GetVR() ); } @@ -71,25 +71,25 @@ int CopyRescaleDicom(std::string const & filename, // We skip pb of SQ recursive exploration } - d=originalH->GetNextEntry(); + d=originalF->GetNextEntry(); } - gdcm::FileHelper *original = new gdcm::FileHelper( originalH ); - gdcm::FileHelper *copy = new gdcm::FileHelper( copyH ); + gdcm::FileHelper *original = new gdcm::FileHelper( originalF ); + gdcm::FileHelper *copy = new gdcm::FileHelper( copyF ); size_t dataSize = original->GetImageDataSize(); size_t rescaleSize; uint8_t *rescaleImage; - const std::string & bitsStored = originalH->GetEntryValue(0x0028,0x0101); + const std::string & bitsStored = originalF->GetEntryValue(0x0028,0x0101); if( bitsStored == "16" ) { std::cout << "Rescale..."; - copyH->InsertValEntry( "8", 0x0028, 0x0100); // BitsAllocated - copyH->InsertValEntry( "8", 0x0028, 0x0101); // BitsStored - copyH->InsertValEntry( "7", 0x0028, 0x0102); // HighBit - copyH->InsertValEntry( "0", 0x0028, 0x0103); //Pixel Representation + copyF->InsertValEntry( "8", 0x0028, 0x0100); // BitsAllocated + copyF->InsertValEntry( "8", 0x0028, 0x0101); // BitsStored + copyF->InsertValEntry( "7", 0x0028, 0x0102); // HighBit + copyF->InsertValEntry( "0", 0x0028, 0x0103); //Pixel Representation // We assume the value were from 0 to uint16_t max rescaleSize = dataSize / 2; @@ -121,15 +121,15 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; - delete copyH; + delete originalF; + delete copyF; delete[] rescaleImage; return 1; } delete copy; - delete copyH; + delete copyF; //////////////// Step 4: std::cout << "4..."; @@ -142,7 +142,7 @@ int CopyRescaleDicom(std::string const & filename, << " " << output << " not readable" << std::endl; delete original; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -153,21 +153,21 @@ int CopyRescaleDicom(std::string const & filename, size_t dataSizeWritten = copy->GetImageDataSize(); uint8_t* imageDataWritten = copy->GetImageData(); - if (originalH->GetXSize() != copy->GetFile()->GetXSize() || - originalH->GetYSize() != copy->GetFile()->GetYSize() || - originalH->GetZSize() != copy->GetFile()->GetZSize()) + if (originalF->GetXSize() != copy->GetFile()->GetXSize() || + originalF->GetYSize() != copy->GetFile()->GetYSize() || + originalF->GetZSize() != copy->GetFile()->GetZSize()) { std::cout << "Failed" << std::endl << " X Size differs: " - << "X: " << originalH->GetXSize() << " # " + << "X: " << originalF->GetXSize() << " # " << copy->GetFile()->GetXSize() << " | " - << "Y: " << originalH->GetYSize() << " # " + << "Y: " << originalF->GetYSize() << " # " << copy->GetFile()->GetYSize() << " | " - << "Z: " << originalH->GetZSize() << " # " + << "Z: " << originalF->GetZSize() << " # " << copy->GetFile()->GetZSize() << std::endl; delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -181,7 +181,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -195,7 +195,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -204,7 +204,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 0; @@ -245,7 +245,7 @@ int TestCopyRescaleDicom(int argc, char* argv[]) << "GetImageDataSize() " << std::endl; std::cout << " step 2: create a copy of the readed file and the new" - << " pixel datas are set to the copy" + << " pixel data are set to the copy" << std::endl; std::cout << " step 3: write the copy of the image" << std::endl; diff --git a/Testing/TestDicomDir.cxx b/Testing/TestDicomDir.cxx index ea6b686e..64bc7d75 100644 --- a/Testing/TestDicomDir.cxx +++ b/Testing/TestDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:10:50 $ - Version: $Revision: 1.32 $ + Date: $Date: 2005/01/26 16:43:10 $ + Version: $Revision: 1.33 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -28,7 +28,7 @@ int TestDicomDir(int argc, char* argv[]) { - gdcm::DicomDir *e1; + gdcm::DicomDir *dicomdir; gdcm::DicomDirPatient *pa; gdcm::DicomDirStudy *st; @@ -46,21 +46,21 @@ int TestDicomDir(int argc, char* argv[]) file += "/DICOMDIR"; } - e1 = new gdcm::DicomDir(file); + dicomdir = new gdcm::DicomDir(file); if (argc > 2) { int level = atoi(argv[2]); - e1->SetPrintLevel(level); + dicomdir->SetPrintLevel(level); } // Test if the DicomDir is readable - if( !e1->IsReadable() ) + if( !dicomdir->IsReadable() ) { std::cout<<" DicomDir '"<GetFirstPatient() ) + if( !dicomdir->GetFirstPatient() ) { std::cout<<" DicomDir '"<GetFirstPatient(); + pa = dicomdir->GetFirstPatient(); while ( pa ) { // we process all the PATIENT of this DICOMDIR std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name @@ -112,16 +112,16 @@ int TestDicomDir(int argc, char* argv[]) } st = pa->GetNextStudy(); } - pa = e1->GetNextPatient(); + pa = dicomdir->GetNextPatient(); } std::cout << std::endl << std::endl << " = DICOMDIR full content ====================================" << std::endl<< std::endl; - e1->Print(); + dicomdir->Print(); std::cout<Print( std::cout ); + delete ddElt; return 0; } diff --git a/Testing/TestDict.cxx b/Testing/TestDict.cxx index db151958..54c87a5b 100644 --- a/Testing/TestDict.cxx +++ b/Testing/TestDict.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestDict.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 14:14:09 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/01/26 16:43:10 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,7 +24,19 @@ #include int TestDict(int , char* []) -{ +{ + + std::cout << "-------- Test Default Dicom Dictionary : ----------" << std::endl; + // Just to improve test coverage: + gdcm::Dict *tempDict = new gdcm::Dict("dummyFileNameThatDoesntExist"); + // Default dict is supposed to be used. + tempDict->Print(); + std::cout << "-------- end Test Default Dicom Dictionary : --------" << std::endl; + + // Lets delete it. + delete tempDict; + + // Print the DictSet std::cout<<"#######################################################\n"; gdcm::DictSet *dicts=gdcm::Global::GetDicts(); @@ -42,6 +54,11 @@ int TestDict(int , char* []) std::cout << "Dictset is empty" << std::endl; return 1; } + + std::cout << "----------- Print DictSet contents: ----------" << std::endl; + dicts->Print(); + std::cout << "----------- End Print DictSet contents: ------" << std::endl; + while (d) { std::cout << "------------- a Dict is found : ----------" << std::endl; @@ -85,5 +102,12 @@ int TestDict(int , char* []) entry=pubDict->GetNextEntry(); } + // Let's play with DicEntry stuff ! + + // First, we try to break an Entry. + entry=pubDict->GetFirstEntry(); + entry->SetVR("PN"); + // Should warn us ! + return(0); } diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index af00b7c5..60b31813 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Testing/TestWriteSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWriteSimple.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 15:44:23 $ - Version: $Revision: 1.16 $ + Date: $Date: 2005/01/26 16:43:10 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -72,54 +72,54 @@ int WriteSimple(Image &img) // Step 1 : Create the header of the image std::cout << " 1..."; - gdcm::File *header = new gdcm::File(); + gdcm::File *fileToBuild = new gdcm::File(); std::ostringstream str; // Set the image size str.str(""); str << img.sizeX; - header->InsertValEntry(str.str(),0x0028,0x0011); // Columns + fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns str.str(""); str << img.sizeY; - header->InsertValEntry(str.str(),0x0028,0x0010); // Rows + fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows if(img.sizeZ>1) { str.str(""); str << img.sizeZ; - header->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames + fileToBuild->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames } // Set the pixel type str.str(""); str << img.componentSize; - header->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated + fileToBuild->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated str.str(""); str << img.componentUse; - header->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored + fileToBuild->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << img.componentSize - 1; - header->InsertValEntry(str.str(),0x0028,0x0102); // High Bit + fileToBuild->InsertValEntry(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation str.str(""); str << img.sign; - header->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation + fileToBuild->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation // Set the samples per pixel str.str(""); str << img.components; - header->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel + fileToBuild->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel - if( !header->IsReadable() ) + if( !fileToBuild->IsReadable() ) { std::cout << "Failed\n" << " Prepared image isn't readable\n"; - delete header; + delete fileToBuild; return 1; } @@ -156,7 +156,7 @@ int WriteSimple(Image &img) // Step 3 : Create the file of the image std::cout << "3..."; - gdcm::FileHelper *file = new gdcm::FileHelper(header); + gdcm::FileHelper *file = new gdcm::FileHelper(fileToBuild); file->SetImageData(imageData,size); // Step 4 : Set the writting mode and write the image @@ -182,7 +182,7 @@ int WriteSimple(Image &img) << " Write mode '"<GetImageData(); // Test the image size - if (header->GetXSize() != reread->GetFile()->GetXSize() || - header->GetYSize() != reread->GetFile()->GetYSize() || - header->GetZSize() != reread->GetFile()->GetZSize()) + if (fileToBuild->GetXSize() != reread->GetFile()->GetXSize() || + fileToBuild->GetYSize() != reread->GetFile()->GetYSize() || + fileToBuild->GetZSize() != reread->GetFile()->GetZSize()) { std::cout << "Failed" << std::endl << " X Size differs: " - << "X: " << header->GetXSize() << " # " + << "X: " << fileToBuild->GetXSize() << " # " << reread->GetFile()->GetXSize() << " | " - << "Y: " << header->GetYSize() << " # " + << "Y: " << fileToBuild->GetYSize() << " # " << reread->GetFile()->GetYSize() << " | " - << "Z: " << header->GetZSize() << " # " + << "Z: " << fileToBuild->GetZSize() << " # " << reread->GetFile()->GetZSize() << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -244,7 +244,7 @@ int WriteSimple(Image &img) std::cout << "Failed" << std::endl << " Pixel areas lengths differ: " << size << " # " << dataSizeWritten << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -258,7 +258,7 @@ int WriteSimple(Image &img) (void)res; std::cout << "Failed" << std::endl << " Pixel differ (as expanded in memory)." << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -268,7 +268,7 @@ int WriteSimple(Image &img) std::cout << "OK" << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; -- 2.48.1