Blame test/TiffTestCommon.cmake

Packit 7838c8
# CMake tests for libtiff (common functionality)
Packit 7838c8
#
Packit 7838c8
# Copyright © 2015 Open Microscopy Environment / University of Dundee
Packit 7838c8
# Written by Roger Leigh <rleigh@codelibre.net>
Packit 7838c8
#
Packit 7838c8
# Permission to use, copy, modify, distribute, and sell this software and
Packit 7838c8
# its documentation for any purpose is hereby granted without fee, provided
Packit 7838c8
# that (i) the above copyright notices and this permission notice appear in
Packit 7838c8
# all copies of the software and related documentation, and (ii) the names of
Packit 7838c8
# Sam Leffler and Silicon Graphics may not be used in any advertising or
Packit 7838c8
# publicity relating to the software without the specific, prior written
Packit 7838c8
# permission of Sam Leffler and Silicon Graphics.
Packit 7838c8
#
Packit 7838c8
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
Packit 7838c8
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
Packit 7838c8
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit 7838c8
#
Packit 7838c8
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
Packit 7838c8
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
Packit 7838c8
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit 7838c8
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
Packit 7838c8
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
Packit 7838c8
# OF THIS SOFTWARE.
Packit 7838c8
Packit 7838c8
#
Packit 7838c8
# Test a simple convert-like command.
Packit 7838c8
#
Packit 7838c8
# test_convert command infile outfile
Packit 7838c8
macro(test_convert command infile outfile)
Packit 7838c8
  file(TO_NATIVE_PATH "${infile}" native_infile)
Packit 7838c8
  file(TO_NATIVE_PATH "${outfile}" native_outfile)
Packit 7838c8
  file(REMOVE "${outfile}")
Packit 7838c8
  message(STATUS Running "${MEMCHECK} ${command} ${native_infile} ${native_outfile}")
Packit 7838c8
  execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}" "${native_outfile}"
Packit 7838c8
                  RESULT_VARIABLE TEST_STATUS)
Packit 7838c8
  if(TEST_STATUS)
Packit 7838c8
    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}\"")
Packit 7838c8
  endif()
Packit 7838c8
endmacro()
Packit 7838c8
Packit 7838c8
#
Packit 7838c8
# Test a simple convert-like command.
Packit 7838c8
#
Packit 7838c8
# test_convert command infile outfile
Packit 7838c8
macro(test_convert_multi command infile outfile)
Packit 7838c8
  foreach(file ${infile})
Packit 7838c8
    file(TO_NATIVE_PATH "${file}" native_file)
Packit 7838c8
    list(APPEND native_infile "${native_file}")
Packit 7838c8
  endforeach()
Packit 7838c8
  file(TO_NATIVE_PATH "${outfile}" native_outfile)
Packit 7838c8
  file(REMOVE "${outfile}")
Packit 7838c8
  message(STATUS Running "${MEMCHECK} ${command} ${native_infile} ${native_outfile}")
Packit 7838c8
  execute_process(COMMAND ${MEMCHECK} ${command} ${native_infile} "${native_outfile}"
Packit 7838c8
                  RESULT_VARIABLE TEST_STATUS)
Packit 7838c8
  if(TEST_STATUS)
Packit 7838c8
    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}\"")
Packit 7838c8
  endif()
Packit 7838c8
endmacro()
Packit 7838c8
#
Packit 7838c8
# Test a simple command which sends output to stdout
Packit 7838c8
#
Packit 7838c8
# test_stdout command infile outfile
Packit 7838c8
macro(test_stdout command infile outfile)
Packit 7838c8
  file(TO_NATIVE_PATH "${infile}" native_infile)
Packit 7838c8
  file(TO_NATIVE_PATH "${outfile}" native_outfile)
Packit 7838c8
  file(REMOVE "${outfile}")
Packit 7838c8
  message(STATUS "Running ${MEMCHECK} ${command} ${native_infile} > ${native_outfile}")
Packit 7838c8
  execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}"
Packit 7838c8
                  OUTPUT_FILE "${outfile}"
Packit 7838c8
                  RESULT_VARIABLE TEST_STATUS)
Packit 7838c8
  if(TEST_STATUS)
Packit 7838c8
    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}")
Packit 7838c8
  endif()
Packit 7838c8
endmacro()
Packit 7838c8
Packit 7838c8
#
Packit 7838c8
# Execute a simple command (e.g. tiffinfo) with one input file
Packit 7838c8
#
Packit 7838c8
# test_exec command infile
Packit 7838c8
macro(test_reader command infile)
Packit 7838c8
  file(TO_NATIVE_PATH "${infile}" native_infile)
Packit 7838c8
  message(STATUS "Running ${MEMCHECK} ${command} ${native_infile}")
Packit 7838c8
  execute_process(COMMAND ${MEMCHECK} ${command} "${native_infile}"
Packit 7838c8
                  RESULT_VARIABLE TEST_STATUS)
Packit 7838c8
  if(TEST_STATUS)
Packit 7838c8
    message(FATAL_ERROR "Returned failed status ${TEST_STATUS}!  Output (if any) is in \"${native_outfile}")
Packit 7838c8
  endif()
Packit 7838c8
endmacro()
Packit 7838c8
Packit 7838c8
#
Packit 7838c8
# Execute tiffinfo on a specified file to validate it
Packit 7838c8
#
Packit 7838c8
# tiffinfo_validate infile
Packit 7838c8
macro(tiffinfo_validate file)
Packit 7838c8
  test_reader("${TIFFINFO};-D" "${file}")
Packit 7838c8
endmacro()
Packit 7838c8
Packit 7838c8
# Add the directory containing libtiff to the PATH (Windows only)
Packit 7838c8
if(WIN32)
Packit 7838c8
  get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
Packit 7838c8
  file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
Packit 7838c8
  set(ENV{PATH} "${LIBTIFF_DIR};$ENV{PATH}")
Packit 7838c8
endif()
Packit 7838c8
if(CYGWIN)
Packit 7838c8
  get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
Packit 7838c8
  file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
Packit 7838c8
  set(ENV{PATH} "${LIBTIFF_DIR}:$ENV{PATH}")
Packit 7838c8
endif()