##############################################################################
# @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, 2013 University of Pennsylvania.
#
# This file is part of DTI-DROID.
#
# DTI-DROID is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DTI-DROID is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DTI-DROID.  If not, see <http://www.gnu.org/licenses/>.
#
# 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
# ============================================================================

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

# ----------------------------------------------------------------------------
basis_add_test (
  droid_081222_003184_to_JHU_ds
  COMMAND
    basis.testdriver -v
      --intensity-tolerance 0.00001
      --compare 081222_003184_to_JHU_ds.nii.gz
                "${BASELINE_DIR}/081222_003184_to_JHU_ds.nii.gz"
      -- "$<TARGET_FILE:dtidroid>" -v
          -d "${INPUT_DIR}/081222_003184_DTI_jLMMSE_ds.nii.gz"
          -t "${INPUT_DIR}/JHU_2m_lps_ds.nii.gz"
          -o . -p 081222_003184_to_JHU_ds.nii.gz
)

# ----------------------------------------------------------------------------
basis_add_test (
  droid_pre_l0
  COMMAND
    basis.testdriver -v
      --intensity-tolerance 0.00001
      --compare "pre_warped_l0.nii.gz"
                "${BASELINE_DIR}/pre_warped_l0.nii.gz"
      -- $<TARGET_FILE:dtidroid> -v
          -d "${INPUT_DIR}/pre_subject.nii.gz"
          -t "${INPUT_DIR}/pre_template.nii.gz"
          -o . -p pre_warped_l0.nii.gz
          -l 0
)

# ----------------------------------------------------------------------------
basis_add_test (
  droid_pre_l1
  COMMAND
    basis.testdriver -v
      --intensity-tolerance 0.00001
      --compare "pre_warped_l1.nii.gz"
                "${BASELINE_DIR}/pre_warped_l1.nii.gz"
      -- $<TARGET_FILE:dtidroid> -v
          -d "${INPUT_DIR}/pre_subject.nii.gz"
          -t "${INPUT_DIR}/pre_template.nii.gz"
          -o . -p pre_warped_l1.nii.gz
          -l 1
)

# ----------------------------------------------------------------------------
basis_add_test (
  droid_pre_l3
  COMMAND
    basis.testdriver -v
      --intensity-tolerance 0.00001
      --compare "pre_warped_l3.nii.gz"
                "${BASELINE_DIR}/pre_warped_l3.nii.gz"
      -- $<TARGET_FILE:dtidroid> -v
          -d "${INPUT_DIR}/pre_subject.nii.gz"
          -t "${INPUT_DIR}/pre_template.nii.gz"
          -o . -p pre_warped_l3.nii.gz
          -l 3
)
