]> Creatis software - gdcm.git/commitdiff
ENH: Adding a test I know that segfault
authormalaterre <malaterre>
Thu, 9 Sep 2004 04:10:58 +0000 (04:10 +0000)
committermalaterre <malaterre>
Thu, 9 Sep 2004 04:10:58 +0000 (04:10 +0000)
Example/TestCopyDicom.cxx
Testing/CMakeLists.txt
Testing/TestCopyDicom.cxx

index e94b5a991737f8da38077f7c07a98efdf68c2b35..f7139f88615de71ca356d631ef773183736a5f2a 100644 (file)
@@ -75,22 +75,21 @@ int main(int argc, char* argv[])
       if (tag->second->GetVR() == "SQ") //to skip pb of SQ recursive exploration
          continue;
 
-      //According to JPR I should also skip those:
-      if (tag->second->GetVR() == "unkn") //to skip pb of SQ recursive exploration
-         continue;
-
       std::string value = ((gdcmValEntry*)(tag->second))->GetValue();
-      if( value.find( "gdcm::NotLoaded" ) != 0 )
-         continue;
+      //According to JPR I should also skip those:
+//      if (tag->second->GetVR() == "unkn") //to skip pb of SQ recursive exploration
+//         continue;
 
-// the following produce a seg fault at write time:
-//      if( value.find( "gdcm::Loaded" ) != 0 )
+//      if( value.find( "gdcm::NotLoaded" ) == 0 )
 //         continue;
 
+      if( value.find( "gdcm::Loaded" ) == 0 )
+         continue;
+         
       //std::cerr << "Reading: " << tag->second->GetVR() << std::endl;
       //tag->second->Print(); std::cout << std::endl;
     
-      //std::cerr << "Reading: " << value  << std::endl;
+      std::cerr << "Reading: " << value  << std::endl;
 
       // Well ... Should have dynamic cast here 
       copy->GetHeader()->ReplaceOrCreateByNumber( 
@@ -104,7 +103,7 @@ int main(int argc, char* argv[])
    size_t dataSize = original->GetImageDataSize();
    void *imageData = original->GetImageData();
 
-   copy->GetImageData();
+   //copy->GetImageData();
    copy->SetImageData(imageData, dataSize);
 
    std::cout << "--- Copy ----------------------" << std::endl;
index 15eb490655fb60bdaa540b2e888941d98203e36b..4385070b6675d8fb0548c9cec2f69a5647298046 100644 (file)
@@ -24,6 +24,7 @@ IF (GDCM_DATA_ROOT)
     TestDicomDir.cxx                 # require DICOMDIR
     BuildUpDicomDir.cxx              # writes a file named "NewDICOMDIR"
     makeDicomDir.cxx                 # writes a file named "NewDICOMDIR"
+    TestCopyDicom.cxx
   )
   # add test that require VTK:
   IF(GDCM_VTK)
index 0225453919dc50341f12ec1d33418a71f5663b89..a5b6dfa3ce8aed993a34c1d2b6bd04a30a2179f7 100644 (file)
@@ -1,5 +1,10 @@
 #include "gdcmHeader.h"
 #include "gdcmFile.h"
+#include "gdcmDocument.h"
+#include "gdcmValEntry.h"
+
+//Generated file:
+#include "gdcmDataImages.h"
 
 // return true if the file exists
 bool FileExists(const char* filename)
@@ -31,48 +36,75 @@ bool RemoveFile(const char* source)
 // Here we load a gdcmFile and then try to create from scratch a copy of it,
 // copying field by field the dicom image
 
-int TestCopyDicom(int argc, char* argv[])
+int TestCopyDicom(int , char* [])
 {
-   if (argc < 3)
+   int i =0;
+   int retVal = 0;  //by default this is an error
+   while( gdcmDataImages[i] != 0 )
    {
-      std::cerr << "Usage :" << std::endl << 
-      argv[0] << " input_dicom output_dicom" << std::endl;
-      return 1;
-   }
+      std::string filename = GDCM_DATA_ROOT;
+      filename += "/";  //doh!
+      filename += gdcmDataImages[i];
+      std::cerr << "Filename: " << filename << std::endl;
 
-   if( FileExists( argv[2] ) )
-   {
-      std::cerr << "Don't try to cheat, I am removing the file anyway" << std::endl;
-      if( !RemoveFile( argv[2] ) )
+      std::string output = "../Testing/Temporary/output.dcm";
+
+      if( FileExists( output.c_str() ) )
       {
-         std::cerr << "Ouch, the file exist, but I cannot remove it" << std::endl;
-         return 1;
+         std::cerr << "Don't try to cheat, I am removing the file anyway" << std::endl;
+         if( !RemoveFile( output.c_str() ) )
+         {
+            std::cerr << "Ouch, the file exist, but I cannot remove it" << std::endl;
+            return 1;
+         }
       }
-   }
-   gdcmFile *original = new gdcmFile( argv[1] );
-   gdcmFile *copy = new gdcmFile( argv[2] );
 
-   //First of all copy the header field by field
-   TagNameHT & nameHt = original->GetHeader()->GetPubDict()->GetEntriesByName();
-   for (TagNameHT::iterator tag = nameHt.begin(); tag != nameHt.end(); ++tag)
-   {
-      std::cerr << "Reading: " << tag->second->GetVR() << std::endl;
+      gdcmFile *original = new gdcmFile( filename );
+      gdcmFile *copy = new gdcmFile( output );
 
-      copy->GetHeader()->ReplaceOrCreateByNumber( tag->second->GetVR(), 
-            tag->second->GetGroup(), tag->second->GetElement() );
-   }
+      //First of all copy the header field by field
+      TagNameHT & nameHt = original->GetHeader()->GetPubDict()->GetEntriesByName();
+      for (TagNameHT::iterator tag = nameHt.begin(); tag != nameHt.end(); ++tag)
+      {
+         if (tag->second->GetVR() == "SQ") //to skip pb of SQ recursive exploration
+            continue;
+
+         //According to JPR I should also skip those:
+//         if (tag->second->GetVR() == "unkn") //to skip pb of SQ recursive exploration
+//            continue;
 
-   size_t dataSize = original->GetImageDataSize();
-   void *imageData = original->GetImageData();
+         //no clue what to do with this one
+         //std::cerr << "Reading: " << tag->second->GetVR() << std::endl;
+         std::string value = ((gdcmValEntry*)(tag->second))->GetValue();
+//         if( value.find( "gdcm::NotLoaded" ) == 0 )
+//            continue;
 
-   copy->SetImageData(imageData, dataSize);
-   //original->GetHeader()->SetImageDataSize(dataSize);
+         //no clue what to do with this one
+         if( value.find( "gdcm::Loaded" ) == 0 )
+            continue;
+
+         copy->GetHeader()->ReplaceOrCreateByNumber( 
+               value, 
+               tag->second->GetGroup(), 
+               tag->second->GetElement() );
+      }
 
-   //copy->GetHeader()->PrintEntry();
+      size_t dataSize = original->GetImageDataSize();
+      void *imageData = original->GetImageData();
 
-   copy->WriteDcmExplVR( argv[2] );
+      copy->SetImageData(imageData, dataSize);
+      //original->GetHeader()->SetImageDataSize(dataSize);
+
+      //copy->GetHeader()->PrintEntry();
+
+      //copy->WriteDcmExplVR( output );
+      
+      //Is the file written still gdcm parsable ?
+      gdcmFile check( output );
+      retVal += !check.GetHeader()->IsReadable();
+   }
 
-   return 0;
+   return retVal;
 }