]> Creatis software - gdcm.git/blob - Testing/TestValidate.cxx
Delete() should avoid memory leaks
[gdcm.git] / Testing / TestValidate.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestValidate.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/11/18 10:31:22 $
7   Version:   $Revision: 1.8 $
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 #include "gdcmFile.h"
19 #include "gdcmValidator.h"
20
21 #include "gdcmGlobal.h"
22 #include "gdcmDictSet.h"
23
24 //Generated file:
25 #include "gdcmDataImages.h"
26
27 int Validate(std::string const &filename);
28
29 int Validate(std::string const &filename)
30 {
31    gdcm::File *input =  gdcm::File::New( );
32    input->SetFileName(filename);
33    input->Load();
34    gdcm::Validator *v = new gdcm::Validator();
35    v->SetInput( input );
36    input->Delete();
37    return 1; // allways true (we don't want to break the test suite)
38
39
40
41 int TestValidate(int argc, char *argv[])
42 {
43    if ( argc == 2 )
44    {
45       // The test is specified a specific filename, use it instead of looping
46       // over all images
47       const std::string input = argv[1];
48       return Validate( input );
49    }
50    else if ( argc > 2 || argc == 2 )
51    {
52       std::cout << "   Usage: " << argv[0]
53                 << " (no arguments needed)." << std::endl;
54       std::cout << "or   Usage: " << argv[0]
55                 << " filename.dcm " << std::endl;
56       return 1;
57    }
58    // Try to track the "FIXME" problem for VM
59    gdcm::Global::GetDicts()->GetDefaultPubDict()->Print();   
60
61    int i =0;
62    int retVal = 0;  //by default : *no* error
63    while( gdcmDataImages[i] != 0 )
64    {
65       std::string filename = GDCM_DATA_ROOT;
66       filename += "/";  //doh!
67       filename += gdcmDataImages[i];
68       std::cout << filename << std::endl;
69       if( Validate( filename ) != 0 )
70       {
71          retVal++;
72       }
73
74       i++;
75    }
76    retVal = 0; // Never break test suite
77    return retVal;
78 }
79