├── .github └── policies │ └── resourceManagement.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── SECURITY.md ├── build ├── devops_gated.yml └── linux │ ├── build_linux.sh │ └── build_linux_iwyu.sh ├── configs └── umock_cConfig.cmake ├── devdoc ├── umock_c_lib_requirements_with_ids.md ├── umock_c_negative_tests_requirements.md ├── umock_c_requirements.md ├── umock_lock_factory_pthread.md ├── umock_lock_factory_windows.md ├── umockalloc_requirements.md ├── umockautoignoreargs_requirements.md ├── umockcall_requirements.md ├── umockcallpairs_requirements.md ├── umockcallrecorder_requirements.md ├── umockstring_requirements.md ├── umocktypename_requirements.md ├── umocktypes_bool_requirements.md ├── umocktypes_c_requirements.md ├── umocktypes_charptr_requirements.md ├── umocktypes_requirements.md ├── umocktypes_stdint_requirements.md ├── umocktypes_struct_requirements.md ├── umocktypes_wcharptr_requirements.md └── umocktypes_windows_requirements.md ├── doc └── umock_c.md ├── inc └── umock_c │ ├── aux_inc │ ├── cstdbool │ ├── cstdint │ ├── inttypes.h │ ├── stdbool.h │ └── stdint.h │ ├── umock_c.h │ ├── umock_c_internal.h │ ├── umock_c_negative_tests.h │ ├── umock_c_prod.h │ ├── umock_lock_factory.h │ ├── umock_lock_factory_default.h │ ├── umock_lock_if.h │ ├── umock_log.h │ ├── umockalloc.h │ ├── umockautoignoreargs.h │ ├── umockcall.h │ ├── umockcallpairs.h │ ├── umockcallrecorder.h │ ├── umockstring.h │ ├── umocktypename.h │ ├── umocktypes.h │ ├── umocktypes_bool.h │ ├── umocktypes_c.h │ ├── umocktypes_charptr.h │ ├── umocktypes_stdint.h │ ├── umocktypes_struct.h │ ├── umocktypes_wcharptr.h │ └── umocktypes_windows.h ├── readme.md ├── set_vld_vars.bat ├── src ├── umock_c.c ├── umock_c_negative_tests.c ├── umock_lock_factory_pthread.c ├── umock_lock_factory_windows.c ├── umockalloc.c ├── umockautoignoreargs.c ├── umockcall.c ├── umockcallpairs.c ├── umockcallrecorder.c ├── umockstring.c ├── umocktypename.c ├── umocktypes.c ├── umocktypes_bool.c ├── umocktypes_c.c ├── umocktypes_charptr.c ├── umocktypes_stdint.c ├── umocktypes_wcharptr.c └── umocktypes_windows.c └── tests ├── CMakeLists.txt ├── umock_c_gen_func_decl_int ├── CMakeLists.txt ├── umock_c_gen_func_decl_int.c └── umock_c_gen_func_multiple_inc.c ├── umock_c_int ├── CMakeLists.txt ├── test_dependency.h └── umock_c_int.c ├── umock_c_malloc_hook_int ├── CMakeLists.txt └── umock_c_malloc_hook_int.c ├── umock_c_mock_filters_int ├── CMakeLists.txt ├── test_dependency.h └── umock_c_mock_filters_int.c ├── umock_c_negt_int ├── CMakeLists.txt ├── test_dependency.h └── umock_c_negt_int_tests.c ├── umock_c_negt_noini_ut ├── CMakeLists.txt └── umock_c_negt_noint_tests.c ├── umock_c_negt_ut ├── CMakeLists.txt └── umock_c_negative_tests_ut.c ├── umock_c_ptrarg_leak_int ├── CMakeLists.txt └── umock_c_ptrarg_leak_int.c ├── umock_c_reals_int ├── CMakeLists.txt ├── test_dependency.h ├── test_dependency_no_enable_mocks.h ├── test_dependency_real_code.c ├── test_dependency_real_code_no_enable_mocks.c ├── test_unit_no_reals.h └── umock_c_reals_int.c ├── umock_c_reg_win_types_int ├── CMakeLists.txt └── umock_c_reg_win_types_int.c ├── umock_c_ut ├── CMakeLists.txt └── umock_c_ut.c ├── umock_c_windows_types_int ├── CMakeLists.txt ├── test_dependency.h └── umock_c_windows_types_int.c ├── umock_c_with_lock_factory_int ├── CMakeLists.txt ├── minipal │ ├── umock_threadapi.h │ ├── umock_threadapi_pthread.c │ └── umock_threadapi_win32.c └── umock_c_with_lock_factory_int.c ├── umock_c_wout_init_ut ├── CMakeLists.txt ├── main.c └── umock_c_wout_init_ut.c ├── umock_lock_factory_pthread_ut ├── CMakeLists.txt ├── umock_lock_factory_pthread_mocked.c └── umock_lock_factory_pthread_ut.c ├── umock_lock_factory_windows_ut ├── CMakeLists.txt ├── umock_lock_factory_windows_mocked.c └── umock_lock_factory_windows_ut.c ├── umockalloc_ut ├── CMakeLists.txt ├── umockalloc_mocked.c └── umockalloc_ut.c ├── umockautoignoreargs_ut ├── CMakeLists.txt └── umockautoignoreargs_ut.c ├── umockcall_ut ├── CMakeLists.txt ├── umockcall_mocked.c └── umockcall_ut.c ├── umockcallpairs_ut ├── CMakeLists.txt ├── umockcallpairs_mocked.c └── umockcallpairs_ut.c ├── umockcallrecorder_ut ├── CMakeLists.txt ├── umockcallrecorder_mocked.c └── umockcallrecorder_ut.c ├── umockstring_ut ├── CMakeLists.txt ├── umockstring_mocked.c └── umockstring_ut.c ├── umocktypename_ut ├── CMakeLists.txt ├── umocktypename_mocked.c └── umocktypename_ut.c ├── umocktypes_bool_ut ├── CMakeLists.txt ├── umocktypes_bool_mocked.c └── umocktypes_bool_ut.c ├── umocktypes_c_fixed_buffer_ut └── CMakeLists.txt ├── umocktypes_c_ut ├── CMakeLists.txt ├── umocktypes_c_mocked.c └── umocktypes_c_ut.c ├── umocktypes_charptr_ut ├── CMakeLists.txt ├── umocktypes_charptr_mocked.c └── umocktypes_charptr_ut.c ├── umocktypes_stdint_ut ├── CMakeLists.txt ├── umocktypes_stdint_mocked.c └── umocktypes_stdint_ut.c ├── umocktypes_struct_int ├── CMakeLists.txt └── umocktypes_struct_int.c ├── umocktypes_ut ├── CMakeLists.txt ├── umocktypes_mocked.c └── umocktypes_ut.c ├── umocktypes_wcharptr_ut ├── CMakeLists.txt ├── umocktypes_wcharptr_mocked.c └── umocktypes_wcharptr_ut.c ├── umocktypes_windows_ut ├── CMakeLists.txt ├── umocktypes_windows_mocked.c └── umocktypes_windows_ut.c └── umocktypes_wout_init_ut ├── CMakeLists.txt ├── umocktypes_mocked.c └── umocktypes_wout_init_ut.c /.github/policies/resourceManagement.yml: -------------------------------------------------------------------------------- 1 | id: 2 | name: GitOps.PullRequestIssueManagement 3 | description: GitOps.PullRequestIssueManagement primitive 4 | owner: 5 | resource: repository 6 | disabled: false 7 | where: 8 | configuration: 9 | resourceManagementConfiguration: 10 | scheduledSearches: [] 11 | eventResponderTasks: 12 | - if: 13 | - payloadType: Pull_Request 14 | - filesMatchPattern: 15 | pattern: deps/* 16 | - isOpen 17 | then: 18 | - approvePullRequest: 19 | comment: PR contains deps update, engage rubber stamping! 20 | description: 21 | - if: 22 | - payloadType: Pull_Request 23 | - isOpen 24 | then: 25 | - requestReview: 26 | reviewer: anporumb 27 | - requestReview: 28 | reviewer: avranju 29 | - requestReview: 30 | reviewer: mattdurak 31 | - requestReview: 32 | reviewer: dcristoloveanu 33 | - requestReview: 34 | reviewer: jebrando 35 | - requestReview: 36 | reviewer: darobs 37 | - requestReview: 38 | reviewer: ipg2013 39 | - requestReview: 40 | reviewer: parth21999 41 | - requestReview: 42 | reviewer: cyrus-jackson 43 | - requestReview: 44 | reviewer: jasmineymlo 45 | - requestReview: 46 | reviewer: RohitG28 47 | - requestReview: 48 | reviewer: ACKPaul 49 | - requestReview: 50 | reviewer: M-iceberg 51 | - requestReview: 52 | reviewer: BertKleewein 53 | description: 54 | onFailure: 55 | onSuccess: 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Typical cmake folder 2 | [cC]make*/ 3 | *.orig 4 | *.jar 5 | 6 | /.vscode -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/c-build-tools"] 2 | path = deps/c-build-tools 3 | url = https://github.com/Azure/c-build-tools 4 | [submodule "deps/macro-utils-c"] 5 | path = deps/macro-utils-c 6 | url = https://github.com/Azure/macro-utils-c 7 | [submodule "deps/c-logging"] 8 | path = deps/c-logging 9 | url = https://github.com/Azure/c-logging 10 | [submodule "deps/ctest"] 11 | path = deps/ctest 12 | url = https://github.com/Azure/ctest 13 | [submodule "deps/c-testrunnerswitcher"] 14 | path = deps/c-testrunnerswitcher 15 | url = https://github.com/Azure/c-testrunnerswitcher 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /build/devops_gated.yml: -------------------------------------------------------------------------------- 1 | name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) 2 | resources: 3 | repositories: 4 | - repository: self 5 | clean: true 6 | - repository: c_build_tools 7 | type: github 8 | name: azure/c-build-tools 9 | endpoint: github.com_azure 10 | ref: refs/heads/master 11 | jobs: 12 | - template: /pipeline_templates/build_all_flavors.yml@c_build_tools 13 | 14 | - template: /pipeline_templates/run_master_check.yml@c_build_tools 15 | 16 | - template: /pipeline_templates/codeql3000_default.yml@c_build_tools 17 | 18 | - job: linuxubuntu 19 | displayName: 'Build Linux Ubuntu' 20 | variables: 21 | #Codeql does not play nice with valgrind 22 | Codeql.Enabled: false 23 | pool: 24 | name: Azure-MsgStore-Linux2204BuildMachinePool 25 | demands: 26 | - linux 27 | 28 | steps: 29 | 30 | - bash: | 31 | pushd $(Build.Repository.LocalPath) 32 | git submodule update --init 33 | git submodule foreach --recursive "git clean -xdff" 34 | git clean -xdff 35 | popd 36 | workingDirectory: '$(Build.Repository.LocalPath)' 37 | displayName: 'git submodule update and clean' 38 | 39 | - task: Bash@3 40 | displayName: 'Build and run tests' 41 | inputs: 42 | targetType: filePath 43 | filePath: './build/linux/build_linux.sh' 44 | arguments: '$(Build.Repository.LocalPath)' 45 | workingDirectory: '$(Build.Repository.LocalPath)' 46 | 47 | # Will be re-enabled at a later time 48 | #- job: includecheck 49 | # pool: 50 | # name: Azure-MessagingStore 51 | # demands: 52 | # - Build 53 | # - Cmd 54 | # - msbuild 55 | # - cmake 56 | # - visualstudio 57 | # 58 | # steps: 59 | # - task: BatchScript@1 60 | # displayName: 'Git submodule update' 61 | # inputs: 62 | # filename: 'C:\Program Files\Git\bin\git.exe' 63 | # arguments: 'submodule update --init --force' 64 | # 65 | # - task: BatchScript@1 66 | # displayName: 'Git submodule clean' 67 | # inputs: 68 | # filename: 'C:\Program Files\Git\bin\git.exe' 69 | # arguments: 'submodule foreach --recursive "git clean -xdff"' 70 | # 71 | # - task: BatchScript@1 72 | # displayName: 'Git clean' 73 | # inputs: 74 | # filename: 'C:\Program Files\Git\bin\git.exe' 75 | # arguments: 'clean -xdff' 76 | # 77 | # - task: BatchScript@1 78 | # displayName: 'Setup VS Vars' 79 | # inputs: 80 | # filename: '"c:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"' 81 | # modifyEnvironment: true 82 | # 83 | # - task: CMake@1 84 | # displayName: 'Running cmake' 85 | # inputs: 86 | # workingDirectory: 'build_ninja' 87 | # cmakeArgs: '.. -GNinja -DCMAKE_C_INCLUDE_WHAT_YOU_USE:UNINITIALIZED=include-what-you-use;-Xiwyu;--mapping_file=../deps/c-build-tools/iwyu/rules.imp;--driver-mode=cl -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE:UNINITIALIZED=include-what-you-use;-Xiwyu;--mapping_file=../deps/c-build-tools/iwyu/rules.imp;--driver-mode=cl -Drun_unittests:bool=ON -Drun_int_tests:bool=ON -Drun_perf_tests:bool=ON -Duse_cppunittest:bool=ON' 88 | # 89 | # - task: PowerShell@2 90 | # displayName: 'Build solution and check includes' 91 | # inputs: 92 | # workingDirectory: 'build_ninja' 93 | # targetType: 'inline' 94 | # script: | 95 | # cmake --build . | tee build.log 96 | # if ((Select-String -Path "./build.log" -Pattern "Warning:") -ne $null) { throw "include check failed" } 97 | 98 | #- job: includecheck_linux 99 | # pool: 100 | # name: Azure-MessagingStore-LinuxBuildMachinePool 101 | # demands: 102 | # - linux 103 | # 104 | # steps: 105 | # 106 | # - bash: | 107 | # pushd $(Build.Repository.LocalPath) 108 | # git submodule update --init 109 | # git submodule foreach --recursive "git clean -xdff" 110 | # git clean -xdff 111 | # popd 112 | # workingDirectory: '$(Build.Repository.LocalPath)' 113 | # displayName: 'git submodule update and clean' 114 | 115 | #re-enable with https://msazure.visualstudio.com/One/_workitems/edit/29593386 116 | # - task: Bash@3 117 | # displayName: 'Build with iwyu' 118 | # inputs: 119 | # targetType: filePath 120 | # filePath: './build/linux/build_linux_iwyu.sh' 121 | # arguments: '$(Build.Repository.LocalPath)' 122 | # workingDirectory: '$(Build.Repository.LocalPath)' 123 | -------------------------------------------------------------------------------- /build/linux/build_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Microsoft. All rights reserved. 3 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | 5 | set -e 6 | 7 | build_root=$(cd "$1" && pwd) 8 | cd $build_root 9 | 10 | build_folder=$build_root"/cmake_linux" 11 | 12 | # Set the default cores 13 | CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) 14 | 15 | rm -r -f $build_folder 16 | mkdir -p $build_folder 17 | pushd $build_folder 18 | cmake -Drun_valgrind:BOOL=ON -Drun_unittests:BOOL=ON -Drun_int_tests:BOOL=ON $build_root 19 | make --jobs=$CORES 20 | 21 | ctest -j $CORES --output-on-failure 22 | 23 | popd -------------------------------------------------------------------------------- /build/linux/build_linux_iwyu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Microsoft. All rights reserved. 3 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | 5 | set -e 6 | 7 | build_root=$(cd "$1" && pwd) 8 | cd $build_root 9 | 10 | build_folder=$build_root"/cmake_linux_iwyu" 11 | 12 | # Set the default cores 13 | CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) 14 | 15 | rm -r -f $build_folder 16 | mkdir -p $build_folder 17 | pushd $build_folder 18 | CC="clang" CXX="clang++" cmake $build_root -GNinja -DCMAKE_C_INCLUDE_WHAT_YOU_USE:UNINITIALIZED="include-what-you-use;-Xiwyu;--mapping_file=$build_root/deps/c-build-tools/iwyu/rules.imp;" -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE:UNINITIALIZED="include-what-you-use;-Xiwyu;--mapping_file=$build_root/deps/c-build-tools/iwyu/rules.imp;" -Drun_unittests:bool=ON -Drun_int_tests:bool=ON 19 | cmake --build . > >(tee $build_folder"/build.log") 2> >(tee $build_folder"/builderror.log" >&2) 20 | 21 | if grep 'Warning:' $build_folder"/builderror.log"; then 22 | echo "Failing build due to iwyu warnings" 23 | exit -1 24 | fi 25 | 26 | if grep 'Warning:' $build_folder"/build.log"; then 27 | echo "Failing build due to iwyu warnings" 28 | exit -1 29 | fi 30 | 31 | popd -------------------------------------------------------------------------------- /configs/umock_cConfig.cmake: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | if (DEFINED run_e2e_tests) 5 | set(original_run_e2e_tests ${run_e2e_tests}) 6 | else() 7 | set(original_run_e2e_tests OFF) 8 | endif() 9 | 10 | if (DEFINED run_int_tests) 11 | set(original_run_int_tests ${run_int_tests}) 12 | else() 13 | set(original_run_int_tests OFF) 14 | endif() 15 | 16 | if (DEFINED run_unittests) 17 | set(original_run_unittests ${run_unittests}) 18 | else() 19 | set(original_run_unittests OFF) 20 | endif() 21 | 22 | 23 | set(run_e2e_tests OFF) 24 | set(run_int_tests OFF) 25 | set(run_unittests OFF) 26 | 27 | if(${original_run_int_tests} OR ${original_run_unittests}) 28 | if(NOT ctest_FOUND) 29 | find_package(ctest REQUIRED CONFIG) 30 | endif() 31 | if(NOT testrunnerswitcher_FOUND) 32 | find_package(testrunnerswitcher REQUIRED CONFIG) 33 | endif() 34 | endif() 35 | 36 | set(run_e2e_tests ${original_run_e2e_tests}) 37 | set(run_int_tests ${original_run_int_tests}) 38 | set(run_unittests ${original_run_unittests}) 39 | 40 | include("${CMAKE_CURRENT_LIST_DIR}/umock_cTargets.cmake") 41 | include("${CMAKE_CURRENT_LIST_DIR}/umock_cFunctions.cmake") 42 | 43 | get_target_property(UMOCK_C_INCLUDES umock_c INTERFACE_INCLUDE_DIRECTORIES) 44 | 45 | set(UMOCK_C_INCLUDES ${UMOCK_C_INCLUDES} CACHE INTERNAL "") 46 | 47 | -------------------------------------------------------------------------------- /devdoc/umock_c_negative_tests_requirements.md: -------------------------------------------------------------------------------- 1 | # umock_c_negative_tests requirements 2 | 3 | # Overview 4 | 5 | `umock_c_negative_tests` is an addon to `umock_c` that exposes APIs used to automate negative tests. 6 | 7 | # Exposed API 8 | 9 | ```c 10 | int umock_c_negative_tests_init(void); 11 | void umock_c_negative_tests_deinit(void); 12 | void umock_c_negative_tests_snapshot(void); 13 | void umock_c_negative_tests_reset(void); 14 | void umock_c_negative_tests_fail_call(size_t index); 15 | size_t umock_c_negative_tests_call_count(void); 16 | int umock_c_negative_tests_can_call_fail(size_t index); 17 | ``` 18 | 19 | ## umock_c_negative_tests_init 20 | 21 | ```c 22 | int umock_c_negative_tests_init(void); 23 | ``` 24 | 25 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_001: [** `umock_c_negative_tests_init` shall initialize the `umock_c` negative tests library. **]** 26 | 27 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_004: [** On success, `umock_c_negative_tests_init` shall return 0. **]** 28 | 29 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_005: [** If the module has already been initialized, `umock_c_negative_tests_init` shall return a non-zero value. **]** 30 | 31 | ## umock_c_negative_tests_deinit 32 | 33 | ```c 34 | void umock_c_negative_tests_deinit(void); 35 | ``` 36 | 37 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_002: [** `umock_c_negative_tests_deinit` shall free all resources associated with the negative tests module. **]** 38 | 39 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_003: [** If the module was not previously initialized, `umock_c_negative_tests_deinit` shall do nothing. **]** 40 | 41 | ## umock_c_negative_tests_snapshot 42 | 43 | ```c 44 | void umock_c_negative_tests_snapshot(void); 45 | ``` 46 | 47 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_006: [** `umock_c_negative_tests_snapshot` shall make a copy of the current call recorder for `umock_c` with all its recorded calls. **]** 48 | 49 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_007: [** The current call recorder shall be obtained by calling `umock_c_get_call_recorder`. **]** 50 | 51 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_008: [** The copy of the recorder shall be made by calling `umockcallrecorder_clone`. **]** 52 | 53 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_009: [** If getting the call recorder fails, `umock_c_negative_tests_snapshot` shall indicate the error via the umock error callback with error code `UMOCK_C_ERROR`. **]** 54 | 55 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_010: [** If copying the call recorder fails, `umock_c_negative_tests_snapshot` shall indicate the error via the umock error callback with error code `UMOCK_C_ERROR`. **]** 56 | 57 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_015: [** If the module was not previously initialized, `umock_c_negative_tests_snapshot` shall do nothing. **]** 58 | 59 | ## umock_c_negative_tests_reset 60 | 61 | ```c 62 | void umock_c_negative_tests_reset(void); 63 | ``` 64 | 65 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_011: [** `umock_c_negative_tests_reset` shall reset the call recorder used by `umock_c` to the call recorder stored in `umock_c_negative_tests_reset`. **]** 66 | 67 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_012: [** If no call has been made to umock_c_negative_tests_snapshot, `umock_c_negative_tests_reset` shall indicate a failure via the umock error callback with error code UMOCK_C_ERROR. **]** 68 | 69 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_013: [** The reset shall be done by calling `umock_c_set_call_recorder` and passing the call recorder stored in `umock_c_negative_tests_reset` as argument. **]** 70 | 71 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_014: [** If `umock_c_set_call_recorder` fails, `umock_c_negative_tests_reset` shall indicate a failure via the umock error callback with error code `UMOCK_C_ERROR`. **]** 72 | 73 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_016: [** If the module was not previously initialized, umock_c_negative_tests_reset shall do nothing. **]** 74 | 75 | ## umock_c_negative_tests_fail_call 76 | 77 | ```c 78 | void umock_c_negative_tests_fail_call(size_t index); 79 | ``` 80 | 81 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_017: [** `umock_c_negative_tests_fail_call` shall call `umockcallrecorder_fail_call` on the currently used call recorder used by `umock_c`. **]** 82 | 83 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_018: [** The currently used recorder shall be obtained by calling `umock_c_get_call_recorder`. **]** 84 | 85 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_019: [** If `umock_c_get_call_recorder` fails, `umock_c_negative_tests_fail_call` shall indicate the error via the umock error callback with error code `UMOCK_C_ERROR`. **]** 86 | 87 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_025: [** If failing the call by calling `umockcallrecorder_fail_call` fails, `umock_c_negative_tests_fail_call` shall indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** 88 | 89 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_020: [** If the module was not previously initialized, `umock_c_negative_tests_fail_call` shall do nothing. **]** 90 | 91 | ## umock_c_negative_tests_call_count 92 | 93 | ```c 94 | size_t umock_c_negative_tests_call_count(void); 95 | ``` 96 | 97 | XX**SRS_UMOCK_C_NEGATIVE_TESTS_01_021: [** `umock_c_negative_tests_call_count` shall return the count of expected calls for the current snapshot call recorder by calling `umockcallrecorder_get_expected_call_count`. **]** 98 | 99 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_022: [** If no call has been made to `umock_c_negative_tests_snapshot`, `umock_c_negative_tests_fail_call` shall return 0 and indicate the error via the umock error callback with error code `UMOCK_C_ERROR`. **]** 100 | 101 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_023: [** If `umockcallrecorder_get_expected_call_count` fails, `umock_c_negative_tests_fail_call` shall return 0 and indicate the error via the umock error callback with error code `UMOCK_C_ERROR`. **]** 102 | 103 | **SRS_UMOCK_C_NEGATIVE_TESTS_01_024: [** If the module was not previously initialized, `umock_c_negative_tests_call_count` shall return 0. **]** 104 | 105 | 106 | ## umock_c_negative_tests_can_call_fail 107 | 108 | ```c 109 | int umock_c_negative_tests_can_call_fail(size_t index); 110 | ``` 111 | 112 | **SRS_UMOCK_C_NEGATIVE_TESTS_31_026: [** If the module was not previously initialized, `umock_c_negative_tests_can_call_fail` shall return 1. **]** 113 | 114 | **SRS_UMOCK_C_NEGATIVE_TESTS_31_027: [** If `umock_c_get_call_recorder` fails, `umock_c_negative_tests_can_call_fail` shall indicate the error via the umock error callback with error code `UMOCK_C_ERROR`. **]** 115 | 116 | **SRS_UMOCK_C_NEGATIVE_TESTS_31_028: [** Whether the call can fail for the given index shall made by calling `umockcallrecorder_can_call_fail`. **]** 117 | 118 | **SRS_UMOCK_C_NEGATIVE_TESTS_31_029: [** If `umockcallrecorder_can_call_fail` fails, `umock_c_negative_tests_fail_call` shall indicate the error via the umock error callback with error code `UMOCK_C_ERROR` and return 1. **]** 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /devdoc/umock_lock_factory_pthread.md: -------------------------------------------------------------------------------- 1 | # umock_lock_factory_pthread 2 | 3 | ## Overview 4 | 5 | `umock_lock_factory_pthread` is a module that implements the reader/writer lock factory for `umock_c` for the pthread library. 6 | 7 | ## Exposed API 8 | 9 | ```c 10 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params); 11 | ``` 12 | 13 | ## static lock functions 14 | 15 | ```c 16 | static void umock_lock_pthread_acquire_shared(UMOCK_C_LOCK_HANDLE lock); 17 | static void umock_lock_pthread_release_shared(UMOCK_C_LOCK_HANDLE lock); 18 | static void umock_lock_pthread_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock); 19 | static void umock_lock_pthread_release_exclusive(UMOCK_C_LOCK_HANDLE lock); 20 | static void umock_lock_pthread_destroy(UMOCK_C_LOCK_HANDLE lock); 21 | ``` 22 | 23 | ### umockcall_create 24 | 25 | ```c 26 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params); 27 | ``` 28 | 29 | `umock_lock_factory_create_lock` creates a new lock to be used by `umock_c`. 30 | 31 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_001: [** `umock_lock_factory_create_lock` shall allocate memory for the lock. **]** 32 | 33 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_002: [** `umock_lock_factory_create_lock` shall initialize a pthread RW lock that is encapsulated by the new `UMOCK_C_LOCK_HANDLE`. **]** 34 | 35 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_003: [** `umock_lock_factory_create_lock` shall return a lock handle that has the function pointers set to `umock_lock_pthread_acquire_shared`, `umock_lock_pthread_release_shared`, `umock_lock_pthread_acquire_exclusive`, `umock_lock_pthread_release_exclusive` and `umock_lock_pthread_destroy`. **]** 36 | 37 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_004: [** If any error occurs, `umock_lock_factory_create_lock` shall fail and return `NULL`. **]** 38 | 39 | ### umock_lock_pthread_acquire_shared 40 | 41 | ```c 42 | static void umock_lock_pthread_acquire_shared(UMOCK_C_LOCK_HANDLE lock); 43 | ``` 44 | 45 | `umock_lock_pthread_acquire_shared` acquires the lock in shared mode. 46 | 47 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_010: [** If `lock` is `NULL`, `umock_lock_pthread_acquire_shared` shall return. **]** 48 | 49 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_005: [** `umock_lock_pthread_acquire_shared` shall acquire the read lock by calling `pthread_rwlock_rdlock`. **]** 50 | 51 | ### umock_lock_pthread_release_shared 52 | 53 | ```c 54 | static void umock_lock_pthread_release_shared(UMOCK_C_LOCK_HANDLE lock); 55 | ``` 56 | 57 | `umock_lock_pthread_release_shared` releases the lock that was acquired in shared mode. 58 | 59 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_011: [** If `lock` is `NULL`, `umock_lock_pthread_release_shared` shall return. **]** 60 | 61 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_006: [** `umock_lock_pthread_release_shared` shall release the lock that was acquired in shared mode by calling `pthread_rwlock_unlock`. **]** 62 | 63 | ### umock_lock_pthread_acquire_exclusive 64 | 65 | ```c 66 | static void umock_lock_pthread_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock); 67 | ``` 68 | 69 | `umock_lock_pthread_acquire_exclusive` acquires the lock in exclusive mode. 70 | 71 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_012: [** If `lock` is `NULL`, `umock_lock_pthread_acquire_exclusive` shall return. **]** 72 | 73 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_007: [** `umock_lock_pthread_acquire_exclusive` shall acquire the lock in exclusive mode by calling `pthread_rwlock_wrlock`. **]** 74 | 75 | ### umock_lock_pthread_release_exclusive 76 | 77 | ```c 78 | static void umock_lock_pthread_release_exclusive(UMOCK_C_LOCK_HANDLE lock); 79 | ``` 80 | 81 | `umock_lock_pthread_release_exclusive` releases the lock that was acquired in exclusive mode. 82 | 83 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_013: [** If `lock` is `NULL`, `umock_lock_pthread_release_exclusive` shall return. **]** 84 | 85 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_008: [** `umock_lock_pthread_release_exclusive` shall release the lock that was acquired in exclusive mode by calling `pthread_rwlock_unlock`. **]** 86 | 87 | ### umock_lock_pthread_destroy 88 | 89 | ```c 90 | static void umock_lock_pthread_destroy(UMOCK_C_LOCK_HANDLE lock); 91 | ``` 92 | 93 | `umock_lock_pthread_destroy` frees the resources associated with the lock. 94 | 95 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_014: [** If `lock` is `NULL`, `umock_lock_pthread_destroy` shall return. **]** 96 | 97 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_001: [** `umock_lock_pthread_destroy` shall release the resources for the pthread lock by calling `pthread_rwlock_destroy`. **]** 98 | 99 | **SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_009: [** `umock_lock_pthread_destroy` shall free the memory associated with the lock. **]** 100 | -------------------------------------------------------------------------------- /devdoc/umock_lock_factory_windows.md: -------------------------------------------------------------------------------- 1 | # umock_lock_factory_windows 2 | 3 | ## Overview 4 | 5 | `umock_lock_factory_windows` is a module that implements the lock factory for `umock_c` for Windows. 6 | 7 | ## Exposed API 8 | 9 | ```c 10 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params); 11 | ``` 12 | 13 | ## static lock functions 14 | 15 | ```c 16 | static void umock_lock_windows_acquire_shared(UMOCK_C_LOCK_HANDLE lock); 17 | static void umock_lock_windows_release_shared(UMOCK_C_LOCK_HANDLE lock); 18 | static void umock_lock_windows_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock); 19 | static void umock_lock_windows_release_exclusive(UMOCK_C_LOCK_HANDLE lock); 20 | static void umock_lock_windows_destroy(UMOCK_C_LOCK_HANDLE lock); 21 | ``` 22 | 23 | ### umockcall_create 24 | 25 | ```c 26 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params); 27 | ``` 28 | 29 | `umock_lock_factory_create_lock` creates a new lock to be used by `umock_c`. 30 | 31 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_001: [** `umock_lock_factory_create_lock` shall allocate memory for the lock. **]** 32 | 33 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_002: [** `umock_lock_factory_create_lock` shall initialize a SRW lock that is encapsulated by the new `UMOCK_C_LOCK_HANDLE`. **]** 34 | 35 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_003: [** `umock_lock_factory_create_lock` shall return a lock handle that has the function pointers set to `umock_lock_windows_acquire_shared`, `umock_lock_windows_release_shared`, `umock_lock_windows_acquire_exclusive`, `umock_lock_windows_release_exclusive` and `umock_lock_windows_destroy`. **]** 36 | 37 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_004: [** If any error occurs, `umock_lock_factory_create_lock` shall fail and return `NULL`. **]** 38 | 39 | ### umock_lock_windows_acquire_shared 40 | 41 | ```c 42 | static void umock_lock_windows_acquire_shared(UMOCK_C_LOCK_HANDLE lock); 43 | ``` 44 | 45 | `umock_lock_windows_acquire_shared` acquires the lock in shared mode. 46 | 47 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_010: [** If `lock` is `NULL`, `umock_lock_windows_acquire_shared` shall return. **]** 48 | 49 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_005: [** `umock_lock_windows_acquire_shared` shall acquire the lock in shared mode by calling `AcquireSRWLockShared`. **]** 50 | 51 | ### umock_lock_windows_release_shared 52 | 53 | ```c 54 | static void umock_lock_windows_release_shared(UMOCK_C_LOCK_HANDLE lock); 55 | ``` 56 | 57 | `umock_lock_windows_release_shared` releases the lock that was acquired in shared mode. 58 | 59 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_011: [** If `lock` is `NULL`, `umock_lock_windows_release_shared` shall return. **]** 60 | 61 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_006: [** `umock_lock_windows_release_shared` shall release the lock that was acquired in shared mode by calling `ReleaseSRWLockShared`. **]** 62 | 63 | ### umock_lock_windows_acquire_exclusive 64 | 65 | ```c 66 | static void umock_lock_windows_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock); 67 | ``` 68 | 69 | `umock_lock_windows_acquire_exclusive` acquires the lock in exclusive mode. 70 | 71 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_012: [** If `lock` is `NULL`, `umock_lock_windows_acquire_exclusive` shall return. **]** 72 | 73 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_007: [** `umock_lock_windows_acquire_exclusive` shall acquire the lock in exclusive mode by calling `AcquireSRWLockExclusive`. **]** 74 | 75 | ### umock_lock_windows_release_exclusive 76 | 77 | ```c 78 | static void umock_lock_windows_release_exclusive(UMOCK_C_LOCK_HANDLE lock); 79 | ``` 80 | 81 | `umock_lock_windows_release_exclusive` releases the lock that was acquired in exclusive mode. 82 | 83 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_013: [** If `lock` is `NULL`, `umock_lock_windows_release_exclusive` shall return. **]** 84 | 85 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_008: [** `umock_lock_windows_release_exclusive` shall release the lock that was acquired in exclusive mode by calling `ReleaseSRWLockExclusive`. **]** 86 | 87 | ### umock_lock_windows_destroy 88 | 89 | ```c 90 | static void umock_lock_windows_destroy(UMOCK_C_LOCK_HANDLE lock); 91 | ``` 92 | 93 | `umock_lock_windows_destroy` frees the resources associated with the lock. 94 | 95 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_014: [** If `lock` is `NULL`, `umock_lock_windows_destroy` shall return. **]** 96 | 97 | **SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_009: [** `umock_lock_windows_destroy` shall free the memory associated with the lock. **]** 98 | -------------------------------------------------------------------------------- /devdoc/umockalloc_requirements.md: -------------------------------------------------------------------------------- 1 | # umockalloc requirements 2 | 3 | # Overview 4 | 5 | `umockalloc` is a module that wraps the C memory allocation functions (`malloc`, `calloc`, `realloc` and `free`). 6 | This is so that `umock_c` can control what code is executed for allocation and there are no undesired redefinitions of `malloc`/`calloc`/`realloc`/`free`. 7 | 8 | # Exposed API 9 | 10 | ```c 11 | void* umockalloc_malloc(size_t size); 12 | void* umockalloc_calloc(size_t nmemb, size_t size); 13 | void* umockalloc_realloc(void* ptr, size_t size); 14 | void umockalloc_free(void* ptr); 15 | ``` 16 | 17 | ## umockalloc_malloc 18 | 19 | ```c 20 | void* umockalloc_malloc(size_t size); 21 | ``` 22 | 23 | `umockalloc_malloc` is a wrapper over `malloc`. 24 | 25 | **SRS_UMOCKALLOC_01_001: [** `umockalloc_malloc` shall call `malloc`, while passing the `size` argument to `malloc`. **]** 26 | 27 | **SRS_UMOCKALLOC_01_002: [** `umockalloc_malloc` shall return the result of `malloc`. **]** 28 | 29 | ## umockalloc_calloc 30 | 31 | ```c 32 | void* umockalloc_calloc(size_t nmemb, size_t size); 33 | ``` 34 | 35 | `umockalloc_calloc` is a wrapper over `calloc`. 36 | 37 | **SRS_UMOCKALLOC_09_001: [** `umockalloc_calloc` shall call `calloc`, while passing the `nmemb` and `size` arguments to `calloc`. **]** 38 | 39 | **SRS_UMOCKALLOC_09_002: [** `umockalloc_calloc` shall return the result of `calloc`. **]** 40 | 41 | ## umockalloc_realloc 42 | 43 | ```c 44 | void* umockalloc_realloc(void* ptr, size_t size); 45 | ``` 46 | 47 | `umockalloc_realloc` is a wrapper over `realloc`. 48 | 49 | **SRS_UMOCKALLOC_01_003: [** `umockalloc_realloc` shall call `realloc`, while passing the `ptr` and `size` arguments to `realloc`. **]** 50 | 51 | **SRS_UMOCKALLOC_01_004: [** `umockalloc_realloc` shall return the result of `realloc`. **]** 52 | 53 | ## umockalloc_free 54 | 55 | ```c 56 | void umockalloc_free(void* ptr); 57 | ``` 58 | 59 | `umockalloc_free` is a wrapper over `free`. 60 | 61 | **SRS_UMOCKALLOC_01_005: [** `umockalloc_free` shall call `free`, while passing the `ptr` argument to `free`. **]** 62 | -------------------------------------------------------------------------------- /devdoc/umockautoignoreargs_requirements.md: -------------------------------------------------------------------------------- 1 | `umockautoignoreargs` requirements 2 | 3 | # Overview 4 | 5 | `umockautoignoreargs` is a module that provides the functionality of inspecting the arguments of a function to determine whether they should be ignored or not. 6 | 7 | # Exposed API 8 | 9 | ```c 10 | int umockautoignoreargs_is_call_argument_ignored(const char* call, size_t argument_index, int* is_argument_ignored); 11 | ``` 12 | 13 | ## umockautoignoreargs_is_call_argument_ignored 14 | 15 | ```c 16 | int umockautoignoreargs_is_call_argument_ignored(const char* call, size_t argument_index, int* is_argument_ignored); 17 | ``` 18 | 19 | **SRS_UMOCKAUTOIGNOREARGS_01_001: [** `umockautoignoreargs_is_call_argument_ignored` shall determine whether argument `argument_index` shall be ignored or not. **]** 20 | 21 | **SRS_UMOCKAUTOIGNOREARGS_01_002: [** If `call` or `is_argument_ignored` is NULL, `umockautoignoreargs_is_call_argument_ignored` shall fail and return a non-zero value. **]** 22 | 23 | **SRS_UMOCKAUTOIGNOREARGS_01_003: [** `umockautoignoreargs_is_call_argument_ignored` shall parse the `call` string as a function call: function_name(arg1, arg2, ...). **]** 24 | 25 | **SRS_UMOCKAUTOIGNOREARGS_01_010: [** `umockautoignoreargs_is_call_argument_ignored` shall look for the arguments as being the string contained in the scope of the rightmost parenthesis set in `call`. **]** 26 | 27 | Note: nesting is allowed. An example of arguments that would have nested parenthesis scope: 28 | 29 | ```c 30 | function_name(arg1, some_call(x), ...) 31 | ``` 32 | 33 | For this example, the arg list would be `arg1, some_call(x), ...`. 34 | 35 | **SRS_UMOCKAUTOIGNOREARGS_01_011: [** If a valid scope of the rightmost parenthesis set cannot be formed (imbalanced parenthesis for example), `umockautoignoreargs_is_call_argument_ignored` shall fail and return a non-zero value. **]** 36 | 37 | **SRS_UMOCKAUTOIGNOREARGS_01_004: [** If `umockautoignoreargs_is_call_argument_ignored` fails parsing the `call` argument it shall fail and return a non-zero value. **]** 38 | 39 | **SRS_UMOCKAUTOIGNOREARGS_01_009: [** If the number of arguments parsed from `call` is less than `argument_index`, `umockautoignoreargs_is_call_argument_ignored` shall fail and return a non-zero value. **]** 40 | 41 | **SRS_UMOCKAUTOIGNOREARGS_01_005: [** If `umockautoignoreargs_is_call_argument_ignored` was able to parse the `argument_index`th argument it shall succeed and return 0, while writing whether the argument is ignored in the `is_argument_ignored` output argument. **]** 42 | 43 | **SRS_UMOCKAUTOIGNOREARGS_01_007: [** If the argument value is `IGNORED_ARG` then `is_argument_ignored` shall be set to 1. **]** 44 | 45 | **SRS_UMOCKAUTOIGNOREARGS_01_012: [** If the argument value starts with `IGNORED_STRUCT_ARG` then `is_argument_ignored` shall be set to 1. **]** 46 | 47 | **SRS_UMOCKAUTOIGNOREARGS_01_008: [** If the argument value is any other value then `is_argument_ignored` shall be set to 0. **]** 48 | -------------------------------------------------------------------------------- /devdoc/umockcallpairs_requirements.md: -------------------------------------------------------------------------------- 1 | 2 | # umockcallpairs requirements 3 | 4 | # Overview 5 | 6 | `umockcallpairs` is a module that handles tracking of call pairs. 7 | 8 | # Exposed API 9 | 10 | ```c 11 | typedef struct PAIRED_HANDLE_TAG 12 | { 13 | void* handle_value; 14 | char* handle_type; 15 | } PAIRED_HANDLE; 16 | 17 | typedef struct PAIRED_HANDLES_TAG 18 | { 19 | PAIRED_HANDLE* paired_handles; 20 | size_t paired_handle_count; 21 | } PAIRED_HANDLES; 22 | 23 | int umockcallpairs_track_create_paired_call(PAIRED_HANDLES* paired_handles, const void* handle, const char* handle_type, size_t handle_type_size); 24 | int umockcallpairs_track_destroy_paired_call(PAIRED_HANDLES* paired_handles, const void* handle); 25 | ``` 26 | 27 | ## umockcallpairs_track_create_paired_call 28 | 29 | ```c 30 | int umockcallpairs_track_create_paired_call(PAIRED_HANDLES* paired_handles, const void* handle, const char* handle_type, size_t handle_type_size); 31 | ``` 32 | 33 | `umockcallpairs_track_create_paired_call` stores a handle to be tracked in the create/destroy pair tracking. 34 | 35 | **SRS_UMOCKCALLPAIRS_01_001: [** `umockcallpairs_track_create_paired_call` shall add a new entry to the PAIRED_HANDLES array and on success it shall return 0. **]** 36 | 37 | **SRS_UMOCKCALLPAIRS_01_002: [** `umockcallpairs_track_create_paired_call` shall copy the `handle` to the `handle_value` member of the new entry. **]** 38 | 39 | **SRS_UMOCKCALLPAIRS_01_003: [** `umockcallpairs_track_create_paired_call` shall allocate a memory block and store a pointer to it in the memory field of the new entry. **]** 40 | 41 | **SRS_UMOCKCALLPAIRS_01_004: [** If any of the arguments `paired_handles`, `handle` or `handle_type` is `NULL`, `umockcallpairs_track_create_paired_call` shall fail and return a non-zero value. **]** 42 | 43 | **SRS_UMOCKCALLPAIRS_01_005: [** If allocating memory fails, `umockcallpairs_track_create_paired_call` shall fail and return a non-zero value. **]** 44 | 45 | **SRS_UMOCKCALLPAIRS_01_006: [** The `handle` value shall be copied by using `umocktypes_copy`. **]** 46 | 47 | **SRS_UMOCKCALLPAIRS_01_007: [** If `umocktypes_copy` fails, `umockcallpairs_track_create_paired_call` shall fail and return a non-zero value. **]** 48 | 49 | ## umockcallpairs_track_destroy_paired_call 50 | 51 | ```c 52 | int umockcallpairs_track_destroy_paired_call(PAIRED_HANDLES* paired_handles, const void* handle); 53 | ``` 54 | 55 | `umockcallpairs_track_create_paired_call` removes a handle that is tracked in the create/destroy pair tracking. 56 | 57 | **SRS_UMOCKCALLPAIRS_01_008: [** `umockcallpairs_track_destroy_paired_call` shall remove from the paired handles array pointed by the `paired_handles` field the entry that is associated with the handle passed in the `handle` argument. **]** 58 | 59 | **SRS_UMOCKCALLPAIRS_01_009: [** On success `umockcallpairs_track_destroy_paired_call` shall return 0. **]** 60 | 61 | **SRS_UMOCKCALLPAIRS_01_010: [** If any of the arguments is `NULL`, `umockcallpairs_track_destroy_paired_call` shall fail and return a non-zero value. **]** 62 | 63 | **SRS_UMOCKCALLPAIRS_01_011: [** `umockcallpairs_track_destroy_paired_call` shall free the memory pointed by the memory field in the `PAIRED_HANDLES` array entry associated with handle. **]** 64 | 65 | **SRS_UMOCKCALLPAIRS_01_012: [** If the paired handles array is empty after removing the entry, the `paired_handles` field shall be freed and set to `NULL`. **]** 66 | 67 | **SRS_UMOCKCALLPAIRS_01_013: [** When looking up which entry to remove, the comparison of the handle values shall be done by calling `umocktypes_are_equal`. **]** 68 | 69 | **SRS_UMOCKCALLPAIRS_01_014: [** If `umocktypes_are_equal` fails, `umockcallpairs_track_destroy_paired_call` shall fail and return a non-zero value. **]** 70 | 71 | **SRS_UMOCKCALLPAIRS_01_015: [** If the handle is not found in the array then `umockcallpairs_track_destroy_paired_call` shall fail and return a non-zero value. **]** 72 | -------------------------------------------------------------------------------- /devdoc/umockstring_requirements.md: -------------------------------------------------------------------------------- 1 | 2 | # umockstring requirements 3 | 4 | # Overview 5 | 6 | `umockstring` is a module that provides the functionality of cloning a string (allocating memory and copying the chars). 7 | 8 | # Exposed API 9 | 10 | ```c 11 | char* umockstring_clone(const char* source); 12 | ``` 13 | 14 | ## umockstring_clone 15 | 16 | ```c 17 | char* umockstring_clone(const char* source); 18 | ``` 19 | 20 | **UMOCK_STRING_01_001: [** `umockstring_clone` shall allocate memory for the cloned string (including the `NULL` terminator). **]** 21 | 22 | **UMOCK_STRING_01_002: [** `umockstring_clone` shall copy the string to the newly allocated memory (including the `NULL` terminator). **]** 23 | 24 | **UMOCK_STRING_01_003: [** On success `umockstring_clone` shall return a pointer to the newly allocated memory containing the copy of the string. **]** 25 | 26 | **UMOCK_STRING_01_004: [** If allocating the memory fails, `umockstring_clone` shall return `NULL`. **]** 27 | 28 | **UMOCK_STRING_01_005: [** If `umockstring_clone` is called with a `NULL` `source`, it shall return `NULL`. **]** 29 | -------------------------------------------------------------------------------- /devdoc/umocktypename_requirements.md: -------------------------------------------------------------------------------- 1 | 2 | # umocktypename requirements 3 | 4 | # Overview 5 | 6 | `umocktypename` is a module that provides a way to bring C type names to a normalized form in order to ensure that type name comparisons can be made easily. 7 | 8 | For example `const char *` would be brought to `const char*`. 9 | 10 | # Exposed API 11 | 12 | ```c 13 | char* umocktypename_normalize(const char* typename); 14 | ``` 15 | 16 | ## umocktypename_normalize 17 | 18 | ```c 19 | char* umocktypename_normalize(const char* typename); 20 | ``` 21 | 22 | **SRS_UMOCKTYPENAME_01_001: [** `umocktypename_normalize` shall return a `char*` with a newly allocated string that contains the normalized `typename`. **]** 23 | 24 | **SRS_UMOCKTYPENAME_01_006: [** No space shall exist between any other token and a star. **]** 25 | 26 | **SRS_UMOCKTYPENAME_01_002: [** `umocktypename_normalize` shall remove all spaces at the beginning of the `typename`. **]** 27 | 28 | **SRS_UMOCKTYPENAME_01_003: [** `umocktypename_normalize` shall remove all spaces at the end of the `typename`. **]** 29 | 30 | **SRS_UMOCKTYPENAME_01_004: [** `umocktypename_normalize` shall remove all extra spaces (more than 1 space) between elements that are part of the `typename`. **]** 31 | 32 | **SRS_UMOCKTYPENAME_01_005: [** If `typename` is `NULL`, then `umocktypename_normalize` shall fail and return `NULL`. **]** 33 | 34 | **SRS_UMOCKTYPENAME_01_007: [** If the length of the normalized `typename` is 0, `umocktypename_normalize` shall return `NULL`. **]** 35 | 36 | **SRS_UMOCKTYPENAME_01_008: [** If allocating memory fails, `umocktypename_normalize` shall fail and return `NULL`. **]** 37 | 38 | For example `const char` would be normalized to `const char`. Also `char *` would be normalized to `char*`. 39 | -------------------------------------------------------------------------------- /devdoc/umocktypes_bool_requirements.md: -------------------------------------------------------------------------------- 1 | 2 | # umocktypes_bool requirements 3 | 4 | # Overview 5 | 6 | `umocktypes_bool` is a module that exposes out of the box functionality for `bool` and `_Bool` for `umock_c`. 7 | 8 | # Exposed API 9 | 10 | ```c 11 | int umocktypes_bool_register_types(void); 12 | 13 | char* umocktypes_stringify_bool(const bool* value); \ 14 | int umocktypes_are_equal_bool(const bool* left, const bool* right); \ 15 | int umocktypes_copy_bool(bool* destination, const bool* source); \ 16 | void umocktypes_free_bool(bool* value); 17 | ``` 18 | 19 | ## umocktypes_bool_register_types 20 | 21 | ```c 22 | int umocktypes_bool_register_types(void); 23 | ``` 24 | 25 | **SRS_UMOCKTYPES_BOOL_01_001: [** `umocktypes_bool_register_types` shall register support for the C99 `bool` type. **]** 26 | 27 | **SRS_UMOCKTYPES_BOOL_01_014: [** On success, `umocktypes_bool_register_types` shall return 0. **]** 28 | 29 | **SRS_UMOCKTYPES_BOOL_01_015: [** If registering fails, `umocktypes_bool_register_types` shall fail and return a non-zero value. **]** 30 | 31 | ## umocktypes_stringify_char 32 | 33 | ```c 34 | char* umocktypes_stringify_bool(const bool* value); 35 | ``` 36 | 37 | **SRS_UMOCKTYPES_BOOL_01_002: [** `umocktypes_stringify_bool` shall return the string representation of value. **]** 38 | 39 | **SRS_UMOCKTYPES_BOOL_01_003: [** If value is `NULL`, `umocktypes_stringify_bool` shall return NULL. **]** 40 | 41 | **SRS_UMOCKTYPES_BOOL_01_004: [** If allocating a new string to hold the string representation fails, `umocktypes_stringify_bool` shall return `NULL`. **]** 42 | 43 | ## umocktypes_are_equal_bool 44 | 45 | ```c 46 | int umocktypes_are_equal_char(bool* left, bool* right); 47 | ``` 48 | 49 | **SRS_UMOCKTYPES_BOOL_01_006: [** `umocktypes_are_equal_bool` shall compare the 2 bools pointed to by `left` and `right`. **]** 50 | 51 | **SRS_UMOCKTYPES_BOOL_01_007: [** If any of the arguments is `NULL`, `umocktypes_are_equal_bool` shall return -1. **]** 52 | 53 | **SRS_UMOCKTYPES_BOOL_01_008: [** If the values pointed to by `left` and `right` are equal, `umocktypes_are_equal_bool` shall return 1. **]** 54 | 55 | **SRS_UMOCKTYPES_BOOL_01_009: [** If the values pointed to by `left` and `right` are different, `umocktypes_are_equal_bool` shall return 0. **]** 56 | 57 | ## umocktypes_copy_bool 58 | 59 | ```c 60 | int umocktypes_copy_bool(bool* destination, const bool* source); 61 | ``` 62 | 63 | **SRS_UMOCKTYPES_BOOL_01_010: [** `umocktypes_copy_bool` shall copy the bool value from `source` to `destination`. **]** 64 | 65 | **SRS_UMOCKTYPES_BOOL_01_011: [** On success `umocktypes_copy_bool` shall return 0. **]** 66 | 67 | **SRS_UMOCKTYPES_BOOL_01_012: [** If source or destination are `NULL`, `umocktypes_copy_bool` shall return a non-zero value. **]** 68 | 69 | ## umocktypes_free_bool 70 | 71 | ```c 72 | void umocktypes_free_bool(bool* value); 73 | ``` 74 | 75 | **SRS_UMOCKTYPES_BOOL_01_013: [** `umocktypes_free_bool` shall do nothing. **]** 76 | -------------------------------------------------------------------------------- /devdoc/umocktypes_struct_requirements.md: -------------------------------------------------------------------------------- 1 | 2 | # umocktypes_struct requirements 3 | 4 | # Overview 5 | 6 | `umocktypes_struct` is a module that exposes stringify, an equality comparer, copy, and free for structs in umock_c. It performs member-by-member operations. 7 | 8 | # Exposed API 9 | 10 | ```c 11 | #define UMOCK_DEFINE_TYPE_STRUCT_STRINGIFY(type, ...) \ 12 | static char* MU_C2(umocktypes_stringify_, type)(const type* value) \ 13 | /*...*/ 14 | 15 | #define UMOCK_DEFINE_TYPE_STRUCT_ARE_EQUAL(type, ...) \ 16 | static int MU_C2(umocktypes_are_equal_, type)(const type* left, const type* right) \ 17 | /*...*/ 18 | 19 | #define UMOCK_DEFINE_TYPE_STRUCT_COPY(type, ...) \ 20 | static int MU_C2(umocktypes_copy_, type)(type* destination, const type* source) \ 21 | /*...*/ 22 | 23 | #define UMOCK_DEFINE_TYPE_STRUCT_FREE(type, ...) \ 24 | static void MU_C2(umocktypes_free_, type)(type* value) \ 25 | /*...*/ 26 | 27 | #define UMOCK_DEFINE_TYPE_STRUCT(type, ...) \ 28 | UMOCK_DEFINE_TYPE_STRUCT_STRINGIFY(type, __VA_ARGS__) \ 29 | UMOCK_DEFINE_TYPE_STRUCT_ARE_EQUAL(type, __VA_ARGS__) \ 30 | UMOCK_DEFINE_TYPE_STRUCT_COPY(type, __VA_ARGS__) \ 31 | UMOCK_DEFINE_TYPE_STRUCT_FREE(type, __VA_ARGS__) 32 | ``` 33 | 34 | # Usage 35 | 36 | ```c 37 | /// Header 38 | 39 | #define MY_STRUCT_FIELDS \ 40 | int, foo, \ 41 | char, bar 42 | 43 | MU_DEFINE_STRUCT(MY_STRUCT, MY_STRUCT_FIELDS) 44 | 45 | /// Test file 46 | 47 | // Define the umock c functions 48 | UMOCK_DEFINE_TYPE_STRUCT(MY_STRUCT, MY_STRUCT_FIELDS) 49 | 50 | // ... 51 | 52 | // Register the functions with umock 53 | REGISTER_TYPE(MY_STRUCT, MY_STRUCT); 54 | 55 | // ... 56 | 57 | // Now MY_STRUCT can be used in mock expectations 58 | 59 | ``` 60 | 61 | ## umocktypes_stringify_\ 62 | 63 | ```c 64 | static char* MU_C2(umocktypes_stringify_, type)(const type* value) 65 | ``` 66 | 67 | **SRS_UMOCKTYPES_STRUCT_42_001: [** `umocktypes_stringify_` shall call `umocktypes_stringify` for each field in `type`. **]** 68 | 69 | **SRS_UMOCKTYPES_STRUCT_42_002: [** `umocktypes_stringify_` shall generate a string containing all stringified fields in `type` and return it. **]** 70 | 71 | **SRS_UMOCKTYPES_STRUCT_42_003: [** `umocktypes_stringify_` shall free all of the stringified fields. **]** 72 | 73 | **SRS_UMOCKTYPES_STRUCT_42_004: [** If there are any errors then `umocktypes_stringify_` shall fail and return `NULL`. **]** 74 | 75 | ## umocktypes_are_equal_\ 76 | 77 | ```c 78 | static int MU_C2(umocktypes_are_equal_, type)(const type* left, const type* right) 79 | ``` 80 | 81 | **SRS_UMOCKTYPES_STRUCT_42_005: [** If `left` is `NULL` then `umocktypes_are_equal_` shall fail and return `-1`. **]** 82 | 83 | **SRS_UMOCKTYPES_STRUCT_42_006: [** If `right` is `NULL` then `umocktypes_are_equal_` shall fail and return `-1`. **]** 84 | 85 | **SRS_UMOCKTYPES_STRUCT_42_007: [** `umocktypes_are_equal_` shall call `umocktypes_are_equal` for each field in `type`. **]** 86 | 87 | **SRS_UMOCKTYPES_STRUCT_42_008: [** If any call to `umocktypes_are_equal` does not return `1` then `umocktypes_are_equal_` shall return `0`. **]** 88 | 89 | **SRS_UMOCKTYPES_STRUCT_42_009: [** Otherwise, `umocktypes_are_equal_` shall return `1`. **]** 90 | 91 | ## umocktypes_copy_\ 92 | 93 | ```c 94 | static int MU_C2(umocktypes_copy_, type)(type* destination, const type* source) 95 | ``` 96 | 97 | **SRS_UMOCKTYPES_STRUCT_42_010: [** If `destination` is `NULL` then `umocktypes_copy_` shall fail and return a non-zero value. **]** 98 | 99 | **SRS_UMOCKTYPES_STRUCT_42_011: [** If `source` is `NULL` then `umocktypes_copy_` shall fail and return a non-zero value. **]** 100 | 101 | **SRS_UMOCKTYPES_STRUCT_42_012: [** `umocktypes_copy_` shall call `umocktypes_copy` for each field in `type`. **]** 102 | 103 | **SRS_UMOCKTYPES_STRUCT_42_013: [** If any call to `umocktypes_copy` does not return `0` then `umocktypes_copy_` shall return a non-zero value. **]** 104 | 105 | **SRS_UMOCKTYPES_STRUCT_42_014: [** Otherwise `umocktypes_copy_` shall return `0`. **]** 106 | 107 | 108 | ## umocktypes_free_\ 109 | 110 | ```c 111 | static void MU_C2(umocktypes_free_, type)(type* value) 112 | ``` 113 | 114 | **SRS_UMOCKTYPES_STRUCT_42_015: [** `umocktypes_free_` shall call `umocktypes_free` for each field in `type`. **]** 115 | -------------------------------------------------------------------------------- /devdoc/umocktypes_windows_requirements.md: -------------------------------------------------------------------------------- 1 | 2 | # umocktypes_windows requirements 3 | 4 | # Overview 5 | 6 | `umocktypes_windows` is a module that exposes out of the box functionality for several Windows types. 7 | 8 | The types are implemented as described [here](https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types) 9 | 10 | # Exposed API 11 | 12 | ```c 13 | int umocktypes_windows_register_types(void); 14 | ``` 15 | 16 | ## umocktypes_windows_register_types 17 | 18 | ```c 19 | int umocktypes_windows_register_types(void); 20 | ``` 21 | 22 | **SRS_UMOCKTYPES_WINDOWS_01_026: [** `umocktypes_windows_register_types` shall register the charptr types by calling `umocktypes_charptr_register_types`. **]** 23 | 24 | **SRS_UMOCKTYPES_WINDOWS_01_033: [** `umocktypes_windows_register_types` shall register the wcharptr types by calling `umocktypes_wcharptr_register_types`. **]** 25 | 26 | **SRS_UMOCKTYPES_WINDOWS_01_035: [** `umocktypes_windows_register_types` shall register the stdint types by calling `umocktypes_stdint_register_types`. **]** 27 | 28 | **SRS_UMOCKTYPES_WINDOWS_01_009: [** `umocktypes_windows_register_types` shall register support for the following alias types: **]** 29 | 30 | - **SRS_UMOCKTYPES_WINDOWS_01_001: [** `LONG` as an alias of `long`. **]** 31 | 32 | - **SRS_UMOCKTYPES_WINDOWS_01_002: [** `LONGLONG` as an alias of `long long`. **]** 33 | 34 | - **SRS_UMOCKTYPES_WINDOWS_01_003: [** `DWORD` as an alias of `unsigned long`. **]** 35 | 36 | - **SRS_UMOCKTYPES_WINDOWS_01_004: [** `HRESULT` as an alias of `LONG`. **]** 37 | 38 | - **SRS_UMOCKTYPES_WINDOWS_01_025: [** `BOOL` as an alias of `int`. **]** 39 | 40 | - **SRS_UMOCKTYPES_WINDOWS_01_007: [** `PVOID` as an alias of `void*`. **]** 41 | 42 | - **SRS_UMOCKTYPES_WINDOWS_01_008: [** `LPCSTR` as an alias of `const char*`. **]** 43 | 44 | - **SRS_UMOCKTYPES_WINDOWS_01_010: [** `LPSECURITY_ATTRIBUTES` as an alias of `void*`. **]** 45 | 46 | - **SRS_UMOCKTYPES_WINDOWS_01_011: [** `HANDLE` as an alias of `void*`. **]** 47 | 48 | - **SRS_UMOCKTYPES_WINDOWS_01_012: [** `UCHAR` as an alias of `unsigned char`. **]** 49 | 50 | - **SRS_UMOCKTYPES_WINDOWS_01_013: [** `PTP_POOL` as an alias of `void*`. **]** 51 | 52 | - **SRS_UMOCKTYPES_WINDOWS_01_014: [** `PTP_CLEANUP_GROUP` as an alias of `void*`. **]** 53 | 54 | - **SRS_UMOCKTYPES_WINDOWS_01_015: [** `PTP_CALLBACK_ENVIRON` as an alias of `void*`. **]** 55 | 56 | - **SRS_UMOCKTYPES_WINDOWS_01_016: [** `PTP_CLEANUP_GROUP_CANCEL_CALLBACK` as an alias of `void*`. **]** 57 | 58 | - **SRS_UMOCKTYPES_WINDOWS_01_017: [** `PTP_IO` as an alias of `void*`. **]** 59 | 60 | - **SRS_UMOCKTYPES_WINDOWS_01_018: [** `PTP_WIN32_IO_CALLBACK` as an alias of `void*`. **]** 61 | 62 | - **SRS_UMOCKTYPES_WINDOWS_01_019: [** `PTP_WORK_CALLBACK` as an alias of `void*`. **]** 63 | 64 | - **SRS_UMOCKTYPES_WINDOWS_01_020: [** `PTP_WORK` as an alias of `void*`. **]** 65 | 66 | - **SRS_UMOCKTYPES_WINDOWS_01_021: [** `LPCVOID` as an alias of `void*`. **]** 67 | 68 | - **SRS_UMOCKTYPES_WINDOWS_01_022: [** `LPDWORD` as an alias of `void*`. **]** 69 | 70 | - **SRS_UMOCKTYPES_WINDOWS_01_023: [** `LPOVERLAPPED` as an alias of `void*`. **]** 71 | 72 | - **SRS_UMOCKTYPES_WINDOWS_01_024: [** `LPVOID` as an alias of `void*`. **]** 73 | 74 | - **SRS_UMOCKTYPES_WINDOWS_01_027: [** `PTP_SIMPLE_CALLBACK` as an alias of `void*`. **]** 75 | 76 | - **SRS_UMOCKTYPES_WINDOWS_01_028: [** `LPLONG` as an alias of `void*`. **]** 77 | 78 | - **SRS_UMOCKTYPES_WINDOWS_01_029: [** `BYTE` as an alias of `unsigned char`. **]** 79 | 80 | - **SRS_UMOCKTYPES_WINDOWS_01_030: [** `BOOLEAN` as an alias of `BYTE`. **]** 81 | 82 | - **SRS_UMOCKTYPES_WINDOWS_01_031: [** `ULONG` as an alias of `unsigned long`. **]** 83 | 84 | - **SRS_UMOCKTYPES_WINDOWS_01_032: [** `LPCWSTR` as an alias of `const wchar_t*`. **]** 85 | 86 | - **SRS_UMOCKTYPES_WINDOWS_01_034: [** `LONG64` as an alias of `int64_t`. **]** 87 | 88 | - **SRS_UMOCKTYPES_WINDOWS_43_036: [** `SHORT` as an alias of `int16_t`. **]** 89 | 90 | - **SRS_UMOCKTYPES_WINDOWS_01_036: [** `SIZE_T` as an alias of `size_t`. **]** 91 | 92 | - **SRS_UMOCKTYPES_WINDOWS_01_037: [** `PSIZE_T` as an alias of `void*`. **]** 93 | 94 | - **SRS_UMOCKTYPES_WINDOWS_01_038: [** `PHANDLE` as an alias of `void*`. **]** 95 | 96 | **SRS_UMOCKTYPES_WINDOWS_01_005: [** On success, `umocktypes_windows_register_types` shall return 0. **]** 97 | 98 | **SRS_UMOCKTYPES_WINDOWS_01_006: [** If registering any of the types fails, `umocktypes_windows_register_types` shall fail and return a non-zero value. **]** 99 | -------------------------------------------------------------------------------- /inc/umock_c/aux_inc/cstdbool: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CSTDBOOL_H 5 | #define CSTDBOOL_H 6 | 7 | #include "stdbool.h" 8 | 9 | #endif /* STDBOOL_H */ 10 | -------------------------------------------------------------------------------- /inc/umock_c/aux_inc/cstdint: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CSTDINT_H 5 | #define CSTDINT_H 6 | 7 | #include "stdint.h" 8 | 9 | #endif /* CSTDINT_H */ 10 | -------------------------------------------------------------------------------- /inc/umock_c/aux_inc/inttypes.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef INTTYPES_H 5 | #define INTTYPES_H 6 | 7 | #define PRId8 "hhd" 8 | #define PRId16 "hd" 9 | #define PRId32 "d" 10 | #define PRId64 "lld" 11 | 12 | #define PRIu8 "hhu" 13 | #define PRIu16 "hu" 14 | #define PRIu32 "u" 15 | #define PRIu64 "llu" 16 | 17 | #endif // INTTYPES_H 18 | -------------------------------------------------------------------------------- /inc/umock_c/aux_inc/stdbool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef STDBOOL_H 5 | #define STDBOOL_H 6 | 7 | #define __bool_true_false_are_defined 1 8 | 9 | #define HAS_STDBOOL 10 | 11 | #ifndef __cplusplus 12 | 13 | typedef unsigned char bool; 14 | #ifdef _MSC_VER 15 | typedef bool _Bool; 16 | #endif 17 | 18 | #define false 0 19 | #define true 1 20 | 21 | #endif /* __cplusplus */ 22 | 23 | #endif /* STDBOOL_H */ 24 | -------------------------------------------------------------------------------- /inc/umock_c/aux_inc/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef STDINT_H 5 | #define STDINT_H 6 | 7 | typedef signed char int8_t; 8 | typedef short int16_t; 9 | typedef int int32_t; 10 | typedef long long int64_t; 11 | typedef unsigned char uint8_t; 12 | typedef unsigned short uint16_t; 13 | typedef unsigned int uint32_t; 14 | typedef unsigned long long uint64_t; 15 | 16 | typedef signed char int_least8_t; 17 | typedef short int_least16_t; 18 | typedef int int_least32_t; 19 | typedef long long int_least64_t; 20 | typedef unsigned char uint_least8_t; 21 | typedef unsigned short uint_least16_t; 22 | typedef unsigned int uint_least32_t; 23 | typedef unsigned long long uint_least64_t; 24 | 25 | typedef signed char int_fast8_t; 26 | typedef int int_fast16_t; 27 | typedef int int_fast32_t; 28 | typedef long long int_fast64_t; 29 | typedef unsigned char uint_fast8_t; 30 | typedef unsigned int uint_fast16_t; 31 | typedef unsigned int uint_fast32_t; 32 | typedef unsigned long long uint_fast64_t; 33 | 34 | #define INT8_MIN (-127i8 - 1) 35 | #define INT16_MIN (-32767i16 - 1) 36 | #define INT32_MIN (-2147483647i32 - 1) 37 | #define INT64_MIN (-9223372036854775807i64 - 1) 38 | #define INT8_MAX 127i8 39 | #define INT16_MAX 32767i16 40 | #define INT32_MAX 2147483647i32 41 | #define INT64_MAX 9223372036854775807i64 42 | #define UINT8_MAX 0xffui8 43 | #define UINT16_MAX 0xffffui16 44 | #define UINT32_MAX 0xffffffffui32 45 | #define UINT64_MAX 0xffffffffffffffffui64 46 | 47 | #endif /* STDINT_H */ 48 | -------------------------------------------------------------------------------- /inc/umock_c/umock_c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_C_H 5 | #define UMOCK_C_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #include "macro_utils/macro_utils.h" 14 | 15 | #include "umock_c/umockcallrecorder.h" 16 | #include "umock_c/umock_lock_factory.h" 17 | 18 | /* Define UMOCK_STATIC to static to make mocks private to compilation unit */ 19 | #ifndef UMOCK_STATIC 20 | #define UMOCK_STATIC 21 | #endif 22 | 23 | #define UMOCK_C_ERROR_CODE_VALUES \ 24 | UMOCK_C_ARG_INDEX_OUT_OF_RANGE, \ 25 | UMOCK_C_MALLOC_ERROR, \ 26 | UMOCK_C_INVALID_ARGUMENT_BUFFER, \ 27 | UMOCK_C_COMPARE_CALL_ERROR, \ 28 | UMOCK_C_RESET_CALLS_ERROR, \ 29 | UMOCK_C_CAPTURE_RETURN_ALREADY_USED, \ 30 | UMOCK_C_NULL_ARGUMENT, \ 31 | UMOCK_C_INVALID_PAIRED_CALLS, \ 32 | UMOCK_C_REGISTER_TYPE_FAILED, \ 33 | UMOCK_C_ERROR 34 | 35 | MU_DEFINE_ENUM(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) 36 | 37 | /* This is the type for the error callback by which umock_c shall indicate errors to the user */ 38 | typedef void(*ON_UMOCK_C_ERROR)(UMOCK_C_ERROR_CODE error_code); 39 | 40 | // Always use 0 as it does not really matter what value we pass since the argument will be ignored anyway 41 | #define IGNORED_ARG (0) 42 | 43 | #define REGISTER_GLOBAL_MOCK_HOOK(mock_function, mock_hook_function) \ 44 | MU_C2(set_global_mock_hook_,mock_function)(mock_hook_function); 45 | 46 | #define REGISTER_GLOBAL_MOCK_RETURN(mock_function, return_value) \ 47 | MU_C2(set_global_mock_return_,mock_function)(return_value); 48 | 49 | #define REGISTER_GLOBAL_MOCK_FAIL_RETURN(mock_function, fail_return_value) \ 50 | MU_C2(set_global_mock_fail_return_,mock_function)(fail_return_value); 51 | 52 | #define REGISTER_GLOBAL_MOCK_RETURNS(mock_function, return_value, fail_return_value) \ 53 | MU_C2(set_global_mock_returns_,mock_function)(return_value, fail_return_value); 54 | 55 | /* Codes_SRS_UMOCK_C_LIB_01_013: [STRICT_EXPECTED_CALL shall record that a certain call is expected.] */ 56 | #define STRICT_EXPECTED_CALL(call) \ 57 | MU_C2(get_auto_ignore_args_function_, call)(MU_C2(umock_c_strict_expected_,call), #call) 58 | 59 | #define EXPECTED_CALL(call) \ 60 | MU_C2(umock_c_expected_,call) 61 | 62 | #define DECLARE_UMOCK_POINTER_TYPE_FOR_TYPE(value_type, alias) \ 63 | char* MU_C3(stringify_func_,alias,ptr)(const value_type** value) \ 64 | { \ 65 | char temp_buffer[32]; \ 66 | char* result; \ 67 | size_t length = sprintf(temp_buffer, "%p", (void*)*value); \ 68 | if (length < 0) \ 69 | { \ 70 | result = NULL; \ 71 | } \ 72 | else \ 73 | { \ 74 | result = (char*)malloc(length + 1); \ 75 | if (result != NULL) \ 76 | { \ 77 | (void)memcpy(result, temp_buffer, length + 1); \ 78 | } \ 79 | } \ 80 | return result; \ 81 | } \ 82 | int MU_C3(are_equal_func_,alias,ptr)(const value_type** left, const value_type** right) \ 83 | { \ 84 | return *left == *right; \ 85 | } \ 86 | int MU_C3(copy_func_,alias,ptr)(value_type** destination, const value_type** source) \ 87 | { \ 88 | *destination = (value_type*)*source; \ 89 | return 0; \ 90 | } \ 91 | void MU_C3(free_func_,alias,ptr)(value_type** value) \ 92 | { \ 93 | (void)value; \ 94 | } \ 95 | 96 | #ifdef __cplusplus 97 | extern "C" { 98 | #endif 99 | 100 | void umock_c_indicate_error(UMOCK_C_ERROR_CODE error_code); 101 | int umock_c_init(ON_UMOCK_C_ERROR on_umock_c_error); 102 | int umock_c_init_with_lock_factory(ON_UMOCK_C_ERROR on_umock_c_error, UMOCK_C_LOCK_FACTORY_CREATE_LOCK_FUNC lock_factory_create_lock, void* lock_factory_create_lock_params); 103 | void umock_c_deinit(void); 104 | void umock_c_reset_all_calls(void); 105 | const char* umock_c_get_actual_calls(void); 106 | const char* umock_c_get_expected_calls(void); 107 | UMOCKCALLRECORDER_HANDLE umock_c_get_call_recorder(void); 108 | int umock_c_set_call_recorder(UMOCKCALLRECORDER_HANDLE umockc_call_recorder); 109 | int umock_c_add_actual_call(UMOCKCALL_HANDLE mock_call, UMOCKCALL_HANDLE* matched_call); 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | 115 | /* Codes_SRS_UMOCK_C_LIB_01_065: [REGISTER_UMOCK_VALUE_TYPE shall register the type identified by value_type to be usable by umock_c for argument and return types and instruct umock_c which functions to use for getting the stringify, are_equal, copy and free.]*/ 116 | /* Codes_SRS_UMOCK_C_LIB_01_197: [ If REGISTER_UMOCK_VALUE_TYPE fails, the on_error callback shall be called with UMOCK_C_REGISTER_TYPE_FAILED. ]*/ 117 | #define REGISTER_UMOCK_VALUE_TYPE_ALL(value_type, stringify_func, are_equal_func, copy_func, free_func) \ 118 | { \ 119 | if (umocktypes_register_type(MU_TOSTRING(value_type), (UMOCKTYPE_STRINGIFY_FUNC)stringify_func, (UMOCKTYPE_ARE_EQUAL_FUNC)are_equal_func, (UMOCKTYPE_COPY_FUNC)copy_func, (UMOCKTYPE_FREE_FUNC)free_func) != 0) \ 120 | { \ 121 | umock_c_indicate_error(UMOCK_C_REGISTER_TYPE_FAILED); \ 122 | } \ 123 | } 124 | 125 | /* Codes_SRS_UMOCK_C_LIB_01_066: [If only the value_type is specified in the macro invocation then the stringify, are_equal, copy and free function names shall be automatically derived from the type as: umockvalue_stringify_value_type, umockvalue_are_equal_value_type, umockvalue_copy_value_type, umockvalue_free_value_type.]*/ 126 | #define REGISTER_UMOCK_VALUE_TYPE_ONLY_TYPE(value_type) \ 127 | REGISTER_UMOCK_VALUE_TYPE_ALL (value_type, MU_C2(umock_stringify_,value_type), MU_C2(umock_are_equal_,value_type), MU_C2(umock_copy_,value_type), MU_C2(umock_free_,value_type)) 128 | 129 | #if defined(_MSC_VER) && (_MSC_VER < 1920) 130 | #define REGISTER_UMOCK_VALUE_TYPE(...) \ 131 | MU_IF(MU_DIV2(MU_COUNT_ARG(__VA_ARGS__)), REGISTER_UMOCK_VALUE_TYPE_ALL, REGISTER_UMOCK_VALUE_TYPE_ONLY_TYPE) MU_LPAREN __VA_ARGS__) 132 | #else 133 | #define REGISTER_UMOCK_VALUE_TYPE(...) \ 134 | MU_IF(MU_DIV2(MU_COUNT_ARG(__VA_ARGS__)), REGISTER_UMOCK_VALUE_TYPE_ALL, REGISTER_UMOCK_VALUE_TYPE_ONLY_TYPE) (__VA_ARGS__) 135 | #endif 136 | 137 | #define UMOCK_INTERNAL_REGISTER_ALIAS_TYPE(registered_type, is_type) \ 138 | (((sizeof(registered_type) != sizeof(is_type)) || (umocktypes_register_alias_type(MU_TOSTRING(registered_type), MU_TOSTRING(is_type)) != 0)) ? MU_FAILURE : 0) 139 | 140 | /* Codes_SRS_UMOCK_C_LIB_01_149: [ REGISTER_UMOCK_ALIAS_TYPE registers a new alias type for another type. ]*/ 141 | /* Codes_SRS_UMOCK_C_LIB_02_001: [ If the types do not have the same size the on_error callback shall be called with UMOCK_C_REGISTER_TYPE_FAILED. ]*/ 142 | /* Codes_SRS_UMOCK_C_LIB_01_198: [ If REGISTER_UMOCK_ALIAS_TYPE fails, the on_error callback shall be called with UMOCK_C_REGISTER_TYPE_FAILED. ]*/ 143 | #define REGISTER_UMOCK_ALIAS_TYPE(value_type, is_value_type) \ 144 | if (UMOCK_INTERNAL_REGISTER_ALIAS_TYPE(value_type, is_value_type) != 0) \ 145 | { \ 146 | umock_c_indicate_error(UMOCK_C_REGISTER_TYPE_FAILED); \ 147 | } \ 148 | 149 | #define UMOCK_TYPE(value_type) \ 150 | (const char*)(const void*)(const value_type*)(const void*)MU_TOSTRING(value_type) 151 | 152 | #include "umock_c/umock_c_internal.h" 153 | #include "umock_c/umock_c_prod.h" 154 | 155 | #endif /* UMOCK_C_H */ 156 | -------------------------------------------------------------------------------- /inc/umock_c/umock_c_negative_tests.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_C_NEGATIVE_TESTS_H 5 | #define UMOCK_C_NEGATIVE_TESTS_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | int umock_c_negative_tests_init(void); 18 | void umock_c_negative_tests_deinit(void); 19 | void umock_c_negative_tests_snapshot(void); 20 | void umock_c_negative_tests_reset(void); 21 | void umock_c_negative_tests_fail_call(size_t index); 22 | size_t umock_c_negative_tests_call_count(void); 23 | int umock_c_negative_tests_can_call_fail(size_t index); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* UMOCK_C_NEGATIVE_TESTS_H */ 30 | -------------------------------------------------------------------------------- /inc/umock_c/umock_lock_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_LOCK_FACTORY_H 5 | #define UMOCK_LOCK_FACTORY_H 6 | 7 | #include "umock_c/umock_lock_if.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef UMOCK_C_LOCK_HANDLE(*UMOCK_C_LOCK_FACTORY_CREATE_LOCK_FUNC)(void* params); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /* UMOCK_LOCK_FACTORY_H */ 20 | -------------------------------------------------------------------------------- /inc/umock_c/umock_lock_factory_default.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_LOCK_FACTORY_DEFAULT_H 5 | #define UMOCK_LOCK_FACTORY_DEFAULT_H 6 | 7 | #include "umock_c/umock_lock_if.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /* UMOCK_LOCK_FACTORY_DEFAULT_H */ 20 | -------------------------------------------------------------------------------- /inc/umock_c/umock_lock_if.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_LOCK_IF_H 5 | #define UMOCK_LOCK_IF_H 6 | 7 | #include "macro_utils/macro_utils.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef const struct UMOCK_C_LOCK_IF_TAG* UMOCK_C_LOCK_HANDLE; 14 | 15 | typedef void (*UMOCK_C_LOCK_ACQUIRE_SHARED_FUNC)(UMOCK_C_LOCK_HANDLE lock); 16 | typedef void (*UMOCK_C_LOCK_RELEASE_SHARED_FUNC)(UMOCK_C_LOCK_HANDLE lock); 17 | typedef void (*UMOCK_C_LOCK_ACQUIRE_EXCLUSIVE_FUNC)(UMOCK_C_LOCK_HANDLE lock); 18 | typedef void (*UMOCK_C_LOCK_RELEASE_EXCLUSIVE_FUNC)(UMOCK_C_LOCK_HANDLE lock); 19 | typedef void (*UMOCK_C_LOCK_DESTROY_FUNC)(UMOCK_C_LOCK_HANDLE lock); 20 | 21 | typedef struct UMOCK_C_LOCK_IF_TAG 22 | { 23 | UMOCK_C_LOCK_ACQUIRE_SHARED_FUNC acquire_shared; 24 | UMOCK_C_LOCK_RELEASE_SHARED_FUNC release_shared; 25 | UMOCK_C_LOCK_ACQUIRE_EXCLUSIVE_FUNC acquire_exclusive; 26 | UMOCK_C_LOCK_RELEASE_EXCLUSIVE_FUNC release_exclusive; 27 | UMOCK_C_LOCK_DESTROY_FUNC destroy; 28 | } UMOCK_C_LOCK_IF; 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* UMOCK_LOCK_IF_H */ 35 | -------------------------------------------------------------------------------- /inc/umock_c/umock_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_LOG_H 5 | #define UMOCK_LOG_H 6 | 7 | #include "c_logging/logger.h" 8 | #include "c_logging/log_level.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define UMOCK_LOG(format, ...) \ 15 | LOGGER_LOG(LOG_LEVEL_ERROR, NULL, format, __VA_ARGS__) 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif /* UMOCK_LOG_H */ 22 | -------------------------------------------------------------------------------- /inc/umock_c/umockalloc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKALLOC_H 5 | #define UMOCKALLOC_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void* umockalloc_malloc(size_t size); 18 | void* umockalloc_calloc(size_t nmemb, size_t size); 19 | void* umockalloc_realloc(void* ptr, size_t size); 20 | void umockalloc_free(void* ptr); 21 | 22 | char* umockc_stringify_buffer(const void* bytes, size_t length); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* UMOCKALLOC_H */ 29 | -------------------------------------------------------------------------------- /inc/umock_c/umockautoignoreargs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKAUTOIGNOREARGS_H 5 | #define UMOCKAUTOIGNOREARGS_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #else 11 | #include 12 | #endif 13 | 14 | int umockautoignoreargs_is_call_argument_ignored(const char* call, size_t argument_index, int* is_argument_ignored); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif /* UMOCKAUTOIGNOREARGS_H */ 21 | -------------------------------------------------------------------------------- /inc/umock_c/umockcall.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKCALL_H 5 | #define UMOCKCALL_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct UMOCKCALL_TAG* UMOCKCALL_HANDLE; 18 | typedef void*(*UMOCKCALL_DATA_COPY_FUNC)(void* umockcall_data); 19 | typedef void(*UMOCKCALL_DATA_FREE_FUNC)(void* umockcall_data); 20 | typedef char*(*UMOCKCALL_DATA_STRINGIFY_FUNC)(void* umockcall_data); 21 | typedef int(*UMOCKCALL_DATA_ARE_EQUAL_FUNC)(void* left, void* right); 22 | 23 | UMOCKCALL_HANDLE umockcall_create(const char* function_name, void* umockcall_data, UMOCKCALL_DATA_COPY_FUNC umockcall_data_copy, UMOCKCALL_DATA_FREE_FUNC umockcall_data_free, UMOCKCALL_DATA_STRINGIFY_FUNC umockcall_data_stringify, UMOCKCALL_DATA_ARE_EQUAL_FUNC umockcall_data_are_equal); 24 | void umockcall_destroy(UMOCKCALL_HANDLE umockcall); 25 | int umockcall_are_equal(UMOCKCALL_HANDLE left, UMOCKCALL_HANDLE right); 26 | char* umockcall_stringify(UMOCKCALL_HANDLE umockcall); 27 | void* umockcall_get_call_data(UMOCKCALL_HANDLE umockcall); 28 | UMOCKCALL_HANDLE umockcall_clone(UMOCKCALL_HANDLE umockcall); 29 | int umockcall_set_fail_call(UMOCKCALL_HANDLE umockcall, int fail_call); 30 | int umockcall_get_fail_call(UMOCKCALL_HANDLE umockcall); 31 | int umockcall_set_ignore_all_calls(UMOCKCALL_HANDLE umockcall, int ignore_all_calls); 32 | int umockcall_get_ignore_all_calls(UMOCKCALL_HANDLE umockcall); 33 | int umockcall_set_call_can_fail(UMOCKCALL_HANDLE umockcall, int call_can_fail); 34 | int umockcall_get_call_can_fail(UMOCKCALL_HANDLE umockcall); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* UMOCKCALL_H */ 41 | -------------------------------------------------------------------------------- /inc/umock_c/umockcallpairs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKCALLPAIRS_H 5 | #define UMOCKCALLPAIRS_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct PAIRED_HANDLE_TAG 18 | { 19 | void* handle_value; 20 | char* handle_type; 21 | } PAIRED_HANDLE; 22 | 23 | typedef struct PAIRED_HANDLES_TAG 24 | { 25 | PAIRED_HANDLE* paired_handles; 26 | size_t paired_handle_count; 27 | } PAIRED_HANDLES; 28 | 29 | int umockcallpairs_track_create_paired_call(PAIRED_HANDLES* paired_handles, const void* handle, const char* handle_type, size_t handle_type_size); 30 | int umockcallpairs_track_destroy_paired_call(PAIRED_HANDLES* paired_handles, const void* handle); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* UMOCKCALLPAIRS_H */ 37 | -------------------------------------------------------------------------------- /inc/umock_c/umockcallrecorder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKCALLRECORDER_H 5 | #define UMOCKCALLRECORDER_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #include "umock_c/umockcall.h" 14 | #include "umock_c/umock_lock_factory.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct UMOCKCALLRECORDER_TAG* UMOCKCALLRECORDER_HANDLE; 21 | 22 | UMOCKCALLRECORDER_HANDLE umockcallrecorder_create(UMOCK_C_LOCK_FACTORY_CREATE_LOCK_FUNC lock_factory_create_lock, void* lock_factory_create_lock_params); 23 | void umockcallrecorder_destroy(UMOCKCALLRECORDER_HANDLE umock_call_recorder); 24 | int umockcallrecorder_reset_all_calls(UMOCKCALLRECORDER_HANDLE umock_call_recorder); 25 | int umockcallrecorder_add_expected_call(UMOCKCALLRECORDER_HANDLE umock_call_recorder, UMOCKCALL_HANDLE mock_call); 26 | int umockcallrecorder_add_actual_call(UMOCKCALLRECORDER_HANDLE umock_call_recorder, UMOCKCALL_HANDLE mock_call, UMOCKCALL_HANDLE* matched_call); 27 | const char* umockcallrecorder_get_actual_calls(UMOCKCALLRECORDER_HANDLE umock_call_recorder); 28 | const char* umockcallrecorder_get_expected_calls(UMOCKCALLRECORDER_HANDLE umock_call_recorder); 29 | UMOCKCALL_HANDLE umockcallrecorder_get_last_expected_call(UMOCKCALLRECORDER_HANDLE umock_call_recorder); 30 | UMOCKCALLRECORDER_HANDLE umockcallrecorder_clone(UMOCKCALLRECORDER_HANDLE umock_call_recorder); 31 | int umockcallrecorder_get_expected_call_count(UMOCKCALLRECORDER_HANDLE umock_call_recorder, size_t* expected_call_count); 32 | int umockcallrecorder_fail_call(UMOCKCALLRECORDER_HANDLE umock_call_recorder, size_t index); 33 | int umockcallrecorder_can_call_fail(UMOCKCALLRECORDER_HANDLE umock_call_recorder, size_t index, int* can_call_fail); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* UMOCKCALLRECORDER_H */ 40 | -------------------------------------------------------------------------------- /inc/umock_c/umockstring.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKSTRING_H 5 | #define UMOCKSTRING_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | char* umockstring_clone(const char* source); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* UMOCKSTRING_H */ 18 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypename.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPENAME_H 5 | #define UMOCKTYPENAME_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | char* umocktypename_normalize(const char* type_name); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* UMOCKTYPENAME_H */ 18 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_H 5 | #define UMOCKTYPES_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #include 10 | #else 11 | #include 12 | #include 13 | #endif 14 | 15 | #include "macro_utils/macro_utils.h" 16 | 17 | #include "umock_c/umock_c.h" 18 | #include "umock_c/umockalloc.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef char*(*UMOCKTYPE_STRINGIFY_FUNC)(const void* value); 25 | typedef int(*UMOCKTYPE_COPY_FUNC)(void* destination, const void* source); 26 | typedef void(*UMOCKTYPE_FREE_FUNC)(void* value); 27 | typedef int(*UMOCKTYPE_ARE_EQUAL_FUNC)(const void* left, const void* right); 28 | 29 | int umocktypes_init(void); 30 | void umocktypes_deinit(void); 31 | int umocktypes_register_type(const char* type, UMOCKTYPE_STRINGIFY_FUNC stringify_func, UMOCKTYPE_ARE_EQUAL_FUNC are_equal_func, UMOCKTYPE_COPY_FUNC copy_func, UMOCKTYPE_FREE_FUNC free_func); 32 | int umocktypes_register_alias_type(const char* type, const char* alias_type); 33 | 34 | char* umocktypes_stringify(const char* type, const void* value); 35 | int umocktypes_are_equal(const char* type, const void* left, const void* right); 36 | int umocktypes_copy(const char* type, void* destination, const void* source); 37 | void umocktypes_free(const char* type, void* value); 38 | 39 | /* This is a convenience macro that allows registering a type by simply specifying the name and a function_postfix*/ 40 | #define REGISTER_TYPE(type, function_postfix) \ 41 | umocktypes_register_type(MU_TOSTRING(type), (UMOCKTYPE_STRINGIFY_FUNC)MU_C2(umocktypes_stringify_, function_postfix), \ 42 | (UMOCKTYPE_ARE_EQUAL_FUNC)MU_C2(umocktypes_are_equal_,function_postfix), \ 43 | (UMOCKTYPE_COPY_FUNC)MU_C2(umocktypes_copy_,function_postfix), \ 44 | (UMOCKTYPE_FREE_FUNC)MU_C2(umocktypes_free_,function_postfix)) 45 | 46 | #define IMPLEMENT_UMOCK_C_ENUM_STRINGIFY_COMMON(enum_name, ...) \ 47 | char* MU_C2(umocktypes_stringify_,enum_name)(const enum_name* value) \ 48 | { \ 49 | char* result; \ 50 | if (value == NULL) \ 51 | { \ 52 | result = NULL; \ 53 | } \ 54 | else \ 55 | { \ 56 | int length = snprintf(NULL, 0, "%" PRI_MU_ENUM "", MU_ENUM_VALUE(MU_C2(enum_name,_for_umock), *value)); \ 57 | if (length < 0) \ 58 | { \ 59 | result = NULL; \ 60 | } \ 61 | else \ 62 | { \ 63 | result = (char*)umockalloc_malloc(length + 1); \ 64 | if (result != NULL) \ 65 | { \ 66 | if (snprintf(result, length + 1, "%" PRI_MU_ENUM "", MU_ENUM_VALUE(MU_C2(enum_name,_for_umock), *value)) < 0) \ 67 | { \ 68 | umockalloc_free(result); \ 69 | } \ 70 | else \ 71 | { \ 72 | /* return as is */ \ 73 | } \ 74 | } \ 75 | else \ 76 | { \ 77 | /* return as is */ \ 78 | } \ 79 | } \ 80 | } \ 81 | return result; \ 82 | } 83 | /* Codes_SRS_UMOCK_C_LIB_01_181: [ If a value that is not part of the enum is used, it shall be treated as an int value. ]*/ 84 | #define IMPLEMENT_UMOCK_C_ENUM_STRINGIFY(enum_name, ...) \ 85 | typedef enum_name MU_C2(enum_name,_for_umock); \ 86 | MU_DEFINE_ENUM_STRINGS(MU_C2(enum_name,_for_umock), __VA_ARGS__); \ 87 | IMPLEMENT_UMOCK_C_ENUM_STRINGIFY_COMMON(enum_name, __VA_ARGS__) 88 | 89 | #define IMPLEMENT_UMOCK_C_ENUM_STRINGIFY_WITHOUT_INVALID(enum_name, ...) \ 90 | typedef enum_name MU_C2(enum_name,_for_umock); \ 91 | MU_DEFINE_ENUM_STRINGS_WITHOUT_INVALID(MU_C2(enum_name,_for_umock), __VA_ARGS__); \ 92 | IMPLEMENT_UMOCK_C_ENUM_STRINGIFY_COMMON(enum_name, __VA_ARGS__) 93 | 94 | #define IMPLEMENT_UMOCK_C_ENUM_ARE_EQUAL(type) \ 95 | int MU_C2(umocktypes_are_equal_,type)(const type* left, const type* right) \ 96 | { \ 97 | int result; \ 98 | if ((left == NULL) || (right == NULL)) \ 99 | { \ 100 | result = -1; \ 101 | } \ 102 | else \ 103 | { \ 104 | result = ((*left) == (*right)) ? 1 : 0; \ 105 | } \ 106 | return result; \ 107 | } 108 | 109 | #define IMPLEMENT_UMOCK_C_ENUM_COPY(type) \ 110 | int MU_C2(umocktypes_copy_,type)(type* destination, const type* source) \ 111 | { \ 112 | int result; \ 113 | if ((destination == NULL) || \ 114 | (source == NULL)) \ 115 | { \ 116 | result = __LINE__; \ 117 | } \ 118 | else \ 119 | { \ 120 | *destination = *source; \ 121 | result = 0; \ 122 | } \ 123 | return result; \ 124 | } 125 | 126 | #define IMPLEMENT_UMOCK_C_ENUM_FREE(type) \ 127 | void MU_C2(umocktypes_free_,type)(type* value) \ 128 | { \ 129 | (void)value; \ 130 | } 131 | 132 | /* Codes_SRS_UMOCK_C_LIB_01_179: [ IMPLEMENT_UMOCK_C_ENUM_TYPE and IMPLEMENT_UMOCK_C_ENUM_STRINGIFY_WITHOUT_INVALID shall implement umock_c handlers for an enum type. ]*/ 133 | /* Codes_SRS_UMOCK_C_LIB_01_180: [ The variable arguments are a list making up the enum values. ]*/ 134 | #define IMPLEMENT_UMOCK_C_ENUM_TYPE(type, ...) \ 135 | IMPLEMENT_UMOCK_C_ENUM_STRINGIFY(type, __VA_ARGS__) \ 136 | IMPLEMENT_UMOCK_C_ENUM_ARE_EQUAL(type) \ 137 | IMPLEMENT_UMOCK_C_ENUM_COPY(type) \ 138 | IMPLEMENT_UMOCK_C_ENUM_FREE(type) 139 | 140 | #define IMPLEMENT_UMOCK_C_ENUM_TYPE_WITHOUT_INVALID(type, ...) \ 141 | IMPLEMENT_UMOCK_C_ENUM_STRINGIFY_WITHOUT_INVALID(type, __VA_ARGS__) \ 142 | IMPLEMENT_UMOCK_C_ENUM_ARE_EQUAL(type) \ 143 | IMPLEMENT_UMOCK_C_ENUM_COPY(type) \ 144 | IMPLEMENT_UMOCK_C_ENUM_FREE(type) 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif /* UMOCKTYPES_H */ 151 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes_bool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_BOOL_H 5 | #define UMOCKTYPES_BOOL_H 6 | 7 | #ifdef __cplusplus 8 | #else 9 | #include 10 | #endif 11 | 12 | #include "macro_utils/macro_utils.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | int umocktypes_bool_register_types(void); 19 | 20 | char* umocktypes_stringify_bool(const bool* value); \ 21 | int umocktypes_are_equal_bool(const bool* left, const bool* right); \ 22 | int umocktypes_copy_bool(bool* destination, const bool* source); \ 23 | void umocktypes_free_bool(bool* value); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* UMOCKTYPES_BOOL_H */ 30 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes_c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_C_H 5 | #define UMOCKTYPES_C_H 6 | 7 | #include "macro_utils/macro_utils.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | int umocktypes_c_register_types(void); 14 | 15 | #define UMOCKTYPES_HANDLERS(type, function_postfix) \ 16 | char* MU_C2(umocktypes_stringify_,function_postfix)(type* value); \ 17 | int MU_C2(umocktypes_are_equal_, function_postfix)(type* left, type* right); \ 18 | int MU_C2(umocktypes_copy_, function_postfix)(type* destination, type* source); \ 19 | void MU_C2(umocktypes_free_, function_postfix)(type* value); 20 | 21 | UMOCKTYPES_HANDLERS(char, char) 22 | UMOCKTYPES_HANDLERS(unsigned char, unsignedchar) 23 | UMOCKTYPES_HANDLERS(short, short) 24 | UMOCKTYPES_HANDLERS(unsigned short, unsignedshort) 25 | UMOCKTYPES_HANDLERS(int, int) 26 | UMOCKTYPES_HANDLERS(unsigned int, unsignedint) 27 | UMOCKTYPES_HANDLERS(long, long) 28 | UMOCKTYPES_HANDLERS(unsigned long, unsignedlong) 29 | UMOCKTYPES_HANDLERS(long long, longlong) 30 | UMOCKTYPES_HANDLERS(unsigned long long, unsignedlonglong) 31 | UMOCKTYPES_HANDLERS(float, float) 32 | UMOCKTYPES_HANDLERS(double, double) 33 | UMOCKTYPES_HANDLERS(long double, longdouble) 34 | UMOCKTYPES_HANDLERS(size_t, size_t) 35 | UMOCKTYPES_HANDLERS(void*, void_ptr) 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* UMOCKTYPES_C_H */ 42 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes_charptr.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_CHARPTR_H 5 | #define UMOCKTYPES_CHARPTR_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* Codes_SRS_UMOCK_C_LIB_01_067: [char\* and const char\* shall be supported out of the box through a separate header, umockvalue_charptr.h.]*/ 12 | /* Codes_SRS_UMOCK_C_LIB_01_069: [The signature shall be: ...*/ 13 | int umocktypes_charptr_register_types(void); 14 | 15 | char* umocktypes_stringify_charptr(const char** value); 16 | int umocktypes_are_equal_charptr(const char** left, const char** right); 17 | int umocktypes_copy_charptr(char** destination, const char** source); 18 | void umocktypes_free_charptr(char** value); 19 | 20 | char* umocktypes_stringify_const_charptr(const char** value); 21 | int umocktypes_are_equal_const_charptr(const char** left, const char** right); 22 | int umocktypes_copy_const_charptr(const char** destination, const char** source); 23 | void umocktypes_free_const_charptr(const char** value); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* UMOCKTYPES_CHARPTR_H */ 30 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes_stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_STDINT_H 5 | #define UMOCKTYPES_STDINT_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #include "macro_utils/macro_utils.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int umocktypes_stdint_register_types(void); 20 | 21 | #define UMOCKTYPES_STDINT_HANDLERS(type, function_postfix) \ 22 | char* MU_C2(umocktypes_stringify_,function_postfix)(type* value); \ 23 | int MU_C2(umocktypes_are_equal_, function_postfix)(type* left, type* right); \ 24 | int MU_C2(umocktypes_copy_, function_postfix)(type* destination, type* source); \ 25 | void MU_C2(umocktypes_free_, function_postfix)(type* value); 26 | 27 | UMOCKTYPES_STDINT_HANDLERS(uint8_t, uint8_t) 28 | UMOCKTYPES_STDINT_HANDLERS(int8_t, int8_t) 29 | UMOCKTYPES_STDINT_HANDLERS(uint16_t, uint16_t) 30 | UMOCKTYPES_STDINT_HANDLERS(int16_t, int16_t) 31 | UMOCKTYPES_STDINT_HANDLERS(uint32_t, uint32_t) 32 | UMOCKTYPES_STDINT_HANDLERS(int32_t, int32_t) 33 | UMOCKTYPES_STDINT_HANDLERS(uint64_t, uint64_t) 34 | UMOCKTYPES_STDINT_HANDLERS(int64_t, int64_t) 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* UMOCKTYPES_STDINT_H */ 41 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes_wcharptr.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_WCHARPTR_H 5 | #define UMOCKTYPES_WCHARPTR_H 6 | 7 | #ifndef __cplusplus 8 | #include 9 | #endif 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /* Codes_SRS_UMOCK_C_LIB_01_067: [wchar_t\* and const wchar_t\* shall be supported out of the box through a separate header, umockvalue_wcharptr.h.]*/ 16 | /* Codes_SRS_UMOCK_C_LIB_01_069: [The signature shall be: ...*/ 17 | int umocktypes_wcharptr_register_types(void); 18 | 19 | char* umocktypes_stringify_wcharptr(const wchar_t** value); 20 | int umocktypes_are_equal_wcharptr(const wchar_t** left, const wchar_t** right); 21 | int umocktypes_copy_wcharptr(wchar_t** destination, const wchar_t** source); 22 | void umocktypes_free_wcharptr(wchar_t** value); 23 | 24 | char* umocktypes_stringify_const_wcharptr(const wchar_t** value); 25 | int umocktypes_are_equal_const_wcharptr(const wchar_t** left, const wchar_t** right); 26 | int umocktypes_copy_const_wcharptr(const wchar_t** destination, const wchar_t** source); 27 | void umocktypes_free_const_wcharptr(const wchar_t** value); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* UMOCKTYPES_WCHARPTR_H */ 34 | -------------------------------------------------------------------------------- /inc/umock_c/umocktypes_windows.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCKTYPES_WINDOWS_H 5 | #define UMOCKTYPES_WINDOWS_H 6 | 7 | #ifndef __cplusplus 8 | #include 9 | #endif 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | int umocktypes_windows_register_types(void); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif /* UMOCKTYPES_WINDOWS_H */ 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 2 | 3 | # umock_c 4 | 5 | umock_c is a C mocking library. 6 | 7 | ## Setup 8 | 9 | ### Build 10 | 11 | - Clone umock_c by: 12 | 13 | ``` 14 | git clone --recursive https://github.com/Azure/umock-c.git 15 | ``` 16 | 17 | - Create a cmake folder under the root of umock-c 18 | 19 | - Switch to the cmake folder and run 20 | ``` 21 | cmake .. 22 | ``` 23 | 24 | If you would like to use installed (by CMake) versions of packages already on your machine: 25 | 26 | ``` 27 | cmake -Duse_installed=ON ../ 28 | ``` 29 | 30 | - Build the code for your platform (msbuild for Windows, make for Linux, etc.) by executing in the cmake folder: 31 | 32 | ``` 33 | cmake --build . 34 | ``` 35 | 36 | ### To install umock_c: 37 | 38 | ``` 39 | cmake -Duse_installed=ON ../ 40 | ``` 41 | On Linux: 42 | ``` 43 | sudo make install 44 | ``` 45 | On Windows: 46 | ``` 47 | msbuild /m INSTALL.vcxproj 48 | ``` 49 | 50 | _This requires that ctest and testrunnerswitcher are both installed (through CMake) on your machine._ 51 | 52 | ### Building tests 53 | 54 | In order to build the tests use the *run_unittests* cmake option: 55 | 56 | ``` 57 | cmake .. -Drun_unittests:bool=ON 58 | ``` 59 | 60 | ## Example 61 | 62 | Ever wanted to write something like this in C as a test? 63 | 64 | ```c 65 | TEST_FUNCTION(my_first_test) 66 | { 67 | // arrange 68 | STRICT_EXPECTED_CALL(test_dependency_1_arg(42)) 69 | .SetReturn(44) 70 | .IgnoreAllArguments(); 71 | 72 | // act 73 | int result = function_under_test(); 74 | 75 | // assert 76 | ASSERT_ARE_EQUAL(int, 44, result); 77 | ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); 78 | } 79 | ``` 80 | 81 | umock_c has way more features than this simple example! 82 | 83 | ## Dependencies 84 | 85 | - umock_c uses ctest as test runner (https://github.com/Azure/azure-ctest.git). ctest is a C test runner that can be run on many platforms as it does not make use of compiler/platform specific code and thus it is easily portable. 86 | - umock_c uses cmake (https://cmake.org/) to generate build files. 87 | - umock_c uses testrunnerswitcher to allow switching between ctest and CppUnitTest for Windows. 88 | 89 | ## Documentation 90 | 91 | Complete documentation is available [here](doc/umock_c.md). 92 | -------------------------------------------------------------------------------- /set_vld_vars.bat: -------------------------------------------------------------------------------- 1 | set PATH=c:\Program Files (x86)\Visual Leak Detector\bin\Win64;%PATH% -------------------------------------------------------------------------------- /src/umock_lock_factory_pthread.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | 7 | #include "macro_utils/macro_utils.h" 8 | 9 | #include "umock_c/umockalloc.h" 10 | #include "umock_c/umock_log.h" 11 | #include "umock_c/umock_lock_if.h" // for UMOCK_C_LOCK_HANDLE 12 | #include "umock_c/umock_lock_factory_default.h" 13 | 14 | typedef struct UMOCK_C_LOCK_PTHREAD_TAG 15 | { 16 | UMOCK_C_LOCK_IF lock_if; 17 | pthread_rwlock_t rw_lock; 18 | } UMOCK_C_LOCK_PTHREAD; 19 | 20 | static void umock_lock_pthreads_acquire_shared(UMOCK_C_LOCK_HANDLE lock) 21 | { 22 | if (lock == NULL) 23 | { 24 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_010: [ If lock is NULL, umock_lock_pthread_acquire_shared shall return. ]*/ 25 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 26 | } 27 | else 28 | { 29 | UMOCK_C_LOCK_PTHREAD* umock_c_lock_pthread = (UMOCK_C_LOCK_PTHREAD*)lock; 30 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_005: [ umock_lock_pthread_acquire_shared shall acquire the read lock by calling pthread_rwlock_rdlock. ]*/ 31 | if (pthread_rwlock_rdlock(&umock_c_lock_pthread->rw_lock) != 0) 32 | { 33 | UMOCK_LOG("pthread_rwlock_rdlock failed"); 34 | } 35 | } 36 | } 37 | 38 | static void umock_lock_pthreads_release_shared(UMOCK_C_LOCK_HANDLE lock) 39 | { 40 | if (lock == NULL) 41 | { 42 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_011: [ If lock is NULL, umock_lock_pthread_release_shared shall return. ]*/ 43 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 44 | } 45 | else 46 | { 47 | UMOCK_C_LOCK_PTHREAD* umock_c_lock_pthread = (UMOCK_C_LOCK_PTHREAD*)lock; 48 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_006: [ umock_lock_pthread_release_shared shall release the lock that was acquired in shared mode by calling pthread_rwlock_unlock. ]*/ 49 | if (pthread_rwlock_unlock(&umock_c_lock_pthread->rw_lock) != 0) 50 | { 51 | UMOCK_LOG("pthread_rwlock_unlock failed"); 52 | } 53 | } 54 | } 55 | 56 | static void umock_lock_pthreads_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock) 57 | { 58 | if (lock == NULL) 59 | { 60 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_012: [ If lock is NULL, umock_lock_pthread_acquire_exclusive shall return. ]*/ 61 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 62 | } 63 | else 64 | { 65 | UMOCK_C_LOCK_PTHREAD* umock_c_lock_pthread = (UMOCK_C_LOCK_PTHREAD*)lock; 66 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_007: [ umock_lock_pthread_acquire_exclusive shall acquire the lock in exclusive mode by calling pthread_rwlock_wrlock. ]*/ 67 | if (pthread_rwlock_wrlock(&umock_c_lock_pthread->rw_lock) != 0) 68 | { 69 | UMOCK_LOG("pthread_rwlock_rdlock failed"); 70 | } 71 | } 72 | } 73 | 74 | static void umock_lock_pthreads_release_exclusive(UMOCK_C_LOCK_HANDLE lock) 75 | { 76 | if (lock == NULL) 77 | { 78 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_013: [ If lock is NULL, umock_lock_pthread_release_exclusive shall return. ]*/ 79 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 80 | } 81 | else 82 | { 83 | UMOCK_C_LOCK_PTHREAD* umock_c_lock_pthread = (UMOCK_C_LOCK_PTHREAD*)lock; 84 | if (pthread_rwlock_unlock(&umock_c_lock_pthread->rw_lock) != 0) 85 | { 86 | UMOCK_LOG("pthread_rwlock_unlock failed"); 87 | } 88 | } 89 | } 90 | 91 | static void umock_lock_pthreads_destroy(UMOCK_C_LOCK_HANDLE lock) 92 | { 93 | if (lock == NULL) 94 | { 95 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_014: [ If lock is NULL, umock_lock_pthread_destroy shall return. ]*/ 96 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 97 | } 98 | else 99 | { 100 | UMOCK_C_LOCK_PTHREAD* umock_c_lock_pthread = (UMOCK_C_LOCK_PTHREAD*)lock; 101 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_001: [ umock_lock_pthread_destroy shall release the resources for the pthread lock by calling pthread_rwlock_destroy. ]*/ 102 | if (pthread_rwlock_destroy(&umock_c_lock_pthread->rw_lock) != 0) 103 | { 104 | UMOCK_LOG("pthread_rwlock_destroy failed"); 105 | } 106 | 107 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_009: [ umock_lock_pthread_destroy shall free the memory associated with the lock. ]*/ 108 | umockalloc_free(umock_c_lock_pthread); 109 | } 110 | } 111 | 112 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params) 113 | { 114 | (void)params; 115 | 116 | UMOCK_C_LOCK_HANDLE result; 117 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_001: [ umock_lock_factory_create_lock shall allocate memory for the lock. ]*/ 118 | UMOCK_C_LOCK_PTHREAD* rw_lock_pthreads = umockalloc_malloc(sizeof(UMOCK_C_LOCK_PTHREAD)); 119 | if (rw_lock_pthreads == NULL) 120 | { 121 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_004: [ If any error occurs, umock_lock_factory_create_lock shall fail and return NULL. ]*/ 122 | UMOCK_LOG("umockalloc_malloc(%zu) failed", sizeof(UMOCK_C_LOCK_PTHREAD)); 123 | } 124 | else 125 | { 126 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_003: [ umock_lock_factory_create_lock shall return a lock handle that has the function pointers set to umock_lock_pthread_acquire_shared, umock_lock_pthread_release_shared, umock_lock_pthread_acquire_exclusive, umock_lock_pthread_release_exclusive and umock_lock_pthread_destroy. ]*/ 127 | rw_lock_pthreads->lock_if.acquire_shared = umock_lock_pthreads_acquire_shared; 128 | rw_lock_pthreads->lock_if.release_shared = umock_lock_pthreads_release_shared; 129 | rw_lock_pthreads->lock_if.acquire_exclusive = umock_lock_pthreads_acquire_exclusive; 130 | rw_lock_pthreads->lock_if.release_exclusive = umock_lock_pthreads_release_exclusive; 131 | rw_lock_pthreads->lock_if.destroy = umock_lock_pthreads_destroy; 132 | 133 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_002: [] umock_lock_factory_create_lock shall initialize a pthread RW lock that is encapsulated by the new UMOCK_C_LOCK_HANDLE. ]*/ 134 | if (pthread_rwlock_init(&rw_lock_pthreads->rw_lock, NULL) != 0) 135 | { 136 | /* Codes_SRS_UMOCK_LOCK_FACTORY_PTHREAD_01_004: [ If any error occurs, umock_lock_factory_create_lock shall fail and return NULL. ]*/ 137 | UMOCK_LOG("pthread_rwlock_init failed"); 138 | } 139 | else 140 | { 141 | result = &rw_lock_pthreads->lock_if; 142 | goto all_ok; 143 | } 144 | 145 | umockalloc_free(rw_lock_pthreads); 146 | } 147 | 148 | result = NULL; 149 | 150 | all_ok: 151 | return result; 152 | } 153 | -------------------------------------------------------------------------------- /src/umock_lock_factory_windows.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include // for NULL 5 | 6 | #include "windows.h" 7 | 8 | #include "umock_c/umockalloc.h" 9 | #include "umock_c/umock_log.h" 10 | #include "umock_c/umock_lock_if.h" // for UMOCK_C_LOCK_HANDLE 11 | #include "umock_c/umock_lock_factory_default.h" 12 | 13 | typedef struct UMOCK_C_LOCK_WINDOWS_TAG 14 | { 15 | UMOCK_C_LOCK_IF lock_if; 16 | SRWLOCK srw_lock; 17 | } UMOCK_C_LOCK_WINDOWS; 18 | 19 | static void umock_lock_windows_acquire_shared(UMOCK_C_LOCK_HANDLE lock) 20 | { 21 | if (lock == NULL) 22 | { 23 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_010: [ If lock is NULL, umock_lock_windows_acquire_shared shall return. ]*/ 24 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 25 | } 26 | else 27 | { 28 | UMOCK_C_LOCK_WINDOWS* wmock_c_lock_windows = (UMOCK_C_LOCK_WINDOWS*)lock; 29 | 30 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_005: [ umock_lock_windows_acquire_shared shall acquire the lock in shared mode by calling AcquireSRWLockShared. ]*/ 31 | AcquireSRWLockShared(&wmock_c_lock_windows->srw_lock); 32 | } 33 | } 34 | 35 | static void umock_lock_windows_release_shared(UMOCK_C_LOCK_HANDLE lock) 36 | { 37 | if (lock == NULL) 38 | { 39 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_011: [ If lock is NULL, umock_lock_windows_release_shared shall return. ]*/ 40 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 41 | } 42 | else 43 | { 44 | UMOCK_C_LOCK_WINDOWS* wmock_c_lock_windows = (UMOCK_C_LOCK_WINDOWS*)lock; 45 | 46 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_006: [ umock_lock_windows_release_shared shall release the lock that was acquired in shared mode by calling ReleaseSRWLockShared. ]*/ 47 | ReleaseSRWLockShared(&wmock_c_lock_windows->srw_lock); 48 | } 49 | } 50 | 51 | static void umock_lock_windows_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock) 52 | { 53 | if (lock == NULL) 54 | { 55 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_012: [ If lock is NULL, umock_lock_windows_acquire_exclusive shall return. ]*/ 56 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 57 | } 58 | else 59 | { 60 | UMOCK_C_LOCK_WINDOWS* wmock_c_lock_windows = (UMOCK_C_LOCK_WINDOWS*)lock; 61 | 62 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_007: [ umock_lock_windows_acquire_exclusive shall acquire the lock in exclusive mode by calling AcquireSRWLockExclusive. ]*/ 63 | AcquireSRWLockExclusive(&wmock_c_lock_windows->srw_lock); 64 | } 65 | } 66 | 67 | static void umock_lock_windows_release_exclusive(UMOCK_C_LOCK_HANDLE lock) 68 | { 69 | if (lock == NULL) 70 | { 71 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_013: [ If lock is NULL, umock_lock_windows_release_exclusive shall return. ]*/ 72 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 73 | } 74 | else 75 | { 76 | UMOCK_C_LOCK_WINDOWS* wmock_c_lock_windows = (UMOCK_C_LOCK_WINDOWS*)lock; 77 | 78 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_008: [ umock_lock_windows_release_exclusive shall release the lock that was acquired in exclusive mode by calling ReleaseSRWLockExclusive. ]*/ 79 | ReleaseSRWLockExclusive(&wmock_c_lock_windows->srw_lock); 80 | } 81 | } 82 | 83 | static void umock_lock_windows_destroy(UMOCK_C_LOCK_HANDLE lock) 84 | { 85 | if (lock == NULL) 86 | { 87 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_014: [ If lock is NULL, umock_lock_windows_destroy shall return. ]*/ 88 | UMOCK_LOG("Invalid arguments: UMOCK_C_LOCK_HANDLE lock=%p", lock); 89 | } 90 | else 91 | { 92 | UMOCK_C_LOCK_WINDOWS* wmock_c_lock_windows = (UMOCK_C_LOCK_WINDOWS*)lock; 93 | 94 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_009: [ umock_lock_windows_destroy shall free the memory associated with the lock. ]*/ 95 | umockalloc_free(wmock_c_lock_windows); 96 | } 97 | } 98 | 99 | UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params) 100 | { 101 | (void)params; 102 | 103 | UMOCK_C_LOCK_HANDLE result; 104 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_001: [ umock_lock_factory_create_lock shall allocate memory for the lock. ]*/ 105 | UMOCK_C_LOCK_WINDOWS* srw_lock_windows = umockalloc_malloc(sizeof(UMOCK_C_LOCK_WINDOWS)); 106 | if (srw_lock_windows == NULL) 107 | { 108 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_004: [ If any error occurs, umock_lock_factory_create_lock shall fail and return NULL. ]*/ 109 | UMOCK_LOG("umockalloc_malloc(%zu) failed", sizeof(UMOCK_C_LOCK_WINDOWS)); 110 | result = NULL; 111 | } 112 | else 113 | { 114 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_003: [ umock_lock_factory_create_lock shall return a lock handle that has the function pointers set to umock_lock_windows_acquire_shared, umock_lock_windows_release_shared, umock_lock_windows_acquire_exclusive, umock_lock_windows_release_exclusive and umock_lock_windows_destroy. ]*/ 115 | srw_lock_windows->lock_if.acquire_shared = umock_lock_windows_acquire_shared; 116 | srw_lock_windows->lock_if.release_shared = umock_lock_windows_release_shared; 117 | srw_lock_windows->lock_if.acquire_exclusive = umock_lock_windows_acquire_exclusive; 118 | srw_lock_windows->lock_if.release_exclusive = umock_lock_windows_release_exclusive; 119 | srw_lock_windows->lock_if.destroy = umock_lock_windows_destroy; 120 | 121 | /* Codes_SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_002: [ umock_lock_factory_create_lock shall initialize a SRW lock that is encapsulated by the new UMOCK_C_LOCK_HANDLE. ]*/ 122 | InitializeSRWLock(&srw_lock_windows->srw_lock); 123 | 124 | result = &srw_lock_windows->lock_if; 125 | } 126 | 127 | return result; 128 | } 129 | -------------------------------------------------------------------------------- /src/umockalloc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | #include 7 | #include "umock_c/umockalloc.h" 8 | 9 | void* umockalloc_malloc(size_t size) 10 | { 11 | /* Codes_SRS_UMOCKALLOC_01_001: [ umockalloc_malloc shall call malloc, while passing the size argument to malloc. ] */ 12 | /* Codes_SRS_UMOCKALLOC_01_002: [ umockalloc_malloc shall return the result of malloc. ]*/ 13 | return malloc(size); 14 | } 15 | 16 | void* umockalloc_calloc(size_t nmemb, size_t size) 17 | { 18 | /* Codes_SRS_UMOCKALLOC_09_001: [ umockalloc_calloc shall call calloc, while passing the nmemb and size arguments to calloc. ] */ 19 | /* Codes_SRS_UMOCKALLOC_09_002: [ umockalloc_calloc shall return the result of calloc. ]*/ 20 | return calloc(nmemb, size); 21 | } 22 | 23 | void* umockalloc_realloc(void* ptr, size_t size) 24 | { 25 | /* Codes_SRS_UMOCKALLOC_01_003: [ umockalloc_realloc shall call realloc, while passing the ptr and size arguments to realloc. ] */ 26 | /* Codes_SRS_UMOCKALLOC_01_004: [ umockalloc_realloc shall return the result of realloc. ]*/ 27 | return realloc(ptr, size); 28 | } 29 | 30 | void umockalloc_free(void* ptr) 31 | { 32 | /* Codes_SRS_UMOCKALLOC_01_005: [ umockalloc_free shall call free, while passing the ptr argument to free. ]*/ 33 | free(ptr); 34 | } 35 | 36 | char* umockc_stringify_buffer(const void* bytes, size_t length) 37 | { 38 | size_t string_length = 2 + (4 * length); 39 | char* result; 40 | if (length > 1) 41 | { 42 | string_length += length - 1; 43 | } 44 | 45 | result = (char*)umockalloc_malloc(string_length + 1); 46 | if (result != NULL) 47 | { 48 | size_t i; 49 | 50 | result[0] = '['; 51 | for (i = 0; i < length; i++) 52 | { 53 | if (sprintf(result + 1 + (i * 5), "0x%02X ", ((const unsigned char*)bytes)[i]) < 0) 54 | { 55 | break; 56 | } 57 | } 58 | 59 | if (i < length) 60 | { 61 | umockalloc_free(result); 62 | result = NULL; 63 | } 64 | else 65 | { 66 | result[string_length - 1] = ']'; 67 | result[string_length] = '\0'; 68 | } 69 | } 70 | 71 | return result; 72 | } 73 | -------------------------------------------------------------------------------- /src/umockstring.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | 7 | #include "macro_utils/macro_utils.h" 8 | 9 | #include "umock_c/umockalloc.h" 10 | #include "umock_c/umockstring.h" 11 | #include "umock_c/umock_log.h" 12 | 13 | char* umockstring_clone(const char* source) 14 | { 15 | char* result; 16 | 17 | if (source == NULL) 18 | { 19 | /* Codes_UMOCK_STRING_01_005: [ If umockstring_clone is called with a NULL source, it shall return NULL. ]*/ 20 | UMOCK_LOG("umockstring_clone called with NULL source"); 21 | result = NULL; 22 | } 23 | else 24 | { 25 | size_t string_length = strlen(source); 26 | 27 | /* Codes_UMOCK_STRING_01_001: [ umockstring_clone shall allocate memory for the cloned string (including the NULL terminator). ]*/ 28 | /* Codes_UMOCK_STRING_01_003: [ On success umockstring_clone shall return a pointer to the newly allocated memory containing the copy of the string. ]*/ 29 | result = (char*)umockalloc_malloc(string_length + 1); 30 | if (result == NULL) 31 | { 32 | /* Codes_UMOCK_STRING_01_004: [ If allocating the memory fails, umockstring_clone shall return NULL. ]*/ 33 | UMOCK_LOG("Error allocating memory for string clone"); 34 | } 35 | else 36 | { 37 | /* Codes_UMOCK_STRING_01_002: [ umockstring_clone shall copy the string to the newly allocated memory (including the NULL terminator). ]*/ 38 | (void)memcpy(result, source, string_length + 1); 39 | } 40 | } 41 | 42 | return result; 43 | } 44 | -------------------------------------------------------------------------------- /src/umocktypename.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | 7 | #include "macro_utils/macro_utils.h" 8 | 9 | #include "umock_c/umocktypename.h" 10 | #include "umock_c/umockalloc.h" 11 | #include "umock_c/umock_log.h" 12 | 13 | char* umocktypename_normalize(const char* type_name) 14 | { 15 | char* result; 16 | 17 | if (type_name == NULL) 18 | { 19 | /* Codes_SRS_UMOCKTYPENAME_01_005: [ If typename is NULL, then umocktypename_normalize shall fail and return NULL. ]*/ 20 | UMOCK_LOG("umocktypename: NULL type_name."); 21 | result = NULL; 22 | } 23 | else 24 | { 25 | size_t length = 0; 26 | size_t pos = 0; 27 | size_t last_pos; 28 | 29 | /* we first compute how much space we need for the normalized version ... */ 30 | while (type_name[pos] != '\0') 31 | { 32 | last_pos = pos; 33 | 34 | /* find all the spaces first */ 35 | while ((type_name[pos] != '\0') && (isspace(type_name[pos]))) 36 | { 37 | pos++; 38 | } 39 | 40 | /* we got a bunch of spaces, figure out whether we need to add any spaces to the normalized type name or not */ 41 | /* Codes_SRS_UMOCKTYPENAME_01_002: [ umocktypename_normalize shall remove all spaces at the beginning of the typename. ]*/ 42 | /* Codes_SRS_UMOCKTYPENAME_01_003: [ umocktypename_normalize shall remove all spaces at the end of the typename. ] */ 43 | /* Codes_SRS_UMOCKTYPENAME_01_006: [ No space shall exist between any other token and a star. ]*/ 44 | if ((last_pos == 0) || 45 | (type_name[pos] == '\0') || 46 | (type_name[last_pos - 1] == '*') || 47 | (type_name[pos] == '*')) 48 | { 49 | /* do not add any spaces */ 50 | } 51 | else 52 | { 53 | /* add one space */ 54 | /* Codes_SRS_UMOCKTYPENAME_01_004: [ umocktypename_normalize shall remove all extra spaces (more than 1 space) between elements that are part of the typename. ]*/ 55 | length ++; 56 | } 57 | 58 | /* found something that is a non-space character, add to the normalized type name */ 59 | while ((type_name[pos] != '\0') && (!isspace(type_name[pos]))) 60 | { 61 | pos++; 62 | length++; 63 | } 64 | } 65 | 66 | if (length == 0) 67 | { 68 | /* Codes_SRS_UMOCKTYPENAME_01_007: [ If the length of the normalized typename is 0, umocktypename_normalize shall return NULL. ]*/ 69 | UMOCK_LOG("umocktypename: 0 length for the normalized type name."); 70 | result = NULL; 71 | } 72 | else 73 | { 74 | /* ... then we allocate*/ 75 | /* Codes_SRS_UMOCKTYPENAME_01_001: [ umocktypename_normalize shall return a char\* with a newly allocated string that contains the normalized typename. ]*/ 76 | result = (char*)umockalloc_malloc(length + 1); 77 | /* Codes_SRS_UMOCKTYPENAME_01_008: [ If allocating memory fails, umocktypename_normalize shall fail and return NULL. ]*/ 78 | if (result != NULL) 79 | { 80 | pos = 0; 81 | length = 0; 82 | (void)last_pos; 83 | 84 | while (type_name[pos] != '\0') 85 | { 86 | last_pos = pos; 87 | 88 | /* find all the spaces first */ 89 | while ((type_name[pos] != '\0') && (isspace(type_name[pos]))) 90 | { 91 | pos++; 92 | } 93 | 94 | /* we got a bunch of spaces, figure out whether we need to add any spaces to the normalized type name or not */ 95 | /* Codes_SRS_UMOCKTYPENAME_01_002: [ umocktypename_normalize shall remove all spaces at the beginning of the typename. ]*/ 96 | /* Codes_SRS_UMOCKTYPENAME_01_003: [ umocktypename_normalize shall remove all spaces at the end of the typename. ] */ 97 | /* Codes_SRS_UMOCKTYPENAME_01_006: [ No space shall exist between any other token and a star. ]*/ 98 | if ((last_pos == 0) || 99 | (type_name[pos] == '\0') || 100 | (type_name[last_pos - 1] == '*') || 101 | (type_name[pos] == '*')) 102 | { 103 | /* do not add any spaces */ 104 | } 105 | else 106 | { 107 | /* add one space */ 108 | /* Codes_SRS_UMOCKTYPENAME_01_004: [ umocktypename_normalize shall remove all extra spaces (more than 1 space) between elements that are part of the typename. ]*/ 109 | result[length++] = ' '; 110 | } 111 | 112 | /* found something that is a non-space character, add to the normalized type name */ 113 | while ((type_name[pos] != '\0') && (!isspace(type_name[pos]))) 114 | { 115 | result[length++] = type_name[pos++]; 116 | } 117 | } 118 | 119 | result[length] = '\0'; 120 | } 121 | } 122 | } 123 | 124 | return result; 125 | } 126 | -------------------------------------------------------------------------------- /src/umocktypes_bool.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "macro_utils/macro_utils.h" 9 | 10 | #include "umock_c/umock_log.h" 11 | #include "umock_c/umockalloc.h" 12 | #include "umock_c/umocktypes.h" 13 | 14 | #include "umock_c/umocktypes_bool.h" 15 | 16 | /* Codes_SRS_UMOCKTYPES_BOOL_01_002: [ umocktypes_stringify_bool shall return the string representation of value. ]*/ 17 | char* umocktypes_stringify_bool(const bool* value) 18 | { 19 | char* result; 20 | 21 | /* Codes_SRS_UMOCKTYPES_BOOL_01_003: [ If value is NULL, umocktypes_stringify_bool shall return NULL. ]*/ 22 | if (value == NULL) 23 | { 24 | UMOCK_LOG("umocktypes_stringify_bool: NULL value."); 25 | result = NULL; 26 | } 27 | else 28 | { 29 | const char* stringified_bool = *value ? "true" : "false"; 30 | size_t length = strlen(stringified_bool); 31 | 32 | result = (char*)umockalloc_malloc(length + 1); 33 | if (result == NULL) 34 | { 35 | /* Codes_SRS_UMOCKTYPES_BOOL_01_004: [ If allocating a new string to hold the string representation fails, umocktypes_stringify_bool shall return NULL. ]*/ 36 | UMOCK_LOG("umocktypes_stringify_bool: Cannot allocate memory for result."); 37 | } 38 | else 39 | { 40 | (void)memcpy(result, stringified_bool, length + 1); 41 | } 42 | } 43 | return result; 44 | } 45 | 46 | /* Codes_SRS_UMOCKTYPES_BOOL_01_006: [ umocktypes_are_equal_bool shall compare the 2 chars pointed to by left and right. ]*/ 47 | int umocktypes_are_equal_bool(const bool* left, const bool* right) 48 | { 49 | int result; 50 | 51 | if ((left == NULL) || (right == NULL)) 52 | { 53 | /* Codes_SRS_UMOCKTYPES_BOOL_01_007: [ If any of the arguments is NULL, umocktypes_are_equal_bool shall return -1. ]*/ 54 | UMOCK_LOG("umocktypes_are_equal_bool: Bad arguments:left = %p, right = %p.", left, right); 55 | result = -1; 56 | } 57 | else 58 | { 59 | /* Codes_SRS_UMOCKTYPES_BOOL_01_009: [ If the values pointed to by left and right are different, umocktypes_are_equal_bool shall return 0. ]*/ 60 | /* Codes_SRS_UMOCKTYPES_BOOL_01_008: [ If the values pointed to by left and right are equal, umocktypes_are_equal_bool shall return 1. ]*/ 61 | result = ((*left) == (*right)) ? 1 : 0; 62 | } 63 | 64 | return result; 65 | } 66 | 67 | /* Codes_SRS_UMOCKTYPES_BOOL_01_010: [ umocktypes_copy_bool shall copy the bool value from source to destination. ]*/ 68 | int umocktypes_copy_bool(bool* destination, const bool* source) 69 | { 70 | int result; 71 | 72 | if ((destination == NULL) || 73 | (source == NULL)) 74 | { 75 | /* Codes_SRS_UMOCKTYPES_BOOL_01_012: [ If source or destination are NULL, umocktypes_copy_bool shall return a non-zero value. ]*/ 76 | UMOCK_LOG("umocktypes_copy_bool: Bad arguments:destination = %p, source = %p.", destination, source); 77 | result = __LINE__; 78 | } 79 | else 80 | { 81 | *destination = *source; 82 | 83 | /* Codes_SRS_UMOCKTYPES_BOOL_01_011: [ On success umocktypes_copy_bool shall return 0. ]*/ 84 | result = 0; 85 | } 86 | return result; 87 | } 88 | 89 | /* Codes_SRS_UMOCKTYPES_BOOL_01_013: [ umocktypes_free_bool shall do nothing. ]*/ 90 | void umocktypes_free_bool(bool* value) 91 | { 92 | (void)value; 93 | } 94 | 95 | int umocktypes_bool_register_types(void) 96 | { 97 | int result; 98 | 99 | /* Codes_SRS_UMOCKTYPES_BOOL_01_001: [ umocktypes_bool_register_types shall register support for all the types in the module. ]*/ 100 | if ((umocktypes_register_type("bool", (UMOCKTYPE_STRINGIFY_FUNC)umocktypes_stringify_bool, (UMOCKTYPE_ARE_EQUAL_FUNC)umocktypes_are_equal_bool, (UMOCKTYPE_COPY_FUNC)umocktypes_copy_bool, (UMOCKTYPE_FREE_FUNC)umocktypes_free_bool) != 0) || 101 | (umocktypes_register_type("_Bool", (UMOCKTYPE_STRINGIFY_FUNC)umocktypes_stringify_bool, (UMOCKTYPE_ARE_EQUAL_FUNC)umocktypes_are_equal_bool, (UMOCKTYPE_COPY_FUNC)umocktypes_copy_bool, (UMOCKTYPE_FREE_FUNC)umocktypes_free_bool) != 0)) 102 | { 103 | /* Codes_SRS_UMOCKTYPES_BOOL_01_015: [ If registering any of the types fails, umocktypes_bool_register_types shall fail and return a non-zero value. ]*/ 104 | UMOCK_LOG("umocktypes_bool_register_types: Cannot register types."); 105 | result = __LINE__; 106 | } 107 | else 108 | { 109 | /* Codes_SRS_UMOCKTYPES_BOOL_01_014: [ On success, umocktypes_bool_register_types shall return 0. ]*/ 110 | result = 0; 111 | } 112 | 113 | return result; 114 | } 115 | -------------------------------------------------------------------------------- /src/umocktypes_windows.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | 7 | #include "windows.h" 8 | 9 | #include "macro_utils/macro_utils.h" 10 | 11 | #include "umock_c/umock_c.h" 12 | #include "umock_c/umocktypes_charptr.h" 13 | #include "umock_c/umocktypes_wcharptr.h" 14 | #include "umock_c/umocktypes_stdint.h" 15 | #include "umock_c/umocktypes_windows.h" 16 | #include "umock_c/umock_log.h" 17 | 18 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_001: [ LONG as an alias of long. ]*/ 19 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_002: [ LONGLONG as an alias of long long. ]*/ 20 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_003: [ DWORD as an alias of unsigned long. ]*/ 21 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_004: [ HRESULT as an alias of LONG. ]*/ 22 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_025: [ BOOL as an alias of int. ]*/ 23 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_007: [ PVOID as an alias of void*. ]*/ 24 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_008: [ LPCSTR as an alias of const char*. ]*/ 25 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_010: [ LPSECURITY_ATTRIBUTES as an alias of void*. ]*/ 26 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_011: [ HANDLE as an alias of void*. ]*/ 27 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_012: [ UCHAR as an alias of unsigned char. ]*/ 28 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_013: [ PTP_POOL as an alias of void*. ]*/ 29 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_014: [ PTP_CLEANUP_GROUP as an alias of void*. ]*/ 30 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_015: [ PTP_CALLBACK_ENVIRON as an alias of void*. ]*/ 31 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_016: [ PTP_CLEANUP_GROUP_CANCEL_CALLBACK as an alias of void*. ]*/ 32 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_017: [ PTP_IO as an alias of void*. ]*/ 33 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_018: [ PTP_WIN32_IO_CALLBACK as an alias of void*. ]*/ 34 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_019: [ PTP_WORK_CALLBACK as an alias of void*. ]*/ 35 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_020: [ PTP_WORK as an alias of void*. ]*/ 36 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_021: [ LPCVOID as an alias of void*. ]*/ 37 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_022: [ LPDWORD as an alias of void*. ]*/ 38 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_023: [ LPOVERLAPPED as an alias of void*. ]*/ 39 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_024: [ LPVOID as an alias of void*. ]*/ 40 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_027: [ PTP_SIMPLE_CALLBACK as an alias of void*. ]*/ 41 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_028: [ LPLONG as an alias of void*. ]*/ 42 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_029: [ BYTE as an alias of unsigned char. ]*/ 43 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_030: [ BOOLEAN as an alias of BYTE. ]*/ 44 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_031: [ ULONG as an alias of unsigned long. ]*/ 45 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_032: [ LPCWSTR as an alias of const wchar_t*. ]*/ 46 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_034: [ LONG64 as an alias of int64_t. ]*/ 47 | /* Codes_SRS_UMOCKTYPES_WINDOWS_43_036: [ SHORT as an alias of int16_t. ]*/ 48 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_036: [ SIZE_T as an alias of size_t. ]*/ 49 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_037: [ PSIZE_T as an alias of void*. ]*/ 50 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_038: [ PHANDLE as an alias of void*. ]*/ 51 | #define WINDOWS_TYPES_ALIAS_PAIRS \ 52 | LONG, long, \ 53 | LONGLONG, long long, \ 54 | DWORD, unsigned long, \ 55 | HRESULT, LONG, \ 56 | BOOL, int, \ 57 | PVOID, void*, \ 58 | LPCSTR, const char*, \ 59 | LPSECURITY_ATTRIBUTES, void*, \ 60 | HANDLE, void*, \ 61 | UCHAR, unsigned char, \ 62 | PTP_POOL, void*, \ 63 | PTP_CLEANUP_GROUP, void*, \ 64 | PTP_CALLBACK_ENVIRON, void*, \ 65 | PTP_CLEANUP_GROUP_CANCEL_CALLBACK, void*, \ 66 | PTP_IO, void*, \ 67 | PTP_WIN32_IO_CALLBACK, void*, \ 68 | PTP_WORK_CALLBACK, void*, \ 69 | PTP_WORK, void*, \ 70 | LPCVOID, void*, \ 71 | LPDWORD, void*, \ 72 | LPOVERLAPPED, void*, \ 73 | LPVOID, void*, \ 74 | PTP_SIMPLE_CALLBACK, void*, \ 75 | LPLONG, void*, \ 76 | BYTE, unsigned char, \ 77 | BOOLEAN, BYTE, \ 78 | ULONG, unsigned long, \ 79 | LPCWSTR, const wchar_t*, \ 80 | LONG64, int64_t ,\ 81 | SHORT, int16_t, \ 82 | SIZE_T, size_t, \ 83 | PSIZE_T, void*, \ 84 | PHANDLE, void* \ 85 | 86 | #define REGISTER_ALIAS_PAIR(alias_pair_type, alias_pair_is_type) \ 87 | if ( \ 88 | (result == 0) && \ 89 | (UMOCK_INTERNAL_REGISTER_ALIAS_TYPE(alias_pair_type, alias_pair_is_type) != 0) \ 90 | ) \ 91 | { \ 92 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_006: [ If registering any of the types fails, umocktypes_windows_register_types shall fail and return a non-zero value. ]*/ \ 93 | UMOCK_LOG("umocktypes_register_alias_type failed for " MU_TOSTRING(alias_pair_type)); \ 94 | result = MU_FAILURE; \ 95 | } 96 | 97 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_001: [ The following Windows types shall be supported out of the box, aliased to their underlying types: ]*/ 98 | int umocktypes_windows_register_types(void) 99 | { 100 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_005: [ On success, umocktypes_windows_register_types shall return 0. ]*/ 101 | int result; 102 | 103 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_026: [ umocktypes_windows_register_types shall register the charptr types by calling umocktypes_charptr_register_types. ]*/ 104 | if (umocktypes_charptr_register_types() != 0) 105 | { 106 | UMOCK_LOG("umocktypes_charptr_register_types failed"); 107 | result = MU_FAILURE; 108 | } 109 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_033: [ umocktypes_windows_register_types shall register the wcharptr types by calling umocktypes_wcharptr_register_types. ]*/ 110 | else if (umocktypes_wcharptr_register_types() != 0) 111 | { 112 | UMOCK_LOG("umocktypes_wcharptr_register_types failed"); 113 | result = MU_FAILURE; 114 | } 115 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_035: [ umocktypes_windows_register_types shall register the stdint types by calling umocktypes_stdint_register_types. ]*/ 116 | else if (umocktypes_stdint_register_types() != 0) 117 | { 118 | UMOCK_LOG("umocktypes_stdint_register_types failed"); 119 | result = MU_FAILURE; 120 | } 121 | else 122 | { 123 | result = 0; 124 | 125 | /* Codes_SRS_UMOCKTYPES_WINDOWS_01_009: [ umocktypes_windows_register_types shall register support for the following alias types: ]*/ 126 | MU_FOR_EACH_2(REGISTER_ALIAS_PAIR, WINDOWS_TYPES_ALIAS_PAIRS); 127 | } 128 | 129 | return result; 130 | } 131 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #build_yet is a boolean variable that is used in the CMakelists.txt of umock_c_2_int. 5 | #it is used to prohibit generating more than 1 times the project umock_c_2_mock_pp which is intended to be generated only once. 6 | set(build_yet FALSE) 7 | 8 | #unit tests 9 | if(${run_unittests}) 10 | build_test_folder(umockalloc_ut) 11 | build_test_folder(umockstring_ut) 12 | build_test_folder(umockautoignoreargs_ut) 13 | build_test_folder(umockcall_ut) 14 | build_test_folder(umockcallpairs_ut) 15 | build_test_folder(umockcallrecorder_ut) 16 | build_test_folder(umock_c_ut) 17 | build_test_folder(umock_c_wout_init_ut) 18 | build_test_folder(umocktypename_ut) 19 | build_test_folder(umocktypes_ut) 20 | build_test_folder(umocktypes_c_fixed_buffer_ut) 21 | build_test_folder(umocktypes_wout_init_ut) 22 | build_test_folder(umocktypes_bool_ut) 23 | build_test_folder(umocktypes_c_ut) 24 | build_test_folder(umocktypes_charptr_ut) 25 | build_test_folder(umocktypes_stdint_ut) 26 | build_test_folder(umocktypes_wcharptr_ut) 27 | build_test_folder(umock_c_negt_noini_ut) 28 | build_test_folder(umock_c_negt_ut) 29 | 30 | if(WIN32) 31 | build_test_folder(umock_lock_factory_windows_ut) 32 | build_test_folder(umocktypes_windows_ut) 33 | endif() 34 | if(UNIX) 35 | build_test_folder(umock_lock_factory_pthread_ut) 36 | endif() 37 | endif() 38 | 39 | #int tests 40 | if(${run_int_tests}) 41 | build_test_folder(umock_c_int) 42 | build_test_folder(umock_c_reals_int) 43 | build_test_folder(umock_c_mock_filters_int) 44 | build_test_folder(umock_c_negt_int) 45 | build_test_folder(umock_c_gen_func_decl_int) 46 | build_test_folder(umock_c_malloc_hook_int) 47 | build_test_folder(umock_c_ptrarg_leak_int) 48 | build_test_folder(umocktypes_struct_int) 49 | if((WIN32) OR (UNIX)) 50 | build_test_folder(umock_c_with_lock_factory_int) 51 | endif() 52 | 53 | if(WIN32) 54 | build_test_folder(umock_c_windows_types_int) 55 | build_test_folder(umock_c_reg_win_types_int) 56 | endif() 57 | endif() -------------------------------------------------------------------------------- /tests/umock_c_gen_func_decl_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_gen_func_decl_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_gen_func_decl_int.c 8 | umock_c_gen_func_multiple_inc.c 9 | ) 10 | 11 | set(${theseTestsName}_c_files 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 18 | -------------------------------------------------------------------------------- /tests/umock_c_gen_func_decl_int/umock_c_gen_func_decl_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "testrunnerswitcher.h" 5 | 6 | #include "umock_c/umock_c_prod.h" // for MOCKABLE_FUNCTION, MOCKABLE_FUNCTI... 7 | 8 | MOCKABLE_FUNCTION(, int, test_generate_signature, int, a, double, b, char*, s); 9 | MOCKABLE_FUNCTION(, void, test_generate_signature_void_return, int, a); 10 | MOCKABLE_FUNCTION(, void, test_generate_signature_no_args); 11 | MOCKABLE_FUNCTION_WITH_RETURNS(, int, test_generate_signature_with_returns, int, a, double, b, char*, s)(42, 43); 12 | MOCKABLE_FUNCTION_WITH_RETURNS(, int, test_generate_signature_no_args_with_returns)(42, 43); 13 | MOCKABLE_FUNCTION_WITH_RETURNS(, void*, test_generate_signature_with_returns_returning_ptr)((void*)0x4243, NULL); 14 | 15 | int test_generate_signature(int a, double b, char* s) 16 | { 17 | (void)a; 18 | (void)b; 19 | (void)s; 20 | return 42; 21 | } 22 | 23 | void test_generate_signature_void_return(int a) 24 | { 25 | (void)a; 26 | } 27 | 28 | void test_generate_signature_no_args(void) 29 | { 30 | } 31 | 32 | int test_generate_signature_with_returns(int a, double b, char* s) 33 | { 34 | (void)a; 35 | (void)b; 36 | (void)s; 37 | return 42; 38 | } 39 | 40 | int test_generate_signature_no_args_with_returns(void) 41 | { 42 | return 42; 43 | } 44 | 45 | void* test_generate_signature_with_returns_returning_ptr(void) 46 | { 47 | return (void*)0x4242; 48 | } 49 | 50 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 51 | 52 | TEST_SUITE_INITIALIZE(suite_init) 53 | { 54 | } 55 | 56 | TEST_SUITE_CLEANUP(suite_cleanup) 57 | { 58 | } 59 | 60 | TEST_FUNCTION_INITIALIZE(test_function_init) 61 | { 62 | } 63 | 64 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 65 | { 66 | } 67 | 68 | /* Tests_SRS_UMOCK_C_LIB_01_002: [The macro shall generate a function signature in case ENABLE_MOCKS is not defined.] */ 69 | /* Tests_SRS_UMOCK_C_LIB_01_005: [**If ENABLE_MOCKS is not defined, MOCKABLE_FUNCTION shall only generate a declaration for the function.] */ 70 | TEST_FUNCTION(when_ENABLE_MOCKS_is_not_on_MOCKABLE_FUNCTION_generates_a_standard_function_declaration) 71 | { 72 | // arrange 73 | 74 | // act 75 | int result = test_generate_signature(1, 0.42, "42"); 76 | 77 | // assert 78 | ASSERT_ARE_EQUAL(int, 42, result); 79 | } 80 | 81 | /* Tests_SRS_UMOCK_C_LIB_01_002: [The macro shall generate a function signature in case ENABLE_MOCKS is not defined.] */ 82 | /* Tests_SRS_UMOCK_C_LIB_01_005: [**If ENABLE_MOCKS is not defined, MOCKABLE_FUNCTION shall only generate a declaration for the function.] */ 83 | TEST_FUNCTION(when_ENABLE_MOCKS_is_not_on_MOCKABLE_FUNCTION_generates_a_standard_function_declaration_with_void_return) 84 | { 85 | // arrange 86 | 87 | // act 88 | test_generate_signature_void_return(1); 89 | 90 | // assert 91 | // no explicit assert 92 | } 93 | 94 | /* Tests_SRS_UMOCK_C_LIB_01_002: [The macro shall generate a function signature in case ENABLE_MOCKS is not defined.] */ 95 | /* Tests_SRS_UMOCK_C_LIB_01_005: [**If ENABLE_MOCKS is not defined, MOCKABLE_FUNCTION shall only generate a declaration for the function.] */ 96 | TEST_FUNCTION(when_ENABLE_MOCKS_is_not_on_MOCKABLE_FUNCTION_generates_a_standard_function_declaration_with_no_args_and_void_return) 97 | { 98 | // arrange 99 | 100 | // act 101 | test_generate_signature_no_args(); 102 | 103 | // assert 104 | // no explicit assert 105 | } 106 | 107 | /* Tests_SRS_UMOCK_C_LIB_01_213: [ The macro shall generate a function signature in case ENABLE_MOCKS is not defined. ]*/ 108 | TEST_FUNCTION(when_ENABLE_MOCKS_is_not_on_MOCKABLE_FUNCTION_generates_a_standard_function_declaration_for_MOCKABLE_FUNCTION_WITH_RETURNS_with_args) 109 | { 110 | // arrange 111 | 112 | // act 113 | int result = test_generate_signature_with_returns(1, 0.42, "42"); 114 | 115 | // assert 116 | ASSERT_ARE_EQUAL(int, 42, result); 117 | } 118 | 119 | /* Tests_SRS_UMOCK_C_LIB_01_213: [ The macro shall generate a function signature in case ENABLE_MOCKS is not defined. ]*/ 120 | TEST_FUNCTION(when_ENABLE_MOCKS_is_not_on_MOCKABLE_FUNCTION_generates_a_standard_function_declaration_for_MOCKABLE_FUNCTION_WITH_RETURNS_no_args) 121 | { 122 | // arrange 123 | 124 | // act 125 | int result = test_generate_signature_no_args_with_returns(); 126 | 127 | // assert 128 | ASSERT_ARE_EQUAL(int, 42, result); 129 | } 130 | 131 | /* Tests_SRS_UMOCK_C_LIB_01_213: [ The macro shall generate a function signature in case ENABLE_MOCKS is not defined. ]*/ 132 | TEST_FUNCTION(when_ENABLE_MOCKS_is_not_on_MOCKABLE_FUNCTION_generates_a_standard_function_declaration_for_MOCKABLE_FUNCTION_WITH_RETURNS_with_ptr_return) 133 | { 134 | // arrange 135 | 136 | // act 137 | void* result = test_generate_signature_with_returns_returning_ptr(); 138 | 139 | // assert 140 | ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, result); 141 | } 142 | 143 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 144 | -------------------------------------------------------------------------------- /tests/umock_c_gen_func_decl_int/umock_c_gen_func_multiple_inc.c: -------------------------------------------------------------------------------- 1 | // this translation unit is simply here to make sure we can generate code for mocks and raw function declarations 2 | // even when including umock_c_prod multiple times 3 | 4 | #define ENABLE_MOCKS 5 | 6 | #include "umock_c/umock_c.h" 7 | #include "umock_c/umock_c_prod.h" 8 | 9 | // have a mock 10 | MOCKABLE_FUNCTION(, void, have_a_mock); 11 | 12 | #undef ENABLE_MOCKS 13 | 14 | // now include again and have no mocks 15 | #include "umock_c/umock_c_prod.h" 16 | 17 | // this is not supposed to generate any mock 18 | // we simply want to make sure that we can generate the raw declaration *after* ENABLE_MOCKS was disabled 19 | MOCKABLE_FUNCTION(, void, really_no_mock); 20 | 21 | #define ENABLE_MOCKS 22 | 23 | #include "umock_c/umock_c_prod.h" 24 | 25 | // and have another mock 26 | MOCKABLE_FUNCTION(, void, have_another_mock); 27 | 28 | #undef ENABLE_MOCKS 29 | 30 | void really_no_mock(void) 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /tests/umock_c_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | test_dependency.h 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 18 | -------------------------------------------------------------------------------- /tests/umock_c_int/test_dependency.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_DEPENDENCY_H 5 | #define TEST_DEPENDENCY_H 6 | 7 | #include 8 | 9 | #include "umock_c/umock_c_prod.h" 10 | 11 | 12 | typedef struct TEST_STRUCT_TAG 13 | { 14 | int x; 15 | } TEST_STRUCT; 16 | 17 | typedef struct TEST_NESTED_STRUCT_TAG 18 | { 19 | TEST_STRUCT test_struct; 20 | int x; 21 | } TEST_NESTED_STRUCT; 22 | 23 | typedef struct TEST_STRUCT_WITH_2_MEMBERS_TAG 24 | { 25 | int x; 26 | int y; 27 | } TEST_STRUCT_WITH_2_MEMBERS; 28 | 29 | typedef struct TEST_STRUCT_COPY_FAILS_TAG 30 | { 31 | int x; 32 | } TEST_STRUCT_COPY_FAILS; 33 | 34 | typedef struct TEST_STRUCT_NOT_REGISTERED 35 | { 36 | int x; 37 | } TEST_STRUCT_NOT_REGISTERED; 38 | 39 | typedef unsigned char ARRAY_TYPE[16]; 40 | 41 | typedef const TEST_STRUCT* const CONST_P2_CONST_TEST_STRUCT; 42 | 43 | /* Tests_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/ 44 | /* Tests_SRS_UMOCK_C_LIB_01_004: [If ENABLE_MOCKS is defined, MOCKABLE_FUNCTION shall generate the declaration of the function and code for the mocked function, thus allowing setting up of expectations in test functions.] */ 45 | MOCKABLE_FUNCTION(, int, test_dependency_no_args); 46 | MOCKABLE_FUNCTION(, int, test_dependency_1_arg, int, a); 47 | MOCKABLE_FUNCTION(, void, test_dependency_1_arg_no_return, int, a); 48 | MOCKABLE_FUNCTION(, int, test_dependency_2_args, int, a, int, b); 49 | MOCKABLE_FUNCTION(, int, test_dependency_struct_arg, TEST_STRUCT, s); 50 | MOCKABLE_FUNCTION(, const TEST_STRUCT*, test_dependency_return_const_struct_ptr); 51 | MOCKABLE_FUNCTION(, int, test_dependency_struct_with_2_members, TEST_STRUCT_WITH_2_MEMBERS, s, int, a); 52 | MOCKABLE_FUNCTION(, void, test_dependency_nested_struct, TEST_NESTED_STRUCT, s); 53 | MOCKABLE_FUNCTION(, int, test_dependency_char_star_arg, char*, s); 54 | MOCKABLE_FUNCTION(, int, test_dependency_1_out_arg, int*, a); 55 | MOCKABLE_FUNCTION(, int, test_dependency_2_out_args, int*, a, int*, b); 56 | MOCKABLE_FUNCTION(, void, test_dependency_void_return); 57 | MOCKABLE_FUNCTION(, int*, test_dependency_int_ptr_return); 58 | MOCKABLE_FUNCTION(, void, test_dependency_buffer_arg, unsigned char*, a); 59 | MOCKABLE_FUNCTION(, int, test_dependency_global_mock_return_test); 60 | MOCKABLE_FUNCTION(, TEST_STRUCT_COPY_FAILS, test_dependency_global_mock_return_copy_fails); 61 | MOCKABLE_FUNCTION(, void, test_dependency_type_with_space, char *,s); 62 | MOCKABLE_FUNCTION(, void, test_dependency_all_types, char, char_arg, unsigned char, unsignedchar_arg, short, short_arg, unsigned short, unsignedshort_arg, int, int_arg, unsigned int, unsignedint_arg, long, long_arg, unsigned long, unsignedlong_arg, long long, longlong_arg, unsigned long long, unsignedlonglong_arg, float, float_arg, double, double_arg, long double, longdouble_arg, size_t, size_t_arg, void*, void_ptr_arg, const void*, const_void_ptr_arg); 63 | MOCKABLE_FUNCTION(, void, test_dependency_type_not_registered, TEST_STRUCT_NOT_REGISTERED, a); 64 | MOCKABLE_FUNCTION(, int, test_dependency_with_global_mock_hook); 65 | MOCKABLE_FUNCTION(, int, test_dependency_with_global_return); 66 | MOCKABLE_FUNCTION(, int, test_dependency_returning_int); 67 | MOCKABLE_FUNCTION(, char*, test_mock_function_returning_string); 68 | MOCKABLE_FUNCTION(, char*, test_mock_function_returning_string_with_macro); 69 | MOCKABLE_FUNCTION(, void, test_dependency_with_void_ptr, void*, argument); 70 | MOCKABLE_FUNCTION(, void, test_dependency_with_const_void_ptr, const void*, argument); 71 | MOCKABLE_FUNCTION(, void, test_dependency_with_array_arg, ARRAY_TYPE, argument); 72 | MOCKABLE_FUNCTION(, void, test_dependency_with_volatile_arg, volatile int, argument); 73 | MOCKABLE_FUNCTION(, void, test_dependency_with_volatile_pointer_arg, int volatile*, argument); 74 | MOCKABLE_FUNCTION(, volatile void*, test_dependency_with_volatile_pptr_return); 75 | 76 | // this is here to make sure that a function with a const return can compile 77 | MOCKABLE_FUNCTION(, CONST_P2_CONST_TEST_STRUCT, test_dependency_with_const_p2_const_return); 78 | 79 | typedef enum TEST_ENUM_TAG 80 | { 81 | TEST_ENUM_VALUE_1, 82 | TEST_ENUM_VALUE_2 83 | } TEST_ENUM; 84 | 85 | MOCKABLE_FUNCTION(, void, test_mock_function_with_enum_type, TEST_ENUM, enum_type); 86 | 87 | MOCKABLE_FUNCTION_WITH_RETURNS(, int, test_dependency_with_returns_no_args_returning_int)(42, 43); 88 | MOCKABLE_FUNCTION_WITH_RETURNS(, void*, test_dependency_with_returns_no_args_returning_void_ptr)((void*)0x4242, (void*)0x4243); 89 | MOCKABLE_FUNCTION_WITH_RETURNS(, TEST_STRUCT, test_dependency_with_returns_no_args_returning_struct)({ 0x42 }, { 0x43 }); 90 | 91 | 92 | #endif /* TEST_DEPENDENCY_H */ 93 | -------------------------------------------------------------------------------- /tests/umock_c_malloc_hook_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_malloc_hook_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_malloc_hook_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | ) 15 | 16 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 17 | -------------------------------------------------------------------------------- /tests/umock_c_malloc_hook_int/umock_c_malloc_hook_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include // for snprintf 6 | #include 7 | 8 | #include "macro_utils/macro_utils.h" // IWYU pragma: keep 9 | 10 | #include "testrunnerswitcher.h" 11 | 12 | static size_t my_malloc_count; 13 | 14 | void* my_malloc(size_t size) 15 | { 16 | my_malloc_count++; 17 | return malloc(size); 18 | } 19 | 20 | static size_t my_calloc_count; 21 | 22 | void* my_calloc(size_t nmemb, size_t size) 23 | { 24 | my_calloc_count++; 25 | return calloc(nmemb, size); 26 | } 27 | 28 | static size_t my_realloc_count; 29 | 30 | void* my_realloc(void* ptr, size_t size) 31 | { 32 | my_realloc_count++; 33 | return realloc(ptr, size); 34 | } 35 | 36 | static size_t my_free_count; 37 | 38 | void my_free(void* ptr) 39 | { 40 | my_free_count++; 41 | free(ptr); 42 | } 43 | 44 | #define malloc my_malloc 45 | #define calloc my_calloc 46 | #define realloc my_realloc 47 | #define free my_free 48 | 49 | #define ENABLE_MOCKS 50 | 51 | #include "umock_c/umock_c.h" 52 | #include "umock_c/umocktypes_charptr.h" 53 | 54 | MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) 55 | 56 | static void test_on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 57 | { 58 | char temp_str[256]; 59 | (void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", MU_ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code)); 60 | ASSERT_FAIL(temp_str); 61 | } 62 | 63 | MOCK_FUNCTION_WITH_CODE(, int, function1, int, a) 64 | MOCK_FUNCTION_END(42) 65 | 66 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 67 | 68 | TEST_SUITE_INITIALIZE(suite_init) 69 | { 70 | int result; 71 | 72 | result = umock_c_init(test_on_umock_c_error); 73 | ASSERT_ARE_EQUAL(int, 0, result); 74 | result = umocktypes_charptr_register_types(); 75 | ASSERT_ARE_EQUAL(int, 0, result); 76 | } 77 | 78 | TEST_SUITE_CLEANUP(suite_cleanup) 79 | { 80 | umock_c_deinit(); 81 | } 82 | 83 | TEST_FUNCTION_INITIALIZE(test_function_init) 84 | { 85 | umock_c_reset_all_calls(); 86 | my_malloc_count = 0; 87 | my_calloc_count = 0; 88 | my_realloc_count = 0; 89 | my_free_count = 0; 90 | } 91 | 92 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 93 | { 94 | } 95 | 96 | TEST_FUNCTION(when_malloc_is_hooked_no_calls_are_made_to_it) 97 | { 98 | // arrange 99 | STRICT_EXPECTED_CALL(function1(42)); 100 | 101 | // act 102 | function1(42); 103 | 104 | // assert 105 | ASSERT_ARE_EQUAL(size_t, 0, my_malloc_count); 106 | ASSERT_ARE_EQUAL(size_t, 0, my_calloc_count); 107 | ASSERT_ARE_EQUAL(size_t, 0, my_realloc_count); 108 | ASSERT_ARE_EQUAL(size_t, 0, my_free_count); 109 | } 110 | 111 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 112 | -------------------------------------------------------------------------------- /tests/umock_c_mock_filters_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_mock_filters_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_mock_filters_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | test_dependency.h 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 18 | -------------------------------------------------------------------------------- /tests/umock_c_mock_filters_int/test_dependency.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_DEPENDENCY_H 5 | #define TEST_DEPENDENCY_H 6 | 7 | #include "umock_c/umock_c_prod.h" 8 | 9 | 10 | MOCKABLE_FUNCTION(, int, the_mocked_one); 11 | MOCKABLE_FUNCTION(, int, do_not_actually_mock); 12 | MOCKABLE_FUNCTION_WITH_RETURNS(, int, do_not_actually_mock_with_returns)(1, 2); 13 | 14 | 15 | #endif /* TEST_DEPENDENCY_H */ 16 | -------------------------------------------------------------------------------- /tests/umock_c_mock_filters_int/umock_c_mock_filters_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "testrunnerswitcher.h" 5 | #include "umock_c/umock_c.h" 6 | 7 | #define ENABLE_MOCKS 8 | 9 | // this enables mock filtering while being backward compatible 10 | #define ENABLE_MOCK_FILTERING 11 | 12 | // you have to be nice to the framework, so you have to say "please_mock_{function_name}" 13 | #define please_mock_the_mocked_one MOCK_ENABLED 14 | 15 | #include "test_dependency.h" 16 | 17 | static void test_on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 18 | { 19 | (void)error_code; 20 | ASSERT_FAIL("umock error"); 21 | } 22 | 23 | int do_not_actually_mock(void) 24 | { 25 | return 0x42; 26 | } 27 | 28 | int do_not_actually_mock_with_returns(void) 29 | { 30 | return 0x42; 31 | } 32 | 33 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 34 | 35 | TEST_SUITE_INITIALIZE(suite_init) 36 | { 37 | ASSERT_ARE_EQUAL(int, 0, umock_c_init(test_on_umock_c_error)); 38 | } 39 | 40 | TEST_SUITE_CLEANUP(suite_cleanup) 41 | { 42 | umock_c_deinit(); 43 | } 44 | 45 | TEST_FUNCTION_INITIALIZE(test_function_init) 46 | { 47 | } 48 | 49 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 50 | { 51 | } 52 | 53 | TEST_FUNCTION(call_the_not_mocked_function) 54 | { 55 | // arrange 56 | int result; 57 | 58 | // act 59 | result = do_not_actually_mock(); 60 | 61 | // assert 62 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 63 | ASSERT_ARE_EQUAL(int, 0x42, result); 64 | } 65 | 66 | TEST_FUNCTION(call_the_not_mocked_function_with_returns) 67 | { 68 | // arrange 69 | int result; 70 | 71 | // act 72 | result = do_not_actually_mock_with_returns(); 73 | 74 | // assert 75 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 76 | ASSERT_ARE_EQUAL(int, 0x42, result); 77 | } 78 | 79 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 80 | -------------------------------------------------------------------------------- /tests/umock_c_negt_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_negative_tests_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_negt_int_tests.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | test_dependency.h 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 18 | -------------------------------------------------------------------------------- /tests/umock_c_negt_int/test_dependency.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_DEPENDENCY_H 5 | #define TEST_DEPENDENCY_H 6 | 7 | #include "umock_c/umock_c_prod.h" 8 | 9 | 10 | typedef void* SOME_OTHER_HANDLE; 11 | 12 | MOCKABLE_FUNCTION(, int, function_1); 13 | MOCKABLE_FUNCTION(, int, function_2); 14 | MOCKABLE_FUNCTION(, void, function_3_void_return); 15 | MOCKABLE_FUNCTION(, void*, function_3_void_ptr_return, void*, a); 16 | MOCKABLE_FUNCTION(, SOME_OTHER_HANDLE, some_other_create, int, a); 17 | MOCKABLE_FUNCTION(, void, some_other_destroy, SOME_OTHER_HANDLE, h); 18 | 19 | MOCKABLE_FUNCTION(, void, void_function_no_args); 20 | MOCKABLE_FUNCTION(, void, void_function_with_args, int, x); 21 | MOCKABLE_FUNCTION(, int, function_default_no_args); 22 | MOCKABLE_FUNCTION(, int, function_default_with_args, int, x); 23 | MOCKABLE_FUNCTION(, int, function_mark_cannot_fail_no_args); 24 | MOCKABLE_FUNCTION(, int, function_mark_cannot_fail_with_args, int, x); 25 | 26 | MOCKABLE_FUNCTION_WITH_RETURNS(, int, function_with_returns)(42, 43); 27 | 28 | 29 | #endif /* TEST_DEPENDENCY_H */ 30 | -------------------------------------------------------------------------------- /tests/umock_c_negt_noini_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_negt_noint_tests) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_negt_noint_tests.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ../../src/umock_c_negative_tests.c 12 | ) 13 | 14 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 15 | -------------------------------------------------------------------------------- /tests/umock_c_negt_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_negative_tests_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_negative_tests_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ../../src/umock_c_negative_tests.c 12 | ) 13 | 14 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 15 | -------------------------------------------------------------------------------- /tests/umock_c_ptrarg_leak_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_ptrarg_leak_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_ptrarg_leak_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | ) 15 | 16 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 17 | -------------------------------------------------------------------------------- /tests/umock_c_ptrarg_leak_int/umock_c_ptrarg_leak_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "testrunnerswitcher.h" 5 | 6 | #define ENABLE_MOCKS 7 | 8 | #include "umock_c/umock_c.h" 9 | #include "umock_c/umocktypes_charptr.h" 10 | 11 | MOCKABLE_FUNCTION(, int, a_char_star_arg_function, char*, x); 12 | 13 | static void test_on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 14 | { 15 | (void)error_code; 16 | ASSERT_FAIL("umock_c reported error"); 17 | } 18 | 19 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 20 | 21 | TEST_SUITE_INITIALIZE(suite_init) 22 | { 23 | int result; 24 | 25 | result = umock_c_init(test_on_umock_c_error); 26 | ASSERT_ARE_EQUAL(int, 0, result); 27 | result = umocktypes_charptr_register_types(); 28 | ASSERT_ARE_EQUAL(int, 0, result); 29 | } 30 | 31 | TEST_SUITE_CLEANUP(suite_cleanup) 32 | { 33 | umock_c_deinit(); 34 | } 35 | 36 | TEST_FUNCTION_INITIALIZE(test_function_init) 37 | { 38 | umock_c_reset_all_calls(); 39 | } 40 | 41 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 42 | { 43 | } 44 | 45 | TEST_FUNCTION(a_matched_call_with_pointer_type_argument_does_not_leak) 46 | { 47 | // arrange 48 | EXPECTED_CALL(a_char_star_arg_function("a")); 49 | (void)a_char_star_arg_function("a"); 50 | 51 | // act 52 | umock_c_deinit(); 53 | 54 | // assert 55 | // no leaks expected 56 | } 57 | 58 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 59 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_reals_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_reals_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | test_dependency.h 15 | test_dependency_no_enable_mocks.h 16 | ) 17 | 18 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 19 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/test_dependency.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_DEPENDENCY_H 5 | #define TEST_DEPENDENCY_H 6 | 7 | #include "umock_c/umock_c_prod.h" 8 | 9 | 10 | MOCKABLE_FUNCTION(, int, test_dependency_no_args); 11 | MOCKABLE_FUNCTION(, int, test_dependency_no_args_no_real); 12 | 13 | /* Tests_SRS_UMOCK_C_LIB_01_215: [ Each item in ... shall be an entry for one mockable function. ]*/ 14 | /* Tests_SRS_UMOCK_C_LIB_01_216: [ Each item in ... shall be defined using a macro called FUNCTION, which shall be an alias for MOCKABLE_FUNCTION. ]*/ 15 | MOCKABLE_INTERFACE(test_interface, 16 | FUNCTION(, int, test_dependency_1_arg, int, a), 17 | FUNCTION(, int, test_dependency_2_args, int, a, int, b) 18 | ) 19 | 20 | MOCKABLE_INTERFACE(test_interface_no_reals, 21 | FUNCTION(, int, test_dependency_1_arg_no_real, int, a), 22 | FUNCTION(, int, test_dependency_2_args_no_real, int, a, int, b) 23 | ) 24 | 25 | 26 | #endif /* TEST_DEPENDENCY_H */ 27 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/test_dependency_no_enable_mocks.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_DEPENDENCY_NO_ENABLE_MOCKS_H 5 | #define TEST_DEPENDENCY_NO_ENABLE_MOCKS_H 6 | 7 | #include "umock_c/umock_c_prod.h" 8 | 9 | 10 | MOCKABLE_FUNCTION(, int, test_dependency_no_args_no_ENABLE_MOCKS); 11 | 12 | 13 | #endif /* TEST_DEPENDENCY_NO_ENABLE_MOCKS_H */ 14 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/test_dependency_real_code.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "test_dependency.h" 5 | #include "umock_c/umock_c_prod.h" 6 | 7 | IMPLEMENT_MOCKABLE_FUNCTION(, int, test_dependency_no_args) 8 | { 9 | return 42; 10 | } 11 | 12 | IMPLEMENT_MOCKABLE_FUNCTION(, int, test_dependency_1_arg, int, a) 13 | { 14 | (void)a; 15 | return 42; 16 | } 17 | 18 | IMPLEMENT_MOCKABLE_FUNCTION(, int, test_dependency_2_args, int, a, int, b) 19 | { 20 | (void)a; 21 | (void)b; 22 | return 42; 23 | } 24 | 25 | 26 | IMPLEMENT_MOCKABLE_FUNCTION(, int, test_dependency_1_arg_no_real, int, a) 27 | { 28 | (void)a; 29 | return 44; 30 | } 31 | 32 | IMPLEMENT_MOCKABLE_FUNCTION(, int, test_dependency_2_args_no_real, int, a, int, b) 33 | { 34 | (void)a; 35 | (void)b; 36 | return 44; 37 | } 38 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/test_dependency_real_code_no_enable_mocks.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "test_dependency_no_enable_mocks.h" 5 | #include "umock_c/umock_c_prod.h" 6 | 7 | IMPLEMENT_MOCKABLE_FUNCTION(, int, test_dependency_no_args_no_ENABLE_MOCKS) 8 | { 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/test_unit_no_reals.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_UNIT_NO_REALS_H 5 | #define TEST_UNIT_NO_REALS_H 6 | 7 | #include "umock_c/umock_c_prod.h" 8 | 9 | 10 | MOCKABLE_INTERFACE(test_unit_no_reals, 11 | FUNCTION(, int, test_unit_1_arg_no_real, int, a), 12 | FUNCTION(, int, test_unit_2_args_no_real, int, a, int, b) 13 | ) 14 | 15 | 16 | #endif /* TEST_UNIT_NO_REALS_H */ 17 | -------------------------------------------------------------------------------- /tests/umock_c_reals_int/umock_c_reals_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | 5 | #include 6 | 7 | #include "testrunnerswitcher.h" 8 | #include "umock_c/umock_c.h" 9 | 10 | // This include checks that a header with a MOCKABLE_INTERFACE in it can be expanded when no ENABLE_MOCKS is used 11 | #include "test_unit_no_reals.h" // IWYU pragma: keep 12 | 13 | // Tell IWYU to keep this even though it's in the .c file included 14 | #include "test_dependency_no_enable_mocks.h" // IWYU pragma: keep 15 | #include "test_dependency_real_code_no_enable_mocks.c" 16 | 17 | #define ENABLE_MOCKS 18 | 19 | #include "test_dependency.h" 20 | /* Tests_SRS_UMOCK_C_LIB_01_217: [ In the presence of the ENABLE_MOCKS define, IMPLEMENT_MOCKABLE_FUNCTION shall expand to the signature of the function, but the name shall be changed to be prefix with real_. ]*/ 21 | #include "test_dependency_real_code.c" 22 | 23 | typedef struct test_on_umock_c_error_CALL_TAG 24 | { 25 | UMOCK_C_ERROR_CODE error_code; 26 | } test_on_umock_c_error_CALL; 27 | 28 | static test_on_umock_c_error_CALL* test_on_umock_c_error_calls; 29 | static size_t test_on_umock_c_error_call_count; 30 | 31 | static void test_on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 32 | { 33 | test_on_umock_c_error_CALL* new_calls = realloc(test_on_umock_c_error_calls, sizeof(test_on_umock_c_error_CALL) * (test_on_umock_c_error_call_count + 1)); 34 | if (new_calls != NULL) 35 | { 36 | test_on_umock_c_error_calls = new_calls; 37 | test_on_umock_c_error_calls[test_on_umock_c_error_call_count].error_code = error_code; 38 | test_on_umock_c_error_call_count++; 39 | } 40 | } 41 | 42 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 43 | 44 | TEST_SUITE_INITIALIZE(suite_init) 45 | { 46 | int result; 47 | 48 | result = umock_c_init(test_on_umock_c_error); 49 | ASSERT_ARE_EQUAL(int, 0, result); 50 | } 51 | 52 | TEST_SUITE_CLEANUP(suite_cleanup) 53 | { 54 | umock_c_deinit(); 55 | } 56 | 57 | TEST_FUNCTION_INITIALIZE(test_function_init) 58 | { 59 | test_on_umock_c_error_calls = NULL; 60 | test_on_umock_c_error_call_count = 0; 61 | } 62 | 63 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 64 | { 65 | umock_c_reset_all_calls(); 66 | 67 | free(test_on_umock_c_error_calls); 68 | test_on_umock_c_error_calls = NULL; 69 | test_on_umock_c_error_call_count = 0; 70 | } 71 | 72 | /* STRICT_EXPECTED_CALL */ 73 | 74 | TEST_FUNCTION(real_is_called_for_test_dependency_no_args) 75 | { 76 | // arrange 77 | int result; 78 | 79 | REGISTER_GLOBAL_MOCK_HOOK(test_dependency_no_args, UMOCK_REAL(test_dependency_no_args)); 80 | 81 | STRICT_EXPECTED_CALL(test_dependency_no_args()); 82 | 83 | // act 84 | result = test_dependency_no_args(); 85 | 86 | // assert 87 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_expected_calls()); 88 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 89 | ASSERT_ARE_EQUAL(int, 42, result); 90 | } 91 | 92 | TEST_FUNCTION(real_is_not_called_for_test_dependency_no_args_no_real) 93 | { 94 | // arrange 95 | int result; 96 | 97 | REGISTER_GLOBAL_MOCK_RETURN(test_dependency_no_args_no_real, 1); 98 | 99 | STRICT_EXPECTED_CALL(test_dependency_no_args_no_real()); 100 | 101 | // act 102 | result = test_dependency_no_args_no_real(); 103 | 104 | // assert 105 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_expected_calls()); 106 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 107 | ASSERT_ARE_EQUAL(int, 1, result); 108 | } 109 | 110 | /* Tests_SRS_UMOCK_C_LIB_01_219: [ REGISTER_GLOBAL_INTERFACE_HOOKS shall register as mock hooks the real functions for all the functions in a mockable interface. ]*/ 111 | TEST_FUNCTION(reals_are_setup_at_interface_level) 112 | { 113 | // arrange 114 | int result; 115 | 116 | REGISTER_GLOBAL_INTERFACE_HOOKS(test_interface); 117 | 118 | STRICT_EXPECTED_CALL(test_dependency_1_arg(45)); 119 | 120 | // act 121 | result = test_dependency_1_arg(45); 122 | 123 | // assert 124 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_expected_calls()); 125 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 126 | ASSERT_ARE_EQUAL(int, 42, result); 127 | } 128 | 129 | TEST_FUNCTION(real_is_not_called_for_interface_without_reals) 130 | { 131 | // arrange 132 | int result; 133 | 134 | REGISTER_GLOBAL_MOCK_RETURN(test_dependency_1_arg_no_real, 1); 135 | 136 | STRICT_EXPECTED_CALL(test_dependency_1_arg_no_real(45)); 137 | 138 | // act 139 | result = test_dependency_1_arg_no_real(45); 140 | 141 | // assert 142 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_expected_calls()); 143 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 144 | ASSERT_ARE_EQUAL(int, 1, result); 145 | } 146 | 147 | /* Tests_SRS_UMOCK_C_LIB_01_218: [ If ENABLE_MOCKS is not defined, IMPLEMENT_MOCKABLE_FUNCTION shall expand to the signature of the function. ]*/ 148 | TEST_FUNCTION(no_rename_to_Real_if_ENABLE_MOCKS_is_not_defined) 149 | { 150 | // arrange 151 | int result; 152 | 153 | // act 154 | result = test_dependency_no_args_no_ENABLE_MOCKS(); 155 | 156 | // assert 157 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_expected_calls()); 158 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 159 | ASSERT_ARE_EQUAL(int, 42, result); 160 | } 161 | 162 | /* Tests_SRS_UMOCK_C_LIB_01_220: [ UMOCK_REAL shall produce the name of the real function generated by umock. ]*/ 163 | TEST_FUNCTION(calling_a_real_function_is_possible) 164 | { 165 | // arrange 166 | int result; 167 | 168 | // act 169 | result = UMOCK_REAL(test_dependency_no_args)(); 170 | 171 | // assert 172 | ASSERT_ARE_EQUAL(int, 42, result); 173 | } 174 | 175 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 176 | -------------------------------------------------------------------------------- /tests/umock_c_reg_win_types_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_reg_win_types_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_reg_win_types_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 14 | -------------------------------------------------------------------------------- /tests/umock_c_reg_win_types_int/umock_c_reg_win_types_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | 5 | #include "macro_utils/macro_utils.h" 6 | #include "testrunnerswitcher.h" 7 | 8 | #include "umock_c/umocktypes_charptr.h" 9 | #include "umock_c/umocktypes_wcharptr.h" 10 | #include "umock_c/umocktypes_stdint.h" 11 | #include "umock_c/umocktypes_windows.h" 12 | 13 | #include "umock_c/umock_c.h" 14 | 15 | MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES); 16 | 17 | static void test_on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 18 | { 19 | ASSERT_FAIL("test_on_umock_c_error called with %" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code)); 20 | } 21 | 22 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 23 | 24 | TEST_SUITE_INITIALIZE(suite_init) 25 | { 26 | ASSERT_ARE_EQUAL(int, 0, umock_c_init(test_on_umock_c_error), "umock_c_init"); 27 | } 28 | 29 | TEST_SUITE_CLEANUP(suite_cleanup) 30 | { 31 | umock_c_deinit(); 32 | } 33 | 34 | TEST_FUNCTION_INITIALIZE(test_function_init) 35 | { 36 | } 37 | 38 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 39 | { 40 | umock_c_reset_all_calls(); 41 | } 42 | 43 | TEST_FUNCTION(unmatched_expected_calls_with_windows_args_are_reported) 44 | { 45 | // arrange 46 | ASSERT_ARE_EQUAL(int, 0, umocktypes_charptr_register_types(), "umocktypes_charptr_register_types"); 47 | ASSERT_ARE_EQUAL(int, 0, umocktypes_wcharptr_register_types(), "umocktypes_wcharptr_register_types"); 48 | ASSERT_ARE_EQUAL(int, 0, umocktypes_stdint_register_types(), "umocktypes_stdint_register_types"); 49 | 50 | // act 51 | int result = umocktypes_windows_register_types(); 52 | 53 | // assert 54 | ASSERT_ARE_EQUAL(int, 0, result); 55 | } 56 | 57 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 58 | -------------------------------------------------------------------------------- /tests/umock_c_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ../../src/umock_c.c 12 | ) 13 | 14 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 15 | -------------------------------------------------------------------------------- /tests/umock_c_windows_types_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_windows_types_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_windows_types_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | test_dependency.h 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 18 | -------------------------------------------------------------------------------- /tests/umock_c_windows_types_int/test_dependency.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TEST_DEPENDENCY_H 5 | #define TEST_DEPENDENCY_H 6 | 7 | #include "windows.h" 8 | #include "umock_c/umock_c_prod.h" 9 | 10 | 11 | MOCKABLE_FUNCTION(, void, test_dependency_LONG_arg, LONG, LONG_arg); 12 | MOCKABLE_FUNCTION(, void, test_dependency_LONGLONG_arg, LONGLONG, LONGLONG_arg); 13 | MOCKABLE_FUNCTION(, void, test_dependency_DWORD_arg, DWORD, DWORD_arg); 14 | MOCKABLE_FUNCTION(, void, test_dependency_HRESULT_arg, HRESULT, HRESULT_arg); 15 | MOCKABLE_FUNCTION(, void, test_dependency_BOOL_arg, BOOL, BOOL_arg); 16 | MOCKABLE_FUNCTION(, void, test_dependency_PVOID_arg, PVOID, PVOID_arg); 17 | MOCKABLE_FUNCTION(, void, test_dependency_LPCSTR_arg, LPCSTR, LPCSTR_arg); 18 | MOCKABLE_FUNCTION(, void, test_dependency_LPSECURITY_ATTRIBUTES_arg, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES_arg); 19 | MOCKABLE_FUNCTION(, void, test_dependency_HANDLE_arg, HANDLE, HANDLE_arg); 20 | MOCKABLE_FUNCTION(, void, test_dependency_UCHAR_arg, UCHAR, UCHAR_arg); 21 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_POOL_arg, PTP_POOL, PTP_POOL_arg); 22 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_CLEANUP_GROUP_arg, PTP_CLEANUP_GROUP, PTP_CLEANUP_GROUP_arg); 23 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_CALLBACK_ENVIRON_arg, PTP_CALLBACK_ENVIRON, PTP_CALLBACK_ENVIRON_arg); 24 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_CLEANUP_GROUP_CANCEL_CALLBACK_arg, PTP_CLEANUP_GROUP_CANCEL_CALLBACK, PTP_CLEANUP_GROUP_CANCEL_CALLBACK_arg); 25 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_IO_arg, PTP_IO, PTP_IO_arg); 26 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_WIN32_IO_CALLBACK_arg, PTP_WIN32_IO_CALLBACK, PTP_WIN32_IO_CALLBACK_arg); 27 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_WORK_CALLBACK_arg, PTP_WORK_CALLBACK, PTP_WORK_CALLBACK_arg); 28 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_WORK_arg, PTP_WORK, PTP_WORK_arg); 29 | MOCKABLE_FUNCTION(, void, test_dependency_LPCVOID_arg, LPCVOID, LPCVOID_arg); 30 | MOCKABLE_FUNCTION(, void, test_dependency_LPDWORD_arg, LPDWORD, LPDWORD_arg); 31 | MOCKABLE_FUNCTION(, void, test_dependency_LPOVERLAPPED_arg, LPOVERLAPPED, LPOVERLAPPED_arg); 32 | MOCKABLE_FUNCTION(, void, test_dependency_LPVOID_arg, LPVOID, LPVOID_arg); 33 | MOCKABLE_FUNCTION(, void, test_dependency_PTP_SIMPLE_CALLBACK_arg, PTP_SIMPLE_CALLBACK, PTP_SIMPLE_CALLBACK_arg); 34 | MOCKABLE_FUNCTION(, void, test_dependency_LPLONG_arg, LPLONG, LPLONG_arg); 35 | MOCKABLE_FUNCTION(, void, test_dependency_BYTE_arg, BYTE, BYTE_arg); 36 | MOCKABLE_FUNCTION(, void, test_dependency_BOOLEAN_arg, BOOLEAN, BOOLEAN_arg); 37 | MOCKABLE_FUNCTION(, void, test_dependency_ULONG_arg, ULONG, ULONG_arg); 38 | MOCKABLE_FUNCTION(, void, test_dependency_LONG64_arg, LONG64, LONG64_arg); 39 | MOCKABLE_FUNCTION(, void, test_dependency_SHORT_arg, SHORT, SHORT_arg); 40 | MOCKABLE_FUNCTION(, void, test_dependency_SIZE_T_arg, SIZE_T, SIZE_T_arg); 41 | MOCKABLE_FUNCTION(, void, test_dependency_PSIZE_T_arg, PSIZE_T, PSIZE_T_arg); 42 | MOCKABLE_FUNCTION(, void, test_dependency_PHANDLE_arg, PHANDLE, PHANDLE_arg); 43 | 44 | #endif /* TEST_DEPENDENCY_H */ 45 | -------------------------------------------------------------------------------- /tests/umock_c_with_lock_factory_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_with_lock_factory_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_with_lock_factory_int.c 8 | ) 9 | 10 | if(WIN32) 11 | # For Windows use CreateThread et all 12 | set(test_platform_c_files 13 | ./minipal/umock_threadapi_win32.c 14 | ../../src/umock_lock_factory_windows.c 15 | ) 16 | else() 17 | # For others assume pthreads (this should be a real check for pthreads) 18 | set(test_platform_c_files 19 | ./minipal/umock_threadapi_pthread.c 20 | ../../src/umock_lock_factory_pthread.c 21 | ) 22 | endif() 23 | 24 | set(${theseTestsName}_c_files 25 | ${test_platform_c_files} 26 | ) 27 | 28 | set(${theseTestsName}_h_files 29 | ./minipal/umock_threadapi.h 30 | ) 31 | 32 | if(UNIX) 33 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" ADDITIONAL_LIBS pthread) 34 | else() 35 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 36 | endif() 37 | -------------------------------------------------------------------------------- /tests/umock_c_with_lock_factory_int/minipal/umock_threadapi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UMOCK_THREADAPI_H 5 | #define UMOCK_THREADAPI_H 6 | 7 | #include "macro_utils/macro_utils.h" 8 | 9 | 10 | typedef int(*UMOCK_THREAD_START_FUNC)(void *); 11 | 12 | #define UMOCK_THREADAPI_RESULT_VALUES \ 13 | UMOCK_THREADAPI_OK, \ 14 | UMOCK_THREADAPI_INVALID_ARG, \ 15 | UMOCK_THREADAPI_NO_MEMORY, \ 16 | UMOCK_THREADAPI_ERROR 17 | 18 | MU_DEFINE_ENUM(UMOCK_THREADAPI_RESULT, UMOCK_THREADAPI_RESULT_VALUES); 19 | 20 | typedef void* UMOCK_THREAD_HANDLE; 21 | 22 | UMOCK_THREADAPI_RESULT umock_threadapi_create(UMOCK_THREAD_HANDLE* thread_handle, UMOCK_THREAD_START_FUNC func, void* arg); 23 | UMOCK_THREADAPI_RESULT umock_threadapi_join(UMOCK_THREAD_HANDLE thread_handle, int* res); 24 | void umock_threadapi_sleep(unsigned int milliseconds); 25 | 26 | 27 | #endif /* UMOCK_THREADAPI_H */ 28 | -------------------------------------------------------------------------------- /tests/umock_c_with_lock_factory_int/minipal/umock_threadapi_pthread.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #define _DEFAULT_SOURCE 5 | 6 | #include "macro_utils/macro_utils.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include "c_logging/logger.h" 15 | 16 | #include "umock_threadapi.h" 17 | 18 | 19 | MU_DEFINE_ENUM_STRINGS(UMOCK_THREADAPI_RESULT, UMOCK_THREADAPI_RESULT_VALUES); 20 | 21 | typedef struct THREAD_INSTANCE_TAG 22 | { 23 | pthread_t Pthread_handle; 24 | UMOCK_THREAD_START_FUNC ThreadStartFunc; 25 | void* Arg; 26 | } THREAD_INSTANCE; 27 | 28 | static void* ThreadWrapper(void* threadInstanceArg) 29 | { 30 | THREAD_INSTANCE* threadInstance = (THREAD_INSTANCE*)threadInstanceArg; 31 | int result = threadInstance->ThreadStartFunc(threadInstance->Arg); 32 | return (void*)(intptr_t)result; 33 | } 34 | 35 | UMOCK_THREADAPI_RESULT umock_threadapi_create(UMOCK_THREAD_HANDLE* threadHandle, UMOCK_THREAD_START_FUNC func, void* arg) 36 | { 37 | UMOCK_THREADAPI_RESULT result; 38 | 39 | if ((threadHandle == NULL) || 40 | (func == NULL)) 41 | { 42 | result = UMOCK_THREADAPI_INVALID_ARG; 43 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 44 | } 45 | else 46 | { 47 | THREAD_INSTANCE* threadInstance = malloc(sizeof(THREAD_INSTANCE)); 48 | if (threadInstance == NULL) 49 | { 50 | result = UMOCK_THREADAPI_NO_MEMORY; 51 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 52 | } 53 | else 54 | { 55 | threadInstance->ThreadStartFunc = func; 56 | threadInstance->Arg = arg; 57 | int createResult = pthread_create(&threadInstance->Pthread_handle, NULL, ThreadWrapper, threadInstance); 58 | switch (createResult) 59 | { 60 | default: 61 | free(threadInstance); 62 | 63 | result = UMOCK_THREADAPI_ERROR; 64 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 65 | break; 66 | 67 | case 0: 68 | *threadHandle = threadInstance; 69 | result = UMOCK_THREADAPI_OK; 70 | break; 71 | 72 | case EAGAIN: 73 | free(threadInstance); 74 | 75 | result = UMOCK_THREADAPI_NO_MEMORY; 76 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 77 | break; 78 | } 79 | } 80 | } 81 | 82 | return result; 83 | } 84 | 85 | UMOCK_THREADAPI_RESULT umock_threadapi_join(UMOCK_THREAD_HANDLE threadHandle, int* res) 86 | { 87 | UMOCK_THREADAPI_RESULT result; 88 | 89 | THREAD_INSTANCE* threadInstance = (THREAD_INSTANCE*)threadHandle; 90 | if (threadInstance == NULL) 91 | { 92 | result = UMOCK_THREADAPI_INVALID_ARG; 93 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 94 | } 95 | else 96 | { 97 | void* threadResult; 98 | if (pthread_join(threadInstance->Pthread_handle, &threadResult) != 0) 99 | { 100 | result = UMOCK_THREADAPI_ERROR; 101 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 102 | } 103 | else 104 | { 105 | if (res != NULL) 106 | { 107 | *res = (int)(intptr_t)threadResult; 108 | } 109 | 110 | result = UMOCK_THREADAPI_OK; 111 | } 112 | 113 | free(threadInstance); 114 | } 115 | 116 | return result; 117 | } 118 | 119 | void umock_threadapi_sleep(unsigned int milliseconds) 120 | { 121 | time_t seconds = milliseconds / 1000; 122 | long nsRemainder = (milliseconds % 1000) * 1000000; 123 | struct timespec timeToSleep = { seconds, nsRemainder }; 124 | (void)nanosleep(&timeToSleep, NULL); 125 | } 126 | -------------------------------------------------------------------------------- /tests/umock_c_with_lock_factory_int/minipal/umock_threadapi_win32.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | #include "windows.h" 7 | 8 | #include "macro_utils/macro_utils.h" 9 | 10 | #include "c_logging/logger.h" 11 | 12 | #include "umock_threadapi.h" 13 | 14 | MU_DEFINE_ENUM_STRINGS(UMOCK_THREADAPI_RESULT, UMOCK_THREADAPI_RESULT_VALUES); 15 | 16 | UMOCK_THREADAPI_RESULT umock_threadapi_create(UMOCK_THREAD_HANDLE* thread_handle, UMOCK_THREAD_START_FUNC func, void* arg) 17 | { 18 | UMOCK_THREADAPI_RESULT result; 19 | if ((thread_handle == NULL) || 20 | (func == NULL)) 21 | { 22 | result = UMOCK_THREADAPI_INVALID_ARG; 23 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 24 | } 25 | else 26 | { 27 | *thread_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, NULL); 28 | if(*thread_handle == NULL) 29 | { 30 | result = (GetLastError() == ERROR_OUTOFMEMORY) ? UMOCK_THREADAPI_NO_MEMORY : UMOCK_THREADAPI_ERROR; 31 | 32 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 33 | } 34 | else 35 | { 36 | result = UMOCK_THREADAPI_OK; 37 | } 38 | } 39 | 40 | return result; 41 | } 42 | 43 | UMOCK_THREADAPI_RESULT umock_threadapi_join(UMOCK_THREAD_HANDLE thread_handle, int *res) 44 | { 45 | UMOCK_THREADAPI_RESULT result = UMOCK_THREADAPI_OK; 46 | 47 | if (thread_handle == NULL) 48 | { 49 | result = UMOCK_THREADAPI_INVALID_ARG; 50 | LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 51 | } 52 | else 53 | { 54 | DWORD returnCode = WaitForSingleObject(thread_handle, INFINITE); 55 | 56 | if( returnCode != WAIT_OBJECT_0) 57 | { 58 | result = UMOCK_THREADAPI_ERROR; 59 | LogLastError("Error waiting for Single Object. Return Code: %lu. Error Code: %" PRI_MU_ENUM "", returnCode, MU_ENUM_VALUE(UMOCK_THREADAPI_RESULT, result)); 60 | } 61 | else 62 | { 63 | if (res != NULL) 64 | { 65 | DWORD exit_code; 66 | if (!GetExitCodeThread(thread_handle, &exit_code)) //If thread end is signaled we need to get the Thread Exit Code; 67 | { 68 | result = UMOCK_THREADAPI_ERROR; 69 | LogError("Error Getting Exit Code. Error Code: %u.", (unsigned int)GetLastError()); 70 | } 71 | else 72 | { 73 | *res = (int)exit_code; 74 | } 75 | } 76 | } 77 | CloseHandle(thread_handle); 78 | } 79 | 80 | return result; 81 | } 82 | 83 | void umock_threadapi_sleep(unsigned int milliseconds) 84 | { 85 | Sleep(milliseconds); 86 | } 87 | -------------------------------------------------------------------------------- /tests/umock_c_with_lock_factory_int/umock_c_with_lock_factory_int.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | #include "macro_utils/macro_utils.h" // IWYU pragma: keep 7 | 8 | // TEST_DEFINE_ENUM_TYPE will use wchar.h, which we technically get from testrunnerswitcher.h 9 | // IWYU pragma: no_include 10 | #include "testrunnerswitcher.h" 11 | 12 | #include "umock_c/umock_lock_factory_default.h" 13 | #include "minipal/umock_threadapi.h" 14 | 15 | #define ENABLE_MOCKS 16 | 17 | #include "umock_c/umock_c.h" 18 | 19 | MOCKABLE_FUNCTION(, void, test_mock_function, int, arg); 20 | 21 | #undef ENABLE_MOCKS 22 | 23 | MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) 24 | TEST_DEFINE_ENUM_TYPE(UMOCK_THREADAPI_RESULT, UMOCK_THREADAPI_RESULT_VALUES); 25 | 26 | static void test_on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 27 | { 28 | ASSERT_FAIL("umock_c reported error :%s", MU_ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code)); 29 | } 30 | 31 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 32 | 33 | TEST_SUITE_INITIALIZE(suite_init) 34 | { 35 | ASSERT_ARE_EQUAL(int, 0, umock_c_init_with_lock_factory(test_on_umock_c_error, umock_lock_factory_create_lock, NULL)); 36 | } 37 | 38 | TEST_SUITE_CLEANUP(suite_cleanup) 39 | { 40 | umock_c_deinit(); 41 | } 42 | 43 | TEST_FUNCTION_INITIALIZE(test_function_init) 44 | { 45 | umock_c_reset_all_calls(); 46 | } 47 | 48 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 49 | { 50 | } 51 | 52 | #if USE_VALGRIND 53 | #define THREAD_COUNT 8 54 | #define CALLS_PER_THREAD 500 55 | #else 56 | #define THREAD_COUNT 8 57 | #define CALLS_PER_THREAD 5000 58 | #endif 59 | 60 | static int actual_calls_thread(void* arg) 61 | { 62 | size_t i; 63 | 64 | (void)arg; 65 | 66 | for (i = 0; i < CALLS_PER_THREAD; i++) 67 | { 68 | test_mock_function(0); 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | TEST_FUNCTION(expected_calls_and_actual_calls_from_multiple_threads_do_not_crash) 75 | { 76 | // arrange 77 | UMOCK_THREAD_HANDLE threads[THREAD_COUNT]; 78 | size_t i; 79 | 80 | for (i = 0; i < CALLS_PER_THREAD * THREAD_COUNT; i++) 81 | { 82 | STRICT_EXPECTED_CALL(test_mock_function(0)); 83 | } 84 | 85 | for (i = 0; i < THREAD_COUNT; i++) 86 | { 87 | ASSERT_ARE_EQUAL(UMOCK_THREADAPI_RESULT, UMOCK_THREADAPI_OK, umock_threadapi_create(&threads[i], actual_calls_thread, NULL)); 88 | } 89 | 90 | // act 91 | for (i = 0; i < THREAD_COUNT; i++) 92 | { 93 | int dont_care; 94 | ASSERT_ARE_EQUAL(UMOCK_THREADAPI_RESULT, UMOCK_THREADAPI_OK, umock_threadapi_join(threads[i], &dont_care)); 95 | } 96 | 97 | // assert 98 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_expected_calls()); 99 | ASSERT_ARE_EQUAL(char_ptr, "", umock_c_get_actual_calls()); 100 | } 101 | 102 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 103 | -------------------------------------------------------------------------------- /tests/umock_c_wout_init_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_c_wout_init_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_c_wout_init_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ../../src/umock_c.c 12 | ) 13 | 14 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 15 | -------------------------------------------------------------------------------- /tests/umock_c_wout_init_ut/main.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include "testrunnerswitcher.h" 6 | 7 | int main(void) 8 | { 9 | size_t failedTestCount = 0; 10 | RUN_TEST_SUITE(umock_c_without_init_unittests, failedTestCount); 11 | return failedTestCount; 12 | } 13 | -------------------------------------------------------------------------------- /tests/umock_lock_factory_pthread_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_lock_factory_pthread_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_lock_factory_pthread_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umock_lock_factory_pthread_mocked.c 12 | ../../src/ 13 | ) 14 | 15 | set(${theseTestsName}_h_files 16 | ) 17 | 18 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" pthread) 19 | -------------------------------------------------------------------------------- /tests/umock_lock_factory_pthread_ut/umock_lock_factory_pthread_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | 7 | void* mock_malloc(size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_free(ptr) mock_free(ptr) 12 | 13 | #define pthread_rwlock_init(rwlock, attr) mock_pthread_rwlock_init(rwlock, attr) 14 | #define pthread_rwlock_rdlock(rwlock) mock_pthread_rwlock_rdlock(rwlock) 15 | #define pthread_rwlock_unlock(rwlock) mock_pthread_rwlock_unlock(rwlock) 16 | #define pthread_rwlock_wrlock(rwlock) mock_pthread_rwlock_wrlock(rwlock) 17 | #define pthread_rwlock_destroy(rwlock) mock_pthread_rwlock_destroy(rwlock) 18 | 19 | int mock_pthread_rwlock_init(pthread_rwlock_t *rwlock, 20 | const pthread_rwlockattr_t *attr); 21 | int mock_pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); 22 | int mock_pthread_rwlock_unlock(pthread_rwlock_t *rwlock); 23 | int mock_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); 24 | int mock_pthread_rwlock_destroy(pthread_rwlock_t *rwlock); 25 | 26 | /* include code under test */ 27 | #include "../../src/umock_lock_factory_pthread.c" 28 | -------------------------------------------------------------------------------- /tests/umock_lock_factory_windows_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umock_lock_factory_windows_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umock_lock_factory_windows_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umock_lock_factory_windows_mocked.c 12 | ../../src/ 13 | ) 14 | 15 | set(${theseTestsName}_h_files 16 | ) 17 | 18 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 19 | -------------------------------------------------------------------------------- /tests/umock_lock_factory_windows_ut/umock_lock_factory_windows_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | #include "windows.h" 7 | 8 | void* mock_malloc(size_t size); 9 | void mock_free(void* ptr); 10 | 11 | #define umockalloc_malloc(size) mock_malloc(size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | #define InitializeSRWLock(SRWLock) mock_InitializeSRWLock(SRWLock) 15 | #define AcquireSRWLockShared(SRWLock) mock_AcquireSRWLockShared(SRWLock) 16 | #define ReleaseSRWLockShared(SRWLock) mock_ReleaseSRWLockShared(SRWLock) 17 | #define AcquireSRWLockExclusive(SRWLock) mock_AcquireSRWLockExclusive(SRWLock) 18 | #define ReleaseSRWLockExclusive(SRWLock) mock_ReleaseSRWLockExclusive(SRWLock) 19 | 20 | void mock_InitializeSRWLock(PSRWLOCK SRWLock); 21 | void mock_AcquireSRWLockShared(PSRWLOCK SRWLock); 22 | void mock_ReleaseSRWLockShared(PSRWLOCK SRWLock); 23 | void mock_AcquireSRWLockExclusive(PSRWLOCK SRWLock); 24 | void mock_ReleaseSRWLockExclusive(PSRWLOCK SRWLock); 25 | 26 | /* include code under test */ 27 | #include "../../src/umock_lock_factory_windows.c" 28 | -------------------------------------------------------------------------------- /tests/umockalloc_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umockalloc_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umockalloc_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umockalloc_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umockalloc_ut/umockalloc_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_calloc(size_t nmemb, size_t size); 8 | void* mock_realloc(void* ptr, size_t size); 9 | void mock_free(void* ptr); 10 | 11 | #define malloc(size) mock_malloc(size) 12 | #define calloc(nmemb, size) mock_calloc(nmemb, size) 13 | #define realloc(ptr, size) mock_realloc(ptr, size) 14 | #define free(ptr) mock_free(ptr) 15 | 16 | /* include code under test */ 17 | #include "../../src/umockalloc.c" 18 | -------------------------------------------------------------------------------- /tests/umockautoignoreargs_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umockautoignoreargs_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umockautoignoreargs_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ../../src/umockautoignoreargs.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umockcall_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umockcall_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umockcall_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umockcall_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umockcall_ut/umockcall_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umockcall.c" 16 | -------------------------------------------------------------------------------- /tests/umockcallpairs_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umockcallpairs_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umockcallpairs_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umockcallpairs_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umockcallpairs_ut/umockcallpairs_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umockcallpairs.c" 16 | -------------------------------------------------------------------------------- /tests/umockcallrecorder_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umockcallrecorder_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umockcallrecorder_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umockcallrecorder_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umockcallrecorder_ut/umockcallrecorder_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umockcallrecorder.c" 16 | -------------------------------------------------------------------------------- /tests/umockstring_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umockstring_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umockstring_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umockstring_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umockstring_ut/umockstring_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void mock_free(void* ptr); 8 | 9 | #define umockalloc_malloc(size) mock_malloc(size) 10 | #define umockalloc_free(ptr) mock_free(ptr) 11 | 12 | /* include code under test */ 13 | #include "../../src/umockstring.c" 14 | -------------------------------------------------------------------------------- /tests/umockstring_ut/umockstring_ut.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include // for strlen 6 | 7 | #include "testrunnerswitcher.h" 8 | #include "umock_c/umockstring.h" 9 | 10 | typedef struct test_malloc_CALL_TAG 11 | { 12 | size_t size; 13 | } test_malloc_CALL; 14 | 15 | static test_malloc_CALL* test_malloc_calls; 16 | static size_t test_malloc_call_count; 17 | static size_t when_shall_malloc_fail; 18 | 19 | 20 | void* mock_malloc(size_t size) 21 | { 22 | void* result; 23 | 24 | test_malloc_CALL* new_calls = realloc(test_malloc_calls, sizeof(test_malloc_CALL) * (test_malloc_call_count + 1)); 25 | if (new_calls != NULL) 26 | { 27 | test_malloc_calls = new_calls; 28 | test_malloc_calls[test_malloc_call_count].size = size; 29 | test_malloc_call_count++; 30 | } 31 | 32 | if (when_shall_malloc_fail == test_malloc_call_count) 33 | { 34 | result = NULL; 35 | } 36 | else 37 | { 38 | result = malloc(size); 39 | } 40 | 41 | return result; 42 | } 43 | 44 | 45 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 46 | 47 | TEST_SUITE_INITIALIZE(suite_init) 48 | { 49 | } 50 | 51 | TEST_SUITE_CLEANUP(suite_cleanup) 52 | { 53 | } 54 | 55 | TEST_FUNCTION_INITIALIZE(test_function_init) 56 | { 57 | when_shall_malloc_fail = 0; 58 | 59 | test_malloc_calls = NULL; 60 | test_malloc_call_count = 0; 61 | } 62 | 63 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 64 | { 65 | free(test_malloc_calls); 66 | test_malloc_calls = NULL; 67 | test_malloc_call_count = 0; 68 | } 69 | 70 | /* umockstring_clone */ 71 | 72 | /* Tests_UMOCK_STRING_01_001: [ umockstring_clone shall allocate memory for the cloned string (including the NULL terminator). ]*/ 73 | /* Tests_UMOCK_STRING_01_002: [ umockstring_clone shall copy the string to the newly allocated memory (including the NULL terminator). ]*/ 74 | /* Tests_UMOCK_STRING_01_003: [ On success umockstring_clone shall return a pointer to the newly allocated memory containing the copy of the string. ]*/ 75 | TEST_FUNCTION(umockstring_clone_with_an_empty_string_succeeds) 76 | { 77 | // arrange 78 | char* result; 79 | 80 | // act 81 | result = umockstring_clone(""); 82 | 83 | // assert 84 | ASSERT_ARE_EQUAL(char_ptr, "", result); 85 | ASSERT_ARE_EQUAL(size_t, 1, test_malloc_call_count); 86 | ASSERT_ARE_EQUAL(size_t, 1, test_malloc_calls[0].size); 87 | 88 | // cleanup 89 | free(result); 90 | } 91 | 92 | /* Tests_UMOCK_STRING_01_001: [ umockstring_clone shall allocate memory for the cloned string (including the NULL terminator). ]*/ 93 | /* Tests_UMOCK_STRING_01_002: [ umockstring_clone shall copy the string to the newly allocated memory (including the NULL terminator). ]*/ 94 | /* Tests_UMOCK_STRING_01_003: [ On success umockstring_clone shall return a pointer to the newly allocated memory containing the copy of the string. ]*/ 95 | TEST_FUNCTION(umockstring_clone_with_a_one_char_string_succeeds) 96 | { 97 | // arrange 98 | char* result; 99 | 100 | // act 101 | result = umockstring_clone("a"); 102 | 103 | // assert 104 | ASSERT_ARE_EQUAL(char_ptr, "a", result); 105 | ASSERT_ARE_EQUAL(size_t, 1, test_malloc_call_count); 106 | ASSERT_ARE_EQUAL(size_t, 2, test_malloc_calls[0].size); 107 | 108 | // cleanup 109 | free(result); 110 | } 111 | 112 | /* Tests_UMOCK_STRING_01_001: [ umockstring_clone shall allocate memory for the cloned string (including the NULL terminator). ]*/ 113 | /* Tests_UMOCK_STRING_01_002: [ umockstring_clone shall copy the string to the newly allocated memory (including the NULL terminator). ]*/ 114 | /* Tests_UMOCK_STRING_01_003: [ On success umockstring_clone shall return a pointer to the newly allocated memory containing the copy of the string. ]*/ 115 | TEST_FUNCTION(umockstring_clone_with_a_longer_string_succeeds) 116 | { 117 | // arrange 118 | char* result; 119 | 120 | // act 121 | result = umockstring_clone("Management takes the code out of you"); 122 | 123 | // assert 124 | ASSERT_ARE_EQUAL(char_ptr, "Management takes the code out of you", result); 125 | ASSERT_ARE_EQUAL(size_t, 1, test_malloc_call_count); 126 | ASSERT_ARE_EQUAL(size_t, strlen("Management takes the code out of you") + 1, test_malloc_calls[0].size); 127 | 128 | // cleanup 129 | free(result); 130 | } 131 | 132 | /* Tests_UMOCK_STRING_01_004: [ If allocating the memory fails, umockstring_clone shall return NULL. ]*/ 133 | TEST_FUNCTION(when_allocating_memory_fails_umockstring_clone_fails) 134 | { 135 | // arrange 136 | char* result; 137 | 138 | when_shall_malloc_fail = 1; 139 | 140 | // act 141 | result = umockstring_clone("Management takes the code out of you"); 142 | 143 | // assert 144 | ASSERT_IS_NULL(result); 145 | ASSERT_ARE_EQUAL(size_t, 1, test_malloc_call_count); 146 | ASSERT_ARE_EQUAL(size_t, strlen("Management takes the code out of you") + 1, test_malloc_calls[0].size); 147 | } 148 | 149 | /* Tests_UMOCK_STRING_01_005: [ If umockstring_clone is called with a NULL source, it shall return NULL. ]*/ 150 | TEST_FUNCTION(umockstring_clone_called_with_NULL_fails) 151 | { 152 | // arrange 153 | char* result; 154 | 155 | // act 156 | result = umockstring_clone(NULL); 157 | 158 | // assert 159 | ASSERT_IS_NULL(result); 160 | ASSERT_ARE_EQUAL(size_t, 0, test_malloc_call_count); 161 | } 162 | 163 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 164 | -------------------------------------------------------------------------------- /tests/umocktypename_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypename_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypename_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypename_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypename_ut/umocktypename_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypename.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypename_ut/umocktypename_ut.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | #include "testrunnerswitcher.h" 7 | #include "umock_c/umocktypename.h" 8 | 9 | static size_t malloc_call_count; 10 | static size_t realloc_call_count; 11 | 12 | static size_t when_shall_malloc_fail; 13 | static size_t when_shall_realloc_fail; 14 | 15 | 16 | void* mock_malloc(size_t size) 17 | { 18 | void* result; 19 | malloc_call_count++; 20 | if (malloc_call_count == when_shall_malloc_fail) 21 | { 22 | result = NULL; 23 | } 24 | else 25 | { 26 | result = malloc(size); 27 | } 28 | return result; 29 | } 30 | 31 | void* mock_realloc(void* ptr, size_t size) 32 | { 33 | void* result; 34 | realloc_call_count++; 35 | if (realloc_call_count == when_shall_realloc_fail) 36 | { 37 | result = NULL; 38 | } 39 | else 40 | { 41 | result = realloc(ptr, size); 42 | } 43 | return result; 44 | } 45 | 46 | void mock_free(void* ptr) 47 | { 48 | free(ptr); 49 | } 50 | 51 | 52 | BEGIN_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 53 | 54 | TEST_SUITE_INITIALIZE(suite_init) 55 | { 56 | } 57 | 58 | TEST_SUITE_CLEANUP(suite_cleanup) 59 | { 60 | } 61 | 62 | TEST_FUNCTION_INITIALIZE(test_function_init) 63 | { 64 | malloc_call_count = 0; 65 | when_shall_malloc_fail = 0; 66 | realloc_call_count = 0; 67 | when_shall_realloc_fail = 0; 68 | } 69 | 70 | TEST_FUNCTION_CLEANUP(test_function_cleanup) 71 | { 72 | } 73 | 74 | /* umocktypename_normalize */ 75 | 76 | /* Tests_SRS_UMOCKTYPENAME_01_001: [ umocktypename_normalize shall return a char\* with a newly allocated string that contains the normalized typename. ]*/ 77 | TEST_FUNCTION(umocktypename_normalize_returns_the_same_string_when_already_normalized) 78 | { 79 | // arrange 80 | 81 | // act 82 | char* result = umocktypename_normalize("char"); 83 | 84 | // assert 85 | ASSERT_ARE_EQUAL(char_ptr, "char", result); 86 | 87 | // cleanup 88 | free(result); 89 | } 90 | 91 | /* Tests_SRS_UMOCKTYPENAME_01_005: [ If typename is NULL, then umocktypename_normalize shall fail and return NULL. ]*/ 92 | TEST_FUNCTION(umocktypename_normalize_with_NULL_returns_NULL) 93 | { 94 | // arrange 95 | 96 | // act 97 | char* result = umocktypename_normalize(NULL); 98 | 99 | // assert 100 | ASSERT_IS_NULL(result); 101 | } 102 | 103 | /* Tests_SRS_UMOCKTYPENAME_01_004: [ umocktypename_normalize shall remove all extra spaces (more than 1 space) between elements that are part of the typename. ]*/ 104 | TEST_FUNCTION(umocktypename_normalize_removes_1_extra_space_between_2_words) 105 | { 106 | // arrange 107 | 108 | // act 109 | char* result = umocktypename_normalize("const char"); 110 | 111 | // assert 112 | ASSERT_ARE_EQUAL(char_ptr, "const char", result); 113 | 114 | // cleanup 115 | free(result); 116 | } 117 | 118 | /* Tests_SRS_UMOCKTYPENAME_01_004: [ umocktypename_normalize shall remove all extra spaces (more than 1 space) between elements that are part of the typename. ]*/ 119 | TEST_FUNCTION(umocktypename_normalize_removes_2_extra_spaces_between_2_words) 120 | { 121 | // arrange 122 | 123 | // act 124 | char* result = umocktypename_normalize("const char"); 125 | 126 | // assert 127 | ASSERT_ARE_EQUAL(char_ptr, "const char", result); 128 | 129 | // cleanup 130 | free(result); 131 | } 132 | 133 | /* Tests_SRS_UMOCKTYPENAME_01_006: [ No space shall exist between any other token and a star. ]*/ 134 | TEST_FUNCTION(umocktypename_normalize_removes_the_space_before_a_star) 135 | { 136 | // arrange 137 | 138 | // act 139 | char* result = umocktypename_normalize("char *"); 140 | 141 | // assert 142 | ASSERT_ARE_EQUAL(char_ptr, "char*", result); 143 | 144 | // cleanup 145 | free(result); 146 | } 147 | 148 | /* Tests_SRS_UMOCKTYPENAME_01_006: [ No space shall exist between any other token and a star. ]*/ 149 | TEST_FUNCTION(umocktypename_normalize_removes_the_space_after_a_star) 150 | { 151 | // arrange 152 | 153 | // act 154 | char* result = umocktypename_normalize("char* const"); 155 | 156 | // assert 157 | ASSERT_ARE_EQUAL(char_ptr, "char*const", result); 158 | 159 | // cleanup 160 | free(result); 161 | } 162 | 163 | /* Tests_SRS_UMOCKTYPENAME_01_002: [** umocktypename_normalize shall remove all spaces at the beginning of the typename. ] ]*/ 164 | TEST_FUNCTION(umocktypename_normalize_removes_1_space_at_the_beginning) 165 | { 166 | // arrange 167 | 168 | // act 169 | char* result = umocktypename_normalize(" char"); 170 | 171 | // assert 172 | ASSERT_ARE_EQUAL(char_ptr, "char", result); 173 | 174 | // cleanup 175 | free(result); 176 | } 177 | 178 | /* Tests_SRS_UMOCKTYPENAME_01_002: [** umocktypename_normalize shall remove all spaces at the beginning of the typename. ] ]*/ 179 | TEST_FUNCTION(umocktypename_normalize_removes_2_spaces_at_the_beginning) 180 | { 181 | // arrange 182 | 183 | // act 184 | char* result = umocktypename_normalize(" char"); 185 | 186 | // assert 187 | ASSERT_ARE_EQUAL(char_ptr, "char", result); 188 | 189 | // cleanup 190 | free(result); 191 | } 192 | 193 | /* Tests_SRS_UMOCKTYPENAME_01_007: [ If the length of the normalized typename is 0, umocktypename_normalize shall return NULL. ]*/ 194 | TEST_FUNCTION(umocktypename_normalize_for_a_zero_length_normalized_typename_returns_NULL) 195 | { 196 | // arrange 197 | 198 | // act 199 | char* result = umocktypename_normalize(" "); 200 | 201 | // assert 202 | ASSERT_IS_NULL(result); 203 | } 204 | 205 | /* Tests_SRS_UMOCKTYPENAME_01_003: [ umocktypename_normalize shall remove all spaces at the end of the typename. ] */ 206 | TEST_FUNCTION(umocktypename_normalize_removes_1_space_at_the_end) 207 | { 208 | // arrange 209 | 210 | // act 211 | char* result = umocktypename_normalize("char "); 212 | 213 | // assert 214 | ASSERT_ARE_EQUAL(char_ptr, "char", result); 215 | 216 | // cleanup 217 | free(result); 218 | } 219 | 220 | /* Tests_SRS_UMOCKTYPENAME_01_003: [ umocktypename_normalize shall remove all spaces at the end of the typename. ] */ 221 | TEST_FUNCTION(umocktypename_normalize_removes_2_spaces_at_the_end) 222 | { 223 | // arrange 224 | 225 | // act 226 | char* result = umocktypename_normalize("char "); 227 | 228 | // assert 229 | ASSERT_ARE_EQUAL(char_ptr, "char", result); 230 | 231 | // cleanup 232 | free(result); 233 | } 234 | 235 | /* Tests_SRS_UMOCKTYPENAME_01_001: [ umocktypename_normalize shall return a char\* with a newly allocated string that contains the normalized typename. ]*/ 236 | TEST_FUNCTION(umocktypename_normalize_succeeds_with_a_type_that_ends_in_star) 237 | { 238 | // arrange 239 | 240 | // act 241 | char* result = umocktypename_normalize("char*"); 242 | 243 | // assert 244 | ASSERT_ARE_EQUAL(char_ptr, "char*", result); 245 | 246 | // cleanup 247 | free(result); 248 | } 249 | 250 | /* Tests_SRS_UMOCKTYPENAME_01_008: [ If allocating memory fails, umocktypename_normalize shall fail and return NULL. ]*/ 251 | TEST_FUNCTION(when_allocating_memory_Fails_umocktypename_normalize_fails) 252 | { 253 | // arrange 254 | char* result; 255 | 256 | when_shall_malloc_fail = 1; 257 | 258 | // act 259 | result = umocktypename_normalize("char*"); 260 | 261 | // assert 262 | ASSERT_IS_NULL(result); 263 | } 264 | 265 | END_TEST_SUITE(TEST_SUITE_NAME_FROM_CMAKE) 266 | -------------------------------------------------------------------------------- /tests/umocktypes_bool_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_bool_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_bool_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_bool_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypes_bool_ut/umocktypes_bool_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes_bool.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_c_fixed_buffer_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_c_fixed_buffer_ut) 5 | 6 | add_definitions(-DMAX_UMOCK_TYPE_STRINGIFY_SIZE=128) 7 | add_definitions(-DTHIS_TEST_SUITE_NAME=umocktypes_c_fixed_buffer_unittests) 8 | 9 | set(${theseTestsName}_test_files 10 | ../umocktypes_c_ut/umocktypes_c_ut.c 11 | ) 12 | 13 | set(${theseTestsName}_c_files 14 | ../umocktypes_c_ut/umocktypes_c_mocked.c 15 | ) 16 | 17 | set(${theseTestsName}_h_files 18 | ) 19 | 20 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 21 | -------------------------------------------------------------------------------- /tests/umocktypes_c_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_c_ut) 5 | 6 | # The code in this unit test is shared by umocktypes_c_fixed_buffer_ut 7 | add_definitions(-DTHIS_TEST_SUITE_NAME=umocktypes_c_unittests) 8 | 9 | set(${theseTestsName}_test_files 10 | umocktypes_c_ut.c 11 | ) 12 | 13 | set(${theseTestsName}_c_files 14 | umocktypes_c_mocked.c 15 | ) 16 | 17 | set(${theseTestsName}_h_files 18 | ) 19 | 20 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 21 | -------------------------------------------------------------------------------- /tests/umocktypes_c_ut/umocktypes_c_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes_c.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_charptr_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_charptr_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_charptr_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_charptr_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypes_charptr_ut/umocktypes_charptr_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes_charptr.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_stdint_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_stdint_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_stdint_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_stdint_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypes_stdint_ut/umocktypes_stdint_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes_stdint.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_struct_int/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_struct_int) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_struct_int.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | ) 12 | 13 | set(${theseTestsName}_h_files 14 | ) 15 | 16 | build_test_artifacts(${theseTestsName} "tests/umockc_tests" umock_c) 17 | -------------------------------------------------------------------------------- /tests/umocktypes_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_mocked.c 12 | ../../src/umockalloc.c 13 | ) 14 | 15 | set(${theseTestsName}_h_files 16 | ) 17 | 18 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 19 | -------------------------------------------------------------------------------- /tests/umocktypes_ut/umocktypes_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_wcharptr_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_wcharptr_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_wcharptr_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_wcharptr_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypes_wcharptr_ut/umocktypes_wcharptr_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes_wcharptr.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_windows_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_windows_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_windows_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_windows_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypes_windows_ut/umocktypes_windows_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes_windows.c" 16 | -------------------------------------------------------------------------------- /tests/umocktypes_wout_init_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | set(theseTestsName umocktypes_wout_init_ut) 5 | 6 | set(${theseTestsName}_test_files 7 | umocktypes_wout_init_ut.c 8 | ) 9 | 10 | set(${theseTestsName}_c_files 11 | umocktypes_mocked.c 12 | ) 13 | 14 | set(${theseTestsName}_h_files 15 | ) 16 | 17 | build_test_artifacts(${theseTestsName} "tests/umockc_tests") 18 | -------------------------------------------------------------------------------- /tests/umocktypes_wout_init_ut/umocktypes_mocked.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | 6 | void* mock_malloc(size_t size); 7 | void* mock_realloc(void* ptr, size_t size); 8 | void mock_free(void* ptr); 9 | 10 | #define umockalloc_malloc(size) mock_malloc(size) 11 | #define umockalloc_realloc(ptr, size) mock_realloc(ptr, size) 12 | #define umockalloc_free(ptr) mock_free(ptr) 13 | 14 | /* include code under test */ 15 | #include "../../src/umocktypes.c" 16 | --------------------------------------------------------------------------------