# To avoid Ninja complaints
add_library(lib-handlers OBJECT m_handlers.f90)
target_link_libraries(lib-handlers
  "${PROJECT_NAME}-lib"
)

add_executable(xmlf90-sax-features
  example.F90
)
target_link_libraries(xmlf90-sax-features
  PRIVATE
  "${PROJECT_NAME}-lib"
  lib-handlers
)

add_executable(xmlcheck  xmlcheck.f90)
target_link_libraries(xmlcheck
  PRIVATE
  "${PROJECT_NAME}-lib"
  lib-handlers
)

add_executable(xmlcheck_stat  xmlcheck_stat.f90)
target_link_libraries(xmlcheck_stat
  PRIVATE
  "${PROJECT_NAME}-lib"
  lib-handlers
)

file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests")
file(COPY test.xml DESTINATION "${PROJECT_BINARY_DIR}/install_tests")
file(COPY malformed.xml DESTINATION "${PROJECT_BINARY_DIR}/install_tests")
file(COPY bad_entity.xml DESTINATION "${PROJECT_BINARY_DIR}/install_tests")

#--
add_test(  NAME    XMLF90_SAX_Features
           COMMAND $<TARGET_FILE:xmlf90-sax-features>
	   WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests"
	)

set_property (TEST XMLF90_SAX_Features
              PROPERTY PASS_REGULAR_EXPRESSION "Mary had a <little> lamb")
set_property (TEST XMLF90_SAX_Features
              PROPERTY FAIL_REGULAR_EXPRESSION "Cannot open file")

#--
add_test(  NAME    XMLF90_SAX_check
           COMMAND $<TARGET_FILE:xmlcheck> test.xml
	   WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests"
	)
set_property (TEST XMLF90_SAX_check
              PROPERTY PASS_REGULAR_EXPRESSION "Characters processed")
	
#--
add_test(  NAME    XMLF90_SAX_check_stat
           COMMAND $<TARGET_FILE:xmlcheck_stat> test.xml
	   WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests"
	)
set_property (TEST XMLF90_SAX_check_stat
              PROPERTY PASS_REGULAR_EXPRESSION "Characters processed")
	

#--
add_test(  NAME    XMLF90_SAX_Malformed
           COMMAND $<TARGET_FILE:xmlcheck> malformed.xml
	   WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests"
	)

set_property (TEST XMLF90_SAX_Malformed
              PROPERTY PASS_REGULAR_EXPRESSION "outside of element")

#--
add_test(  NAME    XMLF90_SAX_Malformed_stat
           COMMAND $<TARGET_FILE:xmlcheck_stat> malformed.xml
	   WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests"
	)

set_property (TEST XMLF90_SAX_Malformed_stat
              PROPERTY PASS_REGULAR_EXPRESSION "Parsing error")

#--
add_test(  NAME    XMLF90_SAX_BadEntity
           COMMAND $<TARGET_FILE:xmlcheck_stat> bad_entity.xml
	   WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/install_tests"
	)

set_property (TEST XMLF90_SAX_BadEntity
              PROPERTY PASS_REGULAR_EXPRESSION "Parsing error")
