1# CMake tests for libtiff (common functionality)
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#
26# Test a simple convert-like command.
27#
28# test_convert command infile outfile
29macro(test_convert command infile outfile)
30  file(TO_NATIVE_PATH "${infile}" native_infile)
31  file(TO_NATIVE_PATH "${outfile}" native_outfile)
32  file(REMOVE "${outfile}")
33  message(STATUS Running "${MEMCHECK} ${command} ${native_infile} ${native_outfile}")
34  execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}" "${native_outfile}"
35                  RESULT_VARIABLE TEST_STATUS)
36  if(TEST_STATUS)
37    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}\"")
38  endif()
39endmacro()
40
41#
42# Test a simple convert-like command.
43#
44# test_convert command infile outfile
45macro(test_convert_multi command infile outfile)
46  foreach(file ${infile})
47    file(TO_NATIVE_PATH "${file}" native_file)
48    list(APPEND native_infile "${native_file}")
49  endforeach()
50  file(TO_NATIVE_PATH "${outfile}" native_outfile)
51  file(REMOVE "${outfile}")
52  message(STATUS Running "${MEMCHECK} ${command} ${native_infile} ${native_outfile}")
53  execute_process(COMMAND ${MEMCHECK} ${command} ${native_infile} "${native_outfile}"
54                  RESULT_VARIABLE TEST_STATUS)
55  if(TEST_STATUS)
56    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}\"")
57  endif()
58endmacro()
59#
60# Test a simple command which sends output to stdout
61#
62# test_stdout command infile outfile
63macro(test_stdout command infile outfile)
64  file(TO_NATIVE_PATH "${infile}" native_infile)
65  file(TO_NATIVE_PATH "${outfile}" native_outfile)
66  file(REMOVE "${outfile}")
67  message(STATUS "Running ${MEMCHECK} ${command} ${native_infile} > ${native_outfile}")
68  execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}"
69                  OUTPUT_FILE "${outfile}"
70                  RESULT_VARIABLE TEST_STATUS)
71  if(TEST_STATUS)
72    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}")
73  endif()
74endmacro()
75
76#
77# Execute a simple command (e.g. tiffinfo) with one input file
78#
79# test_exec command infile
80macro(test_reader command infile)
81  file(TO_NATIVE_PATH "${infile}" native_infile)
82  message(STATUS "Running ${MEMCHECK} ${command} ${native_infile}")
83  execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}"
84                  RESULT_VARIABLE TEST_STATUS)
85  if(TEST_STATUS)
86    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}")
87  endif()
88endmacro()
89
90#
91# Execute tiffinfo on a specified file to validate it
92#
93# tiffinfo_validate infile
94macro(tiffinfo_validate file)
95  test_reader("${TIFFINFO};-D" "${file}")
96endmacro()
97
98# Add the directory containing libtiff to the PATH (Windows only)
99if(WIN32)
100  get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
101  file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
102  set(ENV{PATH} "${LIBTIFF_DIR};$ENV{PATH}")
103endif()
104if(CYGWIN)
105  get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
106  file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
107  set(ENV{PATH} "${LIBTIFF_DIR}:$ENV{PATH}")
108endif()
109