]> Creatis software - gdcm.git/blob - Testing/TestFileAccessors.cxx
Fix some comments
[gdcm.git] / Testing / TestFileAccessors.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestFileAccessors.cxx,v $
5   Language:  C++
6   Date:      $Date: 2006/03/17 14:33:54 $
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
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       f->Delete(); \
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    
62      // Keep the comment to be able to track a bug on a given image
63      // for all the OS.
64      
65      // if (gdcmDataImages[i] == "00191113.dcm" )
66      //    gdcm::Debug::DebugOn();
67      // else
68          gdcm::Debug::DebugOff();
69
70       std::string filename = GDCM_DATA_ROOT;
71       filename += "/";  //doh!
72       filename += gdcmDataImages[i];
73       
74       std::cout << "Begin with " << filename << std::endl;
75       gdcm::File *f= gdcm::File::New( );
76       f->SetFileName( filename );
77       f->Load( );
78
79 // We don't check the returned values
80 // We just want to be sure no accessor seg faults on any image  ...
81 // And this will improve test coverage ;-)
82
83       TestMethodMacro(std::dec,f,GetSwapCode)
84       TestMethodMacro(std::dec,f,GetImageNumber)
85       TestMethodMacro(std::dec,f,GetModality)
86       TestMethodMacro(std::dec,f,GetXSize)
87       TestMethodMacro(std::dec,f,GetYSize)
88       TestMethodMacro(std::dec,f,GetZSize)
89       TestMethodMacro(std::dec,f,GetXSpacing)
90       TestMethodMacro(std::dec,f,GetYSpacing)
91       TestMethodMacro(std::dec,f,GetZSpacing)
92       TestMethodMacro(std::dec,f,GetXOrigin)
93       TestMethodMacro(std::dec,f,GetYOrigin)
94       TestMethodMacro(std::dec,f,GetZOrigin)
95       TestMethodMacro(std::dec,f,GetBitsStored)
96       TestMethodMacro(std::dec,f,GetBitsAllocated)
97       TestMethodMacro(std::dec,f,GetHighBitPosition)
98       TestMethodMacro(std::dec,f,GetSamplesPerPixel)
99       TestMethodMacro(std::dec,f,GetPlanarConfiguration)
100       TestMethodMacro(std::dec,f,GetPixelSize)
101       TestMethodMacro(std::dec,f,GetPixelType)
102       TestMethodMacro(std::dec,f,GetLUTNbits)
103       TestMethodMacro(std::dec,f,GetRescaleIntercept)
104       TestMethodMacro(std::dec,f,GetRescaleSlope)
105       TestMethodMacro(std::hex,f,GetGrPixel)
106       TestMethodMacro(std::hex,f,GetNumPixel)
107       TestMethodMacro(std::dec,f,GetPixelOffset)
108
109       TestMethodMacro(std::dec,f,GetPixelAreaLength)
110       TestMethodMacro(std::dec,f,GetNumberOfScalarComponents)
111       TestMethodMacro(std::dec,f,GetNumberOfScalarComponentsRaw)
112       TestMethodMacro(std::dec,f,IsSignedPixelData)
113       TestMethodMacro(std::dec,f,IsMonochrome)
114       TestMethodMacro(std::dec,f,IsPaletteColor)
115       TestMethodMacro(std::dec,f,IsYBRFull)
116       TestMethodMacro(std::dec,f,HasLUT)
117       TestMethodMacro(std::dec,f,GetTransferSyntax)
118       TestMethodMacro(std::dec,f,GetTransferSyntaxName)
119       TestMethodMacro(std::dec,f,GetFileType)
120       TestMethodMacro(std::dec,f,GetFileName)
121
122       f->GetImageOrientationPatient( iop );
123       std::cout << "   Orientation:" << std::endl;
124       for (int j=0; j<6; j++)
125          std::cout << "      iop[" << j << "] = " << iop[j] << std::endl;
126
127       if( f->IsReadable() )
128       {
129          std::cout << "   " << filename << " is Readable" << std::endl;
130
131          gdcm::FileHelper *fh= gdcm::FileHelper::New( f );   
132
133          TestMethodMacro(std::dec,fh,GetImageDataSize)
134          TestMethodMacro(std::dec,fh,GetImageDataRawSize)
135          TestMethodMacro(std::dec,fh,GetRGBDataSize)
136          TestMethodMacro(std::dec,fh,GetRawDataSize)
137          TestMethodMacro(std::dec,fh,GetUserDataSize)
138          TestMethodMacro(std::dec,fh,GetWriteType)
139  
140          fh->Delete();
141       }
142       else
143       {
144          std::cout << filename << " is NOT Readable" 
145                    << std::endl << std::endl;
146          f->Delete();
147          return 1;
148       }
149
150       f->Delete();
151       std::cout << "End with " << filename << std::endl;
152       i++;
153    }
154    return 0;
155 }