CMake: Add tests

pull/184/head
Gregor Jasny 7 years ago
parent 1997b142a8
commit a915d0adc6
  1. 5
      CMakeLists.txt
  2. 62
      test/CMakeLists.txt

@ -29,6 +29,7 @@ OPTION (CARES_STATIC "Build as a static library"
OPTION (CARES_SHARED "Build as a shared library" ON)
OPTION (CARES_INSTALL "Create installation targets (chain builders may want to disable this)" ON)
OPTION (CARES_STATIC_PIC "Build the static library as PIC (position independent)" OFF)
OPTION (CARES_BUILD_TESTS "Build and run tests" OFF)
# allow linking against the static runtime library in msvc
IF (MSVC)
@ -626,6 +627,10 @@ IF (CARES_STATIC)
ENDIF ()
ENDIF ()
IF (CARES_WITH_TESTS)
ENABLE_TESTING ()
ADD_SUBDIRECTORY (test)
ENDIF ()
# Headers installation target
IF (CARES_INSTALL)

@ -0,0 +1,62 @@
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)
enable_language(CXX)
find_package(Threads)
# create target to access and use internal cares library
set(ARES_SRC_DIR ${c-ares_SOURCE_DIR})
add_library(caresinternal INTERFACE)
target_compile_definitions(caresinternal INTERFACE HAVE_CONFIG_H=1)
target_include_directories(caresinternal INTERFACE ${ARES_SRC_DIR})
target_link_libraries(caresinternal INTERFACE ${PROJECT_NAME})
# Google Test and Mock
set(GMOCK_DIR gmock-1.8.0)
add_library(gmock STATIC
${GMOCK_DIR}/gmock-gtest-all.cc
${GMOCK_DIR}/gmock/gmock.h
${GMOCK_DIR}/gtest/gtest.h
)
target_include_directories(gmock PUBLIC SYSTEM ${GMOCK_DIR})
target_link_libraries(gmock PRIVATE ${CMAKE_THREAD_LIBS_INIT})
# test targets
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
configure_file(${ARES_SRC_DIR}/ares_config.h.cmake config.h)
add_executable(arestest ${TESTSOURCES} ${TESTHEADERS})
target_include_directories(arestest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(arestest PRIVATE caresinternal gmock)
add_executable(aresfuzz ${FUZZSOURCES})
target_link_libraries(aresfuzz PRIVATE caresinternal)
add_executable(aresfuzzname ${FUZZNAMESOURCES})
target_link_libraries(aresfuzzname PRIVATE caresinternal)
add_executable(dnsdump ${DUMPSOURCES})
target_link_libraries(dnsdump PRIVATE caresinternal)
# register tests
add_test(NAME arestest COMMAND $<TARGET_FILE:arestest>)
file(GLOB_RECURSE FUZZINPUT_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/fuzzinput" "fuzzinput/*")
add_test(
NAME aresfuzz
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fuzzinput"
COMMAND $<TARGET_FILE:aresfuzz> ${FUZZINPUT_FILES}
)
file(GLOB_RECURSE FUZZNAMES_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/fuzznames" "fuzznames/*")
add_test(
NAME aresfuzzname
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fuzznames"
COMMAND $<TARGET_FILE:aresfuzzname> ${FUZZNAMES_FILES}
)
Loading…
Cancel
Save