]> Creatis software - gdcm.git/blob - Testing/CMakeLists.txt
Add some explanations
[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   TestEmpty.cxx
12   TestUtil.cxx
13   TestBug.cxx
14   TestHash.cxx
15   TestCommand.cxx
16   TestTS.cxx
17   TestVR.cxx
18   TestDictGroupName.cxx
19   TestDict.cxx
20   TestDataEntry.cxx
21   TestWriteSimple.cxx
22   TestImageSet.cxx
23   TestDicomDirElement.cxx
24   TestDicomString.cxx
25   TestEnumVR.cxx
26   TestBuildUpDicomDir.cxx          # writes a file named "NewDICOMDIR"
27 )
28 IF(UNIX OR WIN32)
29   SET(TEST_SOURCES ${TEST_SOURCES}
30     TestInline.cxx
31   )
32 ENDIF(UNIX OR WIN32)
33
34 # add tests that require data
35 IF (GDCM_DATA_ROOT)
36   SET(TEST_SOURCES ${TEST_SOURCES}
37     TestFileAccessors.cxx
38     TestMakeIcon.cxx
39     TestLoadAllDocumentsNoPrivNoSeq.cxx # includes generated gdcmDataImages.h
40     #TestLoadAllDocumentsNoShadow.cxx   # includes generated gdcmDataImages.h
41     TestPrintAllDocument.cxx            # includes generated gdcmDataImages.h
42     #TestAllEntryVerify.cxx             # includes generated gdcmDataImages.h
43     #TestAllReadCompareDicom.cxx        # includes generated gdcmDataImages.h
44     TestReadWriteReadCompare.cxx        # includes generated gdcmDataImages.h 
45     TestReadWriteJPEGReadCompare.cxx    # includes generated gdcmDataImages.h 
46     #TestReadWriteJPEG2000ReadCompare.cxx # includes generated gdcmDataImages.h     
47         
48     #TestCopyDicom.cxx                  # includes generated gdcmDataImages.h 
49     #    TestCopyRescaleDicom.cxx       # includes generated gdcmDataImages.h 
50     #TestChangeHeader.cxx
51     #    TestAnonymize.cxx
52     TestDirList.cxx
53     TestDicomDir.cxx                 # require DICOMDIR
54
55     TestMakeDicomDir.cxx             # writes a file named "NewDICOMDIR"
56     TestSerieHelper.cxx              # uses gdcmData as a default root directory    
57     TestAllVM.cxx
58     TestValidate.cxx                 #Just to have on overviews of oddities ...  
59   )
60   # add test that require VTK:
61   IF(GDCM_VTK)
62   
63     IF("${VTK_MAJOR_VERSION}" LESS 4)
64       MESSAGE(FATAL_ERROR "This VTK version is not supported, you are on your own !")
65     ELSE("${VTK_MAJOR_VERSION}" LESS 4)
66     
67       IF("${VTK_MAJOR_VERSION}" EQUAL 4 AND "${VTK_MINOR_VERSION}" EQUAL 2)
68         MESSAGE(FATAL_ERROR "This VTK version is not supported, you are on your own !"
69                              "Although gdcm should compile fine. You just need to turn BUILD_TESTING:=OFF")
70       ENDIF("${VTK_MAJOR_VERSION}" EQUAL 4 AND "${VTK_MINOR_VERSION}" EQUAL 2)
71       IF("${VTK_MAJOR_VERSION}" EQUAL 4 AND "${VTK_MINOR_VERSION}" EQUAL 4 AND "${VTK_BUILD_VERSION}" LESS 3)
72         MESSAGE(FATAL_ERROR "This VTK version is not supported, you are on your own !"
73                              "Although gdcm should compile fine. You just need to turn BUILD_TESTING:=OFF")
74       ENDIF("${VTK_MAJOR_VERSION}" EQUAL 4 AND "${VTK_MINOR_VERSION}" EQUAL 4 AND "${VTK_BUILD_VERSION}" LESS 3)
75       
76       # Include the VTK library since we know this is going to work
77       INCLUDE(${VTK_USE_FILE})
78
79       INCLUDE_DIRECTORIES(
80         ${GDCM_SOURCE_DIR}/vtk
81       )
82       SET(TEST_SOURCES ${TEST_SOURCES}
83         VTKTestRead.cxx
84         VTKTestReadSeq.cxx
85         VTKTestWrite.cxx
86         VTKTestWriteSeq.cxx
87       )
88     ENDIF("${VTK_MAJOR_VERSION}" LESS 4)
89   ENDIF(GDCM_VTK)
90 ENDIF (GDCM_DATA_ROOT)
91
92
93
94 # include stuff
95 INCLUDE_DIRECTORIES(
96   ${GDCM_SOURCE_DIR}/src
97   ${GDCM_BINARY_DIR}
98 )
99
100 CREATE_TEST_SOURCELIST(Tests gdcmTests.cxx ${TEST_SOURCES})
101 ADD_EXECUTABLE(gdcmTests ${Tests})
102 IF(GDCM_VTK)
103   IF(GDCM_DATA_ROOT)
104     TARGET_LINK_LIBRARIES(gdcmTests vtkgdcm vtkRendering)
105   ELSE(GDCM_DATA_ROOT)
106     TARGET_LINK_LIBRARIES(gdcmTests gdcm)
107   ENDIF(GDCM_DATA_ROOT)     
108 ELSE(GDCM_VTK)
109   TARGET_LINK_LIBRARIES(gdcmTests gdcm)
110 ENDIF(GDCM_VTK)
111
112 SET (TestsToRun ${Tests})
113 REMOVE (TestsToRun gdcmTests.cxx)
114
115 # Loop over files and create executables
116 FOREACH(file ${TEST_SOURCES})
117   GET_FILENAME_COMPONENT(name ${file} NAME_WE)
118   ADD_TEST(${name} ${GDCM_TESTS} ${name})
119 ENDFOREACH(file ${TEST_SOURCES})
120
121 #-----------------------------------------------------------------------------
122
123 # We need to test the reading of all dicom images in the gdcmData directory
124 # First parse this directory and extract all images
125
126 FILE(GLOB GDCM_DATA_IMAGES_GLOB
127   "${GDCM_DATA_ROOT}/*.acr"
128   "${GDCM_DATA_ROOT}/*.dcm"
129   "${GDCM_DATA_ROOT}/*.nema"
130   "${GDCM_DATA_ROOT}/*.ima"
131   )
132
133 FILE(GLOB GDCM_DATA_EXTRA_IMAGES_GLOB
134   "${GDCM_DATA_EXTRA_ROOT}/gdcmSampleData/images_of_interest/*.dcm"
135   )
136 #MESSAGE(${GDCM_DATA_EXTRA_IMAGES_GLOB})
137
138 # Black list of images known to break lots of readers (efilm, xmedcon ...):
139 SET(BLACK_LIST
140   # Multiframe Papyrus format image
141   # Just to remember this format exists, and is gdcm::File compliant
142   # (NOT gdcm::FileHelper ...)
143   # any contribution is welcome
144   "PET-cardio-Multiframe-Papyrus.dcm"
145   # From David Clunie's Compresion Dataset  
146   "D_CLUNIE_CT1_JLSN.dcm"
147   "D_CLUNIE_CT1_JLSL.dcm"
148   #Not a Dicom Image, but a RT Object
149   "RS2.16.124.113534.2.3.5.0.120040728.21342.353.12747_anonimized.dcm" 
150   #Dicom MPEG image
151   "ETIAM_video_002.dcm"
152   #Something stupid occured in the code for LibIDO images.
153   #I Black list them for a while. JP
154   #"gdcm-ACR-LibIDO.acr"
155   "LIBIDO-24-ACR_NEMA-Rectangle.dcm"
156   #16 Bits per pixel images with LUT 16 Bits.
157   #I wait to be 100% sure before releasing them. JP
158   "rle16sti.dcm"
159   "rle16loo.dcm"   
160   # Jasper cannot handle this image, only kakadu so far, unless you patch jasper
161   # but then it breaks other images...
162   "CT_Phillips_JPEG2K_Decompr_Problem.dcm"
163   
164   #RTDOSE, 32 bits image : cannot be compressed
165   #"RTDOSE.dcm"
166   
167   #
168   # ------------
169   #  
170   #Still cause troubles (see the .README.txt file for more details)  
171   "MR_Philips_Intera_in_SQ_2001_e05f_item_wrong_lgt_use_NOSHADOWSEQ.dcm"  
172   "MR_Philips_Intera_PrivateSequenceExplicitVR.dcm" 
173   #The 2 previous images are identical !
174   #--> Replaced by more significant name
175   "MR_Philips_Intera_PrivateSequenceExplicitVR_in_SQ_2001_e05f_item_wrong_lgt_use_NOSHADOWSEQ.dcm"
176
177   #hexedit shows something *very* strange around offset 0x76e !
178   #the images looks *over*corrupted (on disc, not from the manufacturer!)
179   "MR_Philips_Intera_PrivateSequenceImplicitVR.dcm"
180   
181   # Seems this one hangs on 64 bits processors ?!?
182   # I blacklist it until the pb is solved.
183   # (to get some more green on the Dasboards)
184   "MR_Philips-Intera_BreaksNOSHADOW.dcm"
185
186   # No way we'll ever be able to read that...
187   "ELSCINT1_LOSSLESS_RICE.dcm"
188
189   # Are we even be able to support our own bugs ?
190   "SIEMENS_MAGNETOM-12-MONO2-GDCM12-VRUN.dcm"
191   "SIEMENS_GBS_III-16-ACR_NEMA_1-ULis2Bytes.dcm"
192   "SIEMENS_ImageLocationUN.dcm"
193   "TheralysGDCM120Bug.dcm"
194   "IM-0001-0066.dcm"
195   "DMCPACS_ExplicitImplicit_BogusIOP.dcm"
196   "MR_ELSCINT1_00e1_1042_SQ_feff_00e0_Item.dcm"
197   "MR_Spectroscopy_SIEMENS_OF.dcm"
198   "ELSCINT1_PMSCT_RLE1.dcm"
199   "ELSCINT1_JP2vsJ2K.dcm"
200   "GE_MR_0025xx1bProtocolDataBlock.dcm"
201   "TG18-CH-2k-01.dcm"
202   "CT-SIEMENS-MissingPixelDataInIconSQ.dcm"
203   "KODAK_CompressedIcon.dcm"
204   "LJPEG_BuginGDCM12.dcm"
205   "DX_J2K_0Padding.dcm"
206   "DX_GE_FALCON_SNOWY-VOI.dcm"
207   "PHILIPS_Brilliance_ExtraBytesInOverlay.dcm"
208   "JPEG_LossyYBR.dcm"
209   )
210
211 # Create a specific list of dicom files that we know are part of a sequence
212 SET(SEQ_LIST
213   "SIEMENS_MAGNETOM-12-MONO2-FileSeq[0-9].dcm"
214   )
215
216 # Add a special test that requires dciodvfy from dicom3tools
217 INCLUDE(${GDCM_SOURCE_DIR}/CMake/FindDicom3Tools.cmake)
218
219 # This is a GLOB expression, change it into a list separated with a comma and \n
220 SET(GDCM_DATA_IMAGES)
221 SET(GDCM_DATA_SEQ_IMAGES)
222 FOREACH(filename ${GDCM_DATA_IMAGES_GLOB})
223   GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
224   IF(DCIODVFY_FOUND)
225     #ADD_TEST("DCIODVFY-INPUT-${filename_temp}" "${DCIODVFY_EXECUTABLE}" "${filename}")
226     #ADD_TEST("DCIODVFY-OUTPUT-${filename_temp}" "${DCIODVFY_EXECUTABLE}" "${GDCM_DATA_ROOT}/BaselineDicom/${filename_temp}")
227   ENDIF(DCIODVFY_FOUND)
228   STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
229   IF(NOT bad_dicom)
230     SET(GDCM_DATA_IMAGES "${GDCM_DATA_IMAGES}\n\"${filename_temp}\",")
231     # SEQ_LIST is a regular expression:
232     STRING(REGEX MATCH ${SEQ_LIST} is_seq ${filename_temp})
233     IF(is_seq)
234       SET(GDCM_DATA_SEQ_IMAGES "${GDCM_DATA_SEQ_IMAGES}\n\"${filename_temp}\",")
235     ENDIF(is_seq)
236   ENDIF(NOT bad_dicom)
237 ENDFOREACH(filename)
238
239 # Paranoid / dcmdump
240 IF(GDCM_DCMTK_CHECK)
241 FOREACH(filename ${GDCM_DATA_IMAGES_GLOB} ${GDCM_DATA_EXTRA_IMAGES_GLOB})
242   GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
243   STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
244   IF(NOT bad_dicom)
245     IF(BUILD_EXAMPLES)
246       FOREACH(mode a d x) #r
247         FOREACH(opt "" monochrome1 noshadowseq noshadow noseq rgb)
248           ADD_TEST(ReWrite-${mode}-${opt}-${filename_temp} ${EXECUTABLE_OUTPUT_PATH}/ReWrite filein=${filename} fileout=${GDCM_BINARY_DIR}/${mode}-${opt}-${filename_temp} mode=${mode} ${opt})
249           ADD_TEST(dcmdump-${mode}-${opt}-${filename_temp} /usr/bin/dcmdump -E -dc +ae ${GDCM_BINARY_DIR}/${mode}-${opt}-${filename_temp})
250           #ADD_TEST(ReWrite-${mode}-${opt}-${filename_temp}-bis ${EXECUTABLE_OUTPUT_PATH}/ReWrite filein=${GDCM_BINARY_DIR}/${mode}-${opt}-${filename_temp} fileout=${GDCM_BINARY_DIR}/reference.dcm mode=${mode} ${opt})
251           #ADD_TEST(diff-${mode}-${opt}-${filename_temp} /usr/bin/diff ${GDCM_BINARY_DIR}/${mode}-${opt}-${filename_temp} ${GDCM_BINARY_DIR}/reference.dcm)
252         ENDFOREACH(opt)
253       ENDFOREACH(mode)
254     ENDIF(BUILD_EXAMPLES)
255   ENDIF(NOT bad_dicom)
256 ENDFOREACH(filename)
257 ENDIF(GDCM_DCMTK_CHECK)
258
259 # Populate GDCM_DATA_IMAGES:
260 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataImages.h"
261   "const char * const gdcmDataImages[] = { ${GDCM_DATA_IMAGES}\n0 };\n" 
262 )
263
264 # Populate GDCM_DATA_SEQ_IMAGES:
265 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataSeqImages.h"
266   "const char * const gdcmDataSeqImages[] = { ${GDCM_DATA_SEQ_IMAGES}\n0 };\n" 
267 )
268
269 #-----------------------------------------------------------------------------
270 # Trying to solve a bizarre problem when loading shared lib if gdcm is static
271 # Therefore I disable the test when building SHAREDLIBS
272 IF(UNIX AND NOT BUILD_SHARED_LIBS)
273   ADD_LIBRARY(dynmodule MODULE dynmodule.cxx)
274   TARGET_LINK_LIBRARIES(dynmodule gdcm)
275   ADD_EXECUTABLE(loadmodule loadmodule.cxx )
276   TARGET_LINK_LIBRARIES(loadmodule gdcm -ldl)
277   ADD_TEST(loadmodule ${CXX_TEST_PATH}/loadmodule)
278 ENDIF(UNIX AND NOT BUILD_SHARED_LIBS)
279
280
281 #-----------------------------------------------------------------------------
282 # Do the build against an installed gdcm
283 SET(GDCM_TEST_INSTALL_LEFT "${CMAKE_INSTALL_PREFIX}")
284 SET(GDCM_TEST_INSTALL_RIGHT "${GDCM_BINARY_DIR}/InstallTest/Root")
285 STRING(COMPARE EQUAL "${GDCM_TEST_INSTALL_LEFT}" "${GDCM_TEST_INSTALL_RIGHT}"
286   GDCM_TEST_INSTALL)
287 IF(GDCM_TEST_INSTALL)
288   ADD_TEST(Install
289     ${CMAKE_CTEST_COMMAND}
290     #  ${GDCM_INSTALL_TEST_CONFIG_TYPE}
291     --build-and-test ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
292     --build-generator ${CMAKE_GENERATOR}
293     --build-project GDCM
294     --build-makeprogram ${CMAKE_MAKE_PROGRAM}
295     --build-noclean
296     --build-target install)
297 ENDIF(GDCM_TEST_INSTALL)
298