]> Creatis software - gdcm.git/blobdiff - Testing/TestAllReadCompareDicom.cxx
First stage of name normalisation : gdcm::File replace by gdcm::FileHelper
[gdcm.git] / Testing / TestAllReadCompareDicom.cxx
index 9e10924e584cae4ebed5f213ee06f80d438b181f..aba924629643210b6c633898e0368204df8b3c90 100644 (file)
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: TestAllReadCompareDicom.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/20 16:16:59 $
+  Version:   $Revision: 1.24 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
 #include "gdcmHeader.h"
-#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
+
+#include <iostream>
+#include <fstream>
 
 //Generated file:
 #include "gdcmDataImages.h"
 
-int InternalTest(std::string const & filename, std::string const & referenceFileName )
+int InternalTest(std::string const & filename, 
+                 std::string const & referenceFileName )
 {
       std::cout << "   Testing: " << filename << std::endl;
 
-      gdcmFile* tested = new gdcmFile( filename );
+      ////// Step 1:
+      std::cout << "      1...";
+      gdcm::FileHelper* tested = new gdcm::FileHelper( filename );
       if( !tested->GetHeader()->IsReadable() )
       {
-        std::cout << "      Image not gdcm compatible:"
+        std::cout << " Failed" << std::endl
+                   << "      Image not gdcm compatible:"
                   << filename << std::endl;
         delete tested;
         return 1;
       }
 
       ////// Step 2:
-
       ////// Check for existence of reference baseline dicom file:
+      std::cout << "2...";
 
-      FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
+      //FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
+      std::ifstream testFILE( referenceFileName.c_str() );
       if (! testFILE )
       {
-      ////// Step 3a:
+         uint8_t* testedImageData = tested->GetImageData(); // Kludge
+         (void)testedImageData;
 
-         int testedDataSize    = tested->GetImageDataSize();
-         (void)testedDataSize;
-         void* testedImageData = tested->GetImageData(); // Kludge
+         tested->SetWriteModeToRGB();
          tested->WriteDcmExplVR( referenceFileName );
-         std::cerr << "      Creating reference baseline file :" << std::endl
-                   << "      " << referenceFileName 
-                   << std::endl;
-         delete tested;
-         delete (char*)testedImageData;
-         return 0;
       }
       else
       {
-         fclose( testFILE );
+         //fclose( testFILE );
       }
+      testFILE.close();
 
+      ////// Step 3a:
       ////// When reference file is not gdcm readable test is failed:
-  
-      gdcmFile* reference = new gdcmFile( referenceFileName.c_str() );
+      std::cout << "3a...";
+
+      gdcm::FileHelper* reference = new gdcm::FileHelper( referenceFileName );
       if( !reference->GetHeader()->IsReadable() )
       {
-         std::cout << "      Reference image " << std::endl
-                   << "      " << referenceFileName <<std::endl
-                   << "      is not gdcm compatible." << std::endl;
+         std::cout << " Failed" << std::endl
+                   << "              reference image " 
+                   << referenceFileName 
+                   << " is not gdcm compatible." << std::endl;
          delete tested;
          delete reference;
          return 1;
       }
 
-      ////// Step 3b:
+      std::string PixelType = reference->GetHeader()->GetPixelType();
 
+      ////// Step 3b:
+      std::cout << "3b...";
       int testedDataSize    = tested->GetImageDataSize();
-      void* testedImageData = tested->GetImageData();
+      uint8_t* testedImageData = tested->GetImageData();
     
       int    referenceDataSize = reference->GetImageDataSize();
-      void* referenceImageData = reference->GetImageData();
+      uint8_t* referenceImageData = reference->GetImageData();
 
+      // Test the image size
+      if (tested->GetHeader()->GetXSize() != reference->GetHeader()->GetXSize() ||
+          tested->GetHeader()->GetYSize() != reference->GetHeader()->GetYSize() ||
+          tested->GetHeader()->GetZSize() != reference->GetHeader()->GetZSize())
+      {
+         std::cout << "Failed" << std::endl
+            << "        Size differs: "
+            << "X: " << tested->GetHeader()->GetXSize() << " # " 
+                     << reference->GetHeader()->GetXSize() << " | "
+            << "Y: " << tested->GetHeader()->GetYSize() << " # " 
+                     << reference->GetHeader()->GetYSize() << " | "
+            << "Z: " << tested->GetHeader()->GetZSize() << " # " 
+                     << reference->GetHeader()->GetZSize() << std::endl;
+         delete reference;
+         delete tested;
+         return 1;
+      }
+
+      // Test the data size
       if (testedDataSize != referenceDataSize)
       {
-         std::cout << "        Pixel areas lengths differ: "
+         std::cout << " Failed" << std::endl
+                   << "        pixel ("
+                   << PixelType
+                   <<") areas lengths differ: "
                    << testedDataSize << " # " << referenceDataSize
                    << std::endl;
          delete tested;
          delete reference;
-         delete (char*)testedImageData;
-         delete (char*)referenceImageData;
          return 1;
       }
 
+      // Test the data content
       if (int res = memcmp(testedImageData, referenceImageData,
                            testedDataSize) != 0 )
       {
          (void)res;
-         std::cout << "        Pixel differ (as expanded in memory)."
+         std::cout << " Failed" << std::endl
+                   << "        pixel (" 
+                   << PixelType
+                   << ") differ (as expanded in memory)."
                    << std::endl;
          delete tested;
          delete reference;
-         delete (char*)testedImageData;
-         delete (char*)referenceImageData;
          return 1;
       }
-      std::cout << "      Passed." << std::endl ;
 
       //////////////// Clean up:
       delete tested;
       delete reference;
-      delete (char*)testedImageData;
-      delete (char*)referenceImageData;
+
+      std::cout << "OK." << std::endl;
       
       return 0;
 }
@@ -148,6 +193,7 @@ int TestAllReadCompareDicom(int argc, char* argv[])
              << std::endl << std::endl;
 
    int i = 0;
+   int result = 0;
    while( gdcmDataImages[i] != 0 )
    {
       ////// Check for existence of reference baseline directory
@@ -155,8 +201,8 @@ int TestAllReadCompareDicom(int argc, char* argv[])
       std::string baseLineDir = GDCM_DATA_ROOT;
       baseLineDir += "/BaselineDicom/";
 
-      FILE* testFILE = fopen( baseLineDir.c_str(), "r" );
-      if (!testFILE )
+      std::ifstream* testDIR = new std::ifstream(baseLineDir.c_str(), std::ios::in | std::ios::binary);
+      if (!testDIR )
       {
          std::cerr << "   The reference baseline directory " << std::endl
                    << "      "
@@ -167,11 +213,10 @@ int TestAllReadCompareDicom(int argc, char* argv[])
       }
       else
       {
-         fclose( testFILE );
+         testDIR->close();
       }
 
       ////// Step 1 (see above description):
-
       std::string filename = GDCM_DATA_ROOT;
       filename += "/";
       filename += gdcmDataImages[i];
@@ -185,9 +230,9 @@ int TestAllReadCompareDicom(int argc, char* argv[])
 
       if( InternalTest( filename, referenceFileName ) != 0 )
       {
-         return 1;
+         result++;
       }
    }
 
-   return 0;
+   return result;
 }