]> Creatis software - gdcm.git/blob - Testing/TestAllVM.cxx
Fix mistypings
[gdcm.git] / Testing / TestAllVM.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestAllVM.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/06/21 14:59:06 $
7   Version:   $Revision: 1.15 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmFile.h"
20 #include "gdcmDataEntry.h"
21
22 //Generated file:
23 #include "gdcmDataImages.h"
24
25 int DoTheVMTest(std::string const &filename)
26 {
27    GDCM_NAME_SPACE::File *file = GDCM_NAME_SPACE::File::New();
28    // - Do not test unknow VM in shadow groups (if element 0x0000 is present)
29    // - Skip Sequences (if they are 'True Length'); loading will be quicker
30    //                  (anyway, Sequences are skipped at processing time ...)
31    file->SetLoadMode( GDCM_NAME_SPACE::LD_NOSHADOW | GDCM_NAME_SPACE::LD_NOSEQ );
32
33    file->SetFileName( filename );
34    if( !file->Load() ) //would be really bad...
35       return 1;
36
37    GDCM_NAME_SPACE::DocEntry *d = file->GetFirstEntry();
38    std::cerr << "Testing file : " << filename << std::endl;
39    GDCM_NAME_SPACE::DataEntry *de;
40    while(d)
41    {
42       if ( (de = dynamic_cast<GDCM_NAME_SPACE::DataEntry *>(d)) )
43       {
44          if ( !(de->GetGroup() % 2) ) // Don't check shadow elements. Righ now,
45                                       // Private Dictionnary are not dealt with
46          {    
47             // We know OB and OW VM is always 1, whatever the actual
48             //  found value is.
49      
50             if (de->GetVR() != "OB" && de->GetVR() != "OW" )
51                if( !de->IsValueCountValid() )
52                {
53                   std::cerr << "Element: " << de->GetKey() <<
54                     " (" << de->GetName() << ") " <<
55                     "Contains a wrong VM: " << de->GetValueCount() 
56                     << " should be: " << de->GetVM() << std::endl;;
57                }
58          }
59       }
60       else
61       {
62           // We skip pb of SQ recursive exploration
63       }
64       d = file->GetNextEntry();
65    }
66    file->Delete();
67
68    return 0;
69 }
70
71 int TestAllVM(int argc, char *argv[])
72 {
73    int i = 0;
74    if( argc >= 2 )
75      {
76      const char *filename = argv[1];
77      if( DoTheVMTest( filename ) )
78        return 1;
79      return 0;
80      }
81    // else
82
83    while( gdcmDataImages[i] != 0 )
84    {
85       std::string filename = GDCM_DATA_ROOT;
86       filename += "/";
87       filename += gdcmDataImages[i];
88       
89       if (!strcmp(gdcmDataImages[i],"00191113.dcm")) // Track bug on Darwin
90           GDCM_NAME_SPACE::Debug::DebugOn();
91       else
92          GDCM_NAME_SPACE::Debug::DebugOff();
93
94       if( DoTheVMTest( filename ) )
95         return 1;
96       i++;
97       std::cerr << std::endl; // skip a line after each file
98    }
99
100    return 0;
101 }
102