]> Creatis software - gdcm.git/blobdiff - Testing/TestAllVM.cxx
Fix mistypings
[gdcm.git] / Testing / TestAllVM.cxx
index 74bab90117f3f5e8d965021bee84e773454c69d2..0abb80701e060e599e57c2475cba0f17a11c832f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestAllVM.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/21 14:42:12 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2007/06/21 14:59:06 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
                                                                                 
 =========================================================================*/
 
-#include "gdcmDictEntry.h"
-#include "gdcmDict.h"
-#include "gdcmDictSet.h"
 #include "gdcmFile.h"
-#include "gdcmFileHelper.h"
-#include "gdcmUtil.h"
-#include "gdcmCommon.h"
-#include "gdcmDocEntry.h" 
-#include "gdcmDocEntrySet.h"           
-#include "gdcmDocument.h"          
-#include "gdcmElementSet.h"        
-#include "gdcmSeqEntry.h" 
-#include "gdcmSQItem.h" 
+#include "gdcmDataEntry.h"
 
 //Generated file:
 #include "gdcmDataImages.h"
 
-int TestAllVM(int, char *[])
+int DoTheVMTest(std::string const &filename)
 {
-   int i = 0;
+   GDCM_NAME_SPACE::File *file = GDCM_NAME_SPACE::File::New();
+   // - Do not test unknow VM in shadow groups (if element 0x0000 is present)
+   // - Skip Sequences (if they are 'True Length'); loading will be quicker
+   //                  (anyway, Sequences are skipped at processing time ...)
+   file->SetLoadMode( GDCM_NAME_SPACE::LD_NOSHADOW | GDCM_NAME_SPACE::LD_NOSEQ );
 
-   while( gdcmDataImages[i] != 0 )
-   {
-      std::string filename = gdcmDataImages[i];
+   file->SetFileName( filename );
+   if( !file->Load() ) //would be really bad...
+      return 1;
 
-      gdcm::File file;
-      //file.SetLoadMode( gdcm::LD_NOSEQ );
-      file.SetFileName( filename );
-      file.Load();
-
-      gdcm::DocEntry *d = file.GetFirstEntry();
-      while(d)
+   GDCM_NAME_SPACE::DocEntry *d = file->GetFirstEntry();
+   std::cerr << "Testing file : " << filename << std::endl;
+   GDCM_NAME_SPACE::DataEntry *de;
+   while(d)
+   {
+      if ( (de = dynamic_cast<GDCM_NAME_SPACE::DataEntry *>(d)) )
       {
-         if ( gdcm::DataEntry *de = dynamic_cast<gdcm::DataEntry *>(d) )
-         {
-           if(! de->IsValueCountValid() )
-             std::cerr << "Filename:" << filename << std::endl;
+         if ( !(de->GetGroup() % 2) ) // Don't check shadow elements. Righ now,
+                                      // Private Dictionnary are not dealt with
+         {    
+            // We know OB and OW VM is always 1, whatever the actual
+            //  found value is.
+     
+            if (de->GetVR() != "OB" && de->GetVR() != "OW" )
+               if( !de->IsValueCountValid() )
+               {
+                  std::cerr << "Element: " << de->GetKey() <<
+                    " (" << de->GetName() << ") " <<
+                    "Contains a wrong VM: " << de->GetValueCount() 
+                    << " should be: " << de->GetVM() << std::endl;;
+               }
          }
-         else
-         {
+      }
+      else
+      {
           // We skip pb of SQ recursive exploration
-         }
-
-         d = file->GetNextEntry();
       }
+      d = file->GetNextEntry();
+   }
+   file->Delete();
 
+   return 0;
+}
+
+int TestAllVM(int argc, char *argv[])
+{
+   int i = 0;
+   if( argc >= 2 )
+     {
+     const char *filename = argv[1];
+     if( DoTheVMTest( filename ) )
+       return 1;
+     return 0;
+     }
+   // else
+
+   while( gdcmDataImages[i] != 0 )
+   {
+      std::string filename = GDCM_DATA_ROOT;
+      filename += "/";
+      filename += gdcmDataImages[i];
+      
+      if (!strcmp(gdcmDataImages[i],"00191113.dcm")) // Track bug on Darwin
+          GDCM_NAME_SPACE::Debug::DebugOn();
+      else
+         GDCM_NAME_SPACE::Debug::DebugOff();
+
+      if( DoTheVMTest( filename ) )
+        return 1;
       i++;
+      std::cerr << std::endl; // skip a line after each file
    }
+
    return 0;
 }