]> Creatis software - gdcm.git/blob - Testing/CMakeLists.txt
coding style
[gdcm.git] / Testing / CMakeLists.txt
1 # CMakeLists for Testing purpose
2 # Cxx file that need a file to run should be place aproprietly
3
4 SET(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
5
6 SET(GDCM_TESTS ${CXX_TEST_PATH}/gdcmTests)
7
8 # add test that does not require data:
9 # They usally return if no argument is given
10 SET(TEST_SOURCES
11   TestBug.cxx
12   TestHash.cxx
13   TestTS.cxx
14   TestVR.cxx
15   TestUtil.cxx
16   TestDicomString.cxx
17   TestDict.cxx
18 )
19
20 # add tests that require data
21 IF (GDCM_DATA_ROOT)
22   SET(TEST_SOURCES ${TEST_SOURCES}     
23     TestReadWriteReadCompare.cxx     # includes generated gdcmDataImages.h 
24     PrintAllDocument.cxx             # includes generated gdcmDataImages.h
25     TestAllReadCompareDicom.cxx      # includes generated gdcmDataImages.h
26     TestAllEntryVerify.cxx           # includes generated gdcmDataImages.h
27     #TestChangeHeader.cxx
28     TestCopyDicom.cxx
29     TestCopyRescaleDicom.cxx
30     TestWriteSimple.cxx
31     TestDicomDir.cxx                 # require DICOMDIR
32     BuildUpDicomDir.cxx              # writes a file named "NewDICOMDIR"
33     makeDicomDir.cxx                 # writes a file named "NewDICOMDIR"
34     TestDirList.cxx
35   )
36   # add test that require VTK:
37   IF(GDCM_VTK)
38     # Include the VTK library
39     INCLUDE(${VTK_USE_FILE})
40
41     INCLUDE_DIRECTORIES(
42       ${GDCM_SOURCE_DIR}/vtk/
43       )
44     SET(TEST_SOURCES ${TEST_SOURCES}
45       ShowDicom.cxx
46       ShowDicomSeq.cxx
47       TestWriteWithVTK.cxx
48       )
49   ENDIF(GDCM_VTK)
50 ENDIF (GDCM_DATA_ROOT)
51
52
53
54 # include stuff
55 INCLUDE_DIRECTORIES(
56   ${GDCM_SOURCE_DIR}/src/
57   ${GDCM_BINARY_DIR}/
58 )
59
60 CREATE_TEST_SOURCELIST(Tests gdcmTests.cxx ${TEST_SOURCES})
61 ADD_EXECUTABLE(gdcmTests ${Tests})
62 IF(GDCM_VTK)
63   TARGET_LINK_LIBRARIES(gdcmTests vtkgdcm vtkRendering)
64 ELSE(GDCM_VTK)
65   TARGET_LINK_LIBRARIES(gdcmTests gdcm)
66 ENDIF(GDCM_VTK)
67
68 SET (TestsToRun ${Tests})
69 REMOVE (TestsToRun gdcmTests.cxx)
70
71 # Loop over files and create executables
72 FOREACH(file ${TEST_SOURCES})
73   GET_FILENAME_COMPONENT(name ${file} NAME_WE)
74 #  IF (GDCM_DATA_ROOT)
75 #    ADD_TEST(${name} ${GDCM_TESTS} ${name}
76 #        -D ${GDCM_DATA_ROOT}
77 #        -T ${GDCM_BINARY_DIR}/Testing/Temporary
78 #        -V Baseline/gdcm/${name}.png)
79 #  ELSE (GDCM_DATA_ROOT)
80     ADD_TEST(${name} ${GDCM_TESTS} ${name})
81 #  ENDIF (GDCM_DATA_ROOT)
82 ENDFOREACH(file ${TEST_SOURCES})
83
84 #-----------------------------------------------------------------------------
85
86 # We need to test the reading of all dicom images in the gdcmData directory
87 # First parse this directory and extract all images
88
89 IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
90   FILE(GLOB GDCM_DATA_IMAGES_GLOB
91     "${GDCM_DATA_ROOT}/*.acr"
92     "${GDCM_DATA_ROOT}/*.dcm"
93     "${GDCM_DATA_ROOT}/*.nema"
94     "${GDCM_DATA_ROOT}/*.ima"
95     )
96   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB
97     "${GDCM_DATA_ROOT}/*FileSeq0.acr"
98     "${GDCM_DATA_ROOT}/*FileSeq0.dcm"
99     "${GDCM_DATA_ROOT}/*FileSeq0.nema"
100     "${GDCM_DATA_ROOT}/*FileSeq0.ima"
101     )
102 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
103   # Since there is a bug in cmake 1.8.3, I'll have to do two separate globs
104   FILE(GLOB GDCM_DATA_IMAGES_GLOB_ACR
105     "${GDCM_DATA_ROOT}/*.acr"
106     )
107   FILE(GLOB GDCM_DATA_IMAGES_GLOB_DCM
108     "${GDCM_DATA_ROOT}/*.dcm"
109     )
110   FILE(GLOB GDCM_DATA_IMAGES_GLOB_NEMA
111     "${GDCM_DATA_ROOT}/*.nema"
112     )
113   FILE(GLOB GDCM_DATA_IMAGES_GLOB_IMA
114     "${GDCM_DATA_ROOT}/*.ima"
115     )
116   SET(GDCM_DATA_IMAGES_GLOB 
117     ${GDCM_DATA_IMAGES_GLOB_DCM} ${GDCM_DATA_IMAGES_GLOB_ACR}
118     ${GDCM_DATA_IMAGES_GLOB_NEMA} ${GDCM_DATA_IMAGES_GLOB_IMA})
119
120   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_ACR
121     "${GDCM_DATA_ROOT}/*FileSeq0.acr"
122     )
123   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_DCM
124     "${GDCM_DATA_ROOT}/*FileSeq0.dcm"
125     )
126   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_NEMA
127     "${GDCM_DATA_ROOT}/*FileSeq0.nema"
128     )
129   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_IMA
130     "${GDCM_DATA_ROOT}/*FileSeq0.ima"
131     )
132   SET(GDCM_DATA_SEQ_IMAGES_GLOB 
133     ${GDCM_DATA_SEQ_IMAGES_GLOB_DCM} ${GDCM_DATA_SEQ_IMAGES_GLOB_ACR}
134     ${GDCM_DATA_SEQ_IMAGES_GLOB_NEMA} ${GDCM_DATA_SEQ_IMAGES_GLOB_IMA})
135 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
136
137 # Black list of images known to break lots of readers (efilm, xmedcon ...):
138 SET(BLACK_LIST
139   # serial killer (also segfaults vtkgdcmViewer, but NOT PrintFile)
140   "gdcm-JPEG-LossLessThoravision.dcm"
141
142   # Mathieu: temporarily remove as it kills my gnome session (but not kde)
143   # JPR: also breaks TestReadWriteReadCompare : Pixel differ (as expanded
144   #      in memory)  
145   "KODAK-12-MONO1-Odd_Terminated_Sequence.dcm"
146   )
147
148 # This is a GLOB expression, change it into a list separated with a comma and \n
149 SET(GDCM_DATA_IMAGES)
150 FOREACH(filename ${GDCM_DATA_IMAGES_GLOB})
151   GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
152   STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
153   IF(NOT bad_dicom)
154     SET(GDCM_DATA_IMAGES "${GDCM_DATA_IMAGES}\n\"${filename_temp}\",")
155   ENDIF(NOT bad_dicom)
156 ENDFOREACH(filename)
157
158 SET(GDCM_DATA_SEQ_IMAGES)
159 FOREACH(filename ${GDCM_DATA_SEQ_IMAGES_GLOB})
160   GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
161   STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
162   IF(NOT bad_dicom)
163     STRING(REGEX REPLACE "(.*)FileSeq0(.*)" "\\1FileSeq%d\\2" filename_temp2 ${filename_temp})
164
165     SET(GDCM_DATA_SEQ_IMAGES "${GDCM_DATA_SEQ_IMAGES}\n\"${filename_temp2}\",")
166   ENDIF(NOT bad_dicom)
167 ENDFOREACH(filename)
168
169 # Populate GDCM_DATA_IMAGES:
170 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataImages.h"
171   "const char * const gdcmDataImages[] = { ${GDCM_DATA_IMAGES}\n0 };\n" 
172   )
173
174 # Populate GDCM_DATA_SEQ_IMAGES:
175 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataSeqImages.h"
176   "const char * const gdcmDataSeqImages[] = { ${GDCM_DATA_SEQ_IMAGES}\n0 };\n" 
177   )