Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/test/TiffTestCommon.cmake

raw
1 # CMake tests for libtiff (common functionality)
2 #
3 # Copyright © 2015 Open Microscopy Environment / University of Dundee
4 # Written by Roger Leigh <[email protected]>
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
29 macro(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()
39 endmacro()
40
41 #
42 # Test a simple convert-like command.
43 #
44 # test_convert command infile outfile
45 macro(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()
58 endmacro()
59
60 #
61 # Test a simple command which sends output to stdout
62 #
63 # test_stdout command infile outfile
64 macro(test_stdout command infile outfile)
65 file(TO_NATIVE_PATH "${infile}" native_infile)
66 file(TO_NATIVE_PATH "${outfile}" native_outfile)
67 file(REMOVE "${outfile}")
68 message(STATUS "Running ${MEMCHECK} ${command} ${native_infile} > ${native_outfile}")
69 execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}"
70 OUTPUT_FILE "${outfile}"
71 RESULT_VARIABLE TEST_STATUS)
72 if(TEST_STATUS)
73 message(FATAL_ERROR "Returned failed status ${TEST_STATUS}! Output (if any) is in \"${native_outfile}")
74 endif()
75 endmacro()
76
77 #
78 # Test a simple command which sends output to stdout
79 #
80 # test_stdout command infile outfile
81 macro(test_stdout_noargs command)
82 message(STATUS "Running ${MEMCHECK} ${command}")
83 execute_process(COMMAND ${MEMCHECK} ${command}
84 RESULT_VARIABLE TEST_STATUS)
85 if(TEST_STATUS)
86 message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!")
87 endif()
88 endmacro()
89
90 #
91 # Execute a simple command (e.g. tiffinfo) with one input file
92 #
93 # test_exec command infile
94 macro(test_reader command infile)
95 file(TO_NATIVE_PATH "${infile}" native_infile)
96 message(STATUS "Running ${MEMCHECK} ${command} ${native_infile}")
97 execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}"
98 RESULT_VARIABLE TEST_STATUS)
99 if(TEST_STATUS)
100 message(FATAL_ERROR "Returned failed status ${TEST_STATUS}! Output (if any) is in \"${native_outfile}")
101 endif()
102 endmacro()
103
104 #
105 # Execute tiffinfo on a specified file to validate it
106 #
107 # tiffinfo_validate infile
108 macro(tiffinfo_validate file)
109 test_reader("${TIFFINFO};-D" "${file}")
110 endmacro()
111
112 # Add the directory containing libtiff to the PATH (Windows only)
113 if(WIN32)
114 get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
115 file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
116 set(ENV{PATH} "${LIBTIFF_DIR};$ENV{PATH}")
117 endif()
118 if(CYGWIN)
119 get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
120 file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
121 set(ENV{PATH} "${LIBTIFF_DIR}:$ENV{PATH}")
122 endif()