]> Creatis software - gdcm.git/blobdiff - Testing/TestAllReadCompareDicom.cxx
Some checking added
[gdcm.git] / Testing / TestAllReadCompareDicom.cxx
index a53ab5020696ce451b4716684ffa26fd4bae9353..56f5646b85814d3ae0bbb79aa6b1cabc31154077 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestAllReadCompareDicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/03/31 07:45:57 $
-  Version:   $Revision: 1.32 $
+  Date:      $Date: 2005/04/19 10:05:36 $
+  Version:   $Revision: 1.39 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -20,7 +20,6 @@
 #include "gdcmFileHelper.h"
 
 #include <iostream>
-#include <fstream>
 
 //Generated file:
 #include "gdcmDataImages.h"
@@ -75,9 +74,24 @@ private:
    bool WriteFileHeader(std::ofstream *fp);
    bool WriteFileData(std::ofstream *fp);
 
-   uint8_t  ReadInt8 (std::ifstream *fp) throw( std::ios::failure );
-   uint16_t ReadInt16(std::ifstream *fp) throw( std::ios::failure );
-   uint32_t ReadInt32(std::ifstream *fp) throw( std::ios::failure );
+   uint8_t  ReadInt8 (std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
+ throw( std::ios::failure );
+#else
+ ;
+#endif
+   uint16_t ReadInt16(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
+  throw( std::ios::failure );
+#else
+ ;
+#endif
+   uint32_t ReadInt32(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
+  throw( std::ios::failure );
+#else
+ ;
+#endif
    void WriteInt8 (std::ofstream *fp,uint8_t  value);
    void WriteInt16(std::ofstream *fp,uint16_t value);
    void WriteInt32(std::ofstream *fp,uint32_t value);
@@ -88,8 +102,8 @@ private:
    int sizeX;
    int sizeY;
    int sizeZ;
-   int scalarSize;
-   int components;
+   uint16_t scalarSize;
+   uint16_t components;
    uint8_t *data;
    int swapCode;
 
@@ -233,7 +247,7 @@ bool TestFile::ReadFileHeader(std::ifstream *fp)
    sizeY = ReadInt32(fp); // Size Y
    sizeZ = ReadInt32(fp); // Size Z
    scalarSize = ReadInt16(fp)/8; // bits per scalar
-   components = ReadInt16(fp); // Number of components
+   components = ReadInt16(fp);   // Number of components
 
    return(true);
 }
@@ -279,7 +293,7 @@ bool TestFile::WriteFileHeader(std::ofstream *fp)
    WriteInt32(fp,sizeY); // Size Y
    WriteInt32(fp,sizeZ); // Size Z
    WriteInt16(fp,scalarSize*8); // bits per scalar
-   WriteInt16(fp,components); // number of components
+   WriteInt16(fp,components);   // number of components
 
    return(true);
 }
@@ -292,26 +306,34 @@ bool TestFile::WriteFileData(std::ofstream *fp)
 }
 
 uint8_t  TestFile::ReadInt8 (std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    throw( std::ios::failure )
+#endif
 {
    uint8_t g;
    fp->read ((char*)&g, (size_t)1);
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    if ( fp->fail() )
       throw std::ios::failure( "TestFile::ReadInt8() - file error." );
    if( fp->eof() )
       throw std::ios::failure( "TestFile::ReadInt8() - EOF." );
+#endif
    return g;
 }
 
 uint16_t TestFile::ReadInt16(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    throw( std::ios::failure )
+#endif
 {
    uint16_t g;
    fp->read ((char*)&g, (size_t)2);
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    if ( fp->fail() )
       throw std::ios::failure( "TestFile::ReadInt16() - file error." );
    if( fp->eof() )
       throw std::ios::failure( "TestFile::ReadInt16() - EOF." );
+#endif
 
 #if defined(GDCM_WORDS_BIGENDIAN)
    g = ( g << 8 |  g >> 8  );
@@ -320,14 +342,18 @@ uint16_t TestFile::ReadInt16(std::ifstream *fp)
 }
 
 uint32_t TestFile::ReadInt32(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    throw( std::ios::failure )
+#endif
 {
    uint32_t g;
    fp->read ((char*)&g, (size_t)4);
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    if ( fp->fail() )
       throw std::ios::failure( "TestFile::ReadInt32() - file error." );
    if( fp->eof() )
       throw std::ios::failure( "TestFile::ReadInt32() - EOF." );
+#endif
 
 #if defined(GDCM_WORDS_BIGENDIAN)
    g = (  (g<<24)               | ((g<<8)  & 0x00ff0000) | 
@@ -381,11 +407,12 @@ int InternalTest(std::string const &filename,
       std::cout << "2...";
 
       TestFile *reference = new TestFile();
-      reference->Load(referenceFileName);
-      if(!reference->IsReadable())
+      std::ifstream refFile(referenceFileName.c_str(),
+                            std::ios::binary|std::ios::in);
+      if(!refFile)
       {
          std::cout << " Failed" << std::endl
-                   << "      Image not BMP compatible:"
+                   << "      Image not found:"
                    << referenceFileName << std::endl;
          reference->SetXSize(tested->GetFile()->GetXSize());
          reference->SetYSize(tested->GetFile()->GetYSize());
@@ -395,6 +422,8 @@ int InternalTest(std::string const &filename,
          reference->SetData(tested->GetImageData());
          reference->Write(referenceFileName);
       }
+      else
+         refFile.close();
 
       reference->Load(referenceFileName);
       if(!reference->IsReadable())
@@ -548,7 +577,7 @@ int TestAllReadCompareDicom(int argc, char *argv[])
       ////// Check for existence of reference baseline directory
 
       std::string baseLineDir = GDCM_DATA_ROOT;
-      baseLineDir += "/BaselineDicom/";
+      baseLineDir += "/BaselineDicom";
 
       if( !gdcm::DirList::IsDirectory(baseLineDir) )
       {
@@ -565,6 +594,7 @@ int TestAllReadCompareDicom(int argc, char *argv[])
       filename += "/";
       filename += gdcmDataImages[i];
       
+      baseLineDir += '/';
       std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
       std::string::size_type slash_pos = referenceFileName.rfind( "." );
       if( slash_pos != std::string::npos )