]> Creatis software - gdcm.git/blob - Testing/TestFileAccessors.cxx
ENH: do not run dashbaord on that
[gdcm.git] / Testing / TestFileAccessors.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestFileAccessors.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/06/21 14:59:06 $
7   Version:   $Revision: 1.11 $
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 // TODO : check what's *actually* usefull
20
21 #include "gdcmDictEntry.h"
22 #include "gdcmDict.h"
23 #include "gdcmDictSet.h"
24 #include "gdcmFile.h"
25 #include "gdcmFileHelper.h"
26 #include "gdcmUtil.h"
27 #include "gdcmCommon.h"
28 #include "gdcmDocEntry.h" 
29 #include "gdcmDocEntrySet.h"           
30 #include "gdcmDocument.h"          
31 #include "gdcmElementSet.h"        
32 #include "gdcmSeqEntry.h" 
33 #include "gdcmSQItem.h" 
34
35 #include <iostream>
36
37 //Generated file:
38 #include "gdcmDataImages.h"
39
40 #define TestMethodMacro(mode,obj,name)                \
41    try                                                \
42    {                                                  \
43       std::cout <<"   "<< #name << "() : "            \
44                 << std::endl;                         \
45       std::cout << "                     "            \
46                 << mode << obj->name() << std::endl;  \
47    }                                                  \
48    catch(...)                                         \
49    {                                                  \
50       std::cout << "   --> Can't access to the '"     \
51                 << #name << "' method !" << std::endl;\
52       f->Delete();                                    \
53       return 1;                                       \
54    }
55
56 int TestFileAccessors(int argc, char *argv[])
57 {
58    int i = 0;
59
60    float iop[6];
61    float ipp[3];
62
63   // gdcm::Debug::DebugOn();
64    
65    while( gdcmDataImages[i] != 0 )
66    {
67    
68      // Keep the comment to be able to track a bug on a given image
69      // for all the OS.
70      
71      // if (gdcmDataImages[i] == "00191113.dcm" )
72      //    gdcm::Debug::DebugOn();
73      // else
74      //    gdcm::Debug::DebugOff();
75
76       std::string filename;      
77       if (argc ==2)
78       {
79          filename = argv[1];
80       }
81       else
82       {
83          filename = GDCM_DATA_ROOT;
84          filename += "/";  //doh!      
85          filename += gdcmDataImages[i];
86       }
87       
88       std::cout << " ----------------------------------------------"
89                 << "Begin with " << filename << std::endl;
90
91       GDCM_NAME_SPACE::File *f= GDCM_NAME_SPACE::File::New( );
92       f->SetFileName( filename );
93       f->Load( );
94
95 // We don't check the returned values
96 // We just want to be sure no accessor seg faults on any image  ...
97 // And this will improve test coverage ;-)
98
99       TestMethodMacro(std::dec,f,GetSwapCode)
100       TestMethodMacro(std::dec,f,GetImageNumber)
101       TestMethodMacro(std::dec,f,GetModality)
102       TestMethodMacro(std::dec,f,GetXSize)
103       TestMethodMacro(std::dec,f,GetYSize)
104       TestMethodMacro(std::dec,f,GetZSize)
105       TestMethodMacro(std::dec,f,GetXSpacing)
106       TestMethodMacro(std::dec,f,GetYSpacing)
107       TestMethodMacro(std::dec,f,GetZSpacing)
108       TestMethodMacro(std::dec,f,GetXOrigin)
109       TestMethodMacro(std::dec,f,GetYOrigin)
110       TestMethodMacro(std::dec,f,GetZOrigin)
111       TestMethodMacro(std::dec,f,GetBitsStored)
112       TestMethodMacro(std::dec,f,GetBitsAllocated)
113       TestMethodMacro(std::dec,f,GetHighBitPosition)
114       TestMethodMacro(std::dec,f,GetSamplesPerPixel)
115       TestMethodMacro(std::dec,f,GetPlanarConfiguration)
116       TestMethodMacro(std::dec,f,GetPixelSize)
117       TestMethodMacro(std::dec,f,GetPixelType)
118       TestMethodMacro(std::dec,f,GetLUTNbits)
119       TestMethodMacro(std::dec,f,GetRescaleIntercept)
120       TestMethodMacro(std::dec,f,GetRescaleSlope)
121       TestMethodMacro(std::hex,f,GetGrPixel)
122       TestMethodMacro(std::hex,f,GetNumPixel)
123       TestMethodMacro(std::dec,f,GetPixelOffset)
124
125       TestMethodMacro(std::dec,f,GetPixelAreaLength)
126       TestMethodMacro(std::dec,f,GetNumberOfScalarComponents)
127       TestMethodMacro(std::dec,f,GetNumberOfScalarComponentsRaw)
128       TestMethodMacro(std::dec,f,IsSignedPixelData)
129       TestMethodMacro(std::dec,f,IsMonochrome)
130       TestMethodMacro(std::dec,f,IsPaletteColor)
131       TestMethodMacro(std::dec,f,IsYBRFull)
132       TestMethodMacro(std::dec,f,HasLUT)
133       TestMethodMacro(std::dec,f,GetTransferSyntax)
134       TestMethodMacro(std::dec,f,GetTransferSyntaxName)
135       TestMethodMacro(std::dec,f,GetFileType)
136       TestMethodMacro(std::dec,f,GetFileName)
137
138       f->GetImageOrientationPatient( iop );
139       std::cout << "   Orientation:" << std::endl;
140       for (int j=0; j<6; j++)
141          std::cout << "      iop[" << j << "] = " << iop[j] << std::endl;
142  
143       f->GetImagePositionPatient( ipp );
144       std::cout << "   Position:" << std::endl;
145       for (int j2=0; j2<3; j2++)
146          std::cout << "      ipp[" << j2 << "] = " << ipp[j2] << std::endl; 
147
148       if( f->IsReadable() )
149       {
150          std::cout << "   " << filename << " is Readable" << std::endl;
151
152          GDCM_NAME_SPACE::FileHelper *fh= GDCM_NAME_SPACE::FileHelper::New( f );   
153
154          TestMethodMacro(std::dec,fh,GetImageDataSize)
155          TestMethodMacro(std::dec,fh,GetImageDataRawSize)
156          TestMethodMacro(std::dec,fh,GetRGBDataSize)
157          TestMethodMacro(std::dec,fh,GetRawDataSize)
158          TestMethodMacro(std::dec,fh,GetUserDataSize)
159          TestMethodMacro(std::dec,fh,GetWriteType)
160  
161          fh->Delete();
162       }
163       else
164       {
165          std::cout << filename << " is NOT Readable" 
166                    << std::endl << std::endl;
167          f->Delete();
168          return 1;
169       }
170       f->Delete();
171
172       if (argc ==2)
173          break; // user asked to check a single file.
174
175       i++;
176    }
177    return 0;
178 }