{"id":20834529,"url":"https://github.com/apriorit/gmock-global","last_synced_at":"2025-10-12T22:32:00.216Z","repository":{"id":26084904,"uuid":"100035326","full_name":"apriorit/gmock-global","owner":"apriorit","description":"Provides ability to mock global functions with gmock","archived":false,"fork":false,"pushed_at":"2024-08-02T11:44:09.000Z","size":31,"stargazers_count":73,"open_issues_count":4,"forks_count":24,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-01-22T07:07:04.021Z","etag":null,"topics":["cpp","gmock","gtest","header-only","library","mock","mocking","unittest"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apriorit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-11T13:36:50.000Z","updated_at":"2025-01-11T20:36:19.000Z","dependencies_parsed_at":"2024-12-31T19:12:10.478Z","dependency_job_id":"d42cbe3e-7901-4125-be97-460a9e039a8b","html_url":"https://github.com/apriorit/gmock-global","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apriorit%2Fgmock-global","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apriorit%2Fgmock-global/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apriorit%2Fgmock-global/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apriorit%2Fgmock-global/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apriorit","download_url":"https://codeload.github.com/apriorit/gmock-global/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236279853,"owners_count":19123451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","gmock","gtest","header-only","library","mock","mocking","unittest"],"created_at":"2024-11-18T00:19:34.088Z","updated_at":"2025-10-12T22:31:54.923Z","avatar_url":"https://github.com/apriorit.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gmock-global [![Build Status](https://github.com/apriorit/gmock-global/actions/workflows/ci.yml/badge.svg)](https://github.com/apriorit/gmock-global/actions/workflows/ci.yml)\n\nThis header-only library implements [gmock](https://github.com/google/googletest/blob/master/googlemock) functionality for global functions. \n\n- [Introduction](#introduction)\n- [Usage](#usage)\n  - [Step 1: Adding includes](#step-1-adding-includes)\n  - [Step 2: Declare mock global](#step-2-declare-mock-global)\n- [Known issues](#known-issues)\n- [Samples](#samples)\n- [License](#license)\n- [Version history](#version-history)\n  - [Version 1.0.2 (28 Aug 2019)](#version-102-28-aug-2019)\n  - [Version 1.0.1 (19 Apr 2019)](#version-101-19-apr-2019)\n  - [Version 1.0.0 (17 Oct 2017)](#version-100-17-oct-2017)\n  \n# Introduction\n[Gmock](https://github.com/google/googletest/blob/master/googlemock) is a C++ framework for writing [mock classes](https://en.wikipedia.org/wiki/Mock_object). It is very convenient to create mock objects for mocking of methods. But [gmock](https://github.com/google/googletest/blob/master/googlemock) can not mock global functions. This problem is quite common but has no trivial solution. [Gmock FAQ](https://github.com/google/googlemock/blob/master/googlemock/docs/FrequentlyAskedQuestions.md#my-code-calls-a-staticglobal-function--can-i-mock-it) says you are doing something wrong if you need to mock static or global functions. However it is required in some cases and [gmock-global](https://github.com/apriorit/gmock-global) provides such functionality.\n\n## Supported environment\n- gmock version 1.8.1-1.15.2 (older versions may work too but they are not covered by CI)\n- gcc/clang/msvc\n\n# Usage\n\n## Step 1: Adding includes\nAt first your project needs to know about [gmock-global](https://github.com/apriorit/gmock-global).\n1. Add `gmock-global/include` to the project include paths.\n2. Add `#include \u003cgmock-global/gmock-global.h\u003e` after [gmock](https://github.com/google/googletest/blob/master/googlemock) include.\n\n## Step 2: Declare mock global\nSyntax is most similar to [gmock](https://github.com/google/googletest/blob/master/googlemock). For example, to mock function `multiply` with two `double` arguments and `double` result you have to write declaration: \n```cpp\nMOCK_GLOBAL_FUNC2(multiply, double(double, double));\n```\nYou can check call count of such function using `EXPECT_GLOBAL_CALL` macro, same as you used `EXPECT_CALL` macro for classes: \n```cpp\nEXPECT_GLOBAL_CALL(multiply, multiply(1, 2));\n```\n\nThe `.Times(...)` and other methods will be work too.\n\nIn result mocking of global `double multiply(double, double)` looks like:\n```cpp\nMOCK_GLOBAL_FUNC2(multiply, double(double, double));\n\n...\n\nTEST(TestGlobal, CanMultiplyGlobal)\n{\n    EXPECT_GLOBAL_CALL(multiply, multiply(1, 2)).Times(1);\n    multiply(1, 2);\n}\n```\n\nAlso you can use `ON_GLOBAL_CALL` to specify default behavior. `ON_GLOBAL_NICE_CALL` can be used to set default behavior with suppressed warning when this mock was actually called.\n\n[gmock-global](https://github.com/apriorit/gmock-global) supports more than 10 arguments with [gtest version 1.8.1](https://github.com/google/googletest/releases/tag/release-1.8.1). But it requires [gmock-more-args version 1.0.1](https://github.com/apriorit/gmock-more-args/releases/tag/1.0.1) in case you use [gtest version 1.8.0](https://github.com/google/googletest/releases/tag/release-1.8.0)\n\n# Known issues\nThe [after clause](https://github.com/google/googletest/blob/master/googlemock/docs/CheatSheet.md#the-after-clause) can't be using with [gmock-global](https://github.com/apriorit/gmock-global), use `Sequences` instead.\n\n# Samples\nTake a look at the test [sample](https://github.com/apriorit/gmock-global/tree/master/sample).\n\n# License\n[gmock-global](https://github.com/apriorit/gmock-global) is licensed under the MIT License. You can freely use it in your commercial or opensource software.\n\n# Version history\n\n## Version 1.0.2 (28 Aug 2019)\n- Added ON_GLOBAL_CALL (#4)\n- Segmentation fault when executing tests on a function that has been mocked in another test (#2)\n\n## Version 1.0.1 (19 Apr 2019)\n- Specified compatibility with gtest 1.8.1\n- Fixed warnings\n\n## Version 1.0.0 (17 Oct 2017)\n- Initial public release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapriorit%2Fgmock-global","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapriorit%2Fgmock-global","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapriorit%2Fgmock-global/lists"}