A copy of the newest cmocka release 1.1.7
|
@ -0,0 +1,2 @@
|
||||||
|
-Iinclude
|
||||||
|
-Iobj
|
|
@ -0,0 +1,109 @@
|
||||||
|
import os
|
||||||
|
import ycm_core
|
||||||
|
|
||||||
|
flags = [
|
||||||
|
'-Wall',
|
||||||
|
'-Wextra',
|
||||||
|
'-Werror',
|
||||||
|
'-x', 'c',
|
||||||
|
'-Iinclude',
|
||||||
|
]
|
||||||
|
|
||||||
|
# Set this to the absolute path to the folder (NOT the file!) containing the
|
||||||
|
# compile_commands.json file to use that instead of 'flags'. See here for
|
||||||
|
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
|
||||||
|
#
|
||||||
|
# Most projects will NOT need to set this to anything; you can just change the
|
||||||
|
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
|
||||||
|
compilation_database_folder = 'obj'
|
||||||
|
|
||||||
|
if os.path.exists( compilation_database_folder ):
|
||||||
|
database = ycm_core.CompilationDatabase( compilation_database_folder )
|
||||||
|
else:
|
||||||
|
database = None
|
||||||
|
|
||||||
|
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
|
||||||
|
|
||||||
|
def DirectoryOfThisScript():
|
||||||
|
return os.path.dirname( os.path.abspath( __file__ ) )
|
||||||
|
|
||||||
|
|
||||||
|
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
|
||||||
|
if not working_directory:
|
||||||
|
return list( flags )
|
||||||
|
new_flags = []
|
||||||
|
make_next_absolute = False
|
||||||
|
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
|
||||||
|
for flag in flags:
|
||||||
|
new_flag = flag
|
||||||
|
|
||||||
|
if make_next_absolute:
|
||||||
|
make_next_absolute = False
|
||||||
|
if not flag.startswith( '/' ):
|
||||||
|
new_flag = os.path.join( working_directory, flag )
|
||||||
|
|
||||||
|
for path_flag in path_flags:
|
||||||
|
if flag == path_flag:
|
||||||
|
make_next_absolute = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if flag.startswith( path_flag ):
|
||||||
|
path = flag[ len( path_flag ): ]
|
||||||
|
new_flag = path_flag + os.path.join( working_directory, path )
|
||||||
|
break
|
||||||
|
|
||||||
|
if new_flag:
|
||||||
|
new_flags.append( new_flag )
|
||||||
|
return new_flags
|
||||||
|
|
||||||
|
|
||||||
|
def IsHeaderFile( filename ):
|
||||||
|
extension = os.path.splitext( filename )[ 1 ]
|
||||||
|
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
|
||||||
|
|
||||||
|
|
||||||
|
def GetCompilationInfoForFile( filename ):
|
||||||
|
# The compilation_commands.json file generated by CMake does not have entries
|
||||||
|
# for header files. So we do our best by asking the db for flags for a
|
||||||
|
# corresponding source file, if any. If one exists, the flags for that file
|
||||||
|
# should be good enough.
|
||||||
|
if IsHeaderFile( filename ):
|
||||||
|
basename = os.path.splitext( filename )[ 0 ]
|
||||||
|
for extension in SOURCE_EXTENSIONS:
|
||||||
|
replacement_file = basename + extension
|
||||||
|
if os.path.exists( replacement_file ):
|
||||||
|
compilation_info = database.GetCompilationInfoForFile(
|
||||||
|
replacement_file )
|
||||||
|
if compilation_info.compiler_flags_:
|
||||||
|
return compilation_info
|
||||||
|
return None
|
||||||
|
return database.GetCompilationInfoForFile( filename )
|
||||||
|
|
||||||
|
|
||||||
|
def FlagsForFile( filename, **kwargs ):
|
||||||
|
if database:
|
||||||
|
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
|
||||||
|
# python list, but a "list-like" StringVec object
|
||||||
|
compilation_info = GetCompilationInfoForFile( filename )
|
||||||
|
if not compilation_info:
|
||||||
|
return None
|
||||||
|
|
||||||
|
final_flags = MakeRelativePathsInFlagsAbsolute(
|
||||||
|
compilation_info.compiler_flags_,
|
||||||
|
compilation_info.compiler_working_dir_ )
|
||||||
|
|
||||||
|
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
|
||||||
|
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
|
||||||
|
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
|
||||||
|
try:
|
||||||
|
final_flags.remove( '-stdlib=libc++' )
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
relative_to = DirectoryOfThisScript()
|
||||||
|
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
|
||||||
|
|
||||||
|
return {
|
||||||
|
'flags': final_flags,
|
||||||
|
'do_cache': True
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
opensource@google.com
|
||||||
|
Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
Jakub Hrozek <jakub.hrozek@posteo.se>
|
|
@ -0,0 +1,93 @@
|
||||||
|
# Required cmake version
|
||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
|
||||||
|
# Specify search path for CMake modules to be loaded by include()
|
||||||
|
# and find_package()
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
|
||||||
|
|
||||||
|
### Add defaults for cmake
|
||||||
|
# These defaults need to be included before the project() call.
|
||||||
|
include(DefineCMakeDefaults)
|
||||||
|
|
||||||
|
# This will provide -DCMAKE_BUILD_TYPE=Profiling
|
||||||
|
# and -DCMAKE_BUILD_TYPE=AddressSanitizer
|
||||||
|
include(DefineCompilerFlags)
|
||||||
|
include(DefinePlatformDefaults)
|
||||||
|
|
||||||
|
project(cmocka VERSION 1.1.7 LANGUAGES C)
|
||||||
|
|
||||||
|
# global needed variables
|
||||||
|
set(APPLICATION_NAME ${PROJECT_NAME})
|
||||||
|
|
||||||
|
# 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.8.0")
|
||||||
|
set(LIBRARY_SOVERSION "0")
|
||||||
|
|
||||||
|
# include cmake files
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(DefineOptions.cmake)
|
||||||
|
include(CPackConfig.cmake)
|
||||||
|
include(CompilerChecks.cmake)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# MinGW DLL Naming Workaround
|
||||||
|
if (MINGW)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||||
|
endif (MINGW)
|
||||||
|
|
||||||
|
# check subdirectories
|
||||||
|
add_subdirectory(include)
|
||||||
|
add_subdirectory(src)
|
||||||
|
add_subdirectory(doc)
|
||||||
|
|
||||||
|
include(AddCMockaTest)
|
||||||
|
if (UNIT_TESTING)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif (UNIT_TESTING)
|
||||||
|
|
||||||
|
if (WITH_EXAMPLES)
|
||||||
|
add_subdirectory(example)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# pkg-config file
|
||||||
|
configure_file(cmocka.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc @ONLY)
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc
|
||||||
|
DESTINATION
|
||||||
|
${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||||
|
COMPONENT
|
||||||
|
pkgconfig
|
||||||
|
)
|
||||||
|
|
||||||
|
write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
|
||||||
|
COMPATIBILITY
|
||||||
|
AnyNewerVersion)
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||||
|
COMPONENT devel)
|
||||||
|
|
||||||
|
# Add 'make dist' target which makes sure to invoke cmake before
|
||||||
|
add_custom_target(dist
|
||||||
|
COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
|
||||||
|
|
||||||
|
# Link combile database for clangd
|
||||||
|
execute_process(COMMAND cmake -E create_symlink
|
||||||
|
"${cmocka_BINARY_DIR}/compile_commands.json"
|
||||||
|
"${cmocka_SOURCE_DIR}/compile_commands.json")
|
|
@ -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.
|
|
@ -0,0 +1,54 @@
|
||||||
|
# For help take a look at:
|
||||||
|
# http://www.cmake.org/Wiki/CMake:CPackConfiguration
|
||||||
|
|
||||||
|
### general settings
|
||||||
|
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unit testing framework for C with mock objects")
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
||||||
|
set(CPACK_PACKAGE_VENDOR "Andreas Schneider")
|
||||||
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
|
||||||
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
|
||||||
|
|
||||||
|
|
||||||
|
### versions
|
||||||
|
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||||
|
|
||||||
|
|
||||||
|
### source generator
|
||||||
|
set(CPACK_SOURCE_GENERATOR "TXZ")
|
||||||
|
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]git;/[.]gitignore")
|
||||||
|
string(APPEND CPACK_SOURCE_IGNORE_FILES ";/build*;/obj*")
|
||||||
|
string(APPEND CPACK_SOURCE_IGNORE_FILES ";/tags;/cscope\.*")
|
||||||
|
string(APPEND CPACK_SOURCE_IGNORE_FILES ";/[.]ycm_extra_conf.pyc;")
|
||||||
|
string(APPEND CPACK_SOURCE_IGNORE_FILES ";/[.]clangd;/[.]cache;/compile_commands.json")
|
||||||
|
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 ${PROJECT_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)
|
|
@ -0,0 +1,9 @@
|
||||||
|
set(UPDATE_TYPE "true")
|
||||||
|
|
||||||
|
set(CTEST_PROJECT_NAME "cmocka")
|
||||||
|
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
|
||||||
|
|
||||||
|
set(CTEST_DROP_METHOD "https")
|
||||||
|
set(CTEST_DROP_SITE "test.cmocka.org")
|
||||||
|
set(CTEST_DROP_LOCATION "/submit.php?project=${CTEST_PROJECT_NAME}")
|
||||||
|
set(CTEST_DROP_SITE_CDASH TRUE)
|
|
@ -0,0 +1,137 @@
|
||||||
|
Thu Feb 23 2023 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka version 1.1.7
|
||||||
|
* Update ignore list for source tarball generation
|
||||||
|
|
||||||
|
Fri Feb 16 2023 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka version 1.1.6
|
||||||
|
* Added new assert macros to compare 2 double given an epsilon
|
||||||
|
* Added meson build system
|
||||||
|
* Added header with version to TAP13 output
|
||||||
|
* Fixed issues with MSVC
|
||||||
|
* Fixed TAP output for skipped tests
|
||||||
|
* Fixed issue with fail_msg
|
||||||
|
* CMake generated configs for find_package(cmocka)
|
||||||
|
* Documentation improvements
|
||||||
|
|
||||||
|
Thu Mar 28 2019 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka version 1.1.5
|
||||||
|
* Added cmocka_set_skip_filter()
|
||||||
|
|
||||||
|
Thu Mar 28 2019 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka version 1.1.4
|
||||||
|
* Added assert_float(_not)_equal()
|
||||||
|
* Added expect_any_always()
|
||||||
|
* Small bug fixes
|
||||||
|
|
||||||
|
Wed Sep 26 2018 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka version 1.1.3
|
||||||
|
* Fixed subunit output on failures
|
||||||
|
* Do not abort if a test is skipped
|
||||||
|
* Switched to Modern CMake
|
||||||
|
|
||||||
|
Wed Aug 29 2018 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka version 1.1.2
|
||||||
|
* Added function to filter tests (cmocka_set_test_filter)
|
||||||
|
* Added new mocking example (uptime)
|
||||||
|
* Fixed fixture error reporting
|
||||||
|
* Fixed compiler flags detection
|
||||||
|
* Some improvement for API documentation
|
||||||
|
|
||||||
|
Fri Apr 07 2016 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka: version 1.1.1
|
||||||
|
* Fixed TAP output
|
||||||
|
* Fixed cmocka on Windows x64
|
||||||
|
* Fixed xUnit output durations
|
||||||
|
|
||||||
|
Wed Sep 21 2016 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka: version 1.1.0
|
||||||
|
* Added support to catch multiple exceptions
|
||||||
|
* Added support to verify call ordering
|
||||||
|
* Added support to pass initial data to test cases
|
||||||
|
* Added will_return_maybe() for ignoring mock returns
|
||||||
|
* Added subtests for groups using TAP output
|
||||||
|
* Added support to write multiple XML files for groups
|
||||||
|
* Improved documentation
|
||||||
|
* Fixed XML output generataion
|
||||||
|
* Fixed Windows builds with VS2015
|
||||||
|
|
||||||
|
Thu Mar 12 2015 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka: version 1.0.1
|
||||||
|
* Added a macro for assert_ptr_equal().
|
||||||
|
* Fixed test_realloc() if 0 size is passed.
|
||||||
|
* Fixed objects packaging bug.
|
||||||
|
* Fixed building with newer gcc versions.
|
||||||
|
|
||||||
|
Sun Feb 16 2015 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka: version 1.0.0
|
||||||
|
* Added new test runner with group fixtures. The old runner is deprecated
|
||||||
|
* Added an extensible message output formatter
|
||||||
|
* Added jUnit XML message output
|
||||||
|
* Added subunit message output
|
||||||
|
* Added Test Anything Protocol message output
|
||||||
|
* Added skip() command
|
||||||
|
* Added test_realloc()
|
||||||
|
* Added a cmockery compat header
|
||||||
|
* Fixed a lot of bugs on Windows
|
||||||
|
|
||||||
|
Thu May 22 2014 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka: version 0.4.1
|
||||||
|
* Added CMOCKA_TEST_ABORT env variable to leave threading apps.
|
||||||
|
* Fixed count parameter of expect_check() macro.
|
||||||
|
* Fixed reporting the number of tests.
|
||||||
|
* Fixed cmake config files.
|
||||||
|
|
||||||
|
Fri Apr 11 2014 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
* cmocka: version 0.4.0
|
||||||
|
* Added support for group testing.
|
||||||
|
* Added assert_return_code().
|
||||||
|
* Added better messages for errors.
|
||||||
|
* Added cmake config mode support.
|
||||||
|
* Fixed bug with unit_test_setup and unit_test_teardown.
|
||||||
|
* Fixed a lot of small bugs.
|
||||||
|
|
||||||
|
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.
|
|
@ -0,0 +1,109 @@
|
||||||
|
include(AddCCompilerFlag)
|
||||||
|
include(CheckCCompilerFlagSSP)
|
||||||
|
|
||||||
|
if (UNIX)
|
||||||
|
#
|
||||||
|
# Check for -Werror turned on if possible
|
||||||
|
#
|
||||||
|
# This will prevent that compiler flags are detected incorrectly.
|
||||||
|
#
|
||||||
|
check_c_compiler_flag("-Werror" REQUIRED_FLAGS_WERROR)
|
||||||
|
if (REQUIRED_FLAGS_WERROR)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "-Werror")
|
||||||
|
|
||||||
|
if (PICKY_DEVELOPER)
|
||||||
|
list(APPEND SUPPORTED_COMPILER_FLAGS "-Werror")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_c_compiler_flag("-std=gnu99" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wpedantic" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wall" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wshadow" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wmissing-prototypes" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wcast-align" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
#add_c_compiler_flag("-Wcast-qual" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=address" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wstrict-prototypes" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=strict-prototypes" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wwrite-strings" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=write-strings" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror-implicit-function-declaration" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wpointer-arith" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=pointer-arith" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wdeclaration-after-statement" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=declaration-after-statement" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wreturn-type" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=return-type" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wuninitialized" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=uninitialized" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wimplicit-fallthrough" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=strict-overflow" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wstrict-overflow=2" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wno-format-zero-length" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wmissing-field-initializers" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
|
||||||
|
check_c_compiler_flag("-Wformat" REQUIRED_FLAGS_WFORMAT)
|
||||||
|
if (REQUIRED_FLAGS_WFORMAT)
|
||||||
|
list(APPEND SUPPORTED_COMPILER_FLAGS "-Wformat")
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat")
|
||||||
|
endif()
|
||||||
|
add_c_compiler_flag("-Wformat-security" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Werror=format-security" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
|
||||||
|
# Allow zero for a variadic macro argument
|
||||||
|
string(TOLOWER "${CMAKE_C_COMPILER_ID}" _C_COMPILER_ID)
|
||||||
|
if ("${_C_COMPILER_ID}" STREQUAL "clang")
|
||||||
|
add_c_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_c_compiler_flag("-fno-common" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
|
||||||
|
if (CMAKE_BUILD_TYPE)
|
||||||
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
||||||
|
if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel))
|
||||||
|
add_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_c_compiler_flag_ssp("-fstack-protector-strong" WITH_STACK_PROTECTOR_STRONG)
|
||||||
|
if (WITH_STACK_PROTECTOR_STRONG)
|
||||||
|
list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector-strong")
|
||||||
|
# This is needed as Solaris has a seperate libssp
|
||||||
|
if (SOLARIS)
|
||||||
|
list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector-strong")
|
||||||
|
endif()
|
||||||
|
else (WITH_STACK_PROTECTOR_STRONG)
|
||||||
|
check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR)
|
||||||
|
if (WITH_STACK_PROTECTOR)
|
||||||
|
list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector")
|
||||||
|
# This is needed as Solaris has a seperate libssp
|
||||||
|
if (SOLARIS)
|
||||||
|
list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif (WITH_STACK_PROTECTOR_STRONG)
|
||||||
|
|
||||||
|
check_c_compiler_flag_ssp("-fstack-clash-protection" WITH_STACK_CLASH_PROTECTION)
|
||||||
|
if (WITH_STACK_CLASH_PROTECTION)
|
||||||
|
list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-clash-protection")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (PICKY_DEVELOPER)
|
||||||
|
add_c_compiler_flag("-Wno-error=deprecated-declarations" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("-Wno-error=tautological-compare" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Unset CMAKE_REQUIRED_FLAGS
|
||||||
|
unset(CMAKE_REQUIRED_FLAGS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("/D _CRT_NONSTDC_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
add_c_compiler_flag("/D _CRT_SECURE_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(DEFAULT_C_COMPILE_FLAGS ${SUPPORTED_COMPILER_FLAGS} CACHE INTERNAL "Default C Compiler Flags" FORCE)
|
||||||
|
set(DEFAULT_LINK_FLAGS ${SUPPORTED_LINKER_FLAGS} CACHE INTERNAL "Default C Linker Flags" FORCE)
|
|
@ -0,0 +1,152 @@
|
||||||
|
include(CheckIncludeFile)
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
include(CheckFunctionExists)
|
||||||
|
include(CheckLibraryExists)
|
||||||
|
include(CheckTypeSize)
|
||||||
|
include(CheckCXXSourceCompiles)
|
||||||
|
include(CheckStructHasMember)
|
||||||
|
include(TestBigEndian)
|
||||||
|
|
||||||
|
set(PACKAGE ${PROJECT_NAME})
|
||||||
|
set(VERSION ${PROJECT_VERSION})
|
||||||
|
set(DATADIR ${DATA_INSTALL_DIR})
|
||||||
|
set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
||||||
|
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(io.h HAVE_IO_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(time.h HAVE_TIME_H)
|
||||||
|
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||||
|
|
||||||
|
if (HAVE_TIME_H)
|
||||||
|
check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC)
|
||||||
|
endif (HAVE_TIME_H)
|
||||||
|
|
||||||
|
# TYPES
|
||||||
|
check_type_size(uintptr_t UINTPTR_T)
|
||||||
|
|
||||||
|
# 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(siglongjmp HAVE_SIGLONGJMP)
|
||||||
|
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(strcmp HAVE_STRCMP)
|
||||||
|
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
|
||||||
|
|
||||||
|
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)
|
||||||
|
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
|
||||||
|
check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF)
|
||||||
|
else (WIN32)
|
||||||
|
check_function_exists(sprintf HAVE_SNPRINTF)
|
||||||
|
check_function_exists(vsnprintf HAVE_VSNPRINTF)
|
||||||
|
endif (WIN32)
|
||||||
|
|
||||||
|
find_library(RT_LIBRARY rt)
|
||||||
|
if (RT_LIBRARY AND NOT LINUX AND NOT ANDROID)
|
||||||
|
set(CMOCKA_REQUIRED_LIBRARIES ${RT_LIBRARY} CACHE INTERNAL "cmocka required system libraries")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# OPTIONS
|
||||||
|
check_c_source_compiles("
|
||||||
|
__thread int tls;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
return 0;
|
||||||
|
}" HAVE_GCC_THREAD_LOCAL_STORAGE)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
check_c_source_compiles("
|
||||||
|
__declspec(thread) int tls;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
return 0;
|
||||||
|
}" HAVE_MSVC_THREAD_LOCAL_STORAGE)
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
|
if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME)
|
||||||
|
if (RT_LIBRARY)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_c_source_compiles("
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}" HAVE_CLOCK_REALTIME)
|
||||||
|
|
||||||
|
# reset cmake requirements
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# ENDIAN
|
||||||
|
if (NOT WIN32)
|
||||||
|
set(WORDS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
|
||||||
|
test_big_endian(WORDS_BIGENDIAN)
|
||||||
|
endif (NOT WIN32)
|
|
@ -0,0 +1,5 @@
|
||||||
|
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||||
|
option(WITH_CMOCKERY_SUPPORT "Install a cmockery header" OFF)
|
||||||
|
option(WITH_EXAMPLES "Build examples" ON)
|
||||||
|
option(UNIT_TESTING "Build with unit testing" OFF)
|
||||||
|
option(PICKY_DEVELOPER "Build with picky developer flags" OFF)
|
|
@ -0,0 +1,120 @@
|
||||||
|
# Installing cmocka
|
||||||
|
|
||||||
|
## Use a package manger (also on Windows)
|
||||||
|
|
||||||
|
If you're using a BSD or Linux distribution, cmocka is already packaged and
|
||||||
|
you should find it in your package manager.
|
||||||
|
|
||||||
|
<your package manager> install cmocka-devel
|
||||||
|
or
|
||||||
|
<your package manager> install libcmocka-devel
|
||||||
|
|
||||||
|
For Windows it is recommended to use: https://vcpkg.io/
|
||||||
|
|
||||||
|
vcpkg install cmocka
|
||||||
|
|
||||||
|
## Building from source
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
#### Common requirements
|
||||||
|
|
||||||
|
In order to build cmocka, you need to install several components:
|
||||||
|
|
||||||
|
- A C compiler
|
||||||
|
- [CMake](http://www.cmake.org) >= 3.5.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, for example:
|
||||||
|
|
||||||
|
cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Debug /path/to/source
|
||||||
|
|
||||||
|
You can also use the CMake GUI which is shipped with CMake. It will list all
|
||||||
|
available generators for MSVC on Windows. We only support Visual Studio 2013
|
||||||
|
or newer which supports C99.
|
||||||
|
|
||||||
|
#### 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 `cmake-gui.exe` (Windows) or `ccmake` (GNU/Linux
|
||||||
|
and MacOS X).
|
||||||
|
|
||||||
|
- Go to the build dir
|
||||||
|
- On Windows: run `cmakesetup`
|
||||||
|
- On GNU/Linux and MacOS X: run `ccmake ..`
|
||||||
|
|
||||||
|
More at https://cmake.org/runningcmake/
|
||||||
|
|
||||||
|
### 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 example tests.
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
As mention above you can turn on the unit tests and make it possible to easily
|
||||||
|
execute them:
|
||||||
|
|
||||||
|
`cmake -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..`
|
||||||
|
|
||||||
|
After that you can simply call `make test` in the build directory or if you
|
||||||
|
want more output simply call `ctest -V`.
|
||||||
|
|
||||||
|
If you want to enable the generation of coverage files you can do this by
|
||||||
|
using the following options:
|
||||||
|
|
||||||
|
`cmake -DCMAKE_BUILD_TYPE=Profiling -DUNIT_TESTING=ON ..`
|
||||||
|
|
||||||
|
After building it you will see that you have several coverage options in
|
||||||
|
|
||||||
|
`make help`
|
||||||
|
|
||||||
|
You should have `make ExperimentalCoverage` and running it will create
|
||||||
|
coverage files. The result is stored in Testing directory.
|
||||||
|
|
||||||
|
## 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
|
|
@ -0,0 +1,22 @@
|
||||||
|
cmocka
|
||||||
|
======
|
||||||
|
|
||||||
|
cmocka is an elegant unit testing framework for C with support for mock
|
||||||
|
objects. It only requires the standard C library, works on a range of computing
|
||||||
|
platforms (including embedded) and with different compilers.
|
||||||
|
|
||||||
|
For information about how to use the cmocka unit testing framework see
|
||||||
|
doc/index.html or https://api.cmocka.org/.
|
||||||
|
|
||||||
|
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.md
|
||||||
|
file.
|
||||||
|
|
||||||
|
Website
|
||||||
|
-------
|
||||||
|
|
||||||
|
https://cmocka.org
|
|
@ -0,0 +1,21 @@
|
||||||
|
#
|
||||||
|
# add_c_compiler_flag("-Werror" SUPPORTED_CFLAGS)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||||
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
|
|
||||||
|
include(CheckCCompilerFlag)
|
||||||
|
|
||||||
|
macro(add_c_compiler_flag _COMPILER_FLAG _OUTPUT_VARIABLE)
|
||||||
|
string(TOUPPER ${_COMPILER_FLAG} _COMPILER_FLAG_NAME)
|
||||||
|
string(REGEX REPLACE "^-" "" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}")
|
||||||
|
string(REGEX REPLACE "(-|=|\ )" "_" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}")
|
||||||
|
|
||||||
|
check_c_compiler_flag("${_COMPILER_FLAG}" WITH_${_COMPILER_FLAG_NAME}_FLAG)
|
||||||
|
if (WITH_${_COMPILER_FLAG_NAME}_FLAG)
|
||||||
|
#string(APPEND ${_OUTPUT_VARIABLE} "${_COMPILER_FLAG} ")
|
||||||
|
list(APPEND ${_OUTPUT_VARIABLE} ${_COMPILER_FLAG})
|
||||||
|
endif()
|
||||||
|
endmacro()
|
|
@ -0,0 +1,143 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
|
||||||
|
# Copyright (c) 2007-2018 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
# Copyright (c) 2018 Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
|
||||||
|
#
|
||||||
|
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||||
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
|
|
||||||
|
#.rst:
|
||||||
|
# AddCMockaTest
|
||||||
|
# -------------
|
||||||
|
#
|
||||||
|
# This file provides a function to add a test
|
||||||
|
#
|
||||||
|
# Functions provided
|
||||||
|
# ------------------
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# add_cmocka_test(target_name
|
||||||
|
# SOURCES src1 src2 ... srcN
|
||||||
|
# [COMPILE_OPTIONS opt1 opt2 ... optN]
|
||||||
|
# [LINK_LIBRARIES lib1 lib2 ... libN]
|
||||||
|
# [LINK_OPTIONS lopt1 lop2 .. loptN]
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# ``target_name``:
|
||||||
|
# Required, expects the name of the test which will be used to define a target
|
||||||
|
#
|
||||||
|
# ``SOURCES``:
|
||||||
|
# Required, expects one or more source files names
|
||||||
|
#
|
||||||
|
# ``COMPILE_OPTIONS``:
|
||||||
|
# Optional, expects one or more options to be passed to the compiler
|
||||||
|
#
|
||||||
|
# ``LINK_LIBRARIES``:
|
||||||
|
# Optional, expects one or more libraries to be linked with the test
|
||||||
|
# executable.
|
||||||
|
#
|
||||||
|
# ``LINK_OPTIONS``:
|
||||||
|
# Optional, expects one or more options to be passed to the linker
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# .. code-block:: cmake
|
||||||
|
#
|
||||||
|
# add_cmocka_test(my_test
|
||||||
|
# SOURCES my_test.c other_source.c
|
||||||
|
# COMPILE_OPTIONS -g -Wall
|
||||||
|
# LINK_LIBRARIES mylib
|
||||||
|
# LINK_OPTIONS -Wl,--enable-syscall-fixup
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# Where ``my_test`` is the name of the test, ``my_test.c`` and
|
||||||
|
# ``other_source.c`` are sources for the binary, ``-g -Wall`` are compiler
|
||||||
|
# options to be used, ``mylib`` is a target of a library to be linked, and
|
||||||
|
# ``-Wl,--enable-syscall-fixup`` is an option passed to the linker.
|
||||||
|
#
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
if (CMAKE_CROSSCOMPILING)
|
||||||
|
if (WIN32)
|
||||||
|
find_program(WINE_EXECUTABLE
|
||||||
|
NAMES wine)
|
||||||
|
set(TARGET_SYSTEM_EMULATOR ${WINE_EXECUTABLE} CACHE INTERNAL "")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(ADD_CMOCKA_TEST _TARGET_NAME)
|
||||||
|
|
||||||
|
set(one_value_arguments
|
||||||
|
)
|
||||||
|
|
||||||
|
set(multi_value_arguments
|
||||||
|
SOURCES
|
||||||
|
COMPILE_OPTIONS
|
||||||
|
LINK_LIBRARIES
|
||||||
|
LINK_OPTIONS
|
||||||
|
)
|
||||||
|
|
||||||
|
cmake_parse_arguments(_add_cmocka_test
|
||||||
|
""
|
||||||
|
"${one_value_arguments}"
|
||||||
|
"${multi_value_arguments}"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT DEFINED _add_cmocka_test_SOURCES)
|
||||||
|
message(FATAL_ERROR "No sources provided for target ${_TARGET_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(${_TARGET_NAME} ${_add_cmocka_test_SOURCES})
|
||||||
|
|
||||||
|
if (DEFINED _add_cmocka_test_COMPILE_OPTIONS)
|
||||||
|
target_compile_options(${_TARGET_NAME}
|
||||||
|
PRIVATE ${_add_cmocka_test_COMPILE_OPTIONS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED _add_cmocka_test_LINK_LIBRARIES)
|
||||||
|
target_link_libraries(${_TARGET_NAME}
|
||||||
|
PRIVATE ${_add_cmocka_test_LINK_LIBRARIES}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED _add_cmocka_test_LINK_OPTIONS)
|
||||||
|
set_target_properties(${_TARGET_NAME}
|
||||||
|
PROPERTIES LINK_FLAGS
|
||||||
|
${_add_cmocka_test_LINK_OPTIONS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_test(${_TARGET_NAME}
|
||||||
|
${TARGET_SYSTEM_EMULATOR} ${_TARGET_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
endfunction (ADD_CMOCKA_TEST)
|
||||||
|
|
||||||
|
function(ADD_CMOCKA_TEST_ENVIRONMENT _TARGET_NAME)
|
||||||
|
if (WIN32 OR CYGWIN OR MINGW OR MSVC)
|
||||||
|
file(TO_NATIVE_PATH "${cmocka-library_BINARY_DIR}" CMOCKA_DLL_PATH)
|
||||||
|
|
||||||
|
if (TARGET_SYSTEM_EMULATOR)
|
||||||
|
set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}")
|
||||||
|
else()
|
||||||
|
set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH}\\${CMAKE_BUILD_TYPE};$ENV{PATH}")
|
||||||
|
endif()
|
||||||
|
#
|
||||||
|
# IMPORTANT NOTE: The set_tests_properties(), below, internally
|
||||||
|
# stores its name/value pairs with a semicolon delimiter.
|
||||||
|
# because of this we must protect the semicolons in the path
|
||||||
|
#
|
||||||
|
string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}")
|
||||||
|
|
||||||
|
set_tests_properties(${_TARGET_NAME}
|
||||||
|
PROPERTIES
|
||||||
|
ENVIRONMENT
|
||||||
|
"${DLL_PATH_ENV}")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
|
@ -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.
|
|
@ -0,0 +1,48 @@
|
||||||
|
# - 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.
|
||||||
|
|
||||||
|
# Requires cmake 3.10
|
||||||
|
#include_guard(GLOBAL)
|
||||||
|
include(CheckCSourceCompiles)
|
||||||
|
include(CMakeCheckCompilerFlagCommonPatterns)
|
||||||
|
|
||||||
|
macro(CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT)
|
||||||
|
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "${_FLAG}")
|
||||||
|
|
||||||
|
# Normalize locale during test compilation.
|
||||||
|
set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
|
||||||
|
foreach(v ${_CheckCCompilerFlag_LOCALE_VARS})
|
||||||
|
set(_CheckCCompilerFlag_SAVED_${v} "$ENV{${v}}")
|
||||||
|
set(ENV{${v}} C)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCCompilerFlag_COMMON_PATTERNS)
|
||||||
|
check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}"
|
||||||
|
${_RESULT}
|
||||||
|
# Some compilers do not fail with a bad flag
|
||||||
|
FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU
|
||||||
|
${_CheckCCompilerFlag_COMMON_PATTERNS})
|
||||||
|
foreach(v ${_CheckCCompilerFlag_LOCALE_VARS})
|
||||||
|
set(ENV{${v}} ${_CheckCCompilerFlag_SAVED_${v}})
|
||||||
|
unset(_CheckCCompilerFlag_SAVED_${v})
|
||||||
|
endforeach()
|
||||||
|
unset(_CheckCCompilerFlag_LOCALE_VARS)
|
||||||
|
unset(_CheckCCompilerFlag_COMMON_PATTERNS)
|
||||||
|
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
|
||||||
|
endmacro(CHECK_C_COMPILER_FLAG_SSP)
|
|
@ -0,0 +1,25 @@
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Create the compile command database for clang by default
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Always build with -fPIC
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
|
# Avoid source tree pollution
|
||||||
|
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
||||||
|
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
|
@ -0,0 +1,49 @@
|
||||||
|
if (UNIX AND NOT WIN32)
|
||||||
|
# Activate with: -DCMAKE_BUILD_TYPE=Profiling
|
||||||
|
set(CMAKE_C_FLAGS_PROFILING "-O0 -g -fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the C compiler during PROFILING builds.")
|
||||||
|
set(CMAKE_CXX_FLAGS_PROFILING "-O0 -g -fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the CXX compiler during PROFILING builds.")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during PROFILING builds.")
|
||||||
|
set(CMAKE_MODULE_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during PROFILING builds.")
|
||||||
|
set(CMAKE_EXEC_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the linker during PROFILING builds.")
|
||||||
|
|
||||||
|
# Activate with: -DCMAKE_BUILD_TYPE=AddressSanitizer
|
||||||
|
set(CMAKE_C_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer"
|
||||||
|
CACHE STRING "Flags used by the C compiler during ADDRESSSANITIZER builds.")
|
||||||
|
set(CMAKE_CXX_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer"
|
||||||
|
CACHE STRING "Flags used by the CXX compiler during ADDRESSSANITIZER builds.")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during ADDRESSSANITIZER builds.")
|
||||||
|
set(CMAKE_MODULE_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during ADDRESSSANITIZER builds.")
|
||||||
|
set(CMAKE_EXEC_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address"
|
||||||
|
CACHE STRING "Flags used by the linker during ADDRESSSANITIZER builds.")
|
||||||
|
|
||||||
|
# Activate with: -DCMAKE_BUILD_TYPE=MemorySanitizer
|
||||||
|
set(CMAKE_C_FLAGS_MEMORYSANITIZER "-g -O2 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer"
|
||||||
|
CACHE STRING "Flags used by the C compiler during MEMORYSANITIZER builds.")
|
||||||
|
set(CMAKE_CXX_FLAGS_MEMORYSANITIZER "-g -O2 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer"
|
||||||
|
CACHE STRING "Flags used by the CXX compiler during MEMORYSANITIZER builds.")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_MEMORYSANITIZER "-fsanitize=memory"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during MEMORYSANITIZER builds.")
|
||||||
|
set(CMAKE_MODULE_LINKER_FLAGS_MEMORYSANITIZER "-fsanitize=memory"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during MEMORYSANITIZER builds.")
|
||||||
|
set(CMAKE_EXEC_LINKER_FLAGS_MEMORYSANITIZER "-fsanitize=memory"
|
||||||
|
CACHE STRING "Flags used by the linker during MEMORYSANITIZER builds.")
|
||||||
|
|
||||||
|
# Activate with: -DCMAKE_BUILD_TYPE=UndefinedSanitizer
|
||||||
|
set(CMAKE_C_FLAGS_UNDEFINEDSANITIZER "-g -O1 -fsanitize=undefined -fsanitize=null -fsanitize=alignment -fno-sanitize-recover"
|
||||||
|
CACHE STRING "Flags used by the C compiler during UNDEFINEDSANITIZER builds.")
|
||||||
|
set(CMAKE_CXX_FLAGS_UNDEFINEDSANITIZER "-g -O1 -fsanitize=undefined -fsanitize=null -fsanitize=alignment -fno-sanitize-recover"
|
||||||
|
CACHE STRING "Flags used by the CXX compiler during UNDEFINEDSANITIZER builds.")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.")
|
||||||
|
set(CMAKE_MODULE_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined"
|
||||||
|
CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.")
|
||||||
|
set(CMAKE_EXEC_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined"
|
||||||
|
CACHE STRING "Flags used by the linker during UNDEFINEDSANITIZER builds.")
|
||||||
|
endif()
|
|
@ -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)")
|
|
@ -0,0 +1,54 @@
|
||||||
|
# - Try to find NSIS
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# NSIS_ROOT_PATH - Set this variable to the root installation of NSIS
|
||||||
|
#
|
||||||
|
# Read-Only variables:
|
||||||
|
#
|
||||||
|
# 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(_x86 "(x86)")
|
||||||
|
|
||||||
|
set(_NSIS_ROOT_PATHS
|
||||||
|
"$ENV{ProgramFiles}/NSIS"
|
||||||
|
"$ENV{ProgramFiles${_x86}}/NSIS"
|
||||||
|
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS;Default]")
|
||||||
|
|
||||||
|
find_path(NSIS_ROOT_PATH
|
||||||
|
NAMES
|
||||||
|
Include/Library.nsh
|
||||||
|
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)
|
|
@ -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)
|
|
@ -0,0 +1,21 @@
|
||||||
|
include(CMakeForceCompiler)
|
||||||
|
|
||||||
|
set(TOOLCHAIN_PREFIX mips-linux-gnu)
|
||||||
|
|
||||||
|
set(CMAKE_SYSTEM_NAME Linux)
|
||||||
|
set(CMAKE_SYSTEM_VERSION 1)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR mips)
|
||||||
|
|
||||||
|
# This is the location of the mips toolchain
|
||||||
|
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||||
|
|
||||||
|
# This is the file system root of the target
|
||||||
|
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||||
|
|
||||||
|
# Search for programs in the build host directories
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
|
||||||
|
# For libraries and headers in the target directories
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
@ -0,0 +1,23 @@
|
||||||
|
set(CMAKE_C_FLAGS "-m32" CACHE STRING "C compiler flags" FORCE)
|
||||||
|
set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "C++ compiler flags" FORCE)
|
||||||
|
|
||||||
|
set(LIB32 /usr/lib) # Fedora
|
||||||
|
|
||||||
|
if(EXISTS /usr/lib32)
|
||||||
|
set(LIB32 /usr/lib32) # Arch, Solus
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE)
|
||||||
|
set(CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE)
|
||||||
|
|
||||||
|
# this is probably unlikely to be needed, but just in case
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE)
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE)
|
||||||
|
set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE)
|
||||||
|
|
||||||
|
# on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have
|
||||||
|
# to include the regular system .pc files as well (at the end), because some
|
||||||
|
# are not always present in the 32 bit directory
|
||||||
|
if(EXISTS ${LIB32}/pkgconfig)
|
||||||
|
set(ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig)
|
||||||
|
endiF()
|
|
@ -0,0 +1,3 @@
|
||||||
|
set_and_check(CMOCKA_INLUDE_DIR @PROJECT_SOURCE_DIR@/include)
|
||||||
|
set_and_check(CMOCKA_LIBRARY @PROJECT_BINARY_DIR@/src/@CMOCKA_LIBRARY_NAME@)
|
||||||
|
set_and_check(CMOCKA_LIBRARIES @PROJECT_BINARY_DIR@/src/@CMOCKA_LIBRARY_NAME@)
|
|
@ -0,0 +1,11 @@
|
||||||
|
# cmocka pkg-config source file
|
||||||
|
|
||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||||
|
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||||
|
|
||||||
|
Name: @PROJECT_NAME@
|
||||||
|
Description: The cmocka unit testing library
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
Libs: -L${libdir} -lcmocka
|
||||||
|
Cflags: -I${includedir}
|
|
@ -0,0 +1,173 @@
|
||||||
|
/* Name of package */
|
||||||
|
#cmakedefine PACKAGE "${PROJECT_NAME}"
|
||||||
|
|
||||||
|
/* Version number of package */
|
||||||
|
#cmakedefine VERSION "${PROJECT_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 <io.h> header file. */
|
||||||
|
#cmakedefine HAVE_IO_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 <time.h> header file. */
|
||||||
|
#cmakedefine HAVE_TIME_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
|
#cmakedefine HAVE_UNISTD_H 1
|
||||||
|
|
||||||
|
/**************************** STRUCTS ****************************/
|
||||||
|
|
||||||
|
#cmakedefine HAVE_STRUCT_TIMESPEC 1
|
||||||
|
|
||||||
|
/***************************** TYPES *****************************/
|
||||||
|
|
||||||
|
#cmakedefine HAVE_UINTPTR_T 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 `snprintf' function. */
|
||||||
|
#cmakedefine HAVE_SNPRINTF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `_snprintf' function. */
|
||||||
|
#cmakedefine HAVE__SNPRINTF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `_snprintf_s' function. */
|
||||||
|
#cmakedefine HAVE__SNPRINTF_S 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vsnprintf' function. */
|
||||||
|
#cmakedefine HAVE_VSNPRINTF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `_vsnprintf' function. */
|
||||||
|
#cmakedefine HAVE__VSNPRINTF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `_vsnprintf_s' function. */
|
||||||
|
#cmakedefine HAVE__VSNPRINTF_S 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 `siglongjmp' function. */
|
||||||
|
#cmakedefine HAVE_SIGLONGJMP 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
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strsignal' function. */
|
||||||
|
#cmakedefine HAVE_STRSIGNAL 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `clock_gettime' function. */
|
||||||
|
#cmakedefine HAVE_CLOCK_GETTIME 1
|
||||||
|
|
||||||
|
/**************************** OPTIONS ****************************/
|
||||||
|
|
||||||
|
/* Check if we have TLS support with GCC */
|
||||||
|
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
|
||||||
|
|
||||||
|
/* Check if we have TLS support with MSVC */
|
||||||
|
#cmakedefine HAVE_MSVC_THREAD_LOCAL_STORAGE 1
|
||||||
|
|
||||||
|
/* Check if we have CLOCK_REALTIME for clock_gettime() */
|
||||||
|
#cmakedefine HAVE_CLOCK_REALTIME 1
|
||||||
|
|
||||||
|
/*************************** 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
|
|
@ -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.
|
|
@ -0,0 +1,156 @@
|
||||||
|
#define LargestIntegralType unsigned long long
|
||||||
|
|
||||||
|
|
||||||
|
void _assert_true(const LargestIntegralType result,
|
||||||
|
const char* const expression,
|
||||||
|
const char * const file, const int line)
|
||||||
|
{
|
||||||
|
if (!result) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_int_equal(
|
||||||
|
const LargestIntegralType a, const LargestIntegralType b,
|
||||||
|
const char * const file, const int line)
|
||||||
|
{
|
||||||
|
if (a != b) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_int_not_equal(
|
||||||
|
const LargestIntegralType a, const LargestIntegralType b,
|
||||||
|
const char * const file, const int line)
|
||||||
|
{
|
||||||
|
if (a == b) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_return_code(const LargestIntegralType result,
|
||||||
|
size_t rlen,
|
||||||
|
const LargestIntegralType error,
|
||||||
|
const char * const expression,
|
||||||
|
const char * const file,
|
||||||
|
const int line)
|
||||||
|
{
|
||||||
|
if (result != 0) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_string_equal(const char * const a, const char * const b,
|
||||||
|
const char * const file, const int line)
|
||||||
|
{
|
||||||
|
char ch;
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
__coverity_weak_guard_sink__(a, b);
|
||||||
|
__coverity_weak_guard_sink__(b, a);
|
||||||
|
|
||||||
|
ch = *((char *)a);
|
||||||
|
ch = *((char *)b);
|
||||||
|
|
||||||
|
if (cmp != 0) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_string_not_equal(const char * const a, const char * const b,
|
||||||
|
const char *file, const int line)
|
||||||
|
{
|
||||||
|
char ch;
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
__coverity_weak_guard_sink__(a, b);
|
||||||
|
__coverity_weak_guard_sink__(b, a);
|
||||||
|
|
||||||
|
ch = *((char *)a);
|
||||||
|
ch = *((char *)b);
|
||||||
|
|
||||||
|
if (cmp == 0) {
|
||||||
|
__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)
|
||||||
|
{
|
||||||
|
unsigned char ch;
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
__coverity_weak_guard_sink__(a, b);
|
||||||
|
__coverity_weak_guard_sink__(b, a);
|
||||||
|
|
||||||
|
ch = *((unsigned char *)a);
|
||||||
|
ch = *((unsigned char *)b);
|
||||||
|
|
||||||
|
if (cmp != 0) {
|
||||||
|
__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)
|
||||||
|
{
|
||||||
|
unsigned char ch;
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
__coverity_weak_guard_sink__(a, b);
|
||||||
|
__coverity_weak_guard_sink__(b, a);
|
||||||
|
|
||||||
|
ch = *((unsigned char *)a);
|
||||||
|
ch = *((unsigned char *)b);
|
||||||
|
|
||||||
|
if (cmp == 0) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_in_range(
|
||||||
|
const LargestIntegralType value, const LargestIntegralType minimum,
|
||||||
|
const LargestIntegralType maximum, const char* const file, const int line)
|
||||||
|
{
|
||||||
|
if (value < minimum || value > maximum) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert_not_in_range(
|
||||||
|
const LargestIntegralType value, const LargestIntegralType minimum,
|
||||||
|
const LargestIntegralType maximum, const char* const file, const int line)
|
||||||
|
{
|
||||||
|
if (value > minimum && value < maximum) {
|
||||||
|
__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)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < number_of_values; i++) {
|
||||||
|
if (value == values[i]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__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)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < number_of_values; i++) {
|
||||||
|
if (value == values[i]) {
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
/* Functions to help coverity do static analysis on cmocka */
|
||||||
|
void exit_test(const int quit_application)
|
||||||
|
{
|
||||||
|
__coverity_panic__();
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
#
|
||||||
|
# Build the documentation
|
||||||
|
#
|
||||||
|
if (${CMAKE_VERSION} VERSION_GREATER "3.8.99")
|
||||||
|
|
||||||
|
find_package(Doxygen)
|
||||||
|
|
||||||
|
if (DOXYGEN_FOUND)
|
||||||
|
set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
set(DOXYGEN_PROJECT_NUMBER ${PROJECT_VERSION})
|
||||||
|
set(DOXYGEN_PROJECT_BRIEF "Unit testing library with mock support")
|
||||||
|
|
||||||
|
set(DOXYGEN_TAB_SIZE 4)
|
||||||
|
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
|
||||||
|
set(DOXYGEN_MARKDOWN_SUPPORT YES)
|
||||||
|
|
||||||
|
set(DOXYGEN_PREDEFINED DOXYGEN
|
||||||
|
CMOCKA_PRINTF_ATTRIBUTE(x,y))
|
||||||
|
|
||||||
|
set(DOXYGEN_EXCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/that_style)
|
||||||
|
set(DOXYGEN_HTML_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/that_style/header.html)
|
||||||
|
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${CMAKE_CURRENT_SOURCE_DIR}/that_style/that_style.css)
|
||||||
|
set(DOXYGEN_HTML_EXTRA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/nav_edge_left.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/nav_edge_right.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/nav_edge_inter.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/sync_off.png
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/sync_on.png
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/splitbar_handle.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/doc.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/mag_glass.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/folderclosed.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/folderopen.svg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/that_style/js/striped_bg.js)
|
||||||
|
|
||||||
|
set(_doxyfile_template "${CMAKE_BINARY_DIR}/CMakeDoxyfile.in")
|
||||||
|
set(_target_doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.docs")
|
||||||
|
configure_file("${_doxyfile_template}" "${_target_doxyfile}")
|
||||||
|
|
||||||
|
doxygen_add_docs(docs
|
||||||
|
${cmocka-library_SOURCE_DIR}
|
||||||
|
${cmocka-header_SOURCE_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
endif(DOXYGEN_FOUND)
|
||||||
|
|
||||||
|
endif() # CMAKE_VERSION
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
|
||||||
|
@mainpage
|
||||||
|
|
||||||
|
This is the online reference for developing with the cmocka library. It
|
||||||
|
documents the cmocka C API.
|
||||||
|
|
||||||
|
cmocka is an elegant unit testing framework for C with support for mock
|
||||||
|
objects. It only requires the standard C library, works on a lot of platforms
|
||||||
|
(including embedded) and with different compilers.
|
||||||
|
|
||||||
|
http://cmocka.org/
|
||||||
|
|
||||||
|
@section main-features Features
|
||||||
|
|
||||||
|
Tests written with cmocka 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:
|
||||||
|
|
||||||
|
- Support for mock objects.
|
||||||
|
- Test fixtures.
|
||||||
|
- Only requires a C library
|
||||||
|
- Exception handling for signals (SIGSEGV, SIGILL, ...)
|
||||||
|
- No use of fork()
|
||||||
|
- Very well tested
|
||||||
|
- Testing of memory leaks, buffer overflows and underflows.
|
||||||
|
- A set of assert macros.
|
||||||
|
- Several supported output formats (stdout, TAP, JUnit XML, Subunit)
|
||||||
|
- License: Apache License 2.0
|
||||||
|
|
||||||
|
@section main-test A cmocka test
|
||||||
|
|
||||||
|
Test cases are functions with the signature void function(void **state). 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 <stdint.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 struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(null_test_success),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
||||||
|
@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 an API to easily mock code.
|
||||||
|
|
||||||
|
Check out the examples <a href="https://git.cryptomilk.org/projects/cmocka.git/tree/example/mock">here</a>.
|
||||||
|
|
||||||
|
@section main-embedded Embedded platforms
|
||||||
|
|
||||||
|
It is possible that some embedded platforms do not provide definitions for
|
||||||
|
required types or that the guards to protect them are not defined. To address
|
||||||
|
this issue you can create a header file name 'cmocka_platform.h' with the
|
||||||
|
required types and definitions. After that point cmake to the include directory
|
||||||
|
using:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
cmake -DCMOCKA_PLATFORM_INCLUDE=/home/compiler/my/include_directory ..
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
@section main-threads Threading
|
||||||
|
|
||||||
|
cmocka is not fully thread safe and it is not the goal of it to be it. We have
|
||||||
|
several global variables to track test states. They are marked as thread local
|
||||||
|
but it is possible that you still run into issues. However if you use cmocka
|
||||||
|
for writing tests in an application which uses threads, you can set the
|
||||||
|
following envionment variable:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
CMOCKA_TEST_ABORT='1' ./my_threading_test
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
With this environment variable set to '1', cmocka will call <tt>abort()</tt> if
|
||||||
|
a test fails.
|
||||||
|
|
||||||
|
@section main-output Output formats
|
||||||
|
|
||||||
|
By default, cmocka prints human-readable test output to stderr. It is
|
||||||
|
possible to configure several other output formats. The configuration is
|
||||||
|
done using the <tt>CMOCKA_MESSAGE_OUTPUT</tt> environment variable. The
|
||||||
|
supported values are:
|
||||||
|
- <tt>STDOUT</tt> for the default standard output printer
|
||||||
|
- <tt>SUBUNIT</tt> for subunit output
|
||||||
|
- <tt>TAP</tt> for Test Anything Protocol (TAP) output
|
||||||
|
- <tt>XML</tt> for JUnit XML format
|
||||||
|
The case doesn't matter.
|
||||||
|
|
||||||
|
The XML output goes to stderr by default. If the environment variable
|
||||||
|
<tt>CMOCKA_XML_FILE</tt> exists and the file specified by this variable
|
||||||
|
doesn't exist yet, then cmocka will put the output to this file. Note
|
||||||
|
that if you are have several groups you should set <tt>CMOCKA_XML_FILE</tt>
|
||||||
|
to <tt>CMOCKA_XML_FILE=cm_%%g.xml</tt>. In this %g will be replaced by
|
||||||
|
the group_name of the test and a file will be created for each group,
|
||||||
|
othwerwise all groups will be printed into the same file.
|
||||||
|
|
||||||
|
*/
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Jan-Lukas Wynen
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,22 @@
|
||||||
|
# that style
|
||||||
|
A plain, more modern HTML style for Doxygen
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- Doxygen (tested with version 1.8.13)
|
||||||
|
- *optional*: a sass/scss compiler if you want to modify the style
|
||||||
|
|
||||||
|
## Simple usage
|
||||||
|
Tell Doxygen about the files for that style as shown in [doxyfile.conf](doxyfile.conf). You might need to adjust the
|
||||||
|
paths depending on where you installed that style.
|
||||||
|
When you run Doxygen, all files are copied into to generated HTML folder. So you don't need to keep the originals around
|
||||||
|
unless you want to re-generate the documentation.
|
||||||
|
|
||||||
|
## Advanced
|
||||||
|
that style uses a custom javascript to hack some nice stripes into some tables. It has to be loaded from HTML. Hence you need
|
||||||
|
to use the provided custom header. Since its default content may change when Doxygen is updated, there might be syntax error in
|
||||||
|
the generated HTML. If this is the case, you can remove the custom header (adjust your doxyfile.conf). This has no
|
||||||
|
disadvantages other than removing the stripes.
|
||||||
|
|
||||||
|
[that_style.css](that_style.css) was generated from the scss files in the folder [sass](sass). If you want to change the style,
|
||||||
|
use those files in order to have better control. For instance, you can easily change most colors by modifying the variables
|
||||||
|
in the beginning of [that_style.scss](sass/that_style.scss).
|
|
@ -0,0 +1,56 @@
|
||||||
|
<!-- HTML header for doxygen 1.8.13-->
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||||
|
<meta name="generator" content="Doxygen $doxygenversion"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||||
|
<!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
|
||||||
|
<!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
|
||||||
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
||||||
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||||
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||||
|
$treeview
|
||||||
|
$search
|
||||||
|
$mathjax
|
||||||
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||||
|
<script src="$relpath^striped_bg.js"></script>
|
||||||
|
$extrastylesheet
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||||
|
|
||||||
|
<!--BEGIN TITLEAREA-->
|
||||||
|
<div id="titlearea">
|
||||||
|
<table cellspacing="0" cellpadding="0">
|
||||||
|
<tbody>
|
||||||
|
<tr style="height: 56px;">
|
||||||
|
<!--BEGIN PROJECT_LOGO-->
|
||||||
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
||||||
|
<!--END PROJECT_LOGO-->
|
||||||
|
<!--BEGIN PROJECT_NAME-->
|
||||||
|
<td id="projectalign" style="padding-left: 0.5em;">
|
||||||
|
<div id="projectname">$projectname
|
||||||
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">$projectnumber</span><!--END PROJECT_NUMBER-->
|
||||||
|
</div>
|
||||||
|
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
||||||
|
</td>
|
||||||
|
<!--END PROJECT_NAME-->
|
||||||
|
<!--BEGIN !PROJECT_NAME-->
|
||||||
|
<!--BEGIN PROJECT_BRIEF-->
|
||||||
|
<td style="padding-left: 0.5em;">
|
||||||
|
<div id="projectbrief">$projectbrief</div>
|
||||||
|
</td>
|
||||||
|
<!--END PROJECT_BRIEF-->
|
||||||
|
<!--END !PROJECT_NAME-->
|
||||||
|
<!--BEGIN DISABLE_INDEX-->
|
||||||
|
<!--BEGIN SEARCHENGINE-->
|
||||||
|
<td>$searchbox</td>
|
||||||
|
<!--END SEARCHENGINE-->
|
||||||
|
<!--END DISABLE_INDEX-->
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--END TITLEAREA-->
|
||||||
|
<!-- end header part -->
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="24"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 6.3499999 5.8208335"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
sodipodi:docname="doc.svg"
|
||||||
|
inkscape:version="0.92.1 r">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="11.139212"
|
||||||
|
inkscape:cy="14.811193"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:showpageshadow="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-291.17915)">
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#4d4d4d;stroke-width:0.26458329;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="M 3.315043,291.8406 H 1.4552083 v 4.49792 h 3.1749999 v -3.10055 z"
|
||||||
|
id="path5095"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#4d4d4d;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 3.1837239,291.84114 v 1.71186 h 1.4472656 v -0.31418 H 3.4473958 v -1.39768 z"
|
||||||
|
id="path5128"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect5132"
|
||||||
|
width="2.1166668"
|
||||||
|
height="0.26458332"
|
||||||
|
x="1.8520833"
|
||||||
|
y="293.82498" />
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect5136"
|
||||||
|
width="1.0583334"
|
||||||
|
height="0.26458332"
|
||||||
|
x="1.8520832"
|
||||||
|
y="294.35416" />
|
||||||
|
<rect
|
||||||
|
y="294.88333"
|
||||||
|
x="1.8520832"
|
||||||
|
height="0.26458332"
|
||||||
|
width="1.8520833"
|
||||||
|
id="rect5138"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect4543"
|
||||||
|
width="1.5875"
|
||||||
|
height="0.26458332"
|
||||||
|
x="1.8520832"
|
||||||
|
y="295.41248" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.5 KiB |
|
@ -0,0 +1,77 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="24"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 6.3499998 5.8208335"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.1 r"
|
||||||
|
sodipodi:docname="folderclosed.svg"
|
||||||
|
inkscape:export-filename="/home/jl/Prog/doxygen_style/folderclosed.png"
|
||||||
|
inkscape:export-xdpi="96"
|
||||||
|
inkscape:export-ydpi="96">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="51.113139"
|
||||||
|
inkscape:cx="7.7057751"
|
||||||
|
inkscape:cy="12.584171"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:snap-global="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:showpageshadow="false"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:measure-start="0,0"
|
||||||
|
inkscape:measure-end="0,0" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-291.17915)">
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.26458332;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke fill markers;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 0.52916667,292.2374 -0.26458334,0.52925 v 3.43958 H 4.7625001 v -3.43958 H 2.38125 L 2.1166667,292.2374 Z"
|
||||||
|
id="rect4498"
|
||||||
|
sodipodi:nodetypes="cccccccc" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.66145831;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="M 2.9104167,292.76665 2.38125,293.56034 H 0.26458333 v 0.26464 H 2.38125 l 0.5291667,-0.79375 h 1.8520834 v -0.26458 z"
|
||||||
|
id="rect4500"
|
||||||
|
sodipodi:nodetypes="ccccccccc" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.4 KiB |
|
@ -0,0 +1,83 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="24"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 6.3499998 5.8208335"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.1 r"
|
||||||
|
sodipodi:docname="folderopen.svg"
|
||||||
|
inkscape:export-filename="/home/jl/Prog/doxygen_style/folderopen.png"
|
||||||
|
inkscape:export-xdpi="96"
|
||||||
|
inkscape:export-ydpi="96">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="43.725861"
|
||||||
|
inkscape:cx="8.2043861"
|
||||||
|
inkscape:cy="13.464183"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:snap-global="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:showpageshadow="false"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:measure-start="0,0"
|
||||||
|
inkscape:measure-end="0,0" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-291.17915)">
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.66145831;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 0.52916667,292.23748 -0.26458334,0.52917 v 3.43958 H 4.762461 l 7.8e-5,-3.43958 H 2.38125 l -0.2645833,-0.52917 z"
|
||||||
|
id="path5228"
|
||||||
|
sodipodi:nodetypes="cccccccc" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path5279"
|
||||||
|
d="M 1.0583333,293.5604 H 5.55625 L 4.7625,296.20603 H 0.26458333 Z"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ececec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.66145831;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
sodipodi:nodetypes="ccccc" />
|
||||||
|
<path
|
||||||
|
sodipodi:nodetypes="ccccccc"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path5234"
|
||||||
|
d="M 1.0583333,294.35415 H 3.175 l 0.5291667,-0.52917 H 5.55625 L 4.7625,296.20603 H 0.26458333 Z"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.66145831;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 4.1 KiB |
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="22"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 5.8208332 5.8208335"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.1 r"
|
||||||
|
sodipodi:docname="mag_glass.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="8.961936"
|
||||||
|
inkscape:cy="10.205344"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:showpageshadow="false"
|
||||||
|
inkscape:snap-bbox="false"
|
||||||
|
inkscape:bbox-nodes="true"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:snap-global="false" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-291.17915)">
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.99999988;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="M 6.9101562 2.4082031 C 3.1105656 2.4082031 -5.9211895e-16 5.5081643 0 9.3027344 C 0 13.097342 3.1105656 16.197266 6.9101562 16.197266 C 8.2869348 16.197266 9.5698699 15.787508 10.650391 15.087891 L 15.162109 19.587891 L 16.636719 18.115234 L 12.214844 13.707031 C 13.214837 12.510659 13.818359 10.974238 13.818359 9.3027344 C 13.818359 5.5081643 10.709747 2.4082031 6.9101562 2.4082031 z M 6.9101562 4.9101562 C 9.3624717 4.9101562 11.324219 6.8631249 11.324219 9.3027344 C 11.324219 11.742382 9.3624717 13.695312 6.9101562 13.695312 C 4.4578408 13.695312 2.5019531 11.742382 2.5019531 9.3027344 C 2.5019531 6.8631249 4.4578408 4.9101562 6.9101562 4.9101562 z "
|
||||||
|
transform="matrix(0.26458333,0,0,0.26458333,0,291.17915)"
|
||||||
|
id="rect4524" />
|
||||||
|
<path
|
||||||
|
transform="matrix(0.99422295,0,0,0.68955299,-0.83134947,91.755588)"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.63466448;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
inkscape:transform-center-y="0.25905895"
|
||||||
|
d="m 5.6074138,294.49889 -1.0836583,-1.87695 2.1673165,0 z"
|
||||||
|
id="path4491" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.8 KiB |
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="10.53333"
|
||||||
|
height="32"
|
||||||
|
viewBox="0 0 9.8749964 30"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.92.1 r"
|
||||||
|
sodipodi:docname="nav_edge_inter.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="8.6823304"
|
||||||
|
inkscape:cy="16.225639"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:snap-bbox="true"
|
||||||
|
inkscape:bbox-paths="false"
|
||||||
|
inkscape:bbox-nodes="true"
|
||||||
|
inkscape:snap-bbox-edge-midpoints="true"
|
||||||
|
inkscape:object-nodes="true"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-1022.3622)">
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 0,1022.3622 v 15 15 l 8,-15 z"
|
||||||
|
id="path4143"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#333333;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.9375px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 1.2910156,1022.3496 -0.82421872,0.4473 7.87890622,14.5527 -7.87890622,14.5527 0.82421872,0.4473 8.1210938,-15 z"
|
||||||
|
id="path5240"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.8 KiB |
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="8.5333338"
|
||||||
|
height="32"
|
||||||
|
viewBox="0 0 8.0000001 30"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.92.1 r"
|
||||||
|
sodipodi:docname="nav_edge_left.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="5.3721385"
|
||||||
|
inkscape:cy="14.16429"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:snap-bbox="true"
|
||||||
|
inkscape:bbox-paths="false"
|
||||||
|
inkscape:bbox-nodes="false"
|
||||||
|
inkscape:snap-bbox-edge-midpoints="false"
|
||||||
|
inkscape:object-nodes="true"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-1022.3622)">
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:6;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="M 0 0 L 0 32 L 8.5332031 16 L 0 0 z "
|
||||||
|
transform="matrix(0.93749998,0,0,0.93749998,0,1022.3622)"
|
||||||
|
id="rect4586" />
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 0,1022.3622 v 15 15 l 8,-15 z"
|
||||||
|
id="path4143"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="8"
|
||||||
|
height="30"
|
||||||
|
viewBox="0 0 8.0000001 30"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
sodipodi:docname="nav_edge.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="5.3721385"
|
||||||
|
inkscape:cy="14.16429"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:snap-bbox="true"
|
||||||
|
inkscape:bbox-paths="false"
|
||||||
|
inkscape:bbox-nodes="false"
|
||||||
|
inkscape:snap-bbox-edge-midpoints="false"
|
||||||
|
inkscape:object-nodes="true"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-1022.3622)">
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 0,1022.3622 0,15 0,15 8,-15 -8,-15 z"
|
||||||
|
id="path4143"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
d="m 1e-8,1022.3622 7.99999999,15 0,-15 -8,0 z m 7.99999999,15 -8,15 8,0 0,-15 z"
|
||||||
|
id="rect4136"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1,120 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="6"
|
||||||
|
height="9"
|
||||||
|
viewBox="0 0 1.5875 2.3812501"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.1 r"
|
||||||
|
sodipodi:docname="splitbar_handle.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="8.7681488"
|
||||||
|
inkscape:cy="-2.7929517"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:showpageshadow="false"
|
||||||
|
showguides="false"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1357"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1">
|
||||||
|
<inkscape:grid
|
||||||
|
type="xygrid"
|
||||||
|
id="grid4487" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-294.61873)">
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect4485"
|
||||||
|
width="0.26458335"
|
||||||
|
height="0.26458332"
|
||||||
|
x="0.26458332"
|
||||||
|
y="294.8833" />
|
||||||
|
<rect
|
||||||
|
y="294.8833"
|
||||||
|
x="1.0583333"
|
||||||
|
height="0.26458332"
|
||||||
|
width="0.26458335"
|
||||||
|
id="rect4489"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||||
|
<rect
|
||||||
|
y="295.41248"
|
||||||
|
x="0.26458329"
|
||||||
|
height="0.26458332"
|
||||||
|
width="0.26458335"
|
||||||
|
id="rect4491"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect4493"
|
||||||
|
width="0.26458335"
|
||||||
|
height="0.26458332"
|
||||||
|
x="1.0583333"
|
||||||
|
y="295.41248" />
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect4495"
|
||||||
|
width="0.26458335"
|
||||||
|
height="0.26458332"
|
||||||
|
x="0.26458332"
|
||||||
|
y="295.94165" />
|
||||||
|
<rect
|
||||||
|
y="295.94165"
|
||||||
|
x="1.0583333"
|
||||||
|
height="0.26458332"
|
||||||
|
width="0.26458335"
|
||||||
|
id="rect4497"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||||
|
<rect
|
||||||
|
y="296.47079"
|
||||||
|
x="0.26458329"
|
||||||
|
height="0.26458332"
|
||||||
|
width="0.26458335"
|
||||||
|
id="rect4499"
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||||
|
<rect
|
||||||
|
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.52916664;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||||
|
id="rect4501"
|
||||||
|
width="0.26458335"
|
||||||
|
height="0.26458332"
|
||||||
|
x="1.0583333"
|
||||||
|
y="296.47079" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 483 B |
After Width: | Height: | Size: 488 B |
|
@ -0,0 +1,32 @@
|
||||||
|
// Adds extra CSS classes "even" and "odd" to .memberdecls to allow
|
||||||
|
// striped backgrounds.
|
||||||
|
function MemberDeclsStriper () {
|
||||||
|
var counter = 0;
|
||||||
|
|
||||||
|
this.stripe = function() {
|
||||||
|
$(".memberdecls tbody").children().each(function(i) {
|
||||||
|
|
||||||
|
// reset counter at every heading -> always start with even
|
||||||
|
if ($(this).is(".heading")) {
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add extra classes
|
||||||
|
if (counter % 2 == 1) {
|
||||||
|
$(this).addClass("odd");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(this).addClass("even");
|
||||||
|
}
|
||||||
|
|
||||||
|
// advance counter at every separator
|
||||||
|
// this is the only way to reliably detect which table rows belong together
|
||||||
|
if ($(this).is('[class^="separator"]')) {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute the function
|
||||||
|
$(document).ready(new MemberDeclsStriper().stripe);
|
|
@ -0,0 +1,57 @@
|
||||||
|
project(cmocka-examples C)
|
||||||
|
|
||||||
|
set_source_files_properties(calculator.c
|
||||||
|
allocate_module.c
|
||||||
|
assert_module.c
|
||||||
|
PROPERTIES
|
||||||
|
COMPILE_DEFINITIONS
|
||||||
|
UNIT_TESTING=1)
|
||||||
|
|
||||||
|
|
||||||
|
### The most simple test
|
||||||
|
add_cmocka_test(simple_test
|
||||||
|
SOURCES simple_test.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_OPTIONS ${DEFAULT_LINK_FLAGS}
|
||||||
|
LINK_LIBRARIES cmocka::cmocka)
|
||||||
|
add_cmocka_test_environment(simple_test)
|
||||||
|
|
||||||
|
### Allocate module test
|
||||||
|
add_cmocka_test(allocate_module_test
|
||||||
|
SOURCES allocate_module.c allocate_module_test.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_OPTIONS ${DEFAULT_LINK_FLAGS}
|
||||||
|
LINK_LIBRARIES cmocka::cmocka)
|
||||||
|
add_cmocka_test_environment(allocate_module_test)
|
||||||
|
|
||||||
|
set_tests_properties(allocate_module_test
|
||||||
|
PROPERTIES
|
||||||
|
WILL_FAIL 1)
|
||||||
|
|
||||||
|
### Assert macro test
|
||||||
|
add_cmocka_test(assert_macro_test
|
||||||
|
SOURCES assert_macro.c assert_macro_test.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_OPTIONS ${DEFAULT_LINK_FLAGS}
|
||||||
|
LINK_LIBRARIES cmocka::cmocka)
|
||||||
|
add_cmocka_test_environment(assert_macro_test)
|
||||||
|
|
||||||
|
set_tests_properties(assert_macro_test
|
||||||
|
PROPERTIES
|
||||||
|
WILL_FAIL 1)
|
||||||
|
|
||||||
|
### Assert module test
|
||||||
|
add_cmocka_test(assert_module_test
|
||||||
|
SOURCES assert_module.c assert_module_test.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_OPTIONS ${DEFAULT_LINK_FLAGS}
|
||||||
|
LINK_LIBRARIES cmocka::cmocka)
|
||||||
|
add_cmocka_test_environment(assert_module_test)
|
||||||
|
|
||||||
|
set_tests_properties(assert_module_test
|
||||||
|
PROPERTIES
|
||||||
|
WILL_FAIL 1)
|
||||||
|
|
||||||
|
if (NOT WIN32)
|
||||||
|
add_subdirectory(mock)
|
||||||
|
endif()
|
|
@ -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>
|
||||||
|
|
||||||
|
#ifdef 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);
|
||||||
|
}
|
|
@ -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(void);
|
||||||
|
extern void buffer_overflow(void);
|
||||||
|
extern void buffer_underflow(void);
|
||||||
|
|
||||||
|
/* 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 struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(leak_memory_test),
|
||||||
|
cmocka_unit_test(buffer_overflow_test),
|
||||||
|
cmocka_unit_test(buffer_underflow_test),
|
||||||
|
};
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
|
@ -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 struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(get_status_code_string_test),
|
||||||
|
cmocka_unit_test(string_to_status_code_test),
|
||||||
|
};
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -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(). */
|
||||||
|
#ifdef 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) --;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
|
@ -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 struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(increment_value_fail),
|
||||||
|
cmocka_unit_test(increment_value_assert),
|
||||||
|
cmocka_unit_test(decrement_value_fail),
|
||||||
|
};
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -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. */
|
||||||
|
#ifdef 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;
|
||||||
|
}
|
|
@ -0,0 +1,482 @@
|
||||||
|
/*
|
||||||
|
* 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, ...) CMOCKA_PRINTF_ATTRIBUTE(2, 3);
|
||||||
|
int example_test_printf(const char *format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
|
||||||
|
|
||||||
|
static 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_ptr(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_ptr(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_null(find_operator_function_by_string(0, NULL, "test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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_null(find_operator_function_by_string(
|
||||||
|
array_length(operator_functions), operator_functions, "test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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(
|
||||||
|
cast_ptr_to_largest_integral_type(
|
||||||
|
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 = NULL;
|
||||||
|
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_non_null(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) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_add),
|
||||||
|
cmocka_unit_test(test_subtract),
|
||||||
|
cmocka_unit_test(test_multiply),
|
||||||
|
cmocka_unit_test(test_divide),
|
||||||
|
cmocka_unit_test(test_divide_by_zero),
|
||||||
|
cmocka_unit_test(test_find_operator_function_by_string_null_functions),
|
||||||
|
cmocka_unit_test(test_find_operator_function_by_string_null_string),
|
||||||
|
cmocka_unit_test(test_find_operator_function_by_string_valid_null_functions),
|
||||||
|
cmocka_unit_test(test_find_operator_function_by_string_not_found),
|
||||||
|
cmocka_unit_test(test_find_operator_function_by_string_found),
|
||||||
|
cmocka_unit_test(test_perform_operation_null_args),
|
||||||
|
cmocka_unit_test(test_perform_operation_null_operator_functions),
|
||||||
|
cmocka_unit_test(test_perform_operation_null_number_of_intermediate_values),
|
||||||
|
cmocka_unit_test(test_perform_operation_null_intermediate_values),
|
||||||
|
cmocka_unit_test(test_perform_operation_no_arguments),
|
||||||
|
cmocka_unit_test(test_perform_operation_first_arg_not_integer),
|
||||||
|
cmocka_unit_test(test_perform_operation_unknown_operator),
|
||||||
|
cmocka_unit_test(test_perform_operation_missing_argument),
|
||||||
|
cmocka_unit_test(test_perform_operation_no_integer_after_operator),
|
||||||
|
cmocka_unit_test(test_perform_operation),
|
||||||
|
cmocka_unit_test(test_example_main_no_args),
|
||||||
|
cmocka_unit_test(test_example_main),
|
||||||
|
};
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# TODO Execute "$CMAKE_LINKER --help" and check for --wrap
|
||||||
|
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)" AND NOT APPLE)
|
||||||
|
add_subdirectory(chef_wrap)
|
||||||
|
add_subdirectory(uptime)
|
||||||
|
endif()
|
|
@ -0,0 +1,20 @@
|
||||||
|
project(cmocka-wrap-examples C)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${CMAKE_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMOCKA_PUBLIC_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(waiter_test_wrap waiter_test_wrap.c chef.c)
|
||||||
|
target_link_libraries(waiter_test_wrap cmocka::cmocka)
|
||||||
|
|
||||||
|
add_test(waiter_test_wrap ${CMAKE_CURRENT_BINARY_DIR}/waiter_test_wrap)
|
||||||
|
|
||||||
|
set_target_properties(waiter_test_wrap
|
||||||
|
PROPERTIES
|
||||||
|
LINK_FLAGS "-Wl,--wrap=chef_cook"
|
||||||
|
)
|
||||||
|
if (WIN32 OR MINGW OR CYGWIN)
|
||||||
|
set_tests_properties(waiter_test_wrap PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
|
||||||
|
endif (WIN32 OR MINGW OR CYGWIN)
|
|
@ -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!";
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
|
@ -0,0 +1,176 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 (c) Andreas Schneider <asn@cynapses.org>
|
||||||
|
* Jakub Hrozek <jakub.hrozek@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
#include "waiter_test_wrap.h"
|
||||||
|
#include "chef.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a mocked Chef object. A real Chef would look if he knows
|
||||||
|
* the dish in some kind of internal database and check his storage for
|
||||||
|
* ingredients. This chef simply retrieves this information from the test
|
||||||
|
* that is calling him.
|
||||||
|
*
|
||||||
|
* This object is also wrapped - if any code links with this file and is
|
||||||
|
* compiled with linker option --wrap chef_cook, any calls of that code to
|
||||||
|
* chef_cook will end up calling __wrap_chef_cook.
|
||||||
|
*
|
||||||
|
* If for any reason the wrapped function wanted to call the real chef_cook()
|
||||||
|
* function, it could do so by calling the special symbol __real_chef_cook().
|
||||||
|
*
|
||||||
|
* Please note that when setting return codes for the chef_cook function, we
|
||||||
|
* use this wrapper as a parameter for the will_return() macro, not the
|
||||||
|
* real function.
|
||||||
|
*
|
||||||
|
* A chef object would return:
|
||||||
|
* 0 - cooking dish went fine
|
||||||
|
* -1 - unknown dish
|
||||||
|
* -2 - ran out of ingredients for the dish
|
||||||
|
* any other error code -- unexpected error while cooking
|
||||||
|
*
|
||||||
|
* The return codes should be consistent between the real and mocked objects.
|
||||||
|
*/
|
||||||
|
int __wrap_chef_cook(const char *order, char **dish_out)
|
||||||
|
{
|
||||||
|
bool has_ingredients;
|
||||||
|
bool knows_dish;
|
||||||
|
char *dish;
|
||||||
|
|
||||||
|
check_expected_ptr(order);
|
||||||
|
|
||||||
|
knows_dish = mock_type(bool);
|
||||||
|
if (knows_dish == false) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
has_ingredients = mock_type(bool);
|
||||||
|
if (has_ingredients == false) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
dish = mock_ptr_type(char *);
|
||||||
|
*dish_out = strdup(dish);
|
||||||
|
if (*dish_out == NULL) return ENOMEM;
|
||||||
|
|
||||||
|
return mock_type(int);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Waiter return codes:
|
||||||
|
* 0 - success
|
||||||
|
* -1 - kitchen failed
|
||||||
|
* -2 - kitchen succeeded, but cooked a different food
|
||||||
|
*/
|
||||||
|
static int waiter_process(const char *order, char **dish)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv = chef_cook(order, dish);
|
||||||
|
if (rv != 0) {
|
||||||
|
fprintf(stderr, "Chef couldn't cook %s: %s\n",
|
||||||
|
order, chef_strerror(rv));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we received the dish we wanted from the kitchen */
|
||||||
|
if (strcmp(order, *dish) != 0) {
|
||||||
|
free(*dish);
|
||||||
|
*dish = NULL;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_order_hotdog(void **state)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
char *dish;
|
||||||
|
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
/* We expect the chef to receive an order for a hotdog */
|
||||||
|
expect_string(__wrap_chef_cook, order, "hotdog");
|
||||||
|
/* And we tell the test chef that ke knows how to cook a hotdog
|
||||||
|
* and has the ingredients
|
||||||
|
*/
|
||||||
|
will_return(__wrap_chef_cook, true);
|
||||||
|
will_return(__wrap_chef_cook, true);
|
||||||
|
/* The result will be a hotdog and the cooking process will succeed */
|
||||||
|
will_return(__wrap_chef_cook, cast_ptr_to_largest_integral_type("hotdog"));
|
||||||
|
will_return(__wrap_chef_cook, 0);
|
||||||
|
|
||||||
|
/* Test the waiter */
|
||||||
|
rv = waiter_process("hotdog", &dish);
|
||||||
|
|
||||||
|
/* We expect the cook to succeed cooking the hotdog */
|
||||||
|
assert_int_equal(rv, 0);
|
||||||
|
/* And actually receive one */
|
||||||
|
assert_string_equal(dish, "hotdog");
|
||||||
|
if (dish != NULL) {
|
||||||
|
free(dish);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_bad_dish(void **state)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
char *dish;
|
||||||
|
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
/* We expect the chef to receive an order for a hotdog */
|
||||||
|
expect_string(__wrap_chef_cook, order, "hotdog");
|
||||||
|
/* And we tell the test chef that ke knows how to cook a hotdog
|
||||||
|
* and has the ingredients
|
||||||
|
*/
|
||||||
|
will_return(__wrap_chef_cook, true);
|
||||||
|
will_return(__wrap_chef_cook, true);
|
||||||
|
/* The result will be a burger and the cooking process will succeed.
|
||||||
|
* We expect the waiter to handle the bad dish and return an error
|
||||||
|
* code
|
||||||
|
*/
|
||||||
|
will_return(__wrap_chef_cook, cast_ptr_to_largest_integral_type("burger"));
|
||||||
|
will_return(__wrap_chef_cook, 0);
|
||||||
|
|
||||||
|
/* Test the waiter */
|
||||||
|
rv = waiter_process("hotdog", &dish);
|
||||||
|
|
||||||
|
/* According to the documentation the waiter should return -2 now */
|
||||||
|
assert_int_equal(rv, -2);
|
||||||
|
/* And do not give the bad dish to the customer */
|
||||||
|
assert_null(dish);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_order_hotdog),
|
||||||
|
cmocka_unit_test(test_bad_dish),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
int __wrap_chef_cook(const char *order, char **dish_out);
|
|
@ -0,0 +1,20 @@
|
||||||
|
add_library(proc_uptime proc_uptime.c)
|
||||||
|
|
||||||
|
add_executable(uptime uptime.c)
|
||||||
|
target_compile_options(uptime PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
|
||||||
|
target_link_libraries(uptime proc_uptime)
|
||||||
|
set_property(TARGET
|
||||||
|
uptime
|
||||||
|
PROPERTY
|
||||||
|
LINK_FLAGS
|
||||||
|
"${DEFAULT_LINK_FLAGS}")
|
||||||
|
|
||||||
|
add_cmocka_test(test_uptime
|
||||||
|
SOURCES test_uptime.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_LIBRARIES cmocka::cmocka)
|
||||||
|
set_property(TARGET
|
||||||
|
test_uptime
|
||||||
|
PROPERTY
|
||||||
|
LINK_FLAGS
|
||||||
|
"${DEFAULT_LINK_FLAGS} -Wl,--wrap=uptime")
|
|
@ -0,0 +1,56 @@
|
||||||
|
The uptime mock example
|
||||||
|
=======================
|
||||||
|
|
||||||
|
This is a very simple example to explain the mocking feature of cmocka. It
|
||||||
|
implement the 'uptime' unix command in a very simple way to demonstrate how to
|
||||||
|
test the time calculation.
|
||||||
|
|
||||||
|
The problem with testing the uptime command is that /proc/uptime constantly
|
||||||
|
ticks. The result is random whenever you call the test. To actually test it
|
||||||
|
we need to make sure that we work with fixed values. The mocking features
|
||||||
|
of cmocka allows us to test it anyway!
|
||||||
|
|
||||||
|
Source files
|
||||||
|
------------
|
||||||
|
|
||||||
|
* *proc_uptime.c*: This implements the `uptime()` function reading and parsing
|
||||||
|
the /proc/uptime file.
|
||||||
|
* *uptime.c*: This is the actual uptime implementation, it calls
|
||||||
|
`calc_uptime()` to get a human readable string representation of the uptime.
|
||||||
|
This function calls `uptime()` from proc_uptime.c.
|
||||||
|
* *test_uptime.c*: This is the test with the mocking function for uptime().
|
||||||
|
|
||||||
|
Linking magic
|
||||||
|
-------------
|
||||||
|
|
||||||
|
The test is linked using:
|
||||||
|
|
||||||
|
ld --wrap=uptime
|
||||||
|
|
||||||
|
This replaces the orginal `uptime()` function which reads from `/proc/uptime`
|
||||||
|
with the mock function we implemented for testing `calc_uptime()`.
|
||||||
|
|
||||||
|
The mock function we implemented has a special name. It is called
|
||||||
|
`__wrap_uptime()`. All the symbols you want to mock (or replace) need to start
|
||||||
|
with the prefix `__wrap_`. So `ld --wrap=uptime` will rename the orignal
|
||||||
|
`uptime()` function to `__real_uptime()`. This means you can still reach the
|
||||||
|
original function using that name and call it e.g. from the wrap function.
|
||||||
|
The symbol `uptime` will be bound to `__wrap_uptime`.
|
||||||
|
|
||||||
|
You can find more details in the manpage: `man ld`
|
||||||
|
|
||||||
|
The uptime test
|
||||||
|
---------------
|
||||||
|
|
||||||
|
The code should be easy to understand. If you have a hard time following, there
|
||||||
|
are two ways to understand how things work.
|
||||||
|
|
||||||
|
You can find out details about symbol binding using:
|
||||||
|
|
||||||
|
LD_DEBUG=symbols ./example/uptime/uptime
|
||||||
|
LD_DEBUG=symbols ./example/uptime/test_uptime
|
||||||
|
|
||||||
|
You can also use a debugger to step through the code!
|
||||||
|
|
||||||
|
|
||||||
|
Have fun!
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "proc_uptime.h"
|
||||||
|
|
||||||
|
#define UPTIME_FILE "/proc/uptime"
|
||||||
|
|
||||||
|
int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs)
|
||||||
|
{
|
||||||
|
double up = 0;
|
||||||
|
double idle = 0;
|
||||||
|
char *savelocale = NULL;
|
||||||
|
char buf[1024] = {0};
|
||||||
|
ssize_t nread;
|
||||||
|
int fd = -1;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (uptime_path == NULL) {
|
||||||
|
uptime_path = UPTIME_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(uptime_path, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
nread = read(fd, buf, sizeof(buf));
|
||||||
|
close(fd);
|
||||||
|
if (nread < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
savelocale = strdup(setlocale(LC_NUMERIC, NULL));
|
||||||
|
if (savelocale == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setlocale(LC_NUMERIC, "C");
|
||||||
|
rc = sscanf(buf, "%lf %lf", &up, &idle);
|
||||||
|
setlocale(LC_NUMERIC, savelocale);
|
||||||
|
free(savelocale);
|
||||||
|
if (rc < 2) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uptime_secs != NULL) {
|
||||||
|
*uptime_secs = up;
|
||||||
|
}
|
||||||
|
if (idle_secs != NULL) {
|
||||||
|
*idle_secs = idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)up;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PROC_UPTIME_H
|
||||||
|
#define _PROC_UPTIME_H
|
||||||
|
|
||||||
|
int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs);
|
||||||
|
|
||||||
|
#endif /* _PROC_UPTIME_H */
|
|
@ -0,0 +1,185 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
#define UNIT_TESTING 1
|
||||||
|
#include "uptime.c"
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a mocked object!
|
||||||
|
*
|
||||||
|
* It is a reimplementation of the uptime() function you can find in
|
||||||
|
* proc_uptime.c.
|
||||||
|
*
|
||||||
|
* This function can be instrumeted by the test. We can tell it what
|
||||||
|
* we expect or should return.
|
||||||
|
*/
|
||||||
|
int __wrap_uptime(const char *uptime_path,
|
||||||
|
double *uptime_secs,
|
||||||
|
double *idle_secs);
|
||||||
|
int __wrap_uptime(const char *uptime_path,
|
||||||
|
double *uptime_secs,
|
||||||
|
double *idle_secs)
|
||||||
|
{
|
||||||
|
double up;
|
||||||
|
double idle;
|
||||||
|
|
||||||
|
/* Verify the passed value of the argument is correct */
|
||||||
|
check_expected_ptr(uptime_path);
|
||||||
|
|
||||||
|
/* Assign the return values */
|
||||||
|
up = mock_type(double);
|
||||||
|
idle = mock_type(double);
|
||||||
|
|
||||||
|
if (uptime_secs != NULL) {
|
||||||
|
*uptime_secs = up;
|
||||||
|
}
|
||||||
|
if (idle_secs != NULL) {
|
||||||
|
*idle_secs = idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)up;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_calc_uptime_minutes(void **state)
|
||||||
|
{
|
||||||
|
char *uptime_str = NULL;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
/* Make sure the passed 'in' argument is correct */
|
||||||
|
expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
|
||||||
|
|
||||||
|
/* We tell the uptime function what values it should return */
|
||||||
|
will_return(__wrap_uptime, 508.16);
|
||||||
|
will_return(__wrap_uptime, 72.23);
|
||||||
|
|
||||||
|
/* We call the function like we would do it normally */
|
||||||
|
uptime_str = calc_uptime();
|
||||||
|
|
||||||
|
/* Now lets check if the result is what we expect it to be */
|
||||||
|
assert_non_null(uptime_str);
|
||||||
|
assert_string_equal(uptime_str, "up 8 minutes");
|
||||||
|
|
||||||
|
free(uptime_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_calc_uptime_hour_minute(void **state)
|
||||||
|
{
|
||||||
|
char *uptime_str = NULL;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
/* Make sure the passed 'in' argument is correct */
|
||||||
|
expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
|
||||||
|
|
||||||
|
/* We tell the uptime function what values it should return */
|
||||||
|
will_return(__wrap_uptime, 3699.16);
|
||||||
|
will_return(__wrap_uptime, 4069.23);
|
||||||
|
|
||||||
|
/* We call the function like we would do it normally */
|
||||||
|
uptime_str = calc_uptime();
|
||||||
|
|
||||||
|
/* Now lets check if the result is what we expect it to be */
|
||||||
|
assert_non_null(uptime_str);
|
||||||
|
assert_string_equal(uptime_str, "up 1 hour, 1 minute");
|
||||||
|
|
||||||
|
free(uptime_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_calc_uptime_days_minutes(void **state)
|
||||||
|
{
|
||||||
|
char *uptime_str = NULL;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
/* Make sure the passed 'in' argument is correct */
|
||||||
|
expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
|
||||||
|
|
||||||
|
/* We tell the uptime function what values it should return */
|
||||||
|
will_return(__wrap_uptime, 259415.14);
|
||||||
|
will_return(__wrap_uptime, 262446.29);
|
||||||
|
|
||||||
|
/* We call the function like we would do it normally */
|
||||||
|
uptime_str = calc_uptime();
|
||||||
|
|
||||||
|
/* Now lets check if the result is what we expect it to be */
|
||||||
|
assert_non_null(uptime_str);
|
||||||
|
assert_string_equal(uptime_str, "up 3 days, 3 minutes");
|
||||||
|
|
||||||
|
free(uptime_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_calc_uptime_days_hours_minutes(void **state)
|
||||||
|
{
|
||||||
|
char *uptime_str = NULL;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
/* Make sure the passed 'in' argument is correct */
|
||||||
|
expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
|
||||||
|
|
||||||
|
/* We tell the uptime function what values it should return */
|
||||||
|
will_return(__wrap_uptime, 359415.14);
|
||||||
|
will_return(__wrap_uptime, 362446.29);
|
||||||
|
|
||||||
|
/* We call the function like we would do it normally */
|
||||||
|
uptime_str = calc_uptime();
|
||||||
|
|
||||||
|
/* Now lets check if the result is what we expect it to be */
|
||||||
|
assert_non_null(uptime_str);
|
||||||
|
assert_string_equal(uptime_str, "up 4 days, 3 hours, 50 minutes");
|
||||||
|
|
||||||
|
free(uptime_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_calc_uptime_null(void **state)
|
||||||
|
{
|
||||||
|
char *uptime_str = NULL;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
/* Make sure the passed 'in' argument is correct */
|
||||||
|
expect_string(__wrap_uptime, uptime_path, "/proc/uptime");
|
||||||
|
|
||||||
|
will_return(__wrap_uptime, -0.0);
|
||||||
|
will_return(__wrap_uptime, 0.1);
|
||||||
|
|
||||||
|
uptime_str = calc_uptime();
|
||||||
|
assert_null(uptime_str);
|
||||||
|
|
||||||
|
free(uptime_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_calc_uptime_minutes),
|
||||||
|
cmocka_unit_test(test_calc_uptime_hour_minute),
|
||||||
|
cmocka_unit_test(test_calc_uptime_days_minutes),
|
||||||
|
cmocka_unit_test(test_calc_uptime_days_hours_minutes),
|
||||||
|
cmocka_unit_test(test_calc_uptime_null),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 Andreas Scheider <asn@cryptomilk.org>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include "proc_uptime.h"
|
||||||
|
|
||||||
|
static char *calc_uptime(void)
|
||||||
|
{
|
||||||
|
uint32_t up_minutes, up_hours, up_days, up_weeks, up_years;
|
||||||
|
ssize_t pos = 0;
|
||||||
|
size_t comma = 0;
|
||||||
|
double uptime_secs, idle_secs;
|
||||||
|
char buf[1024] = {0};
|
||||||
|
int up;
|
||||||
|
|
||||||
|
up = uptime("/proc/uptime", &uptime_secs, &idle_secs);
|
||||||
|
if (up == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
up_years = ((uint32_t)uptime_secs / (60 * 60 * 24 * 365)) % 10;
|
||||||
|
up_weeks = ((uint32_t)uptime_secs / (60 * 60 * 24 * 7)) % 52;
|
||||||
|
up_days = ((uint32_t)uptime_secs / (60 * 60 * 24)) % 7;
|
||||||
|
|
||||||
|
pos += snprintf(buf + pos, sizeof(buf) - pos, "up ");
|
||||||
|
|
||||||
|
up_minutes = (uint32_t)uptime_secs / 60;
|
||||||
|
up_hours = up_minutes / 60;
|
||||||
|
up_hours = up_hours % 24;
|
||||||
|
up_minutes = up_minutes % 60;
|
||||||
|
|
||||||
|
if (up_years > 0) {
|
||||||
|
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||||
|
"%u %s",
|
||||||
|
up_years,
|
||||||
|
up_years > 1 ? "years" : "year");
|
||||||
|
comma++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up_weeks > 0) {
|
||||||
|
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||||
|
"%s%u %s",
|
||||||
|
comma > 0 ? ", " : "",
|
||||||
|
up_weeks,
|
||||||
|
up_weeks > 1 ? "weeks" : "week");
|
||||||
|
comma++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up_days > 0) {
|
||||||
|
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||||
|
"%s%u %s",
|
||||||
|
comma > 0 ? ", " : "",
|
||||||
|
up_days,
|
||||||
|
up_days > 1 ? "days" : "day");
|
||||||
|
comma++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up_hours > 0) {
|
||||||
|
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||||
|
"%s%u %s",
|
||||||
|
comma > 0 ? ", " : "",
|
||||||
|
up_hours,
|
||||||
|
up_hours > 1 ? "hours" : "hour");
|
||||||
|
comma++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up_minutes > 0 || (up_minutes == 0 && uptime_secs < 60)) {
|
||||||
|
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||||
|
"%s%u %s",
|
||||||
|
comma > 0 ? ", " : "",
|
||||||
|
up_minutes,
|
||||||
|
up_minutes != 1 ? "minutes" : "minute");
|
||||||
|
comma++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strdup(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef UNIT_TESTING
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char *uptime_str = NULL;
|
||||||
|
|
||||||
|
uptime_str = calc_uptime();
|
||||||
|
if (uptime_str == NULL) {
|
||||||
|
fprintf(stderr, "Failed to read uptime\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s\n", uptime_str);
|
||||||
|
|
||||||
|
free(uptime_str);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* UNIT_TESTING */
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdint.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 struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(null_test_success),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
project(cmocka-header C)
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
cmocka.h
|
||||||
|
cmocka_pbc.h
|
||||||
|
DESTINATION
|
||||||
|
${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
COMPONENT
|
||||||
|
${PROJECT_NAME})
|
||||||
|
|
||||||
|
if (WITH_CMOCKERY_SUPPORT)
|
||||||
|
install(FILES
|
||||||
|
cmockery/cmockery.h
|
||||||
|
cmockery/pbc.h
|
||||||
|
DESTINATION
|
||||||
|
${CMAKE_INSTALL_INCLUDEDIR}/cmockery
|
||||||
|
COMPONENT
|
||||||
|
${PROJECT_NAME})
|
||||||
|
endif()
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Luis Pabon, Jr.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Programming by Contract is a programming methodology
|
||||||
|
* which binds the caller and the function called to a
|
||||||
|
* contract. The contract is represented using Hoare Triple:
|
||||||
|
* {P} C {Q}
|
||||||
|
* where {P} is the precondition before executing command C,
|
||||||
|
* and {Q} is the postcondition.
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* http://en.wikipedia.org/wiki/Design_by_contract
|
||||||
|
* http://en.wikipedia.org/wiki/Hoare_logic
|
||||||
|
* http://dlang.org/dbc.html
|
||||||
|
*/
|
||||||
|
#ifndef CMOCKA_PBC_H_
|
||||||
|
#define CMOCKA_PBC_H_
|
||||||
|
|
||||||
|
#if defined(UNIT_TESTING) || defined (DEBUG)
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks caller responsibility against contract
|
||||||
|
*/
|
||||||
|
#define REQUIRE(cond) assert(cond)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks function reponsability against contract.
|
||||||
|
*/
|
||||||
|
#define ENSURE(cond) assert(cond)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* While REQUIRE and ENSURE apply to functions, INVARIANT
|
||||||
|
* applies to classes/structs. It ensures that intances
|
||||||
|
* of the class/struct are consistent. In other words,
|
||||||
|
* that the instance has not been corrupted.
|
||||||
|
*/
|
||||||
|
#define INVARIANT(invariant_fnc) do{ (invariant_fnc) } while (0);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define REQUIRE(cond) do { } while (0);
|
||||||
|
#define ENSURE(cond) do { } while (0);
|
||||||
|
#define INVARIANT(invariant_fnc) do{ } while (0);
|
||||||
|
|
||||||
|
#endif /* defined(UNIT_TESTING) || defined (DEBUG) */
|
||||||
|
#endif /* CMOCKA_PBC_H_ */
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
* 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_
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
# include <stdio.h> /* _snprintf */
|
||||||
|
# include <string.h> /* strtok_s */
|
||||||
|
|
||||||
|
# undef inline
|
||||||
|
# define inline __inline
|
||||||
|
|
||||||
|
# ifndef va_copy
|
||||||
|
# define va_copy(dest, src) (dest = src)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define strcasecmp _stricmp
|
||||||
|
# define strncasecmp _strnicmp
|
||||||
|
# define strtok_r strtok_s
|
||||||
|
|
||||||
|
# if defined(HAVE__SNPRINTF_S)
|
||||||
|
# undef snprintf
|
||||||
|
# define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
|
||||||
|
# else /* HAVE__SNPRINTF_S */
|
||||||
|
# if defined(HAVE__SNPRINTF)
|
||||||
|
# undef snprintf
|
||||||
|
# define snprintf _snprintf
|
||||||
|
# else /* HAVE__SNPRINTF */
|
||||||
|
# if !defined(HAVE_SNPRINTF)
|
||||||
|
# error "no snprintf compatible function found"
|
||||||
|
# endif /* HAVE_SNPRINTF */
|
||||||
|
# endif /* HAVE__SNPRINTF */
|
||||||
|
# endif /* HAVE__SNPRINTF_S */
|
||||||
|
|
||||||
|
# if defined(HAVE__VSNPRINTF_S)
|
||||||
|
# undef vsnprintf
|
||||||
|
# define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
|
||||||
|
# else /* HAVE__VSNPRINTF_S */
|
||||||
|
# if defined(HAVE__VSNPRINTF)
|
||||||
|
# undef vsnprintf
|
||||||
|
# define vsnprintf _vsnprintf
|
||||||
|
# else
|
||||||
|
# if !defined(HAVE_VSNPRINTF)
|
||||||
|
# error "No vsnprintf compatible function found"
|
||||||
|
# endif /* HAVE_VSNPRINTF */
|
||||||
|
# endif /* HAVE__VSNPRINTF */
|
||||||
|
# endif /* HAVE__VSNPRINTF_S */
|
||||||
|
# endif /* _MSC_VER */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Backwards compatibility with headers shipped with Visual Studio 2005 and
|
||||||
|
* earlier.
|
||||||
|
*/
|
||||||
|
WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
|
||||||
|
|
||||||
|
#ifndef PRIdS
|
||||||
|
# define PRIdS "Id"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIu64
|
||||||
|
# define PRIu64 "I64u"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIuMAX
|
||||||
|
# define PRIuMAX PRIu64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIxMAX
|
||||||
|
#define PRIxMAX "I64x"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIXMAX
|
||||||
|
#define PRIXMAX "I64X"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else /* _WIN32 */
|
||||||
|
|
||||||
|
#ifndef __PRI64_PREFIX
|
||||||
|
# if __WORDSIZE == 64
|
||||||
|
# define __PRI64_PREFIX "l"
|
||||||
|
# else
|
||||||
|
# define __PRI64_PREFIX "ll"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIdS
|
||||||
|
# define PRIdS "zd"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIu64
|
||||||
|
# define PRIu64 __PRI64_PREFIX "u"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIuMAX
|
||||||
|
# define PRIuMAX __PRI64_PREFIX "u"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIxMAX
|
||||||
|
#define PRIxMAX __PRI64_PREFIX "x"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRIXMAX
|
||||||
|
#define PRIXMAX __PRI64_PREFIX "X"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
/** 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_ */
|
|
@ -0,0 +1 @@
|
||||||
|
#include <cmocka.h>
|
|
@ -0,0 +1 @@
|
||||||
|
#include <cmocka_pbc.h>
|
|
@ -0,0 +1,60 @@
|
||||||
|
project('cmocka', 'c',
|
||||||
|
version : '1.1.5',
|
||||||
|
license : 'Apache-2.0')
|
||||||
|
|
||||||
|
cc = meson.get_compiler('c')
|
||||||
|
|
||||||
|
conf = configuration_data()
|
||||||
|
|
||||||
|
foreach hdr : ['assert.h', 'inttypes.h', 'io.h', 'malloc.h', 'memory.h',
|
||||||
|
'setjmp.h', 'signal.h', 'stdarg.h', 'stddef.h', 'stdint.h',
|
||||||
|
'stdio.h', 'stdlib.h', 'string.h', 'strings.h', 'sys/stat.h',
|
||||||
|
'sys/types.h', 'time.h', 'unistd.h']
|
||||||
|
conf.set('HAVE_@0@'.format(hdr.underscorify().to_upper()), cc.has_header(hdr))
|
||||||
|
endforeach
|
||||||
|
|
||||||
|
code = '''#include <time.h>
|
||||||
|
int a = sizeof(struct timespec);
|
||||||
|
'''
|
||||||
|
conf.set('HAVE_STRUCT_TIMESPEC', cc.compiles(code, name : 'struct timepec'))
|
||||||
|
|
||||||
|
foreach func: ['calloc', 'exit', 'fprintf', 'free', 'longjmp', 'siglongjmp',
|
||||||
|
'malloc', 'memcpy', 'memset', 'printf', 'setjmp', 'signal',
|
||||||
|
'strsignal', 'strcmp', 'clock_gettime']
|
||||||
|
conf.set('HAVE_@0@'.format(func.to_upper()), cc.has_function(func))
|
||||||
|
endforeach
|
||||||
|
|
||||||
|
code = '__thread int tls;'
|
||||||
|
conf.set('HAVE_GCC_THREAD_LOCAL_STORAGE', cc.compiles(code, name : '__thread'))
|
||||||
|
|
||||||
|
code = '''#include <time.h>
|
||||||
|
clockid_t t = CLOCK_REALTIME;'''
|
||||||
|
conf.set('HAVE_CLOCK_REALTIME', cc.compiles(code, name : 'CLOCK_REALTIME'))
|
||||||
|
|
||||||
|
configure_file(output : 'config.h', configuration : conf)
|
||||||
|
|
||||||
|
cmocka_includes = [include_directories('.'), include_directories('include')]
|
||||||
|
libcmocka = library('cmocka', 'src/cmocka.c',
|
||||||
|
c_args : ['-DHAVE_CONFIG_H'],
|
||||||
|
include_directories : cmocka_includes,
|
||||||
|
install : meson.is_subproject(),
|
||||||
|
override_options : ['c_std=gnu99'],
|
||||||
|
dependencies : [cc.find_library('rt', required : false)])
|
||||||
|
|
||||||
|
if meson.is_subproject()
|
||||||
|
cmocka_dep = declare_dependency(include_directories : cmocka_includes,
|
||||||
|
link_with : libcmocka)
|
||||||
|
else
|
||||||
|
install_headers('include/cmocka.h')
|
||||||
|
|
||||||
|
pkgconfig = import('pkgconfig')
|
||||||
|
pkgconfig.generate(libraries : [libcmocka],
|
||||||
|
version : meson.project_version(),
|
||||||
|
name : 'cmocka',
|
||||||
|
filebase : 'cmocka',
|
||||||
|
description : 'The cmocka unit testing library')
|
||||||
|
endif
|
||||||
|
|
||||||
|
if get_option('unit_testing')
|
||||||
|
subdir('tests')
|
||||||
|
endif
|
|
@ -0,0 +1 @@
|
||||||
|
option('unit_testing', type: 'boolean', value: false)
|
|
@ -0,0 +1,106 @@
|
||||||
|
project(cmocka-library C)
|
||||||
|
|
||||||
|
set(CMOCKA_PLATFORM_INCLUDE CACHE PATH "Path to include directory for cmocka_platform.h")
|
||||||
|
mark_as_advanced(CMOCKA_PLATFORM_INCLUDE)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
add_library(cmocka ${cmocka_SRCS})
|
||||||
|
|
||||||
|
target_include_directories(cmocka
|
||||||
|
PRIVATE
|
||||||
|
${CMOCKA_PLATFORM_INCLUDE}
|
||||||
|
${cmocka_BINARY_DIR}
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${cmocka-header_SOURCE_DIR}>
|
||||||
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
|
target_compile_options(cmocka
|
||||||
|
PRIVATE
|
||||||
|
${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
-DHAVE_CONFIG_H)
|
||||||
|
if (CMOCKA_PLATFORM_INCLUDE)
|
||||||
|
target_compile_options(cmocka
|
||||||
|
PRIVATE
|
||||||
|
-DCMOCKA_PLATFORM_INCLUDE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(cmocka PRIVATE ${CMOCKA_LINK_LIBRARIES})
|
||||||
|
set_property(TARGET
|
||||||
|
cmocka
|
||||||
|
PROPERTY
|
||||||
|
DEFINE_SYMBOL
|
||||||
|
CMOCKA_EXPORTS
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET
|
||||||
|
cmocka
|
||||||
|
PROPERTY
|
||||||
|
VERSION
|
||||||
|
${LIBRARY_VERSION}
|
||||||
|
)
|
||||||
|
set_property(TARGET
|
||||||
|
cmocka
|
||||||
|
PROPERTY
|
||||||
|
SOVERSION
|
||||||
|
${LIBRARY_SOVERSION})
|
||||||
|
|
||||||
|
set_property(TARGET
|
||||||
|
cmocka
|
||||||
|
PROPERTY
|
||||||
|
LINK_FLAGS
|
||||||
|
"${DEFAULT_LINK_FLAGS}")
|
||||||
|
|
||||||
|
add_library(cmocka::cmocka ALIAS cmocka)
|
||||||
|
|
||||||
|
install(TARGETS cmocka
|
||||||
|
EXPORT cmocka-config
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
COMPONENT ${PROJECT_NAME})
|
||||||
|
|
||||||
|
install(EXPORT cmocka-config
|
||||||
|
NAMESPACE cmocka::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka)
|
||||||
|
|
||||||
|
if (UNIT_TESTING)
|
||||||
|
# Internal library
|
||||||
|
add_library(cmocka-static STATIC ${cmocka_SRCS})
|
||||||
|
|
||||||
|
target_include_directories(cmocka-static
|
||||||
|
PRIVATE
|
||||||
|
${CMOCKA_PLATFORM_INCLUDE}
|
||||||
|
${cmocka_BINARY_DIR}
|
||||||
|
PUBLIC
|
||||||
|
${cmocka-header_SOURCE_DIR})
|
||||||
|
|
||||||
|
|
||||||
|
target_compile_options(cmocka-static
|
||||||
|
PRIVATE
|
||||||
|
${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
-DHAVE_CONFIG_H)
|
||||||
|
if (CMOCKA_PLATFORM_INCLUDE)
|
||||||
|
target_compile_options(cmocka-static
|
||||||
|
PRIVATE
|
||||||
|
-DCMOCKA_PLATFORM_INCLUDE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(cmocka-static PRIVATE ${CMOCKA_LINK_LIBRARIES})
|
||||||
|
|
||||||
|
add_library(cmocka::static ALIAS cmocka-static)
|
||||||
|
endif()
|
|
@ -0,0 +1,56 @@
|
||||||
|
LIBRARY cmocka
|
||||||
|
EXPORTS
|
||||||
|
_assert_double_equal
|
||||||
|
_assert_double_not_equal
|
||||||
|
_assert_float_equal
|
||||||
|
_assert_float_not_equal
|
||||||
|
_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_return_code
|
||||||
|
_assert_string_equal
|
||||||
|
_assert_string_not_equal
|
||||||
|
_assert_true
|
||||||
|
_check_expected
|
||||||
|
_cmocka_run_group_tests
|
||||||
|
_expect_any
|
||||||
|
_expect_check
|
||||||
|
_expect_function_call
|
||||||
|
_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
|
||||||
|
_function_called
|
||||||
|
_mock
|
||||||
|
_run_test
|
||||||
|
_run_tests
|
||||||
|
_skip
|
||||||
|
_test_calloc
|
||||||
|
_test_free
|
||||||
|
_test_malloc
|
||||||
|
_test_realloc
|
||||||
|
_will_return
|
||||||
|
cm_print_error
|
||||||
|
cmocka_set_message_output
|
||||||
|
cmocka_set_test_filter
|
||||||
|
cmocka_set_skip_filter
|
||||||
|
global_expect_assert_env
|
||||||
|
global_expecting_assert
|
||||||
|
global_last_failed_assert
|
||||||
|
mock_assert
|
||||||
|
print_error
|
||||||
|
print_message
|
||||||
|
vprint_error
|
||||||
|
vprint_message
|
|
@ -0,0 +1,267 @@
|
||||||
|
project(tests C)
|
||||||
|
|
||||||
|
set(TEST_EXCEPTION_HANDLER TRUE)
|
||||||
|
if (WIN32)
|
||||||
|
# FIXME: The exception handler doesn't work on Windows
|
||||||
|
set(TEST_EXCEPTION_HANDLER FALSE)
|
||||||
|
endif()
|
||||||
|
if (CMAKE_BUILD_TYPE)
|
||||||
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
||||||
|
if (CMAKE_BUILD_TYPE_LOWER STREQUAL "undefinedsanitizer")
|
||||||
|
set(TEST_EXCEPTION_HANDLER FALSE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMOCKA_TESTS
|
||||||
|
test_alloc
|
||||||
|
test_group_setup_assert
|
||||||
|
test_group_setup_fail
|
||||||
|
test_fixtures
|
||||||
|
test_group_fixtures
|
||||||
|
test_groups
|
||||||
|
test_float_macros
|
||||||
|
test_double_macros
|
||||||
|
test_assert_macros
|
||||||
|
test_assert_macros_fail
|
||||||
|
test_basics
|
||||||
|
test_skip
|
||||||
|
test_strmatch
|
||||||
|
test_setup_fail
|
||||||
|
test_ordering
|
||||||
|
test_ordering_fail
|
||||||
|
test_returns
|
||||||
|
test_returns_fail
|
||||||
|
test_string
|
||||||
|
test_wildcard
|
||||||
|
test_skip_filter
|
||||||
|
test_cmockery
|
||||||
|
)
|
||||||
|
|
||||||
|
if (TEST_EXCEPTION_HANDLER)
|
||||||
|
list(APPEND CMOCKA_TESTS test_exception_handler)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(_CMOCKA_TEST ${CMOCKA_TESTS})
|
||||||
|
add_cmocka_test(${_CMOCKA_TEST}
|
||||||
|
SOURCES ${_CMOCKA_TEST}.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_LIBRARIES cmocka::static
|
||||||
|
LINK_OPTIONS ${DEFAULT_LINK_FLAGS})
|
||||||
|
target_include_directories(${_CMOCKA_TEST} PRIVATE ${cmocka_BINARY_DIR})
|
||||||
|
|
||||||
|
add_cmocka_test_environment(${_CMOCKA_TEST})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
### Special Cases
|
||||||
|
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
|
||||||
|
set_source_files_properties(test_cmockery.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
### Exceptions
|
||||||
|
|
||||||
|
# test_skip
|
||||||
|
set_tests_properties(
|
||||||
|
test_skip
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ SKIPPED \\] test_check_skip"
|
||||||
|
)
|
||||||
|
|
||||||
|
# test_assert_macros_fail
|
||||||
|
set_tests_properties(
|
||||||
|
test_assert_macros_fail
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ FAILED \\] tests: 1 test"
|
||||||
|
)
|
||||||
|
|
||||||
|
# test_ordering ensure proper failures
|
||||||
|
set_tests_properties(
|
||||||
|
test_ordering_fail
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ FAILED \\] tests: 7 test"
|
||||||
|
)
|
||||||
|
|
||||||
|
# test_returns_fail ensure proper failures
|
||||||
|
set_tests_properties(
|
||||||
|
test_returns_fail
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ FAILED \\] alloc_tests: 3 test"
|
||||||
|
)
|
||||||
|
|
||||||
|
# test_exception_handler
|
||||||
|
if (TEST_EXCEPTION_HANDLER)
|
||||||
|
set_tests_properties(test_exception_handler
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"Test failed with exception")
|
||||||
|
endif (TEST_EXCEPTION_HANDLER)
|
||||||
|
|
||||||
|
set_tests_properties(
|
||||||
|
test_setup_fail
|
||||||
|
PROPERTIES
|
||||||
|
WILL_FAIL
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
set_tests_properties(
|
||||||
|
test_group_setup_assert
|
||||||
|
PROPERTIES
|
||||||
|
WILL_FAIL
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
set_tests_properties(
|
||||||
|
test_group_setup_fail
|
||||||
|
PROPERTIES
|
||||||
|
WILL_FAIL
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(test_setup_fail_1_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
|
||||||
|
add_cmocka_test_environment(test_setup_fail_1_failed)
|
||||||
|
set_tests_properties(
|
||||||
|
test_setup_fail_1_failed
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ ERROR \\] int_test_ignored"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test (test_setup_fail_1_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
|
||||||
|
add_cmocka_test_environment(test_setup_fail_1_passed)
|
||||||
|
set_tests_properties(
|
||||||
|
test_setup_fail_1_passed
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ PASSED \\] 1 test\\(s\\)."
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test (test_setup_fail_match_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
|
||||||
|
add_cmocka_test_environment(test_setup_fail_match_failed)
|
||||||
|
set_tests_properties(
|
||||||
|
test_setup_fail_match_failed
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ ERROR \\] int_test_ignored"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test (test_setup_fail_match_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
|
||||||
|
add_cmocka_test_environment(test_setup_fail_match_passed)
|
||||||
|
set_tests_properties(
|
||||||
|
test_setup_fail_match_passed
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
"\\[ OK \\] int_test_success"
|
||||||
|
)
|
||||||
|
|
||||||
|
### Output formats
|
||||||
|
|
||||||
|
# test output of success, failure, skip, fixture failure
|
||||||
|
set(OUTPUT_TESTS
|
||||||
|
test_basics
|
||||||
|
test_assert_macros_fail
|
||||||
|
test_groups
|
||||||
|
test_skip
|
||||||
|
test_setup_fail)
|
||||||
|
|
||||||
|
set(TEST_OUTPUT_FMTS
|
||||||
|
tap
|
||||||
|
subunit
|
||||||
|
xml)
|
||||||
|
|
||||||
|
set(test_basics_tap_out
|
||||||
|
"^TAP version 13"
|
||||||
|
"1\\.\\.2"
|
||||||
|
"ok 1 - null_test_success"
|
||||||
|
"ok 2 - int_test_success"
|
||||||
|
"# ok - tests")
|
||||||
|
set(test_assert_macros_fail_tap_out
|
||||||
|
"^TAP version 13"
|
||||||
|
"1\\.\\.1"
|
||||||
|
"not ok 1 - test_assert_return_code_fail"
|
||||||
|
"#[^\n\r]+[\n\r]#[^\n\r]+[\n\r]# not ok - tests")
|
||||||
|
set(test_groups_tap_out
|
||||||
|
"^TAP version 13"
|
||||||
|
"1\\.\\.1"
|
||||||
|
"ok 1 - null_test_success"
|
||||||
|
"# ok - test_group1"
|
||||||
|
"1\\.\\.1"
|
||||||
|
"ok 1 - int_test_success"
|
||||||
|
"# ok - test_group2")
|
||||||
|
set(test_skip_tap_out
|
||||||
|
"ok 1 # SKIP")
|
||||||
|
set(test_setup_fail_tap_out
|
||||||
|
"not ok 1 - int_test_ignored Could not run test: Test setup failed")
|
||||||
|
|
||||||
|
set(test_basics_subunit_out
|
||||||
|
"^test: null_test_success"
|
||||||
|
"success: null_test_success")
|
||||||
|
set(test_assert_macros_fail_subunit_out
|
||||||
|
"failure: test_assert_return_code_fail \\[")
|
||||||
|
set(test_groups_subunit_out
|
||||||
|
"^test: null_test_success"
|
||||||
|
"success: null_test_success")
|
||||||
|
set(test_skip_subunit_out
|
||||||
|
"^test: test_check_skip"
|
||||||
|
"skip: test_check_skip")
|
||||||
|
set(test_setup_fail_subunit_out
|
||||||
|
"error: int_test_ignored \\[ Could not run test: Test setup failed \\]")
|
||||||
|
|
||||||
|
set(test_basics_xml_out
|
||||||
|
"<testsuite name=\"tests\" time=\"[0-9.]+\" tests=\"2\" failures=\"0\" errors=\"0\" skipped=\"0\" >"
|
||||||
|
"<testcase name=\"null_test_success\" time=\"[0-9.]+\" >.*</testcase>")
|
||||||
|
set(test_assert_macros_fail_xml_out
|
||||||
|
"<testcase name=\"test_assert_return_code_fail\" time=\"[0-9.]+\" >"
|
||||||
|
"<failure>")
|
||||||
|
set(test_groups_xml_out
|
||||||
|
"^<\\?xml version=\"1.0\" encoding=\"UTF-8\" \\?>"
|
||||||
|
"<testsuites>"
|
||||||
|
"<testsuite name=\"test_group1\" time=\"[0-9.]+\" tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\" >"
|
||||||
|
"<testcase name=\"null_test_success\" time=\"[0-9.]+\" >"
|
||||||
|
"</testcase>"
|
||||||
|
"</testsuite>"
|
||||||
|
".*<testsuite name=\"test_group2\" time=\"[0-9.]+\" tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\" >"
|
||||||
|
"<testcase name=\"int_test_success\" time=\"[0-9.]+\" >"
|
||||||
|
"</testcase>"
|
||||||
|
"</testsuite>"
|
||||||
|
"</testsuites>")
|
||||||
|
set(test_skip_xml_out
|
||||||
|
"<testcase name=\"test_check_skip\" time=\"[0-9.]+\" >"
|
||||||
|
"<skipped/>")
|
||||||
|
set(test_setup_fail_xml_out
|
||||||
|
"<testcase name=\"int_test_ignored\" time=\"[0-9.]+\" >"
|
||||||
|
"<failure><!\\[CDATA\\[Test setup failed\\]\\]></failure>")
|
||||||
|
|
||||||
|
foreach(_TEST_OUTPUT_FMT ${TEST_OUTPUT_FMTS})
|
||||||
|
foreach(_OUTPUT_TEST ${OUTPUT_TESTS})
|
||||||
|
set(TEST_NAME ${_OUTPUT_TEST}_${_TEST_OUTPUT_FMT})
|
||||||
|
add_test(${TEST_NAME} ${TARGET_SYSTEM_EMULATOR} ${_OUTPUT_TEST})
|
||||||
|
add_cmocka_test_environment(${TEST_NAME})
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
TEST
|
||||||
|
${TEST_NAME}
|
||||||
|
APPEND
|
||||||
|
PROPERTY
|
||||||
|
ENVIRONMENT CMOCKA_MESSAGE_OUTPUT=${_TEST_OUTPUT_FMT}
|
||||||
|
)
|
||||||
|
|
||||||
|
list(LENGTH ${TEST_NAME}_out len)
|
||||||
|
list(GET ${TEST_NAME}_out 0 output)
|
||||||
|
if(len GREATER 1)
|
||||||
|
list(REMOVE_AT ${TEST_NAME}_out 0)
|
||||||
|
foreach(line ${${TEST_NAME}_out})
|
||||||
|
set(output "${output}[ \n\r]+${line}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_tests_properties(
|
||||||
|
${TEST_NAME}
|
||||||
|
PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION
|
||||||
|
${output}
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
endforeach()
|
|
@ -0,0 +1,229 @@
|
||||||
|
#
|
||||||
|
# CTEST SCRIPT FOR CMOCKA TESTING
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Running this script:
|
||||||
|
#
|
||||||
|
# ctest -S tests/cmocka_test.cmake \
|
||||||
|
# -DCTEST_MODEL="Nightly"
|
||||||
|
# -DCTEST_SITE="host.cmocka.org" \
|
||||||
|
# -DCTEST_TARGET_SYSTEM="Linux-openSUSE_Tumbleweed-x86_64"
|
||||||
|
#
|
||||||
|
# The Target system describes the target OS, version, architecture, etc. This
|
||||||
|
# parameter allows the testing script to choose appropriate configuration for
|
||||||
|
# CMake and build tools.
|
||||||
|
#
|
||||||
|
# The set of supported targets is defined by the project.
|
||||||
|
#
|
||||||
|
# The generic format for the Target system is <KIND>[-<NAME>][-<ARCH>], where
|
||||||
|
#
|
||||||
|
# <KIND> is one of Linux, Windows, MacOS, Android.
|
||||||
|
# <NAME> is an optional OS name and version, for example Fedora-28, Win10.
|
||||||
|
# <ARCH> is an optional architecture description, for example x86_64, ARM, ARM-Tegra5.
|
||||||
|
#
|
||||||
|
# To enable coverage, set:
|
||||||
|
# -DCTEST_WITH_COVERAGE=TRUE
|
||||||
|
#
|
||||||
|
# To enable dynamic analysis, set:
|
||||||
|
# -DCTEST_WITH_DYNAMIC_ANALYSIS=TRUE
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# 0. Set defaults
|
||||||
|
#
|
||||||
|
set(PROJECT_NAME "cmocka")
|
||||||
|
set(PROJECT_GIT_URL "https://git.cryptomilk.org/projects/cmocka.git")
|
||||||
|
|
||||||
|
#
|
||||||
|
# 1. Include CText Ext module
|
||||||
|
#
|
||||||
|
if(NOT CTEST_EXT_INCLUDED)
|
||||||
|
function(download_ctest_ext)
|
||||||
|
message("Download latest version of CTest Extension module")
|
||||||
|
|
||||||
|
find_package(Git QUIET)
|
||||||
|
|
||||||
|
set(repo_url "https://github.com/jet47/ctest-ext.git")
|
||||||
|
set(repo_dir "${CMAKE_CURRENT_LIST_DIR}/ctest-ext")
|
||||||
|
set(tmp_dir "${CMAKE_CURRENT_LIST_DIR}/ctest-ext-tmp")
|
||||||
|
|
||||||
|
if(NOT EXISTS "${repo_dir}")
|
||||||
|
set(CTEST_CHECKOUT_COMMAND "${GIT_EXECUTABLE} clone ${repo_url} ${repo_dir}")
|
||||||
|
endif()
|
||||||
|
set(CTEST_UPDATE_COMMAND "${GIT_EXECUTABLE}")
|
||||||
|
|
||||||
|
ctest_start("CTestExt" "${repo_dir}" "${tmp_dir}")
|
||||||
|
ctest_update(SOURCE "${repo_dir}")
|
||||||
|
|
||||||
|
file(REMOVE_RECURSE "${tmp_dir}")
|
||||||
|
|
||||||
|
set(CTEST_EXT_MODULE_PATH "${repo_dir}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
if(NOT DEFINED CTEST_EXT_MODULE_PATH)
|
||||||
|
if(DEFINED ENV{CTEST_EXT_MODULE_PATH} AND EXISTS "$ENV{CTEST_EXT_MODULE_PATH}/ctest_ext.cmake")
|
||||||
|
set(CTEST_EXT_MODULE_PATH "$ENV{CTEST_EXT_MODULE_PATH}")
|
||||||
|
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/ctest-ext/ctest_ext.cmake")
|
||||||
|
set(CTEST_EXT_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/ctest-ext")
|
||||||
|
else()
|
||||||
|
download_ctest_ext()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include("${CTEST_EXT_MODULE_PATH}/ctest_ext.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# 2. Initialize CTest Ext module
|
||||||
|
#
|
||||||
|
set_ifndef(CTEST_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
|
||||||
|
set_ifndef(CTEST_PROJECT_GIT_URL ${PROJECT_GIT_URL})
|
||||||
|
set_ifndef(CTEST_WITH_UPDATE TRUE)
|
||||||
|
|
||||||
|
ctest_ext_init()
|
||||||
|
|
||||||
|
#
|
||||||
|
# 3. Configure project for testing
|
||||||
|
#
|
||||||
|
|
||||||
|
# Check supported targets and models
|
||||||
|
check_if_matches(CTEST_TARGET_SYSTEM "^Linux" "^Windows")
|
||||||
|
check_if_matches(CTEST_MODEL "^Experimental$" "^Nightly$" "^Continuous$" "^Release$" "^Documentation$")
|
||||||
|
|
||||||
|
# Checks for Continuous model
|
||||||
|
set(IS_CONTINUOUS FALSE)
|
||||||
|
if(CTEST_MODEL MATCHES "Continuous")
|
||||||
|
set(IS_CONTINUOUS TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(IS_BINARY_EMPTY FALSE)
|
||||||
|
if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
|
||||||
|
set(IS_BINARY_EMPTY TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(IS_CONTINUOUS AND NOT IS_BINARY_EMPTY AND NOT HAVE_UPDATES)
|
||||||
|
ctest_ext_info("Continuous model : no updates")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configure the testing model
|
||||||
|
set_ifndef(CTEST_WITH_SUBMIT TRUE)
|
||||||
|
|
||||||
|
if(CTEST_MODEL MATCHES "Documentation")
|
||||||
|
set_ifndef(CTEST_WITH_TESTS FALSE)
|
||||||
|
else()
|
||||||
|
set_ifndef(CTEST_WITH_TESTS TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
set_ifndef(CTEST_WITH_COVERAGE FALSE)
|
||||||
|
if (CTEST_WITH_COVERAGE)
|
||||||
|
set_ifndef(CTEST_COVERAGE_TOOL "CDASH")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_ifndef(CTEST_WITH_DYNAMIC_ANALYSIS FALSE)
|
||||||
|
if (CTEST_WITH_DYNAMIC_ANALYSIS)
|
||||||
|
set_ifndef(CTEST_DYNAMIC_ANALYSIS_TOOL "CDASH")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(CTEST_MODEL MATCHES "Continuous")
|
||||||
|
set_ifndef(CTEST_EMPTY_BINARY_DIRECTORY FALSE)
|
||||||
|
else()
|
||||||
|
set_ifndef(CTEST_EMPTY_BINARY_DIRECTORY TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set CMake options
|
||||||
|
if(CTEST_TARGET_SYSTEM MATCHES "Windows")
|
||||||
|
if(CTEST_TARGET_SYSTEM MATCHES "64")
|
||||||
|
set_ifndef(CTEST_CMAKE_GENERATOR "Visual Studio 13 Win64")
|
||||||
|
else()
|
||||||
|
set_ifndef(CTEST_CMAKE_GENERATOR "Visual Studio 13")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set_ifndef(CTEST_CMAKE_GENERATOR "Unix Makefiles")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CTEST_MODEL MATCHES "(Release|Continuous)")
|
||||||
|
set_ifndef(CTEST_CONFIGURATION_TYPE "Release")
|
||||||
|
else()
|
||||||
|
set_ifndef(CTEST_CONFIGURATION_TYPE "Debug")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
### Add project default build options here !!!
|
||||||
|
|
||||||
|
add_cmake_cache_entry(UNIT_TESTING ON)
|
||||||
|
add_cmake_cache_entry(WITH_CMOCKERY_SUPPORT ON)
|
||||||
|
|
||||||
|
### Add project default build options here ^^^
|
||||||
|
|
||||||
|
add_cmake_cache_entry("ENABLE_CTEST" TYPE "BOOL" "ON")
|
||||||
|
|
||||||
|
if(CTEST_WITH_COVERAGE)
|
||||||
|
add_cmake_cache_entry("ENABLE_COVERAGE" TYPE "BOOL" "ON")
|
||||||
|
else()
|
||||||
|
add_cmake_cache_entry("ENABLE_COVERAGE" TYPE "BOOL" "OFF")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CTEST_MODEL MATCHES "Documentation")
|
||||||
|
add_cmake_cache_entry("BUILD_DOCS" TYPE "BOOL" "ON")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CTEST_MODEL MATCHES "Release")
|
||||||
|
if(CTEST_TARGET_SYSTEM MATCHES "Windows")
|
||||||
|
add_cmake_cache_entry("CPACK_GENERATOR" TYPE "STRING" "ZIP")
|
||||||
|
else()
|
||||||
|
add_cmake_cache_entry("CPACK_GENERATOR" TYPE "STRING" "TGZ")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# 4. Start testing, configure and build project
|
||||||
|
#
|
||||||
|
ctest_ext_start()
|
||||||
|
|
||||||
|
ctest_ext_configure()
|
||||||
|
|
||||||
|
if(CTEST_MODEL MATCHES "Release")
|
||||||
|
ctest_ext_build(TARGETS "ALL" "package")
|
||||||
|
elseif(CTEST_MODEL MATCHES "Documentation")
|
||||||
|
ctest_ext_build(TARGET "docs")
|
||||||
|
else()
|
||||||
|
ctest_ext_build()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# 5. Run tests
|
||||||
|
#
|
||||||
|
if(CTEST_MODEL MATCHES "Nightly")
|
||||||
|
ctest_ext_test(INCLUDE_LABEL "Full")
|
||||||
|
else()
|
||||||
|
ctest_ext_test(EXCLUDE_LABEL "Light")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
ctest_ext_coverage(
|
||||||
|
CDASH
|
||||||
|
LABELS "Module"
|
||||||
|
)
|
||||||
|
|
||||||
|
ctest_ext_dynamic_analysis(
|
||||||
|
CDASH
|
||||||
|
INCLUDE_LABEL "Light"
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# 6. Submit results to remote server
|
||||||
|
#
|
||||||
|
if(CTEST_MODEL MATCHES "Release")
|
||||||
|
if(CTEST_TARGET_SYSTEM MATCHES "Windows")
|
||||||
|
file(GLOB packages "${CTEST_BINARY_DIRECTORY}/*.zip")
|
||||||
|
else()
|
||||||
|
file(GLOB packages "${CTEST_BINARY_DIRECTORY}/*.tar.gz")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND CTEST_UPLOAD_FILES ${packages})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
ctest_ext_submit()
|
|
@ -0,0 +1,74 @@
|
||||||
|
## The directory to run ctest in.
|
||||||
|
set(CTEST_DIRECTORY "$ENV{HOME}/workspace/tmp/dashboards/cmocka")
|
||||||
|
|
||||||
|
## The hostname of the machine
|
||||||
|
set(CTEST_SITE "host.cmocka.org")
|
||||||
|
## The buildname
|
||||||
|
set(CTEST_BUILD_NAME "Linux_GCC_x86_64_default")
|
||||||
|
|
||||||
|
## The Makefile generator to use
|
||||||
|
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
|
||||||
|
|
||||||
|
## The Build configuration to use.
|
||||||
|
set(CTEST_BUILD_CONFIGURATION "Debug")
|
||||||
|
|
||||||
|
## The build options for the project
|
||||||
|
set(CTEST_BUILD_OPTIONS "-DUNIT_TESTING=ON -DWITH_CMOCKERY_SUPPORT=ON")
|
||||||
|
|
||||||
|
#set(CTEST_CUSTOM_MEMCHECK_IGNORE torture_rand)
|
||||||
|
|
||||||
|
## The Model to set: Nightly, Continous, Experimental
|
||||||
|
set(CTEST_MODEL "Experimental")
|
||||||
|
|
||||||
|
## The URL to the git repository
|
||||||
|
set(CTEST_GIT_REPOSITORY "git://git.cryptomilk.org/projects/cmocka.git")
|
||||||
|
|
||||||
|
## The branch
|
||||||
|
#set(CTEST_GIT_BRANCH "--branch v0-5")
|
||||||
|
|
||||||
|
## Wether to enable memory checking.
|
||||||
|
set(WITH_MEMCHECK FALSE)
|
||||||
|
|
||||||
|
## Wether to enable code coverage.
|
||||||
|
set(WITH_COVERAGE FALSE)
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
if (WITH_COVERAGE AND NOT WIN32)
|
||||||
|
set(CTEST_BUILD_CONFIGURATION "Profiling")
|
||||||
|
endif (WITH_COVERAGE AND NOT WIN32)
|
||||||
|
|
||||||
|
set(CTEST_SOURCE_DIRECTORY "${CTEST_DIRECTORY}/${CTEST_BUILD_NAME}/source")
|
||||||
|
set(CTEST_BINARY_DIRECTORY "${CTEST_DIRECTORY}/${CTEST_BUILD_NAME}/build")
|
||||||
|
|
||||||
|
set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/tests/valgrind.supp)
|
||||||
|
|
||||||
|
find_program(CTEST_GIT_COMMAND NAMES git)
|
||||||
|
find_program(CTEST_COVERAGE_COMMAND NAMES gcov)
|
||||||
|
find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
|
||||||
|
|
||||||
|
if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}")
|
||||||
|
set(CTEST_CHECKOUT_COMMAND "${CTEST_GIT_COMMAND} clone ${CTEST_GIT_BRANCH} ${CTEST_GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CTEST_UPDATE_COMMAND "${CTEST_GIT_COMMAND}")
|
||||||
|
|
||||||
|
set(CTEST_CONFIGURE_COMMAND "${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION}")
|
||||||
|
set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} ${CTEST_BUILD_OPTIONS}")
|
||||||
|
set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-G${CTEST_CMAKE_GENERATOR}\"")
|
||||||
|
set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"${CTEST_SOURCE_DIRECTORY}\"")
|
||||||
|
|
||||||
|
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
|
||||||
|
|
||||||
|
ctest_start(${CTEST_MODEL} TRACK ${CTEST_MODEL})
|
||||||
|
ctest_update(SOURCE ${CTEST_SOURCE_DIRECTORY})
|
||||||
|
ctest_configure(BUILD ${CTEST_BINARY_DIRECTORY})
|
||||||
|
ctest_build(BUILD ${CTEST_BINARY_DIRECTORY})
|
||||||
|
ctest_test(BUILD ${CTEST_BINARY_DIRECTORY})
|
||||||
|
if (WITH_MEMCHECK AND CTEST_COVERAGE_COMMAND)
|
||||||
|
ctest_coverage(BUILD ${CTEST_BINARY_DIRECTORY})
|
||||||
|
endif (WITH_MEMCHECK AND CTEST_COVERAGE_COMMAND)
|
||||||
|
if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
|
||||||
|
ctest_memcheck(BUILD ${CTEST_BINARY_DIRECTORY})
|
||||||
|
endif (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
|
||||||
|
ctest_submit()
|
|
@ -0,0 +1,30 @@
|
||||||
|
tests = {
|
||||||
|
'alloc': false,
|
||||||
|
'group_setup_assert': true,
|
||||||
|
'group_setup_fail': true,
|
||||||
|
'fixtures': false,
|
||||||
|
'group_fixtures': false,
|
||||||
|
'groups': false,
|
||||||
|
'float_macros': false,
|
||||||
|
'assert_macros': false,
|
||||||
|
'assert_macros_fail': true,
|
||||||
|
'basics': false,
|
||||||
|
'skip': false,
|
||||||
|
'strmatch': false,
|
||||||
|
'setup_fail': true,
|
||||||
|
'ordering': false,
|
||||||
|
'ordering_fail': true,
|
||||||
|
'returns': false,
|
||||||
|
'returns_fail': true,
|
||||||
|
'wildcard': false,
|
||||||
|
'skip_filter': false,
|
||||||
|
'cmockery': false
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach name, should_fail: tests
|
||||||
|
exe = executable(name,
|
||||||
|
'test_@0@.c'.format(name),
|
||||||
|
include_directories: [cmocka_includes],
|
||||||
|
link_with: [libcmocka])
|
||||||
|
test(name, exe, should_fail: should_fail)
|
||||||
|
endforeach
|
|
@ -0,0 +1,91 @@
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
#include <cmocka_private.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static void torture_test_malloc(void **state)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t str_len;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
(void)state; /* unsused */
|
||||||
|
|
||||||
|
str_len = 12;
|
||||||
|
str = (char *)test_malloc(str_len);
|
||||||
|
assert_non_null(str);
|
||||||
|
|
||||||
|
len = snprintf(str, str_len, "test string");
|
||||||
|
assert_int_equal(len, 11);
|
||||||
|
|
||||||
|
len = strlen(str);
|
||||||
|
assert_int_equal(len, 11);
|
||||||
|
|
||||||
|
test_free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void torture_test_realloc(void **state)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
char *tmp;
|
||||||
|
size_t str_len;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
(void)state; /* unsused */
|
||||||
|
|
||||||
|
str_len = 16;
|
||||||
|
str = (char *)test_malloc(str_len);
|
||||||
|
assert_non_null(str);
|
||||||
|
|
||||||
|
len = snprintf(str, str_len, "test string 123");
|
||||||
|
assert_int_equal(len, 15);
|
||||||
|
|
||||||
|
len = strlen(str);
|
||||||
|
assert_int_equal(len, 15);
|
||||||
|
|
||||||
|
str_len = 20;
|
||||||
|
tmp = test_realloc(str, str_len);
|
||||||
|
assert_non_null(tmp);
|
||||||
|
|
||||||
|
str = tmp;
|
||||||
|
len = strlen(str);
|
||||||
|
assert_string_equal(tmp, "test string 123");
|
||||||
|
|
||||||
|
snprintf(str + len, str_len - len, "4567");
|
||||||
|
assert_string_equal(tmp, "test string 1234567");
|
||||||
|
|
||||||
|
test_free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void torture_test_realloc_set0(void **state)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t str_len;
|
||||||
|
|
||||||
|
(void)state; /* unsused */
|
||||||
|
|
||||||
|
str_len = 16;
|
||||||
|
str = (char *)test_malloc(str_len);
|
||||||
|
assert_non_null(str);
|
||||||
|
|
||||||
|
/* realloc(ptr, 0) is like a free() */
|
||||||
|
str = (char *)test_realloc(str, 0);
|
||||||
|
assert_null(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest alloc_tests[] = {
|
||||||
|
cmocka_unit_test(torture_test_malloc),
|
||||||
|
cmocka_unit_test(torture_test_realloc),
|
||||||
|
cmocka_unit_test(torture_test_realloc_set0),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(alloc_tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
#include <cmocka_private.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
/**************************************
|
||||||
|
*** assert_return_code
|
||||||
|
**************************************/
|
||||||
|
static void test_assert_return_code(void **state)
|
||||||
|
{
|
||||||
|
struct stat sb = {0};
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
(void)state; /* unused */
|
||||||
|
|
||||||
|
rc = stat(".", &sb);
|
||||||
|
assert_return_code(rc, 0);
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
assert_true(S_ISDIR(sb.st_mode));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_assert_return_code),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
#include <cmocka_private.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_IO_H
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
/**************************************
|
||||||
|
*** assert_return_code
|
||||||
|
**************************************/
|
||||||
|
static void test_assert_return_code_fail(void **state)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
(void)state; /* unused */
|
||||||
|
|
||||||
|
fd = open("this_file_doesnt_exist.cmocka", 0);
|
||||||
|
assert_return_code(fd, errno);
|
||||||
|
|
||||||
|
if (fd >= 0) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_assert_return_code_fail),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Use the unit test allocators */
|
||||||
|
#define UNIT_TESTING 1
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
static int setup(void **state) {
|
||||||
|
int *answer = malloc(sizeof(int));
|
||||||
|
|
||||||
|
assert_non_null(answer);
|
||||||
|
*answer = 42;
|
||||||
|
|
||||||
|
*state = answer;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int teardown(void **state) {
|
||||||
|
free(*state);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(null_test_success),
|
||||||
|
cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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 <cmockery/cmockery.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);
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 Arnaud Gelas <arnaud.gelas@sensefly.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Use the unit test allocators */
|
||||||
|
#define UNIT_TESTING 1
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
/* A test case that does check if double is equal. */
|
||||||
|
static void double_test_success(void **state)
|
||||||
|
{
|
||||||
|
(void)state; /* unused */
|
||||||
|
|
||||||
|
assert_double_equal(0.5, 1. / 2., 0.000001);
|
||||||
|
assert_double_not_equal(0.5, 0.499, 0.000001);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(double_test_success),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
static void test_segfault_recovery(void **state)
|
||||||
|
{
|
||||||
|
(void)state; /* unused */
|
||||||
|
|
||||||
|
/* Raise segmentation fault */
|
||||||
|
raise(SIGSEGV);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_segfault_recovery1(void **state)
|
||||||
|
{
|
||||||
|
test_segfault_recovery(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_segfault_recovery2(void **state)
|
||||||
|
{
|
||||||
|
test_segfault_recovery(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_segfault_recovery3(void **state)
|
||||||
|
{
|
||||||
|
test_segfault_recovery(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest exception_tests[] = {
|
||||||
|
cmocka_unit_test(test_segfault_recovery1),
|
||||||
|
cmocka_unit_test(test_segfault_recovery2),
|
||||||
|
cmocka_unit_test(test_segfault_recovery3),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(exception_tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static int setup_only(void **state)
|
||||||
|
{
|
||||||
|
*state = malloc(1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int teardown_only(void **state)
|
||||||
|
{
|
||||||
|
free(*state);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int prestate_setup(void **state)
|
||||||
|
{
|
||||||
|
int *val = (int *)*state, *a;
|
||||||
|
|
||||||
|
a = malloc(sizeof(int));
|
||||||
|
*a = *val + 1;
|
||||||
|
*state = a;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int prestate_teardown(void **state)
|
||||||
|
{
|
||||||
|
free(*state);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prestate_setup_test(void **state)
|
||||||
|
{
|
||||||
|
int *a = (int *)*state;
|
||||||
|
|
||||||
|
assert_non_null(a);
|
||||||
|
assert_int_equal(*a, 43);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prestate_test(void **state)
|
||||||
|
{
|
||||||
|
int *a = (int *)*state;
|
||||||
|
|
||||||
|
assert_non_null(a);
|
||||||
|
assert_int_equal(*a, 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int prestate = 42;
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test_setup(malloc_setup_test, setup_only),
|
||||||
|
cmocka_unit_test_setup(malloc_setup_test, setup_only),
|
||||||
|
cmocka_unit_test_teardown(malloc_teardown_test, teardown_only),
|
||||||
|
cmocka_unit_test_teardown(malloc_teardown_test, teardown_only),
|
||||||
|
cmocka_unit_test_teardown(malloc_teardown_test, teardown_only),
|
||||||
|
cmocka_unit_test_teardown(malloc_teardown_test, teardown_only),
|
||||||
|
cmocka_unit_test_prestate(prestate_test, &prestate),
|
||||||
|
cmocka_unit_test_prestate_setup_teardown(prestate_setup_test, prestate_setup, prestate_teardown, &prestate),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 Arnaud Gelas <arnaud.gelas@sensefly.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Use the unit test allocators */
|
||||||
|
#define UNIT_TESTING 1
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
/* A test case that does check if float is equal. */
|
||||||
|
static void float_test_success(void **state)
|
||||||
|
{
|
||||||
|
(void)state; /* unused */
|
||||||
|
|
||||||
|
assert_float_equal(0.5f, 1.f / 2.f, 0.000001f);
|
||||||
|
assert_float_not_equal(0.5, 0.499f, 0.000001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(float_test_success),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* Use the unit test allocators */
|
||||||
|
#define UNIT_TESTING 1
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
static int group_setup(void **state)
|
||||||
|
{
|
||||||
|
int *answer = malloc(sizeof(int));
|
||||||
|
assert_non_null(answer);
|
||||||
|
*answer = 42;
|
||||||
|
|
||||||
|
*state = answer;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int group_teardown(void **state)
|
||||||
|
{
|
||||||
|
int *answer = (int *)*state;
|
||||||
|
|
||||||
|
free(answer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_value_equal(void **state)
|
||||||
|
{
|
||||||
|
int a = *((int *)*state);
|
||||||
|
|
||||||
|
assert_int_equal(a, 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_value_range(void **state)
|
||||||
|
{
|
||||||
|
int a = *((int *)*state);
|
||||||
|
|
||||||
|
assert_in_range(a, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int prestate = 1337;
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_value_equal),
|
||||||
|
cmocka_unit_test(test_value_range),
|
||||||
|
cmocka_unit_test_prestate(test_value_equal, &prestate),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, group_setup, group_teardown);
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* Use the unit test allocators */
|
||||||
|
#define UNIT_TESTING 1
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
static int group_setup_failing(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
assert_int_equal(0, 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_true(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
assert_true(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_false(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
assert_false(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(test_true),
|
||||||
|
cmocka_unit_test(test_false),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, group_setup_failing, NULL);
|
||||||
|
}
|