# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

add_executable(OpenEXRUtilTest
  main.cpp
  testFlatImage.cpp
  testFlatImage.h
  testDeepImage.cpp
  testDeepImage.h
  testIO.cpp
  testIO.h
  testImageChannel.cpp
  testImageChannel.h
 )
target_include_directories(OpenEXRUtilTest PRIVATE ../OpenEXRTest)
target_link_libraries(OpenEXRUtilTest OpenEXR::OpenEXRUtil)
set_target_properties(OpenEXRUtilTest PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
  CXX_STANDARD_REQUIRED ON
  CXX_EXTENSIONS OFF
)
if(WIN32 AND BUILD_SHARED_LIBS)
  target_compile_definitions(OpenEXRUtilTest PRIVATE OPENEXR_DLL)
endif()
target_compile_features(OpenEXRUtilTest
    PRIVATE cxx_std_${OPENEXR_CXX_STANDARD}
)

function(DEFINE_OPENEXR_UTIL_TESTS)
  foreach(curtest IN LISTS ARGN)
    # CMAKE_CROSSCOMPILING_EMULATOR is necessary to support cross-compiling (ex: to win32 from mingw and running tests with wine)
    add_test(NAME OpenEXRUtil.${curtest} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:OpenEXRUtilTest> ${curtest})
    set_tests_properties(OpenEXRUtil.${curtest} PROPERTIES LABELS "OpenEXRUtil")
  endforeach()
endfunction()

define_openexr_util_tests(
  testFlatImage
  testDeepImage
  testIO
  testImageChannel
)

# "portability" tests: an abbreviated subset of the test suite run by
# specialty CI jobs (alternate OS/build-variant jobs) to test the
# behaviors most likely to differ across OS/toolchain/libc.
# Primary Linux/macOS/Windows jobs run the complete test suite.
set_tests_properties(OpenEXRUtil.testFlatImage PROPERTIES LABELS "OpenEXRUtil;portability")

# COST hint (measured wall time in seconds from a local full-suite run) so
# ctest's --parallel scheduler starts this long-running test early. See
# the longer explanation in OpenEXRTest/CMakeLists.txt.
set_tests_properties (OpenEXRUtil.testDeepImage PROPERTIES COST 16)
