Sample project demonstrating how gmock_global works. It contains googletest submodule, gmock_global submodule, and source file with samples.
You can build this project using CMake.
This project demonstrates main usecases for a gmock_global. It's mocks several global functions with all possible counts of arguments (like in gmock is from 0 up to 10), and test calls count of them. It also demonstrates that several expectation in one TEST working too.
So, let's imagine you want to mock global function int sum2(int a, int b)
You should declare mock in a global scope:
MOCK_GLOBAL_FUNC2(sum2, int(int, int));
and use it in some TEST as follows:
TEST(SummizerTestGlobal2, CanSumGlobal2)
{
EXPECT_GLOBAL_CALL(sum2, sum2(1, 2)) .Times(1);
sum2(1, 2);
}
You can also specify different call convention using macro MOCK_GLOBAL_FUNC2_WITH_CALLTYPE(...)
placing as first argument the call convention name you want.