summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Versace <chad.versace@linux.intel.com>2013-11-27 15:22:32 -0800
committerChad Versace <chad.versace@linux.intel.com>2013-11-27 16:31:18 -0800
commiteef00229991392863fdc0a82a6779e141aae28bb (patch)
treea0a7c270b0e643b2db9bfc2638e2437d91f2518e
parent5c91ae5a957d66d75ecdabbc25699e4374dadba7 (diff)
parentd5eff09f6ca288b1f2416633e28b599d64858b9c (diff)
cmocka: Add subtree from tag cmocka-0.3.2
Shell-Command: \ git-subtree add --prefix=third_party/cmocka --squash \ git://git.cryptomilk.org/projects/cmocka.git \ refs/tags/cmocka-0.3.2 Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r--third_party/cmocka/.clang_complete1
-rw-r--r--third_party/cmocka/.gitignore5
-rw-r--r--third_party/cmocka/AUTHORS3
-rw-r--r--third_party/cmocka/CMakeLists.txt67
-rw-r--r--third_party/cmocka/COPYING202
-rw-r--r--third_party/cmocka/CPackConfig.cmake53
-rw-r--r--third_party/cmocka/CTestConfig.cmake10
-rw-r--r--third_party/cmocka/ChangeLog45
-rw-r--r--third_party/cmocka/ConfigureChecks.cmake99
-rw-r--r--third_party/cmocka/DefineOptions.cmake2
-rw-r--r--third_party/cmocka/INSTALL75
-rw-r--r--third_party/cmocka/NEWS0
-rw-r--r--third_party/cmocka/README15
-rw-r--r--third_party/cmocka/cmake/Modules/AddCMockaTest.cmake23
-rw-r--r--third_party/cmocka/cmake/Modules/COPYING-CMAKE-SCRIPTS22
-rw-r--r--third_party/cmocka/cmake/Modules/CheckCCompilerFlagSSP.cmake26
-rw-r--r--third_party/cmocka/cmake/Modules/DefineCMakeDefaults.cmake27
-rw-r--r--third_party/cmocka/cmake/Modules/DefineCompilerFlags.cmake82
-rw-r--r--third_party/cmocka/cmake/Modules/DefineInstallationPaths.cmake103
-rw-r--r--third_party/cmocka/cmake/Modules/DefinePlatformDefaults.cmake21
-rw-r--r--third_party/cmocka/cmake/Modules/FindNSIS.cmake51
-rw-r--r--third_party/cmocka/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake17
-rw-r--r--third_party/cmocka/cmake/Modules/UseDoxygen.cmake100
-rw-r--r--third_party/cmocka/cmocka.pc.cmake6
-rw-r--r--third_party/cmocka/config.h.cmake138
-rw-r--r--third_party/cmocka/coverity/README9
-rw-r--r--third_party/cmocka/coverity/coverity_assert_model.c77
-rw-r--r--third_party/cmocka/coverity/coverity_internal_model.c5
-rw-r--r--third_party/cmocka/doc/CMakeLists.txt5
-rw-r--r--third_party/cmocka/doc/doxy.config.in1917
-rw-r--r--third_party/cmocka/doc/index.html706
-rw-r--r--third_party/cmocka/doc/mainpage.dox88
-rw-r--r--third_party/cmocka/example/CMakeLists.txt90
-rw-r--r--third_party/cmocka/example/allocate_module.c55
-rw-r--r--third_party/cmocka/example/allocate_module_test.c53
-rw-r--r--third_party/cmocka/example/assert_macro.c39
-rw-r--r--third_party/cmocka/example/assert_macro.h2
-rw-r--r--third_party/cmocka/example/assert_macro_test.c46
-rw-r--r--third_party/cmocka/example/assert_module.c38
-rw-r--r--third_party/cmocka/example/assert_module.h18
-rw-r--r--third_party/cmocka/example/assert_module_test.c56
-rw-r--r--third_party/cmocka/example/calculator.c286
-rw-r--r--third_party/cmocka/example/calculator_test.c480
-rw-r--r--third_party/cmocka/example/chef_wrap/CMakeLists.txt17
-rw-r--r--third_party/cmocka/example/chef_wrap/chef.c54
-rw-r--r--third_party/cmocka/example/chef_wrap/chef.h19
-rw-r--r--third_party/cmocka/example/chef_wrap/waiter_test_wrap.c176
-rw-r--r--third_party/cmocka/example/chef_wrap/waiter_test_wrap.h2
-rw-r--r--third_party/cmocka/example/customer_database.c51
-rw-r--r--third_party/cmocka/example/customer_database_test.c88
-rw-r--r--third_party/cmocka/example/database.h37
-rw-r--r--third_party/cmocka/example/fixture_test.c37
-rw-r--r--third_party/cmocka/example/key_value.c51
-rw-r--r--third_party/cmocka/example/key_value.h27
-rw-r--r--third_party/cmocka/example/key_value_test.c73
-rw-r--r--third_party/cmocka/example/product_database.c24
-rw-r--r--third_party/cmocka/example/product_database_test.c72
-rw-r--r--third_party/cmocka/example/run_tests.c54
-rw-r--r--third_party/cmocka/include/CMakeLists.txt14
-rw-r--r--third_party/cmocka/include/cmocka.h1736
-rw-r--r--third_party/cmocka/include/cmocka_private.h56
-rw-r--r--third_party/cmocka/src/CMakeLists.txt92
-rw-r--r--third_party/cmocka/src/cmocka.c1856
-rw-r--r--third_party/cmocka/src/cmocka.def42
64 files changed, 9741 insertions, 0 deletions
diff --git a/third_party/cmocka/.clang_complete b/third_party/cmocka/.clang_complete
new file mode 100644
index 0000000..30679be
--- /dev/null
+++ b/third_party/cmocka/.clang_complete
@@ -0,0 +1 @@
+-Iinclude
diff --git a/third_party/cmocka/.gitignore b/third_party/cmocka/.gitignore
new file mode 100644
index 0000000..e4254b6
--- /dev/null
+++ b/third_party/cmocka/.gitignore
@@ -0,0 +1,5 @@
+*.swp
+*~$
+build
+tags
+cscope.*
diff --git a/third_party/cmocka/AUTHORS b/third_party/cmocka/AUTHORS
new file mode 100644
index 0000000..0655e3f
--- /dev/null
+++ b/third_party/cmocka/AUTHORS
@@ -0,0 +1,3 @@
+opensource@google.com
+Andreas Schneider <asn@cryptomilk.org>
+Jakub Hrozek <jhrozek@redhat.com>
diff --git a/third_party/cmocka/CMakeLists.txt b/third_party/cmocka/CMakeLists.txt
new file mode 100644
index 0000000..7926cee
--- /dev/null
+++ b/third_party/cmocka/CMakeLists.txt
@@ -0,0 +1,67 @@
+project(cmocka C)
+
+# Required cmake version
+cmake_minimum_required(VERSION 2.6.0)
+
+# global needed variables
+set(APPLICATION_NAME ${PROJECT_NAME})
+
+set(APPLICATION_VERSION_MAJOR "0")
+set(APPLICATION_VERSION_MINOR "3")
+set(APPLICATION_VERSION_PATCH "2")
+
+set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
+
+# SOVERSION scheme: CURRENT.AGE.REVISION
+# If there was an incompatible interface change:
+# Increment CURRENT. Set AGE and REVISION to 0
+# If there was a compatible interface change:
+# Increment AGE. Set REVISION to 0
+# If the source code was changed, but there were no interface changes:
+# Increment REVISION.
+set(LIBRARY_VERSION "0.1.2")
+set(LIBRARY_SOVERSION "0")
+
+# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
+set(CMAKE_MODULE_PATH
+ ${CMAKE_SOURCE_DIR}/cmake/Modules
+)
+
+# add definitions
+include(DefineCMakeDefaults)
+include(DefinePlatformDefaults)
+include(DefineCompilerFlags)
+include(DefineInstallationPaths)
+include(DefineOptions.cmake)
+include(CPackConfig.cmake)
+
+if (UNIT_TESTING)
+ include(AddCMockaTest)
+endif (UNIT_TESTING)
+
+# disallow in-source build
+include(MacroEnsureOutOfSourceBuild)
+macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
+
+# config.h checks
+include(ConfigureChecks.cmake)
+configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+# check subdirectories
+add_subdirectory(doc)
+add_subdirectory(include)
+add_subdirectory(src)
+if (UNIT_TESTING)
+ add_subdirectory(example)
+endif (UNIT_TESTING)
+
+# pkg-config file
+configure_file(cmocka.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc)
+install(
+ FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc
+ DESTINATION
+ ${LIB_INSTALL_DIR}/pkgconfig
+ COMPONENT
+ pkgconfig
+)
diff --git a/third_party/cmocka/COPYING b/third_party/cmocka/COPYING
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/third_party/cmocka/COPYING
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/third_party/cmocka/CPackConfig.cmake b/third_party/cmocka/CPackConfig.cmake
new file mode 100644
index 0000000..25d922a
--- /dev/null
+++ b/third_party/cmocka/CPackConfig.cmake
@@ -0,0 +1,53 @@
+# For help take a look at:
+# http://www.cmake.org/Wiki/CMake:CPackConfiguration
+
+### general settings
+set(CPACK_PACKAGE_NAME ${APPLICATION_NAME})
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unit testing framework for C with mock objects")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
+set(CPACK_PACKAGE_VENDOR "Andreas Schneider")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_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}")
+
+
+### source generator
+set(CPACK_SOURCE_GENERATOR "TGZ")
+set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;tags;cscope.*")
+set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
+
+if (WIN32)
+ set(CPACK_GENERATOR "ZIP")
+
+ ### nsis generator
+ find_package(NSIS)
+ if (NSIS_MAKE)
+ set(CPACK_GENERATOR "${CPACK_GENERATOR};NSIS")
+ set(CPACK_NSIS_DISPLAY_NAME "CMocka")
+ set(CPACK_NSIS_COMPRESSOR "/SOLID zlib")
+ set(CPACK_NSIS_MENU_LINKS "http://cmocka.org/" "cmocka homepage")
+ endif (NSIS_MAKE)
+endif (WIN32)
+
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "cmocka")
+
+set(CPACK_PACKAGE_FILE_NAME ${APPLICATION_NAME}-${CPACK_PACKAGE_VERSION})
+
+set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
+set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers")
+set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
+ "Libraries used to build programs which use cmocka")
+set(CPACK_COMPONENT_HEADERS_DESCRIPTION
+ "C/C++ header files for use with cmocka")
+set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
+#set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
+set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
+set(CPACK_COMPONENT_HEADERS_GROUP "Development")
+
+include(CPack)
diff --git a/third_party/cmocka/CTestConfig.cmake b/third_party/cmocka/CTestConfig.cmake
new file mode 100644
index 0000000..30a2155
--- /dev/null
+++ b/third_party/cmocka/CTestConfig.cmake
@@ -0,0 +1,10 @@
+set(UPDATE_TYPE "true")
+
+set(CTEST_PROJECT_NAME "cmocka")
+set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
+
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "mock.cryptomilk.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=${CTEST_PROJECT_NAME}")
+set(CTEST_DROP_SITE_CDASH TRUE)
+
diff --git a/third_party/cmocka/ChangeLog b/third_party/cmocka/ChangeLog
new file mode 100644
index 0000000..074161d
--- /dev/null
+++ b/third_party/cmocka/ChangeLog
@@ -0,0 +1,45 @@
+Wed Nov 06 2013 Andreas Schneider <asn@cryptomilk.org>
+ * cmocka: version 0.3.2
+ * Fixed FindNSIS detection.
+ * Fixed unit_test_setup() and unit_test_teardown().
+ * Fixed GTest and GCC message style conformance
+ * Fixed stringification in will_return_always().
+
+Wed Jul 10 15:24 2013 Andreas Schneider <asn@cryptomilk.org>
+ * cmocka: version 0.3.1
+ * Fixed pointer conversion on s390 and ppc (32bit big endian).
+ * Fixed the customer_database test on big endian.
+
+Wed Jun 05 08:14 2013 Andreas Schneider <asn@cryptomilk.org>
+ * cmocka: version 0.3.0
+ * Added a better mock object example.
+ * Added pkgconfig file.
+ * Added new macros mock_type() and mock_ptr_type().
+ * Added more documentation.
+ * Fixed installation problems on some platforms.
+
+Mon Jan 14 11:16 2013 Andreas Schneider <asn@cryptomilk.org>
+ * cmocka: version 0.2.0
+ * Added doxygen api documentation.
+ * Added new cmake build system.
+ * Added support to create windows NSIS installer.
+ * Fixed examples which didn't work.
+ * Fixed a huge amount of bugs.
+
+Mon Sep 15 17:21:22 2008 Google Inc. <opensource@google.com>
+ * cmockery: version 0.12
+ * Made it possible to specify additional compiler, lib tool and link
+ flags on Windows.
+ * Added Windows makefile to the tar ball.
+
+Fri Aug 29 10:50:46 2008 Google Inc. <opensource@google.com>
+
+ * cmockery: version 0.11
+ * Made it possible to specify executable, library and object output
+ directories.
+
+Tue Aug 26 10:18:02 2008 Google Inc. <opensource@google.com>
+
+ * cmockery: initial release:
+ A lightweight library to simplify and generalize the process of
+ writing unit tests for C applications.
diff --git a/third_party/cmocka/ConfigureChecks.cmake b/third_party/cmocka/ConfigureChecks.cmake
new file mode 100644
index 0000000..0d62529
--- /dev/null
+++ b/third_party/cmocka/ConfigureChecks.cmake
@@ -0,0 +1,99 @@
+include(CheckIncludeFile)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckLibraryExists)
+include(CheckTypeSize)
+include(CheckCXXSourceCompiles)
+include(TestBigEndian)
+
+set(PACKAGE ${APPLICATION_NAME})
+set(VERSION ${APPLICATION_VERSION})
+set(DATADIR ${DATA_INSTALL_DIR})
+set(LIBDIR ${LIB_INSTALL_DIR})
+set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
+set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
+
+set(BINARYDIR ${CMAKE_BINARY_DIR})
+set(SOURCEDIR ${CMAKE_SOURCE_DIR})
+
+function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
+ # Remove whitespaces from the argument.
+ # This is needed for CC="ccache gcc" cmake ..
+ string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
+
+ execute_process(
+ COMMAND
+ ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
+ OUTPUT_VARIABLE _COMPILER_VERSION
+ )
+
+ string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
+ _COMPILER_VERSION ${_COMPILER_VERSION})
+
+ set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
+endfunction()
+
+if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
+ compiler_dumpversion(GNUCC_VERSION)
+ if (NOT GNUCC_VERSION EQUAL 34)
+ check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
+ endif (NOT GNUCC_VERSION EQUAL 34)
+endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
+
+# DEFINITIONS
+if (SOLARIS)
+ add_definitions(-D__EXTENSIONS__)
+endif (SOLARIS)
+
+# HEADER FILES
+check_include_file(assert.h HAVE_ASSERT_H)
+check_include_file(inttypes.h HAVE_INTTYPES_H)
+check_include_file(malloc.h HAVE_MALLOC_H)
+check_include_file(memory.h HAVE_MEMORY_H)
+check_include_file(setjmp.h HAVE_SETJMP_H)
+check_include_file(signal.h HAVE_SIGNAL_H)
+check_include_file(stdarg.h HAVE_STDARG_H)
+check_include_file(stddef.h HAVE_STDDEF_H)
+check_include_file(stdint.h HAVE_STDINT_H)
+check_include_file(stdio.h HAVE_STDIO_H)
+check_include_file(stdlib.h HAVE_STDLIB_H)
+check_include_file(string.h HAVE_STRING_H)
+check_include_file(strings.h HAVE_STRINGS_H)
+check_include_file(sys/stat.h HAVE_SYS_STAT_H)
+check_include_file(sys/types.h HAVE_SYS_TYPES_H)
+check_include_file(unistd.h HAVE_UNISTD_H)
+
+
+# FUNCTIONS
+check_function_exists(calloc HAVE_CALLOC)
+check_function_exists(exit HAVE_EXIT)
+check_function_exists(fprintf HAVE_FPRINTF)
+check_function_exists(free HAVE_FREE)
+check_function_exists(longjmp HAVE_LONGJMP)
+check_function_exists(malloc HAVE_MALLOC)
+check_function_exists(memcpy HAVE_MEMCPY)
+check_function_exists(memset HAVE_MEMSET)
+check_function_exists(printf HAVE_PRINTF)
+check_function_exists(setjmp HAVE_SETJMP)
+check_function_exists(signal HAVE_SIGNAL)
+check_function_exists(strsignal HAVE_STRSIGNAL)
+check_function_exists(sprintf HAVE_SNPRINTF)
+check_function_exists(strcmp HAVE_STRCMP)
+check_function_exists(vsnprintf HAVE_VSNPRINTF)
+
+if (WIN32)
+ check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
+ check_function_exists(_vsnprintf HAVE__VSNPRINTF)
+ check_function_exists(_snprintf HAVE__SNPRINTF)
+ check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
+endif (WIN32)
+
+set(CMOCKA_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "cmocka required system libraries")
+
+# OPTIONS
+
+# ENDIAN
+if (NOT WIN32)
+ set(WORDS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
+ test_big_endian(WORDS_BIGENDIAN)
+endif (NOT WIN32)
diff --git a/third_party/cmocka/DefineOptions.cmake b/third_party/cmocka/DefineOptions.cmake
new file mode 100644
index 0000000..86b94fb
--- /dev/null
+++ b/third_party/cmocka/DefineOptions.cmake
@@ -0,0 +1,2 @@
+option(WITH_STATIC_LIB "Build with a static library" OFF)
+option(UNIT_TESTING "Build with unit testing" OFF)
diff --git a/third_party/cmocka/INSTALL b/third_party/cmocka/INSTALL
new file mode 100644
index 0000000..9cb1b03
--- /dev/null
+++ b/third_party/cmocka/INSTALL
@@ -0,0 +1,75 @@
+# How to build from source
+
+## Requirements
+
+### Common requirements
+
+In order to build cmocka, you need to install several components:
+
+- A C compiler
+- [CMake](http://www.cmake.org) >= 2.8.0.
+
+Note that these version numbers are version we know works correctly. If you
+build and run cmocka successfully with an older version, please let us know.
+
+## Building
+First, you need to configure the compilation, using CMake. Go inside the
+`build` dir. Create it if it doesn't exist.
+
+GNU/Linux, MacOS X, MSYS/MinGW:
+
+ cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
+ make
+
+On Windows you should choose a makefile gernerator with -G.
+
+### CMake standard options
+Here is a list of the most interesting options provided out of the box by
+CMake.
+
+- CMAKE_BUILD_TYPE: The type of build (can be Debug Release MinSizeRel
+ RelWithDebInfo)
+- CMAKE_INSTALL_PREFIX: The prefix to use when running make install (Default
+ to /usr/local on GNU/Linux and MacOS X)
+- CMAKE_C_COMPILER: The path to the C compiler
+- CMAKE_CXX_COMPILER: The path to the C++ compiler
+
+### CMake options defined for cmocka
+
+Options are defined in the following files:
+
+- DefineOptions.cmake
+
+They can be changed with the -D option:
+
+`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..`
+
+### Browsing/editing CMake options
+
+In addition to passing options on the command line, you can browse and edit
+CMake options using `cmakesetup` (Windows), `cmake-gui` or `ccmake` (GNU/Linux
+and MacOS X).
+
+- Go to the build dir
+- On Windows: run `cmakesetup`
+- On GNU/Linux and MacOS X: run `ccmake ..`
+
+## Installing
+
+If you want to install cmocka after compilation run:
+
+ make install
+
+## Running
+
+The cmocka library can be found in the `build/src` directory.
+You can run the binaries in `build/examples/*` which is a
+are exsample tests.
+
+## About this document
+
+This document is written using [Markdown][] syntax, making it possible to
+provide usable information in both plain text and HTML format. Whenever
+modifying this document please use [Markdown][] syntax.
+
+[markdown]: http://www.daringfireball.net/projects/markdown
diff --git a/third_party/cmocka/NEWS b/third_party/cmocka/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/cmocka/NEWS
diff --git a/third_party/cmocka/README b/third_party/cmocka/README
new file mode 100644
index 0000000..b432e8e
--- /dev/null
+++ b/third_party/cmocka/README
@@ -0,0 +1,15 @@
+CMOCKA
+=======
+
+cmocka is a fork for Google's cmockery unit testing framework to fix bugs and
+support it in future.
+See https://code.google.com/p/cmockery/
+
+For information about how to use the cmocka unit testing framework see
+doc/index.html.
+
+COMPILING
+---------
+To compile the cmocka library and example applications run, create a build dir,
+and in the build dir call 'cmake /path/to/cmocka' followed by 'make'. On
+Windows you can use the cmake gui. More details can be found in the INSTALL file.
diff --git a/third_party/cmocka/cmake/Modules/AddCMockaTest.cmake b/third_party/cmocka/cmake/Modules/AddCMockaTest.cmake
new file mode 100644
index 0000000..19de66e
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/AddCMockaTest.cmake
@@ -0,0 +1,23 @@
+# - 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>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+enable_testing()
+include(CTest)
+
+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})
+endfunction (ADD_CMOCKA_TEST)
diff --git a/third_party/cmocka/cmake/Modules/COPYING-CMAKE-SCRIPTS b/third_party/cmocka/cmake/Modules/COPYING-CMAKE-SCRIPTS
new file mode 100644
index 0000000..4b41776
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/COPYING-CMAKE-SCRIPTS
@@ -0,0 +1,22 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/third_party/cmocka/cmake/Modules/CheckCCompilerFlagSSP.cmake b/third_party/cmocka/cmake/Modules/CheckCCompilerFlagSSP.cmake
new file mode 100644
index 0000000..2fe4395
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/CheckCCompilerFlagSSP.cmake
@@ -0,0 +1,26 @@
+# - Check whether the C compiler supports a given flag in the
+# context of a stack checking compiler option.
+
+# CHECK_C_COMPILER_FLAG_SSP(FLAG VARIABLE)
+#
+# FLAG - the compiler flag
+# VARIABLE - variable to store the result
+#
+# This actually calls check_c_source_compiles.
+# See help for CheckCSourceCompiles for a listing of variables
+# that can modify the build.
+
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+include(CheckCSourceCompiles)
+
+function(CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT)
+ set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
+ set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
+ check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" ${_RESULT})
+ set(CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
+endfunction(CHECK_C_COMPILER_FLAG_SSP)
diff --git a/third_party/cmocka/cmake/Modules/DefineCMakeDefaults.cmake b/third_party/cmocka/cmake/Modules/DefineCMakeDefaults.cmake
new file mode 100644
index 0000000..72893c3
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/DefineCMakeDefaults.cmake
@@ -0,0 +1,27 @@
+# Always include srcdir and builddir in include path
+# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in
+# about every subdir
+# since cmake 2.4.0
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+# Put the include dirs which are in the source or build tree
+# before all other include dirs, so the headers in the sources
+# are prefered over the already installed ones
+# since cmake 2.4.1
+set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
+
+# Use colored output
+# 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)
diff --git a/third_party/cmocka/cmake/Modules/DefineCompilerFlags.cmake b/third_party/cmocka/cmake/Modules/DefineCompilerFlags.cmake
new file mode 100644
index 0000000..dcf79ab
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/DefineCompilerFlags.cmake
@@ -0,0 +1,82 @@
+# define system dependent compiler flags
+
+include(CheckCCompilerFlag)
+include(CheckCCompilerFlagSSP)
+
+if (UNIX AND NOT WIN32)
+ #
+ # Define GNUCC compiler flags
+ #
+ if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
+
+ # add -Wconversion ?
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
+
+ # with -fPIC
+ check_c_compiler_flag("-fPIC" WITH_FPIC)
+ if (WITH_FPIC)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+ endif (WITH_FPIC)
+
+ check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR)
+ if (WITH_STACK_PROTECTOR)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
+ endif (WITH_STACK_PROTECTOR)
+
+ if (CMAKE_BUILD_TYPE)
+ string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
+ if (NOT CMAKE_BUILD_TYPE_LOWER MATCHES debug)
+ check_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
+ if (WITH_FORTIFY_SOURCE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-D_FORTIFY_SOURCE=2")
+ endif (WITH_FORTIFY_SOURCE)
+ endif()
+ endif()
+
+ check_c_compiler_flag("-D_GNU_SOURCE" WITH_GNU_SOURCE)
+ if (WITH_GNU_SOURCE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
+ endif (WITH_GNU_SOURCE)
+ endif (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
+
+ #
+ # Check for large filesystem support
+ #
+ if (CMAKE_SIZEOF_VOID_P MATCHES "8")
+ # with large file support
+ execute_process(
+ COMMAND
+ getconf LFS64_CFLAGS
+ OUTPUT_VARIABLE
+ _lfs_CFLAGS
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ else (CMAKE_SIZEOF_VOID_P MATCHES "8")
+ # with large file support
+ execute_process(
+ COMMAND
+ getconf LFS_CFLAGS
+ OUTPUT_VARIABLE
+ _lfs_CFLAGS
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
+ if (_lfs_CFLAGS)
+ string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
+ endif (_lfs_CFLAGS)
+
+endif (UNIX AND NOT WIN32)
+
+if (MSVC)
+ # Use secure functions by defaualt and suppress warnings about
+ #"deprecated" functions
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
+endif (MSVC)
diff --git a/third_party/cmocka/cmake/Modules/DefineInstallationPaths.cmake b/third_party/cmocka/cmake/Modules/DefineInstallationPaths.cmake
new file mode 100644
index 0000000..14507ed
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/DefineInstallationPaths.cmake
@@ -0,0 +1,103 @@
+if (UNIX)
+ 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(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()
+ set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
+ set(SBIN_INSTALL_DIR "." CACHE PATH "-")
+ set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "-")
+ set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
+ set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
+ set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
+ set(ICON_INSTALL_DIR "." CACHE PATH "-")
+ set(SOUND_INSTALL_DIR "." CACHE PATH "-")
+ set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
+endif ()
diff --git a/third_party/cmocka/cmake/Modules/DefinePlatformDefaults.cmake b/third_party/cmocka/cmake/Modules/DefinePlatformDefaults.cmake
new file mode 100644
index 0000000..46c3185
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/DefinePlatformDefaults.cmake
@@ -0,0 +1,21 @@
+# Set system vars
+
+if (CMAKE_SYSTEM_NAME MATCHES "Linux")
+ set(LINUX TRUE)
+endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
+
+if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ set(FREEBSD TRUE)
+endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+
+if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
+ set(OPENBSD TRUE)
+endif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
+
+if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
+ set(NETBSD TRUE)
+endif (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
+
+if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
+ set(SOLARIS TRUE)
+endif (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
diff --git a/third_party/cmocka/cmake/Modules/FindNSIS.cmake b/third_party/cmocka/cmake/Modules/FindNSIS.cmake
new file mode 100644
index 0000000..08d839b
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/FindNSIS.cmake
@@ -0,0 +1,51 @@
+# - Try to find NSIS
+# Once done this will define
+#
+# NSIS_FOUND - system has NSIS
+# NSIS_MAKE - NSIS creator executable
+#
+#=============================================================================
+# Copyright (c) 2010-2013 Andreas Schneider <asn@cryptomilk.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+#
+
+if (WIN32)
+ set(_NSIS_ROOT_HINTS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS;Default]")
+
+ set(_NSIS_ROOT_PATHS
+ $ENV{PROGRAMFILES}/NSIS)
+
+ find_path(NSIS_ROOT_PATH
+ NAMES
+ Include/Library.nsh
+ HINTS
+ ${_NSIS_ROOT_HINTS}
+ PATHS
+ ${_NSIS_ROOT_PATHS}
+ )
+ mark_as_advanced(NSIS_ROOT_PATH)
+endif (WIN32)
+
+find_program(NSIS_MAKE
+ NAMES
+ makensis
+ PATHS
+ ${NSIS_ROOT_PATH}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(NSIS DEFAULT_MSG NSIS_MAKE)
+
+if (NSIS_MAKE)
+ set(NSIS_FOUND TRUE)
+endif (NSIS_MAKE)
+
+mark_as_advanced(NSIS_MAKE)
diff --git a/third_party/cmocka/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake b/third_party/cmocka/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
new file mode 100644
index 0000000..a2e9480
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
@@ -0,0 +1,17 @@
+# - MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+macro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
+
+ string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource)
+ if (_insource)
+ message(SEND_ERROR "${_errorMessage}")
+ message(FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first.")
+ endif (_insource)
+
+endmacro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
diff --git a/third_party/cmocka/cmake/Modules/UseDoxygen.cmake b/third_party/cmocka/cmake/Modules/UseDoxygen.cmake
new file mode 100644
index 0000000..723220b
--- /dev/null
+++ b/third_party/cmocka/cmake/Modules/UseDoxygen.cmake
@@ -0,0 +1,100 @@
+# - Run Doxygen
+#
+# Adds a doxygen target that runs doxygen to generate the html
+# and optionally the LaTeX API documentation.
+# The doxygen target is added to the doc target as dependency.
+# i.e.: the API documentation is built with:
+# make doc
+#
+# USAGE: INCLUDE IN PROJECT
+#
+# set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+# include(UseDoxygen)
+# Add the Doxyfile.in and UseDoxygen.cmake files to the projects source directory.
+#
+#
+# Variables you may define are:
+# DOXYFILE_OUTPUT_DIR - Path where the Doxygen output is stored. Defaults to "doc".
+#
+# DOXYFILE_LATEX_DIR - Directory where the Doxygen LaTeX output is stored. Defaults to "latex".
+#
+# DOXYFILE_HTML_DIR - Directory where the Doxygen html output is stored. Defaults to "html".
+#
+
+#
+# Copyright (c) 2009-2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
+# Copyright (c) 2010 Andreas Schneider <mail@cynapses.org>
+#
+# Redistribution and use is allowed according to the terms of the New
+# BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+macro(usedoxygen_set_default name value)
+ if(NOT DEFINED "${name}")
+ set("${name}" "${value}")
+ endif()
+endmacro()
+
+find_package(Doxygen)
+
+if(DOXYGEN_FOUND)
+ find_file(DOXYFILE_IN
+ NAMES
+ doxy.config.in
+ PATHS
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_ROOT}/Modules/
+ NO_DEFAULT_PATH)
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(DOXYFILE_IN DEFAULT_MSG "DOXYFILE_IN")
+endif()
+
+if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
+ add_custom_target(doxygen ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config)
+
+ usedoxygen_set_default(DOXYFILE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+ usedoxygen_set_default(DOXYFILE_HTML_DIR "html")
+
+ set_property(DIRECTORY APPEND PROPERTY
+ ADDITIONAL_MAKE_CLEAN_FILES "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
+
+ set(DOXYFILE_LATEX FALSE)
+ set(DOXYFILE_PDFLATEX FALSE)
+ set(DOXYFILE_DOT FALSE)
+
+ #find_package(LATEX)
+ #if(LATEX_COMPILER AND MAKEINDEX_COMPILER)
+ # set(DOXYFILE_LATEX TRUE)
+ # usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex")
+
+ # set_property(DIRECTORY APPEND PROPERTY
+ # ADDITIONAL_MAKE_CLEAN_FILES
+ # "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
+
+ # if(PDFLATEX_COMPILER)
+ # set(DOXYFILE_PDFLATEX TRUE)
+ # endif()
+ # if(DOXYGEN_DOT_EXECUTABLE)
+ # set(DOXYFILE_DOT TRUE)
+ # endif()
+
+ # add_custom_command(TARGET doxygen
+ # POST_BUILD
+ # COMMAND ${CMAKE_MAKE_PROGRAM}
+ # WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
+ #endif()
+
+ configure_file(${DOXYFILE_IN} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config ESCAPE_QUOTES IMMEDIATE @ONLY)
+ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in ${CMAKE_CURRENT_BINARY_DIR}/doxy.trac ESCAPE_QUOTES IMMEDIATE @ONLY)
+ add_custom_target(doxygen-trac ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.trac)
+ endif()
+
+ get_target_property(DOC_TARGET doc TYPE)
+ if(NOT DOC_TARGET)
+ add_custom_target(doc)
+ endif()
+
+ add_dependencies(doc doxygen)
+endif()
diff --git a/third_party/cmocka/cmocka.pc.cmake b/third_party/cmocka/cmocka.pc.cmake
new file mode 100644
index 0000000..c6f7433
--- /dev/null
+++ b/third_party/cmocka/cmocka.pc.cmake
@@ -0,0 +1,6 @@
+Name: ${APPLICATION_NAME}
+Description: The cmocka unit testing library
+Version: ${APPLICATION_VERSION}
+Libs: -L${LIB_INSTALL_DIR} -lcmocka
+Cflags: -I${INCLUDE_INSTALL_DIR}
+
diff --git a/third_party/cmocka/config.h.cmake b/third_party/cmocka/config.h.cmake
new file mode 100644
index 0000000..4a301ad
--- /dev/null
+++ b/third_party/cmocka/config.h.cmake
@@ -0,0 +1,138 @@
+/* Name of package */
+#cmakedefine PACKAGE "${APPLICATION_NAME}"
+
+/* Version number of package */
+#cmakedefine VERSION "${APPLICATION_VERSION}"
+
+#cmakedefine LOCALEDIR "${LOCALE_INSTALL_DIR}"
+#cmakedefine DATADIR "${DATADIR}"
+#cmakedefine LIBDIR "${LIBDIR}"
+#cmakedefine PLUGINDIR "${PLUGINDIR}"
+#cmakedefine SYSCONFDIR "${SYSCONFDIR}"
+#cmakedefine BINARYDIR "${BINARYDIR}"
+#cmakedefine SOURCEDIR "${SOURCEDIR}"
+
+/************************** HEADER FILES *************************/
+
+/* Define to 1 if you have the <assert.h> header file. */
+#cmakedefine HAVE_ASSERT_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#cmakedefine HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#cmakedefine HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#cmakedefine HAVE_MALLOC_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#cmakedefine HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <setjmp.h> header file. */
+#cmakedefine HAVE_SETJMP_H 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+#cmakedefine HAVE_SIGNAL_H 1
+
+/* Define to 1 if you have the <stdarg.h> header file. */
+#cmakedefine HAVE_STDARG_H 1
+
+/* Define to 1 if you have the <stddef.h> header file. */
+#cmakedefine HAVE_STDDEF_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#cmakedefine HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#cmakedefine HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/*************************** FUNCTIONS ***************************/
+
+/* Define to 1 if you have the `calloc' function. */
+#cmakedefine HAVE_CALLOC 1
+
+/* Define to 1 if you have the `exit' function. */
+#cmakedefine HAVE_EXIT 1
+
+/* Define to 1 if you have the `fprintf' function. */
+#cmakedefine HAVE_FPRINTF 1
+
+/* Define to 1 if you have the `free' function. */
+#cmakedefine HAVE_FREE 1
+
+/* Define to 1 if you have the `longjmp' function. */
+#cmakedefine HAVE_LONGJMP 1
+
+/* Define to 1 if you have the `malloc' function. */
+#cmakedefine HAVE_MALLOC 1
+
+/* Define to 1 if you have the `memcpy' function. */
+#cmakedefine HAVE_MEMCPY 1
+
+/* Define to 1 if you have the `memset' function. */
+#cmakedefine HAVE_MEMSET 1
+
+/* Define to 1 if you have the `printf' function. */
+#cmakedefine HAVE_PRINTF 1
+
+/* Define to 1 if you have the `setjmp' function. */
+#cmakedefine HAVE_SETJMP 1
+
+/* Define to 1 if you have the `signal' function. */
+#cmakedefine HAVE_SIGNAL 1
+
+/* Define to 1 if you have the `snprintf' function. */
+#cmakedefine HAVE_SNPRINTF 1
+
+/* Define to 1 if you have the `strcmp' function. */
+#cmakedefine HAVE_STRCMP 1
+
+/* Define to 1 if you have the `strcpy' function. */
+#cmakedefine HAVE_STRCPY 1
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#cmakedefine HAVE_VSNPRINTF 1
+
+/**************************** OPTIONS ****************************/
+
+/* define if the compiler implements namespaces */
+#cmakedefine HAVE_NAMESPACES
+
+/* Namespace for Google classes */
+#cmakedefine GOOGLE_NAMESPACE
+
+/* the namespace where STL code like vector<> is defined */
+#cmakedefine STL_NAMESPACE
+
+/* Stops putting the code inside the Google namespace */
+#cmakedefine _END_GOOGLE_NAMESPACE_
+
+/* Puts following code inside the Google namespace */
+#cmakedefine _START_GOOGLE_NAMESPACE_
+
+/*************************** ENDIAN *****************************/
+
+#cmakedefine WORDS_SIZEOF_VOID_P ${WORDS_SIZEOF_VOID_P}
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+ significant byte first (like Motorola and SPARC, unlike Intel). */
+#cmakedefine WORDS_BIGENDIAN 1
diff --git a/third_party/cmocka/coverity/README b/third_party/cmocka/coverity/README
new file mode 100644
index 0000000..7756137
--- /dev/null
+++ b/third_party/cmocka/coverity/README
@@ -0,0 +1,9 @@
+coverity_assert_model.c:
+
+This file is a Coverity Modeling file for projects using CMocka for unit
+testing. The assert functiions could create false positives, to avoid that you
+can load this modeling file in the Coverity web interface.
+
+coverity_internal_model.c:
+
+This file is for the CMocka source code itself.
diff --git a/third_party/cmocka/coverity/coverity_assert_model.c b/third_party/cmocka/coverity/coverity_assert_model.c
new file mode 100644
index 0000000..e14e581
--- /dev/null
+++ b/third_party/cmocka/coverity/coverity_assert_model.c
@@ -0,0 +1,77 @@
+#define LargestIntegralType unsigned long long
+
+void _assert_true(const LargestIntegralType result,
+ const char* const expression,
+ const char * const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_int_equal(
+ const LargestIntegralType a, const LargestIntegralType b,
+ const char * const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_int_not_equal(
+ const LargestIntegralType a, const LargestIntegralType b,
+ const char * const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_string_equal(const char * const a, const char * const b,
+ const char * const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_string_not_equal(const char * const a, const char * const b,
+ const char *file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_memory_equal(const void * const a, const void * const b,
+ const size_t size, const char* const file,
+ const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_memory_not_equal(const void * const a, const void * const b,
+ const size_t size, const char* const file,
+ const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_in_range(
+ const LargestIntegralType value, const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const char* const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_not_in_range(
+ const LargestIntegralType value, const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const char* const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_in_set(
+ const LargestIntegralType value, const LargestIntegralType values[],
+ const size_t number_of_values, const char* const file, const int line)
+{
+ __coverity_panic__();
+}
+
+void _assert_not_in_set(
+ const LargestIntegralType value, const LargestIntegralType values[],
+ const size_t number_of_values, const char* const file, const int line)
+{
+ __coverity_panic__();
+}
+
diff --git a/third_party/cmocka/coverity/coverity_internal_model.c b/third_party/cmocka/coverity/coverity_internal_model.c
new file mode 100644
index 0000000..fd1416d
--- /dev/null
+++ b/third_party/cmocka/coverity/coverity_internal_model.c
@@ -0,0 +1,5 @@
+/* Functions to help coverity do static analysis on cmocka */
+void exit_test(const int quit_application)
+{
+ __coverity_panic__();
+}
diff --git a/third_party/cmocka/doc/CMakeLists.txt b/third_party/cmocka/doc/CMakeLists.txt
new file mode 100644
index 0000000..3124281
--- /dev/null
+++ b/third_party/cmocka/doc/CMakeLists.txt
@@ -0,0 +1,5 @@
+#
+# Build the documentation
+#
+include(UseDoxygen OPTIONAL)
+
diff --git a/third_party/cmocka/doc/doxy.config.in b/third_party/cmocka/doc/doxy.config.in
new file mode 100644
index 0000000..5de47b1
--- /dev/null
+++ b/third_party/cmocka/doc/doxy.config.in
@@ -0,0 +1,1917 @@
+# Doxyfile 1.8.4
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed
+# in front of the TAG it is preceding .
+# All text after a hash (#) is considered a comment and will be ignored.
+# The format is:
+# TAG = value [value, ...]
+# For lists items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ").
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or sequence of words) that should
+# identify the project. Note that if you do not use Doxywizard you need
+# to put quotes around the project name if it contains spaces.
+
+PROJECT_NAME = @APPLICATION_NAME@
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER = @APPLICATION_VERSION@
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer
+# a quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF =
+
+# With the PROJECT_LOGO tag one can specify an logo or icon that is
+# included in the documentation. The maximum height of the logo should not
+# exceed 55 pixels and the maximum width should not exceed 200 pixels.
+# Doxygen will copy the logo to the output directory.
+
+PROJECT_LOGO =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Latvian, Lithuanian, Norwegian, Macedonian,
+# Persian, Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic,
+# Slovak, Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip. Note that you specify absolute paths here, but also
+# relative paths, which will be relative from the directory where doxygen is
+# started.
+
+STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH = @CMAKE_SOURCE_DIR@
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful if your file system
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF = YES
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 2
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# This tag can be used to specify a number of word-keyword mappings (TCL only).
+# A mapping has the form "name=value". For example adding
+# "class=itcl::class" will allow you to use the command class in the
+# itcl::class meaning.
+
+TCL_SUBST =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension,
+# and language is one of the parsers supported by doxygen: IDL, Java,
+# Javascript, CSharp, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL, C,
+# C++. For instance to make doxygen treat .inc files as Fortran files (default
+# is PHP), and .f files as C (default is Fortran), use: inc=Fortran f=C. Note
+# that for custom extensions you also need to set FILE_PATTERNS otherwise the
+# files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all
+# comments according to the Markdown format, which allows for more readable
+# documentation. See http://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you
+# can mix doxygen, HTML, and XML commands with Markdown formatting.
+# Disable only in case of backward compatibilities issues.
+
+MARKDOWN_SUPPORT = YES
+
+# When enabled doxygen tries to link words that correspond to documented
+# classes, or namespaces to their corresponding documentation. Such a link can
+# be prevented in individual cases by by putting a % sign in front of the word
+# or globally by setting AUTOLINK_SUPPORT to NO.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also makes the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES (the
+# default) will make doxygen replace the get and set methods by a property in
+# the documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and
+# unions are shown inside the group in which they are included (e.g. using
+# @ingroup) instead of on a separate page (for HTML and Man pages) or
+# section (for LaTeX and RTF).
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and
+# unions with only public data fields or simple typedef fields will be shown
+# inline in the documentation of the scope in which they are defined (i.e. file,
+# namespace, or group documentation), provided this scope is documented. If set
+# to NO (the default), structs, classes, and unions are shown on a separate
+# page (for HTML and Man pages) or section (for LaTeX and RTF).
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT = YES
+
+# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
+# cache is used to resolve symbols given their name and scope. Since this can
+# be an expensive process and often the same symbol appear multiple times in
+# the code, doxygen keeps a cache of pre-resolved symbols. If the cache is too
+# small doxygen will become slower. If the cache is too large, memory is wasted.
+# The cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid
+# range is 0..9, the default is 0, corresponding to a cache size of 2^16 = 65536
+# symbols.
+
+LOOKUP_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal
+# scope will be included in the documentation.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = NO
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespaces are hidden.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = YES
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = YES
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = @CMAKE_INTERNAL_DOC@
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
+# will list include files with double quotes in the documentation
+# rather than with sharp brackets.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS = YES
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen
+# will sort the (brief and detailed) documentation of class members so that
+# constructors and destructors are listed first. If set to NO (the default)
+# the constructors will appear in the respective orders defined by
+# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS.
+# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO
+# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to
+# do proper type resolution of all parameters of a function it will reject a
+# match between the prototype and the implementation of a member function even
+# if there is only one candidate or it is obvious which candidate to choose
+# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen
+# will still accept a match between prototype and implementation in such cases.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if section-label ... \endif
+# and \cond section-label ... \endcond blocks.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or macro consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and macros in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.
+# This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option.
+# You can optionally specify a file name after the option, if omitted
+# DoxygenLayout.xml will be used as the name of the layout file.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files
+# containing the references data. This must be a list of .bib files. The
+# .bib extension is automatically appended if omitted. Using this command
+# requires the bibtex tool to be installed. See also
+# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style
+# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this
+# feature you need bibtex and perl available in the search path. Do not use
+# file names with spaces, bibtex cannot handle them.
+
+CITE_BIB_FILES =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = YES
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR = YES
+
+# The WARN_NO_PARAMDOC option can be enabled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = @CMAKE_SOURCE_DIR@/include \
+ @CMAKE_SOURCE_DIR@/src \
+ @CMAKE_SOURCE_DIR@/doc
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh
+# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py
+# *.f90 *.f *.for *.vhd *.vhdl
+
+FILE_PATTERNS = *.cpp \
+ *.cc \
+ *.c \
+ *.h \
+ *.hh \
+ *.hpp \
+ *.dox
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS = */.git/* \
+ */.svn/* \
+ */cmake/*
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH = @CMAKE_SOURCE_DIR@/example
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS = *.c \
+ *.h \
+ INSTALL \
+ DEPENDENCIES \
+ CHANGELOG \
+ LICENSE \
+ LGPL
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = YES
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+# If FILTER_PATTERNS is specified, this tag will be ignored.
+# Note that the filter must not add or remove lines; it is applied before the
+# code is scanned, but not when the output code is generated. If lines are added
+# or removed, the anchors will not be placed correctly.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.
+# Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.
+# The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty or if
+# non of the patterns match the file name, INPUT_FILTER is applied.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any)
+# and it is also possible to disable source filtering for a specific pattern
+# using *.ext= (so without naming a filter). This option only has effect when
+# FILTER_SOURCE_FILES is enabled.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MD_FILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page
+# (index.html). This can be useful if you have a project on for instance GitHub
+# and want reuse the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE =
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C, C++ and Fortran comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = YES
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code.
+# Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 2
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header. Note that when using a custom header you are responsible
+# for the proper inclusion of any scripts and style sheets that doxygen
+# needs, which is dependent on the configuration options used.
+# It is advised to generate a default header using "doxygen -w html
+# header.html footer.html stylesheet.css YourConfigFile" and then modify
+# that header. Note that the header is subject to change so you typically
+# have to redo this when upgrading to a newer version of doxygen or when
+# changing the value of configuration settings such as GENERATE_TREEVIEW!
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If left blank doxygen will
+# generate a default style sheet. Note that it is recommended to use
+# HTML_EXTRA_STYLESHEET instead of this one, as it is more robust and this
+# tag will in the future become obsolete.
+
+HTML_STYLESHEET =
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional
+# user-defined cascading style sheet that is included after the standard
+# style sheets created by doxygen. Using this option one can overrule
+# certain style aspects. This is preferred over using HTML_STYLESHEET
+# since it does not replace the standard style sheet and is therefor more
+# robust against future updates. Doxygen will copy the style sheet file to
+# the output directory.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that
+# the files will be copied as-is; there are no commands or markers available.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
+# Doxygen will adjust the colors in the style sheet and background images
+# according to this color. Hue is specified as an angle on a colorwheel,
+# see http://en.wikipedia.org/wiki/Hue for more information.
+# For instance the value 0 represents red, 60 is yellow, 120 is green,
+# 180 is cyan, 240 is blue, 300 purple, and 360 is red again.
+# The allowed range is 0 to 359.
+
+HTML_COLORSTYLE_HUE = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of
+# the colors in the HTML output. For a value of 0 the output will use
+# grayscales only. A value of 255 will produce the most vivid colors.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to
+# the luminance component of the colors in the HTML output. Values below
+# 100 gradually make the output lighter, whereas values above 100 make
+# the output darker. The value divided by 100 is the actual gamma applied,
+# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2,
+# and 100 does not change the gamma.
+
+HTML_COLORSTYLE_GAMMA = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting
+# this to NO can help when comparing the output of multiple runs.
+
+HTML_TIMESTAMP = NO
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of
+# entries shown in the various tree structured indices initially; the user
+# can expand and collapse entries dynamically later on. Doxygen will expand
+# the tree to such a level that at most the specified number of entries are
+# visible (unless a fully collapsed tree already exceeds this amount).
+# So setting the number of entries 1 will produce a full collapsed tree by
+# default. 0 is a special value representing an infinite number of entries
+# and will result in a full expanded tree by default.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+
+GENERATE_DOCSET = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely
+# identify the documentation publisher. This should be a reverse domain-name
+# style string, e.g. com.mycompany.MyDocSet.documentation.
+
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+
+# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher.
+
+DOCSET_PUBLISHER_NAME = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated
+# that can be used as input for Qt's qhelpgenerator to generate a
+# Qt Compressed Help (.qch) of the generated HTML documentation.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE =
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to
+# add. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">
+# Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">
+# Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
+# will be generated, which together with the HTML files, form an Eclipse help
+# plugin. To install this plugin and make it available under the help contents
+# menu in Eclipse, the contents of the directory containing the HTML and XML
+# files needs to be copied into the plugins directory of eclipse. The name of
+# the directory within the plugins directory should be the same as
+# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
+# the help appears.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have
+# this name.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs)
+# at top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it. Since the tabs have the same information as the
+# navigation tree you can set this option to NO if you already set
+# GENERATE_TREEVIEW to YES.
+
+DISABLE_INDEX = NO
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to YES, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
+# Windows users are probably better off using the HTML help feature.
+# Since the tree basically has the same information as the tab index you
+# could consider to set DISABLE_INDEX to NO when enabling this option.
+
+GENERATE_TREEVIEW = NO
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values
+# (range [0,1..20]) that doxygen will group on one line in the generated HTML
+# documentation. Note that a value of 0 will completely suppress the enum
+# values from appearing in the overview section.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open
+# links to external symbols imported via tag files in a separate window.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are
+# not supported properly for IE 6.0, but are supported on all modern browsers.
+# Note that when changing this option you need to delete any form_*.png files
+# in the HTML output before the changes have effect.
+
+FORMULA_TRANSPARENT = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax
+# (see http://www.mathjax.org) which uses client side Javascript for the
+# rendering instead of using prerendered bitmaps. Use this if you do not
+# have LaTeX installed or if you want to formulas look prettier in the HTML
+# output. When enabled you may also need to install MathJax separately and
+# configure the path to it using the MATHJAX_RELPATH option.
+
+USE_MATHJAX = NO
+
+# When MathJax is enabled you can set the default output format to be used for
+# the MathJax output. Supported types are HTML-CSS, NativeMML (i.e. MathML) and
+# SVG. The default value is HTML-CSS, which is slower, but has the best
+# compatibility.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the
+# HTML output directory using the MATHJAX_RELPATH option. The destination
+# directory should contain the MathJax.js script. For instance, if the mathjax
+# directory is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to
+# the MathJax Content Delivery Network so you can quickly see the result without
+# installing MathJax.
+# However, it is strongly recommended to install a local
+# copy of MathJax from http://www.mathjax.org before deployment.
+
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension
+# names that should be enabled during MathJax rendering.
+
+MATHJAX_EXTENSIONS =
+
+# The MATHJAX_CODEFILE tag can be used to specify a file with javascript
+# pieces of code that will be used on startup of the MathJax code.
+
+MATHJAX_CODEFILE =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box
+# for the HTML output. The underlying search engine uses javascript
+# and DHTML and should work on any modern browser. Note that when using
+# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
+# (GENERATE_DOCSET) there is already a search function so this one should
+# typically be disabled. For large projects the javascript based search engine
+# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
+
+SEARCHENGINE = NO
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using Javascript.
+# There are two flavours of web server based search depending on the
+# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for
+# searching and an index file used by the script. When EXTERNAL_SEARCH is
+# enabled the indexing and searching needs to be provided by external tools.
+# See the manual for details.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain
+# the search results. Doxygen ships with an example indexer (doxyindexer) and
+# search engine (doxysearch.cgi) which are based on the open source search
+# engine library Xapian. See the manual for configuration details.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will returned the search results when EXTERNAL_SEARCH is enabled.
+# Doxygen ships with an example search engine (doxysearch) which is based on
+# the open source search engine library Xapian. See the manual for configuration
+# details.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH AND EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id
+# of to a relative location where the documentation can be found.
+# The format is: EXTRA_SEARCH_MAPPINGS = id1=loc1 id2=loc2 ...
+
+EXTRA_SEARCH_MAPPINGS =
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = @DOXYFILE_LATEX@
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+# Note that when enabling USE_PDFLATEX this option is only used for
+# generating bitmaps for formulas in the HTML output, but not in the
+# Makefile that is written to the output directory.
+
+LATEX_CMD_NAME = @LATEX_COMPILER@
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME = @MAKEINDEX_COMPILER@
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, letter, legal and
+# executive. If left blank a4 will be used.
+
+PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for
+# the generated latex document. The footer should contain everything after
+# the last chapter. If it is left blank doxygen will generate a
+# standard footer. Notice: only use this tag if you know what you are doing!
+
+LATEX_FOOTER =
+
+# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images
+# or other source files which should be copied to the LaTeX output directory.
+# Note that the files will be copied as-is; there are no commands or markers
+# available.
+
+LATEX_EXTRA_FILES =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = YES
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES = NO
+
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include
+# source code with syntax highlighting in the LaTeX output.
+# Note that which sources are shown also depends on other settings
+# such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See
+# http://en.wikipedia.org/wiki/BibTeX for more info.
+
+LATEX_BIB_STYLE = plain
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+# Load style sheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = YES
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_DOCBOOK tag is set to YES Doxygen will generate DOCBOOK files
+# that can be used to generate PDF.
+
+GENERATE_DOCBOOK = NO
+
+# The DOCBOOK_OUTPUT tag is used to specify where the DOCBOOK pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
+# front of it. If left blank docbook will be used as the default path.
+
+DOCBOOK_OUTPUT = docbook
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.
+# This is useful
+# if you want to understand what is going on.
+# On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# pointed to by INCLUDE_PATH will be searched when a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED = DOXYGEN \
+ PRINTF_ATTRIBUTE(x,y)=
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition that
+# overrules the definition found in the source code.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all references to function-like macros
+# that are alone on a line, have an all uppercase name, and do not end with a
+# semicolon, because these will confuse the parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles. For each
+# tag file the location of the external documentation should be added. The
+# format of a tag file without this location is as follows:
+#
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths
+# or URLs. Note that each tag file must have a unique name (where the name does
+# NOT include the path). If a tag file is not located in the directory in which
+# doxygen is run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE = @CMAKE_CURRENT_BINARY_DIR@/html/@PROJECT_NAME@.TAGFILE
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = YES
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed
+# in the related pages index. If set to NO, only the current project's
+# pages will be listed.
+
+EXTERNAL_PAGES = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option also works with HAVE_DOT disabled, but it is recommended to
+# install and use dot, since it yields more powerful graphs.
+
+CLASS_DIAGRAMS = NO
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = @DOXYGEN_DOT_FOUND@
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
+# allowed to run in parallel. When set to 0 (the default) doxygen will
+# base this on the number of processors available in the system. You can set it
+# explicitly to a value larger than 0 to get control over the balance
+# between CPU load and processing speed.
+
+DOT_NUM_THREADS = 0
+
+# By default doxygen will use the Helvetica font for all dot files that
+# doxygen generates. When you want a differently looking font you can specify
+# the font name using DOT_FONTNAME. You need to make sure dot is able to find
+# the font, which can be done by putting it in a standard location or by setting
+# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the
+# directory containing the font.
+
+DOT_FONTNAME =
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the Helvetica font.
+# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to
+# set the path where dot can find it.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside
+# the class node. If there are many fields or methods and many nodes the
+# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS
+# threshold limits the number of items for each type to make the size more
+# manageable. Set this to 0 for no limit. Note that the threshold may be
+# exceeded by 50% before the limit is enforced.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will generate a graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are svg, png, jpg, or gif.
+# If left blank png will be used. If you choose svg you need to set
+# HTML_FILE_EXTENSION to xhtml in order to make the SVG files
+# visible in IE 9+ (other browsers do not have this requirement).
+
+DOT_IMAGE_FORMAT = png
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+# Note that this requires a modern browser other than Internet Explorer.
+# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you
+# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files
+# visible. Older versions of IE do not have SVG support.
+
+INTERACTIVE_SVG = NO
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH = @DOXYGEN_DOT_EXECUTABLE_PATH@
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the
+# \mscfile command).
+
+MSCFILE_DIRS =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS = YES
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
diff --git a/third_party/cmocka/doc/index.html b/third_party/cmocka/doc/index.html
new file mode 100644
index 0000000..8db0247
--- /dev/null
+++ b/third_party/cmocka/doc/index.html
@@ -0,0 +1,706 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html><head>
+<title>cmocka</title>
+</head>
+<body>
+<h1>cmocka Unit Testing Framework</h1>
+<p>cmocka is a lightweight library that is used to author C unit tests.</p>
+
+<ul>Contents
+ <li><a href="#Motivation">Motivation</a></li>
+ <li><a href="#Overview">Overview</a></li>
+ <li><a href="#Test_Execution">Test Execution</a>
+ <li><a href="#Exception_Handling">Exception Handling</a></li>
+ <li><a href="#Failure_Conditions">Failure Conditions</a></li>
+ <li><a href="#Assertions">Assertions</a></li>
+ <ul>
+ <li><a href="#Assert_Macros">Assert Macros</a></li>
+ </ul>
+ <li><a href="#Dynamic_Memory_Allocation">Dynamic Memory Allocation</a></li>
+ <li><a href="#Mock_Functions">Mock functions</a></li>
+ <ul>
+ <li><a href="#Return_Values">Return Values</a></li>
+ <li><a href="#Checking_Parameters">Checking Parameters</a></li>
+ </ul>
+ <li><a href="#Test_State">Test State</a></li>
+ <li><a href="#Example">Example</a></li>
+</ul>
+
+<a name="Motivation"><h2>Motivation</h2></a>
+<p>There are a variety of C unit testing frameworks available however many of
+them are fairly complex and require the latest compiler technology. Some
+development requires the use of old compilers which makes it difficult to
+use some unit testing frameworks. In addition many unit testing frameworks
+assume the code being tested is an application or module that is targeted to
+the same platform that will ultimately execute the test. Because of this
+assumption many frameworks require the inclusion of standard C library headers
+in the code module being tested which may collide with the custom or
+incomplete implementation of the C library utilized by the code under test.</p>
+
+<p>cmocka only requires a test application is linked with the standard C
+library which minimizes conflicts with standard C library headers. Also,
+cmocka tries avoid the use of some of the newer features of C compilers.</p>
+
+<p>This results in cmocka being a relatively small library that can be used
+to test a variety of exotic code. If a developer wishes to simply test an
+application with the latest compiler then other unit testing frameworks maybe
+preferable.</p>
+
+<a name="Overview"><h2>Overview</h2></a>
+<p>cmocka tests are compiled into stand-alone executables and linked with
+the cmocka library, the standard C library and module being tested. Any
+symbols external to the module being tested should be mocked - replaced with
+functions that return values determined by the test - within the test
+application. Even though significant differences may exist between the target
+execution environment of a code module and the environment used to test the
+code the unit testing is still valid since its goal is to test the logic of a
+code modules at a functional level and not necessarily all of its interactions
+with the target execution environment.</p>
+
+<p>It may not be possible to compile a module into a test application without
+some modification, therefore the preprocessor symbol <b>UNIT_TESTING</b> should
+be defined when cmocka unit test applications are compiled so code within the
+module can be conditionally compiled for tests.</p>
+
+<a name="Test_Execution"><h2>Test Execution</h2></a>
+<p>cmocka unit test cases are functions with the signature
+<b>void function(void **state)</b>. cmocka test applications initialize a
+table with test case function pointers using <b>unit_test*()</b> macros. This
+table is then passed to the <b>run_tests()</b> macro to execute the tests.
+
+<b>run_tests()</b> sets up the appropriate exception / signal handlers and
+other data structures prior to running each test function. When a unit test
+is complete <b>run_tests()</b> performs various checks to determine whether
+the test succeeded.</p>
+
+<h4>Using run_tests()</h4>
+<a href="../example/run_tests.c">run_tests.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;cmocka.h&gt;
+
+// A test case that does nothing and succeeds.
+void null_test_success(void **state) {
+}
+
+int main(int argc, char* argv[]) {
+ const UnitTest tests[] = {
+ unit_test(null_test_success),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<a name="Exception_Handling"><h2>Exception Handling</h2></a>
+<p>Before a test function is executed by <b>run_tests()</b>,
+exception / signal handlers are overridden with a handler that simply
+displays an error and exits a test function if an exception occurs. If an
+exception occurs outside of a test function, for example in cmocka itself,
+the application aborts execution and returns an error code.</p>
+
+<a name="Failure_Conditions"><h2>Failure Conditions</h2></a>
+<p>If a failure occurs during a test function that's executed via
+<b>run_tests()</b>, the test function is aborted and the application's
+execution resumes with the next test function.
+
+Test failures are ultimately signalled via the cmocka function <b>fail()</b>.
+The following events will result in the cmocka library signalling a test
+failure...
+
+<ul>
+ <li><a href="#Assertions">Assertions</a></li>
+ <li><a href="#Exception_Handling">Exceptions</a></li>
+ <li><a href="#Dynamic_Memory_Allocation">Memory leaks</a></li>
+ <li><a href="#Test_State">Mismatched setup and tear down functions</a></li>
+ <li><a href="#Return_Values">Missing mock return values</a></li>
+ <li><a href="#Return_Values">Unused mock return values</a></li>
+ <li><a href="#Checking_Parameters">Missing expected parameter values</a></li>
+ <li><a href="#Checking_Parameters">Unused expected parameter values</a></li>
+</ul>
+</p>
+
+<a name="Assertions"><h2>Assertions</h2></a>
+<p>Runtime assert macros like the standard C library's <b>assert()</b> should
+be redefined in modules being tested to use cmocka's <b>mock_assert()</b>
+function. Normally <b>mock_assert()</b> signals a
+<a href="#Failure_Conditions">test failure</a>. If a function is called using
+the <b>expect_assert_failure()</b> macro, any calls to <b>mock_assert()</b>
+within the function will result in the execution of the test. If no
+calls to <b>mock_assert()</b> occur during the function called via
+<b>expect_assert_failure()</b> a test failure is signalled.</p>
+
+<h4>Using mock_assert()</h4>
+<a href="../example/assert_module.c">assert_module.c</a>
+<listing>
+#include &lt;assert.h&gt;
+
+// If unit testing is enabled override assert with mock_assert().
+#if UNIT_TESTING
+extern void mock_assert(const int result, const char* const expression,
+ const char * const file, const int line);
+#undef assert
+#define assert(expression) \
+ mock_assert((int)(expression), #expression, __FILE__, __LINE__);
+#endif // UNIT_TESTING
+
+void increment_value(int * const value) {
+ assert(value);
+ (*value) ++;
+}
+
+void decrement_value(int * const value) {
+ if (value) {
+ *value --;
+ }
+}
+</listing>
+<a href="../example/assert_module_test.c">assert_module_test.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;cmocka.h&gt;
+
+extern void increment_value(int * const value);
+
+/* This test case will fail but the assert is caught by run_tests() and the
+ * next test is executed. */
+void increment_value_fail(void **state) {
+ increment_value(NULL);
+}
+
+// This test case succeeds since increment_value() asserts on the NULL pointer.
+void increment_value_assert(void **state) {
+ expect_assert_failure(increment_value(NULL));
+}
+
+/* This test case fails since decrement_value() doesn't assert on a NULL
+ * pointer. */
+void decrement_value_fail(void **state) {
+ expect_assert_failure(decrement_value(NULL));
+}
+
+int main(int argc, char *argv[]) {
+ const UnitTest tests[] = {
+ unit_test(increment_value_fail),
+ unit_test(increment_value_assert),
+ unit_test(decrement_value_fail),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<h3><a name="Assert_Macros">Assert Macros</a></h3>
+
+<p>cmocka provides an assortment of assert macros that tests applications
+should use use in preference to the C standard library's assert macro. On an
+assertion failure a cmocka assert macro will write the failure to the
+standard error stream and signal a test failure. Due to limitations of the
+C language the general C standard library assert() and cmocka's
+assert_true() and assert_false() macros can only display the expression that
+caused the assert failure. cmocka's type specific assert macros,
+assert_{type}_equal() and assert_{type}_not_equal(), display the data that
+caused the assertion failure which increases data visibility aiding
+debugging of failing test cases.</p>
+
+<h4>Using assert_{type}_equal() macros</h4>
+<a href="../example/assert_macro.c">assert_macro.c</a>
+<listing>
+#include &lt;string.h&gt;
+
+static const char* status_code_strings[] = {
+ "Address not found",
+ "Connection dropped",
+ "Connection timed out",
+};
+
+const char* get_status_code_string(const unsigned int status_code) {
+ return status_code_strings[status_code];
+};
+
+unsigned int string_to_status_code(const char* const status_code_string) {
+ unsigned int i;
+ for (i = 0; i < sizeof(status_code_strings) /
+ sizeof(status_code_strings[0]); i++) {
+ if (strcmp(status_code_strings[i], status_code_string) == 0) {
+ return i;
+ }
+ }
+ return ~0U;
+}
+</listing>
+<a href="../example/assert_macro_test.c">assert_macro_test.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;cmocka.h&gt;
+
+extern const char* get_status_code_string(const unsigned int status_code);
+extern unsigned int string_to_status_code(
+ const char* const status_code_string);
+
+/* This test will fail since the string returned by get_status_code_string(0)
+ * doesn't match "Connection timed out". */
+void get_status_code_string_test(void **state) {
+ assert_string_equal(get_status_code_string(0), "Address not found");
+ assert_string_equal(get_status_code_string(1), "Connection timed out");
+}
+
+// This test will fail since the status code of "Connection timed out" isn't 1
+void string_to_status_code_test(void **state) {
+ assert_int_equal(string_to_status_code("Address not found"), 0);
+ assert_int_equal(string_to_status_code("Connection timed out"), 1);
+}
+
+int main(int argc, char *argv[]) {
+ const UnitTest tests[] = {
+ unit_test(get_status_code_string_test),
+ unit_test(string_to_status_code_test),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<a name="Dynamic_Memory_Allocation"><h2>Dynamic Memory Allocation</h2></a>
+
+<p>To test for memory leaks, buffer overflows and underflows a module being
+tested by cmocka should replace calls to <b>malloc()</b>, <b>calloc()</b> and
+<b>free()</b> to <b>test_malloc()</b>, <b>test_calloc()</b> and
+<b>test_free()</b> respectively. Each time a block is deallocated using
+<b>test_free()</b> it is checked for corruption, if a corrupt block is found
+a <a href="#Failure_Conditions">test failure</a> is signalled. All blocks
+allocated using the <b>test_*()</b> allocation functions are tracked by the
+cmocka library. When a test completes if any allocated blocks (memory leaks)
+remain they are reported and a test failure is signalled.</p>
+<p>For simplicity cmocka currently executes all tests in one process.
+Therefore all test cases in a test application share a single address space
+which means memory corruption from a single test case could potentially cause
+the test application to exit prematurely.</p>
+
+<h4>Using cmocka's Allocators</h4>
+<a href="../example/allocate_module.c">allocate_module.c</a>
+<listing>
+#include &lt;malloc.h&gt;
+
+#if UNIT_TESTING
+extern void* _test_malloc(const size_t size, const char* file, const int line);
+extern void* _test_calloc(const size_t number_of_elements, const size_t size,
+ const char* file, const int line);
+extern void _test_free(void* const ptr, const char* file, const int line);
+
+#define malloc(size) _test_malloc(size, __FILE__, __LINE__)
+#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
+#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
+#endif // UNIT_TESTING
+
+void leak_memory() {
+ int * const temporary = (int*)malloc(sizeof(int));
+ *temporary = 0;
+}
+
+void buffer_overflow() {
+ char * const memory = (char*)malloc(sizeof(int));
+ memory[sizeof(int)] = '!';
+ free(memory);
+}
+
+void buffer_underflow() {
+ char * const memory = (char*)malloc(sizeof(int));
+ memory[-1] = '!';
+ free(memory);
+}
+</listing>
+<a href="../example/allocate_module_test.c">allocate_module_test.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;cmocka.h&gt;
+
+extern void leak_memory();
+extern void buffer_overflow();
+extern void buffer_underflow();
+
+// Test case that fails as leak_memory() leaks a dynamically allocated block.
+void leak_memory_test(void **state) {
+ leak_memory();
+}
+
+// Test case that fails as buffer_overflow() corrupts an allocated block.
+void buffer_overflow_test(void **state) {
+ buffer_overflow();
+}
+
+// Test case that fails as buffer_underflow() corrupts an allocated block.
+void buffer_underflow_test(void **state) {
+ buffer_underflow();
+}
+
+int main(int argc, char* argv[]) {
+ const UnitTest tests[] = {
+ unit_test(leak_memory_test),
+ unit_test(buffer_overflow_test),
+ unit_test(buffer_underflow_test),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<a name="Mock_Functions"><h2>Mock Functions</h2></a>
+
+<p>A unit test should ideally isolate the function or module being tested
+from any external dependencies. This can be performed using mock functions
+that are either statically or dynamically linked with the module being tested.
+Mock functions must be statically linked when the code being tested directly
+references external functions. Dynamic linking is simply the process of
+setting a function pointer in a table used by the tested module to reference
+a mock function defined in the unit test.</p>
+
+<a name="Return_Values"><h3>Return Values</h3></a>
+
+<p>In order to simplify the implementation of mock functions cmocka provides
+functionality which stores return values for mock functions in each test
+case using <b>will_return()</b>. These values are then returned by each mock
+function using calls to <b>mock()</b>.
+
+Values passed to <b>will_return()</b> are added to a queue for each function
+specified. Each successive call to <b>mock()</b> from a function removes a
+return value from the queue. This makes it possible for a mock function to use
+multiple calls to <b>mock()</b> to return output parameters in addition to a
+return value. In addition this allows the specification of return values for
+multiple calls to a mock function.</p>
+
+<h4>Using will_return()</h4>
+<a href="../example/database.h">database.h</a>
+<listing>
+typedef struct DatabaseConnection DatabaseConnection;
+
+/* Function that takes an SQL query string and sets results to an array of
+ * pointers with the result of the query. The value returned specifies the
+ * number of items in the returned array of results. The returned array of
+ * results are statically allocated and should not be deallocated using free()
+ */
+typedef unsigned int (*QueryDatabase)(
+ DatabaseConnection* const connection, const char * const query_string,
+ void *** const results);
+
+// Connection to a database.
+struct DatabaseConnection {
+ const char *url;
+ unsigned int port;
+ QueryDatabase query_database;
+};
+
+// Connect to a database.
+DatabaseConnection* connect_to_database(const char * const url,
+ const unsigned int port);
+</listing>
+<a href="../example/customer_database.c">customer_database.c</a>
+<listing>
+#include &lt;stddef.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;database.h&gt;
+#ifdef _WIN32
+#define snprintf _snprintf
+#endif // _WIN32
+
+// Connect to the database containing customer information.
+DatabaseConnection* connect_to_customer_database() {
+ 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)results[0];
+}
+</listing>
+<a href="../example/customer_database_test.c">customer_database_test.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;cmocka.h&gt;
+#include &lt;database.h&gt;
+
+
+extern DatabaseConnection* connect_to_customer_database();
+extern unsigned int get_customer_id_by_name(
+ DatabaseConnection * const connection, const char * const customer_name);
+
+// Mock query database function.
+unsigned int mock_query_database(
+ DatabaseConnection* const connection, const char * const query_string,
+ void *** const results) {
+ *results = (void**)mock();
+ return (unsigned int)mock();
+}
+
+// Mock of the connect to database function.
+DatabaseConnection* connect_to_database(const char * const database_url,
+ const unsigned int port) {
+ return (DatabaseConnection*)mock();
+}
+
+void test_connect_to_customer_database(void **state) {
+ will_return(connect_to_database, 0x0DA7ABA53);
+ assert_true(connect_to_customer_database() ==
+ (DatabaseConnection*)0x0DA7ABA53);
+}
+
+/* This test fails as the mock function connect_to_database() will have no
+ * value to return. */
+void fail_connect_to_customer_database(void **state) {
+ will_return(connect_to_database, 0x0DA7ABA53);
+ assert_true(connect_to_customer_database() ==
+ (DatabaseConnection*)0x0DA7ABA53);
+}
+
+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;
+ will_return(mock_query_database, &customer_ids);
+ will_return(mock_query_database, 1);
+ assert_int_equal(get_customer_id_by_name(&connection, "john doe"), 543);
+}
+
+int main(int argc, char* argv[]) {
+ const UnitTest tests[] = {
+ unit_test(test_connect_to_customer_database),
+ unit_test(fail_connect_to_customer_database),
+ unit_test(test_get_customer_id_by_name),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<a name="Checking_Parameters"><h3>Checking Parameters</h3></a>
+<p>In addition to storing the return values of mock functions, cmocka
+provides functionality to store expected values for mock function parameters
+using the expect_*() functions provided. A mock function parameter can then
+be validated using the check_expected() macro.
+
+<p>Successive calls to expect_*() macros for a parameter queues values to
+check the specified parameter. check_expected() checks a function parameter
+against the next value queued using expect_*(), if the parameter check fails a
+test failure is signalled. In addition if check_expected() is called and
+no more parameter values are queued a test failure occurs.</p>
+
+<h4>Using expect_*()</h4>
+<a href="../example/product_database.c">product_database.c</a>
+<listing>
+#include &lt;database.h&gt;
+
+// Connect to the database containing customer information.
+DatabaseConnection* connect_to_product_database() {
+ return connect_to_database("products.abcd.org", 322);
+}
+</listing>
+<a href="../example/product_database_test.c">product_database_test.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;cmocka.h&gt;
+#include &lt;database.h&gt;
+
+extern DatabaseConnection* connect_to_product_database();
+
+/* 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(url);
+ check_expected(port);
+ return (DatabaseConnection*)mock();
+}
+
+void test_connect_to_product_database(void **state) {
+ 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(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(). */
+void test_connect_to_product_database_bad_url(void **state) {
+ 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((int)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. */
+void test_connect_to_product_database_missing_parameter(void **state) {
+ expect_string(connect_to_database, url, "products.abcd.org");
+ will_return(connect_to_database, 0xDA7ABA53);
+ assert_int_equal((int)connect_to_product_database(), 0xDA7ABA53);
+}
+
+int main(int argc, char* argv[]) {
+ const UnitTest tests[] = {
+ unit_test(test_connect_to_product_database),
+ unit_test(test_connect_to_product_database_bad_url),
+ unit_test(test_connect_to_product_database_missing_parameter),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<a name="Test_State"><h2>Test State</h2></a>
+
+<p>cmocka allows the specification of multiple setup and tear down functions
+for each test case. Setup functions, specified by the <b>unit_test_setup()</b>
+or <b>unit_test_setup_teardown()</b> macros allow common initialization to be
+shared between multiple test cases. In addition, tear down functions,
+specified by the <b>unit_test_teardown()</b> or
+<b>unit_test_setup_teardown()</b> macros provide a code path that is always
+executed for a test case even when it fails.</p>
+
+<h4>Using unit_test_setup_teardown()</h4>
+<a href="../example/key_value.c">key_value.c</a>
+<listing>
+#include &lt;stddef.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;string.h&gt;
+
+typedef struct KeyValue {
+ unsigned int key;
+ const char* value;
+} KeyValue;
+
+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.
+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() {
+ qsort(key_values, number_of_key_values, sizeof(*key_values),
+ key_value_compare_keys);
+}
+</listing>
+<a href="../example/key_value_test.c">key_value_test.c</a>
+<listing>
+#include &lt;stdarg.h&gt;
+#include &lt;stddef.h&gt;
+#include &lt;setjmp.h&gt;
+#include &lt;string.h&gt;
+#include &lt;cmocka.h&gt;
+
+/* This is duplicated here from the module setup_teardown.c to reduce the
+ * number of files used in this test. */
+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);
+extern KeyValue* find_item_by_value(const char * const value);
+extern void sort_items_by_key();
+
+static KeyValue key_values[] = {
+ { 10, "this" },
+ { 52, "test" },
+ { 20, "a" },
+ { 13, "is" },
+};
+
+void 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]));
+}
+
+void destroy_key_values(void **state) {
+ test_free(*state);
+ set_key_values(NULL, 0);
+}
+
+void test_find_item_by_value(void **state) {
+ unsigned int i;
+ 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);
+ assert_int_equal(found->key, key_values[i].key);
+ assert_string_equal(found->value, key_values[i].value);
+ }
+}
+
+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(int argc, char* argv[]) {
+ const UnitTest tests[] = {
+ unit_test_setup_teardown(test_find_item_by_value, create_key_values,
+ destroy_key_values),
+ unit_test_setup_teardown(test_sort_items_by_key, create_key_values,
+ destroy_key_values),
+ };
+ return run_tests(tests);
+}
+</listing>
+
+<a name="Example"><h2>Example</h2></a>
+
+<p>A small command line calculator
+<a href="../example/calculator.c">calculator.c</a> application
+and test application that full exercises the calculator application
+<a href="../example/calculator_test.c">calculator_test.c</a>
+are provided as an example of cmocka's features discussed in this document.
+</p>
+
+<hr>
+<address></address>
+<!-- hhmts start --> Last modified: Wed Jul 22 12:11:43 PDT 2009 <!-- hhmts end -->
+</body> </html>
diff --git a/third_party/cmocka/doc/mainpage.dox b/third_party/cmocka/doc/mainpage.dox
new file mode 100644
index 0000000..d7f2027
--- /dev/null
+++ b/third_party/cmocka/doc/mainpage.dox
@@ -0,0 +1,88 @@
+/**
+
+@mainpage
+
+This is the online reference for developing with the CMocka library. It
+documents the CMocka C API.
+
+@section main-motivation Motivation
+
+There are a variety of C unit testing frameworks available supporting different
+platforms and compilers. Some development requires a lot of different compilers
+and older versions which makes it difficult to use unit testing frameworks.
+
+The idea of CMocka is that a test application only requires the standard C
+library and CMocka itself to minimize the conflicts with standard C library
+headers especially on a lot of different platforms.
+
+Currently CMocka is tested on Linux, FreeBSD, Solaris and Windows. See the
+<a href="http://mock.cryptomilk.org/index.php?project=cmocka">Testing Dashboard</a>.
+
+@section main-features Features
+
+CMocka tests are compiled into stand-alone executables and linked with the
+CMock library, the standard C library and module being tested. Any symbols
+external to the module being tested should be mocked - replaced with functions
+that return values determined by the test - within the test application. Even
+though significant differences may exist between the target execution
+environment of a code module and the environment used to test the code the unit
+testing is still valid since its goal is to test the logic of a code modules at
+a functional level and not necessarily all of its interactions with the target
+execution environment.
+
+The CMocka library provides:
+
+ - An easy to use framework to write unit tests.
+ - Support for mock objects.
+ - Fixtures to implement a setup and teardown function.
+ - A set of assert macros.
+
+@section main-test A CMocka test
+
+CMocka unit test cases are functions with the signature void function(void **state).
+CMocka test applications initialize a table with test case function pointers
+using unit_test() macros. This table is then passed to the run_tests() macro to
+execute the tests. run_tests() sets up the appropriate exception / signal
+handlers and other data structures prior to running each test function. When a
+unit test is complete run_tests() performs various checks to determine whether
+the test succeeded.
+
+@code
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+/* A test case that does nothing and succeeds. * /
+static void null_test_success(void **state) {
+ (void) state; /* unused * /
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test(null_test_success),
+ };
+
+ return run_tests(tests);
+}
+@endcode
+
+@section main-mock Mock objects
+
+You may already have heard the term "Mock Object". It describes a special case
+of an object that mimics a real instance of an interface in order to provide
+enough of that interface for testing. While there are several unit testing
+frameworks that already provide some easy to use interface for creating
+different kinds of "fake" objects for testing, there may be some confusion in
+terms of how these test objects are programmed and what the behavioral
+differences are between them.
+
+Mock objects include some logic and the test driver is able to modify the
+behaviour and state. The object can call some functions or act on different
+input (abort a test if it is wrong). The test driver injects what it expects
+the mock object to return. CMocka provides and API to easily mock code.
+
+Read the article <a href="https://lwn.net/Articles/558106/">Unit testing with mock objects in C</a>
+to learn more.
+
+*/
diff --git a/third_party/cmocka/example/CMakeLists.txt b/third_party/cmocka/example/CMakeLists.txt
new file mode 100644
index 0000000..c2d3423
--- /dev/null
+++ b/third_party/cmocka/example/CMakeLists.txt
@@ -0,0 +1,90 @@
+project(cmocka-examples C)
+
+include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMOCKA_PUBLIC_INCLUDE_DIRS}
+)
+
+set_source_files_properties(
+ calculator.c
+ calculator_test.c
+ allocate_module.c
+ allocate_module_test.c
+ run_tests.c
+ PROPERTIES
+ COMPILE_FLAGS -DUNIT_TESTING=1)
+
+add_executable(fixture_test fixture_test.c)
+target_link_libraries(fixture_test ${CMOCKA_SHARED_LIBRARY})
+
+add_test(fixture_test ${CMAKE_CURRENT_BINARY_DIR}/fixture_test)
+
+add_executable(calculator_test calculator.c calculator_test.c)
+target_link_libraries(calculator_test ${CMOCKA_SHARED_LIBRARY})
+
+add_test(calculator_test ${CMAKE_CURRENT_BINARY_DIR}/calculator_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)
+set_tests_properties(
+ allocate_module_test
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "\\[ FAILED \\] 3 test"
+)
+
+add_executable(assert_macro_test assert_macro.c assert_macro_test.c)
+target_link_libraries(assert_macro_test ${CMOCKA_SHARED_LIBRARY})
+
+add_test(assert_macro_test ${CMAKE_CURRENT_BINARY_DIR}/assert_macro_test)
+set_tests_properties(
+ assert_macro_test
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "\\[ FAILED \\] 2 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_macro_test)
+set_tests_properties(
+ assert_module_test
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "\\[ FAILED \\] 2 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)
+
+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)
+
+add_executable(product_database_test product_database.c product_database_test.c)
+target_link_libraries(product_database_test ${CMOCKA_SHARED_LIBRARY})
+
+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"
+)
+
+add_executable(run_tests run_tests.c)
+target_link_libraries(run_tests ${CMOCKA_SHARED_LIBRARY})
+
+add_test(run_tests ${CMAKE_CURRENT_BINARY_DIR}/run_tests)
+
+if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
+ add_subdirectory(chef_wrap)
+endif()
diff --git a/third_party/cmocka/example/allocate_module.c b/third_party/cmocka/example/allocate_module.c
new file mode 100644
index 0000000..295e10e
--- /dev/null
+++ b/third_party/cmocka/example/allocate_module.c
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#include <sys/types.h>
+#include <stdlib.h>
+
+#if UNIT_TESTING
+extern void* _test_malloc(const size_t size, const char* file, const int line);
+extern void* _test_calloc(const size_t number_of_elements, const size_t size,
+ const char* file, const int line);
+extern void _test_free(void* const ptr, const char* file, const int line);
+
+#define malloc(size) _test_malloc(size, __FILE__, __LINE__)
+#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
+#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
+#endif // UNIT_TESTING
+
+void leak_memory(void);
+void buffer_overflow(void);
+void buffer_underflow(void);
+
+void leak_memory(void) {
+ int * const temporary = (int*)malloc(sizeof(int));
+ *temporary = 0;
+}
+
+void buffer_overflow(void) {
+ char * const memory = (char*)malloc(sizeof(int));
+ memory[sizeof(int)] = '!';
+ free(memory);
+}
+
+void buffer_underflow(void) {
+ char * const memory = (char*)malloc(sizeof(int));
+ memory[-1] = '!';
+ free(memory);
+}
diff --git a/third_party/cmocka/example/allocate_module_test.c b/third_party/cmocka/example/allocate_module_test.c
new file mode 100644
index 0000000..1d1e164
--- /dev/null
+++ b/third_party/cmocka/example/allocate_module_test.c
@@ -0,0 +1,53 @@
+/*
+ * 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>
+
+extern void leak_memory();
+extern void buffer_overflow();
+extern void buffer_underflow();
+
+/* Test case that fails as leak_memory() leaks a dynamically allocated block. */
+static void leak_memory_test(void **state) {
+ (void) state; /* unused */
+
+ leak_memory();
+}
+
+/* Test case that fails as buffer_overflow() corrupts an allocated block. */
+static void buffer_overflow_test(void **state) {
+ (void) state; /* unused */
+
+ buffer_overflow();
+}
+
+/* Test case that fails as buffer_underflow() corrupts an allocated block. */
+static void buffer_underflow_test(void **state) {
+ (void) state; /* unused */
+
+ buffer_underflow();
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test(leak_memory_test),
+ unit_test(buffer_overflow_test),
+ unit_test(buffer_underflow_test),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/assert_macro.c b/third_party/cmocka/example/assert_macro.c
new file mode 100644
index 0000000..9590590
--- /dev/null
+++ b/third_party/cmocka/example/assert_macro.c
@@ -0,0 +1,39 @@
+/*
+ * 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 <string.h>
+#include "assert_macro.h"
+
+static const char* status_code_strings[] = {
+ "Address not found",
+ "Connection dropped",
+ "Connection timed out",
+};
+
+const char* get_status_code_string(const unsigned int status_code) {
+ return status_code_strings[status_code];
+}
+
+unsigned int string_to_status_code(const char* const status_code_string) {
+ unsigned int i;
+ for (i = 0; i < sizeof(status_code_strings) /
+ sizeof(status_code_strings[0]); i++) {
+ if (strcmp(status_code_strings[i], status_code_string) == 0) {
+ return i;
+ }
+ }
+ return ~0U;
+}
diff --git a/third_party/cmocka/example/assert_macro.h b/third_party/cmocka/example/assert_macro.h
new file mode 100644
index 0000000..789380c
--- /dev/null
+++ b/third_party/cmocka/example/assert_macro.h
@@ -0,0 +1,2 @@
+const char* get_status_code_string(const unsigned int status_code);
+unsigned int string_to_status_code(const char* const status_code_string);
diff --git a/third_party/cmocka/example/assert_macro_test.c b/third_party/cmocka/example/assert_macro_test.c
new file mode 100644
index 0000000..efe1c64
--- /dev/null
+++ b/third_party/cmocka/example/assert_macro_test.c
@@ -0,0 +1,46 @@
+/*
+ * 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 "assert_macro.h"
+
+/* This test will fail since the string returned by get_status_code_string(0)
+ * doesn't match "Connection timed out". */
+static void get_status_code_string_test(void **state) {
+ (void) state; /* unused */
+
+ assert_string_equal(get_status_code_string(0), "Address not found");
+ assert_string_equal(get_status_code_string(1), "Connection timed out");
+}
+
+/* This test will fail since the status code of "Connection timed out" isn't 1 */
+static void string_to_status_code_test(void **state) {
+ (void) state; /* unused */
+
+ assert_int_equal(string_to_status_code("Address not found"), 0);
+ assert_int_equal(string_to_status_code("Connection timed out"), 1);
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test(get_status_code_string_test),
+ unit_test(string_to_status_code_test),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/assert_module.c b/third_party/cmocka/example/assert_module.c
new file mode 100644
index 0000000..bb75aaa
--- /dev/null
+++ b/third_party/cmocka/example/assert_module.c
@@ -0,0 +1,38 @@
+/*
+ * 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 <assert.h>
+
+#include "assert_module.h"
+
+/* If unit testing is enabled override assert with mock_assert(). */
+#if UNIT_TESTING
+extern void mock_assert(const int result, const char* const expression,
+ const char * const file, const int line);
+#undef assert
+#define assert(expression) \
+ mock_assert(((expression) ? 1 : 0), #expression, __FILE__, __LINE__);
+#endif /* UNIT_TESTING */
+
+void increment_value(int * const value) {
+ assert(value);
+ (*value) ++;
+}
+
+void decrement_value(int * const value) {
+ if (value) {
+ (*value) --;
+ }
+}
diff --git a/third_party/cmocka/example/assert_module.h b/third_party/cmocka/example/assert_module.h
new file mode 100644
index 0000000..b68b4d9
--- /dev/null
+++ b/third_party/cmocka/example/assert_module.h
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+
+void increment_value(int * const value);
+void decrement_value(int * const value);
diff --git a/third_party/cmocka/example/assert_module_test.c b/third_party/cmocka/example/assert_module_test.c
new file mode 100644
index 0000000..6f4f0a9
--- /dev/null
+++ b/third_party/cmocka/example/assert_module_test.c
@@ -0,0 +1,56 @@
+/*
+ * 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 "assert_module.h"
+
+extern void increment_value(int * const value);
+
+/* This test case will fail but the assert is caught by run_tests() and the
+ * next test is executed. */
+static void increment_value_fail(void **state) {
+ (void) state;
+
+ increment_value(NULL);
+}
+
+/* This test case succeeds since increment_value() asserts on the NULL
+ * pointer. */
+static void increment_value_assert(void **state) {
+ (void) state;
+
+ expect_assert_failure(increment_value(NULL));
+}
+
+/* This test case fails since decrement_value() doesn't assert on a NULL
+ * pointer. */
+static void decrement_value_fail(void **state) {
+ (void) state;
+
+ expect_assert_failure(decrement_value(NULL));
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test(increment_value_fail),
+ unit_test(increment_value_assert),
+ unit_test(decrement_value_fail),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/calculator.c b/third_party/cmocka/example/calculator.c
new file mode 100644
index 0000000..684fb9b
--- /dev/null
+++ b/third_party/cmocka/example/calculator.c
@@ -0,0 +1,286 @@
+/*
+ * 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.
+ */
+
+/* A calculator example used to demonstrate the cmocka testing library. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <assert.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* If this is being built for a unit test. */
+#if UNIT_TESTING
+
+/* Redirect printf to a function in the test application so it's possible to
+ * test the standard output. */
+#ifdef printf
+#undef printf
+#endif /* printf */
+extern int example_test_printf(const char *format, ...);
+#define printf example_test_printf
+
+extern void print_message(const char *format, ...);
+
+/* Redirect fprintf to a function in the test application so it's possible to
+ * test error messages. */
+#ifdef fprintf
+#undef fprintf
+#endif /* fprintf */
+#define fprintf example_test_fprintf
+
+extern int example_test_fprintf(FILE * const file, const char *format, ...);
+
+/* Redirect assert to mock_assert() so assertions can be caught by cmocka. */
+#ifdef assert
+#undef assert
+#endif /* assert */
+#define assert(expression) \
+ mock_assert((int)(expression), #expression, __FILE__, __LINE__)
+void mock_assert(const int result, const char* expression, const char *file,
+ const int line);
+
+/* Redirect calloc and free to test_calloc() and test_free() so cmocka can
+ * check for memory leaks. */
+#ifdef calloc
+#undef calloc
+#endif /* calloc */
+#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
+#ifdef free
+#undef free
+#endif /* free */
+#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
+void* _test_calloc(const size_t number_of_elements, const size_t size,
+ const char* file, const int line);
+void _test_free(void* const ptr, const char* file, const int line);
+
+int example_main(int argc, char *argv[]);
+/* main is defined in the unit test so redefine name of the the main function
+ * here. */
+#define main example_main
+
+/* All functions in this object need to be exposed to the test application,
+ * so redefine static to nothing. */
+#define static
+
+#endif /* UNIT_TESTING */
+
+
+/* A binary arithmetic integer operation (add, subtract etc.) */
+typedef int (*BinaryOperator)(int a, int b);
+
+/* Structure which maps operator strings to functions. */
+typedef struct OperatorFunction {
+ const char* operator;
+ BinaryOperator function;
+} OperatorFunction;
+
+
+BinaryOperator find_operator_function_by_string(
+ const size_t number_of_operator_functions,
+ const OperatorFunction * const operator_functions,
+ const char* const operator_string);
+
+int perform_operation(
+ int number_of_arguments, char *arguments[],
+ const size_t number_of_operator_functions,
+ const OperatorFunction * const operator_functions,
+ int * const number_of_intermediate_values,
+ int ** const intermediate_values, int * const error_occurred);
+
+static int add(int a, int b);
+static int subtract(int a, int b);
+static int multiply(int a, int b);
+static int divide(int a, int b);
+
+/* Associate operator strings to functions. */
+static OperatorFunction operator_function_map[] = {
+ {"+", add},
+ {"-", subtract},
+ {"*", multiply},
+ {"/", divide},
+};
+
+static int add(int a, int b) {
+ return a + b;
+}
+
+static int subtract(int a, int b) {
+ return a - b;
+}
+
+static int multiply(int a, int b) {
+ return a * b;
+}
+
+static int divide(int a, int b) {
+ assert(b); /* Check for divide by zero. */
+ return a / b;
+}
+
+/* Searches the specified array of operator_functions for the function
+ * associated with the specified operator_string. This function returns the
+ * function associated with operator_string if successful, NULL otherwise.
+ */
+BinaryOperator find_operator_function_by_string(
+ const size_t number_of_operator_functions,
+ const OperatorFunction * const operator_functions,
+ const char* const operator_string) {
+ size_t i;
+ assert(!number_of_operator_functions || operator_functions);
+ assert(operator_string != NULL);
+
+ for (i = 0; i < number_of_operator_functions; i++) {
+ const OperatorFunction *const operator_function =
+ &operator_functions[i];
+ if (strcmp(operator_function->operator, operator_string) == 0) {
+ return operator_function->function;
+ }
+ }
+ return NULL;
+}
+
+/* Perform a series of binary arithmetic integer operations with no operator
+ * precedence.
+ *
+ * The input expression is specified by arguments which is an array of
+ * containing number_of_arguments strings. Operators invoked by the expression
+ * are specified by the array operator_functions containing
+ * number_of_operator_functions, OperatorFunction structures. The value of
+ * each binary operation is stored in a pointer returned to intermediate_values
+ * which is allocated by malloc().
+ *
+ * If successful, this function returns the integer result of the operations.
+ * If an error occurs while performing the operation error_occurred is set to
+ * 1, the operation is aborted and 0 is returned.
+ */
+int perform_operation(
+ int number_of_arguments, char *arguments[],
+ const size_t number_of_operator_functions,
+ const OperatorFunction * const operator_functions,
+ int * const number_of_intermediate_values,
+ int ** const intermediate_values, int * const error_occurred) {
+ char *end_of_integer;
+ int value;
+ int i;
+ assert(!number_of_arguments || arguments);
+ assert(!number_of_operator_functions || operator_functions);
+ assert(error_occurred != NULL);
+ assert(number_of_intermediate_values != NULL);
+ assert(intermediate_values != NULL);
+
+ *error_occurred = 0;
+ *number_of_intermediate_values = 0;
+ *intermediate_values = NULL;
+ if (!number_of_arguments)
+ return 0;
+
+ /* Parse the first value. */
+ value = (int)strtol(arguments[0], &end_of_integer, 10);
+ if (end_of_integer == arguments[0]) {
+ /* If an error occurred while parsing the integer. */
+ fprintf(stderr, "Unable to parse integer from argument %s\n",
+ arguments[0]);
+ *error_occurred = 1;
+ return 0;
+ }
+
+ /* Allocate an array for the output values. */
+ *intermediate_values = calloc(((number_of_arguments - 1) / 2),
+ sizeof(**intermediate_values));
+
+ i = 1;
+ while (i < number_of_arguments) {
+ int other_value;
+ const char* const operator_string = arguments[i];
+ const BinaryOperator function = find_operator_function_by_string(
+ number_of_operator_functions, operator_functions, operator_string);
+ int * const intermediate_value =
+ &((*intermediate_values)[*number_of_intermediate_values]);
+ (*number_of_intermediate_values) ++;
+
+ if (!function) {
+ fprintf(stderr, "Unknown operator %s, argument %d\n",
+ operator_string, i);
+ *error_occurred = 1;
+ break;
+ }
+ i ++;
+
+ if (i == number_of_arguments) {
+ fprintf(stderr, "Binary operator %s missing argument\n",
+ operator_string);
+ *error_occurred = 1;
+ break;
+ }
+
+ other_value = (int)strtol(arguments[i], &end_of_integer, 10);
+ if (end_of_integer == arguments[i]) {
+ /* If an error occurred while parsing the integer. */
+ fprintf(stderr, "Unable to parse integer %s of argument %d\n",
+ arguments[i], i);
+ *error_occurred = 1;
+ break;
+ }
+ i ++;
+
+ /* Perform the operation and store the intermediate value. */
+ *intermediate_value = function(value, other_value);
+ value = *intermediate_value;
+ }
+ if (*error_occurred) {
+ free(*intermediate_values);
+ *intermediate_values = NULL;
+ *number_of_intermediate_values = 0;
+ return 0;
+ }
+ return value;
+}
+
+int main(int argc, char *argv[]) {
+ int return_value;
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ /* Peform the operation. */
+ const int result = perform_operation(
+ argc - 1, &argv[1],
+ sizeof(operator_function_map) / sizeof(operator_function_map[0]),
+ operator_function_map, &number_of_intermediate_values,
+ &intermediate_values, &return_value);
+
+ /* If no errors occurred display the result. */
+ if (!return_value && argc > 1) {
+ int i;
+ int intermediate_value_index = 0;
+ printf("%s\n", argv[1]);
+ for (i = 2; i < argc; i += 2) {
+ assert(intermediate_value_index < number_of_intermediate_values);
+ printf(" %s %s = %d\n", argv[i], argv[i + 1],
+ intermediate_values[intermediate_value_index++]);
+ }
+ printf("= %d\n", result);
+ }
+ if (intermediate_values) {
+ free(intermediate_values);
+ }
+
+ return return_value;
+}
diff --git a/third_party/cmocka/example/calculator_test.c b/third_party/cmocka/example/calculator_test.c
new file mode 100644
index 0000000..fc2bca0
--- /dev/null
+++ b/third_party/cmocka/example/calculator_test.c
@@ -0,0 +1,480 @@
+/*
+ * 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 <stdio.h>
+
+#ifdef _WIN32
+/* Compatibility with the Windows standard C library. */
+#define vsnprintf _vsnprintf
+#endif /* _WIN32 */
+
+#define array_length(x) (sizeof(x) / sizeof((x)[0]))
+
+/* To simplify this code, these functions and data structures could have been
+ * separated out from the application example.c into a header shared with
+ * test application. However, this example illustrates how it's possible to
+ * test existing code with little modification. */
+
+typedef int (*BinaryOperator)(int a, int b);
+
+typedef struct OperatorFunction {
+ const char* operator;
+ BinaryOperator function;
+} OperatorFunction;
+
+extern int add(int a, int b);
+extern int subtract(int a, int b);
+extern int multiply(int a, int b);
+extern int divide(int a, int b);
+extern BinaryOperator find_operator_function_by_string(
+ const size_t number_of_operator_functions,
+ const OperatorFunction * const operator_functions,
+ const char* const operator_string);
+extern int perform_operation(
+ int number_of_arguments, char *arguments[],
+ const size_t number_of_operator_functions,
+ const OperatorFunction * const operator_functions,
+ int * const number_of_intermediate_values,
+ int ** const intermediate_values, int * const error_occurred);
+extern int example_main(int argc, char *argv[]);
+
+int example_test_fprintf(FILE* const file, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
+int example_test_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
+
+char temporary_buffer[256];
+
+/* A mock fprintf function that checks the value of strings printed to the
+ * standard error stream. */
+int example_test_fprintf(FILE* const file, const char *format, ...) {
+ int return_value;
+ va_list args;
+ assert_true(file == stderr);
+ va_start(args, format);
+ return_value = vsnprintf(temporary_buffer, sizeof(temporary_buffer),
+ format, args);
+ check_expected(temporary_buffer);
+ va_end(args);
+ return return_value;
+}
+
+/* A mock printf function that checks the value of strings printed to the
+ * standard output stream. */
+int example_test_printf(const char *format, ...) {
+ int return_value;
+ va_list args;
+ va_start(args, format);
+ return_value = vsnprintf(temporary_buffer, sizeof(temporary_buffer),
+ format, args);
+ check_expected(temporary_buffer);
+ va_end(args);
+ return return_value;
+}
+
+/* A mock binary operator function. */
+static int binary_operator(int a, int b) {
+ check_expected(a);
+ check_expected(b);
+ return (int)mock();
+}
+
+
+/* Ensure add() adds two integers correctly. */
+static void test_add(void **state) {
+ (void) state; /* unused */
+
+ assert_int_equal(add(3, 3), 6);
+ assert_int_equal(add(3, -3), 0);
+}
+
+/* Ensure subtract() subtracts two integers correctly. */
+static void test_subtract(void **state) {
+ (void) state; /* unused */
+
+ assert_int_equal(subtract(3, 3), 0);
+ assert_int_equal(subtract(3, -3), 6);
+}
+
+/* Ensure multiple() mulitplies two integers correctly. */
+static void test_multiply(void **state) {
+ (void) state; /* unused */
+
+ assert_int_equal(multiply(3, 3), 9);
+ assert_int_equal(multiply(3, 0), 0);
+}
+
+/* Ensure divide() divides one integer by another correctly. */
+static void test_divide(void **state) {
+ (void) state; /* unused */
+
+ assert_int_equal(divide(10, 2), 5);
+ assert_int_equal(divide(2, 10), 0);
+}
+
+/* Ensure divide() asserts when trying to divide by zero. */
+static void test_divide_by_zero(void **state) {
+ (void) state; /* unused */
+
+ expect_assert_failure(divide(100, 0));
+}
+
+/* Ensure find_operator_function_by_string() asserts when a NULL pointer is
+ * specified as the table to search. */
+static void test_find_operator_function_by_string_null_functions(void **state) {
+ (void) state; /* unused */
+
+ expect_assert_failure(find_operator_function_by_string(1, NULL, "test"));
+}
+
+/* Ensure find_operator_function_by_string() asserts when a NULL pointer is
+ * specified as the string to search for. */
+static void test_find_operator_function_by_string_null_string(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+
+ (void) state; /* unused */
+
+ expect_assert_failure(find_operator_function_by_string(
+ array_length(operator_functions), operator_functions, NULL));
+}
+
+/* Ensure find_operator_function_by_string() returns NULL when a NULL pointer
+ * is specified as the table to search when the table size is 0. */
+static void test_find_operator_function_by_string_valid_null_functions(void **state) {
+ (void) state; /* unused */
+
+ assert_int_equal(find_operator_function_by_string(0, NULL, "test"), NULL);
+}
+
+/* Ensure find_operator_function_by_string() returns NULL when searching for
+ * an operator string that isn't in the specified table. */
+static void test_find_operator_function_by_string_not_found(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ {"-", binary_operator},
+ {"/", binary_operator},
+ };
+
+ (void) state; /* unused */
+
+ assert_int_equal(find_operator_function_by_string(
+ array_length(operator_functions), operator_functions, "test"),
+ NULL);
+}
+
+/* Ensure find_operator_function_by_string() returns the correct function when
+ * searching for an operator string that is in the specified table. */
+static void test_find_operator_function_by_string_found(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", (BinaryOperator)0x12345678},
+ {"-", (BinaryOperator)0xDEADBEEF},
+ {"/", (BinaryOperator)0xABADCAFE},
+ };
+
+ (void) state; /* unused */
+
+ assert_int_equal(find_operator_function_by_string(
+ array_length(operator_functions), operator_functions, "-"),
+ 0xDEADBEEF);
+}
+
+/* Ensure perform_operation() asserts when a NULL arguments array is specified. */
+static void test_perform_operation_null_args(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_assert_failure(perform_operation(
+ 1, NULL, array_length(operator_functions), operator_functions,
+ &number_of_intermediate_values, &intermediate_values,
+ &error_occurred));
+}
+
+/* Ensure perform_operation() asserts when a NULL operator_functions array is
+ * specified. */
+static void test_perform_operation_null_operator_functions(void **state) {
+ const char *args[] = {
+ "1", "+", "2", "*", "4"
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_assert_failure(perform_operation(
+ array_length(args), (char **) args, 1, NULL, &number_of_intermediate_values,
+ &intermediate_values, &error_occurred));
+}
+
+/* Ensure perform_operation() asserts when a NULL pointer is specified for
+ * number_of_intermediate_values. */
+static void test_perform_operation_null_number_of_intermediate_values(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ const char *args[] = {
+ "1", "+", "2", "*", "4"
+ };
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_assert_failure(perform_operation(
+ array_length(args), (char **) args, 1, operator_functions, NULL,
+ &intermediate_values, &error_occurred));
+}
+
+/* Ensure perform_operation() asserts when a NULL pointer is specified for
+ * intermediate_values. */
+static void test_perform_operation_null_intermediate_values(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ const char *args[] = {
+ "1", "+", "2", "*", "4"
+ };
+ int number_of_intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_assert_failure(perform_operation(
+ array_length(args), (char **) args, array_length(operator_functions),
+ operator_functions, &number_of_intermediate_values, NULL,
+ &error_occurred));
+}
+
+/* Ensure perform_operation() returns 0 when no arguments are specified. */
+static void test_perform_operation_no_arguments(void **state) {
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ assert_int_equal(perform_operation(
+ 0, NULL, 0, NULL, &number_of_intermediate_values, &intermediate_values,
+ &error_occurred), 0);
+ assert_int_equal(error_occurred, 0);
+}
+
+/* Ensure perform_operation() returns an error if the first argument isn't
+ * an integer string. */
+static void test_perform_operation_first_arg_not_integer(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ const char *args[] = {
+ "test", "+", "2", "*", "4"
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_string(example_test_fprintf, temporary_buffer,
+ "Unable to parse integer from argument test\n");
+
+ assert_int_equal(perform_operation(
+ array_length(args), (char **) args, array_length(operator_functions),
+ operator_functions, &number_of_intermediate_values,
+ &intermediate_values, &error_occurred), 0);
+ assert_int_equal(error_occurred, 1);
+}
+
+/* Ensure perform_operation() returns an error when parsing an unknown
+ * operator. */
+static void test_perform_operation_unknown_operator(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ const char *args[] = {
+ "1", "*", "2", "*", "4"
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_string(example_test_fprintf, temporary_buffer,
+ "Unknown operator *, argument 1\n");
+
+ assert_int_equal(perform_operation(
+ array_length(args), (char **) args, array_length(operator_functions),
+ operator_functions, &number_of_intermediate_values,
+ &intermediate_values, &error_occurred), 0);
+ assert_int_equal(error_occurred, 1);
+}
+
+/* Ensure perform_operation() returns an error when nothing follows an
+ * operator. */
+static void test_perform_operation_missing_argument(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ const char *args[] = {
+ "1", "+",
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_string(example_test_fprintf, temporary_buffer,
+ "Binary operator + missing argument\n");
+
+ assert_int_equal(perform_operation(
+ array_length(args), (char **) args, array_length(operator_functions),
+ operator_functions, &number_of_intermediate_values,
+ &intermediate_values, &error_occurred), 0);
+ assert_int_equal(error_occurred, 1);
+}
+
+/* Ensure perform_operation() returns an error when an integer doesn't follow
+ * an operator. */
+static void test_perform_operation_no_integer_after_operator(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ };
+ const char *args[] = {
+ "1", "+", "test",
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ expect_string(example_test_fprintf, temporary_buffer,
+ "Unable to parse integer test of argument 2\n");
+
+ assert_int_equal(perform_operation(
+ array_length(args), (char **) args, array_length(operator_functions),
+ operator_functions, &number_of_intermediate_values,
+ &intermediate_values, &error_occurred), 0);
+ assert_int_equal(error_occurred, 1);
+}
+
+
+/* Ensure perform_operation() succeeds given valid input parameters. */
+static void test_perform_operation(void **state) {
+ const OperatorFunction operator_functions[] = {
+ {"+", binary_operator},
+ {"*", binary_operator},
+ };
+ const char *args[] = {
+ "1", "+", "3", "*", "10",
+ };
+ int number_of_intermediate_values;
+ int *intermediate_values;
+ int error_occurred;
+
+ (void) state; /* unused */
+
+ /* Setup return values of mock operator functions. */
+ /* Addition. */
+ expect_value(binary_operator, a, 1);
+ expect_value(binary_operator, b, 3);
+ will_return(binary_operator, 4);
+
+ /* Multiplication. */
+ expect_value(binary_operator, a, 4);
+ expect_value(binary_operator, b, 10);
+ will_return(binary_operator, 40);
+
+ assert_int_equal(perform_operation(
+ array_length(args), (char **) args, array_length(operator_functions),
+ operator_functions, &number_of_intermediate_values,
+ &intermediate_values, &error_occurred), 40);
+ assert_int_equal(error_occurred, 0);
+
+ assert_true(intermediate_values);
+ assert_int_equal(intermediate_values[0], 4);
+ assert_int_equal(intermediate_values[1], 40);
+ test_free(intermediate_values);
+}
+
+
+/* Ensure main() in example.c succeeds given no arguments. */
+static void test_example_main_no_args(void **state) {
+ const char *args[] = {
+ "example",
+ };
+
+ (void) state; /* unused */
+
+ assert_int_equal(example_main(array_length(args), (char **) args), 0);
+}
+
+
+
+/* Ensure main() in example.c succeeds given valid input arguments. */
+static void test_example_main(void **state) {
+ const char *args[] = {
+ "example", "1", "+", "3", "*", "10",
+ };
+
+ (void) state; /* unused */
+
+ expect_string(example_test_printf, temporary_buffer, "1\n");
+ expect_string(example_test_printf, temporary_buffer, " + 3 = 4\n");
+ expect_string(example_test_printf, temporary_buffer, " * 10 = 40\n");
+ expect_string(example_test_printf, temporary_buffer, "= 40\n");
+
+ assert_int_equal(example_main(array_length(args), (char **) args), 0);
+}
+
+
+int main(void) {
+ UnitTest tests[] = {
+ unit_test(test_add),
+ unit_test(test_subtract),
+ unit_test(test_multiply),
+ unit_test(test_divide),
+ unit_test(test_divide_by_zero),
+ unit_test(test_find_operator_function_by_string_null_functions),
+ unit_test(test_find_operator_function_by_string_null_string),
+ unit_test(test_find_operator_function_by_string_valid_null_functions),
+ unit_test(test_find_operator_function_by_string_not_found),
+ unit_test(test_find_operator_function_by_string_found),
+ unit_test(test_perform_operation_null_args),
+ unit_test(test_perform_operation_null_operator_functions),
+ unit_test(test_perform_operation_null_number_of_intermediate_values),
+ unit_test(test_perform_operation_null_intermediate_values),
+ unit_test(test_perform_operation_no_arguments),
+ unit_test(test_perform_operation_first_arg_not_integer),
+ unit_test(test_perform_operation_unknown_operator),
+ unit_test(test_perform_operation_missing_argument),
+ unit_test(test_perform_operation_no_integer_after_operator),
+ unit_test(test_perform_operation),
+ unit_test(test_example_main_no_args),
+ unit_test(test_example_main),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/chef_wrap/CMakeLists.txt b/third_party/cmocka/example/chef_wrap/CMakeLists.txt
new file mode 100644
index 0000000..60d5a36
--- /dev/null
+++ b/third_party/cmocka/example/chef_wrap/CMakeLists.txt
@@ -0,0 +1,17 @@
+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"
+)
diff --git a/third_party/cmocka/example/chef_wrap/chef.c b/third_party/cmocka/example/chef_wrap/chef.c
new file mode 100644
index 0000000..1429cde
--- /dev/null
+++ b/third_party/cmocka/example/chef_wrap/chef.c
@@ -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/third_party/cmocka/example/chef_wrap/chef.h b/third_party/cmocka/example/chef_wrap/chef.h
new file mode 100644
index 0000000..c1a01c7
--- /dev/null
+++ b/third_party/cmocka/example/chef_wrap/chef.h
@@ -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/third_party/cmocka/example/chef_wrap/waiter_test_wrap.c b/third_party/cmocka/example/chef_wrap/waiter_test_wrap.c
new file mode 100644
index 0000000..1b8ed94
--- /dev/null
+++ b/third_party/cmocka/example/chef_wrap/waiter_test_wrap.c
@@ -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(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, "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, "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 UnitTest tests[] = {
+ unit_test(test_order_hotdog),
+ unit_test(test_bad_dish),
+ };
+
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/chef_wrap/waiter_test_wrap.h b/third_party/cmocka/example/chef_wrap/waiter_test_wrap.h
new file mode 100644
index 0000000..9178ca2
--- /dev/null
+++ b/third_party/cmocka/example/chef_wrap/waiter_test_wrap.h
@@ -0,0 +1,2 @@
+
+int __wrap_chef_cook(const char *order, char **dish_out);
diff --git a/third_party/cmocka/example/customer_database.c b/third_party/cmocka/example/customer_database.c
new file mode 100644
index 0000000..2d49e19
--- /dev/null
+++ b/third_party/cmocka/example/customer_database.c
@@ -0,0 +1,51 @@
+/*
+ * 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/third_party/cmocka/example/customer_database_test.c b/third_party/cmocka/example/customer_database_test.c
new file mode 100644
index 0000000..33364d9
--- /dev/null
+++ b/third_party/cmocka/example/customer_database_test.c
@@ -0,0 +1,88 @@
+/*
+ * 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();
+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, &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 UnitTest tests[] = {
+ unit_test(test_connect_to_customer_database),
+ unit_test(test_get_customer_id_by_name),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/database.h b/third_party/cmocka/example/database.h
new file mode 100644
index 0000000..880db3c
--- /dev/null
+++ b/third_party/cmocka/example/database.h
@@ -0,0 +1,37 @@
+/*
+ * 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 DatabaseConnection DatabaseConnection;
+
+/* Function that takes an SQL query string and sets results to an array of
+ * pointers with the result of the query. The value returned specifies the
+ * number of items in the returned array of results. The returned array of
+ * results are statically allocated and should not be deallocated using free()
+ */
+typedef unsigned int (*QueryDatabase)(
+ DatabaseConnection* const connection, const char * const query_string,
+ void *** const results);
+
+/* Connection to a database. */
+struct DatabaseConnection {
+ const char *url;
+ unsigned int port;
+ QueryDatabase query_database;
+};
+
+/* Connect to a database. */
+DatabaseConnection* connect_to_database(const char * const url,
+ const unsigned int port);
+
diff --git a/third_party/cmocka/example/fixture_test.c b/third_party/cmocka/example/fixture_test.c
new file mode 100644
index 0000000..757394a
--- /dev/null
+++ b/third_party/cmocka/example/fixture_test.c
@@ -0,0 +1,37 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdlib.h>
+
+static void setup_only(void **state)
+{
+ *state = malloc(1);
+}
+
+static void teardown_only(void **state)
+{
+ free(*state);
+}
+
+static void malloc_setup_test(void **state)
+{
+ assert_non_null(*state);
+ free(*state);
+}
+
+static void malloc_teardown_test(void **state)
+{
+ *state = malloc(1);
+ assert_non_null(*state);
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test_setup(malloc_setup_test, setup_only),
+ unit_test_teardown(malloc_teardown_test, teardown_only),
+ };
+
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/key_value.c b/third_party/cmocka/example/key_value.c
new file mode 100644
index 0000000..057274a
--- /dev/null
+++ b/third_party/cmocka/example/key_value.c
@@ -0,0 +1,51 @@
+/*
+ * 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/third_party/cmocka/example/key_value.h b/third_party/cmocka/example/key_value.h
new file mode 100644
index 0000000..736faf2
--- /dev/null
+++ b/third_party/cmocka/example/key_value.h
@@ -0,0 +1,27 @@
+/*
+ * 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/third_party/cmocka/example/key_value_test.c b/third_party/cmocka/example/key_value_test.c
new file mode 100644
index 0000000..da72ea2
--- /dev/null
+++ b/third_party/cmocka/example/key_value_test.c
@@ -0,0 +1,73 @@
+/*
+ * 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 void 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]));
+}
+
+static void destroy_key_values(void **state) {
+ test_free(*state);
+ set_key_values(NULL, 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 UnitTest tests[] = {
+ unit_test_setup_teardown(test_find_item_by_value, create_key_values,
+ destroy_key_values),
+ unit_test_setup_teardown(test_sort_items_by_key, create_key_values,
+ destroy_key_values),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/product_database.c b/third_party/cmocka/example/product_database.c
new file mode 100644
index 0000000..980b7e5
--- /dev/null
+++ b/third_party/cmocka/example/product_database.c
@@ -0,0 +1,24 @@
+/*
+ * 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/third_party/cmocka/example/product_database_test.c b/third_party/cmocka/example/product_database_test.c
new file mode 100644
index 0000000..c8d7587
--- /dev/null
+++ b/third_party/cmocka/example/product_database_test.c
@@ -0,0 +1,72 @@
+/*
+ * 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(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 UnitTest tests[] = {
+ unit_test(test_connect_to_product_database),
+ unit_test(test_connect_to_product_database_bad_url),
+ unit_test(test_connect_to_product_database_missing_parameter),
+ };
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/example/run_tests.c b/third_party/cmocka/example/run_tests.c
new file mode 100644
index 0000000..817629b
--- /dev/null
+++ b/third_party/cmocka/example/run_tests.c
@@ -0,0 +1,54 @@
+/*
+ * 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>
+
+static void setup(void **state) {
+ int *answer = malloc(sizeof(int));
+
+ assert_non_null(answer);
+ *answer = 42;
+
+ *state = answer;
+}
+
+static void teardown(void **state) {
+ free(*state);
+}
+
+/* A test case that does nothing and succeeds. */
+static void null_test_success(void **state) {
+ (void) state;
+}
+
+/* A test case that does check if an int is equal. */
+static void int_test_success(void **state) {
+ int *answer = *state;
+
+ assert_int_equal(*answer, 42);
+}
+
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test(null_test_success),
+ unit_test_setup_teardown(int_test_success, setup, teardown),
+ };
+
+ return run_tests(tests);
+}
diff --git a/third_party/cmocka/include/CMakeLists.txt b/third_party/cmocka/include/CMakeLists.txt
new file mode 100644
index 0000000..9172633
--- /dev/null
+++ b/third_party/cmocka/include/CMakeLists.txt
@@ -0,0 +1,14 @@
+project(cmocka-headers C)
+
+set(cmocka_HDRS
+ cmocka.h
+)
+
+install(
+ FILES
+ ${cmocka_HDRS}
+ DESTINATION
+ ${INCLUDE_INSTALL_DIR}
+ COMPONENT
+ headers
+)
diff --git a/third_party/cmocka/include/cmocka.h b/third_party/cmocka/include/cmocka.h
new file mode 100644
index 0000000..0df2e90
--- /dev/null
+++ b/third_party/cmocka/include/cmocka.h
@@ -0,0 +1,1736 @@
+/*
+ * 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.
+ */
+#ifndef CMOCKA_H_
+#define CMOCKA_H_
+
+#ifdef _WIN32
+#if _MSC_VER < 1500
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+int __stdcall IsDebuggerPresent();
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* __cplusplus */
+#endif /* _MSC_VER < 1500 */
+#endif /* _WIN32 */
+
+/*
+ * These headers or their equivalents should be included prior to including
+ * this header file.
+ *
+ * #include <stdarg.h>
+ * #include <stddef.h>
+ * #include <setjmp.h>
+ *
+ * This allows test applications to use custom definitions of C standard
+ * library functions and types.
+ */
+
+/* For those who are used to __func__ from gcc. */
+#ifndef __func__
+#define __func__ __FUNCTION__
+#endif
+
+/* GCC have printf type attribute check. */
+#ifdef __GNUC__
+#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
+#else
+#define PRINTF_ATTRIBUTE(a,b)
+#endif /* __GNUC__ */
+
+/**
+ * @defgroup cmocka The CMocka API
+ *
+ * TODO Describe cmocka.
+ *
+ * @{
+ */
+
+/*
+ * Largest integral type. This type should be large enough to hold any
+ * pointer or integer supported by the compiler.
+ */
+#ifndef LargestIntegralType
+#define LargestIntegralType unsigned long long
+#endif /* LargestIntegralType */
+
+/* Printf format used to display LargestIntegralType. */
+#ifndef LargestIntegralTypePrintfFormat
+#ifdef _WIN32
+#define LargestIntegralTypePrintfFormat "%I64x"
+#else
+#define LargestIntegralTypePrintfFormat "%llx"
+#endif /* _WIN32 */
+#endif /* LargestIntegralTypePrintfFormat */
+
+/* Perform an unsigned cast to LargestIntegralType. */
+#define cast_to_largest_integral_type(value) \
+ ((LargestIntegralType)((size_t)(value)))
+
+/* Smallest integral type capable of holding a pointer. */
+#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
+# if defined(_WIN32)
+ /* WIN32 is an ILP32 platform */
+ typedef unsigned int uintptr_t;
+# elif defined(_WIN64)
+ typedef unsigned long int uintptr_t
+# else /* _WIN32 */
+
+/* ILP32 and LP64 platforms */
+# ifdef __WORDSIZE /* glibc */
+# if __WORDSIZE == 64
+ typedef unsigned long int uintptr_t;
+# else
+ typedef unsigned int uintptr_t;
+# endif /* __WORDSIZE == 64 */
+# else /* __WORDSIZE */
+# if defined(_LP64) || defined(_I32LPx)
+ typedef unsigned long int uintptr_t;
+# else
+ typedef unsigned int uintptr_t;
+# endif
+# endif /* __WORDSIZE */
+# endif /* _WIN32 */
+
+# define _UINTPTR_T
+# define _UINTPTR_T_DEFINED
+#endif /* !defined(_UINTPTR_T) || !defined(_UINTPTR_T_DEFINED) */
+
+/* Perform an unsigned cast to uintptr_t. */
+#define cast_to_pointer_integral_type(value) \
+ ((uintptr_t)(value))
+
+/* Perform a cast of a pointer to uintmax_t */
+#define cast_ptr_to_largest_integral_type(value) \
+cast_to_largest_integral_type(cast_to_pointer_integral_type(value))
+
+/**
+ * @defgroup cmocka_mock Mock Objects
+ * @ingroup cmocka
+ *
+ * Mock objects mock objects are simulated objects that mimic the behavior of
+ * real objects. Instead of calling the real objects, the tested object calls a
+ * mock object that merely asserts that the correct methods were called, with
+ * the expected parameters, in the correct order.
+ *
+ * <ul>
+ * <li><strong>will_return(function, value)</strong> - The will_return() macro
+ * pushes a value onto a stack of mock values. This macro is intended to be
+ * used by the unit test itself, while programming the behaviour of the mocked
+ * object.</li>
+ *
+ * <li><strong>mock()</strong> - the mock macro pops a value from a stack of
+ * test values. The user of the mock() macro is the mocked object that uses it
+ * to learn how it should behave.</li>
+ * </ul>
+ *
+ * Because the will_return() and mock() are intended to be used in pairs, the
+ * cmocka library would fail the test if there are more values pushed onto the
+ * stack using will_return() than consumed with mock() and vice-versa.
+ *
+ * The following unit test stub illustrates how would a unit test instruct the
+ * mock object to return a particular value:
+ *
+ * @code
+ * will_return(chef_cook, "hotdog");
+ * will_return(chef_cook, 0);
+ * @endcode
+ *
+ * Now the mock object can check if the parameter it received is the parameter
+ * which is expected by the test driver. This can be done the following way:
+ *
+ * @code
+ * int chef_cook(const char *order, char **dish_out)
+ * {
+ * check_expected(order);
+ * }
+ * @endcode
+ *
+ * For a complete example please at a look
+ * <a href="http://git.cryptomilk.org/projects/cmocka.git/tree/example/chef_wrap/waiter_test_wrap.c">here</a>.
+ *
+ * @{
+ */
+
+#ifdef DOXYGEN
+/**
+ * @brief Retrieve a return value of the current function.
+ *
+ * @return The value which was stored to return by this function.
+ *
+ * @see will_return()
+ */
+void *mock(void);
+#else
+#define mock() _mock(__func__, __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Retrieve a typed return value of the current function.
+ *
+ * The value would be casted to type internally to avoid having the
+ * caller to do the cast manually.
+ *
+ * @param[in] #type The expected type of the return value
+ *
+ * @return The value which was stored to return by this function.
+ *
+ * @code
+ * int param;
+ *
+ * param = mock_type(int);
+ * @endcode
+ *
+ * @see will_return()
+ * @see mock()
+ * @see mock_ptr_type()
+ */
+void *mock_type(#type);
+#else
+#define mock_type(type) ((type) mock())
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Retrieve a typed return value of the current function.
+ *
+ * The value would be casted to type internally to avoid having the
+ * caller to do the cast manually but also casted to uintptr_t to make
+ * sure the result has a valid size to be used as a pointer.
+ *
+ * @param[in] #type The expected type of the return value
+ *
+ * @return The value which was stored to return by this function.
+ *
+ * @code
+ * char *param;
+ *
+ * param = mock_ptr_type(char *);
+ * @endcode
+ *
+ * @see will_return()
+ * @see mock()
+ * @see mock_type()
+ */
+void *mock_ptr_type(#type);
+#else
+#define mock_ptr_type(type) ((type) (uintptr_t) mock())
+#endif
+
+
+#ifdef DOXYGEN
+/**
+ * @brief Store a value to be returned by mock() later.
+ *
+ * @param[in] #function The function which should return the given value.
+ *
+ * @param[in] value The value to be returned by mock().
+ *
+ * @code
+ * int return_integer(void)
+ * {
+ * return (int)mock();
+ * }
+ *
+ * static void test_integer_return(void **state)
+ * {
+ * will_return(return_integer, 42);
+ *
+ * assert_int_equal(my_function_calling_return_integer(), 42);
+ * }
+ * @endcode
+ *
+ * @see mock()
+ * @see will_return_count()
+ */
+void will_return(#function, void *value);
+#else
+#define will_return(function, value) \
+ _will_return(#function, __FILE__, __LINE__, \
+ cast_to_largest_integral_type(value), 1)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Store a value to be returned by mock() later.
+ *
+ * @param[in] #function The function which should return the given value.
+ *
+ * @param[in] value The value to be returned by mock().
+ *
+ * @param[in] count The parameter returns the number of times the value should
+ * be returned by mock(). If count is set to -1 the value will
+ * always be returned.
+ *
+ * @see mock()
+ */
+void will_return_count(#function, void *value, int count);
+#else
+#define will_return_count(function, value, count) \
+ _will_return(#function, __FILE__, __LINE__, \
+ cast_to_largest_integral_type(value), count)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Store a value that will be always returned by mock().
+ *
+ * @param[in] #function The function which should return the given value.
+ *
+ * @param[in] value The value to be returned by mock().
+ *
+ * This is equivalent to:
+ * @code
+ * will_return_count(function, value, -1);
+ * @endcode
+ *
+ * @see will_return_count()
+ * @see mock()
+ */
+void will_return_always(#function, void *value);
+#else
+#define will_return_always(function, value) \
+ will_return_count(function, (value), -1)
+#endif
+
+/** @} */
+
+/**
+ * @defgroup cmocka_param Checking Parameters
+ * @ingroup cmocka
+ *
+ * Functionality to store expected values for mock function parameters.
+ *
+ * In addition to storing the return values of mock functions, cmocka provides
+ * functionality to store expected values for mock function parameters using
+ * the expect_*() functions provided. A mock function parameter can then be
+ * validated using the check_expected() macro.
+ *
+ * Successive calls to expect_*() macros for a parameter queues values to check
+ * the specified parameter. check_expected() checks a function parameter
+ * against the next value queued using expect_*(), if the parameter check fails
+ * a test failure is signalled. In addition if check_expected() is called and
+ * no more parameter values are queued a test failure occurs.
+ *
+ * The following test stub illustrates how to do this. First is the the function
+ * we call in the test driver:
+ *
+ * @code
+ * static void test_driver(void **state)
+ * {
+ * expect_string(chef_cook, order, "hotdog");
+ * }
+ * @endcode
+ *
+ * Now the chef_cook function can check if the parameter we got passed is the
+ * parameter which is expected by the test driver. This can be done the
+ * following way:
+ *
+ * @code
+ * int chef_cook(const char *order, char **dish_out)
+ * {
+ * check_expected(order);
+ * }
+ * @endcode
+ *
+ * For a complete example please at a look at
+ * <a href="http://git.cryptomilk.org/projects/cmocka.git/tree/example/chef_wrap/waiter_test_wrap.c">here</a>
+ *
+ * @{
+ */
+
+/*
+ * Add a custom parameter checking function. If the event parameter is NULL
+ * the event structure is allocated internally by this function. If event
+ * parameter is provided it must be allocated on the heap and doesn't need to
+ * be deallocated by the caller.
+ */
+#ifdef DOXYGEN
+/**
+ * @brief Add a custom parameter checking function.
+ *
+ * If the event parameter is NULL the event structure is allocated internally
+ * by this function. If the parameter is provided it must be allocated on the
+ * heap and doesn't need to be deallocated by the caller.
+ *
+ * @param[in] #function The fuction to add a custom paramater checking function
+ * for.
+ *
+ * @param[in] #parameter The parametes passed to the function.
+ *
+ * @param[in] #check_function The check function to call.
+ *
+ * @param[in] check_data The data to pass to the check function.
+ */
+void expect_check(#function, #parameter, #check_function, const void *check_data);
+#else
+#define expect_check(function, parameter, check_function, check_data) \
+ _expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \
+ cast_to_largest_integral_type(check_data), NULL, 0)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value is part of the provided
+ * array.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value_array[] The array to check for the value.
+ *
+ * @see check_expected().
+ */
+void expect_in_set(#function, #parameter, uintmax_t value_array[]);
+#else
+#define expect_in_set(function, parameter, value_array) \
+ expect_in_set_count(function, parameter, value_array, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value is part of the provided
+ * array.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value_array[] The array to check for the value.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
+#else
+#define expect_in_set_count(function, parameter, value_array, count) \
+ _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \
+ sizeof(value_array) / sizeof((value_array)[0]), count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value is not part of the
+ * provided array.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value_array[] The array to check for the value.
+ *
+ * @see check_expected().
+ */
+void expect_not_in_set(#function, #parameter, uintmax_t value_array[]);
+#else
+#define expect_not_in_set(function, parameter, value_array) \
+ expect_not_in_set_count(function, parameter, value_array, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value is not part of the
+ * provided array.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value_array[] The array to check for the value.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
+#else
+#define expect_not_in_set_count(function, parameter, value_array, count) \
+ _expect_not_in_set( \
+ #function, #parameter, __FILE__, __LINE__, value_array, \
+ sizeof(value_array) / sizeof((value_array)[0]), count)
+#endif
+
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check a parameter is inside a numerical range.
+ * The check would succeed if minimum <= value <= maximum.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] minimum The lower boundary of the interval to check against.
+ *
+ * @param[in] maximum The upper boundary of the interval to check against.
+ *
+ * @see check_expected().
+ */
+void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum);
+#else
+#define expect_in_range(function, parameter, minimum, maximum) \
+ expect_in_range_count(function, parameter, minimum, maximum, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check a parameter is inside a
+ * numerical range. The check would succeed if minimum <= value <= maximum.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] minimum The lower boundary of the interval to check against.
+ *
+ * @param[in] maximum The upper boundary of the interval to check against.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count);
+#else
+#define expect_in_range_count(function, parameter, minimum, maximum, count) \
+ _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \
+ maximum, count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check a parameter is outside a numerical range.
+ * The check would succeed if minimum > value > maximum.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] minimum The lower boundary of the interval to check against.
+ *
+ * @param[in] maximum The upper boundary of the interval to check against.
+ *
+ * @see check_expected().
+ */
+void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum);
+#else
+#define expect_not_in_range(function, parameter, minimum, maximum) \
+ expect_not_in_range_count(function, parameter, minimum, maximum, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check a parameter is outside a
+ * numerical range. The check would succeed if minimum > value > maximum.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] minimum The lower boundary of the interval to check against.
+ *
+ * @param[in] maximum The upper boundary of the interval to check against.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count);
+#else
+#define expect_not_in_range_count(function, parameter, minimum, maximum, \
+ count) \
+ _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \
+ minimum, maximum, count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if a parameter is the given value.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value The value to check.
+ *
+ * @see check_expected().
+ */
+void expect_value(#function, #parameter, uintmax_t value);
+#else
+#define expect_value(function, parameter, value) \
+ expect_value_count(function, parameter, value, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check if a parameter is the given value.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value The value to check.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_value_count(#function, #parameter, uintmax_t value, size_t count);
+#else
+#define expect_value_count(function, parameter, value, count) \
+ _expect_value(#function, #parameter, __FILE__, __LINE__, \
+ cast_to_largest_integral_type(value), count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if a parameter isn't the given value.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value The value to check.
+ *
+ * @see check_expected().
+ */
+void expect_not_value(#function, #parameter, uintmax_t value);
+#else
+#define expect_not_value(function, parameter, value) \
+ expect_not_value_count(function, parameter, value, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check if a parameter isn't the given value.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] value The value to check.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_not_value_count(#function, #parameter, uintmax_t value, size_t count);
+#else
+#define expect_not_value_count(function, parameter, value, count) \
+ _expect_not_value(#function, #parameter, __FILE__, __LINE__, \
+ cast_to_largest_integral_type(value), count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value is equal to the
+ * provided string.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] string The string value to compare.
+ *
+ * @see check_expected().
+ */
+void expect_string(#function, #parameter, const char *string);
+#else
+#define expect_string(function, parameter, string) \
+ expect_string_count(function, parameter, string, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value is equal to the
+ * provided string.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] string The string value to compare.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_string_count(#function, #parameter, const char *string, size_t count);
+#else
+#define expect_string_count(function, parameter, string, count) \
+ _expect_string(#function, #parameter, __FILE__, __LINE__, \
+ (const char*)(string), count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value isn't equal to the
+ * provided string.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] string The string value to compare.
+ *
+ * @see check_expected().
+ */
+void expect_not_string(#function, #parameter, const char *string);
+#else
+#define expect_not_string(function, parameter, string) \
+ expect_not_string_count(function, parameter, string, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter value isn't equal to the
+ * provided string.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] string The string value to compare.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_not_string_count(#function, #parameter, const char *string, size_t count);
+#else
+#define expect_not_string_count(function, parameter, string, count) \
+ _expect_not_string(#function, #parameter, __FILE__, __LINE__, \
+ (const char*)(string), count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter does match an area of memory.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] memory The memory to compare.
+ *
+ * @param[in] size The size of the memory to compare.
+ *
+ * @see check_expected().
+ */
+void expect_memory(#function, #parameter, void *memory, size_t size);
+#else
+#define expect_memory(function, parameter, memory, size) \
+ expect_memory_count(function, parameter, memory, size, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check if the parameter does match an area
+ * of memory.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] memory The memory to compare.
+ *
+ * @param[in] size The size of the memory to compare.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
+#else
+#define expect_memory_count(function, parameter, memory, size, count) \
+ _expect_memory(#function, #parameter, __FILE__, __LINE__, \
+ (const void*)(memory), size, count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if the parameter doesn't match an area of
+ * memory.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] memory The memory to compare.
+ *
+ * @param[in] size The size of the memory to compare.
+ *
+ * @see check_expected().
+ */
+void expect_not_memory(#function, #parameter, void *memory, size_t size);
+#else
+#define expect_not_memory(function, parameter, memory, size) \
+ expect_not_memory_count(function, parameter, memory, size, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check if the parameter doesn't match an
+ * area of memory.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] memory The memory to compare.
+ *
+ * @param[in] size The size of the memory to compare.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_not_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
+#else
+#define expect_not_memory_count(function, parameter, memory, size, count) \
+ _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \
+ (const void*)(memory), size, count)
+#endif
+
+
+#if DOXYGEN
+/**
+ * @brief Add an event to check if a parameter (of any value) has been passed.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @see check_expected().
+ */
+void expect_any(#function, #parameter);
+#else
+#define expect_any(function, parameter) \
+ expect_any_count(function, parameter, 1)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Add an event to repeatedly check if a parameter (of any value) has
+ * been passed.
+ *
+ * The event is triggered by calling check_expected() in the mocked function.
+ *
+ * @param[in] #function The function to add the check for.
+ *
+ * @param[in] #parameter The name of the parameter passed to the function.
+ *
+ * @param[in] count The count parameter returns the number of times the value
+ * should be returned by check_expected(). If count is set
+ * to -1 the value will always be returned.
+ *
+ * @see check_expected().
+ */
+void expect_any_count(#function, #parameter, size_t count);
+#else
+#define expect_any_count(function, parameter, count) \
+ _expect_any(#function, #parameter, __FILE__, __LINE__, count)
+#endif
+
+#if DOXYGEN
+/**
+ * @brief Determine whether a function parameter is correct.
+ *
+ * This ensures the next value queued by one of the expect_*() macros matches
+ * the specified variable.
+ *
+ * This function needs to be called in the mock object.
+ *
+ * @param[in] #parameter The parameter to check.
+ */
+void check_expected(#parameter);
+#else
+#define check_expected(parameter) \
+ _check_expected(__func__, #parameter, __FILE__, __LINE__, \
+ cast_to_largest_integral_type(parameter))
+#endif
+
+/** @} */
+
+/**
+ * @defgroup cmocka_asserts Assert Macros
+ * @ingroup cmocka
+ *
+ * This is a set of useful assert macros like the standard C libary's
+ * assert(3) macro.
+ *
+ * On an assertion failure a cmocka assert macro will write the failure to the
+ * standard error stream and signal a test failure. Due to limitations of the C
+ * language the general C standard library assert() and cmocka's assert_true()
+ * and assert_false() macros can only display the expression that caused the
+ * assert failure. cmocka's type specific assert macros, assert_{type}_equal()
+ * and assert_{type}_not_equal(), display the data that caused the assertion
+ * failure which increases data visibility aiding debugging of failing test
+ * cases.
+ *
+ * @{
+ */
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the given expression is true.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if expression is false (i.e., compares equal to
+ * zero).
+ *
+ * @param[in] expression The expression to evaluate.
+ *
+ * @see assert_int_equal()
+ * @see assert_string_equal()
+ */
+void assert_true(scalar expression);
+#else
+#define assert_true(c) _assert_true(cast_to_largest_integral_type(c), #c, \
+ __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the given expression is false.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if expression is true.
+ *
+ * @param[in] expression The expression to evaluate.
+ *
+ * @see assert_int_equal()
+ * @see assert_string_equal()
+ */
+void assert_false(scalar expression);
+#else
+#define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), #c, \
+ __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the given pointer is non-NULL.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the pointer is non-NULL.
+ *
+ * @param[in] pointer The pointer to evaluate.
+ *
+ * @see assert_null()
+ */
+void assert_non_null(void *pointer);
+#else
+#define assert_non_null(c) _assert_true(cast_ptr_to_largest_integral_type(c), #c, \
+ __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the given pointer is NULL.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the pointer is non-NULL.
+ *
+ * @param[in] pointer The pointer to evaluate.
+ *
+ * @see assert_non_null()
+ */
+void assert_null(void *pointer);
+#else
+#define assert_null(c) _assert_true(!(cast_ptr_to_largest_integral_type(c)), #c, \
+__FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the two given integers are equal.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the integers are not equal.
+ *
+ * @param[in] a The first integer to compare.
+ *
+ * @param[in] b The integer to compare against the first one.
+ */
+void assert_int_equal(int a, int b);
+#else
+#define assert_int_equal(a, b) \
+ _assert_int_equal(cast_to_largest_integral_type(a), \
+ cast_to_largest_integral_type(b), \
+ __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the two given integers are not equal.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the integers are equal.
+ *
+ * @param[in] a The first integer to compare.
+ *
+ * @param[in] b The integer to compare against the first one.
+ *
+ * @see assert_int_equal()
+ */
+void assert_int_not_equal(int a, int b);
+#else
+#define assert_int_not_equal(a, b) \
+ _assert_int_not_equal(cast_to_largest_integral_type(a), \
+ cast_to_largest_integral_type(b), \
+ __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the two given strings are equal.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the strings are not equal.
+ *
+ * @param[in] a The string to check.
+ *
+ * @param[in] b The other string to compare.
+ */
+void assert_string_equal(const char *a, const char *b);
+#else
+#define assert_string_equal(a, b) \
+ _assert_string_equal((const char*)(a), (const char*)(b), __FILE__, \
+ __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the two given strings are not equal.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the strings are equal.
+ *
+ * @param[in] a The string to check.
+ *
+ * @param[in] b The other string to compare.
+ */
+void assert_string_not_equal(const char *a, const char *b);
+#else
+#define assert_string_not_equal(a, b) \
+ _assert_string_not_equal((const char*)(a), (const char*)(b), __FILE__, \
+ __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the two given areas of memory are equal, otherwise fail.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the memory is not equal.
+ *
+ * @param[in] a The first memory area to compare
+ * (interpreted as unsigned char).
+ *
+ * @param[in] b The second memory area to compare
+ * (interpreted as unsigned char).
+ *
+ * @param[in] size The first n bytes of the memory areas to compare.
+ */
+void assert_memory_equal(const void *a, const void *b, size_t size);
+#else
+#define assert_memory_equal(a, b, size) \
+ _assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \
+ __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the two given areas of memory are not equal.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if the memory is equal.
+ *
+ * @param[in] a The first memory area to compare
+ * (interpreted as unsigned char).
+ *
+ * @param[in] b The second memory area to compare
+ * (interpreted as unsigned char).
+ *
+ * @param[in] size The first n bytes of the memory areas to compare.
+ */
+void assert_memory_not_equal(const void *a, const void *b, size_t size);
+#else
+#define assert_memory_not_equal(a, b, size) \
+ _assert_memory_not_equal((const void*)(a), (const void*)(b), size, \
+ __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the specified value is bigger than the minimum and
+ * smaller than the maximum.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if value is not in range.
+ *
+ * @param[in] value The value to check.
+ *
+ * @param[in] minimum The minimum value allowed.
+ *
+ * @param[in] maximum The maximum value allowed.
+ */
+void assert_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
+#else
+#define assert_in_range(value, minimum, maximum) \
+ _assert_in_range( \
+ cast_to_largest_integral_type(value), \
+ cast_to_largest_integral_type(minimum), \
+ cast_to_largest_integral_type(maximum), __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the specified value is smaller than the minimum and
+ * bigger than the maximum.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if value is in range.
+ *
+ * @param[in] value The value to check.
+ *
+ * @param[in] minimum The minimum value to compare.
+ *
+ * @param[in] maximum The maximum value to compare.
+ */
+void assert_not_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
+#else
+#define assert_not_in_range(value, minimum, maximum) \
+ _assert_not_in_range( \
+ cast_to_largest_integral_type(value), \
+ cast_to_largest_integral_type(minimum), \
+ cast_to_largest_integral_type(maximum), __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the specified value is within a set.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if value is not within a set.
+ *
+ * @param[in] value The value to look up
+ *
+ * @param[in] values[] The array to check for the value.
+ *
+ * @param[in] count The size of the values array.
+ */
+void assert_in_set(uintmax_t value, uintmax_t values[], size_t count);
+#else
+#define assert_in_set(value, values, number_of_values) \
+ _assert_in_set(value, values, number_of_values, __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Assert that the specified value is not within a set.
+ *
+ * The function prints an error message to standard error and terminates the
+ * test by calling fail() if value is within a set.
+ *
+ * @param[in] value The value to look up
+ *
+ * @param[in] values[] The array to check for the value.
+ *
+ * @param[in] count The size of the values array.
+ */
+void assert_not_in_set(uintmax_t value, uintmax_t values[], size_t count);
+#else
+#define assert_not_in_set(value, values, number_of_values) \
+ _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__)
+#endif
+
+/** @} */
+
+/**
+ * @defgroup cmocka_exec Running Tests
+ * @ingroup cmocka
+ *
+ * This is the way tests are executed with CMocka.
+ *
+ * The following example illustrates this macro's use with the unit_test macro.
+ *
+ * @code
+ * void Test0(void **state);
+ * void Test1(void **state);
+ *
+ * int main(void)
+ * {
+ * const UnitTest tests[] = {
+ * unit_test(Test0),
+ * unit_test(Test1),
+ * };
+ *
+ * return run_tests(tests);
+ * }
+ * @endcode
+ *
+ * @{
+ */
+
+#ifdef DOXYGEN
+/**
+ * @brief Forces the test to fail immediately and quit.
+ */
+void fail(void);
+#else
+#define fail() _fail(__FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Forces the test to fail immediately and quit, printing the reason.
+ */
+void fail_msg(const char *msg, ...);
+#else
+#define fail_msg(msg, ...) do { \
+ print_error("ERROR: " msg "\n", ##__VA_ARGS__); \
+ fail(); \
+} while (0)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Generic method to run a single test.
+ *
+ * @param[in] #function The function to test.
+ *
+ * @return 0 on success, 1 if an error occured.
+ *
+ * @code
+ * // A test case that does nothing and succeeds.
+ * void null_test_success(void **state) {
+ * }
+ *
+ * int main(void) {
+ * return run_test(null_test_success);
+ * }
+ * @endcode
+ */
+int run_test(#function);
+#else
+#define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL)
+#endif
+
+/** Initializes a UnitTest structure. */
+#define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST }
+
+#define _unit_test_setup(test, setup) \
+ { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP }
+
+/** Initializes a UnitTest structure with a setup function. */
+#define unit_test_setup(test, setup) \
+ _unit_test_setup(test, setup), \
+ unit_test(test)
+
+#define _unit_test_teardown(test, teardown) \
+ { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }
+
+/** Initializes a UnitTest structure with a teardown function. */
+#define unit_test_teardown(test, teardown) \
+ unit_test(test), \
+ _unit_test_teardown(test, teardown)
+
+/**
+ * Initialize an array of UnitTest structures with a setup function for a test
+ * and a teardown function. Either setup or teardown can be NULL.
+ */
+#define unit_test_setup_teardown(test, setup, teardown) \
+ _unit_test_setup(test, setup), \
+ unit_test(test), \
+ _unit_test_teardown(test, teardown)
+
+#ifdef DOXYGEN
+/**
+ * @brief Run tests specified by an array of UnitTest structures.
+ *
+ * @param[in] tests[] The array of unit tests to execute.
+ *
+ * @return 0 on success, 1 if an error occured.
+ *
+ * @code
+ * static void setup(void **state) {
+ * int *answer = malloc(sizeof(int));
+ * assert_non_null(answer);
+ *
+ * *answer = 42;
+ *
+ * *state = answer;
+ * }
+ *
+ * static void teardown(void **state) {
+ * free(*state);
+ * }
+ *
+ * static void null_test_success(void **state) {
+ * (void) state;
+ * }
+ *
+ * static void int_test_success(void **state) {
+ * int *answer = *state;
+ * assert_int_equal(*answer, 42);
+ * }
+ *
+ * int main(void) {
+ * const UnitTest tests[] = {
+ * unit_test(null_test_success),
+ * unit_test_setup_teardown(int_test_success, setup, teardown),
+ * };
+ *
+ * return run_tests(tests);
+ * }
+ * @endcode
+ *
+ * @see unit_test
+ * @see unit_test_setup
+ * @see unit_test_teardown
+ * @see unit_test_setup_teardown
+ */
+int run_tests(const UnitTest tests[]);
+#else
+#define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof(tests)[0])
+#endif
+
+/** @} */
+
+/**
+ * @defgroup cmocka_alloc Dynamic Memory Allocation
+ * @ingroup cmocka
+ *
+ * Memory leaks, buffer overflows and underflows can be checked using cmocka.
+ *
+ * To test for memory leaks, buffer overflows and underflows a module being
+ * tested by cmocka should replace calls to malloc(), calloc() and free() to
+ * test_malloc(), test_calloc() and test_free() respectively. Each time a block
+ * is deallocated using test_free() it is checked for corruption, if a corrupt
+ * block is found a test failure is signalled. All blocks allocated using the
+ * test_*() allocation functions are tracked by the cmocka library. When a test
+ * completes if any allocated blocks (memory leaks) remain they are reported
+ * and a test failure is signalled.
+ *
+ * For simplicity cmocka currently executes all tests in one process. Therefore
+ * all test cases in a test application share a single address space which
+ * means memory corruption from a single test case could potentially cause the
+ * test application to exit prematurely.
+ *
+ * @{
+ */
+
+#ifdef DOXYGEN
+/**
+ * @brief Test function overriding malloc.
+ *
+ * @param[in] size The bytes which should be allocated.
+ *
+ * @return A pointer to the allocated memory or NULL on error.
+ *
+ * @code
+ * #if UNIT_TESTING
+ * extern void* _test_malloc(const size_t size, const char* file, const int line);
+ *
+ * #define malloc(size) _test_malloc(size, __FILE__, __LINE__)
+ * #endif
+ *
+ * void leak_memory() {
+ * int * const temporary = (int*)malloc(sizeof(int));
+ * *temporary = 0;
+ * }
+ * @endcode
+ *
+ * @see malloc(3)
+ */
+void *test_malloc(size_t size);
+#else
+#define test_malloc(size) _test_malloc(size, __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Test function overriding calloc.
+ *
+ * The memory is set to zero.
+ *
+ * @param[in] nmemb The number of elements for an array to be allocated.
+ *
+ * @param[in] size The size in bytes of each array element to allocate.
+ *
+ * @return A pointer to the allocated memory, NULL on error.
+ *
+ * @see calloc(3)
+ */
+void *test_calloc(size_t nmemb, size_t size);
+#else
+#define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
+#endif
+
+#ifdef DOXYGEN
+/**
+ * @brief Test function overriding free(3).
+ *
+ * @param[in] ptr The pointer to the memory space to free.
+ *
+ * @see free(3).
+ */
+void test_free(void *ptr);
+#else
+#define test_free(ptr) _test_free(ptr, __FILE__, __LINE__)
+#endif
+
+/* Redirect malloc, calloc and free to the unit test allocators. */
+#if UNIT_TESTING
+#define malloc test_malloc
+#define calloc test_calloc
+#define free test_free
+#endif /* UNIT_TESTING */
+
+/** @} */
+
+
+/**
+ * @defgroup cmocka_mock_assert Standard Assertions
+ * @ingroup cmocka
+ *
+ * How to handle assert(3) of the standard C library.
+ *
+ * Runtime assert macros like the standard C library's assert() should be
+ * redefined in modules being tested to use cmocka's mock_assert() function.
+ * Normally mock_assert() signals a test failure. If a function is called using
+ * the expect_assert_failure() macro, any calls to mock_assert() within the
+ * function will result in the execution of the test. If no calls to
+ * mock_assert() occur during the function called via expect_assert_failure() a
+ * test failure is signalled.
+ *
+ * @{
+ */
+
+/**
+ * @brief Function to replace assert(3) in tested code.
+ *
+ * In conjuction with check_assert() it's possible to determine whether an
+ * assert condition has failed without stopping a test.
+ *
+ * @param[in] result The expression to assert.
+ *
+ * @param[in] expression The expression as string.
+ *
+ * @param[in] file The file mock_assert() is called.
+ *
+ * @param[in] line The line mock_assert() is called.
+ *
+ * @code
+ * #if UNIT_TESTING
+ * extern void mock_assert(const int result, const char* const expression,
+ * const char * const file, const int line);
+ *
+ * #undef assert
+ * #define assert(expression) \
+ * mock_assert((int)(expression), #expression, __FILE__, __LINE__);
+ * #endif
+ *
+ * void increment_value(int * const value) {
+ * assert(value);
+ * (*value) ++;
+ * }
+ * @endcode
+ *
+ * @see assert(3)
+ * @see expect_assert_failure
+ */
+void mock_assert(const int result, const char* const expression,
+ const char * const file, const int line);
+
+#ifdef DOXYGEN
+/**
+ * @brief Ensure that mock_assert() is called.
+ *
+ * If mock_assert() is called the assert expression string is returned.
+ *
+ * @param[in] fn_call The function will will call mock_assert().
+ *
+ * @code
+ * #define assert mock_assert
+ *
+ * void showmessage(const char *message) {
+ * assert(message);
+ * }
+ *
+ * int main(int argc, const char* argv[]) {
+ * expect_assert_failure(show_message(NULL));
+ * printf("succeeded\n");
+ * return 0;
+ * }
+ * @endcode
+ *
+ */
+void expect_assert_failure(function fn_call);
+#else
+#define expect_assert_failure(function_call) \
+ { \
+ const int result = setjmp(global_expect_assert_env); \
+ global_expecting_assert = 1; \
+ if (result) { \
+ print_message("Expected assertion %s occurred\n", \
+ global_last_failed_assert); \
+ global_expecting_assert = 0; \
+ } else { \
+ function_call ; \
+ global_expecting_assert = 0; \
+ print_error("Expected assert in %s\n", #function_call); \
+ _fail(__FILE__, __LINE__); \
+ } \
+ }
+#endif
+
+/** @} */
+
+/* Function prototype for setup, test and teardown functions. */
+typedef void (*UnitTestFunction)(void **state);
+
+/* Function that determines whether a function parameter value is correct. */
+typedef int (*CheckParameterValue)(const LargestIntegralType value,
+ const LargestIntegralType check_value_data);
+
+/* Type of the unit test function. */
+typedef enum UnitTestFunctionType {
+ UNIT_TEST_FUNCTION_TYPE_TEST = 0,
+ UNIT_TEST_FUNCTION_TYPE_SETUP,
+ UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
+} UnitTestFunctionType;
+
+/*
+ * Stores a unit test function with its name and type.
+ * NOTE: Every setup function must be paired with a teardown function. It's
+ * possible to specify NULL function pointers.
+ */
+typedef struct UnitTest {
+ const char* name;
+ UnitTestFunction function;
+ UnitTestFunctionType function_type;
+} UnitTest;
+
+
+/* Location within some source code. */
+typedef struct SourceLocation {
+ const char* file;
+ int line;
+} SourceLocation;
+
+/* Event that's called to check a parameter value. */
+typedef struct CheckParameterEvent {
+ SourceLocation location;
+ const char *parameter_name;
+ CheckParameterValue check_value;
+ LargestIntegralType check_value_data;
+} CheckParameterEvent;
+
+/* Used by expect_assert_failure() and mock_assert(). */
+extern int global_expecting_assert;
+extern jmp_buf global_expect_assert_env;
+extern const char * global_last_failed_assert;
+
+/* Retrieves a value for the given function, as set by "will_return". */
+LargestIntegralType _mock(const char * const function, const char* const file,
+ const int line);
+
+void _expect_check(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const CheckParameterValue check_function,
+ const LargestIntegralType check_data, CheckParameterEvent * const event,
+ const int count);
+
+void _expect_in_set(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const LargestIntegralType values[],
+ const size_t number_of_values, const int count);
+void _expect_not_in_set(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const LargestIntegralType values[],
+ const size_t number_of_values, const int count);
+
+void _expect_in_range(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const int count);
+void _expect_not_in_range(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const int count);
+
+void _expect_value(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const LargestIntegralType value,
+ const int count);
+void _expect_not_value(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const LargestIntegralType value,
+ const int count);
+
+void _expect_string(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const char* string,
+ const int count);
+void _expect_not_string(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const char* string,
+ const int count);
+
+void _expect_memory(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const void* const memory,
+ const size_t size, const int count);
+void _expect_not_memory(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const void* const memory,
+ const size_t size, const int count);
+
+void _expect_any(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const int count);
+
+void _check_expected(
+ const char * const function_name, const char * const parameter_name,
+ const char* file, const int line, const LargestIntegralType value);
+
+void _will_return(const char * const function_name, const char * const file,
+ const int line, const LargestIntegralType value,
+ const int count);
+void _assert_true(const LargestIntegralType result,
+ const char* const expression,
+ const char * const file, const int line);
+void _assert_int_equal(
+ const LargestIntegralType a, const LargestIntegralType b,
+ const char * const file, const int line);
+void _assert_int_not_equal(
+ const LargestIntegralType a, const LargestIntegralType b,
+ const char * const file, const int line);
+void _assert_string_equal(const char * const a, const char * const b,
+ const char * const file, const int line);
+void _assert_string_not_equal(const char * const a, const char * const b,
+ const char *file, const int line);
+void _assert_memory_equal(const void * const a, const void * const b,
+ const size_t size, const char* const file,
+ const int line);
+void _assert_memory_not_equal(const void * const a, const void * const b,
+ const size_t size, const char* const file,
+ const int line);
+void _assert_in_range(
+ const LargestIntegralType value, const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const char* const file, const int line);
+void _assert_not_in_range(
+ const LargestIntegralType value, const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const char* const file, const int line);
+void _assert_in_set(
+ const LargestIntegralType value, const LargestIntegralType values[],
+ const size_t number_of_values, const char* const file, const int line);
+void _assert_not_in_set(
+ const LargestIntegralType value, const LargestIntegralType values[],
+ const size_t number_of_values, const char* const file, const int line);
+
+void* _test_malloc(const size_t size, const char* file, const int line);
+void* _test_calloc(const size_t number_of_elements, const size_t size,
+ const char* file, const int line);
+void _test_free(void* const ptr, const char* file, const int line);
+
+void _fail(const char * const file, const int line);
+int _run_test(
+ const char * const function_name, const UnitTestFunction Function,
+ void ** const volatile state, const UnitTestFunctionType function_type,
+ const void* const heap_check_point);
+int _run_tests(const UnitTest * const tests, const size_t number_of_tests);
+
+/* Standard output and error print methods. */
+void print_message(const char* const format, ...) PRINTF_ATTRIBUTE(1, 2);
+void print_error(const char* const format, ...) PRINTF_ATTRIBUTE(1, 2);
+void vprint_message(const char* const format, va_list args) PRINTF_ATTRIBUTE(1, 0);
+void vprint_error(const char* const format, va_list args) PRINTF_ATTRIBUTE(1, 0);
+
+/** @} */
+
+#endif /* CMOCKA_H_ */
diff --git a/third_party/cmocka/include/cmocka_private.h b/third_party/cmocka/include/cmocka_private.h
new file mode 100644
index 0000000..d633d64
--- /dev/null
+++ b/third_party/cmocka/include/cmocka_private.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#ifndef CMOCKA_PRIVATE_H_
+#define CMOCKA_PRIVATE_H_
+
+#include <cmocka.h>
+
+/** Free memory space */
+#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
+
+/** Zero a structure */
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+/** Zero a structure given a pointer to the structure */
+#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
+
+/** Get the size of an array */
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+/** Overwrite the complete string with 'X' */
+#define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
+
+/**
+ * This is a hack to fix warnings. The idea is to use this everywhere that we
+ * get the "discarding const" warning by the compiler. That doesn't actually
+ * fix the real issue, but marks the place and you can search the code for
+ * discard_const.
+ *
+ * Please use this macro only when there is no other way to fix the warning.
+ * We should use this function in only in a very few places.
+ *
+ * Also, please call this via the discard_const_p() macro interface, as that
+ * makes the return type safe.
+ */
+#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
+
+/**
+ * Type-safe version of discard_const
+ */
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+
+#endif /* CMOCKA_PRIVATE_H_ */
diff --git a/third_party/cmocka/src/CMakeLists.txt b/third_party/cmocka/src/CMakeLists.txt
new file mode 100644
index 0000000..2b3c486
--- /dev/null
+++ b/third_party/cmocka/src/CMakeLists.txt
@@ -0,0 +1,92 @@
+project(cmocka-library C)
+
+set(CMOCKA_PUBLIC_INCLUDE_DIRS
+ ${CMAKE_SOURCE_DIR}/include
+ CACHE INTERNAL "cmocka public include directories"
+)
+
+set(CMOCKA_PRIVATE_INCLUDE_DIRS
+ ${CMAKE_BINARY_DIR}
+)
+
+set(CMOCKA_SHARED_LIBRARY
+ cmocka_shared
+ CACHE INTERNAL "cmocka shared library"
+)
+
+if (WITH_STATIC_LIB)
+ set(CMOCKA_STATIC_LIBRARY
+ cmocka_static
+ CACHE INTERNAL "cmocka static library"
+ )
+endif (WITH_STATIC_LIB)
+
+set(CMOCKA_LINK_LIBRARIES
+ ${CMOCKA_REQUIRED_LIBRARIES}
+ CACHE INTERNAL "cmocka link libraries"
+)
+
+set(cmocka_SRCS
+ cmocka.c
+)
+
+if (WIN32)
+ set(cmocka_SRCS
+ ${cmocka_SRCS}
+ cmocka.def
+ )
+endif (WIN32)
+
+include_directories(
+ ${CMOCKA_PUBLIC_INCLUDE_DIRS}
+ ${CMOCKA_PRIVATE_INCLUDE_DIRS}
+)
+
+add_definitions(-DHAVE_CONFIG_H=1)
+
+add_library(${CMOCKA_SHARED_LIBRARY} SHARED ${cmocka_SRCS})
+
+target_link_libraries(${CMOCKA_SHARED_LIBRARY} ${CMOCKA_LINK_LIBRARIES})
+
+set_target_properties(
+ ${CMOCKA_SHARED_LIBRARY}
+ PROPERTIES
+ VERSION
+ ${LIBRARY_VERSION}
+ SOVERSION
+ ${LIBRARY_SOVERSION}
+ OUTPUT_NAME
+ cmocka
+ DEFINE_SYMBOL
+ CMOCKA_EXPORTS
+)
+
+install(
+ TARGETS ${CMOCKA_SHARED_LIBRARY}
+ RUNTIME DESTINATION ${BIN_INSTALL_DIR}
+ LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+ ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+ COMPONENT libraries
+)
+
+if (WITH_STATIC_LIB)
+ add_library(${CMOCKA_STATIC_LIBRARY} STATIC ${cmocka_SRCS})
+
+ set_target_properties(
+ ${CMOCKA_STATIC_LIBRARY}
+ PROPERTIES
+ VERSION
+ ${LIBRARY_VERSION}
+ SOVERSION
+ ${LIBRARY_SOVERSION}
+ OUTPUT_NAME
+ cmocka
+ )
+
+ install(
+ TARGETS ${CMOCKA_STATIC_LIBRARY}
+ DESTINATION ${LIB_INSTALL_DIR}
+ COMPONENT libraries
+ )
+endif (WITH_STATIC_LIB)
+
diff --git a/third_party/cmocka/src/cmocka.c b/third_party/cmocka/src/cmocka.c
new file mode 100644
index 0000000..5700fc9
--- /dev/null
+++ b/third_party/cmocka/src/cmocka.c
@@ -0,0 +1,1856 @@
+/*
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _WIN32
+#include <windows.h>
+
+#define vsnprintf _vsnprintf
+
+/*
+ * Backwards compatibility with headers shipped with Visual Studio 2005 and
+ * earlier.
+ */
+WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
+
+#ifndef PRIdS
+#define PRIdS "Id"
+#endif
+
+#else /* _WIN32 */
+
+#ifndef PRIdS
+#define PRIdS "zd"
+#endif
+
+#include <signal.h>
+#endif /* _WIN32 */
+
+#include <cmocka_private.h>
+#include <cmocka.h>
+
+/* Size of guard bytes around dynamically allocated blocks. */
+#define MALLOC_GUARD_SIZE 16
+/* Pattern used to initialize guard blocks. */
+#define MALLOC_GUARD_PATTERN 0xEF
+/* Pattern used to initialize memory allocated with test_malloc(). */
+#define MALLOC_ALLOC_PATTERN 0xBA
+#define MALLOC_FREE_PATTERN 0xCD
+/* Alignment of allocated blocks. NOTE: This must be base2. */
+#define MALLOC_ALIGNMENT sizeof(size_t)
+
+/* Printf formatting for source code locations. */
+#define SOURCE_LOCATION_FORMAT "%s:%u"
+
+/* Calculates the number of elements in an array. */
+#define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
+
+/*
+ * Declare and initialize the pointer member of ValuePointer variable name
+ * with ptr.
+ */
+#define declare_initialize_value_pointer_pointer(name, ptr) \
+ ValuePointer name ; \
+ name.value = 0; \
+ name.x.pointer = (void*)(ptr)
+
+/*
+ * Declare and initialize the value member of ValuePointer variable name
+ * with val.
+ */
+#define declare_initialize_value_pointer_value(name, val) \
+ ValuePointer name ; \
+ name.value = val
+
+/* Cast a LargestIntegralType to pointer_type via a ValuePointer. */
+#define cast_largest_integral_type_to_pointer( \
+ pointer_type, largest_integral_type) \
+ ((pointer_type)((ValuePointer*)&(largest_integral_type))->x.pointer)
+
+/* Used to cast LargetIntegralType to void* and vice versa. */
+typedef union ValuePointer {
+ LargestIntegralType value;
+ struct {
+#if defined(WORDS_BIGENDIAN) && (WORDS_SIZEOF_VOID_P == 4)
+ unsigned int padding;
+#endif
+ void *pointer;
+ } x;
+} ValuePointer;
+
+/* Doubly linked list node. */
+typedef struct ListNode {
+ const void *value;
+ int refcount;
+ struct ListNode *next;
+ struct ListNode *prev;
+} ListNode;
+
+/* Debug information for malloc(). */
+typedef struct MallocBlockInfo {
+ void* block; /* Address of the block returned by malloc(). */
+ size_t allocated_size; /* Total size of the allocated block. */
+ size_t size; /* Request block size. */
+ SourceLocation location; /* Where the block was allocated. */
+ ListNode node; /* Node within list of all allocated blocks. */
+} MallocBlockInfo;
+
+/* State of each test. */
+typedef struct TestState {
+ const ListNode *check_point; /* Check point of the test if there's a */
+ /* setup function. */
+ void *state; /* State associated with the test. */
+} TestState;
+
+/* Determines whether two values are the same. */
+typedef int (*EqualityFunction)(const void *left, const void *right);
+
+/* Value of a symbol and the place it was declared. */
+typedef struct SymbolValue {
+ SourceLocation location;
+ LargestIntegralType value;
+} SymbolValue;
+
+/*
+ * Contains a list of values for a symbol.
+ * NOTE: Each structure referenced by symbol_values_list_head must have a
+ * SourceLocation as its' first member.
+ */
+typedef struct SymbolMapValue {
+ const char *symbol_name;
+ ListNode symbol_values_list_head;
+} SymbolMapValue;
+
+/* Used by list_free() to deallocate values referenced by list nodes. */
+typedef void (*CleanupListValue)(const void *value, void *cleanup_value_data);
+
+/* Structure used to check the range of integer types.a */
+typedef struct CheckIntegerRange {
+ CheckParameterEvent event;
+ LargestIntegralType minimum;
+ LargestIntegralType maximum;
+} CheckIntegerRange;
+
+/* Structure used to check whether an integer value is in a set. */
+typedef struct CheckIntegerSet {
+ CheckParameterEvent event;
+ const LargestIntegralType *set;
+ size_t size_of_set;
+} CheckIntegerSet;
+
+/* Used to check whether a parameter matches the area of memory referenced by
+ * this structure. */
+typedef struct CheckMemoryData {
+ CheckParameterEvent event;
+ const void *memory;
+ size_t size;
+} CheckMemoryData;
+
+static ListNode* list_initialize(ListNode * const node);
+static ListNode* list_add(ListNode * const head, ListNode *new_node);
+static ListNode* list_add_value(ListNode * const head, const void *value,
+ const int count);
+static ListNode* list_remove(
+ ListNode * const node, const CleanupListValue cleanup_value,
+ void * const cleanup_value_data);
+static void list_remove_free(
+ ListNode * const node, const CleanupListValue cleanup_value,
+ void * const cleanup_value_data);
+static int list_empty(const ListNode * const head);
+static int list_find(
+ ListNode * const head, const void *value,
+ const EqualityFunction equal_func, ListNode **output);
+static int list_first(ListNode * const head, ListNode **output);
+static ListNode* list_free(
+ ListNode * const head, const CleanupListValue cleanup_value,
+ void * const cleanup_value_data);
+
+static void add_symbol_value(
+ ListNode * const symbol_map_head, const char * const symbol_names[],
+ const size_t number_of_symbol_names, const void* value, const int count);
+static int get_symbol_value(
+ ListNode * const symbol_map_head, const char * const symbol_names[],
+ const size_t number_of_symbol_names, void **output);
+static void free_value(const void *value, void *cleanup_value_data);
+static void free_symbol_map_value(
+ const void *value, void *cleanup_value_data);
+static void remove_always_return_values(ListNode * const map_head,
+ const size_t number_of_symbol_names);
+static int check_for_leftover_values(
+ const ListNode * const map_head, const char * const error_message,
+ const size_t number_of_symbol_names);
+/*
+ * This must be called at the beginning of a test to initialize some data
+ * structures.
+ */
+static void initialize_testing(const char *test_name);
+
+/* This must be called at the end of a test to free() allocated structures. */
+static void teardown_testing(const char *test_name);
+
+
+/*
+ * Keeps track of the calling context returned by setenv() so that the fail()
+ * method can jump out of a test.
+ */
+static jmp_buf global_run_test_env;
+static int global_running_test = 0;
+
+/* Keeps track of the calling context returned by setenv() so that */
+/* mock_assert() can optionally jump back to expect_assert_failure(). */
+jmp_buf global_expect_assert_env;
+int global_expecting_assert = 0;
+const char *global_last_failed_assert = NULL;
+
+/* Keeps a map of the values that functions will have to return to provide */
+/* mocked interfaces. */
+static ListNode global_function_result_map_head;
+/* Location of the last mock value returned was declared. */
+static SourceLocation global_last_mock_value_location;
+
+/* Keeps a map of the values that functions expect as parameters to their
+ * mocked interfaces. */
+static ListNode global_function_parameter_map_head;
+/* Location of last parameter value checked was declared. */
+static SourceLocation global_last_parameter_location;
+
+/* List of all currently allocated blocks. */
+static ListNode global_allocated_blocks;
+
+#ifndef _WIN32
+/* Signals caught by exception_handler(). */
+static const int exception_signals[] = {
+ SIGFPE,
+ SIGILL,
+ SIGSEGV,
+ SIGBUS,
+ SIGSYS,
+};
+
+/* Default signal functions that should be restored after a test is complete. */
+typedef void (*SignalFunction)(int signal);
+static SignalFunction default_signal_functions[
+ ARRAY_LENGTH(exception_signals)];
+
+#else /* _WIN32 */
+
+/* The default exception filter. */
+static LPTOP_LEVEL_EXCEPTION_FILTER previous_exception_filter;
+
+/* Fatal exceptions. */
+typedef struct ExceptionCodeInfo {
+ DWORD code;
+ const char* description;
+} ExceptionCodeInfo;
+
+#define EXCEPTION_CODE_INFO(exception_code) {exception_code, #exception_code}
+
+static const ExceptionCodeInfo exception_codes[] = {
+ EXCEPTION_CODE_INFO(EXCEPTION_ACCESS_VIOLATION),
+ EXCEPTION_CODE_INFO(EXCEPTION_ARRAY_BOUNDS_EXCEEDED),
+ EXCEPTION_CODE_INFO(EXCEPTION_DATATYPE_MISALIGNMENT),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_DENORMAL_OPERAND),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_DIVIDE_BY_ZERO),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_INEXACT_RESULT),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_INVALID_OPERATION),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_OVERFLOW),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_STACK_CHECK),
+ EXCEPTION_CODE_INFO(EXCEPTION_FLT_UNDERFLOW),
+ EXCEPTION_CODE_INFO(EXCEPTION_GUARD_PAGE),
+ EXCEPTION_CODE_INFO(EXCEPTION_ILLEGAL_INSTRUCTION),
+ EXCEPTION_CODE_INFO(EXCEPTION_INT_DIVIDE_BY_ZERO),
+ EXCEPTION_CODE_INFO(EXCEPTION_INT_OVERFLOW),
+ EXCEPTION_CODE_INFO(EXCEPTION_INVALID_DISPOSITION),
+ EXCEPTION_CODE_INFO(EXCEPTION_INVALID_HANDLE),
+ EXCEPTION_CODE_INFO(EXCEPTION_IN_PAGE_ERROR),
+ EXCEPTION_CODE_INFO(EXCEPTION_NONCONTINUABLE_EXCEPTION),
+ EXCEPTION_CODE_INFO(EXCEPTION_PRIV_INSTRUCTION),
+ EXCEPTION_CODE_INFO(EXCEPTION_STACK_OVERFLOW),
+};
+#endif /* !_WIN32 */
+
+
+/* Exit the currently executing test. */
+static void exit_test(const int quit_application) {
+ if (global_running_test) {
+ longjmp(global_run_test_env, 1);
+ } else if (quit_application) {
+ exit(-1);
+ }
+}
+
+
+/* Initialize a SourceLocation structure. */
+static void initialize_source_location(SourceLocation * const location) {
+ assert_non_null(location);
+ location->file = NULL;
+ location->line = 0;
+}
+
+
+/* Determine whether a source location is currently set. */
+static int source_location_is_set(const SourceLocation * const location) {
+ assert_non_null(location);
+ return location->file && location->line;
+}
+
+
+/* Set a source location. */
+static void set_source_location(
+ SourceLocation * const location, const char * const file,
+ const int line) {
+ assert_non_null(location);
+ location->file = file;
+ location->line = line;
+}
+
+
+/* Create function results and expected parameter lists. */
+void initialize_testing(const char *test_name) {
+ (void)test_name;
+ list_initialize(&global_function_result_map_head);
+ initialize_source_location(&global_last_mock_value_location);
+ list_initialize(&global_function_parameter_map_head);
+ initialize_source_location(&global_last_parameter_location);
+}
+
+
+static void fail_if_leftover_values(const char *test_name) {
+ int error_occurred = 0;
+ (void)test_name;
+ remove_always_return_values(&global_function_result_map_head, 1);
+ if (check_for_leftover_values(
+ &global_function_result_map_head,
+ "%s() has remaining non-returned values.\n", 1)) {
+ error_occurred = 1;
+ }
+
+ remove_always_return_values(&global_function_parameter_map_head, 2);
+ if (check_for_leftover_values(
+ &global_function_parameter_map_head,
+ "%s parameter still has values that haven't been checked.\n", 2)) {
+ error_occurred = 1;
+ }
+ if (error_occurred) {
+ exit_test(1);
+ }
+}
+
+
+static void teardown_testing(const char *test_name) {
+ (void)test_name;
+ list_free(&global_function_result_map_head, free_symbol_map_value,
+ (void*)0);
+ initialize_source_location(&global_last_mock_value_location);
+ list_free(&global_function_parameter_map_head, free_symbol_map_value,
+ (void*)1);
+ initialize_source_location(&global_last_parameter_location);
+}
+
+/* Initialize a list node. */
+static ListNode* list_initialize(ListNode * const node) {
+ node->value = NULL;
+ node->next = node;
+ node->prev = node;
+ node->refcount = 1;
+ return node;
+}
+
+
+/*
+ * Adds a value at the tail of a given list.
+ * The node referencing the value is allocated from the heap.
+ */
+static ListNode* list_add_value(ListNode * const head, const void *value,
+ const int refcount) {
+ ListNode * const new_node = (ListNode*)malloc(sizeof(ListNode));
+ assert_non_null(head);
+ assert_non_null(value);
+ new_node->value = value;
+ new_node->refcount = refcount;
+ return list_add(head, new_node);
+}
+
+
+/* Add new_node to the end of the list. */
+static ListNode* list_add(ListNode * const head, ListNode *new_node) {
+ assert_non_null(head);
+ assert_non_null(new_node);
+ new_node->next = head;
+ new_node->prev = head->prev;
+ head->prev->next = new_node;
+ head->prev = new_node;
+ return new_node;
+}
+
+
+/* Remove a node from a list. */
+static ListNode* list_remove(
+ ListNode * const node, const CleanupListValue cleanup_value,
+ void * const cleanup_value_data) {
+ assert_non_null(node);
+ node->prev->next = node->next;
+ node->next->prev = node->prev;
+ if (cleanup_value) {
+ cleanup_value(node->value, cleanup_value_data);
+ }
+ return node;
+}
+
+
+/* Remove a list node from a list and free the node. */
+static void list_remove_free(
+ ListNode * const node, const CleanupListValue cleanup_value,
+ void * const cleanup_value_data) {
+ assert_non_null(node);
+ free(list_remove(node, cleanup_value, cleanup_value_data));
+}
+
+
+/*
+ * Frees memory kept by a linked list The cleanup_value function is called for
+ * every "value" field of nodes in the list, except for the head. In addition
+ * to each list value, cleanup_value_data is passed to each call to
+ * cleanup_value. The head of the list is not deallocated.
+ */
+static ListNode* list_free(
+ ListNode * const head, const CleanupListValue cleanup_value,
+ void * const cleanup_value_data) {
+ assert_non_null(head);
+ while (!list_empty(head)) {
+ list_remove_free(head->next, cleanup_value, cleanup_value_data);
+ }
+ return head;
+}
+
+
+/* Determine whether a list is empty. */
+static int list_empty(const ListNode * const head) {
+ assert_non_null(head);
+ return head->next == head;
+}
+
+
+/*
+ * Find a value in the list using the equal_func to compare each node with the
+ * value.
+ */
+static int list_find(ListNode * const head, const void *value,
+ const EqualityFunction equal_func, ListNode **output) {
+ ListNode *current;
+ assert_non_null(head);
+ for (current = head->next; current != head; current = current->next) {
+ if (equal_func(current->value, value)) {
+ *output = current;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* Returns the first node of a list */
+static int list_first(ListNode * const head, ListNode **output) {
+ ListNode *target_node;
+ assert_non_null(head);
+ if (list_empty(head)) {
+ return 0;
+ }
+ target_node = head->next;
+ *output = target_node;
+ return 1;
+}
+
+
+/* Deallocate a value referenced by a list. */
+static void free_value(const void *value, void *cleanup_value_data) {
+ (void)cleanup_value_data;
+ assert_non_null(value);
+ free((void*)value);
+}
+
+
+/* Releases memory associated to a symbol_map_value. */
+static void free_symbol_map_value(const void *value,
+ void *cleanup_value_data) {
+ SymbolMapValue * const map_value = (SymbolMapValue*)value;
+ const LargestIntegralType children = cast_ptr_to_largest_integral_type(cleanup_value_data);
+ assert_non_null(value);
+ list_free(&map_value->symbol_values_list_head,
+ children ? free_symbol_map_value : free_value,
+ (void *) ((uintptr_t)children - 1));
+ free(map_value);
+}
+
+
+/*
+ * Determine whether a symbol name referenced by a symbol_map_value matches the
+ * specified function name.
+ */
+static int symbol_names_match(const void *map_value, const void *symbol) {
+ return !strcmp(((SymbolMapValue*)map_value)->symbol_name,
+ (const char*)symbol);
+}
+
+
+/*
+ * Adds a value to the queue of values associated with the given hierarchy of
+ * symbols. It's assumed value is allocated from the heap.
+ */
+static void add_symbol_value(ListNode * const symbol_map_head,
+ const char * const symbol_names[],
+ const size_t number_of_symbol_names,
+ const void* value, const int refcount) {
+ const char* symbol_name;
+ ListNode *target_node;
+ SymbolMapValue *target_map_value;
+ assert_non_null(symbol_map_head);
+ assert_non_null(symbol_names);
+ assert_true(number_of_symbol_names);
+ symbol_name = symbol_names[0];
+
+ if (!list_find(symbol_map_head, symbol_name, symbol_names_match,
+ &target_node)) {
+ SymbolMapValue * const new_symbol_map_value =
+ (SymbolMapValue*)malloc(sizeof(*new_symbol_map_value));
+ new_symbol_map_value->symbol_name = symbol_name;
+ list_initialize(&new_symbol_map_value->symbol_values_list_head);
+ target_node = list_add_value(symbol_map_head, new_symbol_map_value,
+ 1);
+ }
+
+ target_map_value = (SymbolMapValue*)target_node->value;
+ if (number_of_symbol_names == 1) {
+ list_add_value(&target_map_value->symbol_values_list_head,
+ value, refcount);
+ } else {
+ add_symbol_value(&target_map_value->symbol_values_list_head,
+ &symbol_names[1], number_of_symbol_names - 1, value,
+ refcount);
+ }
+}
+
+
+/*
+ * Gets the next value associated with the given hierarchy of symbols.
+ * The value is returned as an output parameter with the function returning the
+ * node's old refcount value if a value is found, 0 otherwise. This means that
+ * a return value of 1 indicates the node was just removed from the list.
+ */
+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;
+ assert_non_null(head);
+ assert_non_null(symbol_names);
+ assert_true(number_of_symbol_names);
+ assert_non_null(output);
+ symbol_name = symbol_names[0];
+
+ if (list_find(head, symbol_name, symbol_names_match, &target_node)) {
+ SymbolMapValue *map_value;
+ ListNode *child_list;
+ int return_value = 0;
+ assert_non_null(target_node);
+ assert_non_null(target_node->value);
+
+ map_value = (SymbolMapValue*)target_node->value;
+ child_list = &map_value->symbol_values_list_head;
+
+ if (number_of_symbol_names == 1) {
+ ListNode *value_node = NULL;
+ return_value = list_first(child_list, &value_node);
+ assert_true(return_value);
+ *output = (void*) value_node->value;
+ return_value = value_node->refcount;
+ if (--value_node->refcount == 0) {
+ list_remove_free(value_node, NULL, NULL);
+ }
+ } else {
+ return_value = get_symbol_value(
+ child_list, &symbol_names[1], number_of_symbol_names - 1,
+ output);
+ }
+ if (list_empty(child_list)) {
+ list_remove_free(target_node, free_symbol_map_value, (void*)0);
+ }
+ return return_value;
+ } else {
+ print_error("No entries for symbol %s.\n", symbol_name);
+ }
+ return 0;
+}
+
+
+/*
+ * Traverse down a tree of symbol values and remove the first symbol value
+ * in each branch that has a refcount < -1 (i.e should always be returned
+ * and has been returned at least once).
+ */
+static void remove_always_return_values(ListNode * const map_head,
+ const size_t number_of_symbol_names) {
+ ListNode *current;
+ assert_non_null(map_head);
+ assert_true(number_of_symbol_names);
+ current = map_head->next;
+ while (current != map_head) {
+ SymbolMapValue * const value = (SymbolMapValue*)current->value;
+ ListNode * const next = current->next;
+ ListNode *child_list;
+ assert_non_null(value);
+ child_list = &value->symbol_values_list_head;
+
+ if (!list_empty(child_list)) {
+ if (number_of_symbol_names == 1) {
+ ListNode * const child_node = child_list->next;
+ /* If this item has been returned more than once, free it. */
+ if (child_node->refcount < -1) {
+ list_remove_free(child_node, free_value, NULL);
+ }
+ } else {
+ remove_always_return_values(child_list,
+ number_of_symbol_names - 1);
+ }
+ }
+
+ if (list_empty(child_list)) {
+ list_remove_free(current, free_value, NULL);
+ }
+ current = next;
+ }
+}
+
+/*
+ * Checks if there are any leftover values set up by the test that were never
+ * retrieved through execution, and fail the test if that is the case.
+ */
+static int check_for_leftover_values(
+ const ListNode * const map_head, const char * const error_message,
+ const size_t number_of_symbol_names) {
+ const ListNode *current;
+ int symbols_with_leftover_values = 0;
+ assert_non_null(map_head);
+ assert_true(number_of_symbol_names);
+
+ for (current = map_head->next; current != map_head;
+ current = current->next) {
+ const SymbolMapValue * const value =
+ (SymbolMapValue*)current->value;
+ const ListNode *child_list;
+ assert_non_null(value);
+ child_list = &value->symbol_values_list_head;
+
+ if (!list_empty(child_list)) {
+ if (number_of_symbol_names == 1) {
+ const ListNode *child_node;
+ print_error(error_message, value->symbol_name);
+
+ for (child_node = child_list->next; child_node != child_list;
+ child_node = child_node->next) {
+ const SourceLocation * const location =
+ (const SourceLocation*)child_node->value;
+ print_error(SOURCE_LOCATION_FORMAT
+ ": note: remaining item was declared here\n",
+ location->file, location->line);
+ }
+ } else {
+ print_error("%s.", value->symbol_name);
+ check_for_leftover_values(child_list, error_message,
+ number_of_symbol_names - 1);
+ }
+ symbols_with_leftover_values ++;
+ }
+ }
+ return symbols_with_leftover_values;
+}
+
+
+/* Get the next return value for the specified mock function. */
+LargestIntegralType _mock(const char * const function, const char* const file,
+ const int line) {
+ void *result;
+ const int rc = get_symbol_value(&global_function_result_map_head,
+ &function, 1, &result);
+ if (rc) {
+ SymbolValue * const symbol = (SymbolValue*)result;
+ const LargestIntegralType value = symbol->value;
+ global_last_mock_value_location = symbol->location;
+ if (rc == 1) {
+ free(symbol);
+ }
+ return value;
+ } else {
+ print_error(SOURCE_LOCATION_FORMAT ": error: Could not get value "
+ "to mock function %s\n", file, line, function);
+ if (source_location_is_set(&global_last_mock_value_location)) {
+ print_error(SOURCE_LOCATION_FORMAT
+ ": note: Previously returned mock value was declared here\n",
+ global_last_mock_value_location.file,
+ global_last_mock_value_location.line);
+ } else {
+ print_error("There were no previously returned mock values for "
+ "this test.\n");
+ }
+ exit_test(1);
+ }
+ return 0;
+}
+
+
+/* Add a return value for the specified mock function name. */
+void _will_return(const char * const function_name, const char * const file,
+ const int line, const LargestIntegralType value,
+ const int count) {
+ SymbolValue * const return_value =
+ (SymbolValue*)malloc(sizeof(*return_value));
+ assert_true(count > 0 || count == -1);
+ return_value->value = value;
+ set_source_location(&return_value->location, file, line);
+ add_symbol_value(&global_function_result_map_head, &function_name, 1,
+ return_value, count);
+}
+
+
+/*
+ * Add a custom parameter checking function. If the event parameter is NULL
+ * the event structure is allocated internally by this function. If event
+ * parameter is provided it must be allocated on the heap and doesn't need to
+ * be deallocated by the caller.
+ */
+void _expect_check(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const CheckParameterValue check_function,
+ const LargestIntegralType check_data,
+ CheckParameterEvent * const event, const int count) {
+ CheckParameterEvent * const check =
+ event ? event : (CheckParameterEvent*)malloc(sizeof(*check));
+ const char* symbols[] = {function, parameter};
+ check->parameter_name = parameter;
+ check->check_value = check_function;
+ check->check_value_data = check_data;
+ set_source_location(&check->location, file, line);
+ add_symbol_value(&global_function_parameter_map_head, symbols, 2, check,
+ count);
+}
+
+
+/* Returns 1 if the specified values are equal. If the values are not equal
+ * an error is displayed and 0 is returned. */
+static int values_equal_display_error(const LargestIntegralType left,
+ const LargestIntegralType right) {
+ const int equal = left == right;
+ if (!equal) {
+ print_error(LargestIntegralTypePrintfFormat " != "
+ LargestIntegralTypePrintfFormat "\n", left, right);
+ }
+ return equal;
+}
+
+/*
+ * Returns 1 if the specified values are not equal. If the values are equal
+ * an error is displayed and 0 is returned. */
+static int values_not_equal_display_error(const LargestIntegralType left,
+ const LargestIntegralType right) {
+ const int not_equal = left != right;
+ if (!not_equal) {
+ print_error(LargestIntegralTypePrintfFormat " == "
+ LargestIntegralTypePrintfFormat "\n", left, right);
+ }
+ return not_equal;
+}
+
+
+/*
+ * Determine whether value is contained within check_integer_set.
+ * If invert is 0 and the value is in the set 1 is returned, otherwise 0 is
+ * returned and an error is displayed. If invert is 1 and the value is not
+ * in the set 1 is returned, otherwise 0 is returned and an error is
+ * displayed.
+ */
+static int value_in_set_display_error(
+ const LargestIntegralType value,
+ const CheckIntegerSet * const check_integer_set, const int invert) {
+ int succeeded = invert;
+ assert_non_null(check_integer_set);
+ {
+ const LargestIntegralType * const set = check_integer_set->set;
+ const size_t size_of_set = check_integer_set->size_of_set;
+ size_t i;
+ for (i = 0; i < size_of_set; i++) {
+ if (set[i] == value) {
+ /* If invert = 0 and item is found, succeeded = 1. */
+ /* If invert = 1 and item is found, succeeded = 0. */
+ succeeded = !succeeded;
+ break;
+ }
+ }
+ if (succeeded) {
+ return 1;
+ }
+ print_error("%llu is %sin the set (", value, invert ? "" : "not ");
+ for (i = 0; i < size_of_set; i++) {
+ print_error("%llu, ", set[i]);
+ }
+ print_error(")\n");
+ }
+ return 0;
+}
+
+
+/*
+ * Determine whether a value is within the specified range. If the value is
+ * within the specified range 1 is returned. If the value isn't within the
+ * specified range an error is displayed and 0 is returned.
+ */
+static int integer_in_range_display_error(
+ const LargestIntegralType value, const LargestIntegralType range_min,
+ const LargestIntegralType range_max) {
+ if (value >= range_min && value <= range_max) {
+ return 1;
+ }
+ print_error("%llu is not within the range %llu-%llu\n", value, range_min,
+ range_max);
+ return 0;
+}
+
+
+/*
+ * Determine whether a value is within the specified range. If the value
+ * is not within the range 1 is returned. If the value is within the
+ * specified range an error is displayed and zero is returned.
+ */
+static int integer_not_in_range_display_error(
+ const LargestIntegralType value, const LargestIntegralType range_min,
+ const LargestIntegralType range_max) {
+ if (value < range_min || value > range_max) {
+ return 1;
+ }
+ print_error("%llu is within the range %llu-%llu\n", value, range_min,
+ range_max);
+ return 0;
+}
+
+
+/*
+ * Determine whether the specified strings are equal. If the strings are equal
+ * 1 is returned. If they're not equal an error is displayed and 0 is
+ * returned.
+ */
+static int string_equal_display_error(
+ const char * const left, const char * const right) {
+ if (strcmp(left, right) == 0) {
+ return 1;
+ }
+ print_error("\"%s\" != \"%s\"\n", left, right);
+ return 0;
+}
+
+
+/*
+ * Determine whether the specified strings are equal. If the strings are not
+ * equal 1 is returned. If they're not equal an error is displayed and 0 is
+ * returned
+ */
+static int string_not_equal_display_error(
+ const char * const left, const char * const right) {
+ if (strcmp(left, right) != 0) {
+ return 1;
+ }
+ print_error("\"%s\" == \"%s\"\n", left, right);
+ return 0;
+}
+
+
+/*
+ * Determine whether the specified areas of memory are equal. If they're equal
+ * 1 is returned otherwise an error is displayed and 0 is returned.
+ */
+static int memory_equal_display_error(const char* const a, const char* const b,
+ const size_t size) {
+ int differences = 0;
+ size_t i;
+ for (i = 0; i < size; i++) {
+ const char l = a[i];
+ const char r = b[i];
+ if (l != r) {
+ print_error("difference at offset %" PRIdS " 0x%02x 0x%02x\n",
+ i, l, r);
+ differences ++;
+ }
+ }
+ if (differences) {
+ print_error("%d bytes of %p and %p differ\n", differences,
+ a, b);
+ return 0;
+ }
+ return 1;
+}
+
+
+/*
+ * Determine whether the specified areas of memory are not equal. If they're
+ * not equal 1 is returned otherwise an error is displayed and 0 is
+ * returned.
+ */
+static int memory_not_equal_display_error(
+ const char* const a, const char* const b, const size_t size) {
+ size_t same = 0;
+ size_t i;
+ for (i = 0; i < size; i++) {
+ const char l = a[i];
+ const char r = b[i];
+ if (l == r) {
+ same ++;
+ }
+ }
+ if (same == size) {
+ print_error("%"PRIdS "bytes of %p and %p the same\n", same,
+ a, b);
+ return 0;
+ }
+ return 1;
+}
+
+
+/* CheckParameterValue callback to check whether a value is within a set. */
+static int check_in_set(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ return value_in_set_display_error(value,
+ cast_largest_integral_type_to_pointer(CheckIntegerSet*,
+ check_value_data), 0);
+}
+
+
+/* CheckParameterValue callback to check whether a value isn't within a set. */
+static int check_not_in_set(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ return value_in_set_display_error(value,
+ cast_largest_integral_type_to_pointer(CheckIntegerSet*,
+ check_value_data), 1);
+}
+
+
+/* Create the callback data for check_in_set() or check_not_in_set() and
+ * register a check event. */
+static void expect_set(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType values[], const size_t number_of_values,
+ const CheckParameterValue check_function, const int count) {
+ CheckIntegerSet * const check_integer_set =
+ (CheckIntegerSet*)malloc(sizeof(*check_integer_set) +
+ (sizeof(values[0]) * number_of_values));
+ LargestIntegralType * const set = (LargestIntegralType*)(
+ check_integer_set + 1);
+ declare_initialize_value_pointer_pointer(check_data, check_integer_set);
+ assert_non_null(values);
+ assert_true(number_of_values);
+ memcpy(set, values, number_of_values * sizeof(values[0]));
+ check_integer_set->set = set;
+ _expect_check(
+ function, parameter, file, line, check_function,
+ check_data.value, &check_integer_set->event, count);
+}
+
+
+/* Add an event to check whether a value is in a set. */
+void _expect_in_set(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType values[], const size_t number_of_values,
+ const int count) {
+ expect_set(function, parameter, file, line, values, number_of_values,
+ check_in_set, count);
+}
+
+
+/* Add an event to check whether a value isn't in a set. */
+void _expect_not_in_set(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType values[], const size_t number_of_values,
+ const int count) {
+ expect_set(function, parameter, file, line, values, number_of_values,
+ check_not_in_set, count);
+}
+
+
+/* CheckParameterValue callback to check whether a value is within a range. */
+static int check_in_range(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ CheckIntegerRange * const check_integer_range =
+ cast_largest_integral_type_to_pointer(CheckIntegerRange*,
+ check_value_data);
+ assert_non_null(check_integer_range);
+ return integer_in_range_display_error(value, check_integer_range->minimum,
+ check_integer_range->maximum);
+}
+
+
+/* CheckParameterValue callback to check whether a value is not within a range. */
+static int check_not_in_range(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ CheckIntegerRange * const check_integer_range =
+ cast_largest_integral_type_to_pointer(CheckIntegerRange*,
+ check_value_data);
+ assert_non_null(check_integer_range);
+ return integer_not_in_range_display_error(
+ value, check_integer_range->minimum, check_integer_range->maximum);
+}
+
+
+/* Create the callback data for check_in_range() or check_not_in_range() and
+ * register a check event. */
+static void expect_range(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType minimum, const LargestIntegralType maximum,
+ const CheckParameterValue check_function, const int count) {
+ CheckIntegerRange * const check_integer_range =
+ (CheckIntegerRange*)malloc(sizeof(*check_integer_range));
+ declare_initialize_value_pointer_pointer(check_data, check_integer_range);
+ check_integer_range->minimum = minimum;
+ check_integer_range->maximum = maximum;
+ _expect_check(function, parameter, file, line, check_function,
+ check_data.value, &check_integer_range->event, count);
+}
+
+
+/* Add an event to determine whether a parameter is within a range. */
+void _expect_in_range(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType minimum, const LargestIntegralType maximum,
+ const int count) {
+ expect_range(function, parameter, file, line, minimum, maximum,
+ check_in_range, count);
+}
+
+
+/* Add an event to determine whether a parameter is not within a range. */
+void _expect_not_in_range(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType minimum, const LargestIntegralType maximum,
+ const int count) {
+ expect_range(function, parameter, file, line, minimum, maximum,
+ check_not_in_range, count);
+}
+
+
+/* CheckParameterValue callback to check whether a value is equal to an
+ * expected value. */
+static int check_value(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ return values_equal_display_error(value, check_value_data);
+}
+
+
+/* Add an event to check a parameter equals an expected value. */
+void _expect_value(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType value, const int count) {
+ _expect_check(function, parameter, file, line, check_value, value, NULL,
+ count);
+}
+
+
+/* CheckParameterValue callback to check whether a value is not equal to an
+ * expected value. */
+static int check_not_value(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ return values_not_equal_display_error(value, check_value_data);
+}
+
+
+/* Add an event to check a parameter is not equal to an expected value. */
+void _expect_not_value(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const LargestIntegralType value, const int count) {
+ _expect_check(function, parameter, file, line, check_not_value, value,
+ NULL, count);
+}
+
+
+/* CheckParameterValue callback to check whether a parameter equals a string. */
+static int check_string(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ return string_equal_display_error(
+ cast_largest_integral_type_to_pointer(char*, value),
+ cast_largest_integral_type_to_pointer(char*, check_value_data));
+}
+
+
+/* Add an event to check whether a parameter is equal to a string. */
+void _expect_string(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const char* string,
+ const int count) {
+ declare_initialize_value_pointer_pointer(string_pointer,
+ discard_const(string));
+ _expect_check(function, parameter, file, line, check_string,
+ string_pointer.value, NULL, count);
+}
+
+
+/* CheckParameterValue callback to check whether a parameter is not equals to
+ * a string. */
+static int check_not_string(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ return string_not_equal_display_error(
+ cast_largest_integral_type_to_pointer(char*, value),
+ cast_largest_integral_type_to_pointer(char*, check_value_data));
+}
+
+
+/* Add an event to check whether a parameter is not equal to a string. */
+void _expect_not_string(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const char* string,
+ const int count) {
+ declare_initialize_value_pointer_pointer(string_pointer,
+ discard_const(string));
+ _expect_check(function, parameter, file, line, check_not_string,
+ string_pointer.value, NULL, count);
+}
+
+/* CheckParameterValue callback to check whether a parameter equals an area of
+ * memory. */
+static int check_memory(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ CheckMemoryData * const check = cast_largest_integral_type_to_pointer(
+ CheckMemoryData*, check_value_data);
+ assert_non_null(check);
+ return memory_equal_display_error(
+ cast_largest_integral_type_to_pointer(const char*, value),
+ (const char*)check->memory, check->size);
+}
+
+
+/* Create the callback data for check_memory() or check_not_memory() and
+ * register a check event. */
+static void expect_memory_setup(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line,
+ const void * const memory, const size_t size,
+ const CheckParameterValue check_function, const int count) {
+ CheckMemoryData * const check_data =
+ (CheckMemoryData*)malloc(sizeof(*check_data) + size);
+ void * const mem = (void*)(check_data + 1);
+ declare_initialize_value_pointer_pointer(check_data_pointer, check_data);
+ assert_non_null(memory);
+ assert_true(size);
+ memcpy(mem, memory, size);
+ check_data->memory = mem;
+ check_data->size = size;
+ _expect_check(function, parameter, file, line, check_function,
+ check_data_pointer.value, &check_data->event, count);
+}
+
+
+/* Add an event to check whether a parameter matches an area of memory. */
+void _expect_memory(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const void* const memory,
+ const size_t size, const int count) {
+ expect_memory_setup(function, parameter, file, line, memory, size,
+ check_memory, count);
+}
+
+
+/* CheckParameterValue callback to check whether a parameter is not equal to
+ * an area of memory. */
+static int check_not_memory(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ CheckMemoryData * const check = cast_largest_integral_type_to_pointer(
+ CheckMemoryData*, check_value_data);
+ assert_non_null(check);
+ return memory_not_equal_display_error(
+ cast_largest_integral_type_to_pointer(const char*, value),
+ (const char*)check->memory,
+ check->size);
+}
+
+
+/* Add an event to check whether a parameter doesn't match an area of memory. */
+void _expect_not_memory(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const void* const memory,
+ const size_t size, const int count) {
+ expect_memory_setup(function, parameter, file, line, memory, size,
+ check_not_memory, count);
+}
+
+
+/* CheckParameterValue callback that always returns 1. */
+static int check_any(const LargestIntegralType value,
+ const LargestIntegralType check_value_data) {
+ (void)value;
+ (void)check_value_data;
+ return 1;
+}
+
+
+/* Add an event to allow any value for a parameter. */
+void _expect_any(
+ const char* const function, const char* const parameter,
+ const char* const file, const int line, const int count) {
+ _expect_check(function, parameter, file, line, check_any, 0, NULL,
+ count);
+}
+
+
+void _check_expected(
+ const char * const function_name, const char * const parameter_name,
+ const char* file, const int line, const LargestIntegralType value) {
+ void *result;
+ const char* symbols[] = {function_name, parameter_name};
+ const int rc = get_symbol_value(&global_function_parameter_map_head,
+ symbols, 2, &result);
+ if (rc) {
+ CheckParameterEvent * const check = (CheckParameterEvent*)result;
+ int check_succeeded;
+ global_last_parameter_location = check->location;
+ check_succeeded = check->check_value(value, check->check_value_data);
+ if (rc == 1) {
+ free(check);
+ }
+ if (!check_succeeded) {
+ print_error(SOURCE_LOCATION_FORMAT
+ ": error: Check of parameter %s, function %s failed\n"
+ SOURCE_LOCATION_FORMAT
+ ": note: Expected parameter declared here\n",
+ file, line,
+ parameter_name, function_name,
+ global_last_parameter_location.file,
+ global_last_parameter_location.line);
+ _fail(file, line);
+ }
+ } else {
+ print_error(SOURCE_LOCATION_FORMAT ": error: Could not get value "
+ "to check parameter %s of function %s\n", file, line,
+ parameter_name, function_name);
+ if (source_location_is_set(&global_last_parameter_location)) {
+ print_error(SOURCE_LOCATION_FORMAT
+ ": note: Previously declared parameter value was declared here\n",
+ global_last_parameter_location.file,
+ global_last_parameter_location.line);
+ } else {
+ print_error("There were no previously declared parameter values "
+ "for this test.\n");
+ }
+ exit_test(1);
+ }
+}
+
+
+/* Replacement for assert. */
+void mock_assert(const int result, const char* const expression,
+ const char* const file, const int line) {
+ if (!result) {
+ if (global_expecting_assert) {
+ global_last_failed_assert = expression;
+ longjmp(global_expect_assert_env, result);
+ } else {
+ print_error("ASSERT: %s\n", expression);
+ _fail(file, line);
+ }
+ }
+}
+
+
+void _assert_true(const LargestIntegralType result,
+ const char * const expression,
+ const char * const file, const int line) {
+ if (!result) {
+ print_error("%s\n", expression);
+ _fail(file, line);
+ }
+}
+
+void _assert_int_equal(
+ const LargestIntegralType a, const LargestIntegralType b,
+ const char * const file, const int line) {
+ if (!values_equal_display_error(a, b)) {
+ _fail(file, line);
+ }
+}
+
+
+void _assert_int_not_equal(
+ const LargestIntegralType a, const LargestIntegralType b,
+ const char * const file, const int line) {
+ if (!values_not_equal_display_error(a, b)) {
+ _fail(file, line);
+ }
+}
+
+
+void _assert_string_equal(const char * const a, const char * const b,
+ const char * const file, const int line) {
+ if (!string_equal_display_error(a, b)) {
+ _fail(file, line);
+ }
+}
+
+
+void _assert_string_not_equal(const char * const a, const char * const b,
+ const char *file, const int line) {
+ if (!string_not_equal_display_error(a, b)) {
+ _fail(file, line);
+ }
+}
+
+
+void _assert_memory_equal(const void * const a, const void * const b,
+ const size_t size, const char* const file,
+ const int line) {
+ if (!memory_equal_display_error((const char*)a, (const char*)b, size)) {
+ _fail(file, line);
+ }
+}
+
+
+void _assert_memory_not_equal(const void * const a, const void * const b,
+ const size_t size, const char* const file,
+ const int line) {
+ if (!memory_not_equal_display_error((const char*)a, (const char*)b,
+ size)) {
+ _fail(file, line);
+ }
+}
+
+
+void _assert_in_range(
+ const LargestIntegralType value, const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const char* const file,
+ const int line) {
+ if (!integer_in_range_display_error(value, minimum, maximum)) {
+ _fail(file, line);
+ }
+}
+
+void _assert_not_in_range(
+ const LargestIntegralType value, const LargestIntegralType minimum,
+ const LargestIntegralType maximum, const char* const file,
+ const int line) {
+ if (!integer_not_in_range_display_error(value, minimum, maximum)) {
+ _fail(file, line);
+ }
+}
+
+void _assert_in_set(const LargestIntegralType value,
+ const LargestIntegralType values[],
+ const size_t number_of_values, const char* const file,
+ const int line) {
+ CheckIntegerSet check_integer_set;
+ check_integer_set.set = values;
+ check_integer_set.size_of_set = number_of_values;
+ if (!value_in_set_display_error(value, &check_integer_set, 0)) {
+ _fail(file, line);
+ }
+}
+
+void _assert_not_in_set(const LargestIntegralType value,
+ const LargestIntegralType values[],
+ const size_t number_of_values, const char* const file,
+ const int line) {
+ CheckIntegerSet check_integer_set;
+ check_integer_set.set = values;
+ check_integer_set.size_of_set = number_of_values;
+ if (!value_in_set_display_error(value, &check_integer_set, 1)) {
+ _fail(file, line);
+ }
+}
+
+
+/* Get the list of allocated blocks. */
+static ListNode* get_allocated_blocks_list() {
+ /* If it initialized, initialize the list of allocated blocks. */
+ if (!global_allocated_blocks.value) {
+ list_initialize(&global_allocated_blocks);
+ global_allocated_blocks.value = (void*)1;
+ }
+ return &global_allocated_blocks;
+}
+
+/* Use the real malloc in this function. */
+#undef malloc
+void* _test_malloc(const size_t size, const char* file, const int line) {
+ char* ptr;
+ MallocBlockInfo *block_info;
+ ListNode * const block_list = get_allocated_blocks_list();
+ const size_t allocate_size = size + (MALLOC_GUARD_SIZE * 2) +
+ sizeof(*block_info) + MALLOC_ALIGNMENT;
+ char* const block = (char*)malloc(allocate_size);
+ assert_non_null(block);
+
+ /* Calculate the returned address. */
+ ptr = (char*)(((size_t)block + MALLOC_GUARD_SIZE + sizeof(*block_info) +
+ MALLOC_ALIGNMENT) & ~(MALLOC_ALIGNMENT - 1));
+
+ /* Initialize the guard blocks. */
+ memset(ptr - MALLOC_GUARD_SIZE, MALLOC_GUARD_PATTERN, MALLOC_GUARD_SIZE);
+ memset(ptr + size, MALLOC_GUARD_PATTERN, MALLOC_GUARD_SIZE);
+ memset(ptr, MALLOC_ALLOC_PATTERN, size);
+
+ block_info = (MallocBlockInfo*)(ptr - (MALLOC_GUARD_SIZE +
+ sizeof(*block_info)));
+ set_source_location(&block_info->location, file, line);
+ block_info->allocated_size = allocate_size;
+ block_info->size = size;
+ block_info->block = block;
+ block_info->node.value = block_info;
+ list_add(block_list, &block_info->node);
+ return ptr;
+}
+#define malloc test_malloc
+
+
+void* _test_calloc(const size_t number_of_elements, const size_t size,
+ const char* file, const int line) {
+ void* const ptr = _test_malloc(number_of_elements * size, file, line);
+ if (ptr) {
+ memset(ptr, 0, number_of_elements * size);
+ }
+ return ptr;
+}
+
+
+/* Use the real free in this function. */
+#undef free
+void _test_free(void* const ptr, const char* file, const int line) {
+ unsigned int i;
+ char *block = discard_const_p(char, ptr);
+
+ MallocBlockInfo *block_info;
+ _assert_true(cast_ptr_to_largest_integral_type(ptr), "ptr", file, line);
+ block_info = (MallocBlockInfo*)(block - (MALLOC_GUARD_SIZE +
+ sizeof(*block_info)));
+ /* Check the guard blocks. */
+ {
+ char *guards[2] = {block - MALLOC_GUARD_SIZE,
+ block + block_info->size};
+ for (i = 0; i < ARRAY_LENGTH(guards); i++) {
+ unsigned int j;
+ char * const guard = guards[i];
+ for (j = 0; j < MALLOC_GUARD_SIZE; j++) {
+ const char diff = guard[j] - MALLOC_GUARD_PATTERN;
+ if (diff) {
+ print_error(SOURCE_LOCATION_FORMAT
+ ": error: Guard block of %p size=%lu is corrupt\n"
+ SOURCE_LOCATION_FORMAT ": note: allocated here at %p\n",
+ file, line,
+ ptr, (unsigned long)block_info->size,
+ block_info->location.file, block_info->location.line,
+ &guard[j]);
+ _fail(file, line);
+ }
+ }
+ }
+ }
+ list_remove(&block_info->node, NULL, NULL);
+
+ block = discard_const_p(char, block_info->block);
+ memset(block, MALLOC_FREE_PATTERN, block_info->allocated_size);
+ free(block);
+}
+#define free test_free
+
+
+/* Crudely checkpoint the current heap state. */
+static const ListNode* check_point_allocated_blocks() {
+ return get_allocated_blocks_list()->prev;
+}
+
+
+/* Display the blocks allocated after the specified check point. This
+ * function returns the number of blocks displayed. */
+static int display_allocated_blocks(const ListNode * const check_point) {
+ const ListNode * const head = get_allocated_blocks_list();
+ const ListNode *node;
+ int allocated_blocks = 0;
+ assert_non_null(check_point);
+ assert_non_null(check_point->next);
+
+ for (node = check_point->next; node != head; node = node->next) {
+ const MallocBlockInfo * const block_info =
+ (const MallocBlockInfo*)node->value;
+ assert_non_null(block_info);
+
+ if (!allocated_blocks) {
+ print_error("Blocks allocated...\n");
+ }
+ print_error(SOURCE_LOCATION_FORMAT ": note: block %p allocated here\n",
+ block_info->location.file,
+ block_info->location.line,
+ block_info->block);
+ allocated_blocks ++;
+ }
+ return allocated_blocks;
+}
+
+
+/* Free all blocks allocated after the specified check point. */
+static void free_allocated_blocks(const ListNode * const check_point) {
+ const ListNode * const head = get_allocated_blocks_list();
+ const ListNode *node;
+ assert_non_null(check_point);
+
+ node = check_point->next;
+ assert_non_null(node);
+
+ while (node != head) {
+ MallocBlockInfo * const block_info = (MallocBlockInfo*)node->value;
+ node = node->next;
+ free(discard_const_p(char, block_info) + sizeof(*block_info) + MALLOC_GUARD_SIZE);
+ }
+}
+
+
+/* Fail if any any blocks are allocated after the specified check point. */
+static void fail_if_blocks_allocated(const ListNode * const check_point,
+ const char * const test_name) {
+ const int allocated_blocks = display_allocated_blocks(check_point);
+ if (allocated_blocks) {
+ free_allocated_blocks(check_point);
+ print_error("ERROR: %s leaked %d block(s)\n", test_name,
+ allocated_blocks);
+ exit_test(1);
+ }
+}
+
+
+void _fail(const char * const file, const int line) {
+ print_error(SOURCE_LOCATION_FORMAT ": error: Failure!\n", file, line);
+ exit_test(1);
+}
+
+
+#ifndef _WIN32
+static void exception_handler(int sig) {
+#ifdef HAVE_STRSIGNAL
+ print_error("%s\n", strsignal(sig));
+#else
+ print_error("%d\n", sig);
+#endif
+ exit_test(1);
+}
+
+#else /* _WIN32 */
+
+static LONG WINAPI exception_filter(EXCEPTION_POINTERS *exception_pointers) {
+ EXCEPTION_RECORD * const exception_record =
+ exception_pointers->ExceptionRecord;
+ const DWORD code = exception_record->ExceptionCode;
+ unsigned int i;
+ for (i = 0; i < ARRAY_LENGTH(exception_codes); i++) {
+ const ExceptionCodeInfo * const code_info = &exception_codes[i];
+ if (code == code_info->code) {
+ static int shown_debug_message = 0;
+ fflush(stdout);
+ print_error("%s occurred at 0x%08x.\n", code_info->description,
+ exception_record->ExceptionAddress);
+ if (!shown_debug_message) {
+ print_error(
+ "\n"
+ "To debug in Visual Studio...\n"
+ "1. Select menu item File->Open Project\n"
+ "2. Change 'Files of type' to 'Executable Files'\n"
+ "3. Open this executable.\n"
+ "4. Select menu item Debug->Start\n"
+ "\n"
+ "Alternatively, set the environment variable \n"
+ "UNIT_TESTING_DEBUG to 1 and rebuild this executable, \n"
+ "then click 'Debug' in the popup dialog box.\n"
+ "\n");
+ shown_debug_message = 1;
+ }
+ exit_test(0);
+ return EXCEPTION_EXECUTE_HANDLER;
+ }
+ }
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+#endif /* !_WIN32 */
+
+
+/* Standard output and error print methods. */
+void vprint_message(const char* const format, va_list args) {
+ char buffer[1024];
+ vsnprintf(buffer, sizeof(buffer), format, args);
+ printf("%s", buffer);
+ fflush(stdout);
+#ifdef _WIN32
+ OutputDebugString(buffer);
+#endif /* _WIN32 */
+}
+
+
+void vprint_error(const char* const format, va_list args) {
+ char buffer[1024];
+ vsnprintf(buffer, sizeof(buffer), format, args);
+ fprintf(stderr, "%s", buffer);
+ fflush(stderr);
+#ifdef _WIN32
+ OutputDebugString(buffer);
+#endif /* _WIN32 */
+}
+
+
+void print_message(const char* const format, ...) {
+ va_list args;
+ va_start(args, format);
+ vprint_message(format, args);
+ va_end(args);
+}
+
+
+void print_error(const char* const format, ...) {
+ va_list args;
+ va_start(args, format);
+ vprint_error(format, args);
+ va_end(args);
+}
+
+
+int _run_test(
+ const char * const function_name, const UnitTestFunction Function,
+ void ** const volatile state, const UnitTestFunctionType function_type,
+ const void* const heap_check_point) {
+ const ListNode * const volatile check_point = (const ListNode*)
+ (heap_check_point ?
+ heap_check_point : check_point_allocated_blocks());
+ void *current_state = NULL;
+ volatile int rc = 1;
+ int handle_exceptions = 1;
+#ifdef _WIN32
+ handle_exceptions = !IsDebuggerPresent();
+#endif /* _WIN32 */
+#if UNIT_TESTING_DEBUG
+ handle_exceptions = 0;
+#endif /* UNIT_TESTING_DEBUG */
+
+ if (handle_exceptions) {
+#ifndef _WIN32
+ unsigned int i;
+ for (i = 0; i < ARRAY_LENGTH(exception_signals); i++) {
+ default_signal_functions[i] = signal(
+ exception_signals[i], exception_handler);
+ }
+#else /* _WIN32 */
+ previous_exception_filter = SetUnhandledExceptionFilter(
+ exception_filter);
+#endif /* !_WIN32 */
+ }
+
+ if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
+ print_message("[ RUN ] %s\n", function_name);
+ }
+ initialize_testing(function_name);
+ global_running_test = 1;
+ if (setjmp(global_run_test_env) == 0) {
+ Function(state ? state : &current_state);
+ fail_if_leftover_values(function_name);
+
+ /* If this is a setup function then ignore any allocated blocks
+ * only ensure they're deallocated on tear down. */
+ if (function_type != UNIT_TEST_FUNCTION_TYPE_SETUP) {
+ fail_if_blocks_allocated(check_point, function_name);
+ }
+
+ global_running_test = 0;
+
+ if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
+ print_message("[ OK ] %s\n", function_name);
+ }
+ rc = 0;
+ } else {
+ global_running_test = 0;
+ print_message("[ FAILED ] %s\n", function_name);
+ }
+ teardown_testing(function_name);
+
+ if (handle_exceptions) {
+#ifndef _WIN32
+ unsigned int i;
+ for (i = 0; i < ARRAY_LENGTH(exception_signals); i++) {
+ signal(exception_signals[i], default_signal_functions[i]);
+ }
+#else /* _WIN32 */
+ if (previous_exception_filter) {
+ SetUnhandledExceptionFilter(previous_exception_filter);
+ previous_exception_filter = NULL;
+ }
+#endif /* !_WIN32 */
+ }
+
+ return rc;
+}
+
+
+int _run_tests(const UnitTest * const tests, const size_t number_of_tests) {
+ /* Whether to execute the next test. */
+ int run_next_test = 1;
+ /* Whether the previous test failed. */
+ int previous_test_failed = 0;
+ /* Check point of the heap state. */
+ const ListNode * const check_point = check_point_allocated_blocks();
+ /* Current test being executed. */
+ size_t current_test = 0;
+ /* Number of tests executed. */
+ size_t tests_executed = 0;
+ /* Number of failed tests. */
+ size_t total_failed = 0;
+ /* Number of setup functions. */
+ size_t setups = 0;
+ /* Number of teardown functions. */
+ size_t teardowns = 0;
+ /*
+ * A stack of test states. A state is pushed on the stack
+ * when a test setup occurs and popped on tear down.
+ */
+ TestState* test_states =
+ (TestState*)malloc(number_of_tests * sizeof(*test_states));
+ size_t number_of_test_states = 0;
+ /* Names of the tests that failed. */
+ const char** failed_names = (const char**)malloc(number_of_tests *
+ sizeof(*failed_names));
+ void **current_state = NULL;
+
+ print_message("[==========] Running %"PRIdS " test(s).\n", number_of_tests);
+
+ /* Make sure LargestIntegralType is at least the size of a pointer. */
+ assert_true(sizeof(LargestIntegralType) >= sizeof(void*));
+
+ while (current_test < number_of_tests) {
+ const ListNode *test_check_point = NULL;
+ TestState *current_TestState;
+ const UnitTest * const test = &tests[current_test++];
+ if (!test->function) {
+ continue;
+ }
+
+ switch (test->function_type) {
+ case UNIT_TEST_FUNCTION_TYPE_TEST:
+ run_next_test = 1;
+ break;
+ case UNIT_TEST_FUNCTION_TYPE_SETUP: {
+ /* Checkpoint the heap before the setup. */
+ current_TestState = &test_states[number_of_test_states++];
+ current_TestState->check_point = check_point_allocated_blocks();
+ test_check_point = current_TestState->check_point;
+ current_state = &current_TestState->state;
+ *current_state = NULL;
+ run_next_test = 1;
+ setups ++;
+ break;
+ }
+ case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
+ /* Check the heap based on the last setup checkpoint. */
+ assert_true(number_of_test_states);
+ current_TestState = &test_states[--number_of_test_states];
+ test_check_point = current_TestState->check_point;
+ current_state = &current_TestState->state;
+ teardowns ++;
+ break;
+ default:
+ print_error("Invalid unit test function type %d\n",
+ test->function_type);
+ exit_test(1);
+ break;
+ }
+
+ if (run_next_test) {
+ int failed = _run_test(test->name, test->function, current_state,
+ test->function_type, test_check_point);
+ if (failed) {
+ failed_names[total_failed] = test->name;
+ }
+
+ switch (test->function_type) {
+ case UNIT_TEST_FUNCTION_TYPE_TEST:
+ previous_test_failed = failed;
+ total_failed += failed;
+ tests_executed ++;
+ break;
+
+ case UNIT_TEST_FUNCTION_TYPE_SETUP:
+ if (failed) {
+ total_failed ++;
+ tests_executed ++;
+ /* Skip forward until the next test or setup function. */
+ run_next_test = 0;
+ }
+ previous_test_failed = 0;
+ break;
+
+ case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
+ /* If this test failed. */
+ if (failed && !previous_test_failed) {
+ total_failed ++;
+ }
+ break;
+ default:
+#ifndef _HPUX
+ assert_null("BUG: shouldn't be here!");
+#endif
+ break;
+ }
+ }
+ }
+
+ print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
+ print_error("[ PASSED ] %"PRIdS " test(s).\n", tests_executed - total_failed);
+
+ if (total_failed) {
+ size_t i;
+ print_error("[ FAILED ] %"PRIdS " test(s), listed below:\n", total_failed);
+ for (i = 0; i < total_failed; i++) {
+ print_error("[ FAILED ] %s\n", failed_names[i]);
+ }
+ } else {
+ print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
+ }
+
+ if (number_of_test_states) {
+ print_error("[ ERROR ] Mismatched number of setup %"PRIdS " and "
+ "teardown %"PRIdS " functions\n", setups, teardowns);
+ total_failed = (size_t)-1;
+ }
+
+ free(test_states);
+ free((void*)failed_names);
+
+ fail_if_blocks_allocated(check_point, "run_tests");
+ return (int)total_failed;
+}
diff --git a/third_party/cmocka/src/cmocka.def b/third_party/cmocka/src/cmocka.def
new file mode 100644
index 0000000..268e1bd
--- /dev/null
+++ b/third_party/cmocka/src/cmocka.def
@@ -0,0 +1,42 @@
+LIBRARY cmocka
+EXPORTS
+ _assert_in_range
+ _assert_in_set
+ _assert_int_equal
+ _assert_int_not_equal
+ _assert_memory_equal
+ _assert_memory_not_equal
+ _assert_not_in_range
+ _assert_not_in_set
+ _assert_string_equal
+ _assert_string_not_equal
+ _assert_true
+ _check_expected
+ _expect_any
+ _expect_check
+ _expect_in_range
+ _expect_in_set
+ _expect_memory
+ _expect_not_in_range
+ _expect_not_in_set
+ _expect_not_memory
+ _expect_not_string
+ _expect_not_value
+ _expect_string
+ _expect_value
+ _fail
+ _mock
+ _run_test
+ _run_tests
+ _test_calloc
+ _test_free
+ _test_malloc
+ _will_return
+ global_expect_assert_env
+ global_expecting_assert
+ global_last_failed_assert
+ mock_assert
+ print_error
+ print_message
+ vprint_error
+ vprint_message