Imported Upstream version 1.1.3 cmocka-1.1.3
authorJinWang An <jinwang.an@samsung.com>
Tue, 27 Dec 2022 03:02:23 +0000 (12:02 +0900)
committerJinWang An <jinwang.an@samsung.com>
Tue, 27 Dec 2022 03:02:23 +0000 (12:02 +0900)
62 files changed:
.gitlab-ci.yml [new file with mode: 0644]
CMakeLists.txt
CPackConfig.cmake
ChangeLog
CompilerChecks.cmake
ConfigureChecks.cmake
DefineOptions.cmake
cmake/Modules/AddCMockaTest.cmake
cmake/Modules/CheckCCompilerFlagSSP.cmake
cmake/Modules/DefineCMakeDefaults.cmake
cmake/Modules/DefineCompilerFlags.cmake [new file with mode: 0644]
cmake/Modules/DefineInstallationPaths.cmake [deleted file]
cmake/Toolchain-cross-m32.cmake [new file with mode: 0644]
cmocka-config-version.cmake.in [deleted file]
cmocka-config.cmake.in
cmocka.pc.cmake
config.h.cmake
doc/CMakeLists.txt
doc/that_style/sass/_fragment_base.scss [deleted file]
doc/that_style/sass/_fragment_color.scss [deleted file]
doc/that_style/sass/_menu_bar.scss [deleted file]
doc/that_style/sass/_mixins.scss [deleted file]
doc/that_style/sass/_nav_tree.scss [deleted file]
doc/that_style/sass/_navpath.scss [deleted file]
doc/that_style/sass/_search.scss [deleted file]
doc/that_style/sass/that_style.scss [deleted file]
doc/that_style/that_style.css
example/CMakeLists.txt
example/chef_wrap/CMakeLists.txt [deleted file]
example/chef_wrap/chef.c [deleted file]
example/chef_wrap/chef.h [deleted file]
example/chef_wrap/waiter_test_wrap.c [deleted file]
example/chef_wrap/waiter_test_wrap.h [deleted file]
example/customer_database.c [deleted file]
example/customer_database_test.c [deleted file]
example/key_value.c [deleted file]
example/key_value.h [deleted file]
example/key_value_test.c [deleted file]
example/mock/CMakeLists.txt [new file with mode: 0644]
example/mock/chef_wrap/CMakeLists.txt [new file with mode: 0644]
example/mock/chef_wrap/chef.c [new file with mode: 0644]
example/mock/chef_wrap/chef.h [new file with mode: 0644]
example/mock/chef_wrap/waiter_test_wrap.c [new file with mode: 0644]
example/mock/chef_wrap/waiter_test_wrap.h [new file with mode: 0644]
example/mock/uptime/CMakeLists.txt [new file with mode: 0644]
example/mock/uptime/README.md [new file with mode: 0644]
example/mock/uptime/proc_uptime.c [new file with mode: 0644]
example/mock/uptime/proc_uptime.h [new file with mode: 0644]
example/mock/uptime/test_uptime.c [new file with mode: 0644]
example/mock/uptime/uptime.c [new file with mode: 0644]
example/product_database.c [deleted file]
example/product_database_test.c [deleted file]
example/uptime/CMakeLists.txt [deleted file]
example/uptime/README.md [deleted file]
example/uptime/proc_uptime.c [deleted file]
example/uptime/proc_uptime.h [deleted file]
example/uptime/test_uptime.c [deleted file]
example/uptime/uptime.c [deleted file]
include/CMakeLists.txt
src/CMakeLists.txt
src/cmocka.c
tests/CMakeLists.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644 (file)
index 0000000..75f3859
--- /dev/null
@@ -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
index d707ab576252b710e6a4932c609849e75243f16f..88408a9d670bc7feeb2beb799c9fd58acd980438 100644 (file)
@@ -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
 )
index a11f80329ce45800b3640d848a0ebf673d832d51..1af76c69323e3124520cec44a8b584e9e4697512 100644 (file)
@@ -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")
index 011041e533775203479d66ad50b7b64732a78543..2ad544d9b2a29bc3c9c508692e87eec21029061d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
index f8a7af145797ad6b603119496de8061999a5c0a5..f07929c18c396ca2dbf70899d15fb4830a460245 100644 (file)
@@ -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)
index 9bdc6f8e679c1d521d9285f8e259863554bdd00b..0e063de78c50816ed71213c27c4f3d782d4f530e 100644 (file)
@@ -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})
 
index bca0848f5428954da02925090cfbbdd2de11e85f..5bc1ef3142acf9f693b9c2ebe7e7993ea3e3859d 100644 (file)
@@ -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)
index 19de66e31e5662bdf15d9863b1e298c07dbd5469..2f45e1afa45fac4323fb821f5c29780f7c2a7cc0 100644 (file)
-# - 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)
index e421091a449d86d23ff61e2e314d3fd97a234f7a..eeaf4fca0964ad248706a41caa3ad1badf11f4f7 100644 (file)
 # 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)
index a08eca1f33c73d7b04ad1e745e09fa07b6aec749..ab0538bf2bb9ced752a16b379e3f0c02aa129546 100644 (file)
@@ -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 (file)
index 0000000..3277b99
--- /dev/null
@@ -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 (file)
index 88e08ca..0000000
+++ /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 (file)
index 0000000..7918c60
--- /dev/null
@@ -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 (file)
index 98f292c..0000000
+++ /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()
index e92ad0380d86b522b831bb67582eb2faf87c85f4..0890d71bc23d1dddea68278aebdf16b99db92205 100644 (file)
@@ -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)
index c6f7433ed511749c6684b04012ef040239531cd3..f54d0a71cc306c76751c2327efc7ef20c28830c0 100644 (file)
@@ -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}
index 1aaabb527744d4fa23c464e436bf12d67f5a1293..f8d79da2f29d1955a3e53e663c08b40ca4d11838 100644 (file)
@@ -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}"
index 4e3dc234e479f1874a7bc729c1c8d5cab30e4a1d..a7bc65e87853d0c67ac65170ba678235d59a658c 100644 (file)
@@ -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 (file)
index b46e46e..0000000
+++ /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 (file)
index 8b7977a..0000000
+++ /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 (file)
index d6aa1c3..0000000
+++ /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 (file)
index aa030de..0000000
+++ /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 (file)
index 0b265c6..0000000
+++ /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 (file)
index a266dca..0000000
+++ /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 (file)
index abd83bc..0000000
+++ /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 (file)
index f1ebf92..0000000
+++ /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;
-  }
-}
index 34c324421257b119af813a73dd93a78d59ab096b..846353ca7fc5dfbe49b2ab94f65bb274719e25d8 100644 (file)
@@ -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 */
index b672092d8df718b4a6643cd9b0ddb8f7b4ea4557..8e80ee200a8eaa1927022711f5a7dd8f5072d6ba 100644 (file)
 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/chef_wrap/CMakeLists.txt b/example/chef_wrap/CMakeLists.txt
deleted file mode 100644 (file)
index 68afec0..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-project(cmocka-wrap-examples C)
-
-include_directories(
-    ${CMAKE_BINARY_DIR}
-    ${CMAKE_CURRENT_SOURCE_DIR}
-    ${CMOCKA_PUBLIC_INCLUDE_DIRS}
-)
-
-add_executable(waiter_test_wrap waiter_test_wrap.c chef.c)
-target_link_libraries(waiter_test_wrap ${CMOCKA_SHARED_LIBRARY})
-
-add_test(waiter_test_wrap ${CMAKE_CURRENT_BINARY_DIR}/waiter_test_wrap)
-
-set_target_properties(waiter_test_wrap
-        PROPERTIES
-        LINK_FLAGS  "-Wl,--wrap=chef_cook"
-)
-if (WIN32 OR MINGW OR CYGWIN)
-    set_tests_properties(waiter_test_wrap PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
-endif (WIN32 OR MINGW OR CYGWIN)
diff --git a/example/chef_wrap/chef.c b/example/chef_wrap/chef.c
deleted file mode 100644 (file)
index 1429cde..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
- *                    Jakub Hrozek <jakub.hrozek@gmail.com>
- *
- * 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 <stdio.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include "chef.h"
-
-
-/* This is the real chef, just not implemented yet, currently it always
- * returns ENOSYS
- */
-int chef_cook(const char *order, char **dish_out)
-{
-    if (order == NULL || dish_out == NULL) return EINVAL;
-
-    return -ENOSYS;
-}
-
-/* Print chef return codes as string */
-const char *chef_strerror(int error)
-{
-    switch (error) {
-    case 0:
-        return "Success";
-    case -1:
-        return "Unknown dish";
-    case -2:
-        return "Not enough ingredients for the dish";
-    }
-
-    return "Unknown error!";
-}
-
diff --git a/example/chef_wrap/chef.h b/example/chef_wrap/chef.h
deleted file mode 100644 (file)
index c1a01c7..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
- *                    Jakub Hrozek <jakub.hrozek@gmail.com>
- *
- * 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.
- */
-
-int chef_cook(const char *order, char **dish_out);
-const char *chef_strerror(int error);
diff --git a/example/chef_wrap/waiter_test_wrap.c b/example/chef_wrap/waiter_test_wrap.c
deleted file mode 100644 (file)
index 4146818..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
- *                    Jakub Hrozek <jakub.hrozek@gmail.com>
- *
- * 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 <errno.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-
-#include "waiter_test_wrap.h"
-#include "chef.h"
-
-/*
- * This is a mocked Chef object. A real Chef would look if he knows
- * the dish in some kind of internal database and check his storage for
- * ingredients. This chef simply retrieves this information from the test
- * that is calling him.
- *
- * This object is also wrapped - if any code links with this file and is
- * compiled with linker option --wrap chef_cook, any calls of that code to
- * chef_cook will end up calling __wrap_chef_cook.
- *
- * If for any reason the wrapped function wanted to call the real chef_cook()
- * function, it could do so by calling the special symbol __real_chef_cook().
- *
- * Please note that when setting return codes for the chef_cook function, we
- * use this wrapper as a parameter for the will_return() macro, not the
- * real function.
- *
- * A chef object would return:
- * 0 - cooking dish went fine
- * -1 - unknown dish
- * -2 - ran out of ingredients for the dish
- * any other error code -- unexpected error while cooking
- *
- * The return codes should be consistent between the real and mocked objects.
- */
-int __wrap_chef_cook(const char *order, char **dish_out)
-{
-    bool has_ingredients;
-    bool knows_dish;
-    char *dish;
-
-    check_expected_ptr(order);
-
-    knows_dish = mock_type(bool);
-    if (knows_dish == false) {
-        return -1;
-    }
-
-    has_ingredients = mock_type(bool);
-    if (has_ingredients == false) {
-        return -2;
-    }
-
-    dish = mock_ptr_type(char *);
-    *dish_out = strdup(dish);
-    if (*dish_out == NULL) return ENOMEM;
-
-    return mock_type(int);
-}
-
-/* Waiter return codes:
- *  0  - success
- * -1  - kitchen failed
- * -2  - kitchen succeeded, but cooked a different food
- */
-static int waiter_process(const char *order, char **dish)
-{
-    int rv;
-
-    rv = chef_cook(order, dish);
-    if (rv != 0) {
-        fprintf(stderr, "Chef couldn't cook %s: %s\n",
-                order, chef_strerror(rv));
-        return -1;
-    }
-
-    /* Check if we received the dish we wanted from the kitchen */
-    if (strcmp(order, *dish) != 0) {
-        free(*dish);
-        *dish = NULL;
-        return -2;
-    }
-
-    return 0;
-}
-
-static void test_order_hotdog(void **state)
-{
-    int rv;
-    char *dish;
-
-    (void) state; /* unused */
-
-    /* We expect the chef to receive an order for a hotdog */
-    expect_string(__wrap_chef_cook, order, "hotdog");
-    /* And we tell the test chef that ke knows how to cook a hotdog
-     * and has the ingredients
-     */
-    will_return(__wrap_chef_cook, true);
-    will_return(__wrap_chef_cook, true);
-    /* The result will be a hotdog and the cooking process will succeed */
-    will_return(__wrap_chef_cook, cast_ptr_to_largest_integral_type("hotdog"));
-    will_return(__wrap_chef_cook, 0);
-
-    /* Test the waiter */
-    rv = waiter_process("hotdog", &dish);
-
-    /* We expect the cook to succeed cooking the hotdog */
-    assert_int_equal(rv, 0);
-    /* And actually receive one */
-    assert_string_equal(dish, "hotdog");
-    if (dish != NULL) {
-        free(dish);
-    }
-}
-
-static void test_bad_dish(void **state)
-{
-    int rv;
-    char *dish;
-
-    (void) state; /* unused */
-
-    /* We expect the chef to receive an order for a hotdog */
-    expect_string(__wrap_chef_cook, order, "hotdog");
-    /* And we tell the test chef that ke knows how to cook a hotdog
-     * and has the ingredients
-     */
-    will_return(__wrap_chef_cook, true);
-    will_return(__wrap_chef_cook, true);
-    /* The result will be a burger and the cooking process will succeed.
-     * We expect the waiter to handle the bad dish and return an error
-     * code
-     */
-    will_return(__wrap_chef_cook, cast_ptr_to_largest_integral_type("burger"));
-    will_return(__wrap_chef_cook, 0);
-
-    /* Test the waiter */
-    rv = waiter_process("hotdog", &dish);
-
-    /* According to the documentation the waiter should return -2 now */
-    assert_int_equal(rv, -2);
-    /* And do not give the bad dish to the customer */
-    assert_null(dish);
-}
-
-int main(void)
-{
-    const struct CMUnitTest tests[] = {
-        cmocka_unit_test(test_order_hotdog),
-        cmocka_unit_test(test_bad_dish),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
diff --git a/example/chef_wrap/waiter_test_wrap.h b/example/chef_wrap/waiter_test_wrap.h
deleted file mode 100644 (file)
index 9178ca2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-
-int __wrap_chef_cook(const char *order, char **dish_out);
diff --git a/example/customer_database.c b/example/customer_database.c
deleted file mode 100644 (file)
index 2d49e19..0000000
+++ /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 (file)
index 45ec782..0000000
+++ /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 (file)
index 057274a..0000000
+++ /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 (file)
index 736faf2..0000000
+++ /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 (file)
index 102a2be..0000000
+++ /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 (file)
index 0000000..04bbb1f
--- /dev/null
@@ -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/mock/chef_wrap/CMakeLists.txt b/example/mock/chef_wrap/CMakeLists.txt
new file mode 100644 (file)
index 0000000..68afec0
--- /dev/null
@@ -0,0 +1,20 @@
+project(cmocka-wrap-examples C)
+
+include_directories(
+    ${CMAKE_BINARY_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMOCKA_PUBLIC_INCLUDE_DIRS}
+)
+
+add_executable(waiter_test_wrap waiter_test_wrap.c chef.c)
+target_link_libraries(waiter_test_wrap ${CMOCKA_SHARED_LIBRARY})
+
+add_test(waiter_test_wrap ${CMAKE_CURRENT_BINARY_DIR}/waiter_test_wrap)
+
+set_target_properties(waiter_test_wrap
+        PROPERTIES
+        LINK_FLAGS  "-Wl,--wrap=chef_cook"
+)
+if (WIN32 OR MINGW OR CYGWIN)
+    set_tests_properties(waiter_test_wrap PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32 OR MINGW OR CYGWIN)
diff --git a/example/mock/chef_wrap/chef.c b/example/mock/chef_wrap/chef.c
new file mode 100644 (file)
index 0000000..1429cde
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
+ *                    Jakub Hrozek <jakub.hrozek@gmail.com>
+ *
+ * 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 <stdio.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "chef.h"
+
+
+/* This is the real chef, just not implemented yet, currently it always
+ * returns ENOSYS
+ */
+int chef_cook(const char *order, char **dish_out)
+{
+    if (order == NULL || dish_out == NULL) return EINVAL;
+
+    return -ENOSYS;
+}
+
+/* Print chef return codes as string */
+const char *chef_strerror(int error)
+{
+    switch (error) {
+    case 0:
+        return "Success";
+    case -1:
+        return "Unknown dish";
+    case -2:
+        return "Not enough ingredients for the dish";
+    }
+
+    return "Unknown error!";
+}
+
diff --git a/example/mock/chef_wrap/chef.h b/example/mock/chef_wrap/chef.h
new file mode 100644 (file)
index 0000000..c1a01c7
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
+ *                    Jakub Hrozek <jakub.hrozek@gmail.com>
+ *
+ * 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.
+ */
+
+int chef_cook(const char *order, char **dish_out);
+const char *chef_strerror(int error);
diff --git a/example/mock/chef_wrap/waiter_test_wrap.c b/example/mock/chef_wrap/waiter_test_wrap.c
new file mode 100644 (file)
index 0000000..4146818
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
+ *                    Jakub Hrozek <jakub.hrozek@gmail.com>
+ *
+ * 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 <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "waiter_test_wrap.h"
+#include "chef.h"
+
+/*
+ * This is a mocked Chef object. A real Chef would look if he knows
+ * the dish in some kind of internal database and check his storage for
+ * ingredients. This chef simply retrieves this information from the test
+ * that is calling him.
+ *
+ * This object is also wrapped - if any code links with this file and is
+ * compiled with linker option --wrap chef_cook, any calls of that code to
+ * chef_cook will end up calling __wrap_chef_cook.
+ *
+ * If for any reason the wrapped function wanted to call the real chef_cook()
+ * function, it could do so by calling the special symbol __real_chef_cook().
+ *
+ * Please note that when setting return codes for the chef_cook function, we
+ * use this wrapper as a parameter for the will_return() macro, not the
+ * real function.
+ *
+ * A chef object would return:
+ * 0 - cooking dish went fine
+ * -1 - unknown dish
+ * -2 - ran out of ingredients for the dish
+ * any other error code -- unexpected error while cooking
+ *
+ * The return codes should be consistent between the real and mocked objects.
+ */
+int __wrap_chef_cook(const char *order, char **dish_out)
+{
+    bool has_ingredients;
+    bool knows_dish;
+    char *dish;
+
+    check_expected_ptr(order);
+
+    knows_dish = mock_type(bool);
+    if (knows_dish == false) {
+        return -1;
+    }
+
+    has_ingredients = mock_type(bool);
+    if (has_ingredients == false) {
+        return -2;
+    }
+
+    dish = mock_ptr_type(char *);
+    *dish_out = strdup(dish);
+    if (*dish_out == NULL) return ENOMEM;
+
+    return mock_type(int);
+}
+
+/* Waiter return codes:
+ *  0  - success
+ * -1  - kitchen failed
+ * -2  - kitchen succeeded, but cooked a different food
+ */
+static int waiter_process(const char *order, char **dish)
+{
+    int rv;
+
+    rv = chef_cook(order, dish);
+    if (rv != 0) {
+        fprintf(stderr, "Chef couldn't cook %s: %s\n",
+                order, chef_strerror(rv));
+        return -1;
+    }
+
+    /* Check if we received the dish we wanted from the kitchen */
+    if (strcmp(order, *dish) != 0) {
+        free(*dish);
+        *dish = NULL;
+        return -2;
+    }
+
+    return 0;
+}
+
+static void test_order_hotdog(void **state)
+{
+    int rv;
+    char *dish;
+
+    (void) state; /* unused */
+
+    /* We expect the chef to receive an order for a hotdog */
+    expect_string(__wrap_chef_cook, order, "hotdog");
+    /* And we tell the test chef that ke knows how to cook a hotdog
+     * and has the ingredients
+     */
+    will_return(__wrap_chef_cook, true);
+    will_return(__wrap_chef_cook, true);
+    /* The result will be a hotdog and the cooking process will succeed */
+    will_return(__wrap_chef_cook, cast_ptr_to_largest_integral_type("hotdog"));
+    will_return(__wrap_chef_cook, 0);
+
+    /* Test the waiter */
+    rv = waiter_process("hotdog", &dish);
+
+    /* We expect the cook to succeed cooking the hotdog */
+    assert_int_equal(rv, 0);
+    /* And actually receive one */
+    assert_string_equal(dish, "hotdog");
+    if (dish != NULL) {
+        free(dish);
+    }
+}
+
+static void test_bad_dish(void **state)
+{
+    int rv;
+    char *dish;
+
+    (void) state; /* unused */
+
+    /* We expect the chef to receive an order for a hotdog */
+    expect_string(__wrap_chef_cook, order, "hotdog");
+    /* And we tell the test chef that ke knows how to cook a hotdog
+     * and has the ingredients
+     */
+    will_return(__wrap_chef_cook, true);
+    will_return(__wrap_chef_cook, true);
+    /* The result will be a burger and the cooking process will succeed.
+     * We expect the waiter to handle the bad dish and return an error
+     * code
+     */
+    will_return(__wrap_chef_cook, cast_ptr_to_largest_integral_type("burger"));
+    will_return(__wrap_chef_cook, 0);
+
+    /* Test the waiter */
+    rv = waiter_process("hotdog", &dish);
+
+    /* According to the documentation the waiter should return -2 now */
+    assert_int_equal(rv, -2);
+    /* And do not give the bad dish to the customer */
+    assert_null(dish);
+}
+
+int main(void)
+{
+    const struct CMUnitTest tests[] = {
+        cmocka_unit_test(test_order_hotdog),
+        cmocka_unit_test(test_bad_dish),
+    };
+
+    return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/example/mock/chef_wrap/waiter_test_wrap.h b/example/mock/chef_wrap/waiter_test_wrap.h
new file mode 100644 (file)
index 0000000..9178ca2
--- /dev/null
@@ -0,0 +1,2 @@
+
+int __wrap_chef_cook(const char *order, char **dish_out);
diff --git a/example/mock/uptime/CMakeLists.txt b/example/mock/uptime/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2464559
--- /dev/null
@@ -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/mock/uptime/README.md b/example/mock/uptime/README.md
new file mode 100644 (file)
index 0000000..081ae51
--- /dev/null
@@ -0,0 +1,56 @@
+The uptime mock example
+=======================
+
+This is a very simple example to explain the mocking feature of cmocka. It
+implement the 'uptime' unix command in a very simple way to demonstrate how to
+test the time calculation.
+
+The problem with testing the uptime command is that /proc/uptime constantly
+ticks. The result is random whenever you call the test. To actually test it
+we need to make sure that we work with fixed values. The mocking features
+of cmocka allows us to test it anyway!
+
+Source files
+------------
+
+* *proc_uptime.c*: This implements the `uptime()` function reading and parsing
+  the /proc/uptime file.
+* *uptime.c*: This is the actual uptime implementation, it calls
+  `calc_uptime()` to get a human readable string representation of the uptime.
+  This function calls `uptime()` from proc_uptime.c.
+* *test_uptime.c*: This is the test with the mocking function for uptime().
+
+Linking magic
+-------------
+
+The test is linked using:
+
+    ld --wrap=uptime
+
+This replaces the orginal `uptime()` function which reads from `/proc/uptime`
+with the mock function we implemented for testing `calc_uptime()`.
+
+The mock function we implemented has a special name. It is called
+`__wrap_uptime()`. All the symbols you want to mock (or replace) need to start
+with the prefix `__wrap_`. So `ld --wrap=uptime` will rename the orignal
+`uptime()` function to `__real_uptime()`. This means you can still reach the
+original function using that name and call it e.g. from the wrap function.
+The symbol `uptime` will be bound to `__wrap_uptime`.
+
+You can find more details in the manpage: `man ld`
+
+The uptime test
+---------------
+
+The code should be easy to understand. If you have a hard time following, there
+are two ways to understand how things work.
+
+You can find out details about symbol binding using:
+
+    LD_DEBUG=symbols ./example/uptime/uptime
+    LD_DEBUG=symbols ./example/uptime/test_uptime
+
+You can also use a debugger to step through the code!
+
+
+Have fun!
diff --git a/example/mock/uptime/proc_uptime.c b/example/mock/uptime/proc_uptime.c
new file mode 100644 (file)
index 0000000..a92c2ab
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
+ *
+ * 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 <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <locale.h>
+#include <unistd.h>
+
+#include "proc_uptime.h"
+
+#define UPTIME_FILE  "/proc/uptime"
+
+int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs)
+{
+    double up = 0;
+    double idle = 0;
+    char *savelocale = NULL;
+    char buf[1024] = {0};
+    ssize_t nread;
+    int fd = -1;
+    int rc;
+
+    if (uptime_path == NULL) {
+        uptime_path = UPTIME_FILE;
+    }
+
+    fd = open(uptime_path, O_RDONLY);
+    if (fd < 0) {
+        return 0;
+    }
+
+    nread = read(fd, buf, sizeof(buf));
+    close(fd);
+    if (nread < 0) {
+        return 0;
+    }
+
+    savelocale = strdup(setlocale(LC_NUMERIC, NULL));
+    if (savelocale == NULL) {
+        return 0;
+    }
+
+    setlocale(LC_NUMERIC, "C");
+    rc = sscanf(buf, "%lf %lf", &up, &idle);
+    setlocale(LC_NUMERIC, savelocale);
+    free(savelocale);
+    if (rc < 2) {
+        errno = EFAULT;
+        return 0;
+    }
+
+    if (uptime_secs != NULL) {
+        *uptime_secs = up;
+    }
+    if (idle_secs != NULL) {
+        *idle_secs = idle;
+    }
+
+    return (int)up;
+}
diff --git a/example/mock/uptime/proc_uptime.h b/example/mock/uptime/proc_uptime.h
new file mode 100644 (file)
index 0000000..222ece5
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
+ *
+ * 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.
+ */
+
+#ifndef _PROC_UPTIME_H
+#define _PROC_UPTIME_H
+
+int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs);
+
+#endif /* _PROC_UPTIME_H */
diff --git a/example/mock/uptime/test_uptime.c b/example/mock/uptime/test_uptime.c
new file mode 100644 (file)
index 0000000..badfac9
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
+ *
+ * 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>
+
+#define UNIT_TESTING 1
+#include "uptime.c"
+
+#define UNUSED(x) (void)(x)
+
+/*
+ * This is a mocked object!
+ *
+ * It is a reimplementation of the uptime() function you can find in
+ * proc_uptime.c.
+ *
+ * This function can be instrumeted by the test. We can tell it what
+ * we expect or should return.
+ */
+int __wrap_uptime(const char *uptime_path,
+                  double *uptime_secs,
+                  double *idle_secs);
+int __wrap_uptime(const char *uptime_path,
+                  double *uptime_secs,
+                  double *idle_secs)
+{
+    double up;
+    double idle;
+
+    /* Verify the passed value of the argument is correct */
+    check_expected_ptr(uptime_path);
+
+    /* Assign the return values */
+    up = mock_type(double);
+    idle = mock_type(double);
+
+    if (uptime_secs != NULL) {
+        *uptime_secs = up;
+    }
+    if (idle_secs != NULL) {
+        *idle_secs = idle;
+    }
+
+    return (int)up;
+}
+
+static void test_calc_uptime_minutes(void **state)
+{
+    char *uptime_str = NULL;
+
+    UNUSED(state);
+
+    /* Make sure the passed 'in' argument is correct */
+    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
+
+    /* We tell the uptime function what values it should return */
+    will_return(__wrap_uptime, 508.16);
+    will_return(__wrap_uptime, 72.23);
+
+    /* We call the function like we would do it normally */
+    uptime_str = calc_uptime();
+
+    /* Now lets check if the result is what we expect it to be */
+    assert_non_null(uptime_str);
+    assert_string_equal(uptime_str, "up 8 minutes");
+
+    free(uptime_str);
+}
+
+static void test_calc_uptime_hour_minute(void **state)
+{
+    char *uptime_str = NULL;
+
+    UNUSED(state);
+
+    /* Make sure the passed 'in' argument is correct */
+    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
+
+    /* We tell the uptime function what values it should return */
+    will_return(__wrap_uptime, 3699.16);
+    will_return(__wrap_uptime, 4069.23);
+
+    /* We call the function like we would do it normally */
+    uptime_str = calc_uptime();
+
+    /* Now lets check if the result is what we expect it to be */
+    assert_non_null(uptime_str);
+    assert_string_equal(uptime_str, "up 1 hour, 1 minute");
+
+    free(uptime_str);
+}
+
+static void test_calc_uptime_days_minutes(void **state)
+{
+    char *uptime_str = NULL;
+
+    UNUSED(state);
+
+    /* Make sure the passed 'in' argument is correct */
+    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
+
+    /* We tell the uptime function what values it should return */
+    will_return(__wrap_uptime, 259415.14);
+    will_return(__wrap_uptime, 262446.29);
+
+    /* We call the function like we would do it normally */
+    uptime_str = calc_uptime();
+
+    /* Now lets check if the result is what we expect it to be */
+    assert_non_null(uptime_str);
+    assert_string_equal(uptime_str, "up 3 days, 3 minutes");
+
+    free(uptime_str);
+}
+
+static void test_calc_uptime_days_hours_minutes(void **state)
+{
+    char *uptime_str = NULL;
+
+    UNUSED(state);
+
+    /* Make sure the passed 'in' argument is correct */
+    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
+
+    /* We tell the uptime function what values it should return */
+    will_return(__wrap_uptime, 359415.14);
+    will_return(__wrap_uptime, 362446.29);
+
+    /* We call the function like we would do it normally */
+    uptime_str = calc_uptime();
+
+    /* Now lets check if the result is what we expect it to be */
+    assert_non_null(uptime_str);
+    assert_string_equal(uptime_str, "up 4 days, 3 hours, 50 minutes");
+
+    free(uptime_str);
+}
+
+static void test_calc_uptime_null(void **state)
+{
+    char *uptime_str = NULL;
+
+    UNUSED(state);
+
+    /* Make sure the passed 'in' argument is correct */
+    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
+
+    will_return(__wrap_uptime, -0.0);
+    will_return(__wrap_uptime, 0.1);
+
+    uptime_str = calc_uptime();
+    assert_null(uptime_str);
+}
+
+int main(void)
+{
+    const struct CMUnitTest tests[] = {
+        cmocka_unit_test(test_calc_uptime_minutes),
+        cmocka_unit_test(test_calc_uptime_hour_minute),
+        cmocka_unit_test(test_calc_uptime_days_minutes),
+        cmocka_unit_test(test_calc_uptime_days_hours_minutes),
+        cmocka_unit_test(test_calc_uptime_null),
+    };
+
+    return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/example/mock/uptime/uptime.c b/example/mock/uptime/uptime.c
new file mode 100644 (file)
index 0000000..77776a7
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+
+#include "proc_uptime.h"
+
+static char *calc_uptime(void)
+{
+    uint32_t up_minutes, up_hours, up_days, up_weeks, up_years;
+    ssize_t pos = 0;
+    size_t comma = 0;
+    double uptime_secs, idle_secs;
+    char buf[1024] = {0};
+    int up;
+
+    up = uptime("/proc/uptime", &uptime_secs, &idle_secs);
+    if (up == 0) {
+        return NULL;
+    }
+
+    up_years = ((uint32_t)uptime_secs / (60 * 60 * 24 * 365)) % 10;
+    up_weeks = ((uint32_t)uptime_secs / (60 * 60 * 24 * 7)) % 52;
+    up_days = ((uint32_t)uptime_secs / (60 * 60 * 24)) % 7;
+
+    pos += snprintf(buf + pos, sizeof(buf) - pos, "up ");
+
+    up_minutes = (uint32_t)uptime_secs / 60;
+    up_hours = up_minutes / 60;
+    up_hours = up_hours % 24;
+    up_minutes = up_minutes % 60;
+
+    if (up_years > 0) {
+        pos += snprintf(buf + pos, sizeof(buf) - pos,
+                        "%u %s",
+                        up_years,
+                        up_years > 1 ? "years" : "year");
+        comma++;
+    }
+
+    if (up_weeks > 0) {
+        pos += snprintf(buf + pos, sizeof(buf) - pos,
+                        "%s%u %s",
+                        comma > 0 ? ", " : "",
+                        up_weeks,
+                        up_weeks > 1 ? "weeks" : "week");
+        comma++;
+    }
+
+    if (up_days > 0) {
+        pos += snprintf(buf + pos, sizeof(buf) - pos,
+                        "%s%u %s",
+                        comma > 0 ? ", " : "",
+                        up_days,
+                        up_days > 1 ? "days" : "day");
+        comma++;
+    }
+
+    if (up_hours > 0) {
+        pos += snprintf(buf + pos, sizeof(buf) - pos,
+                        "%s%u %s",
+                        comma > 0 ? ", " : "",
+                        up_hours,
+                        up_hours > 1 ? "hours" : "hour");
+        comma++;
+    }
+
+    if (up_minutes > 0 || (up_minutes == 0 && uptime_secs < 60)) {
+        pos += snprintf(buf + pos, sizeof(buf) - pos,
+                        "%s%u %s",
+                        comma > 0 ? ", " : "",
+                        up_minutes,
+                        up_minutes != 1 ? "minutes" : "minute");
+        comma++;
+    }
+
+    return strdup(buf);
+}
+
+#ifndef UNIT_TESTING
+int main(void)
+{
+    char *uptime_str = NULL;
+
+    uptime_str = calc_uptime();
+    if (uptime_str == NULL) {
+        fprintf(stderr, "Failed to read uptime\n");
+        return 1;
+    }
+
+    printf("%s\n", uptime_str);
+
+    free(uptime_str);
+
+    return 0;
+}
+#endif /* UNIT_TESTING */
diff --git a/example/product_database.c b/example/product_database.c
deleted file mode 100644 (file)
index 980b7e5..0000000
+++ /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 (file)
index e09eeab..0000000
+++ /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 (file)
index 99924bd..0000000
+++ /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/example/uptime/README.md b/example/uptime/README.md
deleted file mode 100644 (file)
index 081ae51..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-The uptime mock example
-=======================
-
-This is a very simple example to explain the mocking feature of cmocka. It
-implement the 'uptime' unix command in a very simple way to demonstrate how to
-test the time calculation.
-
-The problem with testing the uptime command is that /proc/uptime constantly
-ticks. The result is random whenever you call the test. To actually test it
-we need to make sure that we work with fixed values. The mocking features
-of cmocka allows us to test it anyway!
-
-Source files
-------------
-
-* *proc_uptime.c*: This implements the `uptime()` function reading and parsing
-  the /proc/uptime file.
-* *uptime.c*: This is the actual uptime implementation, it calls
-  `calc_uptime()` to get a human readable string representation of the uptime.
-  This function calls `uptime()` from proc_uptime.c.
-* *test_uptime.c*: This is the test with the mocking function for uptime().
-
-Linking magic
--------------
-
-The test is linked using:
-
-    ld --wrap=uptime
-
-This replaces the orginal `uptime()` function which reads from `/proc/uptime`
-with the mock function we implemented for testing `calc_uptime()`.
-
-The mock function we implemented has a special name. It is called
-`__wrap_uptime()`. All the symbols you want to mock (or replace) need to start
-with the prefix `__wrap_`. So `ld --wrap=uptime` will rename the orignal
-`uptime()` function to `__real_uptime()`. This means you can still reach the
-original function using that name and call it e.g. from the wrap function.
-The symbol `uptime` will be bound to `__wrap_uptime`.
-
-You can find more details in the manpage: `man ld`
-
-The uptime test
----------------
-
-The code should be easy to understand. If you have a hard time following, there
-are two ways to understand how things work.
-
-You can find out details about symbol binding using:
-
-    LD_DEBUG=symbols ./example/uptime/uptime
-    LD_DEBUG=symbols ./example/uptime/test_uptime
-
-You can also use a debugger to step through the code!
-
-
-Have fun!
diff --git a/example/uptime/proc_uptime.c b/example/uptime/proc_uptime.c
deleted file mode 100644 (file)
index a92c2ab..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
- *
- * 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 <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <locale.h>
-#include <unistd.h>
-
-#include "proc_uptime.h"
-
-#define UPTIME_FILE  "/proc/uptime"
-
-int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs)
-{
-    double up = 0;
-    double idle = 0;
-    char *savelocale = NULL;
-    char buf[1024] = {0};
-    ssize_t nread;
-    int fd = -1;
-    int rc;
-
-    if (uptime_path == NULL) {
-        uptime_path = UPTIME_FILE;
-    }
-
-    fd = open(uptime_path, O_RDONLY);
-    if (fd < 0) {
-        return 0;
-    }
-
-    nread = read(fd, buf, sizeof(buf));
-    close(fd);
-    if (nread < 0) {
-        return 0;
-    }
-
-    savelocale = strdup(setlocale(LC_NUMERIC, NULL));
-    if (savelocale == NULL) {
-        return 0;
-    }
-
-    setlocale(LC_NUMERIC, "C");
-    rc = sscanf(buf, "%lf %lf", &up, &idle);
-    setlocale(LC_NUMERIC, savelocale);
-    free(savelocale);
-    if (rc < 2) {
-        errno = EFAULT;
-        return 0;
-    }
-
-    if (uptime_secs != NULL) {
-        *uptime_secs = up;
-    }
-    if (idle_secs != NULL) {
-        *idle_secs = idle;
-    }
-
-    return (int)up;
-}
diff --git a/example/uptime/proc_uptime.h b/example/uptime/proc_uptime.h
deleted file mode 100644 (file)
index 222ece5..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
- *
- * 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.
- */
-
-#ifndef _PROC_UPTIME_H
-#define _PROC_UPTIME_H
-
-int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs);
-
-#endif /* _PROC_UPTIME_H */
diff --git a/example/uptime/test_uptime.c b/example/uptime/test_uptime.c
deleted file mode 100644 (file)
index 32ec79e..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
- *
- * 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>
-
-#define UNIT_TESTING 1
-#include "uptime.c"
-
-#define UNUSED(x) (void)(x)
-
-/*
- * This is a mocked object!
- *
- * It is a reimplementation of the uptime() function you can find in
- * proc_uptime.c.
- *
- * This function can be instrumeted by the test. We can tell it what
- * we expect or should return.
- */
-int __wrap_uptime(const char *uptime_path,
-                  double *uptime_secs,
-                  double *idle_secs);
-int __wrap_uptime(const char *uptime_path,
-                  double *uptime_secs,
-                  double *idle_secs)
-{
-    double up;
-    double idle;
-
-    /* Verify the passed value of the argument is correct */
-    check_expected(uptime_path);
-
-    /* Assign the return values */
-    up = mock_type(double);
-    idle = mock_type(double);
-
-    if (uptime_secs != NULL) {
-        *uptime_secs = up;
-    }
-    if (idle_secs != NULL) {
-        *idle_secs = idle;
-    }
-
-    return (int)up;
-}
-
-static void test_calc_uptime_minutes(void **state)
-{
-    char *uptime_str = NULL;
-
-    UNUSED(state);
-
-    /* Make sure the passed 'in' argument is correct */
-    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
-
-    /* We tell the uptime function what values it should return */
-    will_return(__wrap_uptime, 508.16);
-    will_return(__wrap_uptime, 72.23);
-
-    /* We call the function like we would do it normally */
-    uptime_str = calc_uptime();
-
-    /* Now lets check if the result is what we expect it to be */
-    assert_non_null(uptime_str);
-    assert_string_equal(uptime_str, "up 8 minutes");
-
-    free(uptime_str);
-}
-
-static void test_calc_uptime_hour_minute(void **state)
-{
-    char *uptime_str = NULL;
-
-    UNUSED(state);
-
-    /* Make sure the passed 'in' argument is correct */
-    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
-
-    /* We tell the uptime function what values it should return */
-    will_return(__wrap_uptime, 3699.16);
-    will_return(__wrap_uptime, 4069.23);
-
-    /* We call the function like we would do it normally */
-    uptime_str = calc_uptime();
-
-    /* Now lets check if the result is what we expect it to be */
-    assert_non_null(uptime_str);
-    assert_string_equal(uptime_str, "up 1 hour, 1 minute");
-
-    free(uptime_str);
-}
-
-static void test_calc_uptime_days_minutes(void **state)
-{
-    char *uptime_str = NULL;
-
-    UNUSED(state);
-
-    /* Make sure the passed 'in' argument is correct */
-    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
-
-    /* We tell the uptime function what values it should return */
-    will_return(__wrap_uptime, 259415.14);
-    will_return(__wrap_uptime, 262446.29);
-
-    /* We call the function like we would do it normally */
-    uptime_str = calc_uptime();
-
-    /* Now lets check if the result is what we expect it to be */
-    assert_non_null(uptime_str);
-    assert_string_equal(uptime_str, "up 3 days, 3 minutes");
-
-    free(uptime_str);
-}
-
-static void test_calc_uptime_days_hours_minutes(void **state)
-{
-    char *uptime_str = NULL;
-
-    UNUSED(state);
-
-    /* Make sure the passed 'in' argument is correct */
-    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
-
-    /* We tell the uptime function what values it should return */
-    will_return(__wrap_uptime, 359415.14);
-    will_return(__wrap_uptime, 362446.29);
-
-    /* We call the function like we would do it normally */
-    uptime_str = calc_uptime();
-
-    /* Now lets check if the result is what we expect it to be */
-    assert_non_null(uptime_str);
-    assert_string_equal(uptime_str, "up 4 days, 3 hours, 50 minutes");
-
-    free(uptime_str);
-}
-
-static void test_calc_uptime_null(void **state)
-{
-    char *uptime_str = NULL;
-
-    UNUSED(state);
-
-    /* Make sure the passed 'in' argument is correct */
-    expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
-
-    will_return(__wrap_uptime, -0.0);
-    will_return(__wrap_uptime, 0.1);
-
-    uptime_str = calc_uptime();
-    assert_null(uptime_str);
-}
-
-int main(void)
-{
-    const struct CMUnitTest tests[] = {
-        cmocka_unit_test(test_calc_uptime_minutes),
-        cmocka_unit_test(test_calc_uptime_hour_minute),
-        cmocka_unit_test(test_calc_uptime_days_minutes),
-        cmocka_unit_test(test_calc_uptime_days_hours_minutes),
-        cmocka_unit_test(test_calc_uptime_null),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
diff --git a/example/uptime/uptime.c b/example/uptime/uptime.c
deleted file mode 100644 (file)
index 77776a7..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <time.h>
-#include <sys/time.h>
-
-#include "proc_uptime.h"
-
-static char *calc_uptime(void)
-{
-    uint32_t up_minutes, up_hours, up_days, up_weeks, up_years;
-    ssize_t pos = 0;
-    size_t comma = 0;
-    double uptime_secs, idle_secs;
-    char buf[1024] = {0};
-    int up;
-
-    up = uptime("/proc/uptime", &uptime_secs, &idle_secs);
-    if (up == 0) {
-        return NULL;
-    }
-
-    up_years = ((uint32_t)uptime_secs / (60 * 60 * 24 * 365)) % 10;
-    up_weeks = ((uint32_t)uptime_secs / (60 * 60 * 24 * 7)) % 52;
-    up_days = ((uint32_t)uptime_secs / (60 * 60 * 24)) % 7;
-
-    pos += snprintf(buf + pos, sizeof(buf) - pos, "up ");
-
-    up_minutes = (uint32_t)uptime_secs / 60;
-    up_hours = up_minutes / 60;
-    up_hours = up_hours % 24;
-    up_minutes = up_minutes % 60;
-
-    if (up_years > 0) {
-        pos += snprintf(buf + pos, sizeof(buf) - pos,
-                        "%u %s",
-                        up_years,
-                        up_years > 1 ? "years" : "year");
-        comma++;
-    }
-
-    if (up_weeks > 0) {
-        pos += snprintf(buf + pos, sizeof(buf) - pos,
-                        "%s%u %s",
-                        comma > 0 ? ", " : "",
-                        up_weeks,
-                        up_weeks > 1 ? "weeks" : "week");
-        comma++;
-    }
-
-    if (up_days > 0) {
-        pos += snprintf(buf + pos, sizeof(buf) - pos,
-                        "%s%u %s",
-                        comma > 0 ? ", " : "",
-                        up_days,
-                        up_days > 1 ? "days" : "day");
-        comma++;
-    }
-
-    if (up_hours > 0) {
-        pos += snprintf(buf + pos, sizeof(buf) - pos,
-                        "%s%u %s",
-                        comma > 0 ? ", " : "",
-                        up_hours,
-                        up_hours > 1 ? "hours" : "hour");
-        comma++;
-    }
-
-    if (up_minutes > 0 || (up_minutes == 0 && uptime_secs < 60)) {
-        pos += snprintf(buf + pos, sizeof(buf) - pos,
-                        "%s%u %s",
-                        comma > 0 ? ", " : "",
-                        up_minutes,
-                        up_minutes != 1 ? "minutes" : "minute");
-        comma++;
-    }
-
-    return strdup(buf);
-}
-
-#ifndef UNIT_TESTING
-int main(void)
-{
-    char *uptime_str = NULL;
-
-    uptime_str = calc_uptime();
-    if (uptime_str == NULL) {
-        fprintf(stderr, "Failed to read uptime\n");
-        return 1;
-    }
-
-    printf("%s\n", uptime_str);
-
-    free(uptime_str);
-
-    return 0;
-}
-#endif /* UNIT_TESTING */
index 4cca0316b99c7add6d7059cdd47ad1a32b94be25..4e38547fffca45a58b81a1f908169bb76563c07e 100644 (file)
@@ -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()
index 5732232f31426f05be24bfe8cf1e5194cd11c74e..e44ef40cd18e4435a49be4c6e5fc295dff6c6cc3 100644 (file)
@@ -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)
index 7a68fd800734607789a86853c603dd5b7a29fa06..b21fe15536c9d9e5bd51c2bd78ced96a992fbd69 100644 (file)
@@ -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;
 }
-
index 2833c9f541ce627dd532003dff98de64c2418dcd..f7ea00b7be6203a1e0aab1ed1b5492b311c24dbd 100644 (file)
@@ -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