function(castemptest test_arg)
  set(_CMD)
  set(_NO_XML_OUTPUT )
  set(_WILL_FAIL )
  set(_REFERENCE_FILE)
  foreach(_ARG ${ARGN})
    if ( ${_ARG} MATCHES NO_XML_OUTPUT )
      set ( _NO_XML_OUTPUT ON)
    elseif ( ${_ARG} MATCHES WILL_FAIL)
      set ( _WILL_FAIL ON)
    else()
      message(FATAL_ERROR "castemptest: unsupported option '${_ARG}'")
    endif()
  endforeach(_ARG ${ARGN})
  set(_mtest_args)
  list(APPEND _mtest_args --verbose=level0)
  list(APPEND _mtest_args  --result-file-output=false)
  list(APPEND _mtest_args  --@library@="$<TARGET_FILE:MFrontCastemBehaviours>")
  list(APPEND _mtest_args  --@top_srcdir@=${PROJECT_SOURCE_DIR})
  if(_NO_XML_OUTPUT)
    list(APPEND _mtest_args --xml-output=false)
  else(_NO_XML_OUTPUT)
    list(APPEND _mtest_args --xml-output=true)
  endif(_NO_XML_OUTPUT)
  set(_test_file ${CMAKE_CURRENT_SOURCE_DIR}/castem${test_arg}.ptest)
  add_test(NAME castem${test_arg}_ptest
   	  COMMAND mtest ${_mtest_args} ${_test_file})
  if(_WILL_FAIL)
    set_tests_properties(castem${test_arg}_ptest PROPERTIES WILL_FAIL true)
  endif(_WILL_FAIL)
  if(TFEL_APPEND_SUFFIX)
    install(FILES ${_test_file}
    DESTINATION "share/doc/mtest-${TFEL_SUFFIX}/tests/ptest/behaviours/castem"
    COMPONENT mtest)
  else(TFEL_APPEND_SUFFIX)
    install(FILES ${_test_file}
    DESTINATION "share/doc/mtest/tests/ptest/behaviours/castem"
    COMPONENT mtest)
  endif(TFEL_APPEND_SUFFIX)
endfunction(castemptest)

castemptest(elasticity-linear)
castemptest(elasticity-imposedinnerradius-linear)
castemptest(elasticity-imposedmandrelradius-linear)
castemptest(elasticity-quadratic)
castemptest(isotropic-elastic-linear)
castemptest(isotropic-elastic-quadratic)
castemptest(isotropic-elastic2-linear)
castemptest(isotropic-elastic2-quadratic)
castemptest(isotropic-thermoelastic-linear)
castemptest(isotropic-thermoelastic-quadratic)
#castemptest(nortonpipe1D-linear)
#castemptest(nortonpipe1D-quadratic)
#castemptest(norton2pipe1D-linear)
#castemptest(norton2pipe1D-quadratic)
castemptest(orthotropic-elastic-linear)
castemptest(orthotropic-elastic-quadratic)
castemptest(orthotropic-elastic2-linear)
castemptest(orthotropic-elastic2-quadratic)
castemptest(orthotropic-thermoelastic-linear)
castemptest(orthotropic-thermoelastic-quadratic)
castemptest(orthotropic-thermoelastic2-linear)
castemptest(orthotropic-thermoelastic2-quadratic)
castemptest(tightpipe-linear)
castemptest(tightpipe-quadratic)
castemptest(tightpipe-gd-linear)
castemptest(tightpipe-gd-quadratic)
