From 17f592d4dd25eae98b1a8378625adc454976fcb6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 28 Dec 2010 13:41:33 +0100 Subject: tests: Start to migrate tests to cmockery. https://code.google.com/p/cmockery/wiki/Cmockery_Unit_Testing_Framework --- CMakeLists.txt | 4 +-- cmake/Modules/AddCMockeryTest.cmake | 21 +++++++++++ cmake/Modules/AddCheckTest.cmake | 22 ------------ cmake/Modules/FindCMockery.cmake | 59 ++++++++++++++++++++++++++++++ cmake/Modules/FindCheck.cmake | 72 ------------------------------------- tests/CMakeLists.txt | 9 ++--- tests/client/CMakeLists.txt | 6 ++-- tests/unittests/CMakeLists.txt | 18 +++++----- 8 files changed, 96 insertions(+), 115 deletions(-) create mode 100644 cmake/Modules/AddCMockeryTest.cmake delete mode 100644 cmake/Modules/AddCheckTest.cmake create mode 100644 cmake/Modules/FindCMockery.cmake delete mode 100644 cmake/Modules/FindCheck.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 86e80ee0..a96eec81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux") endif (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (WITH_TESTING) - find_package(Check REQUIRED) - include(AddCheckTest) + find_package(CMockery REQUIRED) + include(AddCMockeryTest) add_subdirectory(tests) endif (WITH_TESTING) diff --git a/cmake/Modules/AddCMockeryTest.cmake b/cmake/Modules/AddCMockeryTest.cmake new file mode 100644 index 00000000..ad086110 --- /dev/null +++ b/cmake/Modules/AddCMockeryTest.cmake @@ -0,0 +1,21 @@ +# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN) + +# Copyright (c) 2007 Daniel Gollub +# Copyright (c) 2007-2010 Andreas Schneider +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +enable_testing() +include(CTest) + +set(CMAKE_C_FLAGS_PROFILING "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Compiler Flags") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags") +set(CMAKE_MODULE_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags") +set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags") + +function (ADD_CMOCKERY_TEST _testName _testSource) + add_executable(${_testName} ${_testSource}) + target_link_libraries(${_testName} ${ARGN}) + add_test(${_testName} ${CMAKE_CURRENT_BINARY_DIR}/${_testName}) +endfunction (ADD_CMOCKERY_TEST) diff --git a/cmake/Modules/AddCheckTest.cmake b/cmake/Modules/AddCheckTest.cmake deleted file mode 100644 index 089a09c2..00000000 --- a/cmake/Modules/AddCheckTest.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN) - -# Copyright (c) 2007, Daniel Gollub, -# Copyright (c) 2007, Andreas Schneider, -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -enable_testing() -include(CTest) - -set(CMAKE_C_FLAGS_PROFILING "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Compiler Flags") -set(CMAKE_SHARED_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags") -set(CMAKE_MODULE_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags") -set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags") - -function (ADD_CHECK_TEST _testName _testSource) - add_executable(${_testName} ${_testSource}) - target_link_libraries(${_testName} ${ARGN}) - add_test(${_testName} ${CMAKE_CURRENT_BINARY_DIR}/${_testName}) -endfunction (ADD_CHECK_TEST) - diff --git a/cmake/Modules/FindCMockery.cmake b/cmake/Modules/FindCMockery.cmake new file mode 100644 index 00000000..9ecde23e --- /dev/null +++ b/cmake/Modules/FindCMockery.cmake @@ -0,0 +1,59 @@ +# - Try to find CMockery +# Once done this will define +# +# CMOCKERY_FOUND - system has CMockery +# CMOCKERY_INCLUDE_DIRS - the CMockery include directory +# CMOCKERY_LIBRARIES - Link these to use CMockery +# CMOCKERY_DEFINITIONS - Compiler switches required for using CMockery +# +# Copyright (c) 2010 Andreas Schneider +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (CMOCKERY_LIBRARIES AND CMOCKERY_INCLUDE_DIRS) + # in cache already + set(CMOCKERY_FOUND TRUE) +else (CMOCKERY_LIBRARIES AND CMOCKERY_INCLUDE_DIRS) + + find_path(CMOCKERY_INCLUDE_DIR + NAMES + google/cmockery.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + find_library(CMOCKERY_LIBRARY + NAMES + cmockery + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(CMOCKERY_INCLUDE_DIRS + ${CMOCKERY_INCLUDE_DIR} + ) + + if (CMOCKERY_LIBRARY) + set(CMOCKERY_LIBRARIES + ${CMOCKERY_LIBRARIES} + ${CMOCKERY_LIBRARY} + ) + endif (CMOCKERY_LIBRARY) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(CMockery DEFAULT_MSG CMOCKERY_LIBRARIES CMOCKERY_INCLUDE_DIRS) + + # show the CMOCKERY_INCLUDE_DIRS and CMOCKERY_LIBRARIES variables only in the advanced view + mark_as_advanced(CMOCKERY_INCLUDE_DIRS CMOCKERY_LIBRARIES) + +endif (CMOCKERY_LIBRARIES AND CMOCKERY_INCLUDE_DIRS) diff --git a/cmake/Modules/FindCheck.cmake b/cmake/Modules/FindCheck.cmake deleted file mode 100644 index 5ab746a9..00000000 --- a/cmake/Modules/FindCheck.cmake +++ /dev/null @@ -1,72 +0,0 @@ -# - Try to find Check -# Once done this will define -# -# CHECK_FOUND - system has Check -# CHECK_INCLUDE_DIRS - the Check include directory -# CHECK_LIBRARIES - Link these to use Check -# CHECK_DEFINITIONS - Compiler switches required for using Check -# -# Copyright (c) 2010 Andreas Schneider -# -# Redistribution and use is allowed according to the terms of the New -# BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# - - -if (CHECK_LIBRARIES AND CHECK_INCLUDE_DIRS) - # in cache already - set(CHECK_FOUND TRUE) -else (CHECK_LIBRARIES AND CHECK_INCLUDE_DIRS) - find_package(PkgConfig) - if (PKG_CONFIG_FOUND) - pkg_check_modules(_CHECK check) - endif (PKG_CONFIG_FOUND) - - find_path(CHECK_INCLUDE_DIR - NAMES - check.h - PATHS - ${_CHECK_INCLUDEDIR} - /usr/include - /usr/local/include - /opt/local/include - /sw/include - /usr/lib/sfw/include - ) - - # check_pic is a workaround for ubuntu's check bug which does not compile - # check as a shared library with -fPIC. - # see https://bugs.launchpad.net/ubuntu/+source/check/+bug/125781 - find_library(CHECK_LIBRARY - NAMES - check_pic check - PATHS - ${_CHECK_LIBDIR} - /usr/lib - /usr/local/lib - /opt/local/lib - /sw/lib - /usr/sfw/lib/64 - /usr/sfw/lib - ) - - set(CHECK_INCLUDE_DIRS - ${CHECK_INCLUDE_DIR} - ) - - if (CHECK_LIBRARY) - set(CHECK_LIBRARIES - ${CHECK_LIBRARIES} - ${CHECK_LIBRARY} - ) - endif (CHECK_LIBRARY) - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Check DEFAULT_MSG CHECK_LIBRARIES CHECK_INCLUDE_DIRS) - - # show the CHECK_INCLUDE_DIRS and CHECK_LIBRARIES variables only in the advanced view - mark_as_advanced(CHECK_INCLUDE_DIRS CHECK_LIBRARIES) - -endif (CHECK_LIBRARIES AND CHECK_INCLUDE_DIRS) - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index da1fb412..42a377b6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,5 @@ project(tests C) -if (UNIX AND NOT LINUX) - find_package(Argp) -endif (UNIX AND NOT LINUX) - set(TORTURE_LIBRARY torture) include_directories( @@ -16,14 +12,13 @@ include_directories( ) # create test library -add_library(${TORTURE_LIBRARY} SHARED torture.c cmdline.c) +add_library(${TORTURE_LIBRARY} SHARED torture.c) target_link_libraries(${TORTURE_LIBRARY} - ${CHECK_LIBRARIES} + ${CMOCKERY_LIBRARY} ${LIBSSH_STATIC_LIBRARY} ${LIBSSH_LINK_LIBRARIES} ${LIBSSH_THREADS_STATIC_LIBRARY} ${LIBSSH_THREADS_LINK_LIBRARIES} - ${ARGP_LIBRARIES} ) set(TEST_TARGET_LIBRARIES ${SUPPORT_LIBRARY} ${LIBSSH_LINK_LIBRARIES}) diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index 11633863..6c63aecd 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -1,5 +1,5 @@ project(clienttests C) -add_check_test(torture_algorithms torture_algorithms.c ${TORTURE_LIBRARY}) -add_check_test(torture_auth torture_auth.c ${TORTURE_LIBRARY}) -add_check_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY}) +#add_check_test(torture_algorithms torture_algorithms.c ${TORTURE_LIBRARY}) +#add_check_test(torture_auth torture_auth.c ${TORTURE_LIBRARY}) +#add_check_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY}) diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index 52efbc52..2386c45e 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -1,11 +1,11 @@ project(unittests C) -add_check_test(torture_buffer torture_buffer.c ${TORTURE_LIBRARY}) -add_check_test(torture_callbacks torture_callbacks.c ${TORTURE_LIBRARY}) -add_check_test(torture_init torture_init.c ${TORTURE_LIBRARY}) -add_check_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY}) -add_check_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY}) -add_check_test(torture_list torture_list.c ${TORTURE_LIBRARY}) -add_check_test(torture_misc torture_misc.c ${TORTURE_LIBRARY}) -add_check_test(torture_options torture_options.c ${TORTURE_LIBRARY}) -add_check_test(torture_rand torture_rand.c ${TORTURE_LIBRARY}) +#add_check_test(torture_buffer torture_buffer.c ${TORTURE_LIBRARY}) +#add_check_test(torture_callbacks torture_callbacks.c ${TORTURE_LIBRARY}) +#add_check_test(torture_init torture_init.c ${TORTURE_LIBRARY}) +#add_check_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY}) +#add_check_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY}) +#add_check_test(torture_list torture_list.c ${TORTURE_LIBRARY}) +#add_check_test(torture_misc torture_misc.c ${TORTURE_LIBRARY}) +#add_check_test(torture_options torture_options.c ${TORTURE_LIBRARY}) +#add_check_test(torture_rand torture_rand.c ${TORTURE_LIBRARY}) -- cgit v1.2.3