summaryrefslogtreecommitdiff
path: root/test/CMakeLists.txt
blob: 1bdb283e3674ce8cd143caeb63ba025077ff42cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# CMake build for libtiff
#
# Copyright © 2015 Open Microscopy Environment / University of Dundee
# Written by Roger Leigh <rleigh@codelibre.net>
#
# Permission to use, copy, modify, distribute, and sell this software and
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
#
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
#
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.

# Images for tiff2bw (8-bit RGB only)
set(RGBIMAGES
    images/palette-1c-8b.tiff
    images/rgb-3c-8b.tiff
    images/quad-lzw-compat.tiff
)

# This list should contain all of the TIFF files in the 'images'
# subdirectory which are intended to be used as input images for
# tests.  All of these files should use the extension ".tiff".
set(TIFFIMAGES
    images/custom_dir_EXIF_GPS.tiff
    images/logluv-3c-16b.tiff
    images/minisblack-1c-16b.tiff
    images/minisblack-1c-8b.tiff
    images/minisblack-2c-8b-alpha.tiff
    images/miniswhite-1c-1b.tiff
    images/palette-1c-1b.tiff
    images/palette-1c-4b.tiff
    images/palette-1c-8b.tiff
    images/rgb-3c-16b.tiff
    images/rgb-3c-8b.tiff
    images/quad-lzw-compat.tiff
    images/lzw-single-strip.tiff
    images/testfax4.tiff)
# TIFF images using old-jpeg.  Unused unless JPEG support is enabled.
set(TIFFIMAGES_OJPEG)

if(JPEG_SUPPORT)
    list(APPEND TIFFIMAGES images/quad-tile.jpg.tiff)
endif()

if (OJPEG_SUPPORT)
    list(APPEND TIFFIMAGES_OJPEG
        images/ojpeg_zackthecat_subsamp22_single_strip.tiff
        images/ojpeg_chewey_subsamp21_multi_strip.tiff
        images/ojpeg_single_strip_no_rowsperstrip.tiff
    )
endif()

set(BMPIMAGES
    images/palette-1c-8b.bmp
    images/rgb-3c-8b.bmp)

set(GIFIMAGES
    images/palette-1c-8b.gif)

set(PNMIMAGES
    images/minisblack-1c-8b.pgm
    images/miniswhite-1c-1b.pbm
    images/rgb-3c-16b.ppm
    images/rgb-3c-8b.ppm)

# All uncompressed image files
set(UNCOMPRESSEDIMAGES
    images/minisblack-1c-16b.tiff
    images/minisblack-1c-8b.tiff
    images/miniswhite-1c-1b.tiff
    images/palette-1c-1b.tiff
    images/palette-1c-4b.tiff
    images/palette-1c-8b.tiff
    images/rgb-3c-8b.tiff)

# This list should include all of the files in the 'images'
# subdirectory which are intended to be distributed.  This may include
# files which are not currently used by the tests.
set(IMAGES_EXTRA_DIST
    images/README.txt
    images/miniswhite-1c-1b.g3
    ${BMPIMAGES}
    ${GIFIMAGES}
    ${PNMIMAGES}
    ${TIFFIMAGES})

set(noinst_HEADERS tifftest.h)

set(simple_tests)

add_executable(ascii_tag ../placeholder.h)
target_sources(ascii_tag PRIVATE ascii_tag.c)
target_link_libraries(ascii_tag PRIVATE tiff port)
list(APPEND simple_tests ascii_tag)

add_executable(long_tag ../placeholder.h)
target_sources(long_tag PRIVATE long_tag.c check_tag.c)
target_link_libraries(long_tag PRIVATE tiff port)
list(APPEND simple_tests long_tag)

add_executable(short_tag ../placeholder.h)
target_sources(short_tag PRIVATE short_tag.c check_tag.c)
target_link_libraries(short_tag PRIVATE tiff port)
list(APPEND simple_tests short_tag)

add_executable(strip_rw ../placeholder.h)
target_sources(strip_rw PRIVATE strip_rw.c strip.c test_arrays.c test_arrays.h)
target_link_libraries(strip_rw PRIVATE tiff port)
list(APPEND simple_tests strip_rw)

add_executable(rewrite ../placeholder.h)
target_sources(rewrite PRIVATE rewrite_tag.c)
target_link_libraries(rewrite PRIVATE tiff port)
list(APPEND simple_tests rewrite)

if(JPEG_SUPPORT)
  add_executable(raw_decode ../placeholder.h)
  target_sources(raw_decode PRIVATE raw_decode.c)
  target_link_libraries(raw_decode PRIVATE tiff port JPEG::JPEG)
  list(APPEND simple_tests raw_decode)
endif()

add_executable(custom_dir ../placeholder.h)
target_sources(custom_dir PRIVATE custom_dir.c)
target_link_libraries(custom_dir PRIVATE tiff port)
list(APPEND simple_tests custom_dir)

# Uses private functions from static library
if(NOT BUILD_SHARED_LIBS)
  add_executable(rational_precision2double ../placeholder.h)
  target_sources(rational_precision2double PRIVATE rational_precision2double.c)
  target_link_libraries(rational_precision2double PRIVATE tiff port)
  list(APPEND simple_tests rational_precision2double)
endif()

add_executable(custom_dir_EXIF_231 ../placeholder.h)
target_sources(custom_dir_EXIF_231 PRIVATE custom_dir_EXIF_231.c)
target_link_libraries(custom_dir_EXIF_231 PRIVATE tiff port)
list(APPEND simple_tests custom_dir_EXIF_231)

add_executable(defer_strile_loading ../placeholder.h)
target_sources(defer_strile_loading PRIVATE defer_strile_loading.c)
target_link_libraries(defer_strile_loading PRIVATE tiff port)
list(APPEND simple_tests defer_strile_loading)

add_executable(defer_strile_writing ../placeholder.h)
target_sources(defer_strile_writing PRIVATE defer_strile_writing.c)
target_link_libraries(defer_strile_writing PRIVATE tiff port)
list(APPEND simple_tests defer_strile_writing)

add_executable(test_directory ../placeholder.h)
target_sources(test_directory PRIVATE test_directory.c)
target_link_libraries(test_directory PRIVATE tiff port)
list(APPEND simple_tests test_directory)

add_executable(testtypes ../placeholder.h)
target_sources(testtypes PRIVATE testtypes.c)
target_link_libraries(testtypes PRIVATE tiff port)
list(APPEND simple_tests testtypes)

if(WEBP_SUPPORT AND EMSCRIPTEN)
  # Emscripten is pretty finnicky about linker flags.
  # It needs --shared-memory if and only if atomics or bulk-memory is used.
  foreach(target
          ascii_tag
          long_tag
          short_tag
          strip_rw
          rewrite
          custom_dir
          defer_strile_loading
          defer_strile_writing
          )
    target_link_options(${target} PUBLIC "-Wl,--shared-memory")
  endforeach()
  if(JPEG_SUPPORT)
    target_link_options(raw_decode PUBLIC "-Wl,--shared-memory")
  endif()
endif()

set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output")
file(MAKE_DIRECTORY "${TEST_OUTPUT}")

set(tiff_test_extra_args
    "-DTIFFCP=$<TARGET_FILE:tiffcp>"
    "-DTIFFINFO=$<TARGET_FILE:tiffinfo>"
    "-DTIFFSPLIT=$<TARGET_FILE:tiffsplit>"
    "-DLIBTIFF=$<TARGET_FILE:tiff>")
if(WIN32)
  list(APPEND tiff_test_extra_args "-DWIN32=${WIN32}")
endif()
if(CYGWIN)
  list(APPEND tiff_test_extra_args "-DCYGWIN=${CYGWIN}")
endif()

function(tiff_test_convert name command1 command2 command3 infile outfile validate)
  add_test(NAME "${name}"
           COMMAND "${CMAKE_COMMAND}"
           "-DCONVERT_COMMAND1=${command1}"
           "-DCONVERT_COMMAND2=${command2}"
           "-DCONVERT_COMMAND3=${command3}"
           "-DINFILE=${infile}"
           "-DOUTFILE=${outfile}"
           "-DVALIDATE=${validate}"
           ${tiff_test_extra_args}
           -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
endfunction()

function(tiff_test_stdout name suffix command infile outfile)
  if (suffix)
     set(name "${name}-${suffix}")
  endif()
  add_test(NAME "${name}"
           COMMAND "${CMAKE_COMMAND}"
           "-DSTDOUT_COMMAND=${command}"
           "-DINFILE=${infile}"
           "-DOUTFILE=${outfile}"
           ${tiff_test_extra_args}
           -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
endfunction()

function(tiff_test_stdout_noargs name command)
  add_test(NAME "${name}"
          COMMAND "${CMAKE_COMMAND}"
          "-DSTDOUT_COMMAND=$<TARGET_FILE:${command}>"
          ${tiff_test_extra_args}
          -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake"
          WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endfunction()

function(tiff_test_reader name command infile)
  add_test(NAME "${name}"
           COMMAND "${CMAKE_COMMAND}"
           "-DREADER_COMMAND=${command}"
           "-DINFILE=${infile}"
           ${tiff_test_extra_args}
           -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
endfunction()

function(add_convert_test_multi commandname1 commandname2 commandname3
      categoryname commandargs1 commandargs2 commandargs3
      image validate)
  string(REPLACE " " "^" escaped_commandargs1 "${commandargs1}")
  string(REPLACE " " "^" escaped_commandargs2 "${commandargs2}")
  string(REPLACE " " "^" escaped_commandargs3 "${commandargs3}")
  get_filename_component(name "${image}" NAME)
  get_filename_component(base "${image}" NAME_WE)
  set(testname "${commandname1}-${categoryname}-${base}")
  if(commandname1)
    set(command1
        "$<TARGET_FILE:${commandname1}>^${escaped_commandargs1}")
  else()
    set(command1)
  endif()
  if(commandname2)
    set(command2
        "$<TARGET_FILE:${commandname2}>^${escaped_commandargs2}")
  else()
    set(command2)
  endif()
  if(commandname3)
    set(command3
        "$<TARGET_FILE:${commandname3}>^${escaped_commandargs3}")
  else()
    set(command3)
  endif()
  set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
  set(outfile "${TEST_OUTPUT}/${commandname1}-${categoryname}-${base}.tiff")
  tiff_test_convert("${testname}" "${command1}" "${command2}" "${command3}"
                    "${infile}" "${outfile}" "${validate}")
endfunction()

function(add_convert_test commandname
      categoryname commandargs
      image validate)
    add_convert_test_multi("${commandname}" "" ""
                           "${categoryname}" "${commandargs}" "" ""
                           "${image}" "${validate}")
endfunction()

function(add_convert_tests_multi commandname1 commandname2 commandname3
      categoryname
      commandargs1 commandargs2 commandargs3
      images validate)
  foreach(file ${${images}})
    add_convert_test_multi("${commandname1}" "${commandname2}"
                           "${commandname3}" "${categoryname}"
                           "${commandargs1}" "${commandargs2}"
                           "${commandargs3}" "${file}" "${validate}")
  endforeach()
endfunction()

function(add_convert_tests commandname categoryname commandargs images validate)
  foreach(file ${${images}})
    add_convert_test("${commandname}" "${categoryname}"
                     "${commandargs}" "${file}" "${validate}")
  endforeach()
endfunction()

function(add_stdout_test commandname suffix commandargs image)
  string(REPLACE " " "^" escaped_commandargs "${commandargs}")
  get_filename_component(name "${image}" NAME)
  get_filename_component(base "${image}" NAME_WE)
  set(testname "${commandname}-${base}")
  set(command "$<TARGET_FILE:${commandname}>^${escaped_commandargs}")
  set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
  set(outfile "${TEST_OUTPUT}/${commandname}-${name}")
  string(REGEX REPLACE "\\.tiff\$" "" name "${name}")
  tiff_test_stdout("${testname}" "${suffix}" "${command}" "${infile}" "${outfile}")
endfunction()

function(add_reader_test commandname commandargs image)
  string(REPLACE " " "^" escaped_commandargs "${commandargs}")
  get_filename_component(name "${image}" NAME)
  get_filename_component(base "${image}" NAME_WE)
  set(testname "${commandname}-${base}")
  set(command "$<TARGET_FILE:${commandname}>^${escaped_commandargs}")
  set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
  tiff_test_reader("${testname}" "${command}" "${infile}")
endfunction()

# Plain executables with no arguments
foreach(target IN LISTS simple_tests)
  tiff_test_stdout_noargs("${target}" "${target}")
endforeach()


# PPM
add_convert_test(ppm2tiff miniswhite "" "images/miniswhite-1c-1b.pbm" TRUE)
add_convert_test(ppm2tiff minisblack "" "images/minisblack-1c-8b.pgm" TRUE)
add_convert_test(ppm2tiff rgb        "" "images/rgb-3c-16b.ppm"       TRUE)
add_convert_test(ppm2tiff rgb        "" "images/rgb-3c-8b.ppm"        TRUE)

# tiffcp
add_convert_test(tiffcp   g3         "-c g3"         "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp   g31d       "-c g3:1d"      "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp   g31dfill   "-c g3:1d:fill" "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp   g32d       "-c g3:2d"      "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp   g32dfill   "-c g3:2d:fill" "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp   g4         "-c g4"         "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test_multi(tiffcp tiffcp "" logluv "-c none" "-c sgilog" ""
                       "images/logluv-3c-16b.tiff"    FALSE)
add_convert_test_multi(tiffcp thumbnail "" thumbnail "-c g3:1d" "" ""
                       "images/miniswhite-1c-1b.tiff"    FALSE)
add_convert_test(tiffcp   none       "-c none"       "images/quad-lzw-compat.tiff" FALSE)
add_convert_test(tiffcp   noner1     "-c none -r 1"  "images/lzw-single-strip.tiff" FALSE)
add_convert_test(tiffcp   float64_lzw_2_le "-c lzw:2       "images/test_float64_predictor2_le_lzw.tif" FALSE)
add_convert_test(tiffcp   float64_lzw_2_be "-c lzw:2       "images/test_float64_predictor2_be_lzw.tif" FALSE)

# tiffdump
add_reader_test(tiffdump "" "images/miniswhite-1c-1b.tiff")

# tiffinfo
add_reader_test(tiffinfo "-c -D -d -j -s" "images/custom_dir_EXIF_GPS.tiff")
add_reader_test(tiffinfo "-c -D -d -j -s" "images/minisblack-1c-16b.tiff")

# tiffcp split/join
foreach(image ${UNCOMPRESSEDIMAGES})
  list(APPEND ESCAPED_UNCOMPRESSED "${CMAKE_CURRENT_SOURCE_DIR}/${image}")
endforeach()
string(REPLACE ";" "^" ESCAPED_UNCOMPRESSED "${ESCAPED_UNCOMPRESSED}")
add_test(NAME "tiffcp-split"
         COMMAND "${CMAKE_COMMAND}"
         "-DTESTFILES=${ESCAPED_UNCOMPRESSED}"
         "-DCONJOINED=${TEST_OUTPUT}/tiffcp-split-conjoined.tiff"
         "-DSPLITFILE=${TEST_OUTPUT}/tiffcp-split-split-"
         ${tiff_test_extra_args}
         -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffSplitTest.cmake")
add_test(NAME "tiffcp-split-join"
         COMMAND "${CMAKE_COMMAND}"
         "-DTESTFILES=${ESCAPED_UNCOMPRESSED}"
         "-DCONJOINED=${TEST_OUTPUT}/tiffcp-split-join-conjoined.tiff"
         "-DSPLITFILE=${TEST_OUTPUT}/tiffcp-split-join-split-"
         "-DRECONJOINED=${TEST_OUTPUT}/tiffcp-split-join-reconjoined.tiff"
         ${tiff_test_extra_args}
         -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffSplitTest.cmake")

# PDF
add_stdout_test(tiff2pdf "" "" "images/miniswhite-1c-1b.tiff" TRUE)

# PS
add_stdout_test(tiff2ps "ps-1" "-a -p -1" "images/miniswhite-1c-1b.tiff" TRUE)
add_stdout_test(tiff2ps "ps-2" "-a -p -2" "images/miniswhite-1c-1b.tiff" TRUE)
add_stdout_test(tiff2ps "ps-3" "-a -p -3" "images/miniswhite-1c-1b.tiff" TRUE)
add_stdout_test(tiff2ps "eps-1" "-e -1" "images/miniswhite-1c-1b.tiff" TRUE)

# BW
add_convert_tests(tiff2bw default      ""                         RGBIMAGES TRUE)

# RGBA
add_convert_tests(tiff2rgba default    ""                         TIFFIMAGES TRUE)
# RGBA (old-jpeg)
add_convert_tests(tiff2rgba default    ""                         TIFFIMAGES_OJPEG TRUE)
# Test rotations
add_convert_tests(tiffcrop  R90        "-R90"                     TIFFIMAGES TRUE)
# Test flip (mirror)
add_convert_tests(tiffcrop  doubleflip "-F both"                  TIFFIMAGES TRUE)
# Test extracting a section 60 pixels wide and 60 pixels high
add_convert_tests(tiffcrop  extract    "-U px -E top -X 60 -Y 60" TIFFIMAGES TRUE)
# Test extracting the first and fourth quarters from the left side.
add_convert_tests(tiffcrop  extractz14 "-E left -Z1:4,2:4"        TIFFIMAGES TRUE)