##############################################################################
# @file  CMakeLists.txt
# @brief Build configuration of software testing.
#
# Unit tests test only single functions, classes, and modules of the software.
# System tests, on the other side, execute the programs of this package with
# given test input data and compare the output of the programs to the expected
# results. For the definition of system tests which perform image regression
# tests, i.e., compare the images written by the test to given baseline images,
# the basis.testdriver executable target imported from BASIS can be used to
# execute the executable to test and perform the regression tests.
#
# Example:
# @code
# basis_add_test (
#  COMMAND basis.testdriver -v
#    --intensity-tolerance 2
#    --compare "t1_bc.nii.gz"
#              "${PROJECT_TESTING_DIR}/baseline/t1_bc.nii.gz"
#    --
#    $<TARGET_FILE:biascorrect>
#      "${PROJECT_TESTING_DIR}/input/t1.nii.gz"
#      t1_bc.nii.gz
# )
# @endcode
#
# If the tests are implemented in C/C++ as supported by CMake's
# create_test_sourcelist() function, a custom test driver can be generated
# using the basis_add_test_driver() function and this test driver then be used
# to execute the tests and perform the regression tests.
#
# Example:
# @code
# basis_add_test_driver (testdriver test1.cxx test2.cxx test3.cxx)
#
# basis_add_test (
#   COMMAND testdriver -v
#     --intensity-tolerance 2
#     --compare "t1_bc.nii.gz"
#               "${PROJECT_TESTING_DIR}/baseline/t1_bc.nii.gz"
#     --
#     biascorrect # test1.cxx defines int biascorrect(int argc, char* argv[])
#      "${PROJECT_TESTING_DIR}/input/t1.nii.gz"
#      t1_bc.nii.gz
# )
#
# # ...
# @endcode
#
# @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:create_test_sourcelist
#
# The built test executables can be found in @c TESTING_RUNTIME_DIR.
# The test output shall be written to @c TESTING_OUTPUT_DIR. In most cases,
# a subdirectory for each test should be created under this output directory.
# Therefore, the basis_add_test() function creates such subdirectory and sets
# the working directory of the test to this output directory.
#
# Copyright (c) 2012 University of Pennsylvania. All rights reserved.<br />
# See http://www.rad.upenn.edu/sbia/software/license.html or COPYING file.
#
# Contact: SBIA Group <sbia-software at uphs.upenn.edu>
##############################################################################

# ============================================================================
# internal tests
# ============================================================================

if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/internal")
  add_subdirectory ("internal")
endif ()

# ============================================================================
# public tests
# ============================================================================

# ----------------------------------------------------------------------------
# common settings
set (INPUT_DIR    "${PROJECT_TESTING_DIR}/input")
set (BASELINE_DIR "${PROJECT_TESTING_DIR}/baseline")

if (OpenCV_VERSION VERSION_LESS "2.0")
  set (BASELINE_SUFFIX "opencv-1.0")
elseif (OpenCV_VERSION VERSION_GREATER "2.3")
  set (BASELINE_SUFFIX "opencv-2.3")
else ()
  set (BASELINE_SUFFIX "opencv-2.0")
endif ()

# ----------------------------------------------------------------------------
# test odvba-index
basis_add_test(test_odvba-index.py)

# ----------------------------------------------------------------------------
# test odvba-ni
basis_add_test (test_odvba-ni.py)

# ----------------------------------------------------------------------------
# test odvba
basis_add_test(
  test_odvba
  COMMAND
    basis.testdriver -v
      # check p-values map
      --intensity-tolerance 0.01
      --compare "p.nii.gz"
                "${BASELINE_DIR}/32_32_32/p-values.n4000_e50_s15_p25.${BASELINE_SUFFIX}.nii.gz"
      # test command
      -- $<TARGET_FILE:odvba> -v -v
          "${INPUT_DIR}/32_32_32/subjects.txt"
          --index "${INPUT_DIR}/32_32_32/index.txt"
          --ni "${INPUT_DIR}/32_32_32/ni_n4000_e50_s15.txt"
          --perms "${INPUT_DIR}/32_32_32/perms_p25.txt"
)
