b9e373f96a19d231ff929c16801546a7c4c284bb
[platform/upstream/tiff.git] / test / CMakeLists.txt
1 # CMake build for libtiff
2 #
3 # Copyright © 2015 Open Microscopy Environment / University of Dundee
4 # Written by Roger Leigh <rleigh@codelibre.net>
5 #
6 # Permission to use, copy, modify, distribute, and sell this software and
7 # its documentation for any purpose is hereby granted without fee, provided
8 # that (i) the above copyright notices and this permission notice appear in
9 # all copies of the software and related documentation, and (ii) the names of
10 # Sam Leffler and Silicon Graphics may not be used in any advertising or
11 # publicity relating to the software without the specific, prior written
12 # permission of Sam Leffler and Silicon Graphics.
13 #
14 # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 #
18 # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 # OF THIS SOFTWARE.
24
25 include_directories(${PROJECT_SOURCE_DIR}/libtiff
26                     ${PROJECT_BINARY_DIR}/libtiff
27                     ${CMAKE_CURRENT_BINARY_DIR}
28                     ${TIFF_INCLUDES})
29
30 # Test scripts (not used by CMake)
31 set(TESTSCRIPTS
32     bmp2tiff_palette.sh
33     bmp2tiff_rgb.sh
34     gif2tiff.sh
35     ppm2tiff_pbm.sh
36     ppm2tiff_pgm.sh
37     ppm2tiff_ppm.sh
38     tiffcp-g3.sh
39     tiffcp-g3-1d.sh
40     tiffcp-g3-1d-fill.sh
41     tiffcp-g3-2d.sh
42     tiffcp-g3-2d-fill.sh
43     tiffcp-g4.sh
44     tiffcp-logluv.sh
45     tiffcp-thumbnail.sh
46     tiffdump.sh
47     tiffinfo.sh
48     tiffcp-split.sh
49     tiffcp-split-join.sh
50     tiff2ps-PS1.sh
51     tiff2ps-PS2.sh
52     tiff2ps-PS3.sh
53     tiff2ps-EPS1.sh
54     tiff2pdf.sh
55     tiffcrop-doubleflip-logluv-3c-16b.sh
56     tiffcrop-doubleflip-minisblack-1c-16b.sh
57     tiffcrop-doubleflip-minisblack-1c-8b.sh
58     tiffcrop-doubleflip-minisblack-2c-8b-alpha.sh
59     tiffcrop-doubleflip-miniswhite-1c-1b.sh
60     tiffcrop-doubleflip-palette-1c-1b.sh
61     tiffcrop-doubleflip-palette-1c-4b.sh
62     tiffcrop-doubleflip-palette-1c-8b.sh
63     tiffcrop-doubleflip-rgb-3c-16b.sh
64     tiffcrop-doubleflip-rgb-3c-8b.sh
65     tiffcrop-extract-logluv-3c-16b.sh
66     tiffcrop-extract-minisblack-1c-16b.sh
67     tiffcrop-extract-minisblack-1c-8b.sh
68     tiffcrop-extract-minisblack-2c-8b-alpha.sh
69     tiffcrop-extract-miniswhite-1c-1b.sh
70     tiffcrop-extract-palette-1c-1b.sh
71     tiffcrop-extract-palette-1c-4b.sh
72     tiffcrop-extract-palette-1c-8b.sh
73     tiffcrop-extract-rgb-3c-16b.sh
74     tiffcrop-extract-rgb-3c-8b.sh
75     tiffcrop-extractz14-logluv-3c-16b.sh
76     tiffcrop-extractz14-minisblack-1c-16b.sh
77     tiffcrop-extractz14-minisblack-1c-8b.sh
78     tiffcrop-extractz14-minisblack-2c-8b-alpha.sh
79     tiffcrop-extractz14-miniswhite-1c-1b.sh
80     tiffcrop-extractz14-palette-1c-1b.sh
81     tiffcrop-extractz14-palette-1c-4b.sh
82     tiffcrop-extractz14-palette-1c-8b.sh
83     tiffcrop-extractz14-rgb-3c-16b.sh
84     tiffcrop-extractz14-rgb-3c-8b.sh
85     tiffcrop-R90-logluv-3c-16b.sh
86     tiffcrop-R90-minisblack-1c-16b.sh
87     tiffcrop-R90-minisblack-1c-8b.sh
88     tiffcrop-R90-minisblack-2c-8b-alpha.sh
89     tiffcrop-R90-miniswhite-1c-1b.sh
90     tiffcrop-R90-palette-1c-1b.sh
91     tiffcrop-R90-palette-1c-4b.sh
92     tiffcrop-R90-palette-1c-8b.sh
93     tiffcrop-R90-rgb-3c-16b.sh
94     tiffcrop-R90-rgb-3c-8b.sh
95     tiff2rgba-logluv-3c-16b.sh
96     tiff2rgba-minisblack-1c-16b.sh
97     tiff2rgba-minisblack-1c-8b.sh
98     tiff2rgba-minisblack-2c-8b-alpha.sh
99     tiff2rgba-miniswhite-1c-1b.sh
100     tiff2rgba-palette-1c-1b.sh
101     tiff2rgba-palette-1c-4b.sh
102     tiff2rgba-palette-1c-8b.sh
103     tiff2rgba-rgb-3c-16b.sh
104     tiff2rgba-rgb-3c-8b.sh
105     tiff2rgba-quad-tile.jpg.sh)
106
107 # This list should contain all of the TIFF files in the 'images'
108 # subdirectory which are intended to be used as input images for
109 # tests.  All of these files should use the extension ".tiff".
110 set(TIFFIMAGES
111     images/logluv-3c-16b.tiff
112     images/minisblack-1c-16b.tiff
113     images/minisblack-1c-8b.tiff
114     images/minisblack-2c-8b-alpha.tiff
115     images/miniswhite-1c-1b.tiff
116     images/palette-1c-1b.tiff
117     images/palette-1c-4b.tiff
118     images/palette-1c-8b.tiff
119     images/rgb-3c-16b.tiff
120     images/rgb-3c-8b.tiff
121     images/quad-tile.jpg.tiff)
122
123 set(BMPIMAGES
124     images/palette-1c-8b.bmp
125     images/rgb-3c-8b.bmp)
126
127 set(GIFIMAGES
128     images/palette-1c-8b.gif)
129
130 set(PNMIMAGES
131     images/minisblack-1c-8b.pgm
132     images/miniswhite-1c-1b.pbm
133     images/rgb-3c-8b.ppm)
134
135 # All uncompressed image files
136 set(UNCOMPRESSEDIMAGES
137     images/minisblack-1c-16b.tiff
138     images/minisblack-1c-8b.tiff
139     images/miniswhite-1c-1b.tiff
140     images/palette-1c-1b.tiff
141     images/palette-1c-4b.tiff
142     images/palette-1c-8b.tiff
143     images/rgb-3c-8b.tiff)
144
145 # This list should include all of the files in the 'images'
146 # subdirectory which are intended to be distributed.  This may include
147 # files which are not currently used by the tests.
148 set(IMAGES_EXTRA_DIST
149     images/README.txt
150     ${BMPIMAGES}
151     ${GIFIMAGES}
152     ${PNMIMAGES}
153     ${TIFFIMAGES})
154
155 extra_dist(
156     ${TESTSCRIPTS}
157     ${IMAGES_EXTRA_DIST}
158     common.sh)
159
160 set(noinst_HEADERS tifftest.h)
161
162 add_executable(ascii_tag ascii_tag.c)
163 target_link_libraries(ascii_tag tiff port)
164
165 add_executable(long_tag long_tag.c check_tag.c)
166 target_link_libraries(long_tag tiff port)
167
168 add_executable(short_tag short_tag.c check_tag.c)
169 target_link_libraries(short_tag tiff port)
170
171 add_executable(strip_rw strip_rw.c strip.c test_arrays.c test_arrays.h)
172 target_link_libraries(strip_rw tiff port)
173
174 add_executable(rewrite rewrite_tag.c)
175 target_link_libraries(rewrite tiff port)
176
177 if(JPEG_SUPPORT)
178   add_executable(raw_decode raw_decode.c)
179   target_link_libraries(raw_decode tiff port)
180 endif()
181
182 add_executable(custom_dir custom_dir.c)
183 target_link_libraries(custom_dir tiff port)
184
185 set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output")
186 file(MAKE_DIRECTORY "${TEST_OUTPUT}")
187
188 macro(tiff_test_convert name command1 command2 command3 infile outfile validate)
189   add_test(NAME "${name}"
190            COMMAND "${CMAKE_COMMAND}"
191            "-DCONVERT_COMMAND1=${command1}"
192            "-DCONVERT_COMMAND2=${command2}"
193            "-DCONVERT_COMMAND3=${command3}"
194            "-DINFILE=${infile}"
195            "-DOUTFILE=${outfile}"
196            "-DTIFFINFO=$<TARGET_FILE:tiffinfo>"
197            "-DLIBTIFF=$<TARGET_FILE:tiff>"
198            "-DVALIDATE=${validate}"
199            -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
200 endmacro()
201
202 macro(tiff_test_stdout name command infile outfile)
203   add_test(NAME "${name}"
204            COMMAND "${CMAKE_COMMAND}"
205            "-DSTDOUT_COMMAND=${command}"
206            "-DINFILE=${infile}"
207            "-DOUTFILE=${outfile}"
208            "-DTIFFINFO=$<TARGET_FILE:tiffinfo>"
209            "-DLIBTIFF=$<TARGET_FILE:tiff>"
210            -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
211 endmacro()
212
213 macro(tiff_test_reader name command infile)
214   add_test(NAME "${name}"
215            COMMAND "${CMAKE_COMMAND}"
216            "-DREADER_COMMAND=${command}"
217            "-DINFILE=${infile}"
218            "-DTIFFINFO=$<TARGET_FILE:tiffinfo>"
219            "-DLIBTIFF=$<TARGET_FILE:tiff>"
220            -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
221 endmacro()
222
223 macro(add_convert_test_multi commandname1 commandname2 commandname3
224       categoryname commandargs1 commandargs2 commandargs3
225       image validate)
226   string(REPLACE " " "^" escaped_commandargs1 "${commandargs1}")
227   string(REPLACE " " "^" escaped_commandargs2 "${commandargs2}")
228   string(REPLACE " " "^" escaped_commandargs3 "${commandargs3}")
229   get_filename_component(name "${image}" NAME)
230   get_filename_component(base "${image}" NAME_WE)
231   set(testname "${commandname1}-${categoryname}-${base}")
232   if(commandname1)
233     set(command1
234         "$<TARGET_FILE:${commandname1}>^${escaped_commandargs1}")
235   else()
236     set(command1)
237   endif()
238   if(commandname2)
239     set(command2
240         "$<TARGET_FILE:${commandname2}>^${escaped_commandargs2}")
241   else()
242     set(command2)
243   endif()
244   if(commandname3)
245     set(command3
246         "$<TARGET_FILE:${commandname3}>^${escaped_commandargs3}")
247   else()
248     set(command3)
249   endif()
250   set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
251   set(outfile "${TEST_OUTPUT}/${commandname1}-${categoryname}-${name}")
252   string(REGEX REPLACE "\\.tiff\$" "" name "${name}")
253   tiff_test_convert("${testname}" "${command1}" "${command2}" "${command3}"
254                     "${infile}" "${outfile}" "${validate}")
255 endmacro()
256
257 macro(add_convert_test commandname
258       categoryname commandargs
259       image validate)
260     add_convert_test_multi("${commandname}" "" ""
261                            "${categoryname}" "${commandargs}" "" ""
262                            "${image}" "${validate}")
263 endmacro()
264
265 macro(add_convert_tests_multi commandname commandname2 commandname3
266       categoryname
267       commandargs1 commandargs2 commandargs3
268       images validate)
269   foreach(file ${${images}})
270     add_convert_test_multi("${commandname1}" "${commandname2}"
271                            "${commandname3}" "${categoryname}"
272                            "${commandargs1}" "${commandargs2}"
273                            "${commandargs3}" "${file}" "${validate}")
274   endforeach()
275 endmacro()
276
277 macro(add_convert_tests commandname categoryname commandargs images validate)
278   foreach(file ${${images}})
279     add_convert_test("${commandname}" "${categoryname}"
280                      "${commandargs}" "${file}" "${validate}")
281   endforeach()
282 endmacro()
283
284 macro(add_stdout_test commandname commandargs image)
285   string(REPLACE " " "^" escaped_commandargs "${commandargs}")
286   get_filename_component(name "${image}" NAME)
287   get_filename_component(base "${image}" NAME_WE)
288   set(testname "${commandname}-${base}")
289   set(command "$<TARGET_FILE:${commandname}>^${escaped_commandargs}")
290   set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
291   set(outfile "${TEST_OUTPUT}/${commandname}-${name}")
292   string(REGEX REPLACE "\\.tiff\$" "" name "${name}")
293   tiff_test_stdout("${testname}" "${command}" "${infile}" "${outfile}")
294 endmacro()
295
296 macro(add_reader_test commandname commandargs image)
297   string(REPLACE " " "^" escaped_commandargs "${commandargs}")
298   get_filename_component(name "${image}" NAME)
299   get_filename_component(base "${image}" NAME_WE)
300   set(testname "${commandname}-${base}")
301   set(command "$<TARGET_FILE:${commandname}>^${escaped_commandargs}")
302   set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
303   string(REGEX REPLACE "\\.tiff\$" "" name "${name}")
304   tiff_test_reader("${testname}" "${command}" "${infile}")
305 endmacro()
306
307 # BMP
308 add_convert_test(bmp2tiff palette "" "images/palette-1c-8b.bmp" TRUE)
309 add_convert_test(bmp2tiff rgb     "" "images/rgb-3c-8b.bmp"     TRUE)
310
311 # GIF
312 add_convert_test(gif2tiff palette "" "images/palette-1c-8b.gif" TRUE)
313
314 # PPM
315 add_convert_test(ppm2tiff miniswhite "" "images/miniswhite-1c-1b.pbm" TRUE)
316 add_convert_test(ppm2tiff minisblack "" "images/minisblack-1c-8b.pgm" TRUE)
317 add_convert_test(ppm2tiff rgb        "" "images/rgb-3c-8b.ppm"        TRUE)
318
319 # tiffcp
320 add_convert_test(tiffcp   g3         "-c g3"         "images/miniswhite-1c-1b.tiff" FALSE)
321 add_convert_test(tiffcp   g31d       "-c g3:1d"      "images/miniswhite-1c-1b.tiff" FALSE)
322 add_convert_test(tiffcp   g31dfill   "-c g3:1d:fill" "images/miniswhite-1c-1b.tiff" FALSE)
323 add_convert_test(tiffcp   g32d       "-c g3:2d"      "images/miniswhite-1c-1b.tiff" FALSE)
324 add_convert_test(tiffcp   g32dfill   "-c g3:2d:fill" "images/miniswhite-1c-1b.tiff" FALSE)
325 add_convert_test(tiffcp   g4         "-c g4"         "images/miniswhite-1c-1b.tiff" FALSE)
326 add_convert_test_multi(tiffcp tiffcp "" logluv "-c none" "-c sgilog" ""
327                        "images/logluv-3c-16b.tiff"    FALSE)
328 add_convert_test_multi(tiffcp thumbnail "" thumbnail "g3:1d" "" ""
329                        "images/miniswhite-1c-1b.tiff"    FALSE)
330
331 # tiffdump
332 add_reader_test(tiffdump "" "images/miniswhite-1c-1b.tiff")
333
334 # tiffinfo
335 add_reader_test(tiffinfo "-c -D -d -j -s" "images/minisblack-1c-16b.tiff")
336
337 # tiffcp split/join
338 foreach(image ${UNCOMPRESSEDIMAGES})
339   list(APPEND ESCAPED_UNCOMPRESSED "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
340 endforeach()
341 string(REPLACE ";" "^" ESCAPED_UNCOMPRESSED "${ESCAPED_UNCOMPRESSED}")
342 add_test(NAME "tiffcp-split"
343          COMMAND "${CMAKE_COMMAND}"
344          "-DTESTFILES=${ESCAPED_UNCOMPRESSED}"
345          "-DCONJOINED=${TEST_OUTPUT}/tiffcp-split-conjoined.tif"
346          "-DSPLITFILE=${TEST_OUTPUT}/tiffcp-split-split-"
347          "-DTIFFCP=$<TARGET_FILE:tiffcp>"
348          "-DTIFFSPLIT=$<TARGET_FILE:tiffsplit>"
349          "-DLIBTIFF=$<TARGET_FILE:tiff>"
350          -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffSplitTest.cmake")
351 add_test(NAME "tiffcp-split-join"
352          COMMAND "${CMAKE_COMMAND}"
353          "-DTESTFILES=${ESCAPED_UNCOMPRESSED}"
354          "-DCONJOINED=${TEST_OUTPUT}/tiffcp-split-join-conjoined.tif"
355          "-DSPLITFILE=${TEST_OUTPUT}/tiffcp-split-join-split-"
356          "-DRECONJOINED=${TEST_OUTPUT}/tiffcp-split-join-reconjoined.tif"
357          "-DTIFFCP=$<TARGET_FILE:tiffcp>"
358          "-DTIFFSPLIT=$<TARGET_FILE:tiffsplit>"
359          "-DLIBTIFF=$<TARGET_FILE:tiff>"
360          -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffSplitTest.cmake")
361
362 # PDF
363 add_stdout_test(tiff2pdf "" "images/miniswhite-1c-1b.tiff" TRUE)
364
365 # RGBA
366 add_convert_tests(tiff2rgba default    ""                         TIFFIMAGES TRUE)
367 # Test rotations
368 add_convert_tests(tiffcrop  R90        "-R90"                     TIFFIMAGES TRUE)
369 # Test flip (mirror)
370 add_convert_tests(tiffcrop  doubleflip "-F both"                  TIFFIMAGES TRUE)
371 # Test extracting a section 60 pixels wide and 60 pixels high
372 add_convert_tests(tiffcrop  extract    "-U px -E top -X 60 -Y 60" TIFFIMAGES TRUE)
373 # Test extracting the first and fourth quarters from the left side.
374 add_convert_tests(tiffcrop  extractz14 "-E left -Z1:4,2:4"        TIFFIMAGES TRUE)