pax_global_header00006660000000000000000000000064146330230750014515gustar00rootroot0000000000000052 comment=1d70e145d4875ca81b89f224d6a18286bcca873e cmocka-mocks-0.52.1/000077500000000000000000000000001463302307500141515ustar00rootroot00000000000000cmocka-mocks-0.52.1/.clang-format000066400000000000000000000003331463302307500165230ustar00rootroot00000000000000BasedOnStyle: Google IndentWidth: 4 ColumnLimit: 120 UseTab: Never AllowShortFunctionsOnASingleLine: Empty DerivePointerAlignment: false PointerAlignment: Right UseTab: Never IndentWidth: 4 AlignConsecutiveMacros: true cmocka-mocks-0.52.1/.clang-tidy000066400000000000000000000013341463302307500162060ustar00rootroot00000000000000Checks: ' -* readability-identifier-naming, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling ' InheritParentConfig: true CheckOptions: - { key: readability-identifier-naming.FunctionCase, value: aNy_CasE } - { key: readability-identifier-naming.GlobalVariableCase, value: lower_case } - { key: readability-identifier-naming.GlobalVariablePrefix, value: __ } - { key: readability-identifier-naming.VariableCase, value: aNy_CasE } - { key: readability-identifier-naming.ParameterCase, value: aNy_CasE } - { key: readability-identifier-naming.ParameterIgnoredRegexp, value: '^_.+' } cmocka-mocks-0.52.1/.githooks/000077500000000000000000000000001463302307500160565ustar00rootroot00000000000000cmocka-mocks-0.52.1/.githooks/pre-commit000077500000000000000000000013261463302307500200620ustar00rootroot00000000000000#!/bin/sh CLANG_TIDY_DIFF="" if [ -x /usr/share/clang/clang-tidy-diff.py ]; then CLANG_TIDY_DIFF="/usr/share/clang/clang-tidy-diff.py" fi if [ -x /usr/lib/llvm-*/share/clang/clang-tidy-diff.py ]; then CLANG_TIDY_DIFF="/usr/lib/llvm-*/share/clang/clang-tidy-diff.py" fi if [ "x$CLANG_TIDY_DIFF" = "x" ]; then echo "No clang-tidy-diff.py found, skipp pre commit checks" exit 0 fi RESULT=$(git diff --staged | ${CLANG_TIDY_DIFF} -p 1 2> /dev/null) echo $RESULT | grep "warning: " if [ $? -eq 0 ]; then echo "There are some coding style issues:" echo "$RESULT" exec < /dev/tty read -p "Commit anyway? (y/N): " ANSWER case $ANSWER in [Yy]* ) echo "Continue with linting errors..."; break;; * ) exit 1; esac fi cmocka-mocks-0.52.1/.gitignore000066400000000000000000000003521463302307500161410ustar00rootroot00000000000000# eclipse project files and folders .profile .cprofile .settings .asciidoctorconfig.adoc ci/sshconfig compile_commands.json # Temporary folders for building and/or testing __pycache__ _build _demo b bld build build-* r release *.swp cmocka-mocks-0.52.1/.gitlab-ci.yml000066400000000000000000000011551463302307500166070ustar00rootroot00000000000000--- variables: DOCKER_HOST: "tcp://docker:2375" stages: - build - test default: image: ubuntu:jammy services: - name: docker:24-dind alias: docker variables: DOCKER_TLS_CERTDIR: "" tags: - "docker" before_script: - apt-get update - apt-get install -y curl bash jq docker.io - docker info - ip a - env | sort build-deb-packages: parallel: matrix: - OS: ubuntu CODENAME: jammy - OS: ubuntu CODENAME: noble stage: build image: ${OS}:${CODENAME} script: - ci/build_debs.sh ${CODENAME} artifacts: paths: - ./*.deb cmocka-mocks-0.52.1/CMakeLists.txt000066400000000000000000000012701463302307500167110ustar00rootroot00000000000000# SPDX-License-Identifier: MIT cmake_minimum_required(VERSION 3.21) include(cmake/ConfigureLibrary.cmake) include(cmake/project.cmake) # redefining OUR cmake project functions project(cmocka_mocks LANGUAGES C VERSION ${CMOCKA_MOCKS_VERSION}) project_set_environment() project_set_version_variables() project_add_documentation_target( TITLE "BaseOS Cmocka_mocks Documentation" MARKDOWN ${CMAKE_SOURCE_DIR}/documentation/documentation.md ) list(APPEND CMAKE_PREFIX_PATH "${INSTALL_DIR}/usr/local/lib/cmake") configureLibrary(cmocka_extensions "${CMOCKA_EXTENSIONS_URI}" "${CMOCKA_EXTENSIONS_REF}") add_subdirectory(src) if(PACKAGING) include(cmake/Packing.cmake) endif(PACKAGING) cmocka-mocks-0.52.1/CONFIG.ini000066400000000000000000000027711463302307500156260ustar00rootroot00000000000000unset SOURCES_URI unset CMOCKA_EXTENSIONS_REPO_NAME unset CMOCKA_EXTENSIONS_REPO_PATH unset CMOCKA_EXTENSIONS_REPO_REF ################################################### # # Using a common base URI or path for dependencies # ################################################### # uncomment and edit for common local workspace folder, containing all project # dependencies #export SOURCES_URI="../" # or # uncomment and edit for common remote repository base URI, containing all # project dependencies # export SOURCES_URI="https://${GIT_USER_TOKEN}@gitlabintern.emlix.com/elektrobit/base-os/" # define repository names of project dependencies # local #export CMOCKA_EXTENSIONS_REPO_NAME="cmocka_extensions" # or # remote # export CMOCKA_EXTENSIONS_REPO_NAME="cmocka_extensions.git" ################################################################# # # Define repository location for each project dependency separately # ################################################################# # uncomment and edit to use a local repository #export CMOCKA_EXTENSIONS_REPO_PATH="../cmocka_extensions" # or # uncomment and edit to use a remote repository #export CMOCKA_EXTENSIONS_REPO_PATH="https://${GIT_USER_TOKEN}@gitlabintern.emlix.com/elektrobit/base-os/cmocka_extensions.git" ########################################################### # # uncomment and edit to set a specific target branch or tag # ########################################################### #export CMOCKA_EXTENSIONS_REPO_REF="cobos-tools-last-release" cmocka-mocks-0.52.1/Jenkinsfile000066400000000000000000000115741463302307500163450ustar00rootroot00000000000000import jenkins.* import jenkins.model.* import hudson.* import hudson.model.* def ASMCOV_URI def SOURCES_URI node { ASMCOV_URI = '' script { def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl.class, Jenkins.instance, null, null ); def jenkins_asmcov_uri = creds.findResult { it.id == 'jenkins_asmcov_uri' ? it : null } if(jenkins_asmcov_uri) { println(jenkins_asmcov_uri.id + ": " +jenkins_asmcov_uri.username + ": " + jenkins_asmcov_uri.password) ASMCOV_URI=jenkins_asmcov_uri.password } } } node { SOURCES_URI = '' script { def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl.class, Jenkins.instance, null, null ); def baseos_gitlab_uri = creds.findResult { it.id == 'baseos_gitlab_uri' ? it : null } if(baseos_gitlab_uri) { println(baseos_gitlab_uri.id + ": " +baseos_gitlab_uri.username + ": " + baseos_gitlab_uri.password) SOURCES_URI=baseos_gitlab_uri.password println("Sources URI is " + SOURCES_URI) } } } properties([gitLabConnection('GitLab')]) pipeline { options { gitlabBuilds(builds: ["cmocka_mocks", "build debug", "build release", "lint sources", "documentation"]) buildDiscarder(logRotator(numToKeepStr: env.BRANCH_NAME == "master"? "1000": env.BRANCH_NAME == "integration"?"1000":"3")) } agent { dockerfile { filename './ci/Dockerfile' reuseNode true additionalBuildArgs "--build-arg USER=jenkins \ --build-arg UID=\$(id -u) --build-arg GID=\$(id -g) \ --build-arg ASMCOV_URI=${ASMCOV_URI}" args "--privileged --userns=keep-id -e SOURCES_URI=${SOURCES_URI}" label "podman" } } stages { stage('debug') { steps{ sh 'ls -lah' sh 'env' sh 'gcc --version' sh 'cmake --version' updateGitlabCommitStatus name: 'cmocka_mocks', state: 'running' } } stage('Build') { steps { parallel( debug: { gitlabCommitStatus("build debug") { sh '''#!/bin/bash -xe env ./ci/build.sh --ci Debug ''' } }, release: { gitlabCommitStatus("build release") { sh '''#!/bin/bash -xe env export SOURCES_URI="${SOURCES_URI}" ./ci/build.sh --ci Release ''' } } ) } } stage('Lint sources') { steps{ gitlabCommitStatus("lint sources") { sh '''#!/bin/bash -xe ./ci/code_lint.py --ci --result-dir=build/Release/result/lint_results ./ci/checklicense.sh ''' } } post { always { archiveArtifacts artifacts: "build/Release/result/lint_results/**", fingerprint: true } } } stage('Build documentation') { steps{ gitlabCommitStatus("documentation") { sh './ci/build_doc.sh' } } post { success { archiveArtifacts artifacts: "build/Debug/doc/**, documentation/monitor.md", fingerprint: true } } } } post { changed { script { def jobName = env.JOB_NAME.tokenize('/') as String[]; def projectName = jobName[0]; def title = '[' + projectName + '] ' def message = ''; if (currentBuild.currentResult == 'FAILURE') { title += 'Pipeline for ' + env.BRANCH_NAME + ' has failed'; message = 'Hi, sorry but the pipeline is broken. See ' + env.BUILD_URL + ' for details.' } if(currentBuild.currentResult == 'SUCCESS') { title += 'Pipeline for ' + env.BRANCH_NAME + ' is now stable again'; message = 'Hi, the pipeline is now stable again. See ' + env.BUILD_URL + ' for details.' } emailext subject: title, body: message, recipientProviders: [ [$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider'] ], replyTo: '$DEFAULT_REPLYTO', to: '$DEFAULT_RECIPIENTS' } } success { updateGitlabCommitStatus name: 'cmocka_mocks', state: 'success' } failure { updateGitlabCommitStatus name: 'cmocka_mocks', state: 'failed' } always { cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true, patterns: [[pattern: '.gitignore', type: 'INCLUDE'], [pattern: '.trace', type: 'INCLUDE']]) } } } cmocka-mocks-0.52.1/LICENSE000066400000000000000000000021131463302307500151530ustar00rootroot00000000000000MIT License Copyright (c) [2023] [emlix GmbH, Elektrobit Automotive GmbH] 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. cmocka-mocks-0.52.1/README.md000066400000000000000000000077621463302307500154440ustar00rootroot00000000000000# cmocka_mocks Library to mock common C functions, like libc and jsonc, for testing purposes. This collection of ready to use mocks is based on [cmocka_extensions](https://github.com/Elektrobit/cmocka_extensions) ## Building cmocka_mocks uses CMake for building: ```bash export BUILD_TYPE= cmake -B ./build/${BUILD_TYPE}/cmake \ -D INSTALL_DIR=build/${BUILD_TYPE}/dist \ -D CMAKE_BUILD_TYPE=${BUILD_TYPE} \ -D CMOCKA_EXTENSIONS_URI=https://github.com/Elektrobit/cmocka_extensions.git \ -D CMOCKA_EXTENSIONS_REF=integration make -C ./build/${BUILD_TYPE}/cmake all make -C ./build/${BUILD_TYPE}/cmake install ``` It is also possible to configure cmake without the -D flags, if cmocka_extensions are already installed on the system. or use the CI hooks ```bash source CONFIG.ini ./ci/build.sh [Release] ``` ### Workspace setup 1. Please run the following git commands after cloning the repository: ```bash git config core.hooksPath .githooks ``` to set the commit message template and to setup the project specific git hooks. 2. Usually it is a good idea to create a symlink to the compilation database created by cmake in the build directory. Run therefore: ``` ln -s build/compile_commands.json ``` ### Building with custom cmocka_extensions If you want to build using a custom location or another remote repository for cmocka_extensions or build another tag or branch then integration, then the use of variables is required. If build using cmake, simply adjust the values of ```CMOCKA_EXTENSIONS_URI``` and ```CMOCKA_EXTENSIONS_REF``` to the wanted values. URI can be a local or remote path. If building using the CI Hook, refer to the configuration file CONFIG.ini ```SOURCES_URI``` configures the location of the project directory while ```CMOCKA_EXTENSIONS_REPO_NAME``` configures the directory name that contains the project directory. Additionally ```CMOCKA_EXTENSIONS_REPO_PATH``` can be set, invalidating both previous variables. This corresponds to setting ```CMOCKA_EXTENSIONS_URI``` in the cmake example. In the same way setting ```CMOCKA_EXTENSIONS_REPO_REF``` does the same as in the cmake variant. ## Folders ### ci Scripts to be used by CI pipelines to build , run various tests and checks. ### debian.native Contains Debian packaging scripts for building the current source tree as .deb packages. This is primarily for CI pipelines to automatically verify if the packages are buildable or if anything needs to be changed. See `debian.native/README.md` for more information. ### documentation A more detailed description of the mocked functions can be found in the documentation. ``` ./documentation/documentation.md ``` ### src Contains the actual productive sources. #### src/cmocka_mocks Contains code. # License MIT License Copyright (c) [2023] [emlix GmbH, Elektrobit Automotive GmbH] The full text of the license can be found in the [LICENSE](LICENSE) file in the repository root directory. ## Powered by EB elos is powered by elektrobit automotive gmbh. Elektrobit is an automotive software company and developer of embedded software products for ECU, AUTOSAR, automated driving, connected vehicles and UX. elos isan integrated part of EB corbos Linux – built on Ubuntu is an open-source operating system for high-performance computing, leveraging the rich functionality of Linux while meeting security and industry regulations. ## Maintainers * Wolfgang Gehrhardt wolfgang.gehrhardt@emlix.com [@gehwolf](https://github.com/gehwolf) * Thomas Brinker thomas.brinker@emlix.com [@ThomasBrinker](https://github.com/ThomasBrinker) ## Credits * Andreas Schickedanz * Andreas Zdziarstek * Anja Lehwess-Litzmann * Annika Schmitt * Anton Hillerband * Benedikt Braunger * Christian Steiger * Daniel Glöckner * Fabian Godehardt * Friedrich Schwedler * Isaac True * Joerg Vehlow * Maryniuk Bogdan * Rainer Müller * Sabrina Otto * Thomas Brinker * Vignesh Jayaraman * Wolfgang Gehrhardt cmocka-mocks-0.52.1/ci/000077500000000000000000000000001463302307500145445ustar00rootroot00000000000000cmocka-mocks-0.52.1/ci/Dockerfile000066400000000000000000000046361463302307500165470ustar00rootroot00000000000000FROM ubuntu:jammy ARG USER=ci ARG UID=1000 ARG GID=1000 ARG ASMCOV_URI="not available" ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y \ binutils-dev \ build-essential \ clang-format \ clang-tidy \ cmake \ curl \ gdb \ git \ gnuplot \ jq \ libcmocka-dev \ libcsv-dev \ libesmtp-dev \ libiberty-dev \ libjson-c-dev \ libmnl-dev \ libsqlite3-0 \ libsqlite3-dev \ libssl-dev \ linux-tools-generic \ locales \ net-tools \ netcat \ ninja-build \ openssl \ pandoc \ pandoc-plantuml-filter \ pkg-config \ python-is-python3 \ python3-pip \ python3-venv \ sqlite3 \ sudo \ wget \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* \ && rm /usr/bin/perf \ && find /usr/lib/linux-tools -name "perf" -executable -exec ln -s {} /usr/bin/perf \; RUN locale-gen en_US.UTF-8 \ && locale-gen de_DE.UTF-8 \ && groupadd -g $GID -o ci \ && useradd -m -u $UID -g $GID -o -s /bin/bash $USER \ && echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers RUN git clone --depth 1 https://github.com/aquynh/capstone.git RUN cd capstone/ \ && ./make.sh \ && sudo ./make.sh install RUN if [ "${ASMCOV_URI}" != "not available" ]; then git clone --depth 1 ${ASMCOV_URI} -b 'integration' \ && cmake -B build asmcov \ && make -C build \ && make -C build install; \ fi RUN git clone https://gitlab.com/esr/tapview.git RUN cd tapview \ && sed -i '/$(INSTALL) -m 644 $(MANPAGES)/d' Makefile\ && make install DESTDIR=/ prefix=usr USER $USER ENV LC_ALL=en_US.UTF-8 ENV DOCKERBUILD=1 RUN python -m venv /home/$USER/.venv \ && . /home/$USER/.venv/bin/activate \ && python -m pip install \ beautifulsoup4 \ sphinx \ sphinx-c-autodoc \ sphinx-copybutton \ sphinx-favicon \ sphinxcontrib-programoutput # install sphinx-c-autodoc dependedncies RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \ && echo "\n\ # for llvm 16 packages\n\ deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main\n\ deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main\n\ " | sudo tee /etc/apt/sources.list \ && sudo apt-get update \ && sudo apt-get install -y libclang1-16 \ && sudo ln -s /usr/lib/x86_64-linux-gnu/libclang-16.so.1 /usr/lib/libclang-16.so ENV SPHINX_VENV="/home/$USER/.venv/" WORKDIR /build CMD /bin/bash cmocka-mocks-0.52.1/ci/build.sh000077500000000000000000000053021463302307500162020ustar00rootroot00000000000000#!/bin/bash set -e -u CMD_PATH=$(realpath "$(dirname "$0")") BASE_DIR=${CMD_PATH%/*} CMAKE_PARAM=${CMAKE_PARAM:-""} NINJA_PARAM=${NINJA_PARAM:-"-j$(nproc)"} SOURCES_URI=${SOURCES_URI:-https://github.com/Elektrobit/} CMOCKA_EXTENSIONS_REPO_NAME=${CMOCKA_EXTENSIONS_REPO_NAME:-cmocka_extensions.git} CMOCKA_EXTENSIONS_REPO_PATH=${CMOCKA_EXTENSIONS_REPO_PATH:-${SOURCES_URI}/${CMOCKA_EXTENSIONS_REPO_NAME}} DEFAULT_BRANCH="integration" if [ "$SOURCES_URI" = "https://github.com/Elektrobit/" ]; then DEFAULT_BRANCH="main" fi CMOCKA_EXTENSIONS_REPO_REF=${CMOCKA_EXTENSIONS_REPO_REF:-${DEFAULT_BRANCH}} PARAM="" OPTION_CI=0 OPTION_CLEAN=0 OPTION_VERBOSE=0 OPTION_PACKAGE=0 for element in "$@"; do case $element in --ci) OPTION_CI=1 ;; --clean|-c) OPTION_CLEAN=1 ;; --verbose|-v) OPTION_VERBOSE=1 ;; --package) OPTION_PACKAGE=1 ;; -*) echo "error: unknown option: $1"; exit 1 ;; *) PARAM="$PARAM $element" ;; esac done set -- $PARAM if [ $# -gt 1 ]; then echo "error: only one build-type allowed" exit 1 elif [ $OPTION_CI -eq 1 ]; then if [ $# -eq 0 ]; then echo "error: build-type must be explicitely set in CI mode" exit 1 fi CMAKE_PARAM="-DENABLE_CI=1" OPTION_CLEAN=1 OPTION_VERBOSE=1 fi BUILD_TYPE="${1:-Debug}" if [ $OPTION_PACKAGE -eq 1 ]; then CMAKE_PARAM="${CMAKE_PARAM} -D PACKAGING=true" BUILD_TYPE=Release OPTION_CLEAN=1 fi CMAKE_PARAM="${CMAKE_PARAM} -D CMOCKA_EXTENSIONS_URI=${CMOCKA_EXTENSIONS_REPO_PATH} \ -D CMOCKA_EXTENSIONS_REF=${CMOCKA_EXTENSIONS_REPO_REF}" BUILD_DIR="$BASE_DIR/build/$BUILD_TYPE" RESULT_DIR="$BUILD_DIR/result" DIST_DIR="$BUILD_DIR/dist" CMAKE_BUILD_DIR="$BUILD_DIR/cmake" export LOCAL_INSTALL_DIR=${LOCAL_INSTALL_DIR:-"$DIST_DIR"} CMAKE_PARAM="${CMAKE_PARAM} -D INSTALL_DIR=${LOCAL_INSTALL_DIR}" DEP_BUILD_PARAM="" if [ $OPTION_CLEAN -eq 1 ]; then DEP_BUILD_PARAM="$DEP_BUILD_PARAM -c" if [ -e "$BUILD_DIR" ]; then echo "Removing $BUILD_DIR ..." rm -rf "$BUILD_DIR" fi fi if [ $OPTION_VERBOSE -eq 1 ]; then DEP_BUILD_PARAM="$DEP_BUILD_PARAM -v" NINJA_PARAM="$NINJA_PARAM -v" fi echo -e "\n#### Configuring cmocka_mocks ($BUILD_TYPE) ####" mkdir -p "$RESULT_DIR" "$DIST_DIR" if [ ! -e "$CMAKE_BUILD_DIR/build.ninja" ]; then cmake -B "$CMAKE_BUILD_DIR" "$BASE_DIR" "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" -G Ninja $CMAKE_PARAM fi echo -e "\n#### Building cmocka_mocks ($BUILD_TYPE) ####" DESTDIR="$LOCAL_INSTALL_DIR" \ ninja -C "$CMAKE_BUILD_DIR" $NINJA_PARAM all install 2>&1 | tee "$RESULT_DIR/build_log.txt" re=${PIPESTATUS[0]} "$BASE_DIR/ci/check_build_log.py" "$RESULT_DIR/build_log.txt" exit "$re" cmocka-mocks-0.52.1/ci/build_debs.sh000077500000000000000000000026031463302307500172000ustar00rootroot00000000000000#!/bin/bash -eu export DEBIAN_FRONTEND="noninteractive" export DEBEMAIL="noreply@test.com" CODENAME="${1:-jammy}" echo "Building .deb packages for series ${CODENAME}" echo "---" echo "NOTICE: make sure to clean up before running this! Debhelper will complain otherwise" # Install dependencies apt-get update apt-get install -y git debhelper devscripts equivs software-properties-common fakeroot add-apt-repository -y ppa:elos-team/ppa # Use the native packaging folder for building the .debs rm -rf debian cp -rv debian.native debian # parse the version from the project.cmake file VERSION="$(sed -n "s/^.*VERSION\s\+\([0-9]\+\.[0-9]\+\.[0-9]\+\).*$/\1/p" cmake/project.cmake)~test" # Add a new changelog entry git config --global --add safe.directory "$(pwd)" dch --newversion="${VERSION}" \ --distribution "${CODENAME}" "Test build" # Install dependencies yes | mk-build-deps -ir || true # Ignore Lintian errors from the native packaging mkdir -p debian/source echo "malformed-debian-changelog-version" >> debian/source/lintian-overrides echo "root-in-contact" >> debian/source/lintian-overrides echo "debian-watch-file-in-native-package" >> debian/source/lintian-overrides echo "odd-historical-debian-changelog-version" >> debian/source/lintian-overrides # Build the unsigned .debs fakeroot debuild --no-tgz-check -uc -us # Need to move the files into the project directory mv ../*.deb ./ cmocka-mocks-0.52.1/ci/build_doc.sh000077500000000000000000000012461463302307500170320ustar00rootroot00000000000000#!/bin/bash CMD_PATH=$(cd "$(dirname "$0")" && pwd) BASE_DIR=${CMD_PATH%/*} BUILD_TYPE="${1:-Debug}" BUILD_DIR="$BASE_DIR/build/$BUILD_TYPE/" CMAKE_BUILD_DIR="$BUILD_DIR/cmake" echo -e "\n#################" echo -e "##\tBuild $BUILD_TYPE" echo -e "#################\n" LOCAL_INSTALL_DIR=${LOCAL_INSTALL_DIR:-"$BUILD_DIR/dist"} export cmocka_mocks_DIR="$LOCAL_INSTALL_DIR/usr/local/lib/cmake/cmocka_mocks/" export cmocka_extensions_DIR="$LOCAL_INSTALL_DIR/usr/local/lib/cmake/cmocka_extensions" cmake -B "$CMAKE_BUILD_DIR" "$BASE_DIR" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -G Ninja ninja -v -C "$CMAKE_BUILD_DIR" -j$(nproc) cmocka_mocks_doc mv "$CMAKE_BUILD_DIR/doc" "$BUILD_DIR" cmocka-mocks-0.52.1/ci/check_build_log.py000077500000000000000000000015231463302307500202170ustar00rootroot00000000000000#!/usr/bin/env python3 """ Checks build log for warnings and errors and displays a summary of them. """ import sys print("#################################") summary_lines = [] count_errors = 0 count_warnings = 0 f = open(sys.argv[1], "r") lines = f.readlines() f.close() state_collect = False for line in lines: if "warning:" in line: state_collect = True count_warnings += 1 summary_lines.append(line) elif "error:" in line: state_collect = True count_errors += 1 summary_lines.append(line) elif state_collect: if line[0] == " " or line[0] == "\t": summary_lines.append(line) else: state_collect = False for line in summary_lines: print(line.strip()) print("Build finished with %i errors and %i warnings" % (count_errors, count_warnings)) cmocka-mocks-0.52.1/ci/checklicense.sh000077500000000000000000000025431463302307500175270ustar00rootroot00000000000000#!/bin/bash CMD_PATH=$(cd "$(dirname "$0")" && pwd) BASE_DIR=${CMD_PATH%/*} BUILD_DIR="$BASE_DIR/build/Debug" LICENSE_RESULT_DIR="${LINT_RESULT_DIR-${BUILD_DIR}/result/checklicense_results}" LICENSE="MIT" FINDINGS_LOGS="$LICENSE_RESULT_DIR/findings.log" function check_for_license { local SEARCH_PATH="$1" local SEARCH_PATTERN="$2" local LICENSE_HEADER="$3" local FINDINGS=0 for i in $(find "$SEARCH_PATH" -type f -name "$SEARCH_PATTERN" -not -path "$BASE_DIR/build*/*"); do local FIRST_LINE FIRST_LINE="$(head -n1 "$i")" if ! echo "$FIRST_LINE" | grep -Eqs "$LICENSE_HEADER" ; then echo "invalid header in $i expected:" | tee -a "$FINDINGS_LOGS" echo -e "$LICENSE_HEADER\nbut found\n$FIRST_LINE\n" | tee -a "$FINDINGS_LOGS" ((FINDINGS++)) fi done return $FINDINGS } mkdir -p "$LICENSE_RESULT_DIR" FINDINGS=0 check_for_license "$BASE_DIR" "*.h" "// SPDX-License-Identifier: $LICENSE" ((FINDINGS+=$?)) check_for_license "$BASE_DIR" "*.c" "// SPDX-License-Identifier: $LICENSE" ((FINDINGS+=$?)) check_for_license "$BASE_DIR" "CMakeLists.txt" "# SPDX-License-Identifier: $LICENSE" ((FINDINGS+=$?)) if [ $FINDINGS -eq 0 ]; then echo "LICENSE OK" | tee -a "$FINDINGS_LOGS" else echo "LICENSE CHECK FAILED ($FINDINGS issues)" | tee -a "$FINDINGS_LOGS" fi exit $FINDINGS cmocka-mocks-0.52.1/ci/clean.sh000077500000000000000000000003141463302307500161630ustar00rootroot00000000000000#!/bin/sh -eu CMD_PATH=$(cd "$(dirname "$0")" && pwd) BASE_DIR=${CMD_PATH%/*} echo "remove build directories" rm -rf \ "$BASE_DIR/build" \ "$BASE_DIR/doc/build" \ "$BASE_DIR/doc/source/generated" cmocka-mocks-0.52.1/ci/code_lint.py000077500000000000000000000544341463302307500170730ustar00rootroot00000000000000#!/usr/bin/env python3 """ Checks or fixes sources with clang-format """ import os import re import sys import glob import json import argparse import itertools import shutil import subprocess as sp def get_env(key, default=None): """ Gets the environment variable or a default value """ result = os.getenv(key, default) if result is None or result == "": result = default return result def test(error_code): """ Returns TEST SUCCESS or TEST FAILED based on the system code """ result = "TEST FAILED" if error_code == os.EX_OK: result = "TEST SUCCESS" return result def flatten_list(l): """ Returns a flattened list """ # https://stackoverflow.com/questions/952914/how-do-i-make-a-flat-list-out-of-a-list-of-lists return [item for sublist in l for item in sublist] def log_line(log_fh, line): """ Prints the given line to stdout and writes it to a file """ print(line) if log_fh: log_fh.write(line + "\n") def collect_sources_all(path_list): """ Collects all available sources (c and h files) in the given directory lists """ source_set = set() for path in path_list: for root, _, files in os.walk(path): for file in files: if file.endswith(".c") or file.endswith(".h"): source_set.add(os.path.abspath(os.path.join(root, file))) return source_set def prepare_compile_commands(cfg): """ Copy and adapt an existing compile_copmmands.json in a way that allows clang-tidy to run without errors due to gcc specific flags which clang does not understand """ print("Preparing compile_commands.json ..") ccj_src = os.path.join(cfg["build_dir"], 'compile_commands.json') ccj_dst = os.path.join(cfg["result_dir"], 'compile_commands.json') shutil.copyfile(ccj_src, ccj_dst) with open(ccj_dst, 'r+', encoding="utf-8") as json_fh: json_data = json.loads(json_fh.read()) json_fh.seek(0) json_fh.truncate() for i, _ in enumerate(json_data): if "command" in json_data[i]: cmd = json_data[i]["command"] cmd = cmd.replace("-fanalyzer ", "") json_data[i]["command"] = cmd json.dump(json_data, json_fh, indent=2) cfg["tidy_dir"] = cfg["result_dir"] def collect_sources_used(build_dir, json_file=None): """ Collects all available sources (c and h files) in the given compile_commands.json file """ source_set = set() json_dict_list = None if json_file is None: json_file = os.path.join(build_dir, 'compile_commands.json') with open(json_file, 'r', encoding="utf-8") as json_fh: json_dict_list = json.loads(json_fh.read()) inc_re = re.compile('(?:-I[^ ]+)|(?:-isystem [^ ]+)') for json_dict in json_dict_list: source = json_dict["file"] iparam = [x.group(0) for x in inc_re.finditer(json_dict["command"])] iparam = ' '.join(iparam).split(" ") command = ['cpp', '-MM', source, *iparam] output = sp.run(command, stdout=sp.PIPE, check=True) results = output.stdout.decode("utf-8").split() results = [ os.path.abspath(x) for x in results if x.endswith(".c") or x.endswith(".h") ] # Remove generated files like version.c from the list results = [ x for x in results if os.path.relpath(x, build_dir).startswith("..") ] source_set.update(results) return source_set def collect_sources_diff(base_dir, target_branch): """ Selects all sources (c and h files) that were modified and/or added between this branch and the target """ source_set = set() cwd = os.getcwd() os.chdir(base_dir) command = ["git", "rev-parse", "--show-toplevel"] output = sp.run(command, stdout=sp.PIPE, check=True) git_dir = output.stdout.decode("utf-8").strip() os.chdir(git_dir) command = ["git", "diff", "--name-status", target_branch] output = sp.run(command, stdout=sp.PIPE, check=True) if len(output.stdout) == 0: return source_set results = output.stdout.decode("utf-8").split("\n") results = [ x[2:] for x in results if x.startswith("M") or x.startswith("A") ] results = [ os.path.abspath(x) for x in results if x.endswith(".c") or x.endswith(".h") ] # Remove sources outside of base_dir results = [ x for x in results if not os.path.relpath(x, base_dir).startswith("..") ] source_set.update(results) os.chdir(cwd) return source_set def collect_sources_list_from_env(env_var, no_match_msg="Globs that don't match anything:"): """ Collect a list of sources from a list of globs in an enviroment variable. And print all the globs not matching any files. """ source_list = [] not_necessary = [] for x in get_env(env_var, "").split(" "): if len(x) <= 1: continue paths = glob.glob(x) if len(paths) == 0: not_necessary.append(x) else: source_list.append(paths) source_set = { os.path.abspath(x) for x in flatten_list(source_list) } if len(not_necessary) != 0: print(no_match_msg) for x in sorted(not_necessary): print(f" {x}") print("") return source_set def collect_sources_ignored(cfg): """ Collects ignored sources """ return collect_sources_list_from_env("IGNORE_SOURCES", "Not existing IGNORE_SOURCES globs:") def collect_sources_intentional_unused(cfg): """ Collect sources that are not used but shouldn't be ignored """ return collect_sources_list_from_env("UNUSED_SOURCES", "UNUSED_SOURCES globs not matcing anything:") def collect_sources(cfg): """ Collects all sources necessary for testing """ source_set = {} ignored_set = collect_sources_ignored(cfg) if "show_sources" not in cfg["steps"]: print("Linting with the following settings:") print(f"BASE_DIR = {cfg['base_dir']}") print(f"BUILD_DIR = {cfg['build_dir']}") print(f"LINT_RESULT_DIR = {cfg['result_dir']}") print("") if len(ignored_set) > 0: print("Ignored sources:") for source in sorted(ignored_set): print(f" {source}") print("") print("Collecting sources...") step_unused = sum([True for x in cfg["steps"] if x.endswith("unused")]) if cfg["collect_mode"] == "diff": branch = "integration" source_set["diff"] = collect_sources_diff(cfg["base_dir"], branch) source_set["diff"] -= ignored_set if cfg["collect_mode"] == "used" or step_unused: source_set["used"] = collect_sources_used(cfg['build_dir']) source_set["used"] -= ignored_set if cfg["collect_mode"] == "all" or step_unused: folders = [os.path.join(cfg['base_dir'], x) for x in ["src", "test"]] source_set["all"] = collect_sources_all(folders) source_set["all"] -= ignored_set source_set["intentionally_unused"] = collect_sources_intentional_unused( cfg) source_set["default"] = source_set[cfg["collect_mode"]] step_tidy = sum([True for x in cfg["steps"] if x.endswith("tidy")]) if step_tidy: mock_path = os.path.join(cfg["base_dir"], "test", "utest", "mocks") source_set["tidy"] = [ x for x in source_set["default"] if x.startswith(mock_path) is False] return source_set def show_sources(cfg, source_set): """ Simply prints a list of selectes sources """ sources = sorted(source_set[cfg["collect_mode"]]) for source in sources: print(source) return os.EX_OK def check_unused(cfg, source_set): """ Checks for unused files """ result = os.EX_OK state = "SUCCESS" log_file = os.path.join(cfg["result_dir"], "results_check_unused.txt") with open(log_file, 'w', encoding='utf-8') as log_fh: log_line(log_fh, "check_unused: Searching for unused files...") source_set_unused = source_set["all"].difference(source_set["used"]) source_set_known_unused = source_set_unused.intersection( source_set["intentionally_unused"]) source_set_unused -= source_set["intentionally_unused"] unused_file_count = len(source_set_unused) should_be_unused = source_set["used"].intersection( source_set["intentionally_unused"]) if unused_file_count > 0: log_line(log_fh, "Unused sources:") for file in sorted(list(source_set_unused)): log_line(log_fh, " " + file) log_line(log_fh, "") result = os.EX_DATAERR state = "FAILED" if len(source_set_known_unused) > 0: print("Known and expected unused sources:") for source in sorted(source_set_known_unused): print(f" {source}") print("") if len(should_be_unused) > 0: print("Specified as not used sources that are in use:") for source in sorted(should_be_unused): print(f" {source}") print("") result = os.EX_DATAERR state = "FAILED" log_line(log_fh, f"check_unused: TEST {state}; " + f"Found {unused_file_count} unused files!") return result def check_format(cfg, source_set): """ Checks the given set of sources with clang-format """ result = os.EX_SOFTWARE log_file = os.path.join(cfg["result_dir"], "results_check_format.txt") dump_file = os.path.join(cfg["result_dir"], "output_clang_format.txt") sources = source_set[cfg["collect_mode"]] error_lines = 0 with open(log_file, 'w', encoding='utf-8') as log_fh, \ open(dump_file, 'bw') as dump_fh: log_line(log_fh, "check_format: Verify formatting with clang-format..") if len(sources) == 0: log_line(log_fh, "check_format: TEST SKIPPED; No sources found.") return os.EX_OK log_fh.write("---- clang-format output start ---\n") params = ["--dry-run", "-Werror"] command = ["clang-format", *params, *sources] with sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT) as proc: buffer = "" while True: byte = proc.stdout.read(1) if byte: dump_fh.write(byte) buffer += byte.decode("utf-8") if buffer[-1] == '\n': if buffer.find(": error:") >= 0: error_lines += 1 result = os.EX_DATAERR log_line(log_fh, buffer) buffer = "" else: break result = proc.wait() log_fh.write("---- clang-format output stop ---\n") log_line(log_fh, f"check_format: {test(result)}; " + f"Found {error_lines} errors " + f"in {len(sources)} scanned files.") return result def check_tidy(cfg, source_set): """ Format the given set of sources with clang-format """ result = os.EX_OK log_file = os.path.join(cfg["result_dir"], "results_check_tidy.txt") dump_file = os.path.join(cfg["result_dir"], "output_clang_tidy.txt") sources = source_set["tidy"] error_lines = 0 with open(log_file, "w", encoding="utf-8") as log_fh, \ open(dump_file, "bw") as dump_fh: log_line(log_fh, "check_tidy: Verify formatting with clang-tidy..") if len(sources) == 0: log_line(log_fh, "check_tidy: TEST SKIPPED; No sources found.") return result log_fh.write("---- clang-tidy output start ---\n") command_params = [ "--extra-arg-before=-Wno-error=unknown-warning-option", "-p", cfg["tidy_dir"] ] command = ["clang-tidy", *command_params, *sources] with sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT) as proc: buffer = "" while True: byte = proc.stdout.read(1) if byte: dump_fh.write(byte) buffer += byte.decode("utf-8") if buffer[-1] == '\n': if buffer.find("warnings generated.") >= 0: pass elif buffer.find(": error:") >= 0: log_line(log_fh, buffer) error_lines += 1 result = os.EX_DATAERR else: log_line(log_fh, buffer) buffer = "" else: break result = proc.wait() log_fh.write("---- clang-tidy output stop ---\n") log_line(log_fh, f"check_tidy: {test(result)}; " + f"Found {error_lines} errors " + f"in {len(sources)} scanned files.") return result def fix_unused(cfg, source_set): """ Checks for unused files """ del cfg result = os.EX_OK source_set_unused = source_set["all"].difference(source_set["used"]) unused_file_count = len(source_set_unused) if unused_file_count > 0: print("fix_unused: Removing files...") for file in sorted(list(source_set_unused)): print(" " + file) os.unlink(file) print() print(f"fix_unused: Removed {unused_file_count} files.") else: print("fix_unused: No unused files found to remove.") return result def fix_format(cfg, source_set): """ Format the given set of sources with clang-format """ result = os.EX_SOFTWARE sources = source_set[cfg["collect_mode"]] command = ["clang-format", "-i", *sources] print("fix_format: Try to fix formatting in sources") if len(sources) == 0: print("fix_format: TEST SKIPPED; No sources found.") return os.EX_OK with sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT) as proc: while True: byte = proc.stdout.read(1) if byte: sys.stdout.buffer.write(byte) sys.stdout.flush() else: break result = proc.wait() print(f"fix_format: {len(sources)} files were formatted.") return result def fix_tidy(cfg, source_set): """ Format the given set of sources with clang-tidy """ result = os.EX_SOFTWARE sources = source_set["tidy"] command_params = [ "--fix-errors", "--extra-arg=-Wno-error=unknown-warning-option", "--warnings-as-errors=-*", "-p", cfg["tidy_dir"] ] command = ["clang-tidy", *command_params, *sources] print("fix_tidy: Try to fix formatting in sources") if len(sources) == 0: print("fix_tidy: TEST SKIPPED; No sources found.") return os.EX_OK with sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT) as proc: buffer = "" while True: byte = proc.stdout.read(1) if byte: buffer += byte.decode("utf-8") if buffer[-1] == '\n': if buffer.find("warnings generated.") < 0: print(buffer) buffer = "" else: break result = proc.wait() print(f"fix_tidy: {len(sources)} files were formatted.") return result def parameter_process_steps(args, cfg): """ Sets the steps to be executed """ cfg["steps"] = set() steps_def = [["format", "f"], ["tidy", "t"]] steps_all = [["unused", "u"], *steps_def] steps = [*steps_all, ["all", "a"]] if args.ci: cfg["steps"].update([f"check_{x[0]}" for x in steps_all]) return cfg if args.show: cfg["steps"].add("show_sources") return cfg modes = {"check": args.check, "fix": args.fix} active_modes = [x[0] for x in modes.items() if x[1] is not None] for key in active_modes: if len(modes[key]) == 0: cfg["steps"].update([f"{key}_{s[0]}" for s in steps_def]) continue for value in modes[key]: found = False for step in steps: if value in step: cfg["steps"].add(f"{key}_{step[0]}") found = True break if not found: values = ", ".join(itertools.chain(*steps)) print(f"{sys.argv[0]}: error: " + f"Unknown value '{value}', valid values are: {values}") sys.exit(os.EX_USAGE) if f"{key}_all" in cfg["steps"]: cfg["steps"].remove(f"{key}_all") cfg["steps"].update([f"{key}_{s[0]}" for s in steps_all]) return cfg def parameter_process_directories(args, cfg): """ Processes parameters and environment to set used directories """ cfg["base_dir"] = args.base_dir if cfg["base_dir"] is None: default = os.path.join(os.path.dirname(sys.argv[0]), '..') cfg["base_dir"] = get_env("BASE_DIR", default) cfg["base_dir"] = os.path.abspath(cfg["base_dir"]) if os.path.exists(cfg["base_dir"]) is False: print(f"{sys.argv[0]}: error: " + f"BASE_DIR path '{cfg['base_dir']}' does not exist!") sys.exit(os.EX_OSFILE) cfg["build_dir"] = args.build_dir if cfg["build_dir"] is None: default = os.path.join(cfg["base_dir"], 'build', 'Debug', 'cmake') if args.ci: default = os.path.join( cfg["base_dir"], 'build', 'Release', "cmake") cfg["build_dir"] = get_env("BUILD_DIR", default) cfg["build_dir"] = os.path.abspath(cfg["build_dir"]) if os.path.exists(cfg["build_dir"]) is False: print(f"{sys.argv[0]}: error: " + f"BUILD_DIR path '{cfg['build_dir']}' does not exist!") sys.exit(os.EX_OSFILE) cfg["result_dir"] = args.result_dir if cfg["result_dir"] is None: default = os.path.join(cfg["build_dir"], 'lint_results') cfg["result_dir"] = get_env("LINT_RESULT_DIR", default) cfg["result_dir"] = os.path.abspath(cfg["result_dir"]) cfg["tidy_dir"] = cfg["result_dir"] if os.path.exists(cfg["result_dir"]) is False: os.mkdir(cfg["result_dir"]) return cfg def parameter_process(args, cfg): """ Sets the default values for unset parameters and a few other things """ if args.ci: cfg["ci"] = True cfg["collect_mode"] = "all" else: cfg["ci"] = False mode = {0: "diff", 1: "all", 2: "diff", 4: "used"} cfg["collect_mode"] = mode[ int(args.select_all) << 0 | int(args.select_diff) << 1 | int(args.select_used) << 2 ] cfg = parameter_process_steps(args, cfg) cfg = parameter_process_directories(args, cfg) return cfg def parameter_parse(): """ Parses command line arguments """ parser = argparse.ArgumentParser( description="Tool for checking and fixing source formatting") grp_mode = parser.add_mutually_exclusive_group(required=True) grp_mode.add_argument( "-c", "--check", nargs="*", help="Checks sources (unused sources, " + "clang-format, clang-tidy) and shows errors.") grp_mode.add_argument( "-f", "--fix", nargs="*", help="Try to fix sources (remove unused files," + " format with clang-format and clang-tidy). " + " MAY DAMAGE FILES, be sure to commit everything beforehand.") grp_mode.add_argument( "-s", "--show", action="store_true", help="Prints a list of selected sources") grp_mode.add_argument( "--ci", action="store_true", help="Special mode intended for use in " + "continuous integration, uses all tests and " + "./build/Release as build-dir per default.") grp_select = parser.add_mutually_exclusive_group(required=False) grp_select.add_argument( "-d", "--select-diff", action="store_true", help="Selects sources based on git branch " + "differences compare to the 'integration' branch (default)") grp_select.add_argument( "-u", "--select-used", action="store_true", help="Selects sources based on compile_commands.json" + "(only uses compiled files, slow)") grp_select.add_argument( "-a", "--select-all", action="store_true", help="Selects all sources in src and test") parser.add_argument( "--base-dir", help="Base directory (e.g. ./) to use; " + "Can also be set with 'export BASE_DIR'") parser.add_argument( "--build-dir", help="Build directory (e.g. ./build) to use; " + "Can also be set with 'export BUILD_DIR'") parser.add_argument( "--result-dir", help="Result directory " + "(e.g. ./build/lint_result) to use; " + "Can also be set with 'export LINT_RESULT_DIR'") args = parser.parse_args() return args def execute_steps(cfg, source_set): """ Runs every specified step and returns an appropriate success/error code """ result = os.EX_OK results = [] function = dict(x for x in globals().items() if callable(x[1])) for step in cfg["steps"]: if step not in function: raise Exception(f"No function exists for step '{step}'!") result = function[step](cfg, source_set) results.append(result) info = None failures = len([x for x in results if x != os.EX_OK]) if failures > 0: result = os.EX_DATAERR info = f"FAILED; {failures} of {len(results)} steps failed!" else: info = f"SUCCESS; {len(results) - failures} " +\ f"of {len(results)} steps executed successfully." if "show_sources" not in cfg["steps"]: print(info) return result def main(): """ Main function, called during command line operation """ args = parameter_parse() cfg = parameter_process(args, {}) source_set = collect_sources(cfg) if len(source_set) == 0: print("No sources found." + " Perhaps try --select-json or --select-all? (see --help)") sys.exit(os.EX_NOINPUT) if "check_tidy" in cfg["steps"] or "fix_tidy" in cfg["steps"]: prepare_compile_commands(cfg) result = execute_steps(cfg, source_set) sys.exit(result) if __name__ == "__main__": main() cmocka-mocks-0.52.1/ci/docker-run.sh000077500000000000000000000020571463302307500171600ustar00rootroot00000000000000#!/bin/sh -e # # create and run docker build env # CMD_PATH=$(cd "$(dirname "$0")" && pwd) BASE_DIR=${CMD_PATH%/*} PROJECT=cmocka-extensios IMAGE_NAME="${PROJECT}-build" if [ -f "${HOME}/.ssh/asmcov_token" ]; then echo "Loading asmcov token from ${HOME}/.ssh/asmcov_token." . "${HOME}/.ssh/asmcov_token" fi echo "==> create docker image" cd "$BASE_DIR/ci" docker build \ --build-arg UID=$(id -u) --build-arg GID=$(id -g) \ --build-arg ASMCOV_URI="${ASMCOV_URI-not available}" \ --tag ${IMAGE_NAME} -f Dockerfile . echo "==> run $PROJECT build container" if ! [ -e "$BASE_DIR"/ci/sshconfig ]; then { echo "Host *" echo " User $(id -u -n)" } > "$BASE_DIR"/ci/sshconfig fi if [ "$SSH_AUTH_SOCK" ]; then SSH_AGENT_SOCK=$(readlink -f "$SSH_AUTH_SOCK") SSH_AGENT_OPTS="-v $SSH_AGENT_SOCK:/run/ssh-agent -e SSH_AUTH_SOCK=/run/ssh-agent" fi docker run --rm -it $SSH_AGENT_OPTS \ -v "$BASE_DIR":/base \ -w /base \ -e GIT_USER_TOKEN="${GIT_USER_TOKEN}" \ --privileged \ --device=/dev/kmsg \ $IMAGE_NAME "$@" cmocka-mocks-0.52.1/ci/package.sh000077500000000000000000000003551463302307500165010ustar00rootroot00000000000000#!/bin/bash set -e -u -o pipefail CMD_PATH=$(realpath "$(dirname "$0")") BASE_DIR=${CMD_PATH%/*} BUILD_TYPE="${1:-Release}" BUILD_DIR="$BASE_DIR/build/$BUILD_TYPE" CMAKE_BUILD_DIR="$BUILD_DIR/cmake" cd "$CMAKE_BUILD_DIR" cpack -G DEB cmocka-mocks-0.52.1/cmake/000077500000000000000000000000001463302307500152315ustar00rootroot00000000000000cmocka-mocks-0.52.1/cmake/ConfigureLibrary.cmake000066400000000000000000000033031463302307500215000ustar00rootroot00000000000000# SPDX-License-Identifier: MIT cmake_minimum_required(VERSION 3.21) include(FetchContent) set(FETCHCONTENT_QUIET OFF) set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE ALWAYS) function(configureLibrary LIBRARY_NAME LIBRARY_REPOSITORY LIBRARY_TAG) message("#### Configuring external library ${LIBRARY_NAME} (${CMAKE_BUILD_TYPE}) ####") if(LIBRARY_NAME STREQUAL "") message(FATAL_ERROR "Parameter LIBRARY_NAME is not set. Exiting.") endif() message("Searching for ${LIBRARY_NAME}") find_package(${LIBRARY_NAME} QUIET) if(${LIBRARY_NAME}_FOUND) message("Found ${LIBRARY_NAME}") return() endif() message("Did not find ${LIBRARY_NAME}") if (LIBRARY_REPOSITORY STREQUAL "") message(FATAL_ERROR "Parameter LIBRARY_REPOSITORY is not set. Exiting.") elseif(LIBRARY_TAG STREQUAL "") set(LIBRARY_TAG "integration") endif() SET(LOCAL_REPO_DIR ${LIBRARY_REPOSITORY}) if (NOT EXISTS ${LIBRARY_REPOSITORY}) message("Fetching ${LIBRARY_NAME}") FetchContent_Declare( ${LIBRARY_NAME} GIT_REPOSITORY ${LIBRARY_REPOSITORY} GIT_TAG ${LIBRARY_TAG} ) FetchContent_MakeAvailable(${LIBRARY_NAME}) SET(LOCAL_REPO_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/${LIBRARY_NAME}-src/) while(NOT EXISTS ${LOCAL_REPO_DIR}/ci/build.sh) execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 0.5) endwhile() message("Done fetching") endif() message("Building ${LIBRARY_NAME}") set(ENV{LOCAL_INSTALL_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../dist) execute_process( COMMAND ${LOCAL_REPO_DIR}/ci/build.sh ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY "${LOCAL_REPO_DIR}" COMMAND_ECHO STDOUT ) message("Done building") find_package(${LIBRARY_NAME} QUIET) endfunction() cmocka-mocks-0.52.1/cmake/Packing.cmake000066400000000000000000000033531463302307500176130ustar00rootroot00000000000000# SPDX-License-Identifier: MIT # these are cache variables, so they could be overwritten with -D, set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) # which is useful in case of packing only selected components instead of the whole thing set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cmocka Mocks used in elos, safu and samconf") set(CPACK_PACKAGE_VENDOR "emlix") set(CPACK_DEBIAN_PACKAGE_DEPENDS "cmocka_extensions") set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) SET(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_SOURCE_DIR}/build/packages") # https://unix.stackexchange.com/a/11552/254512 set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) set(CPACK_PACKAGE_CONTACT "info@emlix.com") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Anton Hillebrand") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") # package name for deb. If set, then instead of some-application-0.9.2-Linux.deb # you'll get some-application_0.9.2_amd64.deb (note the underscores too) set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) # that is if you want every group to have its own package, # although the same will happen if this is not set (so it defaults to ONE_PER_GROUP) # and CPACK_DEB_COMPONENT_INSTALL is set to YES set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE) # without this you won't be able to pack only specified component set(CPACK_DEB_COMPONENT_INSTALL YES) FILE(GLOB_RECURSE MOCK_LIBS "${CMAKE_SOURCE_DIR}/build/Release/cmake/src/*/*.so") install(FILES ${MOCK_LIBS} DESTINATION /opt/${CPACK_PACKAGE_VENDOR}/lib/) include(CPack) cmocka-mocks-0.52.1/cmake/index.rst000066400000000000000000000002231463302307500170670ustar00rootroot00000000000000CMake options ============= ENABLE_ASAN=[on|off] -------------------- default: on Control if cmocka_mocks should be build with address sanitizer cmocka-mocks-0.52.1/cmake/project.cmake000066400000000000000000000076651463302307500177170ustar00rootroot00000000000000# SPDX-License-Identifier: MIT set(CMOCKA_MOCKS_VERSION 0.52.1) # Attention: Aside from the version, as many things as possible in this file # should be put into functions, as this solves potential issues with commands # being run before "project()" gets called in the including CMakeLists.txt. # It also does not force the usage of everything at once which can be useful, # should we need to do things different in one of the projects in the future. macro(project_set_environment) set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_FLAGS_DEBUG "") set(CMAKE_C_FLAGS_RELEASE "") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(GNUInstallDirs) option(UNIT_TESTS "Build unit tests" ON) option(ENABLE_ANALYZER "Build with -fanalyzer" ON) option(ENABLE_CI "Use CI mode for building" OFF) option(INSTALL_UNIT_TESTS "Install unit tests" ON) option(ENABLE_ASAN "Link with ASAN" ON) add_compile_options( -Wshadow -Wall -Wextra -pedantic -D_DEFAULT_SOURCE ) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") if (ENABLE_ASAN) link_libraries(asan) add_compile_options(-fsanitize=address) endif() add_compile_options( -Og -g3 -DDEBUG -fno-omit-frame-pointer $,-fanalyzer,> $,-Wno-analyzer-malloc-leak,> ) elseif(CMAKE_BUILD_TYPE STREQUAL "Release") add_compile_options(-O3 -DNDEBUG -g $,-Werror,>) elseif(CMAKE_BUILD_TYPE STREQUAL "Profiling") add_compile_options(-O3 -DNDEBUG -g -fno-omit-frame-pointer) elseif(CMAKE_BUILD_TYPE STREQUAL "Tsan") link_libraries(tsan) add_compile_options( -Og -g3 -DDEBUG -fsanitize=thread -fno-omit-frame-pointer $,-fanalyzer,> $,-Wno-analyzer-malloc-leak,> ) endif() endmacro() find_package(Git REQUIRED) function(project_set_version_variables) if(ARGN) cmake_parse_arguments(PSVV "" "NAME" "" ${ARGN}) set(prj_name ${PSVV_NAME}) else() set(prj_name ${PROJECT_NAME}) endif() string(TOUPPER ${prj_name} prefix) set(ver_major_name "${prefix}_VERSION_MAJOR") set(ver_minor_name "${prefix}_VERSION_MINOR") set(ver_micro_name "${prefix}_VERSION_MICRO") set(ver_git_name "${prefix}_VERSION_GIT") set(ver_pkg "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(${ver_major_name} ${PROJECT_VERSION_MAJOR} PARENT_SCOPE) set(${ver_minor_name} ${PROJECT_VERSION_MINOR} PARENT_SCOPE) set(${ver_micro_name} ${PROJECT_VERSION_PATCH} PARENT_SCOPE) set(PKG_VERSION ${ver_pkg} PARENT_SCOPE) execute_process( COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE exit_code OUTPUT_VARIABLE git_output OUTPUT_STRIP_TRAILING_WHITESPACE ) if(NOT exit_code EQUAL 0) message(WARNING "failed to retrive git short commit hash") set(git_output "none") endif() set(${ver_git_name} ${git_output} PARENT_SCOPE) message(STATUS "-- Set version for ${prj_name}: ${ver_pkg}.${git_output}") endfunction() function(project_add_documentation_target) if (TARGET cmocka_mocks_doc) return() endif () cmake_parse_arguments(PARAM "" "MARKDOWN;TITLE" "" ${ARGN}) find_program(PLANTUML NAMES plantuml) find_program(PANDOC NAMES pandoc) add_custom_target( cmocka_mocks_doc mkdir -p ${CMAKE_BINARY_DIR}/doc/images && ${PLANTUML} ${CMAKE_SOURCE_DIR}/documentation/images/*.plantuml && ${PANDOC} -s --from gfm --to html --filter pandoc-plantuml -o ${CMAKE_BINARY_DIR}/doc/${PROJECT_NAME}_doc.html --css style.css ${PARAM_MARKDOWN} --metadata title='${PARAM_TITLE}' && cmake -E copy_if_different ${CMAKE_SOURCE_DIR}/documentation/style.css doc/ && cmake -E copy_if_different ${CMAKE_SOURCE_DIR}/documentation/images/*.png doc/images/ ) endfunction() cmocka-mocks-0.52.1/debian.native/000077500000000000000000000000001463302307500166605ustar00rootroot00000000000000cmocka-mocks-0.52.1/debian.native/.gitignore000066400000000000000000000002761463302307500206550ustar00rootroot00000000000000/*.substvars /files /debhelper-build-stamp /libcmocka-mocks-dev/ /libmock-jsonc0/ /libmock-libc0/ /libmock-libmnl0/ /libmock-openssl0/ /cmocka-mocks-doc/ /.debhelper/ /tmp/ /*.debhelper.log cmocka-mocks-0.52.1/debian.native/README.md000066400000000000000000000042041463302307500201370ustar00rootroot00000000000000# cmocka_mocks Debian Packaging Scripts ## Overview This directory contains Debian packaging scripts for building the current source tree as .deb packages. This is primarily for CI pipelines to automatically verify if the packages are buildable or if anything needs to be changed. This is not intended to be used directly for building .deb packages for new releases. ## Building The .deb packages are constructed in the standard Debian way using `debhelper`. The easiest way to build the packages is to just call the `ci/build_debs.sh` script from the top-level directory from inside a Docker/Podman container, which will automatically install all of the necessary dependencies, set the package version, and build the packages using `debhelper`. It's possible to do this all in one line to verify if the packages are buildable on various Debian-based distributions and series. E.g., to build it on Ubuntu Jammy: ```bash podman run --rm -v $(pwd):/build -w /build ubuntu:jammy ci/build_debs.sh ``` Please note that there are some dependencies which are not (yet) in the Debian or Ubuntu archives. These have been built and published for Ubuntu in the [elos PPA](https://launchpad.net/~elos-team/+archive/ubuntu/ppa), which is automatically added by the `ci/build_debs.sh` script. This currently restricts builds using the script to Ubuntu systems, as PPAs are not available on other distributions. ## Extending The Debian packaging scripts leverage the existing CMake build system used by cmocka_mocks to build everything, meaning that very little, if anything, generally needs to be changed inside the packaging scripts when a code change is made to cmocka_mocks. The major exception to this is when new libraries or files need to be installed. In most cases, new files and/or folders can be added to the `.install` file corresponding to the package name that the new files and/or folders should belong to. New packages must be added to the `control` file, and their respective files should be added to a new `.install` file matching the name of the new package. ## Packaging Script Maintainer * Isaac True isaac.true@emlix.com [@IsaacJT](https://github.com/IsaacJT) cmocka-mocks-0.52.1/debian.native/changelog000066400000000000000000000002121463302307500205250ustar00rootroot00000000000000cmocka-mocks (0.0.1) unstable; urgency=medium * Dummy release. -- Isaac True Mon, 27 May 2024 17:18:42 +0200 cmocka-mocks-0.52.1/debian.native/cmocka-mocks-doc.install000066400000000000000000000000571463302307500233640ustar00rootroot00000000000000documentation/* /usr/share/doc/cmocka-mocks/ cmocka-mocks-0.52.1/debian.native/cmocka-mocks-doc.lintian-overrides000066400000000000000000000001361463302307500253520ustar00rootroot00000000000000cmocka-extensions-doc: zero-byte-file-in-doc-directory [usr/share/doc/cmocka-mocks/style.css] cmocka-mocks-0.52.1/debian.native/control000066400000000000000000000041731463302307500202700ustar00rootroot00000000000000Source: cmocka-mocks Section: admin Priority: optional Maintainer: Isaac True Build-Depends: debhelper-compat (= 13), cmake, git, libcmocka-dev, cmocka-extensions-dev, libmnl-dev, libjson-c-dev, pkg-config, libssl-dev, pandoc, pandoc-plantuml-filter, graphviz, Rules-Requires-Root: no Standards-Version: 4.6.0.1 Homepage: https://github.com/Elektrobit/cmocka_mocks Vcs-Browser: https://github.com/Elektrobit/cmocka_mocks Vcs-Git: https://github.com/Elektrobit/cmocka_mocks Package: libmock-jsonc0 Section: libdevel Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, libjson-c-dev, Description: Mock library for libjsonc Mock library for libjsonc generated by cmocka-cmocks. Package: libmock-libc0 Section: libdevel Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, Description: Mock library for libc Mock library for libc generated by cmocka-cmocks. Package: libmock-libmnl0 Section: libdevel Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, libmnl-dev, Description: Mock library for libmnl Mock library for libmnl generated by cmocka-cmocks. Package: libmock-openssl0 Section: libdevel Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, libssl-dev, Description: Mock library for openssl Mock library for openssl generated by cmocka-cmocks. Package: libcmocka-mocks-dev Section: libdevel Architecture: any Depends: ${misc:Depends}, libmock-jsonc0 (= ${binary:Version}), libmock-libmnl0 (= ${binary:Version}), libmock-libc0 (= ${binary:Version}), libmock-openssl0 (= ${binary:Version}), cmocka-extensions-dev, Description: Library to mock common C functions for testing purposes Library to mock common C functions, like libc and jsonc, for testing purposes. This collection of ready to use mocks is based on cmocka_extensions. . Development package. Package: cmocka-mocks-doc Section: doc Architecture: all Depends: ${misc:Depends}, Description: Documentation for cmocka-mocks Library to mock common C functions, like libc and jsonc, for testing purposes. This collection of ready to use mocks is based on cmocka_extensions. . Documentation package. cmocka-mocks-0.52.1/debian.native/copyright000066400000000000000000000025221463302307500206140ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: cmocka_mocks Upstream-Contact: https://github.com/Elektrobit/cmocka_mocks/issues Source: https://github.com/Elektrobit/cmocka_mocks Files: * Copyright: 2023, Elektrobit GmbH 2023, emlix GmbH License: MIT License: MIT 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. cmocka-mocks-0.52.1/debian.native/libcmocka-mocks-dev.install000066400000000000000000000000631463302307500240610ustar00rootroot00000000000000usr/include usr/lib/*/cmake usr/lib/*/libmock_*.so cmocka-mocks-0.52.1/debian.native/libmock-jsonc0.install000066400000000000000000000000351463302307500230600ustar00rootroot00000000000000usr/lib/*/libmock_jsonc.so.* cmocka-mocks-0.52.1/debian.native/libmock-libc0.install000066400000000000000000000000341463302307500226540ustar00rootroot00000000000000usr/lib/*/libmock_libc.so.* cmocka-mocks-0.52.1/debian.native/libmock-libmnl0.install000066400000000000000000000000361463302307500232220ustar00rootroot00000000000000usr/lib/*/libmock_libmnl.so.* cmocka-mocks-0.52.1/debian.native/libmock-libmnl0.lintian-overrides000066400000000000000000000001241463302307500252100ustar00rootroot00000000000000library-not-linked-against-libc [usr/lib/x86_64-linux-gnu/libmock_libmnl.so.0.51.0] cmocka-mocks-0.52.1/debian.native/libmock-openssl0.install000066400000000000000000000000371463302307500234310ustar00rootroot00000000000000usr/lib/*/libmock_openssl.so.* cmocka-mocks-0.52.1/debian.native/libmock-openssl0.lintian-overrides000066400000000000000000000001251463302307500254170ustar00rootroot00000000000000library-not-linked-against-libc [usr/lib/x86_64-linux-gnu/libmock_openssl.so.0.51.0] cmocka-mocks-0.52.1/debian.native/rules000077500000000000000000000007001463302307500177350ustar00rootroot00000000000000#!/usr/bin/make -f export DEB_BUILD_MAINT_OPTIONS = hardening=+all %: dh $@ --buildsystem=cmake --builddirectory=debian/build override_dh_auto_build: dh_auto_build -- all cmocka_mocks_doc override_dh_install: dh_install # Do not ship plantuml source files find debian/ -name \*.plantuml -delete override_dh_compress: # Do not compress .md files dh_compress --exclude=.md override_dh_clean: dh_clean rm -f documentation/images/*.png cmocka-mocks-0.52.1/debian.native/source/000077500000000000000000000000001463302307500201605ustar00rootroot00000000000000cmocka-mocks-0.52.1/debian.native/source/format000066400000000000000000000000151463302307500213670ustar00rootroot000000000000003.0 (native) cmocka-mocks-0.52.1/debian.native/watch000066400000000000000000000001431463302307500177070ustar00rootroot00000000000000version=4 https://github.com/Elektrobit/cmocka_mocks/tags .*/cmocka_mocks-(\d+).(\d+).(\d+).tar.gz cmocka-mocks-0.52.1/doc/000077500000000000000000000000001463302307500147165ustar00rootroot00000000000000cmocka-mocks-0.52.1/doc/source/000077500000000000000000000000001463302307500162165ustar00rootroot00000000000000cmocka-mocks-0.52.1/doc/source/_static/000077500000000000000000000000001463302307500176445ustar00rootroot00000000000000cmocka-mocks-0.52.1/doc/source/_static/eb-logo.png000066400000000000000000000415521463302307500217050ustar00rootroot00000000000000PNG  IHDR~[BPLTEjEtRNS9KZjz{iXG5"$3+?^w[= 8ShyoE. /Uԫ0-R׹}: pܳbuL7qOY(I2xWѕMDfcgs#|e \t<)4, ;~V@m*J>&v`TCͶB Qk1ɿ]nAdPH!a%ؼ6r'N_FlvΗ?IDATxg`U'HG"-H^H>"M@( J$$ tޛHUz l%&[瞙y73{$Xtϐ1S,Y==000(G#G!!y_c*ʽRK^pŒ)^p'Kbē%3*]l垊,_bҭAUZ-sgjd;k Sn4lĽZ4nҴ@Gk*ehXP8J6mo׾C*ѣ;v޹s]WOKL5ݚD<߭{UzP>s~ܑR+e`Ώ<+d24*q#JkýzUѸ ѹtY Gv`4wtqyc093nܱqo@*{ķR;ӏ$Ԕ!q!"d:M;-"ėg?{!g㸃VŠȉ:3Sf߇1ZqЕ*f(&w9Ԩܜ|OS[8˞ L𮑅vSff:n1 =`3/q!jqKBভsʒ˸5+v"ת܂eMwuqC|O.YZnӰܲ0|nIW~8;z|M& ,[?9EsTS+Klsx`.SGo#O/ :UǽjngPȫ^܋'͠2Qs_Tvk6n;5>RWl D;t31CNlkzJO}Of:s8)Ο~)T ɽ\#!;ԏ)V#TyKͺbJmԲAPEq`tr!y/ofreW h}Z*GyNo1Tq/ՐڟU#d&PPYWjL⿧kBPm㦓2j*_m)HA'i`֒oQ2 ͏DM?LPNWip  @wI~Bɮ@WˑN#?u`?wTF`.1xÎ+xXƒ]R~M~jUR,]/JəCB]HȧCMo~eS%wwr3|0=6Yx<^#Ns{I/>?}i@mgVeeMScwɀ|$QkG#|5H3fP}/apuFvJ6L9Wӊ"c O|߮Qw2cs,&/ ֧*:,+i>o} $.i}NWr6Fd3A&A_,Bo=}(]sJŀzo-%ioƧG}^؂8կG[buC.-vPtnWAC3 !Q(= m~Yuf+.Y8Z,KsB$j?E;"F(R?'0G9pctgb}$ ElF8v[e]hWQcWØf^j~%y^lC_KrSoґo\V? hƈy/.UQVj\`}߃#"4CbU?,bG *#̾GnEu]PᘇX+W7ĈDz[ʑmH8#uK  $hDQˆ] }R%DktAp^ӳ>ۍzifVyA!e#'")9?IzJŗդ(T7QE ]ZQޗV˯{VLߙ=(|;><ǭ$g2-Zn_4 ||dS=hS9Ms.a/<@GP«'->;Ƃg[EB]!׀PW7>F'TbfRZ[b FW޾&Dw-!!Sq:+4 qcn*OlE+WZ}T\~;[?R:t2$uLIo`gm7S\ e/$`=󈷹sœ7bKP cA Uz: v|w(fMve-$aJ]Ev5ޚT[9ZnzdY" R/)ozz;|4lG ݅;@+%zKz1OoqK$T?h=mANa%jCw pZ_I6h?TA Z):'p!ʟ厃Tr Z[ ! ňuCJ aw [ !4LjU;.2רaHWJsWF(HaaAU@"8 j")LSer(p#k ,ن_8wF@j]TB:unyPVc@(@eTTr QsAm>wԁz:-@ŕrA*ƥnРֺy{RҢ0ʠr#Pqz\p#VE{Ÿp A`IJέ>q*Rba5ʠr#u⎃y\jS2LnuD-FyqP]ŭB0Z玃p" CnyDpU8hhk)ZQG(jweIQ" jѮtP#Qʭ@T?ѿ#da./m^T .zZ/@*b e0J2(n}#UK8HHooJT[. 2RaQ{3 6배`V#p6@7 S?ˏp+DmP/ h배l>BjG밭A,۠2ReQ-=A=dذTF4lzTTL=0JpkDmPte7nȱ GSA=rGFMJj^zM8V۠e4ډ9ajADLCҎ=fМku"6'P%riUJWn PaJYvlPdsDmPTPӴ!&1d=RO0 i7 gPEnh (-qB5޵0 JQ:nGq­)A݃d+3\[+Rlg? *YK4uKx4>naU)ĭ%ADW-[A݂1cA㖋۠] T?i3Рrn ꎿ`މ/~ HN S 0t00%4n ꆷpxiҠ'j4-`{LI! *֌ ۠i3ў&5|l4 ㌓,EgpFm4| M5ӜtU~MM@ߴ~s *ImP'weY8ȭ ۠N`S5NK"x}.pK6C>Ia\D]-{6zbOt7 a>ݰV?{xZ-6}:G2[H,Aq $+Kr_7|ZͽleS.O(vCoX6h m;ml&>%mMpCMi`4 pQ8u> Wa4QxǣK qWd~º=p݇+ #ZE Z|TzcȺwzw"?/XР]f=pwCTMrt6}gA{^^FȉL*"8ΰ_t}ßM0gk[X3'}w2c ]_fA0`4ũs}F._dZ7*Zɩ 6]^dddmoo`6tIHH8tD1K4{hl̟-t;"Nw՟VhC=Tt>bh +ݗT5ik ̾nСeM,Y Țǡ&o> ԟX5$d 98)ǘנ cm(ؠr'14rK!tRS󜦓UV?-nQ;μGG̓6; sm1h靫aѠ3Ag ʂe?%i:w`4oV%eЊqka>nǿܡ) zp& "gҫ|蠬I$AlHd3QIMJ|ПTy,wFЍAk9J݈@mȵuCī6Vuʟt: 2S厒?G 7T+'QM?%8Q'Ov3A7 B)I6rGJ2V [ SY1q$iEܺ`O:e#t%^KiD. f2 , z[ Ϸ;=[,ɠM5.XɠUMY*ZC~Wz(*{VIy,ct35ʚg#ǣIAp끡C[728l09mJ"Y="(N>mkiP.Ҡ&ߪwb2|;;` +H#ҠE,t w4Sy5,,ّ;VujЛܢ ,U)`;wD($ܠ6nU%"{$+0^mDJ'0 =BXQY;D*VZls+eb Z/j ܟ`}'?+eREmP\nm~̟PTdij/wtH\Y1T@Tܗ TRdy-I돷"csjt`0t)[#,9%;**6%aPXnh͜1Q1Ye+4Jrs/pAQq\AA?r+%]/~@ `2$$ߡͽKρ f9uSS$۠ i=ی),-$۠ 넷Ke/R|g-#۠N)}yyv3EcԙelSm=cԅYqmx3EIE5u%mE:> xxOMG}-AS06Ox=Q|[n =VEܗDOo6hf7,z۠np Ś篴SwRvuGQ| 䖌 ۠n)Ok7dl%yOr FmP 5P{ûȲAhuPYW>[.:lz .زS!A=1icEd"v 1Я'\>Z-%A=ՑCȷwlz E\$]-)A= 袍GZsf6gGh}ee#FϹ;GF>TR Ԓ;i qsDJLĀ}ux8l ?qDLF'Rz<Wy%t;w44ZaϷQ/qKD o q1g4 y`+IR1OwDTeuD?,g3>RpA0m<Г*8st}qq5ᖇP3߸ cN}:Ib08HU;24)[z qB06L@H/ŨnȏHr[iՂ;:pqS{ 6U Ҫ4w tdj|xdqK#F NqBNnw@ 7Ͳx$ @rTn3gFAbP%I%H_!OFk;2$ww$DV*enQpmH(y RU3U+ay(~厄y\w)&N<+w$ $#5(-}6 U-7BGnMeP+OT(]' Ԟ[AAt+w$ʄF-E`},2sGBJJCOA#DeQ= )A*} [ApGB@*?tw(T[BQr"0Tqzhܢ56hGf?>}*._z48aSyǥ<>or-/lpJ;($d~̨;NyM^^2~@3#x ޔ^j$ suLLWmL \wBgF*(,ĿFCw^aౣ?!((vnnU<0Ls)Y`cY4Dy(j>/q-R2PyO*> -bW">}ne=qhPBbO6[US[T uj㻃^RBus_"&iO<ɕo({x֕f* 2%Q:ض2ވWJIay3Đ]mt?ʷ°}D}6К f _e@dgW҄j 9O6[A='tIξF?!{EjbECכEсכ̐ZZ']ΜW T][Oa[ Ԡ̲p3d@J%@S3@rD<1OI)Ȕ.h*^;P8_~.ٹaхrvوBp=ss_4ATrw\,ڿ/`gL~9G)uyi>`?ɻxQ  (DA%Zz0c题$Vc*B{^ϡDwbuO!ܶ|>XzfBB_H[Y@MqKY`d,;"BګJ͞3܂ߜiլρ 3/压q M>喅-v[ʋR$ Ҳq,-$L$K'Ej%88gK'?O{\7 L#>ø=Fu-K J ^ƴ H>Hv4eGsOrKb~+qcr;O11qUMsfVKܮSEY߷/ 0dS3>o,n+CNQӊkkVLҗ֦nh 9?Qȱe绹bĐ97-.+m3=`gڑ1ܪ=y[|2XzZL^И[df'qwft}Ӥbw6C`}C-#h} U[(v gCŘ?%Bs#؄t(o*<y[4ɶ G̘F,1QǺ#nFJuZU+XC ܢroeKDpn1 0O=>_<0 }?K![/p כ3u" BiuFޤy%Bb.F=m1 ܣBJ8nV,D>Y PUBLIC $ ) target_link_options( mock_jsonc PUBLIC -Wl,--wrap=json_object_new_object -Wl,--wrap=json_object_get -Wl,--wrap=json_object_put -Wl,--wrap=json_object_is_type -Wl,--wrap=json_object_get_type -Wl,--wrap=json_object_to_json_string -Wl,--wrap=json_object_to_json_string_ext -Wl,--wrap=json_object_to_json_string_length -Wl,--wrap=json_object_get_userdata -Wl,--wrap=json_object_set_userdata -Wl,--wrap=json_object_set_serializer -Wl,--wrap=json_object_get_object -Wl,--wrap=json_object_object_length -Wl,--wrap=json_object_object_add -Wl,--wrap=json_object_object_add_ex -Wl,--wrap=json_object_object_get -Wl,--wrap=json_object_object_get_ex -Wl,--wrap=json_object_object_del -Wl,--wrap=json_object_new_array -Wl,--wrap=json_object_new_array_ext -Wl,--wrap=json_object_get_array -Wl,--wrap=json_object_array_length -Wl,--wrap=json_object_array_add -Wl,--wrap=json_object_array_put_idx -Wl,--wrap=json_object_array_get_idx -Wl,--wrap=json_object_array_del_idx -Wl,--wrap=json_object_array_shrink -Wl,--wrap=json_object_new_boolean -Wl,--wrap=json_object_get_boolean -Wl,--wrap=json_object_set_boolean -Wl,--wrap=json_object_new_int -Wl,--wrap=json_object_new_int64 -Wl,--wrap=json_object_new_uint64 -Wl,--wrap=json_object_get_int -Wl,--wrap=json_object_set_int -Wl,--wrap=json_object_int_inc -Wl,--wrap=json_object_get_int64 -Wl,--wrap=json_object_get_uint64 -Wl,--wrap=json_object_set_int64 -Wl,--wrap=json_object_set_uint64 -Wl,--wrap=json_object_new_double -Wl,--wrap=json_object_new_double_s -Wl,--wrap=json_c_set_serialization_double_format -Wl,--wrap=json_object_double_to_json_string -Wl,--wrap=json_object_get_double -Wl,--wrap=json_object_set_double -Wl,--wrap=json_object_new_string -Wl,--wrap=json_object_new_string_len -Wl,--wrap=json_object_get_string -Wl,--wrap=json_object_get_string_len -Wl,--wrap=json_object_set_string -Wl,--wrap=json_object_set_string_len -Wl,--wrap=json_object_new_null -Wl,--wrap=json_object_equal -Wl,--wrap=json_object_deep_copy -Wl,--wrap=json_tokener_parse -Wl,--wrap=json_object_from_file -Wl,--wrap=json_util_get_last_err ) target_link_libraries( mock_jsonc PRIVATE cmocka cmocka_extensions::cmocka_extensions json-c::json-c ) install( EXPORT mock_jsoncTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks NAMESPACE cmocka_mocks:: FILE mock_jsoncTargets.cmake # Not sure if this is still needed ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/mock_jsoncConfigVersion.cmake VERSION ${PKG_VERSION} COMPATIBILITY SameMajorVersion ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/mock_jsoncConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks" ) install(TARGETS mock_jsonc EXPORT mock_jsoncTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) cmocka-mocks-0.52.1/src/mock_jsonc/include/000077500000000000000000000000001463302307500205105ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_jsonc/include/cmocka_mocks/000077500000000000000000000000001463302307500231415ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_jsonc/include/cmocka_mocks/mock_jsonc.h000066400000000000000000000341401463302307500254410ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #ifndef __MOCK_JSONC_H__ #define __MOCK_JSONC_H__ #include #include #include #include #include #include #include #include #include // clang-format off // because this order is a cmocka requirement #include #include #include #include #include #include #include // clang-format on extern int MOCK_FUNC_WRAP(json_object_get_int_errno); extern int MOCK_FUNC_WRAP(json_object_get_string_errno); extern int MOCK_FUNC_WRAP(json_object_get_uint64_errno); extern int MOCK_FUNC_WRAP(json_object_get_int64_errno); MOCK_FUNC_VAR_EXTERN(json_object_new_object); struct json_object *MOCK_FUNC_WRAP(json_object_new_object)(); struct json_object *MOCK_FUNC_REAL(json_object_new_object)(); MOCK_FUNC_VAR_EXTERN(json_object_get); struct json_object *MOCK_FUNC_WRAP(json_object_get)(struct json_object *obj); struct json_object *MOCK_FUNC_REAL(json_object_get)(struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_put); int MOCK_FUNC_WRAP(json_object_put)(struct json_object *obj); int MOCK_FUNC_REAL(json_object_put)(struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_is_type); int MOCK_FUNC_WRAP(json_object_is_type)(const struct json_object *obj, enum json_type type); int MOCK_FUNC_REAL(json_object_is_type)(const struct json_object *obj, enum json_type type); MOCK_FUNC_VAR_EXTERN(json_object_get_type); enum json_type MOCK_FUNC_WRAP(json_object_get_type)(const struct json_object *obj); enum json_type MOCK_FUNC_REAL(json_object_get_type)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_to_json_string); const char *MOCK_FUNC_WRAP(json_object_to_json_string)(struct json_object *obj); const char *MOCK_FUNC_REAL(json_object_to_json_string)(struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_to_json_string_ext); const char *MOCK_FUNC_WRAP(json_object_to_json_string_ext)(struct json_object *obj, int flags); const char *MOCK_FUNC_REAL(json_object_to_json_string_ext)(struct json_object *obj, int flags); MOCK_FUNC_VAR_EXTERN(json_object_to_json_string_length); const char *MOCK_FUNC_WRAP(json_object_to_json_string_length)(struct json_object *obj, int flags, size_t *length); const char *MOCK_FUNC_REAL(json_object_to_json_string_length)(struct json_object *obj, int flags, size_t *length); MOCK_FUNC_VAR_EXTERN(json_object_get_userdata); void *MOCK_FUNC_WRAP(json_object_get_userdata)(json_object *jso); void *MOCK_FUNC_REAL(json_object_get_userdata)(json_object *jso); MOCK_FUNC_VAR_EXTERN(json_object_set_userdata); void MOCK_FUNC_WRAP(json_object_set_userdata)(json_object *jso, void *userdata, json_object_delete_fn *user_delete); void MOCK_FUNC_REAL(json_object_set_userdata)(json_object *jso, void *userdata, json_object_delete_fn *user_delete); MOCK_FUNC_VAR_EXTERN(json_object_set_serializer); void MOCK_FUNC_WRAP(json_object_set_serializer)(json_object *jso, json_object_to_json_string_fn *to_string_func, void *userdata, json_object_delete_fn *user_delete); void MOCK_FUNC_REAL(json_object_set_serializer)(json_object *jso, json_object_to_json_string_fn *to_string_func, void *userdata, json_object_delete_fn *user_delete); MOCK_FUNC_VAR_EXTERN(json_object_get_object); struct lh_table *MOCK_FUNC_WRAP(json_object_get_object)(const struct json_object *obj); struct lh_table *MOCK_FUNC_REAL(json_object_get_object)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_object_length); int MOCK_FUNC_WRAP(json_object_object_length)(const struct json_object *obj); int MOCK_FUNC_REAL(json_object_object_length)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_object_add); int MOCK_FUNC_WRAP(json_object_object_add)(struct json_object *obj, const char *key, struct json_object *val); int MOCK_FUNC_REAL(json_object_object_add)(struct json_object *obj, const char *key, struct json_object *val); MOCK_FUNC_VAR_EXTERN(json_object_object_add_ex); int MOCK_FUNC_WRAP(json_object_object_add_ex)(struct json_object *obj, const char *const key, struct json_object *const val, const unsigned opts); int MOCK_FUNC_REAL(json_object_object_add_ex)(struct json_object *obj, const char *const key, struct json_object *const val, const unsigned opts); MOCK_FUNC_VAR_EXTERN(json_object_object_get); struct json_object *MOCK_FUNC_WRAP(json_object_object_get)(const struct json_object *obj, const char *key); struct json_object *MOCK_FUNC_REAL(json_object_object_get)(const struct json_object *obj, const char *key); MOCK_FUNC_VAR_EXTERN(json_object_object_get_ex); json_bool MOCK_FUNC_WRAP(json_object_object_get_ex)(const struct json_object *obj, const char *key, struct json_object **value); json_bool MOCK_FUNC_REAL(json_object_object_get_ex)(const struct json_object *obj, const char *key, struct json_object **value); MOCK_FUNC_VAR_EXTERN(json_object_object_del); void MOCK_FUNC_WRAP(json_object_object_del)(struct json_object *obj, const char *key); void MOCK_FUNC_REAL(json_object_object_del)(struct json_object *obj, const char *key); MOCK_FUNC_VAR_EXTERN(json_object_new_array); struct json_object *MOCK_FUNC_WRAP(json_object_new_array)(); struct json_object *MOCK_FUNC_REAL(json_object_new_array)(); MOCK_FUNC_VAR_EXTERN(json_object_new_array_ext); struct json_object *MOCK_FUNC_WRAP(json_object_new_array_ext)(int initial_size); struct json_object *MOCK_FUNC_REAL(json_object_new_array_ext)(int initial_size); MOCK_FUNC_VAR_EXTERN(json_object_get_array); struct array_list *MOCK_FUNC_WRAP(json_object_get_array)(const struct json_object *obj); struct array_list *MOCK_FUNC_REAL(json_object_get_array)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_array_length); size_t MOCK_FUNC_WRAP(json_object_array_length)(const struct json_object *obj); size_t MOCK_FUNC_REAL(json_object_array_length)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_array_add); int MOCK_FUNC_WRAP(json_object_array_add)(struct json_object *obj, struct json_object *val); int MOCK_FUNC_REAL(json_object_array_add)(struct json_object *obj, struct json_object *val); MOCK_FUNC_VAR_EXTERN(json_object_array_put_idx); int MOCK_FUNC_WRAP(json_object_array_put_idx)(struct json_object *obj, size_t idx, struct json_object *val); int MOCK_FUNC_REAL(json_object_array_put_idx)(struct json_object *obj, size_t idx, struct json_object *val); MOCK_FUNC_VAR_EXTERN(json_object_array_get_idx); struct json_object *MOCK_FUNC_WRAP(json_object_array_get_idx)(const struct json_object *obj, size_t idx); struct json_object *MOCK_FUNC_REAL(json_object_array_get_idx)(const struct json_object *obj, size_t idx); MOCK_FUNC_VAR_EXTERN(json_object_array_del_idx); int MOCK_FUNC_WRAP(json_object_array_del_idx)(struct json_object *obj, size_t idx, size_t count); int MOCK_FUNC_REAL(json_object_array_del_idx)(struct json_object *obj, size_t idx, size_t count); MOCK_FUNC_VAR_EXTERN(json_object_array_shrink); int MOCK_FUNC_WRAP(json_object_array_shrink)(struct json_object *jso, int empty_slots); int MOCK_FUNC_REAL(json_object_array_shrink)(struct json_object *jso, int empty_slots); MOCK_FUNC_VAR_EXTERN(json_object_new_boolean); struct json_object *MOCK_FUNC_WRAP(json_object_new_boolean)(json_bool b); struct json_object *MOCK_FUNC_REAL(json_object_new_boolean)(json_bool b); MOCK_FUNC_VAR_EXTERN(json_object_get_boolean); json_bool MOCK_FUNC_WRAP(json_object_get_boolean)(const struct json_object *obj); json_bool MOCK_FUNC_REAL(json_object_get_boolean)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_set_boolean); int MOCK_FUNC_WRAP(json_object_set_boolean)(struct json_object *obj, json_bool new_value); int MOCK_FUNC_REAL(json_object_set_boolean)(struct json_object *obj, json_bool new_value); MOCK_FUNC_VAR_EXTERN(json_object_new_int); struct json_object *MOCK_FUNC_WRAP(json_object_new_int)(int32_t i); struct json_object *MOCK_FUNC_REAL(json_object_new_int)(int32_t i); MOCK_FUNC_VAR_EXTERN(json_object_new_int64); struct json_object *MOCK_FUNC_WRAP(json_object_new_int64)(int64_t i); struct json_object *MOCK_FUNC_REAL(json_object_new_int64)(int64_t i); MOCK_FUNC_VAR_EXTERN(json_object_new_uint64); struct json_object *MOCK_FUNC_WRAP(json_object_new_uint64)(uint64_t i); struct json_object *MOCK_FUNC_REAL(json_object_new_uint64)(uint64_t i); MOCK_FUNC_VAR_EXTERN(json_object_get_int); int32_t MOCK_FUNC_WRAP(json_object_get_int)(const struct json_object *obj); int32_t MOCK_FUNC_REAL(json_object_get_int)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_set_int); int MOCK_FUNC_WRAP(json_object_set_int)(struct json_object *obj, int new_value); int MOCK_FUNC_REAL(json_object_set_int)(struct json_object *obj, int new_value); MOCK_FUNC_VAR_EXTERN(json_object_int_inc); int MOCK_FUNC_WRAP(json_object_int_inc)(struct json_object *obj, int64_t val); int MOCK_FUNC_REAL(json_object_int_inc)(struct json_object *obj, int64_t val); MOCK_FUNC_VAR_EXTERN(json_object_get_int64); int64_t MOCK_FUNC_WRAP(json_object_get_int64)(const struct json_object *obj); int64_t MOCK_FUNC_REAL(json_object_get_int64)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_get_uint64); uint64_t MOCK_FUNC_WRAP(json_object_get_uint64)(const struct json_object *obj); uint64_t MOCK_FUNC_REAL(json_object_get_uint64)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_set_int64); int MOCK_FUNC_WRAP(json_object_set_int64)(struct json_object *obj, int64_t new_value); int MOCK_FUNC_REAL(json_object_set_int64)(struct json_object *obj, int64_t new_value); MOCK_FUNC_VAR_EXTERN(json_object_set_uint64); int MOCK_FUNC_WRAP(json_object_set_uint64)(struct json_object *obj, uint64_t new_value); int MOCK_FUNC_REAL(json_object_set_uint64)(struct json_object *obj, uint64_t new_value); MOCK_FUNC_VAR_EXTERN(json_object_new_double); struct json_object *MOCK_FUNC_WRAP(json_object_new_double)(double d); struct json_object *MOCK_FUNC_REAL(json_object_new_double)(double d); MOCK_FUNC_VAR_EXTERN(json_object_new_double_s); struct json_object *MOCK_FUNC_WRAP(json_object_new_double_s)(double d, const char *ds); struct json_object *MOCK_FUNC_REAL(json_object_new_double_s)(double d, const char *ds); MOCK_FUNC_VAR_EXTERN(json_c_set_serialization_double_format); int MOCK_FUNC_WRAP(json_c_set_serialization_double_format)(const char *double_format, int global_or_thread); int MOCK_FUNC_REAL(json_c_set_serialization_double_format)(const char *double_format, int global_or_thread); MOCK_FUNC_VAR_EXTERN(json_object_double_to_json_string); int MOCK_FUNC_WRAP(json_object_double_to_json_string)(struct json_object *jso, struct printbuf *pb, int level, int flags); int MOCK_FUNC_REAL(json_object_double_to_json_string)(struct json_object *jso, struct printbuf *pb, int level, int flags); MOCK_FUNC_VAR_EXTERN(json_object_get_double); double MOCK_FUNC_WRAP(json_object_get_double)(const struct json_object *obj); double MOCK_FUNC_REAL(json_object_get_double)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_set_double); int MOCK_FUNC_WRAP(json_object_set_double)(struct json_object *obj, double new_value); int MOCK_FUNC_REAL(json_object_set_double)(struct json_object *obj, double new_value); MOCK_FUNC_VAR_EXTERN(json_object_new_string); struct json_object *MOCK_FUNC_WRAP(json_object_new_string)(const char *s); struct json_object *MOCK_FUNC_REAL(json_object_new_string)(const char *s); MOCK_FUNC_VAR_EXTERN(json_object_new_string_len); struct json_object *MOCK_FUNC_WRAP(json_object_new_string_len)(const char *s, const int len); struct json_object *MOCK_FUNC_REAL(json_object_new_string_len)(const char *s, const int len); MOCK_FUNC_VAR_EXTERN(json_object_get_string); const char *MOCK_FUNC_WRAP(json_object_get_string)(struct json_object *obj); const char *MOCK_FUNC_REAL(json_object_get_string)(struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_get_string_len); int MOCK_FUNC_WRAP(json_object_get_string_len)(const struct json_object *obj); int MOCK_FUNC_REAL(json_object_get_string_len)(const struct json_object *obj); MOCK_FUNC_VAR_EXTERN(json_object_set_string); int MOCK_FUNC_WRAP(json_object_set_string)(json_object *obj, const char *new_value); int MOCK_FUNC_REAL(json_object_set_string)(json_object *obj, const char *new_value); MOCK_FUNC_VAR_EXTERN(json_object_set_string_len); int MOCK_FUNC_WRAP(json_object_set_string_len)(json_object *obj, const char *new_value, int len); int MOCK_FUNC_REAL(json_object_set_string_len)(json_object *obj, const char *new_value, int len); MOCK_FUNC_VAR_EXTERN(json_object_new_null); struct json_object *MOCK_FUNC_WRAP(json_object_new_null)(); struct json_object *MOCK_FUNC_REAL(json_object_new_null)(); MOCK_FUNC_VAR_EXTERN(json_object_equal); int MOCK_FUNC_WRAP(json_object_equal)(struct json_object *obj1, struct json_object *obj2); int MOCK_FUNC_REAL(json_object_equal)(struct json_object *obj1, struct json_object *obj2); MOCK_FUNC_VAR_EXTERN(json_object_deep_copy); int MOCK_FUNC_WRAP(json_object_deep_copy)(struct json_object *src, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy); int MOCK_FUNC_REAL(json_object_deep_copy)(struct json_object *src, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy); MOCK_FUNC_VAR_EXTERN(json_tokener_parse); struct json_object *MOCK_FUNC_WRAP(json_tokener_parse)(const char *str); struct json_object *MOCK_FUNC_REAL(json_tokener_parse)(const char *str); MOCK_FUNC_VAR_EXTERN(json_object_from_file); struct json_object *MOCK_FUNC_WRAP(json_object_from_file)(const char *_path); struct json_object *MOCK_FUNC_REAL(json_object_from_file)(const char *_path); MOCK_FUNC_VAR_EXTERN(json_util_get_last_err); const char *MOCK_FUNC_WRAP(json_util_get_last_err)(); const char *MOCK_FUNC_REAL(json_util_get_last_err)(); #endif /* __MOCK_JSONC_H__ */ cmocka-mocks-0.52.1/src/mock_jsonc/mock_jsonc.c000066400000000000000000000517271463302307500213720ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #include "cmocka_mocks/mock_jsonc.h" #include MOCK_FUNC_VAR_NEW(json_object_new_object); struct json_object *MOCK_FUNC_WRAP(json_object_new_object)() { if (MOCK_IS_ACTIVE(json_object_new_object)) { return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_object)(); } MOCK_FUNC_VAR_NEW(json_object_get); struct json_object *MOCK_FUNC_WRAP(json_object_get)(struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get)) { check_expected_ptr(obj); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_get)(obj); } MOCK_FUNC_VAR_NEW(json_object_put); int MOCK_FUNC_WRAP(json_object_put)(struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_put)) { check_expected_ptr(obj); return mock_type(int); } return MOCK_FUNC_REAL(json_object_put)(obj); } MOCK_FUNC_VAR_NEW(json_object_is_type); int MOCK_FUNC_WRAP(json_object_is_type)(const struct json_object *obj, enum json_type type) { if (MOCK_IS_ACTIVE(json_object_is_type)) { check_expected_ptr(obj); check_expected(type); return mock_type(int); } return MOCK_FUNC_REAL(json_object_is_type)(obj, type); } MOCK_FUNC_VAR_NEW(json_object_get_type); enum json_type MOCK_FUNC_WRAP(json_object_get_type)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_type)) { check_expected_ptr(obj); return mock_type(int); } return MOCK_FUNC_REAL(json_object_get_type)(obj); } MOCK_FUNC_VAR_NEW(json_object_to_json_string); const char *MOCK_FUNC_WRAP(json_object_to_json_string)(struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_to_json_string)) { check_expected_ptr(obj); return mock_ptr_type(char *); } return MOCK_FUNC_REAL(json_object_to_json_string)(obj); } MOCK_FUNC_VAR_NEW(json_object_to_json_string_ext); const char *MOCK_FUNC_WRAP(json_object_to_json_string_ext)(struct json_object *obj, int flags) { if (MOCK_IS_ACTIVE(json_object_to_json_string_ext)) { check_expected_ptr(obj); check_expected(flags); return mock_ptr_type(char *); } return MOCK_FUNC_REAL(json_object_to_json_string_ext)(obj, flags); } MOCK_FUNC_VAR_NEW(json_object_to_json_string_length); const char *MOCK_FUNC_WRAP(json_object_to_json_string_length)(struct json_object *obj, int flags, size_t *length) { if (MOCK_IS_ACTIVE(json_object_to_json_string_length)) { check_expected_ptr(obj); check_expected(flags); check_expected_ptr(length); return mock_ptr_type(char *); } return MOCK_FUNC_REAL(json_object_to_json_string_length)(obj, flags, length); } MOCK_FUNC_VAR_NEW(json_object_get_userdata); void *MOCK_FUNC_WRAP(json_object_get_userdata)(json_object *jso) { if (MOCK_IS_ACTIVE(json_object_get_userdata)) { check_expected_ptr(jso); return mock_ptr_type(void *); } return MOCK_FUNC_REAL(json_object_get_userdata)(jso); } MOCK_FUNC_VAR_NEW(json_object_set_userdata); void MOCK_FUNC_WRAP(json_object_set_userdata)(json_object *jso, void *userdata, json_object_delete_fn *user_delete) { if (MOCK_IS_ACTIVE(json_object_set_userdata)) { check_expected_ptr(jso); check_expected_ptr(userdata); check_expected_ptr(user_delete); } MOCK_FUNC_REAL(json_object_set_userdata)(jso, userdata, user_delete); } MOCK_FUNC_VAR_NEW(json_object_set_serializer); void MOCK_FUNC_WRAP(json_object_set_serializer)(json_object *jso, json_object_to_json_string_fn *to_string_func, void *userdata, json_object_delete_fn *user_delete) { if (MOCK_IS_ACTIVE(json_object_set_serializer)) { check_expected_ptr(jso); check_expected_ptr(to_string_func); check_expected_ptr(userdata); check_expected_ptr(user_delete); } MOCK_FUNC_REAL(json_object_set_serializer)(jso, to_string_func, userdata, user_delete); } MOCK_FUNC_VAR_NEW(json_object_get_object); struct lh_table *MOCK_FUNC_WRAP(json_object_get_object)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_object)) { check_expected_ptr(obj); return mock_ptr_type(lh_table *); } return MOCK_FUNC_REAL(json_object_get_object)(obj); } MOCK_FUNC_VAR_NEW(json_object_object_length); int MOCK_FUNC_WRAP(json_object_object_length)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_object_length)) { check_expected_ptr(obj); return mock_type(int); } return MOCK_FUNC_REAL(json_object_object_length)(obj); } MOCK_FUNC_VAR_NEW(json_object_object_add); int MOCK_FUNC_WRAP(json_object_object_add)(struct json_object *obj, const char *key, struct json_object *val) { if (MOCK_IS_ACTIVE(json_object_object_add)) { check_expected_ptr(obj); check_expected_ptr(key); check_expected_ptr(val); return mock_type(int); } return MOCK_FUNC_REAL(json_object_object_add)(obj, key, val); } MOCK_FUNC_VAR_NEW(json_object_object_add_ex); int MOCK_FUNC_WRAP(json_object_object_add_ex)(struct json_object *obj, const char *const key, struct json_object *const val, const unsigned opts) { if (MOCK_IS_ACTIVE(json_object_object_add_ex)) { check_expected_ptr(obj); check_expected_ptr(key); check_expected_ptr(val); check_expected(opts); return mock_type(int); } return MOCK_FUNC_REAL(json_object_object_add_ex)(obj, key, val, opts); } MOCK_FUNC_VAR_NEW(json_object_object_get); struct json_object *MOCK_FUNC_WRAP(json_object_object_get)(const struct json_object *obj, const char *key) { if (MOCK_IS_ACTIVE(json_object_object_get)) { check_expected_ptr(obj); check_expected_ptr(key); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_object_get)(obj, key); } MOCK_FUNC_VAR_NEW(json_object_object_get_ex); json_bool MOCK_FUNC_WRAP(json_object_object_get_ex)(const struct json_object *obj, const char *key, struct json_object **value) { if (MOCK_IS_ACTIVE(json_object_object_get_ex)) { check_expected_ptr(obj); check_expected_ptr(key); check_expected_ptr(value); return mock_type(json_bool); } return MOCK_FUNC_REAL(json_object_object_get_ex)(obj, key, value); } MOCK_FUNC_VAR_NEW(json_object_object_del); void MOCK_FUNC_WRAP(json_object_object_del)(struct json_object *obj, const char *key) { if (MOCK_IS_ACTIVE(json_object_object_del)) { check_expected_ptr(obj); check_expected_ptr(key); } MOCK_FUNC_REAL(json_object_object_del)(obj, key); } MOCK_FUNC_VAR_NEW(json_object_new_array); struct json_object *MOCK_FUNC_WRAP(json_object_new_array)() { if (MOCK_IS_ACTIVE(json_object_new_array)) { return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_array)(); } MOCK_FUNC_VAR_NEW(json_object_new_array_ext); struct json_object *MOCK_FUNC_WRAP(json_object_new_array_ext)(int initial_size) { if (MOCK_IS_ACTIVE(json_object_new_array_ext)) { check_expected(initial_size); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_array_ext)(initial_size); } MOCK_FUNC_VAR_NEW(json_object_get_array); struct array_list *MOCK_FUNC_WRAP(json_object_get_array)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_array)) { check_expected_ptr(obj); return mock_ptr_type(array_list *); } return MOCK_FUNC_REAL(json_object_get_array)(obj); } MOCK_FUNC_VAR_NEW(json_object_array_length); size_t MOCK_FUNC_WRAP(json_object_array_length)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_array_length)) { check_expected_ptr(obj); return mock_type(size_t); } return MOCK_FUNC_REAL(json_object_array_length)(obj); } MOCK_FUNC_VAR_NEW(json_object_array_add); int MOCK_FUNC_WRAP(json_object_array_add)(struct json_object *obj, struct json_object *val) { if (MOCK_IS_ACTIVE(json_object_array_add)) { check_expected_ptr(obj); check_expected_ptr(val); return mock_type(int); } return MOCK_FUNC_REAL(json_object_array_add)(obj, val); } MOCK_FUNC_VAR_NEW(json_object_array_put_idx); int MOCK_FUNC_WRAP(json_object_array_put_idx)(struct json_object *obj, size_t idx, struct json_object *val) { if (MOCK_IS_ACTIVE(json_object_array_put_idx)) { check_expected_ptr(obj); check_expected(idx); check_expected_ptr(val); return mock_type(int); } return MOCK_FUNC_REAL(json_object_array_put_idx)(obj, idx, val); } MOCK_FUNC_VAR_NEW(json_object_array_get_idx); struct json_object *MOCK_FUNC_WRAP(json_object_array_get_idx)(const struct json_object *obj, size_t idx) { if (MOCK_IS_ACTIVE(json_object_array_get_idx)) { check_expected_ptr(obj); check_expected(idx); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_array_get_idx)(obj, idx); } MOCK_FUNC_VAR_NEW(json_object_array_del_idx); int MOCK_FUNC_WRAP(json_object_array_del_idx)(struct json_object *obj, size_t idx, size_t count) { if (MOCK_IS_ACTIVE(json_object_array_del_idx)) { check_expected_ptr(obj); check_expected(idx); check_expected(count); return mock_type(int); } return MOCK_FUNC_REAL(json_object_array_del_idx)(obj, idx, count); } MOCK_FUNC_VAR_NEW(json_object_array_shrink); int MOCK_FUNC_WRAP(json_object_array_shrink)(struct json_object *jso, int empty_slots) { if (MOCK_IS_ACTIVE(json_object_array_shrink)) { check_expected_ptr(jso); check_expected(empty_slots); return mock_type(int); } return MOCK_FUNC_REAL(json_object_array_shrink)(jso, empty_slots); } MOCK_FUNC_VAR_NEW(json_object_new_boolean); struct json_object *MOCK_FUNC_WRAP(json_object_new_boolean)(json_bool b) { if (MOCK_IS_ACTIVE(json_object_new_boolean)) { check_expected(b); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_boolean)(b); } MOCK_FUNC_VAR_NEW(json_object_get_boolean); json_bool MOCK_FUNC_WRAP(json_object_get_boolean)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_boolean)) { check_expected_ptr(obj); return mock_ptr_type(json_bool); } return MOCK_FUNC_REAL(json_object_get_boolean)(obj); } MOCK_FUNC_VAR_NEW(json_object_set_boolean); int MOCK_FUNC_WRAP(json_object_set_boolean)(struct json_object *obj, json_bool new_value) { if (MOCK_IS_ACTIVE(json_object_set_boolean)) { check_expected_ptr(obj); check_expected(new_value); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_boolean)(obj, new_value); } MOCK_FUNC_VAR_NEW(json_object_new_int); struct json_object *MOCK_FUNC_WRAP(json_object_new_int)(int32_t i) { if (MOCK_IS_ACTIVE(json_object_new_int)) { check_expected(i); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_int)(i); } MOCK_FUNC_VAR_NEW(json_object_new_int64); struct json_object *MOCK_FUNC_WRAP(json_object_new_int64)(int64_t i) { if (MOCK_IS_ACTIVE(json_object_new_int64)) { check_expected(i); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_int64)(i); } MOCK_FUNC_VAR_NEW(json_object_new_uint64); struct json_object *MOCK_FUNC_WRAP(json_object_new_uint64)(uint64_t i) { if (MOCK_IS_ACTIVE(json_object_new_uint64)) { check_expected(i); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_uint64)(i); } MOCK_FUNC_VAR_NEW(json_object_get_int); int MOCK_FUNC_WRAP(json_object_get_int_errno = 0); int32_t MOCK_FUNC_WRAP(json_object_get_int)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_int)) { check_expected_ptr(obj); if (MOCK_FUNC_WRAP(json_object_get_int_errno) != 0) { errno = MOCK_FUNC_WRAP(json_object_get_int_errno); MOCK_FUNC_WRAP(json_object_get_int_errno) = 0; } return mock_type(int32_t); } return MOCK_FUNC_REAL(json_object_get_int)(obj); } MOCK_FUNC_VAR_NEW(json_object_set_int); int MOCK_FUNC_WRAP(json_object_set_int)(struct json_object *obj, int new_value) { if (MOCK_IS_ACTIVE(json_object_set_int)) { check_expected_ptr(obj); check_expected(new_value); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_int)(obj, new_value); } MOCK_FUNC_VAR_NEW(json_object_int_inc); int MOCK_FUNC_WRAP(json_object_int_inc)(struct json_object *obj, int64_t val) { if (MOCK_IS_ACTIVE(json_object_int_inc)) { check_expected_ptr(obj); check_expected(val); return mock_type(int); } return MOCK_FUNC_REAL(json_object_int_inc)(obj, val); } MOCK_FUNC_VAR_NEW(json_object_get_int64); int MOCK_FUNC_WRAP(json_object_get_int64_errno = 0); int64_t MOCK_FUNC_WRAP(json_object_get_int64)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_int64)) { check_expected_ptr(obj); if (MOCK_FUNC_WRAP(json_object_get_int64_errno) != 0) { errno = MOCK_FUNC_WRAP(json_object_get_int64_errno); MOCK_FUNC_WRAP(json_object_get_int64_errno) = 0; } return mock_type(int64_t); } return MOCK_FUNC_REAL(json_object_get_int64)(obj); } MOCK_FUNC_VAR_NEW(json_object_get_uint64); int MOCK_FUNC_WRAP(json_object_get_uint64_errno = 0); uint64_t MOCK_FUNC_WRAP(json_object_get_uint64)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_uint64)) { check_expected_ptr(obj); if (MOCK_FUNC_WRAP(json_object_get_uint64_errno) != 0) { errno = MOCK_FUNC_WRAP(json_object_get_uint64_errno); MOCK_FUNC_WRAP(json_object_get_uint64_errno) = 0; } return mock_type(uint64_t); } return MOCK_FUNC_REAL(json_object_get_uint64)(obj); } MOCK_FUNC_VAR_NEW(json_object_set_int64); int MOCK_FUNC_WRAP(json_object_set_int64)(struct json_object *obj, int64_t new_value) { if (MOCK_IS_ACTIVE(json_object_set_int64)) { check_expected_ptr(obj); check_expected(new_value); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_int64)(obj, new_value); } MOCK_FUNC_VAR_NEW(json_object_set_uint64); int MOCK_FUNC_WRAP(json_object_set_uint64)(struct json_object *obj, uint64_t new_value) { if (MOCK_IS_ACTIVE(json_object_set_uint64)) { check_expected_ptr(obj); check_expected(new_value); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_uint64)(obj, new_value); } MOCK_FUNC_VAR_NEW(json_object_new_double); struct json_object *MOCK_FUNC_WRAP(json_object_new_double)(double d) { if (MOCK_IS_ACTIVE(json_object_new_double)) { check_expected(d); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_double)(d); } MOCK_FUNC_VAR_NEW(json_object_new_double_s); struct json_object *MOCK_FUNC_WRAP(json_object_new_double_s)(double d, const char *ds) { if (MOCK_IS_ACTIVE(json_object_new_double_s)) { check_expected(d); check_expected_ptr(ds); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_double_s)(d, ds); } MOCK_FUNC_VAR_NEW(json_c_set_serialization_double_format); int MOCK_FUNC_WRAP(json_c_set_serialization_double_format)(const char *double_format, int global_or_thread) { if (MOCK_IS_ACTIVE(json_c_set_serialization_double_format)) { check_expected_ptr(double_format); check_expected(global_or_thread); return mock_type(int); } return MOCK_FUNC_REAL(json_c_set_serialization_double_format)(double_format, global_or_thread); } MOCK_FUNC_VAR_NEW(json_object_double_to_json_string); int MOCK_FUNC_WRAP(json_object_double_to_json_string)(struct json_object *jso, struct printbuf *pb, int level, int flags) { if (MOCK_IS_ACTIVE(json_object_double_to_json_string)) { check_expected_ptr(jso); check_expected_ptr(pb); check_expected(level); check_expected(flags); return mock_type(int); } return MOCK_FUNC_REAL(json_object_double_to_json_string)(jso, pb, level, flags); } MOCK_FUNC_VAR_NEW(json_object_get_double); double MOCK_FUNC_WRAP(json_object_get_double)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_double)) { check_expected_ptr(obj); return mock_type(double); } return MOCK_FUNC_REAL(json_object_get_double)(obj); } MOCK_FUNC_VAR_NEW(json_object_set_double); int MOCK_FUNC_WRAP(json_object_set_double)(struct json_object *obj, double new_value) { if (MOCK_IS_ACTIVE(json_object_set_double)) { check_expected_ptr(obj); check_expected(new_value); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_double)(obj, new_value); } MOCK_FUNC_VAR_NEW(json_object_new_string); struct json_object *MOCK_FUNC_WRAP(json_object_new_string)(const char *s) { if (MOCK_IS_ACTIVE(json_object_new_string)) { check_expected_ptr(s); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_string)(s); } MOCK_FUNC_VAR_NEW(json_object_new_string_len); struct json_object *MOCK_FUNC_WRAP(json_object_new_string_len)(const char *s, const int len) { if (MOCK_IS_ACTIVE(json_object_new_string_len)) { check_expected_ptr(s); check_expected(len); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_string_len)(s, len); } MOCK_FUNC_VAR_NEW(json_object_get_string); int MOCK_FUNC_WRAP(json_object_get_string_errno = 0); const char *MOCK_FUNC_WRAP(json_object_get_string)(struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_string)) { check_expected_ptr(obj); if (MOCK_FUNC_WRAP(json_object_get_string_errno) != 0) { errno = MOCK_FUNC_WRAP(json_object_get_string_errno); MOCK_FUNC_WRAP(json_object_get_string_errno) = 0; } return mock_ptr_type(char *); } return MOCK_FUNC_REAL(json_object_get_string)(obj); } MOCK_FUNC_VAR_NEW(json_object_get_string_len); int MOCK_FUNC_WRAP(json_object_get_string_len)(const struct json_object *obj) { if (MOCK_IS_ACTIVE(json_object_get_string_len)) { check_expected_ptr(obj); return mock_type(int); } return MOCK_FUNC_REAL(json_object_get_string_len)(obj); } MOCK_FUNC_VAR_NEW(json_object_set_string); int MOCK_FUNC_WRAP(json_object_set_string)(json_object *obj, const char *new_value) { if (MOCK_IS_ACTIVE(json_object_set_string)) { check_expected_ptr(obj); check_expected_ptr(new_value); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_string)(obj, new_value); } MOCK_FUNC_VAR_NEW(json_object_set_string_len); int MOCK_FUNC_WRAP(json_object_set_string_len)(json_object *obj, const char *new_value, int len) { if (MOCK_IS_ACTIVE(json_object_set_string_len)) { check_expected_ptr(obj); check_expected_ptr(new_value); check_expected(len); return mock_type(int); } return MOCK_FUNC_REAL(json_object_set_string_len)(obj, new_value, len); } MOCK_FUNC_VAR_NEW(json_object_new_null); struct json_object *MOCK_FUNC_WRAP(json_object_new_null)() { if (MOCK_IS_ACTIVE(json_object_new_null)) { return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_new_null)(); } MOCK_FUNC_VAR_NEW(json_object_equal); int MOCK_FUNC_WRAP(json_object_equal)(struct json_object *obj1, struct json_object *obj2) { if (MOCK_IS_ACTIVE(json_object_equal)) { check_expected_ptr(obj1); check_expected_ptr(obj2); return mock_type(int); } return MOCK_FUNC_REAL(json_object_equal)(obj1, obj2); } MOCK_FUNC_VAR_NEW(json_object_deep_copy); int MOCK_FUNC_WRAP(json_object_deep_copy)(struct json_object *src, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy) { if (MOCK_IS_ACTIVE(json_object_deep_copy)) { check_expected_ptr(src); check_expected_ptr(dst); check_expected_ptr(shallow_copy); return mock_type(int); } return MOCK_FUNC_REAL(json_object_deep_copy)(src, dst, shallow_copy); } MOCK_FUNC_VAR_NEW(json_tokener_parse); struct json_object *MOCK_FUNC_WRAP(json_tokener_parse)(const char *str) { if (MOCK_IS_ACTIVE(json_tokener_parse)) { check_expected_ptr(str); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_tokener_parse)(str); } MOCK_FUNC_VAR_NEW(json_object_from_file); struct json_object *MOCK_FUNC_WRAP(json_object_from_file)(const char *filename) { if (MOCK_IS_ACTIVE(json_object_from_file)) { check_expected_ptr(filename); return mock_ptr_type(json_object *); } return MOCK_FUNC_REAL(json_object_from_file)(filename); } MOCK_FUNC_VAR_NEW(json_util_get_last_err); const char *MOCK_FUNC_WRAP(json_util_get_last_err)() { if (MOCK_IS_ACTIVE(json_util_get_last_err)) { return mock_ptr_type(const char *); } return MOCK_FUNC_REAL(json_util_get_last_err)(); } cmocka-mocks-0.52.1/src/mock_libc/000077500000000000000000000000001463302307500166625ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_libc/CMakeLists.txt000066400000000000000000000056301463302307500214260ustar00rootroot00000000000000# SPDX-License-Identifier: MIT find_package(cmocka_extensions REQUIRED) add_library( mock_libc SHARED mock_libc.c ) set_property(TARGET mock_libc PROPERTY POSITION_INDEPENDENT_CODE ON) set_target_properties( mock_libc PROPERTIES SOVERSION ${CMOCKA_MOCKS_VERSION_MAJOR} VERSION ${CMOCKA_MOCKS_VERSION_MAJOR}.${CMOCKA_MOCKS_VERSION_MINOR}.${CMOCKA_MOCKS_VERSION_MICRO} ) target_include_directories( mock_libc PRIVATE $ PUBLIC $ ) target_link_options( mock_libc PUBLIC -Wl,--wrap=malloc -Wl,--wrap=realloc -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=memcpy -Wl,--wrap=strdup -Wl,--wrap=fopen -Wl,--wrap=fdopen -Wl,--wrap=fclose -Wl,--wrap=fwrite -Wl,--wrap=fread -Wl,--wrap=fseek -Wl,--wrap=scandir -Wl,--wrap=access -Wl,--wrap=fseek -Wl,--wrap=rewind -Wl,--wrap=ftell -Wl,--wrap=popen -Wl,--wrap=pclose -Wl,--wrap=getline -Wl,--wrap=getenv -Wl,--wrap=getpid -Wl,--wrap=opendir -Wl,--wrap=closedir -Wl,--wrap=remove -Wl,--wrap=readdir -Wl,--wrap=stat -Wl,--wrap=fputc -Wl,--wrap=time -Wl,--wrap=clock_gettime -Wl,--wrap=inet_aton -Wl,--wrap=inet_pton -Wl,--wrap=getaddrinfo -Wl,--wrap=freeaddrinfo -Wl,--wrap=socket -Wl,--wrap=setsockopt -Wl,--wrap=accept -Wl,--wrap=connect -Wl,--wrap=bind -Wl,--wrap=listen -Wl,--wrap=close -Wl,--wrap=open -Wl,--wrap=regerror -Wl,--wrap=regexec -Wl,--wrap=regcomp -Wl,--wrap=strndup -Wl,--wrap=raise -Wl,--wrap=pselect -Wl,--wrap=pthread_create -Wl,--wrap=pthread_join -Wl,--wrap=pthread_once -Wl,--wrap=pthread_mutex_init -Wl,--wrap=pthread_mutex_destroy -Wl,--wrap=pthread_mutex_trylock -Wl,--wrap=pthread_mutex_lock -Wl,--wrap=pthread_mutex_unlock -Wl,--wrap=pthread_mutex_timedlock -Wl,--wrap=pthread_setname_np -Wl,--wrap=sem_init -Wl,--wrap=sem_post -Wl,--wrap=sem_destroy -Wl,--wrap=sem_timedwait -Wl,--wrap=eventfd -Wl,--wrap=eventfd_read -Wl,--wrap=eventfd_write ) target_link_libraries( mock_libc PRIVATE cmocka cmocka_extensions::cmocka_extensions ) install( EXPORT mock_libcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks NAMESPACE cmocka_mocks:: FILE mock_libcTargets.cmake # Not sure if this is still needed ) include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/mock_libcConfigVersion.cmake VERSION ${PKG_VERSION} COMPATIBILITY SameMajorVersion ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/mock_libcConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks" ) install(TARGETS mock_libc EXPORT mock_libcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) cmocka-mocks-0.52.1/src/mock_libc/include/000077500000000000000000000000001463302307500203055ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_libc/include/cmocka_mocks/000077500000000000000000000000001463302307500227365ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_libc/include/cmocka_mocks/mock_libc.h000066400000000000000000000237771463302307500250510ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #ifndef __MOCK_LIBC_H__ #define __MOCK_LIBC_H__ // clang-format off // because this order is a cmocka requirement #include #include #include #include #include #include #include // clang-format on #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include MOCK_FUNC_VAR_EXTERN(regcomp); int MOCK_FUNC_WRAP(regcomp)(regex_t *preg, const char *regex, int cflags); int MOCK_FUNC_REAL(regcomp)(regex_t *preg, const char *regex, int cflags); MOCK_FUNC_VAR_EXTERN(regerror); size_t MOCK_FUNC_WRAP(regerror)(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size); size_t MOCK_FUNC_REAL(regerror)(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size); MOCK_FUNC_VAR_EXTERN(regexec); int MOCK_FUNC_WRAP(regexec)(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); int MOCK_FUNC_REAL(regexec)(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); MOCK_FUNC_VAR_EXTERN(malloc); void *MOCK_FUNC_WRAP(malloc)(size_t size); void *MOCK_FUNC_REAL(malloc)(size_t size); MOCK_FUNC_VAR_EXTERN(realloc); void *MOCK_FUNC_WRAP(realloc)(void *ptr, size_t newSize); void *MOCK_FUNC_REAL(realloc)(void *ptr, size_t newSize); MOCK_FUNC_VAR_EXTERN(calloc); void *MOCK_FUNC_WRAP(calloc)(size_t nmemb, size_t size); void *MOCK_FUNC_REAL(calloc)(size_t nmemb, size_t size); MOCK_FUNC_VAR_EXTERN(free); void MOCK_FUNC_WRAP(free)(void *ptr); void MOCK_FUNC_REAL(free)(void *ptr); MOCK_FUNC_VAR_EXTERN(memcpy); void *MOCK_FUNC_WRAP(memcpy)(void *destination, const void *source, size_t num); void *MOCK_FUNC_REAL(memcpy)(void *destination, const void *source, size_t num); MOCK_FUNC_VAR_EXTERN(strdup); char *MOCK_FUNC_WRAP(strdup)(const char *string); char *MOCK_FUNC_REAL(strdup)(const char *string); MOCK_FUNC_VAR_EXTERN(strndup); char *MOCK_FUNC_WRAP(strndup)(const char *string, size_t n); char *MOCK_FUNC_REAL(strndup)(const char *string, size_t n); MOCK_FUNC_VAR_EXTERN(access); int MOCK_FUNC_WRAP(access)(const char *pathname, int mode); int MOCK_FUNC_REAL(access)(const char *pathname, int mode); MOCK_FUNC_VAR_EXTERN(fopen); FILE *MOCK_FUNC_WRAP(fopen)(const char *filename, const char *mode); FILE *MOCK_FUNC_REAL(fopen)(const char *filename, const char *mode); MOCK_FUNC_VAR_EXTERN(fdopen); FILE *MOCK_FUNC_WRAP(fdopen)(const int fd, const char *mode); FILE *MOCK_FUNC_REAL(fdopen)(const int fd, const char *mode); MOCK_FUNC_VAR_EXTERN(fclose); int MOCK_FUNC_WRAP(fclose)(FILE *stream); int MOCK_FUNC_REAL(fclose)(FILE *stream); MOCK_FUNC_VAR_EXTERN(fwrite); size_t MOCK_FUNC_WRAP(fwrite)(const void *ptr, size_t size, size_t count, FILE *stream); size_t MOCK_FUNC_REAL(fwrite)(const void *ptr, size_t size, size_t count, FILE *stream); MOCK_FUNC_VAR_EXTERN(fread); size_t MOCK_FUNC_WRAP(fread)(void *ptr, size_t size, size_t count, FILE *stream); size_t MOCK_FUNC_REAL(fread)(void *ptr, size_t size, size_t count, FILE *stream); MOCK_FUNC_VAR_EXTERN(scandir); int MOCK_FUNC_WRAP(scandir)(const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); int MOCK_FUNC_REAL(scandir)(const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); MOCK_FUNC_VAR_EXTERN(fseek); int MOCK_FUNC_WRAP(fseek)(FILE *stream, long int offset, int origin); int MOCK_FUNC_REAL(fseek)(FILE *stream, long int offset, int origin); MOCK_FUNC_VAR_EXTERN(rewind); void MOCK_FUNC_WRAP(rewind)(FILE *stream); void MOCK_FUNC_REAL(rewind)(FILE *stream); MOCK_FUNC_VAR_EXTERN(ftell); long int MOCK_FUNC_WRAP(ftell)(FILE *stream); long int MOCK_FUNC_REAL(ftell)(FILE *stream); MOCK_FUNC_VAR_EXTERN(popen); FILE *MOCK_FUNC_WRAP(popen)(const char *command, const char *type); FILE *MOCK_FUNC_REAL(popen)(const char *command, const char *type); MOCK_FUNC_VAR_EXTERN(pclose); int MOCK_FUNC_WRAP(pclose)(FILE *stream); int MOCK_FUNC_REAL(pclose)(FILE *stream); MOCK_FUNC_VAR_EXTERN(getline); ssize_t MOCK_FUNC_WRAP(getline)(char **lineptr, size_t *n, FILE *stream); ssize_t MOCK_FUNC_REAL(getline)(char **lineptr, size_t *n, FILE *stream); MOCK_FUNC_VAR_EXTERN(getenv); char *MOCK_FUNC_WRAP(getenv)(const char *name); char *MOCK_FUNC_REAL(getenv)(const char *name); MOCK_FUNC_VAR_EXTERN(getpid); pid_t MOCK_FUNC_WRAP(getpid)(); pid_t MOCK_FUNC_REAL(getpid)(); MOCK_FUNC_VAR_EXTERN(opendir); DIR *MOCK_FUNC_WRAP(opendir)(const char *name); DIR *MOCK_FUNC_REAL(opendir)(const char *name); MOCK_FUNC_VAR_EXTERN(closedir); int MOCK_FUNC_WRAP(closedir)(DIR *dirp); int MOCK_FUNC_REAL(closedir)(DIR *dirp); MOCK_FUNC_VAR_EXTERN(remove); int MOCK_FUNC_WRAP(remove)(const char *filename); int MOCK_FUNC_REAL(remove)(const char *filename); MOCK_FUNC_VAR_EXTERN(readdir); struct dirent *MOCK_FUNC_WRAP(readdir)(DIR *dirp); struct dirent *MOCK_FUNC_REAL(readdir)(DIR *dirp); MOCK_FUNC_VAR_EXTERN(stat); int MOCK_FUNC_WRAP(stat)(const char *pathname, struct stat *statbuf); int MOCK_FUNC_REAL(stat)(const char *pathname, struct stat *statbuf); MOCK_FUNC_VAR_EXTERN(fputc); int MOCK_FUNC_WRAP(fputc)(int character, FILE *stream); int MOCK_FUNC_REAL(fputc)(int character, FILE *stream); MOCK_FUNC_VAR_EXTERN(time); time_t MOCK_FUNC_REAL(time)(time_t *timer); time_t MOCK_FUNC_WRAP(time)(time_t *timer); MOCK_FUNC_VAR_EXTERN(clock_gettime); int MOCK_FUNC_REAL(clock_gettime)(clockid_t clock_id, struct timespec *tp); int MOCK_FUNC_WRAP(clock_gettime)(clockid_t clock_id, struct timespec *tp); MOCK_FUNC_VAR_EXTERN(inet_aton); int MOCK_FUNC_WRAP(inet_aton)(const char *cp, struct in_addr *inp); int MOCK_FUNC_REAL(inet_aton)(const char *cp, struct in_addr *inp); MOCK_FUNC_VAR_EXTERN(inet_pton); int MOCK_FUNC_WRAP(inet_pton)(int af, const char *cp, void *buf); int MOCK_FUNC_REAL(inet_pton)(int af, const char *cp, void *buf); MOCK_FUNC_VAR_EXTERN(getaddrinfo); int MOCK_FUNC_WRAP(getaddrinfo)(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); int MOCK_FUNC_REAL(getaddrinfo)(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); MOCK_FUNC_VAR_EXTERN(freeaddrinfo); void MOCK_FUNC_WRAP(freeaddrinfo)(struct addrinfo *res); void MOCK_FUNC_REAL(freeaddrinfo)(struct addrinfo *res); MOCK_FUNC_VAR_EXTERN(socket); int MOCK_FUNC_WRAP(socket)(int domain, int type, int protocol); int MOCK_FUNC_REAL(socket)(int domain, int type, int protocol); MOCK_FUNC_VAR_EXTERN(setsockopt); int MOCK_FUNC_WRAP(setsockopt)(int fd, int level, int optname, const void *optval, socklen_t optlen); int MOCK_FUNC_REAL(setsockopt)(int fd, int level, int optname, const void *optval, socklen_t optlen); MOCK_FUNC_VAR_EXTERN(accept); extern int MOCK_FUNC_WRAP(accept_errno); int MOCK_FUNC_WRAP(accept)(int fd, __SOCKADDR_ARG addr, socklen_t *len); int MOCK_FUNC_REAL(accept)(int fd, __SOCKADDR_ARG addr, socklen_t *len); MOCK_FUNC_VAR_EXTERN(connect); int MOCK_FUNC_WRAP(connect)(int fd, const struct sockaddr *addr, socklen_t len); int MOCK_FUNC_REAL(connect)(int fd, const struct sockaddr *addr, socklen_t len); MOCK_FUNC_VAR_EXTERN(bind); int MOCK_FUNC_WRAP(bind)(int fd, __CONST_SOCKADDR_ARG addr, socklen_t len); int MOCK_FUNC_REAL(bind)(int fd, __CONST_SOCKADDR_ARG addr, socklen_t len); MOCK_FUNC_VAR_EXTERN(listen); int MOCK_FUNC_WRAP(listen)(int fd, int n); int MOCK_FUNC_REAL(listen)(int fd, int n); MOCK_FUNC_VAR_EXTERN(close); int MOCK_FUNC_WRAP(close)(int fd); int MOCK_FUNC_REAL(close)(int fd); MOCK_FUNC_VAR_EXTERN(open); int MOCK_FUNC_WRAP(open)(char *file, int flags, mode_t mode); int MOCK_FUNC_REAL(open)(char *file, int flags, mode_t mode); MOCK_FUNC_VAR_EXTERN(pselect); extern int MOCK_FUNC_WRAP(pselect_errno); int MOCK_FUNC_WRAP(pselect)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const __sigset_t *sigmask); int MOCK_FUNC_REAL(pselect)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const __sigset_t *sigmask); MOCK_FUNC_PROTOTYPE(raise, int, int __sig) MOCK_FUNC_PROTOTYPE(pthread_create, int, pthread_t *__newthread, const pthread_attr_t *__attr, void *(*__start_routine)(void *), void *__arg) MOCK_FUNC_PROTOTYPE(pthread_once, int, pthread_once_t *__once_control, void (*__init_routine)(void)) MOCK_FUNC_PROTOTYPE(pthread_join, int, pthread_t __th, void **__thread_return) MOCK_FUNC_PROTOTYPE(pthread_mutex_init, int, pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr) MOCK_FUNC_PROTOTYPE(pthread_mutex_destroy, int, pthread_mutex_t *__mutex) MOCK_FUNC_PROTOTYPE(pthread_mutex_trylock, int, pthread_mutex_t *__mutex) MOCK_FUNC_PROTOTYPE(pthread_mutex_lock, int, pthread_mutex_t *__mutex) MOCK_FUNC_PROTOTYPE(pthread_mutex_unlock, int, pthread_mutex_t *__mutex) MOCK_FUNC_PROTOTYPE(pthread_mutex_timedlock, int, pthread_mutex_t *__mutex, const struct timespec *__abstime) MOCK_FUNC_PROTOTYPE(pthread_setname_np, int, pthread_t thread, const char *name) MOCK_FUNC_PROTOTYPE(sem_init, int, sem_t *__sem, int __pshared, unsigned int __value) MOCK_FUNC_PROTOTYPE(sem_post, int, sem_t *__sem) MOCK_FUNC_PROTOTYPE(sem_destroy, int, sem_t *__sem) MOCK_FUNC_PROTOTYPE(sem_timedwait, int, sem_t *__sem, const struct timespec *__abstime) MOCK_FUNC_PROTOTYPE(eventfd, int, unsigned int __count, int __flags) MOCK_FUNC_PROTOTYPE(eventfd_read, int, int __fd, eventfd_t *__value) MOCK_FUNC_PROTOTYPE(eventfd_write, int, int __fd, eventfd_t __value) #endif cmocka-mocks-0.52.1/src/mock_libc/mock_libc.c000066400000000000000000000502101463302307500207460ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #include "cmocka_mocks/mock_libc.h" #include #include #include #include MOCK_FUNC_VAR_NEW(regcomp); int MOCK_FUNC_WRAP(regcomp)(regex_t *preg, const char *regex, int cflags) { if (MOCK_IS_ACTIVE(regcomp)) { check_expected_ptr(preg); check_expected_ptr(regex); check_expected(cflags); return mock_type(int); } return MOCK_FUNC_REAL(regcomp)(preg, regex, cflags); } MOCK_FUNC_VAR_NEW(regerror); size_t MOCK_FUNC_WRAP(regerror)(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) { if (MOCK_IS_ACTIVE(regerror)) { check_expected(errcode); check_expected_ptr(preg); check_expected_ptr(errbuf); check_expected(errbuf_size); return mock_type(size_t); } return MOCK_FUNC_REAL(regerror)(errcode, preg, errbuf, errbuf_size); } MOCK_FUNC_VAR_NEW(regexec); int MOCK_FUNC_WRAP(regexec)(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) { if (MOCK_IS_ACTIVE(regexec)) { check_expected_ptr(preg); check_expected_ptr(string); check_expected(nmatch); check_expected_ptr(pmatch); check_expected_ptr(eflags); return mock_type(int); } return MOCK_FUNC_REAL(regexec)(preg, string, nmatch, pmatch, eflags); } MOCK_FUNC_VAR_NEW(malloc); void *MOCK_FUNC_WRAP(malloc)(size_t size) { if (MOCK_IS_ACTIVE(malloc)) { check_expected(size); return mock_ptr_type(void *); } return MOCK_FUNC_REAL(malloc)(size); } MOCK_FUNC_VAR_NEW(realloc); void *MOCK_FUNC_WRAP(realloc)(void *ptr, size_t newSize) { if (MOCK_IS_ACTIVE(realloc)) { check_expected(ptr); check_expected(newSize); return mock_ptr_type(void *); } return MOCK_FUNC_REAL(realloc)(ptr, newSize); } MOCK_FUNC_VAR_NEW(calloc); void *MOCK_FUNC_WRAP(calloc)(size_t nmemb, size_t size) { if (MOCK_IS_ACTIVE(calloc)) { check_expected(nmemb); check_expected(size); return mock_ptr_type(void *); } return MOCK_FUNC_REAL(calloc)(nmemb, size); } MOCK_FUNC_VAR_NEW(free); void MOCK_FUNC_WRAP(free)(void *ptr) { if (MOCK_IS_ACTIVE(free)) { check_expected(ptr); } else { MOCK_FUNC_REAL(free)(ptr); } } MOCK_FUNC_VAR_NEW(memcpy); void *MOCK_FUNC_WRAP(memcpy)(void *destination, const void *source, size_t num) { if (MOCK_IS_ACTIVE(memcpy)) { check_expected(destination); check_expected(source); check_expected(num); return mock_ptr_type(void *); } return MOCK_FUNC_REAL(memcpy)(destination, source, num); } MOCK_FUNC_VAR_NEW(strdup); char *MOCK_FUNC_WRAP(strdup)(const char *string) { if (MOCK_IS_ACTIVE(strdup)) { check_expected(string); return mock_ptr_type(char *); } return MOCK_FUNC_REAL(strdup)(string); } MOCK_FUNC_VAR_NEW(strndup); char *MOCK_FUNC_WRAP(strndup)(const char *string, size_t n) { if (MOCK_IS_ACTIVE(strndup)) { check_expected(string); check_expected(n); return mock_ptr_type(char *); } return MOCK_FUNC_REAL(strndup)(string, n); } MOCK_FUNC_VAR_NEW(fopen); FILE *MOCK_FUNC_WRAP(fopen)(const char *filename, const char *mode) { if (MOCK_IS_ACTIVE(fopen)) { check_expected_ptr(filename); check_expected_ptr(mode); return mock_ptr_type(FILE *); } return MOCK_FUNC_REAL(fopen)(filename, mode); } MOCK_FUNC_VAR_NEW(fdopen); FILE *MOCK_FUNC_WRAP(fdopen)(const int fd, const char *mode) { if (MOCK_IS_ACTIVE(fdopen)) { check_expected(fd); check_expected_ptr(mode); return mock_ptr_type(FILE *); } return MOCK_FUNC_REAL(fdopen)(fd, mode); } MOCK_FUNC_VAR_NEW(fclose); int MOCK_FUNC_WRAP(fclose)(FILE *stream) { if (MOCK_IS_ACTIVE(fclose)) { check_expected_ptr(stream); return mock_type(int); } return MOCK_FUNC_REAL(fclose)(stream); } MOCK_FUNC_VAR_NEW(fwrite); size_t MOCK_FUNC_WRAP(fwrite)(const void *ptr, size_t size, size_t count, FILE *stream) { if (MOCK_IS_ACTIVE(fwrite)) { check_expected_ptr(ptr); check_expected(size); check_expected(count); check_expected_ptr(stream); return mock_type(size_t); } return MOCK_FUNC_REAL(fwrite)(ptr, size, count, stream); } MOCK_FUNC_VAR_NEW(fread); size_t MOCK_FUNC_WRAP(fread)(void *ptr, size_t size, size_t count, FILE *stream) { if (MOCK_IS_ACTIVE(fread)) { check_expected(ptr); check_expected(size); check_expected(count); check_expected_ptr(stream); return mock_type(size_t); } return MOCK_FUNC_REAL(fread)(ptr, size, count, stream); } MOCK_FUNC_VAR_NEW(scandir); int MOCK_FUNC_WRAP(scandir)(const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) { if (MOCK_IS_ACTIVE(scandir)) { check_expected_ptr(dirp); check_expected_ptr(namelist); check_expected_ptr(filter); check_expected_ptr(compar); return mock_type(int); } return MOCK_FUNC_REAL(scandir)(dirp, namelist, filter, compar); } MOCK_FUNC_VAR_NEW(access); int MOCK_FUNC_WRAP(access)(const char *pathname, int mode) { if (MOCK_IS_ACTIVE(access)) { check_expected_ptr(pathname); check_expected(mode); return mock_type(int); } return MOCK_FUNC_REAL(access)(pathname, mode); } MOCK_FUNC_VAR_NEW(fseek); int MOCK_FUNC_WRAP(fseek)(FILE *stream, long int offset, int origin) { if (MOCK_IS_ACTIVE(fseek)) { check_expected_ptr(stream); check_expected(offset); check_expected(origin); return mock_type(int); } return MOCK_FUNC_REAL(fseek)(stream, offset, origin); } MOCK_FUNC_VAR_NEW(rewind); void MOCK_FUNC_WRAP(rewind)(FILE *stream) { if (MOCK_IS_ACTIVE(rewind)) { check_expected_ptr(stream); } } MOCK_FUNC_VAR_NEW(ftell); long int MOCK_FUNC_WRAP(ftell)(FILE *stream) { if (MOCK_IS_ACTIVE(ftell)) { check_expected_ptr(stream); return mock_type(long); } return MOCK_FUNC_REAL(ftell)(stream); } MOCK_FUNC_VAR_NEW(popen); FILE *MOCK_FUNC_WRAP(popen)(const char *command, const char *type) { if (MOCK_IS_ACTIVE(popen)) { check_expected_ptr(command); check_expected_ptr(type); return mock_ptr_type(FILE *); } return MOCK_FUNC_REAL(popen)(command, type); } MOCK_FUNC_VAR_NEW(pclose); int MOCK_FUNC_WRAP(pclose)(FILE *stream) { if (MOCK_IS_ACTIVE(pclose)) { check_expected_ptr(stream); return mock_type(int); } return MOCK_FUNC_REAL(pclose)(stream); } MOCK_FUNC_VAR_NEW(getline); ssize_t MOCK_FUNC_WRAP(getline)(char **lineptr, size_t *n, FILE *stream) { if (MOCK_IS_ACTIVE(getline)) { check_expected_ptr(lineptr); check_expected(n); check_expected_ptr(stream); *lineptr = mock_ptr_type(char *); return mock_type(ssize_t); } return MOCK_FUNC_REAL(getline)(lineptr, n, stream); } MOCK_FUNC_VAR_NEW(getenv); char *MOCK_FUNC_WRAP(getenv)(const char *name) { if (MOCK_IS_ACTIVE(getenv)) { check_expected_ptr(name); return mock_ptr_type(char *); } return MOCK_FUNC_REAL(getenv)(name); } MOCK_FUNC_VAR_NEW(getpid); pid_t MOCK_FUNC_WRAP(getpid)() { if (MOCK_IS_ACTIVE(getpid)) { return mock_type(pid_t); } return MOCK_FUNC_REAL(getpid)(); } MOCK_FUNC_VAR_NEW(opendir); DIR *MOCK_FUNC_WRAP(opendir)(const char *name) { if (MOCK_IS_ACTIVE(opendir)) { check_expected_ptr(name); return mock_type(DIR *); } return MOCK_FUNC_REAL(opendir)(name); } MOCK_FUNC_VAR_NEW(closedir); int MOCK_FUNC_WRAP(closedir)(DIR *dirp) { if (MOCK_IS_ACTIVE(closedir)) { check_expected_ptr(dirp); return mock_type(int); } return MOCK_FUNC_REAL(closedir)(dirp); } MOCK_FUNC_VAR_NEW(remove); int MOCK_FUNC_WRAP(remove)(const char *filename) { if (MOCK_IS_ACTIVE(remove)) { check_expected_ptr(filename); return mock_type(int); } return MOCK_FUNC_REAL(remove)(filename); } MOCK_FUNC_VAR_NEW(readdir); struct dirent *MOCK_FUNC_WRAP(readdir)(DIR *dirp) { if (MOCK_IS_ACTIVE(readdir)) { check_expected_ptr(dirp); return mock_type(struct dirent *); } return MOCK_FUNC_REAL(readdir)(dirp); } MOCK_FUNC_VAR_NEW(stat); int MOCK_FUNC_WRAP(stat)(const char *pathname, struct stat *statbuf) { if (MOCK_IS_ACTIVE(stat)) { check_expected_ptr(pathname); check_expected_ptr(statbuf); return mock_type(int); } return MOCK_FUNC_REAL(stat)(pathname, statbuf); } MOCK_FUNC_VAR_NEW(fputc); int MOCK_FUNC_WRAP(fputc)(int character, FILE *stream) { if (MOCK_IS_ACTIVE(fputc)) { check_expected(character); check_expected_ptr(stream); return mock_type(int); } return MOCK_FUNC_REAL(fputc)(character, stream); } MOCK_FUNC_VAR_NEW(time); time_t MOCK_FUNC_WRAP(time)(time_t *timer) { if (MOCK_IS_ACTIVE(time)) { check_expected_ptr(timer); if (timer != NULL) { *timer = mock_type(time_t); } return mock_type(time_t); } return MOCK_FUNC_REAL(time)(timer); } MOCK_FUNC_VAR_NEW(clock_gettime); int MOCK_FUNC_WRAP(clock_gettime)(clockid_t clock_id, struct timespec *tp) { if (MOCK_IS_ACTIVE(clock_gettime)) { check_expected(clock_id); check_expected_ptr(tp); memcpy(tp, mock_ptr_type(struct timespec *), sizeof(struct timespec)); return mock_type(int); } return MOCK_FUNC_REAL(clock_gettime)(clock_id, tp); } MOCK_FUNC_VAR_NEW(inet_aton); int MOCK_FUNC_WRAP(inet_aton)(const char *cp, struct in_addr *inp) { if (MOCK_IS_ACTIVE(inet_aton)) { check_expected_ptr(cp); check_expected_ptr(inp); return mock_type(int); } return MOCK_FUNC_REAL(inet_aton)(cp, inp); } MOCK_FUNC_VAR_NEW(inet_pton); int MOCK_FUNC_WRAP(inet_pton)(int af, const char *cp, void *buf) { if (MOCK_IS_ACTIVE(inet_pton)) { check_expected(af); check_expected_ptr(cp); check_expected_ptr(buf); return mock_type(int); } return MOCK_FUNC_REAL(inet_pton)(af, cp, buf); } MOCK_FUNC_VAR_NEW(getaddrinfo); int MOCK_FUNC_WRAP(getaddrinfo)(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { if (MOCK_IS_ACTIVE(getaddrinfo)) { check_expected_ptr(node); check_expected_ptr(service); check_expected_ptr(hints); *res = mock_ptr_type(struct addrinfo *); return mock_type(int); } return MOCK_FUNC_REAL(getaddrinfo)(node, service, hints, res); } MOCK_FUNC_VAR_NEW(freeaddrinfo); void MOCK_FUNC_WRAP(freeaddrinfo)(struct addrinfo *res) { if (MOCK_IS_ACTIVE(freeaddrinfo)) { check_expected_ptr(res); } else { MOCK_FUNC_REAL(freeaddrinfo)(res); } } MOCK_FUNC_VAR_NEW(socket); int MOCK_FUNC_WRAP(socket)(int domain, int type, int protocol) { if (MOCK_IS_ACTIVE(socket)) { check_expected(domain); check_expected(type); check_expected(protocol); return mock_type(int); } return MOCK_FUNC_REAL(socket)(domain, type, protocol); } MOCK_FUNC_VAR_NEW(setsockopt); int MOCK_FUNC_WRAP(setsockopt)(int fd, int level, int optname, const void *optval, socklen_t optlen) { if (MOCK_IS_ACTIVE(setsockopt)) { check_expected(fd); check_expected(level); check_expected(optname); check_expected_ptr(optval); check_expected(optlen); return mock_type(int); } return MOCK_FUNC_REAL(setsockopt)(fd, level, optname, optval, optlen); } MOCK_FUNC_VAR_NEW(accept); int MOCK_FUNC_WRAP(accept_errno = 0); int MOCK_FUNC_WRAP(accept)(int fd, __SOCKADDR_ARG addr, socklen_t *len) { if (MOCK_IS_ACTIVE(accept)) { check_expected(fd); check_expected_ptr(addr); check_expected(len); if (MOCK_FUNC_WRAP(accept_errno) != 0) { errno = MOCK_FUNC_WRAP(accept_errno); MOCK_FUNC_WRAP(accept_errno) = 0; } return mock_type(int); } return MOCK_FUNC_REAL(accept)(fd, addr, len); } MOCK_FUNC_VAR_NEW(connect); int MOCK_FUNC_WRAP(connect)(int fd, const struct sockaddr *addr, socklen_t len) { if (MOCK_IS_ACTIVE(connect)) { check_expected(fd); check_expected_ptr(addr); check_expected(len); return mock_type(int); } return MOCK_FUNC_REAL(connect)(fd, addr, len); } MOCK_FUNC_VAR_NEW(bind); int MOCK_FUNC_WRAP(bind)(int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) { if (MOCK_IS_ACTIVE(bind)) { check_expected(fd); check_expected(addr); check_expected(len); return mock_type(int); } return MOCK_FUNC_REAL(bind)(fd, addr, len); } MOCK_FUNC_VAR_NEW(listen); int MOCK_FUNC_WRAP(listen)(int fd, int n) { if (MOCK_IS_ACTIVE(listen)) { check_expected(fd); check_expected(n); return mock_type(int); } return MOCK_FUNC_REAL(listen)(fd, n); } MOCK_FUNC_VAR_NEW(close); int MOCK_FUNC_WRAP(close)(int fd) { if (MOCK_IS_ACTIVE(close)) { check_expected(fd); return mock_type(int); } return MOCK_FUNC_REAL(close)(fd); } MOCK_FUNC_VAR_NEW(open); int MOCK_FUNC_WRAP(open)(char *file, int flags, mode_t mode) { if (MOCK_IS_ACTIVE(open)) { check_expected(file); check_expected(flags); check_expected(mode); return mock_type(int); } return MOCK_FUNC_REAL(open)(file, flags, mode); } MOCK_FUNC_VAR_NEW(pselect); int MOCK_FUNC_WRAP(pselect_errno = 0); int MOCK_FUNC_WRAP(pselect)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const __sigset_t *sigmask) { if (MOCK_IS_ACTIVE(pselect)) { check_expected(nfds); check_expected_ptr(readfds); check_expected_ptr(writefds); check_expected_ptr(exceptfds); check_expected_ptr(timeout); check_expected_ptr(sigmask); if (MOCK_FUNC_WRAP(pselect_errno) != 0) { errno = MOCK_FUNC_WRAP(pselect_errno); MOCK_FUNC_WRAP(pselect_errno) = 0; } return mock_type(int); } return MOCK_FUNC_REAL(pselect)(nfds, readfds, writefds, exceptfds, timeout, sigmask); } MOCK_FUNC_VAR_NEW(raise); int MOCK_FUNC_WRAP(raise)(int __sig) { if (MOCK_IS_ACTIVE(raise)) { check_expected(__sig); return mock_type(int); } return MOCK_FUNC_REAL(raise)(__sig); } MOCK_FUNC_VAR_NEW(pthread_create); int MOCK_FUNC_WRAP(pthread_create)(pthread_t *__newthread, const pthread_attr_t *__attr, void *(*__start_routine)(void *), void *__arg) { int result; switch (MOCK_GET_TYPE(pthread_create)) { case CMOCKA_MOCK_ENABLED_WITH_FUNC: result = MOCK_FUNC_WITH(pthread_create)(__newthread, __attr, __start_routine, __arg); break; case CMOCKA_MOCK_ENABLED: check_expected_ptr(__newthread); check_expected_ptr(__attr); check_expected_ptr(__start_routine); check_expected_ptr(__arg); result = mock_type(int); break; default: result = MOCK_FUNC_REAL(pthread_create)(__newthread, __attr, __start_routine, __arg); break; } return result; } MOCK_FUNC_VAR_NEW(pthread_once); int MOCK_FUNC_WRAP(pthread_once)(pthread_once_t *__once_control, void (*__init_routine)(void)) { if (MOCK_IS_ACTIVE(pthread_once)) { check_expected_ptr(__once_control); check_expected_ptr(__init_routine); return mock_type(int); } return MOCK_FUNC_REAL(pthread_once)(__once_control, __init_routine); } MOCK_FUNC_VAR_NEW(pthread_join); int MOCK_FUNC_WRAP(pthread_join)(pthread_t __th, void **__thread_return) { if (MOCK_IS_ACTIVE(pthread_join)) { check_expected(__th); check_expected_ptr(__thread_return); return mock_type(int); } return MOCK_FUNC_REAL(pthread_join)(__th, __thread_return); } MOCK_FUNC_VAR_NEW(pthread_mutex_init); int MOCK_FUNC_WRAP(pthread_mutex_init)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr) { if (MOCK_IS_ACTIVE(pthread_mutex_init)) { check_expected_ptr(__mutex); check_expected_ptr(__mutexattr); return mock_type(int); } return MOCK_FUNC_REAL(pthread_mutex_init)(__mutex, __mutexattr); } MOCK_FUNC_VAR_NEW(pthread_mutex_destroy); int MOCK_FUNC_WRAP(pthread_mutex_destroy)(pthread_mutex_t *__mutex) { if (MOCK_IS_ACTIVE(pthread_mutex_destroy)) { check_expected_ptr(__mutex); return mock_type(int); } return MOCK_FUNC_REAL(pthread_mutex_destroy)(__mutex); } MOCK_FUNC_VAR_NEW(pthread_mutex_trylock); int MOCK_FUNC_WRAP(pthread_mutex_trylock)(pthread_mutex_t *__mutex) { if (MOCK_IS_ACTIVE(pthread_mutex_trylock)) { check_expected_ptr(__mutex); return mock_type(int); } return MOCK_FUNC_REAL(pthread_mutex_trylock)(__mutex); } MOCK_FUNC_VAR_NEW(pthread_mutex_lock); int MOCK_FUNC_WRAP(pthread_mutex_lock)(pthread_mutex_t *__mutex) { if (MOCK_IS_ACTIVE(pthread_mutex_lock)) { check_expected_ptr(__mutex); return mock_type(int); } return MOCK_FUNC_REAL(pthread_mutex_lock)(__mutex); } MOCK_FUNC_VAR_NEW(pthread_mutex_unlock); int MOCK_FUNC_WRAP(pthread_mutex_unlock)(pthread_mutex_t *__mutex) { if (MOCK_IS_ACTIVE(pthread_mutex_unlock)) { check_expected_ptr(__mutex); return mock_type(int); } return MOCK_FUNC_REAL(pthread_mutex_unlock)(__mutex); } MOCK_FUNC_VAR_NEW(pthread_mutex_timedlock); int MOCK_FUNC_WRAP(pthread_mutex_timedlock)(pthread_mutex_t *__mutex, const struct timespec *__abstime) { if (MOCK_IS_ACTIVE(pthread_mutex_timedlock)) { check_expected_ptr(__mutex); check_expected_ptr(__abstime); return mock_type(int); } return MOCK_FUNC_REAL(pthread_mutex_timedlock)(__mutex, __abstime); } MOCK_FUNC_VAR_NEW(pthread_setname_np); int MOCK_FUNC_WRAP(pthread_setname_np)(pthread_t thread, const char *name) { if (MOCK_IS_ACTIVE(pthread_setname_np)) { check_expected(thread); check_expected_ptr(name); return mock_type(int); } return MOCK_FUNC_REAL(pthread_setname_np)(thread, name); } MOCK_FUNC_VAR_NEW(sem_init); int MOCK_FUNC_WRAP(sem_init)(sem_t *__sem, int __pshared, unsigned int __value) { if (MOCK_IS_ACTIVE(sem_init)) { check_expected_ptr(__sem); check_expected(__pshared); check_expected(__value); return mock_type(int); } return MOCK_FUNC_REAL(sem_init)(__sem, __pshared, __value); } MOCK_FUNC_VAR_NEW(sem_post); int MOCK_FUNC_WRAP(sem_post)(sem_t *__sem) { if (MOCK_IS_ACTIVE(sem_post)) { check_expected_ptr(__sem); return mock_type(int); } return MOCK_FUNC_REAL(sem_post)(__sem); } MOCK_FUNC_VAR_NEW(sem_destroy); int MOCK_FUNC_WRAP(sem_destroy)(sem_t *__sem) { if (MOCK_IS_ACTIVE(sem_destroy)) { check_expected_ptr(__sem); return mock_type(int); } return MOCK_FUNC_REAL(sem_destroy)(__sem); } MOCK_FUNC_VAR_NEW(sem_timedwait); int MOCK_FUNC_WRAP(sem_timedwait)(sem_t *__sem, const struct timespec *__abstime) { if (MOCK_IS_ACTIVE(sem_timedwait)) { check_expected_ptr(__sem); check_expected_ptr(__abstime); return mock_type(int); } return MOCK_FUNC_REAL(sem_timedwait)(__sem, __abstime); } MOCK_FUNC_VAR_NEW(eventfd); int MOCK_FUNC_WRAP(eventfd)(unsigned int __count, int __flags) { if (MOCK_IS_ACTIVE(eventfd)) { check_expected(__count); check_expected(__flags); return mock_type(int); } return MOCK_FUNC_REAL(eventfd)(__count, __flags); } MOCK_FUNC_VAR_NEW(eventfd_read); int MOCK_FUNC_WRAP(eventfd_read)(int __fd, eventfd_t *__value) { if (MOCK_IS_ACTIVE(eventfd_read)) { check_expected(__fd); check_expected_ptr(__value); return mock_type(int); } return MOCK_FUNC_REAL(eventfd_read)(__fd, __value); } MOCK_FUNC_VAR_NEW(eventfd_write); int MOCK_FUNC_WRAP(eventfd_write)(int __fd, eventfd_t __value) { if (MOCK_IS_ACTIVE(eventfd_write)) { check_expected(__fd); check_expected(__value); return mock_type(int); } return MOCK_FUNC_REAL(eventfd_write)(__fd, __value); } cmocka-mocks-0.52.1/src/mock_libmnl/000077500000000000000000000000001463302307500172265ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_libmnl/CMakeLists.txt000066400000000000000000000031731463302307500217720ustar00rootroot00000000000000# SPDX-License-Identifier: MIT find_package(cmocka_extensions REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(LIBMNL REQUIRED libmnl) add_library( mock_libmnl SHARED mock_libmnl.c ) set_property(TARGET mock_libmnl PROPERTY POSITION_INDEPENDENT_CODE ON) set_target_properties( mock_libmnl PROPERTIES SOVERSION ${CMOCKA_MOCKS_VERSION_MAJOR} VERSION ${CMOCKA_MOCKS_VERSION_MAJOR}.${CMOCKA_MOCKS_VERSION_MINOR}.${CMOCKA_MOCKS_VERSION_MICRO} ) target_link_options( mock_libmnl PUBLIC -Wl,--wrap=mnl_socket_open -Wl,--wrap=mnl_socket_bind -Wl,--wrap=mnl_socket_close -Wl,--wrap=mnl_socket_recvfrom -Wl,--wrap=mnl_socket_sendto -Wl,--wrap=mnl_socket_get_portid ) target_include_directories( mock_libmnl PRIVATE $ PUBLIC $ ) target_link_libraries( mock_libmnl PRIVATE cmocka cmocka_extensions::cmocka_extensions ${LIBMNL_LIBRARIES} ) install( EXPORT mock_libmnlTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks NAMESPACE cmocka_mocks:: FILE mock_libmnlTargets.cmake # Not sure if this is still needed ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/mock_libmnlConfigVersion.cmake VERSION ${PKG_VERSION} COMPATIBILITY SameMajorVersion ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/mock_libmnlConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks" ) install(TARGETS mock_libmnl EXPORT mock_libmnlTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) cmocka-mocks-0.52.1/src/mock_libmnl/include/000077500000000000000000000000001463302307500206515ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_libmnl/include/cmocka_mocks/000077500000000000000000000000001463302307500233025ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_libmnl/include/cmocka_mocks/mock_libmnl.h000066400000000000000000000014461463302307500257460ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #ifndef __MOCK_LIBMNL_H__ #define __MOCK_LIBMNL_H__ #include #include #include #include MOCK_FUNC_PROTOTYPE(mnl_socket_open, struct mnl_socket *, int bus) MOCK_FUNC_PROTOTYPE(mnl_socket_bind, int, struct mnl_socket *nl, unsigned int groups, pid_t pid) MOCK_FUNC_PROTOTYPE(mnl_socket_close, int, struct mnl_socket *nl) MOCK_FUNC_PROTOTYPE(mnl_socket_recvfrom, ssize_t, const struct mnl_socket *nl, void *buf, size_t siz) MOCK_FUNC_PROTOTYPE(mnl_socket_sendto, ssize_t, const struct mnl_socket *nl, const void *req, size_t siz) MOCK_FUNC_PROTOTYPE(mnl_socket_get_portid, unsigned int, struct mnl_socket *nl) #endif /* __MOCK_LIBMNL_H__ */ cmocka-mocks-0.52.1/src/mock_libmnl/mock_libmnl.c000066400000000000000000000035251463302307500216650ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #include "cmocka_mocks/mock_libmnl.h" #include MOCK_FUNC_BODY(mnl_socket_open, struct mnl_socket *, int bus) { if (MOCK_IS_ACTIVE(mnl_socket_open)) { check_expected(bus); return mock_ptr_type(struct mnl_socket *); } return MOCK_FUNC_REAL(mnl_socket_open)(bus); } MOCK_FUNC_BODY(mnl_socket_bind, int, struct mnl_socket *nl, unsigned int groups, pid_t pid) { if (MOCK_IS_ACTIVE(mnl_socket_bind)) { check_expected_ptr(nl); check_expected(groups); check_expected(pid); return mock_type(int); } return MOCK_FUNC_REAL(mnl_socket_bind)(nl, groups, pid); } MOCK_FUNC_BODY(mnl_socket_close, int, struct mnl_socket *nl) { if (MOCK_IS_ACTIVE(mnl_socket_close)) { check_expected_ptr(nl); return mock_type(int); } return MOCK_FUNC_REAL(mnl_socket_close)(nl); } MOCK_FUNC_BODY(mnl_socket_recvfrom, ssize_t, const struct mnl_socket *nl, void *buf, size_t siz) { if (MOCK_IS_ACTIVE(mnl_socket_recvfrom)) { check_expected_ptr(nl); check_expected_ptr(buf); check_expected(siz); return mock_type(ssize_t); } return MOCK_FUNC_REAL(mnl_socket_recvfrom)(nl, buf, siz); } MOCK_FUNC_BODY(mnl_socket_sendto, ssize_t, const struct mnl_socket *nl, const void *req, size_t siz) { if (MOCK_IS_ACTIVE(mnl_socket_sendto)) { check_expected_ptr(nl); check_expected_ptr(req); check_expected(siz); return mock_type(ssize_t); } return MOCK_FUNC_REAL(mnl_socket_sendto)(nl, req, siz); } MOCK_FUNC_BODY(mnl_socket_get_portid, unsigned int, struct mnl_socket *nl) { if (MOCK_IS_ACTIVE(mnl_socket_get_portid)) { check_expected_ptr(nl); return mock_type(unsigned int); } return MOCK_FUNC_REAL(mnl_socket_get_portid)(nl); } cmocka-mocks-0.52.1/src/mock_openssl/000077500000000000000000000000001463302307500174345ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_openssl/CMakeLists.txt000066400000000000000000000034601463302307500221770ustar00rootroot00000000000000# SPDX-License-Identifier: MIT find_package(cmocka_extensions REQUIRED) find_package(OpenSSL REQUIRED) add_library( mock_openssl SHARED mock_openssl.c ) set_property(TARGET mock_openssl PROPERTY POSITION_INDEPENDENT_CODE ON) set_target_properties( mock_openssl PROPERTIES SOVERSION ${CMOCKA_MOCKS_VERSION_MAJOR} VERSION ${CMOCKA_MOCKS_VERSION_MAJOR}.${CMOCKA_MOCKS_VERSION_MINOR}.${CMOCKA_MOCKS_VERSION_MICRO} ) target_link_options( mock_openssl PUBLIC -Wl,--wrap=PEM_read_PUBKEY -Wl,--wrap=EVP_MD_CTX_new -Wl,--wrap=EVP_MD_CTX_create -Wl,--wrap=EVP_MD_fetch -Wl,--wrap=EVP_get_digestbyname -Wl,--wrap=EVP_DecodeBlock -Wl,--wrap=EVP_DigestVerifyInit -Wl,--wrap=EVP_DigestUpdate -Wl,--wrap=EVP_DigestVerifyFinal -Wl,--wrap=EVP_PKEY_free -Wl,--wrap=EVP_MD_free -Wl,--wrap=EVP_MD_CTX_free -Wl,--wrap=EVP_MD_CTX_destroy ) target_include_directories( mock_openssl PRIVATE $ PUBLIC $ ) target_link_libraries( mock_openssl PRIVATE cmocka cmocka_extensions::cmocka_extensions OpenSSL::Crypto ) install( EXPORT mock_opensslTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks NAMESPACE cmocka_mocks:: FILE mock_opensslTargets.cmake # Not sure if this is still needed ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/mock_opensslConfigVersion.cmake VERSION ${PKG_VERSION} COMPATIBILITY SameMajorVersion ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/mock_opensslConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmocka_mocks" ) install(TARGETS mock_openssl EXPORT mock_opensslTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) cmocka-mocks-0.52.1/src/mock_openssl/include/000077500000000000000000000000001463302307500210575ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_openssl/include/cmocka_mocks/000077500000000000000000000000001463302307500235105ustar00rootroot00000000000000cmocka-mocks-0.52.1/src/mock_openssl/include/cmocka_mocks/mock_openssl.h000066400000000000000000000054501463302307500263610ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #ifndef __MOCK_OPENSSL_H__ #define __MOCK_OPENSSL_H__ #include #include #include #include #include // clang-format off // because this order is a cmocka requirement #include #include #include #include #include #include #include // clang-format on MOCK_FUNC_VAR_EXTERN(PEM_read_PUBKEY); EVP_PKEY *MOCK_FUNC_WRAP(PEM_read_PUBKEY)(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); EVP_PKEY *MOCK_FUNC_REAL(PEM_read_PUBKEY)(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); MOCK_FUNC_VAR_EXTERN(EVP_DecodeBlock); int MOCK_FUNC_WRAP(EVP_DecodeBlock)(unsigned char *t, const unsigned char *f, int n); int MOCK_FUNC_REAL(EVP_DecodeBlock)(unsigned char *t, const unsigned char *f, int n); #if OPENSSL_VERSION_NUMBER >= 0x10100000L MOCK_FUNC_VAR_EXTERN(EVP_MD_CTX_new); EVP_MD_CTX *MOCK_FUNC_WRAP(EVP_MD_CTX_new)(void); EVP_MD_CTX *MOCK_FUNC_REAL(EVP_MD_CTX_new)(void); #else MOCK_FUNC_VAR_EXTERN(EVP_MD_CTX_create); EVP_MD_CTX *MOCK_FUNC_WRAP(EVP_MD_CTX_create)(void); EVP_MD_CTX *MOCK_FUNC_REAL(EVP_MD_CTX_create)(void); #endif MOCK_FUNC_VAR_EXTERN(EVP_get_digestbyname); const EVP_MD *MOCK_FUNC_WRAP(EVP_get_digestbyname)(const char *name); const EVP_MD *MOCK_FUNC_REAL(EVP_get_digestbyname)(const char *name); MOCK_FUNC_VAR_EXTERN(EVP_DigestVerifyInit); int MOCK_FUNC_WRAP(EVP_DigestVerifyInit)(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); int MOCK_FUNC_REAL(EVP_DigestVerifyInit)(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); MOCK_FUNC_VAR_EXTERN(EVP_DigestUpdate); int MOCK_FUNC_WRAP(EVP_DigestUpdate)(EVP_MD_CTX *ctx, const void *d, size_t cnt); int MOCK_FUNC_REAL(EVP_DigestUpdate)(EVP_MD_CTX *ctx, const void *d, size_t cnt); MOCK_FUNC_VAR_EXTERN(EVP_DigestVerifyFinal); int MOCK_FUNC_WRAP(EVP_DigestVerifyFinal)(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen); int MOCK_FUNC_REAL(EVP_DigestVerifyFinal)(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen); MOCK_FUNC_VAR_EXTERN(EVP_PKEY_free); void MOCK_FUNC_WRAP(EVP_PKEY_free)(EVP_PKEY *pkey); void MOCK_FUNC_REAL(EVP_PKEY_free)(EVP_PKEY *pkey); #if OPENSSL_VERSION_NUMBER >= 0x10100000L MOCK_FUNC_VAR_EXTERN(EVP_MD_CTX_free); void MOCK_FUNC_WRAP(EVP_MD_CTX_free)(EVP_MD_CTX *mdctx); void MOCK_FUNC_REAL(EVP_MD_CTX_free)(EVP_MD_CTX *mdctx); #else MOCK_FUNC_VAR_EXTERN(EVP_MD_CTX_destroy); void MOCK_FUNC_WRAP(EVP_MD_CTX_destroy)(EVP_MD_CTX *mdctx); void MOCK_FUNC_REAL(EVP_MD_CTX_destroy)(EVP_MD_CTX *mdctx); #endif #endif /* __MOCK_OPENSSL_H__ */ cmocka-mocks-0.52.1/src/mock_openssl/mock_openssl.c000066400000000000000000000072551463302307500223050ustar00rootroot00000000000000// SPDX-License-Identifier: MIT #include "cmocka_mocks/mock_openssl.h" #include #include MOCK_FUNC_VAR_NEW(PEM_read_PUBKEY); EVP_PKEY *MOCK_FUNC_WRAP(PEM_read_PUBKEY)(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u) { if (MOCK_IS_ACTIVE(PEM_read_PUBKEY)) { check_expected_ptr(fp); check_expected_ptr(x); check_expected_ptr(cb); check_expected_ptr(u); return mock_ptr_type(EVP_PKEY *); } return MOCK_FUNC_REAL(PEM_read_PUBKEY)(fp, x, cb, u); } MOCK_FUNC_VAR_NEW(EVP_DecodeBlock); int MOCK_FUNC_WRAP(EVP_DecodeBlock)(unsigned char *t, const unsigned char *f, int n) { if (MOCK_IS_ACTIVE(EVP_DecodeBlock)) { check_expected_ptr(t); check_expected(f); check_expected(n); return mock_type(int); } return MOCK_FUNC_REAL(EVP_DecodeBlock)(t, f, n); } #if OPENSSL_VERSION_NUMBER >= 0x10100000L MOCK_FUNC_VAR_NEW(EVP_MD_CTX_new); EVP_MD_CTX *MOCK_FUNC_WRAP(EVP_MD_CTX_new)(void) { if (MOCK_IS_ACTIVE(EVP_MD_CTX_new)) { return mock_ptr_type(EVP_MD_CTX *); } return MOCK_FUNC_REAL(EVP_MD_CTX_new)(); } #else MOCK_FUNC_VAR_NEW(EVP_MD_CTX_create); EVP_MD_CTX *MOCK_FUNC_WRAP(EVP_MD_CTX_create)(void) { if (MOCK_IS_ACTIVE(EVP_MD_CTX_create)) { return mock_ptr_type(EVP_MD_CTX *); } return MOCK_FUNC_REAL(EVP_MD_CTX_create)(); } #endif MOCK_FUNC_VAR_NEW(EVP_get_digestbyname); const EVP_MD *MOCK_FUNC_WRAP(EVP_get_digestbyname)(const char *name) { if (MOCK_IS_ACTIVE(EVP_get_digestbyname)) { check_expected(name); return mock_ptr_type(const EVP_MD *); } return MOCK_FUNC_REAL(EVP_get_digestbyname)(name); } MOCK_FUNC_VAR_NEW(EVP_DigestVerifyInit); int MOCK_FUNC_WRAP(EVP_DigestVerifyInit)(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey) { if (MOCK_IS_ACTIVE(EVP_DigestVerifyInit)) { check_expected_ptr(ctx); check_expected_ptr(pctx); check_expected_ptr(type); check_expected_ptr(e); check_expected_ptr(pkey); return mock_type(int); } return MOCK_FUNC_REAL(EVP_DigestVerifyInit)(ctx, pctx, type, e, pkey); } MOCK_FUNC_VAR_NEW(EVP_DigestUpdate); int MOCK_FUNC_WRAP(EVP_DigestUpdate)(EVP_MD_CTX *ctx, const void *d, size_t cnt) { if (MOCK_IS_ACTIVE(EVP_DigestUpdate)) { check_expected_ptr(ctx); check_expected_ptr(d); check_expected(cnt); return mock_type(int); } return MOCK_FUNC_REAL(EVP_DigestUpdate)(ctx, d, cnt); } MOCK_FUNC_VAR_NEW(EVP_DigestVerifyFinal); int MOCK_FUNC_WRAP(EVP_DigestVerifyFinal)(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen) { if (MOCK_IS_ACTIVE(EVP_DigestVerifyFinal)) { check_expected_ptr(ctx); check_expected_ptr(sig); check_expected(siglen); return mock_type(int); } return MOCK_FUNC_REAL(EVP_DigestVerifyFinal)(ctx, sig, siglen); } MOCK_FUNC_VAR_NEW(EVP_PKEY_free); void MOCK_FUNC_WRAP(EVP_PKEY_free)(EVP_PKEY *pkey) { if (MOCK_IS_ACTIVE(EVP_PKEY_free)) { check_expected_ptr(pkey); return; } MOCK_FUNC_REAL(EVP_PKEY_free)(pkey); } #if OPENSSL_VERSION_NUMBER >= 0x10100000L MOCK_FUNC_VAR_NEW(EVP_MD_CTX_free); void MOCK_FUNC_WRAP(EVP_MD_CTX_free)(EVP_MD_CTX *mdctx) { if (MOCK_IS_ACTIVE(EVP_MD_CTX_free)) { check_expected_ptr(mdctx); return; } MOCK_FUNC_REAL(EVP_MD_CTX_free)(mdctx); } #else MOCK_FUNC_VAR_NEW(EVP_MD_CTX_destroy); void MOCK_FUNC_WRAP(EVP_MD_CTX_destroy)(EVP_MD_CTX *mdctx) { if (MOCK_IS_ACTIVE(EVP_MD_CTX_destroy)) { check_expected_ptr(mdctx); return; } MOCK_FUNC_REAL(EVP_MD_CTX_destroy)(mdctx); } #endif