]> Creatis software - gdcm.git/blob - Testing/TestAllVM.cxx
ENH: Rearchitecture the test to test one file at a time
[gdcm.git] / Testing / TestAllVM.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestAllVM.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/21 15:16:22 $
7   Version:   $Revision: 1.5 $
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;
28       // Do not test unknow VM ...
29       file.SetLoadMode( gdcm::LD_NOSHADOW | gdcm::LD_NOSHADOWSEQ );
30       file.SetFileName( filename );
31       if( !file.Load() ) //would be really bad...
32         return 1;
33
34       gdcm::DocEntry *d = file.GetFirstEntry();
35       std::cerr << "Testing file : " << filename << std::endl;
36       while(d)
37       {
38          if ( gdcm::DataEntry *de = dynamic_cast<gdcm::DataEntry *>(d) )
39          {
40            if( !de->IsValueCountValid() )
41              {
42              std::cerr << "Element: " << de->GetKey() <<
43                " (" << de->GetName() << ") " <<
44                "Contains a wrong VM: " << de->GetValueCount() 
45                << " should be: " << de->GetVM() << std::endl;;
46              }
47          }
48          else
49          {
50           // We skip pb of SQ recursive exploration
51          }
52
53          d = file.GetNextEntry();
54       }
55
56       return 0;
57 }
58
59 int TestAllVM(int argc, char *argv[])
60 {
61    int i = 0;
62    if( argc >= 2 )
63      {
64      const char *filename = argv[1];
65      if( DoTheVMTest( filename ) )
66        return 1;
67      return 0;
68      }
69    // else
70
71    while( gdcmDataImages[i] != 0 )
72    {
73       std::string filename = GDCM_DATA_ROOT;
74       filename += "/";
75       filename += gdcmDataImages[i];
76
77       if( DoTheVMTest( filename ) )
78         return 1;
79       i++;
80       std::cerr << std::endl; // skip a line after each file
81    }
82
83    return 0;
84 }
85