diff options
author | JinWang An <jinwang.an@samsung.com> | 2022-12-27 12:02:23 +0900 |
---|---|---|
committer | JinWang An <jinwang.an@samsung.com> | 2022-12-27 12:02:23 +0900 |
commit | 2a04bf5fdf7719f8ed087ac0feeb4309e0784ee1 (patch) | |
tree | e64de45ec54faa6bb12b3d9550b48ba6b18b8e49 | |
parent | 01e83079bffa26492ad137416b8b5e330f970e6b (diff) | |
download | cmocka-2a04bf5fdf7719f8ed087ac0feeb4309e0784ee1.tar.gz cmocka-2a04bf5fdf7719f8ed087ac0feeb4309e0784ee1.tar.bz2 cmocka-2a04bf5fdf7719f8ed087ac0feeb4309e0784ee1.zip |
Imported Upstream version 1.1.3cmocka-1.1.3
52 files changed, 828 insertions, 2686 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..75f3859 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,297 @@ +variables: + BUILD_IMAGES_PROJECT: cmocka/gitlab-build-images + FEDORA_BUILD: buildenv-fedora + CENTOS7_BUILD: buildenv-centos7 + TUMBLEWEED_BUILD: buildenv-tumbleweed + MINGW_BUILD: buildenv-mingw + DEBIAN_CROSS_BUILD: buildenv-debian-cross + +centos7/x86_64: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD + script: + - mkdir -p obj && cd obj && cmake3 + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/x86_64: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/address-sanitizer: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=AddressSanitizer + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/undefined-sanitizer: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=UndefinedSanitizer + -DUNIT_TESTING=ON .. + && make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +freebsd/x86_64: + image: + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make && ctest --output-on-failure + tags: + - freebsd + except: + - tags + only: + - branches@cmocka/cmocka + - branches@cryptomilk/cmocka + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/mingw64: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$MINGW_BUILD + script: + - export WINEPATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin + - export WINEDEBUG=-all + - mkdir -p obj && cd obj && mingw64-cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && + ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/mingw32: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$MINGW_BUILD + script: + - export WINEPATH=/usr/i686-w64-mingw32/sys-root/mingw/bin + - export WINEDEBUG=-all + - mkdir -p obj && cd obj && mingw32-cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DWITH_SFTP=ON -DWITH_SERVER=ON -DWITH_ZLIB=ON --DWITH_PCAP=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && + ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +.Debian.cross.template: &Debian_cross_template + stage: test + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_CROSS_BUILD + script: + - build=$(dpkg-architecture -qDEB_HOST_GNU_TYPE) + - host="${CI_JOB_NAME#*.cross.}" + - mkdir -p obj && cd obj && cmake + -DCMAKE_C_COMPILER="$(which $host-gcc)" + -DCMAKE_CXX_COMPILER="$(which $host-g++)" + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DUNIT_TESTING=ON .. && make -j$(nproc) + - ctest --output-on-failure -j$(nproc) + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +Debian.cross.mips-linux-gnu: + <<: *Debian_cross_template + +tumbleweed/x86_64/gcc: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/x86/gcc: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/x86_64/gcc7: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/x86/gcc7: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake + -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/x86_64/clang: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/docs: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake .. && make docs + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/static-analysis: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - export CCC_CC=clang + - export CCC_CXX=clang++ + - mkdir -p obj && cd obj && scan-build cmake + -DCMAKE_BUILD_TYPE=Debug + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + scan-build --status-bugs -o scan make -j$(nproc) + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/scan diff --git a/CMakeLists.txt b/CMakeLists.txt index d707ab5..88408a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,24 @@ -project(cmocka C) - # Required cmake version -cmake_minimum_required(VERSION 3.3.0) +cmake_minimum_required(VERSION 3.5.0) +cmake_policy(SET CMP0048 NEW) -# global needed variables -set(APPLICATION_NAME ${PROJECT_NAME}) +# Specify search path for CMake modules to be loaded by include() +# and find_package() +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") + +### Add defaults for cmake +# These defaults need to be included before the project() call. +include(DefineCMakeDefaults) -set(APPLICATION_VERSION_MAJOR "1") -set(APPLICATION_VERSION_MINOR "1") -set(APPLICATION_VERSION_PATCH "2") +# This will provide -DCMAKE_BUILD_TYPE=Profiling +# and -DCMAKE_BUILD_TYPE=AddressSanitizer +include(DefineCompilerFlags) +include(DefinePlatformDefaults) -set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}") +project(cmocka VERSION 1.1.3 LANGUAGES C) + +# global needed variables +set(APPLICATION_NAME ${PROJECT_NAME}) # SOVERSION scheme: CURRENT.AGE.REVISION # If there was an incompatible interface change: @@ -19,21 +27,14 @@ set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO # Increment AGE. Set REVISION to 0 # If the source code was changed, but there were no interface changes: # Increment REVISION. -set(LIBRARY_VERSION "0.5.0") +set(LIBRARY_VERSION "0.5.1") set(LIBRARY_SOVERSION "0") -# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked -set(CMAKE_MODULE_PATH - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules -) - -# add definitions -include(DefineCMakeDefaults) -include(DefinePlatformDefaults) -include(DefineInstallationPaths) +# include cmake files +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) include(DefineOptions.cmake) include(CPackConfig.cmake) -include(CheckSymbolExists) include(CompilerChecks.cmake) # disallow in-source build @@ -54,8 +55,8 @@ add_subdirectory(doc) add_subdirectory(include) add_subdirectory(src) +include(AddCMockaTest) if (UNIT_TESTING) - include(AddCMockaTest) add_subdirectory(tests) endif (UNIT_TESTING) @@ -67,7 +68,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc DESTINATION - ${LIB_INSTALL_DIR}/pkgconfig + ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT pkgconfig ) @@ -75,14 +76,25 @@ install( # cmake config files set(CMOCKA_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) -configure_file(${PROJECT_NAME}-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake @ONLY) -configure_file(${PROJECT_NAME}-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake @ONLY) +set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE INTERNAL "") +set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "") +configure_package_config_file(${PROJECT_NAME}-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + PATH_VARS + INCLUDE_INSTALL_DIR LIB_INSTALL_DIR + INSTALL_DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake + COMPATIBILITY + AnyNewerVersion) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake DESTINATION - ${CMAKE_INSTALL_DIR}/${PROJECT_NAME} + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} COMPONENT devel ) diff --git a/CPackConfig.cmake b/CPackConfig.cmake index a11f803..1af76c6 100644 --- a/CPackConfig.cmake +++ b/CPackConfig.cmake @@ -2,7 +2,7 @@ # http://www.cmake.org/Wiki/CMake:CPackConfiguration ### general settings -set(CPACK_PACKAGE_NAME ${APPLICATION_NAME}) +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unit testing framework for C with mock objects") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CPACK_PACKAGE_VENDOR "Andreas Schneider") @@ -11,10 +11,7 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") ### versions -set(CPACK_PACKAGE_VERSION_MAJOR "${APPLICATION_VERSION_MAJOR}") -set(CPACK_PACKAGE_VERSION_MINOR "${APPLICATION_VERSION_MINOR}") -set(CPACK_PACKAGE_VERSION_PATCH "${APPLICATION_VERSION_PATCH}") -set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) ### source generator @@ -37,7 +34,7 @@ endif (WIN32) set(CPACK_PACKAGE_INSTALL_DIRECTORY "cmocka") -set(CPACK_PACKAGE_FILE_NAME ${APPLICATION_NAME}-${CPACK_PACKAGE_VERSION}) +set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}) set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers") @@ -1,3 +1,9 @@ +Wed Sep 26 2018 Andreas Schneider <asn@cryptomilk.org> + * cmocka version 1.1.3 + * Fixed subunit output on failures + * Do not abort if a test is skipped + * Switched to Modern CMake + Wed Aug 29 2018 Andreas Schneider <asn@cryptomilk.org> * cmocka version 1.1.2 * Added function to filter tests (cmocka_set_test_filter) diff --git a/CompilerChecks.cmake b/CompilerChecks.cmake index f8a7af1..f07929c 100644 --- a/CompilerChecks.cmake +++ b/CompilerChecks.cmake @@ -17,8 +17,7 @@ if (UNIX) endif() add_c_compiler_flag("-std=gnu99" SUPPORTED_COMPILER_FLAGS) - add_c_compiler_flag("-pedantic" SUPPORTED_COMPILER_FLAGS) - add_c_compiler_flag("-pedantic-errors" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wpedantic" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wall" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wshadow" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wmissing-prototypes" SUPPORTED_COMPILER_FLAGS) @@ -63,9 +62,27 @@ if (UNIX) endif() endif() - check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR) - if (WITH_STACK_PROTECTOR) - list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector") + check_c_compiler_flag_ssp("-fstack-protector-strong" WITH_STACK_PROTECTOR_STRONG) + if (WITH_STACK_PROTECTOR_STRONG) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector-strong") + # This is needed as Solaris has a seperate libssp + if (SOLARIS) + list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector-strong") + endif() + else (WITH_STACK_PROTECTOR_STRONG) + check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR) + if (WITH_STACK_PROTECTOR) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector") + # This is needed as Solaris has a seperate libssp + if (SOLARIS) + list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector") + endif() + endif() + endif (WITH_STACK_PROTECTOR_STRONG) + + check_c_compiler_flag_ssp("-fstack-clash-protection" WITH_STACK_CLASH_PROTECTION) + if (WITH_STACK_CLASH_PROTECTION) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-clash-protection") endif() if (PICKY_DEVELOPER) @@ -84,10 +101,5 @@ if (MSVC) add_c_compiler_flag("/D _CRT_SECURE_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) endif() -# This removes this annoying warning -# "warning: 'BN_CTX_free' is deprecated: first deprecated in OS X 10.7 [-Wdeprecated-declarations]" -if (OSX) - add_c_compiler_flag("-Wno-deprecated-declarations" SUPPORTED_COMPILER_FLAGS) -endif() - set(DEFAULT_C_COMPILE_FLAGS ${SUPPORTED_COMPILER_FLAGS} CACHE INTERNAL "Default C Compiler Flags" FORCE) +set(DEFAULT_LINK_FLAGS ${SUPPORTED_LINKER_FLAGS} CACHE INTERNAL "Default C Linker Flags" FORCE) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 9bdc6f8..0e063de 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -7,10 +7,10 @@ include(CheckCXXSourceCompiles) include(CheckStructHasMember) include(TestBigEndian) -set(PACKAGE ${APPLICATION_NAME}) -set(VERSION ${APPLICATION_VERSION}) +set(PACKAGE ${PROJECT_NAME}) +set(VERSION ${PROJECT_VERSION}) set(DATADIR ${DATA_INSTALL_DIR}) -set(LIBDIR ${LIB_INSTALL_DIR}) +set(LIBDIR ${CMAKE_INSTALL_LIBDIR}) set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}") set(SYSCONFDIR ${SYSCONF_INSTALL_DIR}) diff --git a/DefineOptions.cmake b/DefineOptions.cmake index bca0848..5bc1ef3 100644 --- a/DefineOptions.cmake +++ b/DefineOptions.cmake @@ -3,6 +3,10 @@ option(WITH_CMOCKERY_SUPPORT "Install a cmockery header" OFF) option(UNIT_TESTING "Build with unit testing" OFF) option(PICKY_DEVELOPER "Build with picky developer flags" OFF) +if (WITH_STATIC_LIB) + set(BUILD_STATIC_LIB ON) +endif (WITH_STATIC_LIB) + if (UNIT_TESTING) - set(WITH_STATIC_LIB ON) -endif() + set(BUILD_STATIC_LIB ON) +endif (UNIT_TESTING) diff --git a/cmake/Modules/AddCMockaTest.cmake b/cmake/Modules/AddCMockaTest.cmake index 19de66e..2f45e1a 100644 --- a/cmake/Modules/AddCMockaTest.cmake +++ b/cmake/Modules/AddCMockaTest.cmake @@ -1,23 +1,120 @@ -# - ADD_CMOCKA_TEST(test_name test_source linklib1 ... linklibN) - +# # Copyright (c) 2007 Daniel Gollub <dgollub@suse.de> -# Copyright (c) 2007-2010 Andreas Schneider <asn@cynapses.org> +# Copyright (c) 2007-2018 Andreas Schneider <asn@cryptomilk.org> +# Copyright (c) 2018 Anderson Toshiyuki Sasaki <ansasaki@redhat.com> # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. +#.rst: +# AddCMockaTest +# ------------- +# +# This file provides a function to add a test +# +# Functions provided +# ------------------ +# +# :: +# +# add_cmocka_test(target_name +# SOURCES src1 src2 ... srcN +# [COMPILE_OPTIONS opt1 opt2 ... optN] +# [LINK_LIBRARIES lib1 lib2 ... libN] +# [LINK_OPTIONS lopt1 lop2 .. loptN] +# ) +# +# ``target_name``: +# Required, expects the name of the test which will be used to define a target +# +# ``SOURCES``: +# Required, expects one or more source files names +# +# ``COMPILE_OPTIONS``: +# Optional, expects one or more options to be passed to the compiler +# +# ``LINK_LIBRARIES``: +# Optional, expects one or more libraries to be linked with the test +# executable. +# +# ``LINK_OPTIONS``: +# Optional, expects one or more options to be passed to the linker +# +# +# Example: +# +# .. code-block:: cmake +# +# add_cmocka_test(my_test +# SOURCES my_test.c other_source.c +# COMPILE_OPTIONS -g -Wall +# LINK_LIBRARIES mylib +# LINK_OPTIONS -Wl,--enable-syscall-fixup +# ) +# +# Where ``my_test`` is the name of the test, ``my_test.c`` and +# ``other_source.c`` are sources for the binary, ``-g -Wall`` are compiler +# options to be used, ``mylib`` is a target of a library to be linked, and +# ``-Wl,--enable-syscall-fixup`` is an option passed to the linker. +# + enable_testing() include(CTest) -if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW) - 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") -endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW) - -function (ADD_CMOCKA_TEST _testName _testSource) - add_executable(${_testName} ${_testSource}) - target_link_libraries(${_testName} ${ARGN}) - add_test(${_testName} ${CMAKE_CURRENT_BINARY_DIR}/${_testName}) +if (CMAKE_CROSSCOMPILING) + if (WIN32) + find_program(WINE_EXECUTABLE + NAMES wine) + set(TARGET_SYSTEM_EMULATOR ${WINE_EXECUTABLE} CACHE INTERNAL "") + endif() +endif() + +function(ADD_CMOCKA_TEST _TARGET_NAME) + + set(one_value_arguments + ) + + set(multi_value_arguments + SOURCES + COMPILE_OPTIONS + LINK_LIBRARIES + LINK_OPTIONS + ) + + cmake_parse_arguments(_add_cmocka_test + "" + "${one_value_arguments}" + "${multi_value_arguments}" + ${ARGN} + ) + + if (NOT DEFINED _add_cmocka_test_SOURCES) + message(FATAL_ERROR "No sources provided for target ${_TARGET_NAME}") + endif() + + add_executable(${_TARGET_NAME} ${_add_cmocka_test_SOURCES}) + + if (DEFINED _add_cmocka_test_COMPILE_OPTIONS) + target_compile_options(${_TARGET_NAME} + PRIVATE ${_add_cmocka_test_COMPILE_OPTIONS} + ) + endif() + + if (DEFINED _add_cmocka_test_LINK_LIBRARIES) + target_link_libraries(${_TARGET_NAME} + PRIVATE ${_add_cmocka_test_LINK_LIBRARIES} + ) + endif() + + if (DEFINED _add_cmocka_test_LINK_OPTIONS) + set_target_properties(${_TARGET_NAME} + PROPERTIES LINK_FLAGS + ${_add_cmocka_test_LINK_OPTIONS} + ) + endif() + + add_test(${_TARGET_NAME} + ${TARGET_SYSTEM_EMULATOR} ${_TARGET_NAME} + ) + endfunction (ADD_CMOCKA_TEST) diff --git a/cmake/Modules/CheckCCompilerFlagSSP.cmake b/cmake/Modules/CheckCCompilerFlagSSP.cmake index e421091..eeaf4fc 100644 --- a/cmake/Modules/CheckCCompilerFlagSSP.cmake +++ b/cmake/Modules/CheckCCompilerFlagSSP.cmake @@ -18,12 +18,31 @@ # Requires cmake 3.10 #include_guard(GLOBAL) include(CheckCSourceCompiles) +include(CMakeCheckCompilerFlagCommonPatterns) macro(CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT) - set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") - set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") + set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${_FLAG}") - check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" ${_RESULT}) + # Normalize locale during test compilation. + set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) + foreach(v ${_CheckCCompilerFlag_LOCALE_VARS}) + set(_CheckCCompilerFlag_SAVED_${v} "$ENV{${v}}") + set(ENV{${v}} C) + endforeach() - set(CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") + CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCCompilerFlag_COMMON_PATTERNS) + check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" + ${_RESULT} + # Some compilers do not fail with a bad flag + FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU + ${_CheckCCompilerFlag_COMMON_PATTERNS}) + foreach(v ${_CheckCCompilerFlag_LOCALE_VARS}) + set(ENV{${v}} ${_CheckCCompilerFlag_SAVED_${v}}) + unset(_CheckCCompilerFlag_SAVED_${v}) + endforeach() + unset(_CheckCCompilerFlag_LOCALE_VARS) + unset(_CheckCCompilerFlag_COMMON_PATTERNS) + + set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endmacro(CHECK_C_COMPILER_FLAG_SSP) diff --git a/cmake/Modules/DefineCMakeDefaults.cmake b/cmake/Modules/DefineCMakeDefaults.cmake index a08eca1..ab0538b 100644 --- a/cmake/Modules/DefineCMakeDefaults.cmake +++ b/cmake/Modules/DefineCMakeDefaults.cmake @@ -14,23 +14,5 @@ set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) # since cmake 2.4.0 set(CMAKE_COLOR_MAKEFILE ON) -# Define the generic version of the libraries here -set(GENERIC_LIB_VERSION "0.1.0") -set(GENERIC_LIB_SOVERSION "0") - -# Set the default build type to release with debug info -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE RelWithDebInfo - CACHE STRING - "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." - ) -endif (NOT CMAKE_BUILD_TYPE) - # Create the compile command database for clang by default set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -if (APPLE) - set(CMAKE_MACOSX_RPATH ON) - set(CMAKE_SKIP_BUILD_RPATH FALSE) - set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -endif(APPLE) diff --git a/cmake/Modules/DefineCompilerFlags.cmake b/cmake/Modules/DefineCompilerFlags.cmake new file mode 100644 index 0000000..3277b99 --- /dev/null +++ b/cmake/Modules/DefineCompilerFlags.cmake @@ -0,0 +1,37 @@ +if (UNIX AND NOT WIN32) + # Activate with: -DCMAKE_BUILD_TYPE=Profiling + set(CMAKE_C_FLAGS_PROFILING "-O0 -g -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C compiler during PROFILING builds.") + set(CMAKE_CXX_FLAGS_PROFILING "-O0 -g -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the CXX compiler during PROFILING builds.") + set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the linker during the creation of shared libraries during PROFILING builds.") + set(CMAKE_MODULE_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the linker during the creation of shared libraries during PROFILING builds.") + set(CMAKE_EXEC_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the linker during PROFILING builds.") + + # Activate with: -DCMAKE_BUILD_TYPE=AddressSanitizer + set(CMAKE_C_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer" + CACHE STRING "Flags used by the C compiler during ADDRESSSANITIZER builds.") + set(CMAKE_CXX_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer" + CACHE STRING "Flags used by the CXX compiler during ADDRESSSANITIZER builds.") + set(CMAKE_SHARED_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" + CACHE STRING "Flags used by the linker during the creation of shared libraries during ADDRESSSANITIZER builds.") + set(CMAKE_MODULE_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" + CACHE STRING "Flags used by the linker during the creation of shared libraries during ADDRESSSANITIZER builds.") + set(CMAKE_EXEC_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" + CACHE STRING "Flags used by the linker during ADDRESSSANITIZER builds.") + + # Activate with: -DCMAKE_BUILD_TYPE=UndefinedSanitizer + set(CMAKE_C_FLAGS_UNDEFINEDSANITIZER "-g -O1 -fsanitize=undefined -fsanitize=null -fsanitize=alignment -fno-sanitize-recover" + CACHE STRING "Flags used by the C compiler during UNDEFINEDSANITIZER builds.") + set(CMAKE_CXX_FLAGS_UNDEFINEDSANITIZER "-g -O1 -fsanitize=undefined -fsanitize=null -fsanitize=alignment -fno-sanitize-recover" + CACHE STRING "Flags used by the CXX compiler during UNDEFINEDSANITIZER builds.") + set(CMAKE_SHARED_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined" + CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.") + set(CMAKE_MODULE_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined" + CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.") + set(CMAKE_EXEC_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined" + CACHE STRING "Flags used by the linker during UNDEFINEDSANITIZER builds.") +endif() diff --git a/cmake/Modules/DefineInstallationPaths.cmake b/cmake/Modules/DefineInstallationPaths.cmake deleted file mode 100644 index 88e08ca..0000000 --- a/cmake/Modules/DefineInstallationPaths.cmake +++ /dev/null @@ -1,109 +0,0 @@ -if (UNIX OR OS2) - IF (NOT APPLICATION_NAME) - MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME") - SET(APPLICATION_NAME ${PROJECT_NAME}) - ENDIF (NOT APPLICATION_NAME) - - # Suffix for Linux - SET(LIB_SUFFIX - CACHE STRING "Define suffix of directory name (32/64)" - ) - - SET(EXEC_INSTALL_PREFIX - "${CMAKE_INSTALL_PREFIX}" - CACHE PATH "Base directory for executables and libraries" - ) - SET(SHARE_INSTALL_PREFIX - "${CMAKE_INSTALL_PREFIX}/share" - CACHE PATH "Base directory for files which go to share/" - ) - SET(DATA_INSTALL_PREFIX - "${SHARE_INSTALL_PREFIX}/${APPLICATION_NAME}" - CACHE PATH "The parent directory where applications can install their data") - - # The following are directories where stuff will be installed to - SET(BIN_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/bin" - CACHE PATH "The ${APPLICATION_NAME} binary install dir (default prefix/bin)" - ) - SET(SBIN_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/sbin" - CACHE PATH "The ${APPLICATION_NAME} sbin install dir (default prefix/sbin)" - ) - SET(LIB_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" - CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/lib)" - ) - SET(LIBEXEC_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/libexec" - CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/libexec)" - ) - SET(PLUGIN_INSTALL_DIR - "${LIB_INSTALL_DIR}/${APPLICATION_NAME}" - CACHE PATH "The subdirectory relative to the install prefix where plugins will be installed (default is prefix/lib/${APPLICATION_NAME})" - ) - SET(INCLUDE_INSTALL_DIR - "${CMAKE_INSTALL_PREFIX}/include" - CACHE PATH "The subdirectory to the header prefix (default prefix/include)" - ) - - set(CMAKE_INSTALL_DIR - "${LIB_INSTALL_DIR}/cmake" - CACHE PATH "The subdirectory to install cmake config files") - - SET(DATA_INSTALL_DIR - "${DATA_INSTALL_PREFIX}" - CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})" - ) - SET(HTML_INSTALL_DIR - "${DATA_INSTALL_PREFIX}/doc/HTML" - CACHE PATH "The HTML install dir for documentation (default data/doc/html)" - ) - SET(ICON_INSTALL_DIR - "${DATA_INSTALL_PREFIX}/icons" - CACHE PATH "The icon install dir (default data/icons/)" - ) - SET(SOUND_INSTALL_DIR - "${DATA_INSTALL_PREFIX}/sounds" - CACHE PATH "The install dir for sound files (default data/sounds)" - ) - - SET(LOCALE_INSTALL_DIR - "${SHARE_INSTALL_PREFIX}/locale" - CACHE PATH "The install dir for translations (default prefix/share/locale)" - ) - - SET(XDG_APPS_DIR - "${SHARE_INSTALL_PREFIX}/applications/" - CACHE PATH "The XDG apps dir" - ) - SET(XDG_DIRECTORY_DIR - "${SHARE_INSTALL_PREFIX}/desktop-directories" - CACHE PATH "The XDG directory" - ) - - SET(SYSCONF_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/etc" - CACHE PATH "The ${APPLICATION_NAME} sysconfig install dir (default prefix/etc)" - ) - SET(MAN_INSTALL_DIR - "${SHARE_INSTALL_PREFIX}/man" - CACHE PATH "The ${APPLICATION_NAME} man install dir (default prefix/man)" - ) - SET(INFO_INSTALL_DIR - "${SHARE_INSTALL_PREFIX}/info" - CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)" - ) -else() - # Same same - set(BIN_INSTALL_DIR "bin" CACHE PATH "-") - set(SBIN_INSTALL_DIR "sbin" CACHE PATH "-") - set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "-") - set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-") - set(CMAKE_INSTALL_DIR "CMake" CACHE PATH "-") - set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-") - set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-") - set(ICON_INSTALL_DIR "icons" CACHE PATH "-") - set(SOUND_INSTALL_DIR "soudns" CACHE PATH "-") - set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-") -endif () diff --git a/cmake/Toolchain-cross-m32.cmake b/cmake/Toolchain-cross-m32.cmake new file mode 100644 index 0000000..7918c60 --- /dev/null +++ b/cmake/Toolchain-cross-m32.cmake @@ -0,0 +1,23 @@ +set(CMAKE_C_FLAGS "-m32" CACHE STRING "C compiler flags" FORCE) +set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "C++ compiler flags" FORCE) + +set(LIB32 /usr/lib) # Fedora + +if(EXISTS /usr/lib32) + set(LIB32 /usr/lib32) # Arch, Solus +endif() + +set(CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE) +set(CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE) + +# this is probably unlikely to be needed, but just in case +set(CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE) +set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE) + +# on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have +# to include the regular system .pc files as well (at the end), because some +# are not always present in the 32 bit directory +if(EXISTS ${LIB32}/pkgconfig) + set(ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig) +endiF() diff --git a/cmocka-config-version.cmake.in b/cmocka-config-version.cmake.in deleted file mode 100644 index 98f292c..0000000 --- a/cmocka-config-version.cmake.in +++ /dev/null @@ -1,11 +0,0 @@ -set(PACKAGE_VERSION @APPLICATION_VERSION@) - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() diff --git a/cmocka-config.cmake.in b/cmocka-config.cmake.in index e92ad03..0890d71 100644 --- a/cmocka-config.cmake.in +++ b/cmocka-config.cmake.in @@ -1,13 +1,15 @@ +@PACKAGE_INIT@ + get_filename_component(CMOCKA_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) if (EXISTS "${CMOCKA_CMAKE_DIR}/CMakeCache.txt") # In build tree include(${CMOCKA_CMAKE_DIR}/cmocka-build-tree-settings.cmake) else() - set(CMOCKA_INCLUDE_DIR @INCLUDE_INSTALL_DIR@) + set(CMOCKA_INCLUDE_DIR @PACKAGE_INCLUDE_INSTALL_DIR@) endif() -set(CMOCKA_LIBRARY @LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) -set(CMOCKA_LIBRARIES @LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) +set(CMOCKA_LIBRARY @PACKAGE_LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) +set(CMOCKA_LIBRARIES @PACKAGE_LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) mark_as_advanced(CMOCKA_LIBRARY CMOCKA_INCLUDE_DIR) diff --git a/cmocka.pc.cmake b/cmocka.pc.cmake index c6f7433..f54d0a7 100644 --- a/cmocka.pc.cmake +++ b/cmocka.pc.cmake @@ -1,6 +1,5 @@ -Name: ${APPLICATION_NAME} +Name: ${PROJECT_NAME} Description: The cmocka unit testing library -Version: ${APPLICATION_VERSION} -Libs: -L${LIB_INSTALL_DIR} -lcmocka -Cflags: -I${INCLUDE_INSTALL_DIR} - +Version: ${PROJECT_VERSION} +Libs: -L${CMAKE_INSTALL_FULL_LIBDIR} -lcmocka +Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR} diff --git a/config.h.cmake b/config.h.cmake index 1aaabb5..f8d79da 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,8 +1,8 @@ /* Name of package */ -#cmakedefine PACKAGE "${APPLICATION_NAME}" +#cmakedefine PACKAGE "${PROJECT_NAME}" /* Version number of package */ -#cmakedefine VERSION "${APPLICATION_VERSION}" +#cmakedefine VERSION "${PROJECT_VERSION}" #cmakedefine LOCALEDIR "${LOCALE_INSTALL_DIR}" #cmakedefine DATADIR "${DATADIR}" diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 4e3dc23..a7bc65e 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,11 +1,13 @@ # # Build the documentation # +if (${CMAKE_VERSION} VERSION_GREATER "3.8.99") + find_package(Doxygen) if (DOXYGEN_FOUND) - set(DOXYGEN_PROJECT_NAME ${APPLICATION_NAME}) - set(DOXYGEN_PROJECT_NUMBER ${APPLICATION_VERSION}) + set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME}) + set(DOXYGEN_PROJECT_NUMBER ${PROJECT_VERSION}) set(DOXYGEN_PROJECT_BRIEF "Unit testing library with mock support") set(DOXYGEN_TAB_SIZE 4) @@ -39,3 +41,5 @@ if (DOXYGEN_FOUND) ${cmocka-headers_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) endif(DOXYGEN_FOUND) + +endif() # CMAKE_VERSION diff --git a/doc/that_style/sass/_fragment_base.scss b/doc/that_style/sass/_fragment_base.scss deleted file mode 100644 index b46e46e..0000000 --- a/doc/that_style/sass/_fragment_base.scss +++ /dev/null @@ -1,69 +0,0 @@ -/* - Basic styling for fragments shared by all themes. -*/ - -div.fragment { - padding: 0; - margin: 4px 8px 4px 2px; - color: #bebebe; - background-color: #323232; - border: 3px solid #e8e8e8; - border-radius: 2px; - overflow-y: hidden; - overflow-x: auto; - position: relative; - -} - -div.line { - font-family: monospace, fixed; - font-size: 13px; - min-height: 13px; - line-height: 1.0; - text-indent: -53px; - margin: 0px; - padding: 1px 0 1px 53px; - white-space: pre; - - @include transition-property(background-color); - @include transition-duration(0s); - - &:hover { - background-color: #1a1a1a; - } - - &::after { - // insert linefeed - content:"\000A"; - white-space: pre; - } -} - -span.lineno { - padding-right: 4px; - text-align: right; - color: black; - height: 100px; - white-space: pre; - border-right: 3px solid #1d7567; - background-color: #a0a0a0; -} - -span.lineno a, span.lineno a:visited { - background-color: inherit; - color: #1e595a; -} - -span.lineno a:hover { - background-color: #C8C8C8; - text-decoration: none; -} - -.lineno { - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} diff --git a/doc/that_style/sass/_fragment_color.scss b/doc/that_style/sass/_fragment_color.scss deleted file mode 100644 index 8b7977a..0000000 --- a/doc/that_style/sass/_fragment_color.scss +++ /dev/null @@ -1,80 +0,0 @@ -// colours of code view - -div.fragment { - color: #bebebe; - background-color: #323232; -} - -div.fragment::before { - background-color: #1a1a1a; - border-right: 1px solid #3e3e3e; -} - -div.line:hover { - background-color: #1a1a1a; -} - -span.lineno { - color: #969696; - background-color: #1a1a1a; - border-right: 1px solid #3e3e3e; -} - -span.lineno a, span.lineno a:visited { - background-color: inherit; - color: #dcdcdc; -} - -span.lineno a:hover { - background-color: #323232; -} - - -// syntax highlighting - -a.code, a.code:visited { - color: #6cc7eb; -} - -a.codeRef, a.codeRef:visited { - color: #3d95e6; -} - -span.keyword { - color: #98f77a; - font-weight: bold; -} - -span.keywordtype { - color: #ffa0a0; -} - -span.keywordflow { - color: #98f77a; - font-weight: bold; -} - -span.comment { - // color: #dadbb1; - color: #999; - font-style: oblique; -} - -span.preprocessor { - color: #cd5c57; -} - -span.stringliteral { - color: #64b041; -} - -span.charliteral { - color: #64b041; -} - -blockquote { - background-color: #F7F8FB; - border-left: 2px solid #9CAFD4; - margin: 0 24px 0 4px; - padding: 0 12px 0 16px; -} diff --git a/doc/that_style/sass/_menu_bar.scss b/doc/that_style/sass/_menu_bar.scss deleted file mode 100644 index d6aa1c3..0000000 --- a/doc/that_style/sass/_menu_bar.scss +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The main menu at the top - */ - -#main-menu { - background-image: none; - background: $background-color-dark; - padding: 0; -} - -.sm-dox { - // :not(:last-child) -> do not style search box - &> li:not(:last-child) > a { - background-image: none; - text-shadow: none; - color: white; - font-weight: normal; - letter-spacing: 1px; - font-size: 11pt; - text-transform: uppercase; - } - - &> li:not(:last-child) > a:hover, - &> li:not(:last-child) > a.highlighted { - background-color: $primary-color; - } - - a span.sub-arrow { - // this sets the color of the arrow - border-color: white transparent transparent; - } - - ul { - // sub menus - border: none; - @include border-radius(0 !important); - padding: 0; - background: $background-color-dark; - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); - - a { - background: inherit; - color: white; - font-weight: normal; - letter-spacing: 1px; - font-size: 11pt; - } - - a:hover { - background: $primary-color; - color: white; - font-weight: normal; - letter-spacing: 1px; - font-size: 11pt; - } - - a.highlighted { - background: $primary-color; - color: white; - font-weight: normal; - letter-spacing: 1px; - font-size: 11pt; - } - - a span.sub-arrow { - /* this sets the color of the arrow */ - border-color: white transparent transparent; - } - } -} diff --git a/doc/that_style/sass/_mixins.scss b/doc/that_style/sass/_mixins.scss deleted file mode 100644 index aa030de..0000000 --- a/doc/that_style/sass/_mixins.scss +++ /dev/null @@ -1,33 +0,0 @@ -@mixin box-shadow($args...) { - -moz-box-shadow: $args; - -webkit-box-shadow: $args; - -o-box-shadow: $args; - box-shadow: $args; -} - -@mixin border-radius($args...) { - -moz-border-radius: $args; - -webkit-border-radius: $args; - border-radius: $args; -} - -@mixin transition($args...) { - -webkit-transition: $args; - -moz-transition: $args; - -o-transition: $args; - transition: $args; -} - -@mixin transition-property($arg) { - -webkit-transition: $arg; - -moz-transition: $arg; - -o-transition: $arg; - transition: $arg; -} - -@mixin transition-duration($arg) { - -webkit-duration: $arg; - -moz-duration: $arg; - -o-duration: $arg; - duration: $arg; -} diff --git a/doc/that_style/sass/_nav_tree.scss b/doc/that_style/sass/_nav_tree.scss deleted file mode 100644 index 0b265c6..0000000 --- a/doc/that_style/sass/_nav_tree.scss +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The tree view on the left - */ - -.arrow { - color:black; - cursor: pointer; - font-size: 80%; - display: inline-block; - width: 16px; - height: 22px; - margin-left: 4px; - - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - - &:hover { - color: black; - } -} - -#selected .arrow { - color: white; - - &:hover { - color: #d2d2d2; - } -} - -#nav-tree { - background-image: none; - background-color: white; - - .item { - margin: 0; - - &:hover { - background-color: #d2d2d2; - } - } - - .selected { - background-image: none; - background-color: $primary-color; - color: white; - text-shadow: none; - - &:hover { - background-image: none; - background-color: $primary-color; - color: white; - text-shadow: none; - } - } - - a { - color: black; - } -} - -.ui-resizable-e { - background: #808080 url("splitbar_handle.svg") no-repeat center; - border-right: solid 1px #c0c0c0; - border-left: solid 1px black; - - &:hover { - background-color: #606060; - } -} diff --git a/doc/that_style/sass/_navpath.scss b/doc/that_style/sass/_navpath.scss deleted file mode 100644 index a266dca..0000000 --- a/doc/that_style/sass/_navpath.scss +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The line at the bottom - */ - -.navpath { - ul { - font-size: 11px; - background-image: none; - height: 30px; - line-height: 30px; - color: black; - border: none; - border-top: 1px solid #808080; - overflow: hidden; - margin: 0px; - padding: 0px; - } - - /* intermediate navelems */ - li:not(:first-child) { - list-style-type: none; - float: left; - padding-left: 18px; - padding-right: 10px; - color: black; - background-color: white; - background-image: url('nav_edge_inter.svg'); - background-repeat: no-repeat; - background-position: left -1px; - background-size: auto 100%; - } - - /* first navelem */ - li:first-child { - list-style-type: none; - float: left; - padding-left: 15px; - padding-right: 10px; - color: black; - background-color: white; - background-image: none; - } - - /* last navelem */ - li:nth-last-child(2) { - list-style-type: none; - float: left; - padding-left:10px; - padding-right:15px; - color: white; - background-color: $primary-color; - background-image: url('nav_edge_right.svg'); - background-repeat: no-repeat; - background-position: right -1px; - background-size: auto 100%; - - } - - li:nth-last-child(2):not(:first-child) { - list-style-type: none; - float: left; - padding-left:15px; - padding-right:15px; - color: white; - background-color: $primary-color; - background-image: url('nav_edge_left.svg'), url('nav_edge_right.svg'); - background-repeat: no-repeat; - background-position: -1px -1px, right -1px; - background-size: auto 100%; - } - - li.navelem a, .navpath li.navelem b { - height:32px; - display:block; - text-decoration: none; - outline: none; - color: inherit; - font-family: Roboto,sans-serif; - text-shadow: none; - text-decoration: none; - font-weight: normal; - } - - li.navelem a:hover { - color: inherit; - text-decoration: underline; - } - - // the "doxygen" logo at the right - li.footer { - list-style-type: none; - float: right; - padding-left: 0; - padding-right: 10px; - background-color: #d5d5d5; - background-image: none; - color: black; - font-size: 8pt; - - // show the edge image - &:before { - content: ""; - width: 13px; - height: 30px; - display: inline-block; - float: left; - background-image: url("nav_edge_right.svg"); - background-repeat: no-repeat; - background-position: right 0; - background-size: auto 100%; - - /* flip the element horizontally */ - -moz-transform: scaleX(-1); - -o-transform: scaleX(-1); - -webkit-transform: scaleX(-1); - transform: scaleX(-1); - filter: FlipH; - -ms-filter: "FlipH"; - } - } -} diff --git a/doc/that_style/sass/_search.scss b/doc/that_style/sass/_search.scss deleted file mode 100644 index abd83bc..0000000 --- a/doc/that_style/sass/_search.scss +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The search box - */ - -.sm-dox > li:last-child { - margin-right: 10pt; -} - -#MSearchBox { - border: 2px inset black; - display: table; - width: 350px; - height: 26px; - background: white; - margin-top: 5px; - - .left { - background-image: none; - display: table-cell; - width: 100%; - height: inherit; - left: 0; - } - - // don't need this element - .right { - background-image: none; - width: 0; - display: none; - visibility: hidden; - } -} - -// override for when there is no main menu -nav > #MSearchBox { - border: 2px solid #666666; - margin: 5px 10pt 0 0; - height: 22px; -} - -#MSearchSelect, .left #MSearchSelect { - left: 0; - background-image: url("mag_glass.svg"); - width: 22px; - height: 22px; - padding: 22px 22px 0 0 ; - margin: 0 4px 0 4px; - box-sizing: border-box; -} - -#MSearchField { - background-image: none; - display: table-cell; - margin: 0; - // leave room for #MSearchSelect and a bit more for the border - margin-left: 30px; - width: calc(100% - 34px); - height: 22px; - font: 11pt sans-serif; -} - -#MSearchSelectWindow { - background-color: $background-color-dark; - padding: 0; - border: solid 1px black; - @include border-radius(0); - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); -} - -a.SelectItem { - color: white; - padding: 3px 4px; - font: 10pt sans-serif; - letter-spacing: 1px; - - &:hover { - background-color: $primary-color; - color: white; - } - - &:focus, &:active { - color: white; - } -} - -#MSearchResultsWindow { - background-color: white; - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); -} diff --git a/doc/that_style/sass/that_style.scss b/doc/that_style/sass/that_style.scss deleted file mode 100644 index f1ebf92..0000000 --- a/doc/that_style/sass/that_style.scss +++ /dev/null @@ -1,1240 +0,0 @@ -/* - * My own little style - */ - -@import "mixins"; - -// colors -$primary-color: #5f082b; -$primary-color-dark: #2c0414; -$primary-color-light: #820a32; -$secondary-color: #00549f; -$secondary-color-dark: #002546; -$background-color: #ffffff; -$background-color-dark: #414141; - -body, table, div, p, dl { - font: 400 14px/22px Roboto,sans-serif; -} - -h1.groupheader { - font-size: 150%; -} - -.title { - font: 400 14px/28px Roboto,sans-serif; - font-size: 150%; - font-weight: bold; - margin: 10px 2px; -} - -h2.groupheader { - border-bottom: 1px solid #555555; - color: black; - font-size: 200%; - font-weight: bold; - margin-top: 1.75em; - padding-top: 1em; - padding-bottom: 4px; - width: 100%; -} - -tr.heading h2 { - border-bottom: 1px solid #a5a5a5; - font-size: 150%; - margin-top: 6px; - margin-bottom: 6px; - padding-top: 3px; - padding-bottom: 7px; -} - -h2.groupheader a { - margin-left: 1%; -} - -h3.groupheader { - font-size: 100%; -} - -h1, h2, h3, h4, h5, h6 { - @include transition(none); - margin-right: 15px; - - &.glow { - text-shadow: none; - color: $primary-color; - } -} - -dt { - font-weight: bold; -} - -div.multicol { - -moz-column-gap: 1em; - -webkit-column-gap: 1em; - -moz-column-count: 3; - -webkit-column-count: 3; -} - -p.startli, p.startdd { - margin-top: 2px; -} - -p.starttd { - margin-top: 0px; -} - -p.endli { - margin-bottom: 0px; -} - -p.enddd { - margin-bottom: 4px; -} - -p.endtd { - margin-bottom: 2px; -} - -#top { - border: none; - position: relative; - z-index: 100; - @include box-shadow(0 0 4px rgba(0,0,0,0.4), 0 0 8px rgba(0,0,0,0.3)); -} - -caption { - font-weight: bold; -} - -span.legend { - font-size: 70%; - text-align: center; -} - -h3.version { - font-size: 90%; - text-align: center; -} - -div.qindex, div.navtab { - background-color: $background-color; - border: none; - text-align: center; -} - -div.qindex, div.navpath { - width: 100%; - line-height: 140%; -} - -div.navtab { - margin-right: 15px; -} - -a, a:visited { - color: $secondary-color; - font-weight: normal; - text-decoration: none; -} - -.contents a:visited { - color: #4665A2; -} - -a:hover { - text-decoration: underline; -} - -a.qindex { - font-weight: bold; - text-transform: uppercase; -} - -a.qindexHL { - font-weight: bold; - background-color: #9CAFD4; - color: #ffffff; - border: 1px double #869DCA; -} - -.contents a.qindexHL:visited { - color: #ffffff; -} - -a.el, a.el:visited { - font-weight: normal; - color: $secondary-color; -} - -a.elRef, a.elRef:visited { - font-family: monospace; - color: #006bc8; -} - -@import "menu_bar"; - -dl.el { - margin-left: -1cm; -} - -div.ah, span.ah { - background: none; - color: black; - margin-bottom: 3px; - margin-top: 3px; - padding: 0.2em; - - border: none; - @include border-radius(0); - @include box-shadow(none); - - font: 14pt monospace; - font-weight: bold; - text-transform: uppercase; -} - -div.classindex ul { - list-style: none; - padding-left: 0; -} - -div.classindex span.ai { - display: inline-block; -} - -div.groupHeader { - margin-left: 16px; - margin-top: 12px; - font-weight: bold; -} - -div.groupText { - margin-left: 16px; - font-style: italic; -} - -body { - background-color: $background-color; - color: black; - margin: 0; -} - -#doc-content { - background-color: #111; - color: $background-color; -} - -// this is for individual member pages -div.contents { - color: black; - background-color: $background-color; - padding: 0; - margin: 5pt; - - // the line after the member documentations - hr { - display: none; - visibility: hidden; - } -} - -// override for 'normal' mode -div.header + div.contents { - padding: 1ex; - margin: 0 5pt 5pt 5pt; -} - -div.textblock { - padding: 1ex 1ex 0 1ex; -} - -div.textblock + ul { - padding-bottom: 1%; -} - -img.footer { - border: 0px; - vertical-align: middle; -} - -@import "fragment_base"; -@import "fragment_color"; - -@import "search"; - -table.memberdecls { - width: 100%; - border-spacing: 0px; - padding: 0px; - margin-top: 7px; - background-color: $background-color; - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); -} - -.memberdecls tbody { - background-color: $background-color; -} - -.memberdecls .odd { - background: #f6f6f6; -} - -/* all but last separator show a line */ -.memberdecls tr[class^="separator"]:not(:last-child) .memSeparator { - border-bottom: 1px solid #c5c5c5; - line-height: 1px; - margin: 0; - padding: 0; -} - -.memberdecls tr[class^="separator"]:last-child .memSeparator { - border-bottom: none; - line-height: 0; - margin: 0; - padding: 0; -} - -table.fieldtable { - @include border-radius(0); - @include box-shadow(none); -} - -.memberdecls td, .fieldtable tr { - background-color: inherit; -} - -.fieldtable th { - display: none; - height: 0; - visibility: hidden; -} - -td.fieldname { - color: $primary-color-light; - font-family: monospace; - font-weight: bold; -} - -th.markdownTableHeadLeft, th.markdownTableHeadRight, -th.markdownTableHeadCenter, th.markdownTableHeadNone { - background-color: $background-color-dark; - color: white; -} - -.memItemLeft, .memItemRight, -.memTemplItemLeft, .memTemplItemRight, .memTemplParams { - font-family: monospace; - background-color: $background-color; - border: none; - margin: 4px; - padding: 1px 0 0 8px; -} - -.mdescLeft, .mdescRight { - background-color: $background-color; - border: none; - margin: 4px; - padding: 1px 0 0 8px; -} - -.mdescLeft, .mdescRight { - padding: 0px 8px 4px 8px; - color: #555; -} - -.memItemLeft, .memTemplItemLeft { - white-space: nowrap; -} - -.memItemRight { - width: 100%; -} - -.memTemplParams { - color: #4665A2; - white-space: nowrap; - font-size: 80%; -} - -/* Styles for detailed member documentation */ - -.memtitle { - padding: 8px; - border: none; - margin-bottom: -1px; - background-image: none; - background-color: #f6f6f6; - line-height: 1.25; - font-weight: bold; - color: black; - float: left; - z-index: 0; - position: relative; - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); -} - -.permalink { - font-size: 100%; - display: inline-block; - vertical-align: middle; -} - -/* replace content of permalinks */ -.permalink a { - visibility: hidden; -} -.permalink a:after { - content: "§"; - visibility: visible; - display: block; - position: absolute; - color: black; - top: 20%; -} - -.permalink a:visited { - color: black; -} - -.memtemplate { - font-size: 100%; - color: black; - font-family: monospace; - font-weight: normal; - margin-left: 9px; -} - -.memnav { - background-color: #EBEFF6; - border: 1px solid #A3B4D7; - text-align: center; - margin: 2px; - margin-right: 15px; - padding: 2px; -} - -.mempage { - width: 100%; -} - -.memitem { - font-family: monospace; - padding: 0; - margin-bottom: 10px; - margin-right: 5px; - -webkit-transition: none; - -moz-transition: none; - -ms-transition: none; - -o-transition: none; - transition: none; - display: table !important; - width: 100%; - background-color: #f6f6f6; - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); -} - -.memitem.glow { - @include box-shadow(none); -} - -.memname { - font-family: monospace; - font-weight: 400; - margin-left: 6px; -} - -.memname td { - vertical-align: bottom; -} - -.memproto, dl.reflist dt { - border: none; - padding: 6px 0px 6px 0px; - color: black; - font-weight: bold; - text-shadow: none; - background-color: #f6f6f6; - position: relative; - z-index: 1; - @include box-shadow(none); -} - - -.overload { - font-family: "courier new",courier,monospace; - font-size: 65%; -} - -.memdoc, dl.reflist dd { - border: none; - border-left: 4px solid $primary-color; - border-bottom-left-radius: 0px; - border-bottom-right-radius: 0px; - -webkit-border-bottom-left-radius: 0px; - -webkit-border-bottom-right-radius: 0px; - -moz-border-bottom-left-radius: 0px; - -moz-border-bottom-right-radius: 0px; - padding: 2px 1% 2px 1%; - margin: 1%; - background-color: $background-color; - background-image: none; - @include box-shadow(none); - - /* allow movement of elements inside */ - display: flex; - flex-direction: column; -} - -/* overrides for docs on individual pages */ - -.memtitle:nth-child(2) { - width: 0; - height: 0; - display: none; - visibility: hidden; -} - -.memitem:nth-child(3) { - margin: 0; - margin-top: 0.5%; - background-color: $background-color; - @include box-shadow(none); -} - -.memitem:nth-child(3) .memproto { - padding: 10px; - background-color: $background-color; - margin-bottom: 10px; -} - -.memitem:nth-child(3) .memproto::after { - content: ""; - width: 99%; - height: 1px; - position: absolute; - bottom: -10px; - left: 0.5%; - background: #666; -} - -.memitem:nth-child(3) .memdoc { - border: none; - padding: 0; -} - -.memitem:nth-child(3) table.memname { - background-color: #f6f6f6; - border-collapse: collapse; - border-spacing: initial; - border: 1px solid #aaa; -} - -.memitem:nth-child(3) table.memname tr:not(:last-child) { - border-bottom: 1px dashed #aaa; -} - - -dl.reflist dt { - padding: 5px; - z-index: 0; /* cover the top shadow of dd */ - position: relative; - @include box-shadow(0 0 4px rgba(0,0,0,0.35), 0 0 8px rgba(0,0,0,0.2)); -} - -/* cover up the shadow at the bottom */ -dl.reflist dt::after { - content: " "; - width: 100%; - display: block; - height: 8px; - position: absolute; - background-color: #f6f6f6; - left: 0; - bottom: -8px; -} - -dl.reflist dd { - border-left: 4px solid $primary-color; - padding: 2px 1% 2px 1%; - margin: 8px 8px 24px 8px; - outline: 8px solid #f6f6f6; - @include box-shadow(0 0 4px 8px rgba(0,0,0,0.35), 0 0 8px 8px rgba(0,0,0,0.2)); -} - -dl.reflist dd p::before { - font-size: 85%; - content: "\25B6\00A0\00A0"; - display: inline-block; - width: 12pt; -} - -dl.reflist dd p { - margin-top: 4px; - margin-bottom: 4px; -} - -.paramkey { - text-align: right; -} - -.paramtype { - font-family: monospace; - white-space: nowrap; - color:$secondary-color-dark; -} - -.paramname { - color: black; - font-family: monospace; - white-space: nowrap; -} -.paramname em { - color: $primary-color-light; - font-style: normal; -} -.paramname code { - color: #404040; - line-height: 14px; -} - -.params, .retval, .exception, .tparams { - margin-left: 0; - padding-left: 0; - margin-bottom: -0.25em; -} - -.params dt, .tparams dt { - margin-bottom: 0.5em; -} - -.params .paramname, .tparams .paramname, .retval .paramname, .exception .paramname { - color: $primary-color-light; - font-family: monospace; - font-weight: bold; - vertical-align: top; -} - -.params .paramtype, .tparams .paramtype { - font-family: monospace; - font-style: italic; - vertical-align: top; -} - -.params .paramdir, .tparams .paramdir { - font-family: "courier new",courier,monospace; - vertical-align: top; -} - -/* line over parameters docs */ -.params, .tparams { - border-collapse: collapse; -} - -.params tr, .tparams tr { - @include box-shadow(0 -2px 0 -1px #606060); -} - -.params .paramname, .tparams .paramname { - border-top: 2px solid $primary-color; - padding-right: 5pt; -} - -.params td, .tparams td { - padding-bottom: 1em; -} - -table.mlabels { - border-spacing: 0px; -} - -td.mlabels-left { - width: 100%; - padding: 0px; -} - -td.mlabels-right { - vertical-align: bottom; - padding: 0px; - white-space: nowrap; -} - -span.mlabels { - margin-left: 8px; -} - -span.mlabel { - background-color: #444444; - border: none; - border-radius: 3px; - text-shadow: none; - color: white; - margin-right: 4px; - padding: 3px 5px; - font-size: 8pt; - white-space: nowrap; - vertical-align: middle; -} - -.memdoc .definition { - position: relative; - padding-top: 0.5em; - - /* move definition line to bottom of memdoc */ - order: 3; - - // border above - &::before { - content: ""; - width: 33%; - height: 1px; - border-top: 1px solid black; - position: absolute; - top: 0; - } -} - - - -// list of all members and class / file / ... lists -table.directory { - border-top: 1px solid #c5c5c5; - border-bottom: 1px solid #c5c5c5; - border-collapse:collapse; - width: 100%; - font: 400 14px Roboto,sans-serif; - - tr { - // overwrite doxygen weirdness - background-color: white !important; - - &.even { - background-color: #f6f6f6 !important; - } - - &:hover { - background-color: #e6e6e6 !important; - } - } - - td.entry { - padding: 1.5pt 3pt 1.5pt 3pt; - white-space: normal; - } -} - -// class / file / ... lists specific -div.directory { - border: none; - - table.directory { - tr { - // this makes all lines the same height - line-height: 17pt; - } - - td { - margin: 0; - padding: 0.5pt 6pt 0.5pt 0; - vertical-align: middle; - - &.entry { - white-space: nowrap; - } - - &.desc { - width: 100%; - padding-left: 6pt; - border-left: 1px solid rgba(0,0,0,0.05); - } - } - } -} - -// "detail level" at the top -.directory .levels { - white-space: nowrap; - width: 100%; - text-align: right; - font-size: 9pt; - - span { - cursor: pointer; - padding-left: 2px; - padding-right: 2px; - color: $secondary-color; - - &:hover { - text-decoration: underline; - } - } -} - -@import "nav_tree"; - -.icon { - font-family: monospace; - font-weight: bold; - font-size: 12px; - height: 15px; - width: 15px; - display: inline-block; - background-color: #444444; - color: white; - text-align: center; - border-radius: 3px; - margin: 0; - padding-top: 1px; - text-indent: -1px; -} - -.icona { - width: 0; - height: 0; - display: none; - visibility: hidden; -} - -.iconfopen { - width: 24px; - height: 18px; - margin-bottom: 4px; - background-image:url('folderopen.svg'); - background-position: 0; - background-repeat: no-repeat; - vertical-align:top; - display: inline-block; -} - -.iconfclosed { - width: 24px; - height: 18px; - margin-bottom: 4px; - background-image:url('folderclosed.svg'); - background-position: 0; - background-repeat: no-repeat; - vertical-align:top; - display: inline-block; -} - -.icondoc { - width: 24px; - height: 18px; - margin-bottom: 4px; - background-image:url('doc.svg'); - background-position: 0; - background-repeat: no-repeat; - vertical-align:top; - display: inline-block; -} - -div.dynheader { - margin-top: 8px; - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -address { - font-style: normal; - color: #2A3D61; -} - -table.doxtable caption { - caption-side: top; -} - -table.doxtable { - border-collapse: collapse; - margin-top: 4px; - margin-bottom: 4px; -} - -table.doxtable td, table.doxtable th { - border: 1px solid #444444; - padding: 3px 7px 2px; -} - -table.doxtable th { - background-color: #444444; - color: #FFFFFF; - font-size: 110%; - padding-bottom: 4px; - padding-top: 5px; -} - -@import "navpath"; - -div.summary { - -webkit-order: 2; - order: 2; - float: right; - font-size: 8pt; - padding-right: 5px; - width: 50%; - text-align: right; - margin-right: 0.5%; -} - -div.summary a { - white-space: nowrap; -} - -table.classindex { - margin: 10px; - white-space: nowrap; - margin-left: 1%; - margin-right: 1%; - width: 98%; - border: none; - border-top: 1px solid black; - border-bottom: 1px solid black; - border-spacing: 0.5em; - padding: 0; -} - -div.ingroups { - font-size: 8pt; - width: 50%; - text-align: left; -} - -div.ingroups a { - white-space: nowrap; -} - -div.header { - display: -webkit-flex; - display: flex; - justify-content: space-between; - background-image: none; - background-color: $background-color; - color: black; - margin: 5pt 5pt 0 5pt; - padding: 0 1ex 0 1ex; - align-items: center; - justify-content: center; - border-bottom: none; - position: relative; -} - -div.header::after { - content: ""; - height: 2px; - width: 99%; - position: absolute; - bottom: -5px; - left: 0.5%; - background: #666; -} - -div.headertitle { - -webkit-order: 1; - order: 1; - margin-right: auto; - text-align: center; -} - -dl { - padding: 0; -} - -dl.section { - margin-left: 0px; - padding-left: 0px; -} - -dl.section > dt { - font-weight: bold; - font-family: sans-serif; -} - -dl.note, dl.warning, dl.attention, dl.pre, dl.post, dl.invariant, -dl.deprecated, dl.todo, dl.test, dl.bug { - margin-left: -7px; - padding-left: 3px; -} - -dl.note { - padding-left: 7px; - border: none; -} - -dl.warning { - background-color: #ffe6ea; - border: 1px solid #ff0728; - border-left: 4px solid #ff0728; - padding-top: 4px; - padding-bottom: 3px; -} - -dl.attention { - border-left: 4px solid #ff0728; -} - -dl.pre, dl.post, dl.invariant { - background-color: #f0ffe6; - border: 1px solid #5eb82a; - border-left: 4px solid #5eb82a; -} - -dl.deprecated { - background-color: #f6f6f6; - border: 1px solid black; -} - -dl.todo { - border-left: 4px solid #e8d500; -} - -dl.test { - border-left: 4px solid #00549f; -} - -dl.bug { - background-color: #f6f6f6; - border: 1px solid #cc071e; - border-left: 4px solid #cc071e; -} - -dl.section dd { - margin-bottom: 6px; -} - -.memdoc dl dt a.el { - font-weight: bold; - color: black; -} - -#projectlogo -{ - text-align: center; - vertical-align: bottom; - border-collapse: separate; -} - -#projectlogo img -{ - border: 0px none; -} - -#projectalign -{ - vertical-align: middle; -} - -#projectname -{ - font: 300% Tahoma, Arial,sans-serif; - margin: 0px; - padding: 2px 0px; -} - -#projectbrief -{ - font: 120% Tahoma, Arial,sans-serif; - margin: 0px; - padding: 0px; -} - -#projectnumber { - font: 50% Roboto,sans-serif; - margin: 0px; - padding: 0px; -} - -#titlearea { - padding: 0px; - margin: 0px; - width: 100%; - border-bottom: none; - - // should only match if main menu is disabled (depends on javascripts in #top) - &:nth-last-child(2) { - border-bottom: 2px solid #444444; - } -} - -.image -{ - text-align: center; -} - -.dotgraph, .mscgraph, .diagraph { - text-align: center; -} - -.caption -{ - font-weight: bold; -} - -div.zoom -{ - border: 1px solid #90A5CE; -} - -dl.citelist { - margin-bottom: 5ex; - - dt { - color: black; - float: left; - font-weight: bold; - padding: 5px 0; - margin: 2px 10pt 2px 0; - } - - dd { - margin: 2px 0; - padding: 5px 0; - } - - .startdd { - margin-top: 0; - } -} - -div.toc { - background-color: transparent; - border: 1px solid $background-color-dark; - @include border-radius(0); - float: right; - height: auto; - margin: 0 8px 10px 10px; - padding: 10px 15px 5px 25px; - width: auto; - - li { - background: transparent; - font: 10pt Roboto,DejaVu Sans,sans-serif; - padding-left: 0; - padding-top: 0.5ex; - - .level1 { - margin-left: 10pt; - } - - .level2 { - margin-left: 10pt; - } - - .level3 { - margin-left: 10pt; - } - - .level4 { - margin-left: 10pt; - } - } - - h3 { - font: bold 12px/1.2 Roboto,DejaVu Sans,sans-serif; - color: black; - border-bottom: none; - margin: 0; - letter-spacing: 1px; - } - - ul { - list-style: disc; - border: none; - padding: 0; - } -} - -.inherit_header { - font-weight: bold; - color: gray; - cursor: pointer; - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -.inherit_header td { - padding: 6px 0px 2px 5px; -} - -.inherit { - display: none; -} - -/* tooltip related style info */ - -.ttc { - position: absolute; - display: none; -} - -#powerTip { - cursor: default; - white-space: nowrap; - background-color: $background-color; - border: 1px solid #323232; - border-radius: 0; - @include box-shadow(none); - display: none; - font-size: smaller; - max-width: 80%; - opacity: 0.9; - padding: 1ex 1em 1em 1em; - position: absolute; - z-index: 2147483647; - - div.ttdoc { - color: grey; - font-style: italic; - } - - div.ttname a { - font-weight: bold; - } - - div.ttname { - font-weight: bold; - } - - div.ttdeci { - color: #006318; - } - - div { - margin: 0px; - padding: 0px; - font: 12px/16px Roboto,sans-serif; - } - - &:before, &:after { - content: ""; - position: absolute; - margin: 0px; - } -} - -@media print -{ - #top { display: none; } - #side-nav { display: none; } - #nav-path { display: none; } - body { overflow:visible; } - h1, h2, h3, h4, h5, h6 { page-break-after: avoid; } - .summary { display: none; } - .memitem { page-break-inside: avoid; } - #doc-content - { - margin-left:0 !important; - height:auto !important; - width:auto !important; - overflow:inherit; - display:inline; - background-color: white; - } -} diff --git a/doc/that_style/that_style.css b/doc/that_style/that_style.css index 34c3244..846353c 100644 --- a/doc/that_style/that_style.css +++ b/doc/that_style/that_style.css @@ -152,10 +152,14 @@ a.elRef, a.elRef:visited { letter-spacing: 1px; font-size: 11pt; text-transform: uppercase; } -.sm-dox > li:not(:last-child) > a:hover, .sm-dox > li:not(:last-child) > a.highlighted { + +.sm-dox > li:not(:last-child) > a:hover, +.sm-dox > li:not(:last-child) > a.highlighted { background-color: #5f082b; } + .sm-dox a span.sub-arrow { border-color: white transparent transparent; } + .sm-dox ul { border: none; -moz-border-radius: 0 !important; @@ -262,7 +266,7 @@ img.footer { Basic styling for fragments shared by all themes. */ div.fragment { - padding: 0; + padding: 4px; margin: 4px 8px 4px 2px; color: #bebebe; background-color: #323232; @@ -302,7 +306,7 @@ span.lineno { height: 100px; white-space: pre; border-right: 3px solid #1d7567; - background-color: #a0a0a0; } + background-color: #323232; } span.lineno a, span.lineno a:visited { background-color: inherit; @@ -333,7 +337,7 @@ div.line:hover { span.lineno { color: #969696; - background-color: #1a1a1a; + background-color: #323232; border-right: 1px solid #3e3e3e; } span.lineno a, span.lineno a:visited { @@ -539,9 +543,9 @@ th.markdownTableHeadCenter, th.markdownTableHeadNone { width: 100%; } .memTemplParams { - color: #4665A2; + color: black; white-space: nowrap; - font-size: 80%; } + font-size: 100%; } /* Styles for detailed member documentation */ .memtitle { @@ -1406,25 +1410,18 @@ div.toc { @media print { #top { display: none; } - #side-nav { display: none; } - #nav-path { display: none; } - body { overflow: visible; } - h1, h2, h3, h4, h5, h6 { page-break-after: avoid; } - .summary { display: none; } - .memitem { page-break-inside: avoid; } - #doc-content { margin-left: 0 !important; height: auto !important; @@ -1432,5 +1429,3 @@ div.toc { overflow: inherit; display: inline; background-color: white; } } - -/*# sourceMappingURL=that_style.css.map */ diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index b672092..8e80ee2 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,141 +1,73 @@ project(cmocka-examples C) -include_directories( - ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMOCKA_PUBLIC_INCLUDE_DIRS} -) - -set_source_files_properties( - calculator.c - allocate_module.c - assert_module.c - PROPERTIES - COMPILE_DEFINITIONS UNIT_TESTING=1) - - -if (WIN32 OR CYGWIN OR MINGW) - set(CMOCKA_DLL_LIB ${CMAKE_BINARY_DIR}/src) - file(TO_NATIVE_PATH "${CMOCKA_DLL_PATH}" CMOCKA_DLL_PATH) - set(DLL_PATH_ENV "${CMOCKA_DLL_PATH};$ENV{PATH}") - - # - # IMPORTANT NOTE: The set_tests_properties(), below, internally - # stores its name/value pairs with a semicolon delimiter. - # because of this we must protect the semicolons in the path - # - string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) +function(ADD_CMOCKA_TEST_ENVIRONMENT _TARGET_NAME) + if (WIN32 OR CYGWIN OR MINGW) + file(TO_NATIVE_PATH "${cmocka-library_BINARY_DIR}" CMOCKA_DLL_PATH) + + if (TARGET_SYSTEM_EMULATOR) + set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}") + else() + set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH};$ENV{PATH}") + endif() + # + # IMPORTANT NOTE: The set_tests_properties(), below, internally + # stores its name/value pairs with a semicolon delimiter. + # because of this we must protect the semicolons in the path + # + string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") + + set_tests_properties(${_TARGET_NAME} + PROPERTIES + ENVIRONMENT + "${DLL_PATH_ENV}") + endif() +endfunction() + +set_source_files_properties(calculator.c + allocate_module.c + assert_module.c + PROPERTIES + COMPILE_DEFINITIONS + UNIT_TESTING=1) ### The most simple test -add_executable(simple_test simple_test.c) -target_link_libraries(simple_test ${CMOCKA_SHARED_LIBRARY}) - -add_test(simple_test ${CMAKE_CURRENT_BINARY_DIR}/simple_test) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(simple_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) - -### Calulator test -#TODO investigate dll jmp issue on MinGW -if (NOT MINGW OR WITH_STATIC_LIB) - add_executable(calculator_test calculator.c calculator_test.c) - add_test(calculator_test ${CMAKE_CURRENT_BINARY_DIR}/calculator_test) - if (WIN32 OR CYGWIN) - set_tests_properties(calculator_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") - endif (WIN32 OR CYGWIN) - - if (MINGW) - target_link_libraries(calculator_test ${CMOCKA_STATIC_LIBRARY}) - else (MINGW) - target_link_libraries(calculator_test ${CMOCKA_SHARED_LIBRARY}) - endif (MINGW) - - if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(calculator_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") - endif (WIN32 OR CYGWIN OR MINGW) -endif (NOT MINGW OR WITH_STATIC_LIB) +add_cmocka_test(simple_test + SOURCES simple_test.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) +add_cmocka_test_environment(simple_test) ### Allocate module test -add_executable(allocate_module_test allocate_module.c allocate_module_test.c) -target_link_libraries(allocate_module_test ${CMOCKA_SHARED_LIBRARY}) - -# This is a test that should detect leaks and overflows and will fail for that -add_test(allocate_module_test ${CMAKE_CURRENT_BINARY_DIR}/allocate_module_test) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(allocate_module_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) +add_cmocka_test(allocate_module_test + SOURCES allocate_module.c allocate_module_test.c + LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) +add_cmocka_test_environment(allocate_module_test) -set_tests_properties( - allocate_module_test - PROPERTIES - WILL_FAIL 1 -) +set_tests_properties(allocate_module_test + PROPERTIES + WILL_FAIL 1) ### Assert macro test -add_executable(assert_macro_test assert_macro.c assert_macro_test.c) -target_link_libraries(assert_macro_test ${CMOCKA_SHARED_LIBRARY}) +add_cmocka_test(assert_macro_test + SOURCES assert_macro.c assert_macro_test.c + LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) +add_cmocka_test_environment(assert_macro_test) -add_test(assert_macro_test ${CMAKE_CURRENT_BINARY_DIR}/assert_macro_test) -set_tests_properties( - assert_macro_test - PROPERTIES - WILL_FAIL 1 -) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(assert_macro_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) +set_tests_properties(assert_macro_test + PROPERTIES + WILL_FAIL 1) ### Assert module test -add_executable(assert_module_test assert_module.c assert_module_test.c) -target_link_libraries(assert_module_test ${CMOCKA_SHARED_LIBRARY}) - -add_test(assert_module_test ${CMAKE_CURRENT_BINARY_DIR}/assert_module_test) -set_tests_properties( - assert_module_test - PROPERTIES - WILL_FAIL 1 -) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(assert_module_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) - -### Customer database test -add_executable(customer_database_test customer_database.c customer_database_test.c) -target_link_libraries(customer_database_test ${CMOCKA_SHARED_LIBRARY}) - -add_test(customer_database_test ${CMAKE_CURRENT_BINARY_DIR}/customer_database_test) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(customer_database_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) - -### Key Value Test -add_executable(key_value_test key_value.c key_value_test.c) -target_link_libraries(key_value_test ${CMOCKA_SHARED_LIBRARY}) - -add_test(key_value_test ${CMAKE_CURRENT_BINARY_DIR}/key_value_test) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(key_value_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) - -### Product database test -add_executable(product_database_test product_database.c product_database_test.c) -target_link_libraries(product_database_test ${CMOCKA_SHARED_LIBRARY}) +add_cmocka_test(assert_module_test + SOURCES assert_module.c assert_module_test.c + LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) +add_cmocka_test_environment(assert_module_test) -add_test(product_database_test ${CMAKE_CURRENT_BINARY_DIR}/product_database_test) -set_tests_properties( - product_database_test - PROPERTIES - PASS_REGULAR_EXPRESSION - "\\[ FAILED \\] 2 test" -) -if (WIN32 OR CYGWIN OR MINGW) - set_tests_properties(product_database_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") -endif (WIN32 OR CYGWIN OR MINGW) +set_tests_properties(assert_module_test + PROPERTIES + WILL_FAIL 1) -# TODO Execute "$CMAKE_LINKER --help" and check for --wrap -if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)" AND NOT APPLE) - add_subdirectory(chef_wrap) - add_subdirectory(uptime) +if (NOT WIN32) + add_subdirectory(mock) endif() diff --git a/example/customer_database.c b/example/customer_database.c deleted file mode 100644 index 2d49e19..0000000 --- a/example/customer_database.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <stddef.h> -#include <stdio.h> -#include <database.h> -#ifdef _WIN32 -#define snprintf _snprintf -#endif /* _WIN32 */ - -DatabaseConnection* connect_to_customer_database(void); -unsigned int get_customer_id_by_name( - DatabaseConnection * const connection, - const char * const customer_name); - -/* Connect to the database containing customer information. */ -DatabaseConnection* connect_to_customer_database(void) { - return connect_to_database("customers.abcd.org", 321); -} - -/* Find the ID of a customer by his/her name returning a value > 0 if - * successful, 0 otherwise. */ -unsigned int get_customer_id_by_name( - DatabaseConnection * const connection, - const char * const customer_name) { - char query_string[256]; - int number_of_results; - void **results; - snprintf(query_string, sizeof(query_string), - "SELECT ID FROM CUSTOMERS WHERE NAME = %s", customer_name); - number_of_results = connection->query_database(connection, query_string, - &results); - - if (number_of_results != 1) { - return -1; - } - - return (unsigned int)*((int *)results); -} diff --git a/example/customer_database_test.c b/example/customer_database_test.c deleted file mode 100644 index 45ec782..0000000 --- a/example/customer_database_test.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <database.h> - -extern DatabaseConnection* connect_to_customer_database(void); -extern unsigned int get_customer_id_by_name( - DatabaseConnection * const connection, const char * const customer_name); - -/* Mock query database function. */ -static unsigned int mock_query_database(DatabaseConnection* const connection, - const char * const query_string, - void *** const results) { - (void) connection; /* unused */ - (void) query_string; /* unused */ - - *results = (void **)mock_ptr_type(int *); - return mock_ptr_type(int); -} - -/* Mock of the connect to database function. */ -DatabaseConnection* connect_to_database(const char * const database_url, - const unsigned int port) { - (void) database_url; /* unused */ - (void) port; /* unused */ - - return (DatabaseConnection*)((size_t)mock()); -} - -static void test_connect_to_customer_database(void **state) { - (void) state; /* unused */ - - will_return(connect_to_database, 0x0DA7ABA53); - - assert_int_equal((size_t)connect_to_customer_database(), 0x0DA7ABA53); -} - -/* This test fails as the mock function connect_to_database() will have no - * value to return. */ -#if 0 -static void fail_connect_to_customer_database(void **state) { - (void) state; /* unused */ - - assert_true(connect_to_customer_database() == - (DatabaseConnection*)0x0DA7ABA53); -} -#endif - -static void test_get_customer_id_by_name(void **state) { - DatabaseConnection connection = { - "somedatabase.somewhere.com", 12345678, mock_query_database - }; - /* Return a single customer ID when mock_query_database() is called. */ - int customer_ids = 543; - int rc; - - (void) state; /* unused */ - - will_return(mock_query_database, - cast_ptr_to_largest_integral_type(&customer_ids)); - will_return(mock_query_database, 1); - - rc = get_customer_id_by_name(&connection, "john doe"); - assert_int_equal(rc, 543); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_connect_to_customer_database), - cmocka_unit_test(test_get_customer_id_by_name), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/example/key_value.c b/example/key_value.c deleted file mode 100644 index 057274a..0000000 --- a/example/key_value.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <stddef.h> -#include <stdlib.h> -#include <string.h> - -#include "key_value.h" - -static KeyValue *key_values = NULL; -static unsigned int number_of_key_values = 0; - -void set_key_values(KeyValue * const new_key_values, - const unsigned int new_number_of_key_values) { - key_values = new_key_values; - number_of_key_values = new_number_of_key_values; -} - -/* Compare two key members of KeyValue structures. */ -static int key_value_compare_keys(const void *a, const void *b) { - return (int)((KeyValue*)a)->key - (int)((KeyValue*)b)->key; -} - -/* Search an array of key value pairs for the item with the specified value. */ -KeyValue* find_item_by_value(const char * const value) { - unsigned int i; - for (i = 0; i < number_of_key_values; i++) { - if (strcmp(key_values[i].value, value) == 0) { - return &key_values[i]; - } - } - return NULL; -} - -/* Sort an array of key value pairs by key. */ -void sort_items_by_key(void) { - qsort(key_values, number_of_key_values, sizeof(*key_values), - key_value_compare_keys); -} diff --git a/example/key_value.h b/example/key_value.h deleted file mode 100644 index 736faf2..0000000 --- a/example/key_value.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -typedef struct KeyValue { - unsigned int key; - const char* value; -} KeyValue; - -void set_key_values(KeyValue * const new_key_values, - const unsigned int new_number_of_key_values); - -KeyValue* find_item_by_value(const char * const value); - -void sort_items_by_key(void); diff --git a/example/key_value_test.c b/example/key_value_test.c deleted file mode 100644 index 102a2be..0000000 --- a/example/key_value_test.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <string.h> -#include <cmocka.h> - -#include "key_value.h" - -static KeyValue key_values[] = { - { 10, "this" }, - { 52, "test" }, - { 20, "a" }, - { 13, "is" }, -}; - -static int create_key_values(void **state) { - KeyValue * const items = (KeyValue*)test_malloc(sizeof(key_values)); - memcpy(items, key_values, sizeof(key_values)); - *state = (void*)items; - set_key_values(items, sizeof(key_values) / sizeof(key_values[0])); - - return 0; -} - -static int destroy_key_values(void **state) { - test_free(*state); - set_key_values(NULL, 0); - - return 0; -} - -static void test_find_item_by_value(void **state) { - unsigned int i; - - (void) state; /* unused */ - - for (i = 0; i < sizeof(key_values) / sizeof(key_values[0]); i++) { - KeyValue * const found = find_item_by_value(key_values[i].value); - assert_true(found != NULL); - assert_int_equal(found->key, key_values[i].key); - assert_string_equal(found->value, key_values[i].value); - } -} - -static void test_sort_items_by_key(void **state) { - unsigned int i; - KeyValue * const kv = *state; - sort_items_by_key(); - for (i = 1; i < sizeof(key_values) / sizeof(key_values[0]); i++) { - assert_true(kv[i - 1].key < kv[i].key); - } -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_find_item_by_value, - create_key_values, destroy_key_values), - cmocka_unit_test_setup_teardown(test_sort_items_by_key, - create_key_values, destroy_key_values), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/example/mock/CMakeLists.txt b/example/mock/CMakeLists.txt new file mode 100644 index 0000000..04bbb1f --- /dev/null +++ b/example/mock/CMakeLists.txt @@ -0,0 +1,5 @@ +# TODO Execute "$CMAKE_LINKER --help" and check for --wrap +if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)" AND NOT APPLE) + add_subdirectory(chef_wrap) + add_subdirectory(uptime) +endif() diff --git a/example/chef_wrap/CMakeLists.txt b/example/mock/chef_wrap/CMakeLists.txt index 68afec0..68afec0 100644 --- a/example/chef_wrap/CMakeLists.txt +++ b/example/mock/chef_wrap/CMakeLists.txt diff --git a/example/chef_wrap/chef.c b/example/mock/chef_wrap/chef.c index 1429cde..1429cde 100644 --- a/example/chef_wrap/chef.c +++ b/example/mock/chef_wrap/chef.c diff --git a/example/chef_wrap/chef.h b/example/mock/chef_wrap/chef.h index c1a01c7..c1a01c7 100644 --- a/example/chef_wrap/chef.h +++ b/example/mock/chef_wrap/chef.h diff --git a/example/chef_wrap/waiter_test_wrap.c b/example/mock/chef_wrap/waiter_test_wrap.c index 4146818..4146818 100644 --- a/example/chef_wrap/waiter_test_wrap.c +++ b/example/mock/chef_wrap/waiter_test_wrap.c diff --git a/example/chef_wrap/waiter_test_wrap.h b/example/mock/chef_wrap/waiter_test_wrap.h index 9178ca2..9178ca2 100644 --- a/example/chef_wrap/waiter_test_wrap.h +++ b/example/mock/chef_wrap/waiter_test_wrap.h diff --git a/example/mock/uptime/CMakeLists.txt b/example/mock/uptime/CMakeLists.txt new file mode 100644 index 0000000..2464559 --- /dev/null +++ b/example/mock/uptime/CMakeLists.txt @@ -0,0 +1,20 @@ +add_library(proc_uptime proc_uptime.c) + +add_executable(uptime uptime.c) +target_compile_options(uptime PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) +target_link_libraries(uptime proc_uptime) +set_property(TARGET + uptime + PROPERTY + LINK_FLAGS + "${DEFAULT_LINK_FLAGS}") + +add_cmocka_test(test_uptime + SOURCES test_uptime.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) +set_property(TARGET + test_uptime + PROPERTY + LINK_FLAGS + "${DEFAULT_LINK_FLAGS} -Wl,--wrap=uptime") diff --git a/example/uptime/README.md b/example/mock/uptime/README.md index 081ae51..081ae51 100644 --- a/example/uptime/README.md +++ b/example/mock/uptime/README.md diff --git a/example/uptime/proc_uptime.c b/example/mock/uptime/proc_uptime.c index a92c2ab..a92c2ab 100644 --- a/example/uptime/proc_uptime.c +++ b/example/mock/uptime/proc_uptime.c diff --git a/example/uptime/proc_uptime.h b/example/mock/uptime/proc_uptime.h index 222ece5..222ece5 100644 --- a/example/uptime/proc_uptime.h +++ b/example/mock/uptime/proc_uptime.h diff --git a/example/uptime/test_uptime.c b/example/mock/uptime/test_uptime.c index 32ec79e..badfac9 100644 --- a/example/uptime/test_uptime.c +++ b/example/mock/uptime/test_uptime.c @@ -44,7 +44,7 @@ int __wrap_uptime(const char *uptime_path, double idle; /* Verify the passed value of the argument is correct */ - check_expected(uptime_path); + check_expected_ptr(uptime_path); /* Assign the return values */ up = mock_type(double); diff --git a/example/uptime/uptime.c b/example/mock/uptime/uptime.c index 77776a7..77776a7 100644 --- a/example/uptime/uptime.c +++ b/example/mock/uptime/uptime.c diff --git a/example/product_database.c b/example/product_database.c deleted file mode 100644 index 980b7e5..0000000 --- a/example/product_database.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <database.h> - -DatabaseConnection* connect_to_product_database(void); - -/* Connect to the database containing customer information. */ -DatabaseConnection* connect_to_product_database(void) { - return connect_to_database("products.abcd.org", 322); -} - diff --git a/example/product_database_test.c b/example/product_database_test.c deleted file mode 100644 index e09eeab..0000000 --- a/example/product_database_test.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <database.h> - -extern DatabaseConnection* connect_to_product_database(void); - -/* Mock connect to database function. - * NOTE: This mock function is very general could be shared between tests - * that use the imaginary database.h module. */ -DatabaseConnection* connect_to_database(const char * const url, - const unsigned int port) { - check_expected_ptr(url); - check_expected(port); - return (DatabaseConnection*)((size_t)mock()); -} - -static void test_connect_to_product_database(void **state) { - (void) state; /* unused */ - - expect_string(connect_to_database, url, "products.abcd.org"); - expect_value(connect_to_database, port, 322); - will_return(connect_to_database, 0xDA7ABA53); - assert_int_equal((size_t)connect_to_product_database(), 0xDA7ABA53); -} - -/* This test will fail since the expected URL is different to the URL that is - * passed to connect_to_database() by connect_to_product_database(). */ -static void test_connect_to_product_database_bad_url(void **state) { - (void) state; /* unused */ - - expect_string(connect_to_database, url, "products.abcd.com"); - expect_value(connect_to_database, port, 322); - will_return(connect_to_database, 0xDA7ABA53); - assert_int_equal((size_t)connect_to_product_database(), 0xDA7ABA53); -} - -/* This test will fail since the mock connect_to_database() will attempt to - * retrieve a value for the parameter port which isn't specified by this - * test function. */ -static void test_connect_to_product_database_missing_parameter(void **state) { - (void) state; /* unused */ - - expect_string(connect_to_database, url, "products.abcd.org"); - will_return(connect_to_database, 0xDA7ABA53); - assert_int_equal((size_t)connect_to_product_database(), 0xDA7ABA53); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_connect_to_product_database), - cmocka_unit_test(test_connect_to_product_database_bad_url), - cmocka_unit_test(test_connect_to_product_database_missing_parameter), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/example/uptime/CMakeLists.txt b/example/uptime/CMakeLists.txt deleted file mode 100644 index 99924bd..0000000 --- a/example/uptime/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -include_directories( - ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMOCKA_PUBLIC_INCLUDE_DIRS} -) - -add_library(proc_uptime proc_uptime.c) - -add_executable(uptime uptime.c) -target_compile_options(uptime PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) -target_link_libraries(uptime proc_uptime) - -add_executable(test_uptime test_uptime.c) -target_compile_options(test_uptime PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) -target_link_libraries(test_uptime ${CMOCKA_SHARED_LIBRARY}) - -set_target_properties(test_uptime - PROPERTIES - LINK_FLAGS "-Wl,--wrap=uptime") - -add_test(test_uptime ${CMAKE_CURRENT_BINARY_DIR}/test_uptime) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 4cca031..4e38547 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,27 +1,19 @@ -project(cmocka-headers C) +project(cmocka-header C) -set(cmocka_HDRS - cmocka.h - cmocka_pbc.h -) - -install( - FILES - ${cmocka_HDRS} - DESTINATION - ${INCLUDE_INSTALL_DIR} - COMPONENT - headers -) +install(FILES + cmocka.h + cmocka_pbc.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT + ${PROJECT_NAME}) if (WITH_CMOCKERY_SUPPORT) - install( - FILES - cmockery/cmockery.h - cmockery/pbc.h - DESTINATION - ${INCLUDE_INSTALL_DIR}/cmockery - COMPONENT - headers - ) + install(FILES + cmockery/cmockery.h + cmockery/pbc.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/cmockery + COMPONENT + ${PROJECT_NAME}) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5732232..e44ef40 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,28 +1,19 @@ project(cmocka-library C) set(CMOCKA_PLATFORM_INCLUDE CACHE PATH "Path to include directory for cmocka_platform.h") - -set(CMOCKA_PUBLIC_INCLUDE_DIRS - ${cmocka_SOURCE_DIR}/include - ${CMOCKA_PLATFORM_INCLUDE} - CACHE INTERNAL "cmocka public include directories" -) - -set(CMOCKA_PRIVATE_INCLUDE_DIRS - ${cmocka_BINARY_DIR} -) +mark_as_advanced(CMOCKA_PLATFORM_INCLUDE) set(CMOCKA_SHARED_LIBRARY - cmocka_shared + cmocka CACHE INTERNAL "cmocka shared library" ) -if (WITH_STATIC_LIB) +if (BUILD_STATIC_LIB) set(CMOCKA_STATIC_LIBRARY - cmocka_static + cmocka-static CACHE INTERNAL "cmocka static library" ) -endif (WITH_STATIC_LIB) +endif() set(CMOCKA_LINK_LIBRARIES ${CMOCKA_REQUIRED_LIBRARIES} @@ -40,27 +31,35 @@ if (WIN32) ) endif (WIN32) -include_directories( - ${CMOCKA_PUBLIC_INCLUDE_DIRS} - ${CMOCKA_PRIVATE_INCLUDE_DIRS} -) +add_library(${CMOCKA_SHARED_LIBRARY} SHARED ${cmocka_SRCS}) -add_definitions(-DHAVE_CONFIG_H=1) +target_include_directories(${CMOCKA_SHARED_LIBRARY} + PRIVATE + ${CMOCKA_PLATFORM_INCLUDE} + ${cmocka_BINARY_DIR} + PUBLIC + ${cmocka-header_SOURCE_DIR}) + + +target_compile_options(${CMOCKA_SHARED_LIBRARY} + PRIVATE + ${DEFAULT_C_COMPILE_FLAGS} + -DHAVE_CONFIG_H) if (CMOCKA_PLATFORM_INCLUDE) - add_definitions(-DCMOCKA_PLATFORM_INCLUDE=1) + target_compile_options(${CMOCKA_SHARED_LIBRARY} + PRIVATE + -DCMOCKA_PLATFORM_INCLUDE) endif() -add_library(${CMOCKA_SHARED_LIBRARY} SHARED ${cmocka_SRCS}) -target_compile_options(${CMOCKA_SHARED_LIBRARY} PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) target_link_libraries(${CMOCKA_SHARED_LIBRARY} ${CMOCKA_LINK_LIBRARIES}) -set_target_properties( - ${CMOCKA_SHARED_LIBRARY} - PROPERTIES - OUTPUT_NAME - cmocka - DEFINE_SYMBOL - CMOCKA_EXPORTS -) +set_property(TARGET + ${CMOCKA_SHARED_LIBRARY} + PROPERTY + DEFINE_SYMBOL + CMOCKA_EXPORTS + PROPERTY + LINKER_FLAGS + "${DEFAULT_LINK_FLAGS}") if (NOT WIN32) set_target_properties( @@ -73,58 +72,50 @@ if (NOT WIN32) ) endif (NOT WIN32) -install( - TARGETS ${CMOCKA_SHARED_LIBRARY} - RUNTIME DESTINATION ${BIN_INSTALL_DIR} - LIBRARY DESTINATION ${LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} - COMPONENT libraries -) +install(TARGETS + ${CMOCKA_SHARED_LIBRARY} + ARCHIVE DESTINATION + ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION + ${CMAKE_INSTALL_LIBDIR} + COMPONENT + ${PROJECT_NAME}) -if (WITH_STATIC_LIB) +if (BUILD_STATIC_LIB) add_library(${CMOCKA_STATIC_LIBRARY} STATIC ${cmocka_SRCS}) - target_compile_options(${CMOCKA_STATIC_LIBRARY} PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) - - set_target_properties( - ${CMOCKA_STATIC_LIBRARY} - PROPERTIES - VERSION - ${LIBRARY_VERSION} - SOVERSION - ${LIBRARY_SOVERSION} - OUTPUT_NAME - cmocka - ) - if (NOT WIN32) - set_target_properties( - ${CMOCKA_STATIC_LIBRARY} - PROPERTIES - OUTPUT_NAME - cmocka - ) + target_include_directories(${CMOCKA_STATIC_LIBRARY} + PRIVATE + ${CMOCKA_PLATFORM_INCLUDE} + ${cmocka_BINARY_DIR} + PUBLIC + ${cmocka-header_SOURCE_DIR}) + + target_compile_options(${CMOCKA_STATIC_LIBRARY} + PRIVATE + ${DEFAULT_C_COMPILE_FLAGS} + -DHAVE_CONFIG_H) + if (CMOCKA_PLATFORM_INCLUDE) + target_compile_options(${CMOCKA_STATIC_LIBRARY} + PRIVATE + -DCMOCKA_PLATFORM_INCLUDE) endif() - install( - TARGETS ${CMOCKA_STATIC_LIBRARY} - DESTINATION ${LIB_INSTALL_DIR} - COMPONENT libraries - ) -endif (WITH_STATIC_LIB) - -if (WIN32) - if (POLICY CMP0026) - cmake_policy(SET CMP0026 OLD) + set_property(TARGET + ${CMOCKA_STATIC_LIBRARY} + PROPERTY + DEFINE_SYMBOL + CMOCKA_EXPORTS + PROPERTY + LINK_FLAGS + "${DEFAULT_LINK_FLAGS}") + + if (WITH_STATIC_LIB) + install(TARGETS + ${CMOCKA_STATIC_LIBRARY} + ARCHIVE DESTINATION + ${CMAKE_INSTALL_LIBDIR} + COMPONENT + ${PROJECT_NAME}) endif() - -# -# In order to run tests we will need to set the approriate environment -# variable so that the test program can locate its dependent DLL's. First -# we want to know what directory our dependent DLL was installed into: -# - get_target_property(_cmocka_dir cmocka_shared LOCATION_${CMOCKA_BUILD_TYPE}) - get_filename_component(_cmocka_path "${_cmocka_dir}" PATH) - file(TO_NATIVE_PATH "${_cmocka_path}" _cmocka_path_native) - - set(CMOCKA_DLL_PATH "${_cmocka_path_native}" PARENT_SCOPE) -endif() +endif (BUILD_STATIC_LIB) diff --git a/src/cmocka.c b/src/cmocka.c index 7a68fd8..b21fe15 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -388,9 +388,15 @@ struct CMUnitTestState { /* Exit the currently executing test. */ static void exit_test(const int quit_application) { - const char *abort_test = getenv("CMOCKA_TEST_ABORT"); + const char *env = getenv("CMOCKA_TEST_ABORT"); + int abort_test = 0; - if (abort_test != NULL && abort_test[0] == '1') { + if (env != NULL && strlen(env) == 1) { + abort_test = (env[0] == '1'); + } + + if (global_skip_test == 0 && + abort_test == 1) { print_error("%s", cm_error_message); abort(); } else if (global_running_test) { @@ -686,7 +692,7 @@ static int list_find(ListNode * const head, const void *value, /* Returns the first node of a list */ static int list_first(ListNode * const head, ListNode **output) { - ListNode *target_node; + ListNode *target_node = NULL; assert_non_null(head); if (list_empty(head)) { return 0; @@ -774,8 +780,8 @@ static void add_symbol_value(ListNode * const symbol_map_head, static int get_symbol_value( ListNode * const head, const char * const symbol_names[], const size_t number_of_symbol_names, void **output) { - const char* symbol_name; - ListNode *target_node; + const char* symbol_name = NULL; + ListNode *target_node = NULL; assert_non_null(head); assert_non_null(symbol_names); assert_true(number_of_symbol_names); @@ -783,8 +789,8 @@ static int get_symbol_value( symbol_name = symbol_names[0]; if (list_find(head, symbol_name, symbol_names_match, &target_node)) { - SymbolMapValue *map_value; - ListNode *child_list; + SymbolMapValue *map_value = NULL; + ListNode *child_list = NULL; int return_value = 0; assert_non_null(target_node); assert_non_null(target_node->value); @@ -796,6 +802,10 @@ static int get_symbol_value( ListNode *value_node = NULL; return_value = list_first(child_list, &value_node); assert_true(return_value); + /* Add a check to silence clang analyzer */ + if (return_value == 0) { + goto out; + } *output = (void*) value_node->value; return_value = value_node->refcount; if (value_node->refcount - 1 == 0) { @@ -812,9 +822,9 @@ static int get_symbol_value( list_remove_free(target_node, free_symbol_map_value, (void*)0); } return return_value; - } else { - cm_print_error("No entries for symbol %s.\n", symbol_name); } +out: + cm_print_error("No entries for symbol %s.\n", symbol_name); return 0; } @@ -1597,7 +1607,7 @@ void _expect_any( void _check_expected( const char * const function_name, const char * const parameter_name, const char* file, const int line, const LargestIntegralType value) { - void *result; + void *result = NULL; const char* symbols[] = {function_name, parameter_name}; const int rc = get_symbol_value(&global_function_parameter_map_head, symbols, 2, &result); @@ -2500,7 +2510,7 @@ static void cmprintf_subunit(enum cm_printf_type type, case PRINTF_TEST_FAILURE: print_message("failure: %s", test_name); if (error_message != NULL) { - print_message(" [\n%s]\n", error_message); + print_message(" [\n%s\n]\n", error_message); } break; case PRINTF_TEST_SKIPPED: @@ -3284,7 +3294,9 @@ int _run_group_tests(const UnitTest * const tests, const size_t number_of_tests) const ListNode * const check_point = check_point_allocated_blocks(); const char **failed_names = NULL; void **current_state = NULL; - TestState group_state; + TestState group_state = { + .check_point = NULL, + }; if (number_of_tests == 0) { return -1; @@ -3417,4 +3429,3 @@ int _run_group_tests(const UnitTest * const tests, const size_t number_of_tests) return (int)total_failed; } - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2833c9f..f7ea00b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,12 @@ project(tests C) -include_directories( - ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${cmocka-headers_SOURCE_DIR} -) +set(TEST_EXCEPTION_HANDLER TRUE) +if (CMAKE_BUILD_TYPE) + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) + if (CMAKE_BUILD_TYPE_LOWER STREQUAL "undefinedsanitizer") + set(TEST_EXCEPTION_HANDLER FALSE) + endif() +endif() set(CMOCKA_TESTS test_alloc @@ -15,7 +17,6 @@ set(CMOCKA_TESTS test_groups test_assert_macros test_assert_macros_fail - test_exception_handler test_basics test_skip test_strmatch @@ -26,17 +27,28 @@ set(CMOCKA_TESTS test_returns_fail test_wildcard) +if (TEST_EXCEPTION_HANDLER) + list(APPEND CMOCKA_TESTS test_exception_handler) +endif() + foreach(_CMOCKA_TEST ${CMOCKA_TESTS}) - add_cmocka_test(${_CMOCKA_TEST} ${_CMOCKA_TEST}.c ${CMOCKA_STATIC_LIBRARY}) - target_compile_options(${_CMOCKA_TEST} PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) + add_cmocka_test(${_CMOCKA_TEST} + SOURCES ${_CMOCKA_TEST}.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES ${CMOCKA_STATIC_LIBRARY} + LINK_OPTIONS ${DEFAULT_LINK_FLAGS}) + target_include_directories(${_CMOCKA_TEST} PRIVATE ${cmocka_BINARY_DIR}) endforeach() ### Special Cases if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)") set_source_files_properties(test_cmockery.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") endif() -add_cmocka_test(test_cmockery test_cmockery.c ${CMOCKA_STATIC_LIBRARY}) -target_compile_options(test_cmockery PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) +add_cmocka_test(test_cmockery + SOURCES test_cmockery.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES ${CMOCKA_STATIC_LIBRARY} + LINK_OPTIONS ${DEFAULT_LINK_FLAGS}) ### Exceptions @@ -73,20 +85,19 @@ set_tests_properties( ) # test_exception_handler -if (WIN32) - set_tests_properties( - test_exception_handler - PROPERTIES - PASS_REGULAR_EXPRESSION - "EXCEPTION_ACCESS_VIOLATION occurred at") -else() - set_tests_properties( - test_exception_handler - PROPERTIES - PASS_REGULAR_EXPRESSION - "Test failed with exception: (Segmentation fault|Segmentation Fault|11|Illegal instruction)" - ) -endif (WIN32) +if (TEST_EXCEPTION_HANDLER) + if (WIN32) + set_tests_properties(test_exception_handler + PROPERTIES + PASS_REGULAR_EXPRESSION + "EXCEPTION_ACCESS_VIOLATION occurred at") + else() + set_tests_properties(test_exception_handler + PROPERTIES + PASS_REGULAR_EXPRESSION + "Test failed with exception: (Segmentation fault|Segmentation Fault|11|Illegal instruction)") + endif (WIN32) +endif (TEST_EXCEPTION_HANDLER) set_tests_properties( test_setup_fail @@ -109,7 +120,7 @@ set_tests_properties( 1 ) -add_test (test_setup_fail_1_failed test_setup_fail) +add_test(test_setup_fail_1_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) set_tests_properties( test_setup_fail_1_failed PROPERTIES @@ -117,7 +128,7 @@ set_tests_properties( "\\[ ERROR \\] int_test_ignored" ) -add_test (test_setup_fail_1_passed test_setup_fail) +add_test (test_setup_fail_1_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) set_tests_properties( test_setup_fail_1_passed PROPERTIES @@ -125,7 +136,7 @@ set_tests_properties( "\\[ PASSED \\] 1 test\\(s\\)." ) -add_test (test_setup_fail_match_failed test_setup_fail) +add_test (test_setup_fail_match_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) set_tests_properties( test_setup_fail_match_failed PROPERTIES @@ -133,7 +144,7 @@ set_tests_properties( "\\[ ERROR \\] int_test_ignored" ) -add_test (test_setup_fail_match_passed test_setup_fail) +add_test (test_setup_fail_match_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) set_tests_properties( test_setup_fail_match_passed PROPERTIES @@ -219,7 +230,7 @@ set(test_setup_fail_xml_out foreach(_TEST_OUTPUT_FMT ${TEST_OUTPUT_FMTS}) foreach(_OUTPUT_TEST ${OUTPUT_TESTS}) set(TEST_NAME ${_OUTPUT_TEST}_${_TEST_OUTPUT_FMT}) - add_test(${TEST_NAME} ${_OUTPUT_TEST}) + add_test(${TEST_NAME} ${TARGET_SYSTEM_EMULATOR} ${_OUTPUT_TEST}) set_property( TEST |