]> Creatis software - gdcm.git/blob - Testing/TestDict.cxx
To improve test coverage
[gdcm.git] / Testing / TestDict.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestDict.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/17 14:18:48 $
7   Version:   $Revision: 1.3 $
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 "gdcmGlobal.h"
19 #include "gdcmDictSet.h"
20 #include "gdcmDict.h"
21 #include "gdcmDictEntry.h"
22
23 #include <iostream>
24 #include <iomanip>
25
26 int TestDict(int , char* [])
27 {  
28    // Print the DictSet
29    std::cout<<"#######################################################\n";
30    gdcm::DictSet *dicts=gdcm::Global::GetDicts();
31    if(!dicts)
32    {
33       std::cout<<"DictSet hasn't be found... Failed\n";
34       return(1);
35    }
36
37    std::cout<<"DictSet content :\n";
38
39    dicts->InitTraversal();
40    gdcm::Dict *d = dicts->GetNextEntry();
41    if (!d)
42    {
43       std::cout << "Dictset is empty" << std::endl;
44       return 1;
45    }
46    while (d)
47    {
48       std::cout << "------------- a Dict is found : ----------" << std::endl;
49       d->Print();
50       d = dicts->GetNextEntry();
51    }
52
53    // Print the Dict (public)
54    std::cout<<"#######################################################\n";
55    gdcm::Dict *pubDict=dicts->GetDefaultPubDict();
56    if(!pubDict)
57    {
58       std::cout<<"The public Dict hasn't be found... Failed\n";
59       return(1);
60    }
61    std::cout<<"Public Dict content :\n";
62 //   pubDict->Print();
63
64    // Print the DictEntry (0x10,0x20)
65    std::cout<<"#######################################################\n";
66    const int ENTRY_GR = 0x10;
67    const int ENTRY_EL = 0x20;
68    std::string key=gdcm::DictEntry::TranslateToKey(ENTRY_GR,ENTRY_EL);
69    gdcm::DictEntry *entry=pubDict->GetDictEntry(ENTRY_GR,ENTRY_EL);
70    if(!entry)
71    {
72       std::cout<<"The DictEntry hasn't be found... Failed\n";
73       return(1);
74    }
75    std::cout<<"Entry "<<key<<" content :\n";
76    entry->Print();
77
78    // Print all the DictEntry
79    std::cout<<"#######################################################\n";
80    pubDict->InitTraversal();
81    entry=pubDict->GetNextEntry();
82    while(entry)
83    {
84       entry->Print();
85       entry=pubDict->GetNextEntry();
86    }
87
88    return(0);
89 }