]> Creatis software - gdcm.git/blobdiff - Testing/TestFileAccessors.cxx
Fix mistypings
[gdcm.git] / Testing / TestFileAccessors.cxx
index 5a55f1069e2ae9c58105ffa2254ee42f746074df..a685a593f6d89729f9f062b493f7e17e02f8715c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestFileAccessors.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/03 09:51:53 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/09/15 15:49:21 $
+  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
 #include "gdcmFileHelper.h"
 #include "gdcmUtil.h"
 #include "gdcmCommon.h"
-#include "gdcmBinEntry.h"  
 #include "gdcmDocEntry.h" 
 #include "gdcmDocEntrySet.h"           
 #include "gdcmDocument.h"          
 #include "gdcmElementSet.h"        
 #include "gdcmSeqEntry.h" 
 #include "gdcmSQItem.h" 
-#include "gdcmValEntry.h" 
 
 #include <iostream>
 
 //Generated file:
 #include "gdcmDataImages.h"
 
-int TestFileAccessors(int, char *[])
+#define TestMethodMacro(mode,obj,name)                \
+   try                                                \
+   {                                                  \
+      std::cout <<"   "<< #name << "() : "            \
+                << std::endl;                         \
+      std::cout << "                     "            \
+                << mode << obj->name() << std::endl;  \
+   }                                                  \
+   catch(...)                                         \
+   {                                                  \
+      std::cout << "   --> Can't access to the '"     \
+                << #name << "' method !" << std::endl;\
+      f->Delete();                                    \
+      return 1;                                       \
+   }
+
+int TestFileAccessors(int argc, char *argv[])
 {
    int i = 0;
 
    float iop[6];
+   float ipp[3];
 
+  // GDCM_NAME_SPACE::Debug::DebugOn();
+   
    while( gdcmDataImages[i] != 0 )
    {
-      std::string filename = GDCM_DATA_ROOT;
-      filename += "/";  //doh!
-      filename += gdcmDataImages[i];
+   
+     // Keep the comment to be able to track a bug on a given image
+     // for all the OS.
+     
+     // if (gdcmDataImages[i] == "00191113.dcm" )
+     //    GDCM_NAME_SPACE::Debug::DebugOn();
+     // else
+     //    GDCM_NAME_SPACE::Debug::DebugOff();
+
+      std::string filename;      
+      if (argc ==2)
+      {
+         filename = argv[1];
+      }
+      else
+      {
+         filename = GDCM_DATA_ROOT;
+         filename += "/";  //doh!      
+         filename += gdcmDataImages[i];
+      }
+      
+      std::cout << " ----------------------------------------------"
+                << "Begin with " << filename << std::endl;
 
-      gdcm::File *e1= new gdcm::File( filename );
+      GDCM_NAME_SPACE::File *f= GDCM_NAME_SPACE::File::New( );
+      f->SetFileName( filename );
+      f->Load( );
 
 // We don't check the returned values
 // We just want to be sure no accessor seg faults on any image  ...
 // And this will improve test coverage ;-)
 
-      std::cout << "GetSwapCode()"      << e1->GetSwapCode()      << std::endl;
-      std::cout << "GetImageNumber()"   << e1->GetImageNumber()   << std::endl;
-      std::cout << "GetModality()"      << e1->GetModality()      << std::endl;
-      std::cout << "GetXSize()"         << e1->GetXSize()         << std::endl;
-      std::cout << "GetYSize()"         << e1->GetYSize()         << std::endl;
-      std::cout << "GetZSize()"         << e1->GetZSize()         << std::endl;
-      std::cout << "GetXSpacing()"      << e1->GetXSpacing()      << std::endl;
-      std::cout << "GetYSpacing()"      << e1->GetYSpacing()      << std::endl;
-      std::cout << "GetZSpacing()"      << e1->GetZSpacing()      << std::endl;
-      std::cout << "GetXOrigin()"       << e1->GetXOrigin()       << std::endl;
-      std::cout << "GetYOrigin()"       << e1->GetYOrigin()       << std::endl;
-      std::cout << "GetZOrigin()"       << e1->GetZOrigin()       << std::endl;
-      std::cout << "GetBitsStored()"    << e1->GetBitsStored()    << std::endl;
-      std::cout << "GetBitsAllocated()" << e1->GetBitsAllocated() << std::endl;
-      std::cout << "GetHighBitPosition()" << e1->GetHighBitPosition()  << std::endl;
-      std::cout << "GetSamplesPerPixel()" << e1->GetSamplesPerPixel()  << std::endl;
-      std::cout << "GetPlanarConfiguration()" << e1->GetPlanarConfiguration()    << std::endl;
-      std::cout << "GetPixelSize()"        << e1->GetPixelSize()        << std::endl;
-      std::cout << "GetPixelType()"        << e1->GetPixelType()        << std::endl;
-      std::cout << "GetLUTNbits()"         << e1->GetLUTNbits()         << std::endl;
-      std::cout << "GetRescaleIntercept()" << e1->GetRescaleIntercept() << std::endl;
-      std::cout << "GetRescaleSlope()"     << e1->GetRescaleSlope()     << std::endl;
-      std::cout << "GetGrPixel()"  << std::hex << e1->GetGrPixel()  << std::endl;
-      std::cout << "GetNumPixel()" << std::hex << e1->GetNumPixel() << std::endl;
-      std::cout << "GetPixelOffset()" << e1->GetPixelOffset() << std::endl;
-
-      std::cout << "GetPixelAreaLength()"     << e1->GetPixelAreaLength()<< std::endl;
-      std::cout << "GetNumberOfScalarComponents()"    << e1->GetNumberOfScalarComponents()<< std::endl;
-      std::cout << "GetNumberOfScalarComponentsRaw()" << e1->GetNumberOfScalarComponentsRaw()<< std::endl;
-      std::cout << "IsSignedPixelData()"      << e1->IsSignedPixelData()<< std::endl;
-      std::cout << "IsMonochrome()"           << e1->IsMonochrome()     << std::endl;
-      std::cout << "IsPaletteColor()"         << e1->IsPaletteColor()   << std::endl;
-      std::cout << "IsYBRFull()"              << e1->IsYBRFull()        << std::endl;
-      std::cout << "HasLut()   "              << e1->HasLUT()           << std::endl;
-      std::cout << "GetTransferSyntax()"      << e1->GetTransferSyntax()      << std::endl;
-      std::cout << "GetTransferSyntaxName()"  << e1->GetTransferSyntaxName()  << std::endl;
-      std::cout << "GetFileType()"            << e1->GetFileType()            << std::endl;
-      std::cout << "GetFileName()"            << e1->GetFileName()            << std::endl;
-
-      e1->GetImageOrientationPatient( iop );
+      TestMethodMacro(std::dec,f,GetSwapCode)
+      TestMethodMacro(std::dec,f,GetImageNumber)
+      TestMethodMacro(std::dec,f,GetModality)
+      TestMethodMacro(std::dec,f,GetXSize)
+      TestMethodMacro(std::dec,f,GetYSize)
+      TestMethodMacro(std::dec,f,GetZSize)
+      TestMethodMacro(std::dec,f,GetXSpacing)
+      TestMethodMacro(std::dec,f,GetYSpacing)
+      TestMethodMacro(std::dec,f,GetZSpacing)
+      TestMethodMacro(std::dec,f,GetXOrigin)
+      TestMethodMacro(std::dec,f,GetYOrigin)
+      TestMethodMacro(std::dec,f,GetZOrigin)
+      TestMethodMacro(std::dec,f,GetBitsStored)
+      TestMethodMacro(std::dec,f,GetBitsAllocated)
+      TestMethodMacro(std::dec,f,GetHighBitPosition)
+      TestMethodMacro(std::dec,f,GetSamplesPerPixel)
+      TestMethodMacro(std::dec,f,GetPlanarConfiguration)
+      TestMethodMacro(std::dec,f,GetPixelSize)
+      TestMethodMacro(std::dec,f,GetPixelType)
+      TestMethodMacro(std::dec,f,GetLUTNbits)
+      TestMethodMacro(std::dec,f,GetRescaleIntercept)
+      TestMethodMacro(std::dec,f,GetRescaleSlope)
+      TestMethodMacro(std::hex,f,GetGrPixel)
+      TestMethodMacro(std::hex,f,GetNumPixel)
+      TestMethodMacro(std::dec,f,GetPixelOffset)
+
+      TestMethodMacro(std::dec,f,GetPixelAreaLength)
+      TestMethodMacro(std::dec,f,GetNumberOfScalarComponents)
+      TestMethodMacro(std::dec,f,GetNumberOfScalarComponentsRaw)
+      TestMethodMacro(std::dec,f,IsSignedPixelData)
+      TestMethodMacro(std::dec,f,IsMonochrome)
+      TestMethodMacro(std::dec,f,IsPaletteColor)
+      TestMethodMacro(std::dec,f,IsYBRFull)
+      TestMethodMacro(std::dec,f,HasLUT)
+      TestMethodMacro(std::dec,f,GetTransferSyntax)
+      TestMethodMacro(std::dec,f,GetTransferSyntaxName)
+      TestMethodMacro(std::dec,f,GetFileType)
+      TestMethodMacro(std::dec,f,GetFileName)
+
+      f->GetImageOrientationPatient( iop );
+      std::cout << "   Orientation:" << std::endl;
       for (int j=0; j<6; j++)
-         std::cout << "iop[" << j << "] = " << iop[j] << std::endl;
+         std::cout << "      iop[" << j << "] = " << iop[j] << std::endl;
+      f->GetImagePositionPatient( ipp );
+      std::cout << "   Position:" << std::endl;
+      for (int j2=0; j2<3; j2++)
+         std::cout << "      ipp[" << j2 << "] = " << ipp[j2] << std::endl; 
 
-      if( e1->IsReadable() )
+      if( f->IsReadable() )
       {
-         std::cout <<filename   << " is Readable" 
-                   << std::endl << std::endl;
+         std::cout << "   " << filename << " is Readable" << std::endl;
 
-         gdcm::FileHelper *fh1= new gdcm::FileHelper( e1 );   
+         GDCM_NAME_SPACE::FileHelper *fh= GDCM_NAME_SPACE::FileHelper::New( f );   
 
-         // TODO : Newbe user would appreciate any comment !
+         TestMethodMacro(std::dec,fh,GetImageDataSize)
+         TestMethodMacro(std::dec,fh,GetImageDataRawSize)
+         TestMethodMacro(std::dec,fh,GetRGBDataSize)
+         TestMethodMacro(std::dec,fh,GetRawDataSize)
+         TestMethodMacro(std::dec,fh,GetUserDataSize)
+         TestMethodMacro(std::dec,fh,GetWriteType)
  
-         std::cout << "GetImageDataSize()"    << fh1->GetImageDataSize()    << std::endl;
-         std::cout << "GetImageDataRawSize()" << fh1->GetImageDataRawSize() << std::endl;
-         // User Data
-         std::cout << "GetRGBDataSize()"      << fh1->GetRGBDataSize()      << std::endl;
-         std::cout << "GetRawDataSize()"      << fh1->GetRawDataSize()      << std::endl;
-         std::cout << "GetUserDataSize()"     << fh1->GetUserDataSize()     << std::endl;
-
-         std::cout << "GetWriteType()"        << fh1->GetWriteType()        << std::endl;
-         delete fh1;
+         fh->Delete();
       }
       else
       {
          std::cout << filename << " is NOT Readable" 
                    << std::endl << std::endl;
-         delete e1;
+         f->Delete();
          return 1;
       }
+      f->Delete();
+
+      if (argc ==2)
+         break; // user asked to check a single file.
 
-      delete e1;
       i++;
    }
    return 0;