77 lines
2.4 KiB
CMake
77 lines
2.4 KiB
CMake
if (NOT BUILD_TESTING)
|
|
message("-- libdipp tests disabled")
|
|
return()
|
|
endif()
|
|
message("-- libdipp tests enabled")
|
|
|
|
# redis-server configuration used for testing
|
|
set(REDIS_PORT 56379)
|
|
set(REDIS_SERVER "redis-server")
|
|
set(REDIS_PIDFILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-test.pid)
|
|
set(REDIS_TEST_CONFIG
|
|
"# redis-server configuration generated by CMake
|
|
daemonize yes
|
|
port ${REDIS_PORT}
|
|
bind 127.0.0.1
|
|
pidfile ${REDIS_PIDFILE}
|
|
notify-keyspace-events \"Kh\"
|
|
databases 2"
|
|
)
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/redis.conf ${REDIS_TEST_CONFIG})
|
|
|
|
set(TESTS
|
|
application
|
|
configuration
|
|
debug
|
|
json
|
|
jsondiff
|
|
mailbox
|
|
redis
|
|
tcpclient
|
|
time
|
|
timer
|
|
semaphore
|
|
requesthandler
|
|
rpc/reader
|
|
rpc/classes
|
|
rpc/classes_project
|
|
rpc/classes_sensor
|
|
rpc/msg
|
|
translation
|
|
)
|
|
|
|
include("${DI_COMMON_CMAKE_DIR}/libs/gtest.txt")
|
|
|
|
configure_file("CTestCustom.cmake.in" "${CMAKE_BINARY_DIR}/CTestCustom.cmake" @ONLY)
|
|
|
|
find_package(Threads REQUIRED)
|
|
find_package(Jansson REQUIRED)
|
|
find_package(Hiredis REQUIRED)
|
|
|
|
set(gtest_xml_dir "${CMAKE_CURRENT_BINARY_DIR}/gtest")
|
|
file(MAKE_DIRECTORY ${gtest_xml_dir})
|
|
|
|
foreach(test ${TESTS})
|
|
string(REPLACE "/" "_" target ${test})
|
|
set(test_args "--gtest_output=xml:${gtest_xml_dir}/${target}.xml")
|
|
|
|
add_executable(${target} ${test}.cpp)
|
|
set_source_files_properties("${test}.cpp" PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast -Wno-deprecated-declarations")
|
|
add_dependencies(${target} dipp gtest)
|
|
target_link_libraries(${target} dipp ${gtest_library} ${gtest_main_library} ${CMAKE_THREAD_LIBS_INIT} ${JANSSON_LIBRARIES} ${HIREDIS_LIBRARIES} zmq)
|
|
add_test(NAME "${target}" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${target}" "${test_args}")
|
|
set_tests_properties("${target}" PROPERTIES TIMEOUT 30)
|
|
set_property(TEST "${target}" PROPERTY ENVIRONMENT "TESTNAME=${target}")
|
|
endforeach()
|
|
set_source_files_properties("application.cpp" PROPERTIES COMPILE_FLAGS -Wno-write-strings)
|
|
|
|
###
|
|
# LaTeX test report
|
|
###
|
|
set(test_reportdir "${CMAKE_CURRENT_BINARY_DIR}/report")
|
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/report" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
configure_file("${test_reportdir}/libdipp-test-report.tex.in" "${test_reportdir}/libdipp-test-report.tex")
|
|
|
|
add_custom_target(test-report COMMAND "${CMAKE_SOURCE_DIR}/common/gtest-report/gtest-report.py" "'${gtest_xml_dir}/*.xml'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
add_custom_target(test-report-pdf COMMAND "make" WORKING_DIRECTORY ${test_reportdir})
|