]> Creatis software - gdcm.git/blob - Testing/TestFileAccessors.cxx
* Fix some compilation warnings
[gdcm.git] / Testing / TestFileAccessors.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestFileAccessors.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/20 08:58:15 $
7   Version:   $Revision: 1.4 $
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 << "() : "      << mode << obj->name() << std::endl; \
44    } \
45    catch(...) \
46    { \
47       std::cout << "   --> Can't access to the '" << #name << "' method !" << std::endl; \
48       delete f; \
49       return 1; \
50    }
51
52
53 int TestFileAccessors(int, char *[])
54 {
55    int i = 0;
56
57    float iop[6];
58
59    while( gdcmDataImages[i] != 0 )
60    {
61       std::string filename = GDCM_DATA_ROOT;
62       filename += "/";  //doh!
63       filename += gdcmDataImages[i];
64       
65       std::cout << "Begin with " << filename << std::endl;
66       gdcm::File *f= new gdcm::File( );
67       f->SetFileName( filename );
68       f->Load( );
69
70 // We don't check the returned values
71 // We just want to be sure no accessor seg faults on any image  ...
72 // And this will improve test coverage ;-)
73
74       TestMethodMacro(std::dec,f,GetSwapCode)
75       TestMethodMacro(std::dec,f,GetImageNumber)
76       TestMethodMacro(std::dec,f,GetModality)
77       TestMethodMacro(std::dec,f,GetXSize)
78       TestMethodMacro(std::dec,f,GetYSize)
79       TestMethodMacro(std::dec,f,GetZSize)
80       TestMethodMacro(std::dec,f,GetXSpacing)
81       TestMethodMacro(std::dec,f,GetYSpacing)
82       TestMethodMacro(std::dec,f,GetZSpacing)
83       TestMethodMacro(std::dec,f,GetXOrigin)
84       TestMethodMacro(std::dec,f,GetYOrigin)
85       TestMethodMacro(std::dec,f,GetZOrigin)
86       TestMethodMacro(std::dec,f,GetBitsStored)
87       TestMethodMacro(std::dec,f,GetBitsAllocated)
88       TestMethodMacro(std::dec,f,GetHighBitPosition)
89       TestMethodMacro(std::dec,f,GetSamplesPerPixel)
90       TestMethodMacro(std::dec,f,GetPlanarConfiguration)
91       TestMethodMacro(std::dec,f,GetPixelSize)
92       TestMethodMacro(std::dec,f,GetPixelType)
93       TestMethodMacro(std::dec,f,GetLUTNbits)
94       TestMethodMacro(std::dec,f,GetRescaleIntercept)
95       TestMethodMacro(std::dec,f,GetRescaleSlope)
96       TestMethodMacro(std::hex,f,GetGrPixel)
97       TestMethodMacro(std::hex,f,GetNumPixel)
98       TestMethodMacro(std::dec,f,GetPixelOffset)
99
100       TestMethodMacro(std::dec,f,GetPixelAreaLength)
101       TestMethodMacro(std::dec,f,GetNumberOfScalarComponents)
102       TestMethodMacro(std::dec,f,GetNumberOfScalarComponentsRaw)
103       TestMethodMacro(std::dec,f,IsSignedPixelData)
104       TestMethodMacro(std::dec,f,IsMonochrome)
105       TestMethodMacro(std::dec,f,IsPaletteColor)
106       TestMethodMacro(std::dec,f,IsYBRFull)
107       TestMethodMacro(std::dec,f,HasLUT)
108       TestMethodMacro(std::dec,f,GetTransferSyntax)
109       TestMethodMacro(std::dec,f,GetTransferSyntaxName)
110       TestMethodMacro(std::dec,f,GetFileType)
111       TestMethodMacro(std::dec,f,GetFileName)
112
113       f->GetImageOrientationPatient( iop );
114       std::cout << "   Orientation:" << std::endl;
115       for (int j=0; j<6; j++)
116          std::cout << "      iop[" << j << "] = " << iop[j] << std::endl;
117
118       if( f->IsReadable() )
119       {
120          std::cout << "   " << filename << " is Readable" << std::endl;
121
122          gdcm::FileHelper *fh= new gdcm::FileHelper( f );   
123
124          TestMethodMacro(std::dec,fh,GetImageDataSize)
125          TestMethodMacro(std::dec,fh,GetImageDataRawSize)
126          TestMethodMacro(std::dec,fh,GetRGBDataSize)
127          TestMethodMacro(std::dec,fh,GetRawDataSize)
128          TestMethodMacro(std::dec,fh,GetUserDataSize)
129          TestMethodMacro(std::dec,fh,GetWriteType)
130  
131          delete fh;
132       }
133       else
134       {
135          std::cout << filename << " is NOT Readable" 
136                    << std::endl << std::endl;
137          delete f;
138          return 1;
139       }
140
141       delete f;
142       std::cout << "End with " << filename << std::endl;
143       i++;
144    }
145    return 0;
146 }