]> Creatis software - gdcm.git/blob - Testing/TestAllVM.cxx
Pass the VR to method InsertEntryString
[gdcm.git] / Testing / TestAllVM.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestAllVM.cxx,v $
5   Language:  C++
6   Date:      $Date: 2006/03/25 17:02:11 $
7   Version:   $Revision: 1.12 $
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::File *file = gdcm::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::LD_NOSHADOW | gdcm::LD_NOSEQ );
32
33    file->SetFileName( filename );
34    if( !file->Load() ) //would be really bad...
35       return 1;
36
37    gdcm::DocEntry *d = file->GetFirstEntry();
38    std::cerr << "Testing file : " << filename << std::endl;
39    while(d)
40    {
41       if ( gdcm::DataEntry *de = dynamic_cast<gdcm::DataEntry *>(d) )
42       {
43          if ( !(de->GetGroup() % 2) ) // Don't check shadow elements. Righ now,
44                                       // Private Dictionnary are not dealt with
45          {    
46             // We know OB and OW VM is always 1, whatever the actual
47             //  found value is.
48      
49             if (de->GetVR() != "OB" && de->GetVR() != "OW" )
50                if( !de->IsValueCountValid() )
51                {
52                   std::cerr << "Element: " << de->GetKey() <<
53                     " (" << de->GetName() << ") " <<
54                     "Contains a wrong VM: " << de->GetValueCount() 
55                     << " should be: " << de->GetVM() << std::endl;;
56                }
57          }
58       }
59       else
60       {
61           // We skip pb of SQ recursive exploration
62       }
63       d = file->GetNextEntry();
64    }
65    file->Delete();
66
67    return 0;
68 }
69
70 int TestAllVM(int argc, char *argv[])
71 {
72    int i = 0;
73    if( argc >= 2 )
74      {
75      const char *filename = argv[1];
76      if( DoTheVMTest( filename ) )
77        return 1;
78      return 0;
79      }
80    // else
81
82    while( gdcmDataImages[i] != 0 )
83    {
84       std::string filename = GDCM_DATA_ROOT;
85       filename += "/";
86       filename += gdcmDataImages[i];
87       
88       if (!strcmp(gdcmDataImages[i],"00191113.dcm")) // Track bug on Darwin
89           gdcm::Debug::DebugOn();
90       else
91          gdcm::Debug::DebugOff();
92
93       if( DoTheVMTest( filename ) )
94         return 1;
95       i++;
96       std::cerr << std::endl; // skip a line after each file
97    }
98
99    return 0;
100 }
101