]> Creatis software - gdcm.git/commitdiff
Renaming some local variables + test coverage improvement
authorjpr <jpr>
Wed, 26 Jan 2005 16:43:10 +0000 (16:43 +0000)
committerjpr <jpr>
Wed, 26 Jan 2005 16:43:10 +0000 (16:43 +0000)
Testing/TestCopyDicom.cxx
Testing/TestCopyRescaleDicom.cxx
Testing/TestDicomDir.cxx
Testing/TestDicomDirElement.cxx
Testing/TestDict.cxx
Testing/TestWriteSimple.cxx

index 1dfd328ead71784d6260dd3eca6435664edfd1cf..8c3ad7491b056a390eadeabee24ef9b5eec5e11e 100644 (file)
@@ -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;
index 3400ec8668760ded239002150cd7ded6e3d748df..dc9b2a9244e4db63308419364fbcc626e29a4adf 100644 (file)
@@ -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<gdcm::BinEntry*>(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<gdcm::ValEntry*>(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;
index ea6b686eeaa598395a1c46dc1ff1a424078f1887..64bc7d754973270cb1b99777ae3936327e1d8b42 100644 (file)
@@ -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 '"<<file
                <<"' is not readable"<<std::endl
                <<"          ...Failed"<<std::endl;
 
-      delete e1;
+      delete dicomdir;
       return 1;
    }
    else
@@ -70,13 +70,13 @@ int TestDicomDir(int argc, char* argv[])
    }
 
    // Test if the DicomDir contains any Patient
-   if( !e1->GetFirstPatient() )
+   if( !dicomdir->GetFirstPatient() )
    {
       std::cout<<"          DicomDir '"<<file
                <<" has no patient"<<std::endl
                <<"          ...Failed"<<std::endl;
 
-      delete e1;
+      delete dicomdir;
       return 1;
    }
 
@@ -85,7 +85,7 @@ int TestDicomDir(int argc, char* argv[])
              << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
              << std::endl<< std::endl;
   
-   pa = e1->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<<std::flush;
-   delete e1;
+   delete dicomdir;
 
    return 0;
 }
index 82e3f66dd398ad7f8565cf6a935132dc681c7fd6..ddea03e5364f67add4a3a280b1897359cacb4d4f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestDicomDirElement.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/24 14:14:09 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/01/26 16:43:10 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 int TestDicomDirElement(int , char *[])
 {
-   gdcm::DicomDirElement ddElt;
-   ddElt.Print( std::cout );
+   gdcm::DicomDirElement *ddElt = new gdcm::DicomDirElement();
+   if (ddElt == 0)
+   {
+   std::cout << "new DicomDirElement failed" << std::endl;
+   return 1;
+   }  
+   ddElt->Print( std::cout );
 
+   delete ddElt;
    return 0;
 }
index db151958f1c070bd188ea57bbd73d2fa9262e369..54c87a5b16d4c9fdee4a7df799a38805a34b80cc 100644 (file)
@@ -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
 #include <iomanip>
 
 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);
 }
index af00b7c57af0f8804cbb3daa4322bd20a6a596ff..60b31813c7b245bdb59b4a442f4f49ceb6417016 100644 (file)
@@ -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 '"<<img.writeMode<<"' is undefined\n";
 
          delete file;
-         delete header;
+         delete fileToBuild;
          delete[] imageData;
          return 1;
    }
@@ -193,7 +193,7 @@ int WriteSimple(Image &img)
                 << "File in unwrittable\n";
 
       delete file;
-      delete header;
+      delete fileToBuild;
       delete[] imageData;
       return 1;
    }
@@ -206,7 +206,7 @@ int WriteSimple(Image &img)
      std::cerr << "Failed" << std::endl
                << "Test::TestReadWriteReadCompare: Could not reread image "
                << "written:" << fileName << std::endl;
-     delete header;
+     delete fileToBuild;
      delete file;
      delete reread;
      return 1;
@@ -218,19 +218,19 @@ int WriteSimple(Image &img)
    uint8_t* imageDataWritten = reread->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;