project(EMSegmentTesting)

include_directories(
  ${EMSegment_SOURCE_DIR}
  ${EMSegment_SOURCE_DIR}/MRML
  ${EMSegment_SOURCE_DIR}/Algorithm
  ${VTK_INCLUDE_DIR}
  )

set(EMSegment_TEST_DIR ${EMSegment_BINARY_DIR})
set(EMSegment_TUTORIAL_DIR
  ${EMSegment_SOURCE_DIR}/Testing/TestData/TutorialTest)
set(EMSegment_TUTORIAL2_DIR
  ${EMSegment_SOURCE_DIR}/Testing/TestData/TutorialTest2)
set(EMSegment_TESTDATA_DIR
  ${EMSegment_SOURCE_DIR}/Testing/TestData)


#### MIDAS
include( ../../../Applications/CLI/BRAINSTools/BuildScripts/MIDAS.cmake )
SETIFEMPTY(MIDAS_REST_URL "http://midas.kitware.com/api/rest" CACHE STRING "The MIDAS server where testing data resides")
set(MIDAS_KEY_DIR "${EMSegment_SOURCE_DIR}/Testing/TestData/MIDAS_Keys")
#### MIDAS


# Extra Tests:
# Change these to 1 if you want to run the extra EMSegment tests.  They
# require a testing dataset that is not distributed by default with
# Slicer3.  NB: The extra tests may take a long time and a large
# amount of memory!!!

set(EMSEG_RUN_COMPARE_TESTS   OFF
  CACHE BOOL "Enable EMSegment tests to compare segmentation results." FORCE
  )
mark_as_advanced(EMSEG_RUN_COMPARE_TESTS)

set(EMSEG_RUN_VALGRIND_TESTS    OFF
  CACHE BOOL "Enable EMSegment Valgrind test." FORCE
  )
mark_as_advanced(EMSEG_RUN_VALGRIND_TESTS)
set(EMSEG_RUN_EXTRA_SHORT_TESTS  OFF
  CACHE BOOL "Enable EMSegment extra, short tests." FORCE
  )
mark_as_advanced(EMSEG_RUN_EXTRA_SHORT_TESTS)
set(EMSEG_RUN_EXTRA_LONG_TESTS   OFF
  CACHE BOOL "Enable EMSegment extra, long tests." FORCE
  )
mark_as_advanced(EMSEG_RUN_EXTRA_LONG_TESTS)

mark_as_advanced(EMSEG_RUN_REG_TESTS)
set(EMSEG_RUN_REG_TESTS   OFF
  CACHE BOOL "Enable EMSegment extra, registration tests."
  )

# Set to 1 to remove temporary test output files
set(EMSEG_REMOVE_TMP_TEST_DATA   "1"
  CACHE BOOL "Remove EMSegment temporary test data." FORCE)
mark_as_advanced(EMSEG_REMOVE_TMP_TEST_DATA)

if(NOT DISABLE_CXX_TESTING)

  ############################################################################
  # add test executables
  ############################################################################
  add_executable(
    vtkEMSegmentRemoteIOTest
    vtkEMSegmentRemoteIOTest.cxx

    )
  target_link_libraries(
    vtkEMSegmentRemoteIOTest
    RemoteIO
    vtkCommon
    )


  add_executable(
    vtkEMSegmentBlackBoxSegmentationTest
    vtkEMSegmentBlackBoxSegmentationTest.cxx
    vtkEMSegmentTestUtilities.cxx
    )
  target_link_libraries(
    vtkEMSegmentBlackBoxSegmentationTest
    EMSegment
    vtkCommon
    )


  add_executable(
    vtkEMSegmentCompareTest
    vtkEMSegmentCompareTest.cxx
    vtkEMSegmentTestUtilities.cxx
    )
  target_link_libraries(
    vtkEMSegmentCompareTest
    EMSegment
    vtkCommon
    )

  add_executable(
    vtkEMSegmentReadWriteMRMLTest
    vtkEMSegmentReadWriteMRMLTest.cxx
    )
  target_link_libraries(
    vtkEMSegmentReadWriteMRMLTest
    EMSegment
    vtkCommon
    )

  add_executable(
    vtkEMSegmentMRMLManagerTest
    vtkEMSegmentMRMLManagerTest.cxx
    vtkEMSegmentTestUtilities.cxx
    )
  target_link_libraries(
    vtkEMSegmentMRMLManagerTest
    EMSegment
    vtkCommon
    )

  add_executable(
    vtkEMSegmentPreprocessingManagerTest
    vtkEMSegmentPreprocessingManagerTest.cxx
    vtkEMSegmentTestUtilities.cxx
    )
  target_link_libraries(
    vtkEMSegmentPreprocessingManagerTest
    EMSegment
    vtkCommon
    )

  ############################################################################
  # The test is a stand-alone executable.  However, the Slicer3
  # launcher is needed to set up shared library paths correctly.
  # We create a prefix for the test executable that accomplishes this
  # wrapping.
  # WRAPPED_TEST_EXE_PREFIX: path to tests that only exist in build tree
  # WRAPPED_EXE_PREFIX: path to command line utilities that install with
  # slicer
  ############################################################################
  set(Slicer3_EXE ${Slicer3_BINARY_DIR}/Slicer3)
  set(WRAPPED_TEST_EXE_PREFIX --launch ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  set(WRAPPED_EXE_PREFIX --launch ${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_PLUGINS_BIN_DIR})
  if(WIN32)
    set(WRAPPED_EXE_PREFIX ${WRAPPED_EXE_PREFIX}/${CMAKE_BUILD_TYPE})
    set(WRAPPED_TEST_EXE_PREFIX ${WRAPPED_TEST_EXE_PREFIX}/${CMAKE_BUILD_TYPE})
  endif(WIN32)

  ############################################################################
  #
  # command line tests---does the logic work, does it fail elegently
  #
  ############################################################################

  # Does the mrml manager's api function correctly?
  add_test(
    vtkEMSegmentMRMLManagerTest
    ${Slicer3_EXE} ${WRAPPED_TEST_EXE_PREFIX}/vtkEMSegmentMRMLManagerTest
    ${EMSegment_TUTORIAL_DIR}/Template_small_normalizationOn.mrml
    "EMSegment Tutorial Template"
    )

  # Does the preprocessing function correctly?
  #add_test(
  #  vtkEMSegmentPreprocessingManagerTest
  #  ${Slicer3_EXE} ${WRAPPED_TEST_EXE_PREFIX}/vtkEMSegmentPreprocessingManagerTest
  #  ${EMSegment_TUTORIAL_DIR}/Template_small_normalizationOn.mrml
  #  "EMSegment Tutorial Template"
  #  )

  # Test that the segmentation results match what the expected
  # results.  This is a legacy test that should not be removed.
  add_test(
    vtkEMSegmentBlackBoxSegmentationTest_TutorialDataSmallRead
    ${Slicer3_EXE} ${WRAPPED_TEST_EXE_PREFIX}/vtkEMSegmentBlackBoxSegmentationTest
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    ${EMSegment_TUTORIAL_DIR}
    "EMSegment Tutorial Template"
    ${EMSegment_TUTORIAL_DIR}/StandardData/StandardSegmentationResult_small.mhd
    )

  # Build parameters from scratch and run the segmentation
  #add_test(
  #  vtkEMSegmentBuildAndRunNewSegmentationParameters001
  #  ${Slicer3_EXE} ${WRAPPED_TEST_EXE_PREFIX}/vtkEMSegmentBuildAndRunNewSegmentationParameters001
  #  ${EMSegment_SOURCE_DIR}/Testing/TestData/MiscVolumeData/R.mhd
  #  ${EMSegment_SOURCE_DIR}/Testing/TestData/MiscVolumeData/G.mhd
  #  ${EMSegment_SOURCE_DIR}/Testing/TestData/MiscVolumeData/B.mhd
  #  ${EMSegment_TEST_DIR}/RGBSegmentationResult.mhd
  #  )

  # Does help work right?
  add_test(
    EMSegCL_Help
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --help
    )
  set_tests_properties(
    EMSegCL_Help
    PROPERTIES
    PASS_REGULAR_EXPRESSION "USAGE"
    )


  if(EMSEG_RUN_REG_TESTS)
    # Does the segmenter work and give the correct answer using the
    # Tutorial2 default parameters (this includes registration)?
    set(test_name        "EMSegCL_RunReg")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.raw.gz")
    set(test_std_file    "${EMSegment_TUTORIAL2_DIR}/StandardData/Segmentation_med.raw.gz")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw.gz)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args
      ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
      --verbose
      --mrmlSceneFileName ${EMSegment_TUTORIAL2_DIR}/EMSegmentTestSet2_med.mrml
      --resultVolumeFileName "${test_file_prefix}.nhdr"
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )

    # Does the segmenter work and give the correct answer using the
    # Tutorial2 default parameters with no registration?
    set(test_name        "EMSegCL_RunRegNoReg")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.raw.gz")
    set(test_std_file    "${EMSegment_TUTORIAL2_DIR}/StandardData/Segmentation_NoReg_med.raw.gz")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw.gz)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args
      ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
      --verbose
      --mrmlSceneFileName ${EMSegment_TUTORIAL2_DIR}/EMSegmentTestSet2_NoReg_med.mrml 
      --resultVolumeFileName "${test_file_prefix}.nhdr"
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )

    # Does the segmenter work and give the correct answer using the
    # Tutorial2 default parameters with only T2T registration?
    set(test_name        "EMSegCL_RunRegT2T")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.raw.gz")
    set(test_std_file    "${EMSegment_TUTORIAL2_DIR}/StandardData/Segmentation_T2TReg_med.raw.gz")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw.gz)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args
      ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
      --verbose
      --mrmlSceneFileName ${EMSegment_TUTORIAL2_DIR}/EMSegmentTestSet2_T2TReg_med.mrml 
      --resultVolumeFileName "${test_file_prefix}.nhdr"
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )

    # Does the segmenter work and give the correct answer using the
    # Tutorial2 default parameters with only A2T registration?
    set(test_name        "EMSegCL_RunRegA2T")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.raw.gz")
    set(test_std_file    "${EMSegment_TUTORIAL2_DIR}/StandardData/Segmentation_A2TReg_med.raw.gz")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw.gz)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args
      ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
      --verbose
      --mrmlSceneFileName ${EMSegment_TUTORIAL2_DIR}/EMSegmentTestSet2_A2TReg_med.mrml 
      --resultVolumeFileName "${test_file_prefix}.nhdr"
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )
  endif(EMSEG_RUN_REG_TESTS)

  # Does the segmenter work and give the correct answer using the
  # default parameters from the small template scene.
  set(test_name        "EMSegCL_RunDefaultNodes")
  set(test_exe         "${Slicer3_EXE}")
  set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
  set(test_cmp_file    "${test_file_prefix}.raw")
  set(test_std_file    "${EMSegment_TUTORIAL_DIR}/StandardData/StandardSegmentationResult_small.raw")
  if(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw)
  else(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_rm_files)
  endif(${EMSEG_REMOVE_TMP_TEST_DATA})
  set(test_args 
    ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --verbose 
    --mrmlSceneFileName ${EMSegment_TUTORIAL_DIR}/Template_small.mrml 
    --resultVolumeFileName "${test_file_prefix}.mhd"
    --disableCompression
    )
  add_test(
    ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
    "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
    "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
    "-Drm_files:STRING=${test_rm_files}"
    -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
    )

  # Does the segmenter work and give the correct answer when
  # normalization is turned on?
  set(test_name        "EMSegCL_RunNormalize")
  set(test_exe         "${Slicer3_EXE}")
  set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
  set(test_cmp_file    "${test_file_prefix}.raw")
  set(test_std_file    "${EMSegment_TUTORIAL_DIR}/StandardData/StandardSegmentationResult_small_normalizationOn.raw")
  if(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw)
  else(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_rm_files)
  endif(${EMSEG_REMOVE_TMP_TEST_DATA})
  set(test_args 
    ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --verbose 
    --mrmlSceneFileName ${EMSegment_TUTORIAL_DIR}/Template_small_normalizationOn.mrml 
    --resultVolumeFileName "${test_file_prefix}.mhd"
    --disableCompression
    )
  #add_test(
  #  ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
  #  "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
  #  "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
  #  "-Drm_files:STRING=${test_rm_files}"
  #  -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
  #  )

  # Does the segmenter work and give the correct answer when
  # everything is specified on the command line?
  set(test_name        "EMSegCL_RunSetEverything")
  set(test_exe         "${Slicer3_EXE}")
  set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
  set(test_cmp_file    "${test_file_prefix}.raw")
  set(test_std_file    "${EMSegment_TUTORIAL_DIR}/StandardData/StandardSegmentationResult_small.raw")
  if(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw)
  else(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_rm_files)
  endif(${EMSEG_REMOVE_TMP_TEST_DATA})
  set(test_args 
    ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --verbose 
    --mrmlSceneFileName ${EMSegment_TUTORIAL_DIR}/Template_small.mrml 
    --targetVolumeFileNames
    ${EMSegment_TUTORIAL_DIR}/VolumeData/targetT1Normed_small.mhd,${EMSegment_TUTORIAL_DIR}/VolumeData/targetT2Normed_small.mhd
    --parametersMRMLNodeName EMSegment\ Tutorial\ Template
    --resultVolumeFileName "${test_file_prefix}.mhd"
    --disableCompression
    )
  add_test(
    ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
    "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
    "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
    "-Drm_files:STRING=${test_rm_files}"
    -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
    )

  # Is multithreading disabled when the command line flag is given?
  add_test(
    EMSegCL_DisableMultithreading
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --verbose --dontWriteResults --mrmlSceneFileName 
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --disableMultithreading 
    )
  set_tests_properties(
    EMSegCL_DisableMultithreading
    PROPERTIES
    PASS_REGULAR_EXPRESSION "Multithreading is disabled"
    )

  # Does it fail elegently when a bogus parameter node is specified?
  add_test(
    EMSegCL_EFBogusParameterNode
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --dontWriteResults --mrmlSceneFileName 
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --parametersMRMLNodeName BogusNodeName  
    )
  set_tests_properties(
    EMSegCL_EFBogusParameterNode
    PROPERTIES
    PASS_REGULAR_EXPRESSION
    "ERROR: no EMSegment parameters found in scene with name ")

  # Does it fail elegently when a bogus mrml scene is specified?
  add_test(
    EMSegCL_EFBogusMRMLScene
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --dontWriteResults --mrmlSceneFileName ${Slicer3_BINARY_DIR}/Testing/Temporary/bogus_file_scene.mrml
    )
  set_tests_properties(
    EMSegCL_EFBogusMRMLScene
    PROPERTIES
    PASS_REGULAR_EXPRESSION
    "Error: MRML scene file does not exist.")

  # Does it fail elegently when a bogus target images are specified?
  add_test(
    EMSegCL_EFBogusTargetImages
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --dontWriteResults --mrmlSceneFileName 
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TUTORIAL_DIR}/VolumeData/targetT1Normed_small.mhd,${EMSegment_TUTORIAL_DIR}/VolumeData/bogus.mhd
    )
  set_tests_properties(
    EMSegCL_EFBogusTargetImages
    PROPERTIES
    PASS_REGULAR_EXPRESSION
    "Error: target volume file ")

  # Does it fail elegently when too many target images are specified?
  add_test(
    EMSegCL_EFTooManyImages
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --dontWriteResults --mrmlSceneFileName 
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TUTORIAL_DIR}/VolumeData/targetT1Normed_small.mhd,${EMSegment_TUTORIAL_DIR}/VolumeData/targetT2Normed_small.mhd,${EMSegment_TUTORIAL_DIR}/VolumeData/targetT2Normed_small.mhd
    )
  set_tests_properties(
    EMSegCL_EFTooManyImages
    PROPERTIES
    PASS_REGULAR_EXPRESSION
    "ERROR: Number of input channels")

  # Does it fail elegently when too few target images are specified?
  add_test(
    EMSegCL_EFTooFewImages
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --dontWriteResults --mrmlSceneFileName 
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TUTORIAL_DIR}/VolumeData/targetT1Normed_small.mhd
    )
  set_tests_properties(
    EMSegCL_EFTooFewImages
    PROPERTIES
    PASS_REGULAR_EXPRESSION
    "ERROR: Number of input channels")

  # Does the option --intermediateResultsDirectory work?
  add_test(
    EMSegCL_IntermediateResults
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TUTORIAL_DIR}/VolumeData/targetT1Normed_small.mhd,${EMSegment_TUTORIAL_DIR}/VolumeData/targetT2Normed_small.mhd
    --resultVolumeFileName
    ${Slicer3_BINARY_DIR}/Testing/Temporary/EMSegCL_IntermediateResults_FinalResult.nrrd
    --intermediateResultsDirectory
    ${Slicer3_BINARY_DIR}/Testing/Temporary/EMSegCL_IntermediateResults_FinalResultsFolder
    )
  set_tests_properties(
    EMSegCL_IntermediateResults
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR;Error writing intermediate results"
    )


  # Task test - small
  add_test(
    EMSegCL_TaskMRIHumanBrain_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrain_T1_aligned.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskMRIHumanBrain_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(EMSegCL_TaskMRIHumanBrain_smallCompareTest ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
             ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrain_T1_aligned.nrrd
                               MIDAS{RESULT_small_MRIHumanBrain_T1_aligned.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)


  # Task test - very small
  add_test(
    EMSegCL_TaskMRIHumanBrain_very_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain_very_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/very_small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_very_small_MRIHumanBrain_T1_aligned.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskMRIHumanBrain_very_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(NAME EMSegCL_TaskMRIHumanBrain_very_smallCompareTest
                   COMMAND ${Slicer3_EXE} --launch vtkCompareDriverTest --no-error-popup
                   ${EMSegment_BINARY_DIR}/RESULT_very_small_MRIHumanBrain_T1_aligned.nrrd
                                     MIDAS{RESULT_very_small_MRIHumanBrain_T1_aligned.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)


  # Task test - small
  add_test(
    EMSegCL_TaskMRIHumanBrainParcellation_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Parcellation_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Parcellation/small_MRIHumanBrainParcellation_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrainParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskMRIHumanBrainParcellation_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(EMSegCL_TaskMRIHumanBrainParcellation_smallCompareTest ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
             ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrainParcellation_T1.nrrd
                               MIDAS{RESULT_small_MRIHumanBrainParcellation_T1.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)
    
    

  # Task test - very small
  add_test(
    EMSegCL_TaskMRIHumanBrainParcellation_very_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Parcellation_very_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Parcellation/very_small_MRIHumanBrainParcellation_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_very_small_MRIHumanBrainParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskMRIHumanBrainParcellation_very_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(EMSegCL_TaskMRIHumanBrainParcellation_very_smallCompareTest ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
             ${EMSegment_BINARY_DIR}/RESULT_very_small_MRIHumanBrainParcellation_T1.nrrd
                               MIDAS{RESULT_very_small_MRIHumanBrainParcellation_T1.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)


  # Task test - small
  add_test(
    EMSegCL_TaskMRIHumanBrainFullParcellation_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Full-Parcellation_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrainFullParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskMRIHumanBrainFullParcellation_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(EMSegCL_TaskMRIHumanBrainFullParcellation_smallCompareTest ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
             ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrainFullParcellation_T1.nrrd
                               MIDAS{RESULT_small_MRIHumanBrainFullParcellation_T1.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)

    

  # Task test - very small
  add_test(
    EMSegCL_TaskMRIHumanBrainFullParcellation_very_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Full-Parcellation_very_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/very_small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_very_small_MRIHumanBrainFullParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskMRIHumanBrainFullParcellation_very_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(EMSegCL_TaskMRIHumanBrainFullParcellation_very_smallCompareTest ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
             ${EMSegment_BINARY_DIR}/RESULT_very_small_MRIHumanBrainFullParcellation_T1.nrrd
                               MIDAS{RESULT_very_small_MRIHumanBrainFullParcellation_T1.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)


  # Task test - small
  add_test(
    EMSegCL_TaskNonHumanPrimate_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/Non-Human-Primate_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/Non-Human-Primate/Unbiased/small_NonHumanPrimate_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_NonHumanPrimate_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskNonHumanPrimate_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(NAME EMSegCL_TaskNonHumanPrimate_smallCompareTest
                   COMMAND ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
                   ${EMSegment_BINARY_DIR}/RESULT_small_NonHumanPrimate_T1.nrrd
                                     MIDAS{RESULT_small_NonHumanPrimate_T1.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)
    

  # Task test - very small
  add_test(
    EMSegCL_TaskNonHumanPrimate_very_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/Non-Human-Primate_very_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/Non-Human-Primate/Unbiased/very_small_NonHumanPrimate_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_very_small_NonHumanPrimate_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_TaskNonHumanPrimate_very_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
  if(EMSEG_RUN_COMPARE_TESTS)
    midas_add_test(EMSegCL_TaskNonHumanPrimate_very_smallCompareTest ${Slicer3_EXE} --launch vtkEMSegmentCompareTest --no-error-popup
             ${EMSegment_BINARY_DIR}/RESULT_very_small_NonHumanPrimate_T1.nrrd
                               MIDAS{RESULT_very_small_NonHumanPrimate_T1.nrrd.md5}
    )
  endif(EMSEG_RUN_COMPARE_TESTS)


#====CMTK============================

  # Task test - small
  add_test(
    EMSegCL_Task_CMTK_MRIHumanBrain_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/CMTK_MRI-Human-Brain_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_CMTK_small_MRIHumanBrain_T1_aligned.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_CMTK_MRIHumanBrain_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )



  # Task test - small
  add_test(
    EMSegCL_Task_CMTK_MRIHumanBrainParcellation_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/CMTK_MRI-Human-Brain-Parcellation_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Parcellation/small_MRIHumanBrainParcellation_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrainParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_CMTK_MRIHumanBrainParcellation_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )

  # Task test - small
  add_test(
    EMSegCL_Task_CMTK_MRIHumanBrainFullParcellation_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/CMTK_MRI-Human-Brain-Full-Parcellation_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_MRIHumanBrainFullParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_CMTK_MRIHumanBrainFullParcellation_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )

  # Task test - small
  add_test(
    EMSegCL_Task_CMTK_NonHumanPrimate_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/CMTK_Non-Human-Primate_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/Non-Human-Primate/Unbiased/small_NonHumanPrimate_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_small_NonHumanPrimate_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_CMTK_NonHumanPrimate_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
#==================================

#====BRAINS============================

  # Task test - small
  add_test(
    EMSegCL_Task_BRAINS_MRIHumanBrain_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/BRAINS_MRI-Human-Brain_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_BRAINS_small_MRIHumanBrain_T1_aligned.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_BRAINS_MRIHumanBrain_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )



  # Task test - small
  add_test(
    EMSegCL_Task_BRAINS_MRIHumanBrainParcellation_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/BRAINS_MRI-Human-Brain-Parcellation_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain-Parcellation/small_MRIHumanBrainParcellation_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_BRAINS_small_MRIHumanBrainParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_BRAINS_MRIHumanBrainParcellation_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )

  # Task test - small
  add_test(
    EMSegCL_Task_BRAINS_MRIHumanBrainFullParcellation_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/BRAINS_MRI-Human-Brain-Full-Parcellation_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/MRI-Human-Brain/small_MRIHumanBrain_T1_aligned.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_BRAINS_small_MRIHumanBrainFullParcellation_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_BRAINS_MRIHumanBrainFullParcellation_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )

  # Task test - small
  add_test(
    EMSegCL_Task_BRAINS_NonHumanPrimate_small
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --mrmlSceneFileName
    ${EMSegment_TESTDATA_DIR}/BRAINS_Non-Human-Primate_small.mrml
    --targetVolumeFileNames
    ${EMSegment_TESTDATA_DIR}/Non-Human-Primate/Unbiased/small_NonHumanPrimate_T1.nrrd
    --resultVolumeFileName
    ${EMSegment_BINARY_DIR}/RESULT_BRAINS_small_NonHumanPrimate_T1.nrrd
    )
  set_tests_properties(
    EMSegCL_Task_BRAINS_NonHumanPrimate_small
    PROPERTIES
    FAIL_REGULAR_EXPRESSION
    "ERROR"
    )
#==================================



  # Does it fail elegently when a bogus result standard is specified?
  add_test(
    EMSegCL_EFBogusResultStandardImage
    ${Slicer3_EXE} ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
    --no-error-popup
    --verbose --dontWriteResults --mrmlSceneFileName 
    ${EMSegment_TUTORIAL_DIR}/Template_small.mrml
    --resultStandardVolumeFileName
    ${EMSegment_TEST_DIR}/bogus_file.mhd
    )
  set_tests_properties(
    EMSegCL_EFBogusResultStandardImage
    PROPERTIES
    PASS_REGULAR_EXPRESSION 
    "Error: result standard volume file does not exist")

  if(EMSEG_RUN_EXTRA_LONG_TESTS)
    # run tutorial data
    set(test_name        "EMSegCL_RunTutorialData")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.raw")
    set(test_std_file    "${EMSegment_TUTORIAL_DIR}/StandardData/StandardSegmentationResult.raw")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mhd ${test_file_prefix}.raw)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args 
      ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
      --verbose 
      --mrmlSceneFileName ${EMSegment_TUTORIAL_DIR}/Template_large.mrml 
      --resultVolumeFileName "${test_file_prefix}.mhd"
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )
  endif(EMSEG_RUN_EXTRA_LONG_TESTS)

  ############################################################################
  #
  # MRML---do the logic readers and writers work?
  #
  ############################################################################

  #
  # these tests break every time MRML is modified.  disable them for now.
  #

  if(EMSEG_RUN_EXTRA_SHORT_TESTS)
    # Make sure the default parameter set has not changed
    set(test_name        "EMSegMRML_DiffDefaultNodes")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.mrml")
    set(test_std_file    "${EMSegment_SOURCE_DIR}/Testing/TestData/DefaultMRMLNodes.mrml")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mrml)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args 
      ${WRAPPED_EXE_PREFIX}/EMSegmentCommandLine
      --verbose --generateEmptyMRMLSceneAndQuit ${test_cmp_file}
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )
    
    # Test that the mrml readers/writers work.
    set(test_name        "EMSegMRML_DiffReadWriteNodes")
    set(test_exe         "${Slicer3_EXE}")
    set(test_file_prefix "${EMSegment_TEST_DIR}/${test_name}_tmp")
    set(test_cmp_file    "${test_file_prefix}.mrml")
    set(test_std_file    "${EMSegment_TUTORIAL_DIR}/Template_small_normalizationOn_noImages.mrml")
    if(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files    ${test_file_prefix}.mrml)
    else(${EMSEG_REMOVE_TMP_TEST_DATA})
      set(test_rm_files)
    endif(${EMSEG_REMOVE_TMP_TEST_DATA})
    set(test_args 
      ${WRAPPED_EXE_PREFIX}/vtkEMSegmentReadWriteMRMLTest
      ${test_std_file} ${test_cmp_file}
      )
    add_test(
      ${test_name} ${CMAKE_COMMAND} -V -VV "-Dtest_name:STRING=${test_name}"
      "-Dtest_exe:STRING=${test_exe}"      "-Dtest_exe_args:STRING=${test_args}"
      "-Dfile_cmp:STRING=${test_cmp_file}" "-Dfile_std:STRING=${test_std_file}"
      "-Drm_files:STRING=${test_rm_files}"
      -P "${EMSegment_SOURCE_DIR}/Testing/RunDiffRemoveTest.cmake"
      )
  endif(EMSEG_RUN_EXTRA_SHORT_TESTS)

  ############################################################################
  #
  # Valgrind tests---are there memory leaks?
  #
  ############################################################################

  if(EMSEG_RUN_VALGRIND_TESTS)
    add_test(
      EMSegMRML_ValgrindTest
      valgrind --leak-check=full 
      ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/EMSegmentCommandLine
      --verbose 
      --mrmlSceneFileName 
      ${EMSegment_TUTORIAL_DIR}/Template_small_normalizationOn.mrml
      --dontWriteResults
      )
  endif(EMSEG_RUN_VALGRIND_TESTS)

  if(EMSEG_RUN_EXTRA_SHORT_TESTS)
    
  endif(EMSEG_RUN_EXTRA_SHORT_TESTS)

endif(NOT DISABLE_CXX_TESTING)



# Are we able to download our update file ?
add_test(
  RemoteIOTest
  ${Slicer3_EXE} ${WRAPPED_TEST_EXE_PREFIX}/vtkEMSegmentRemoteIOTest
  http://slicer.org/EMSegmentUpdates/
  ${Slicer3_BINARY_DIR}/Testing/Temporary/EMSegmenterUpdates
)

