1,171 questions
Best practices
0 votes
5 replies
77 views
How to intercept calls to a function that returns file paths in gmock
I am working on a C++ code base that has a function called "getConfigFilePath()" in name space "utils" which returns the file path to a config file. The config file is really hard-...
1 vote
1 answer
43 views
How to test via ON_CALL for any enum value in an overloaded function
I have a class that has two functions with the same name and number of arguments. I wish to provide a default return value via ON_CALL. From reading around the matcher code - I have come to a partial ...
1 vote
1 answer
82 views
Diff btw "Invoke( lambda )" and directly calling a lambda when we use Google Mock EXPECT_CALL
Since I learnt to use Google Test/Mock framework, I allways used the form to setup an expectation as following: EXPECT_CALL( mock_obj, mock_method ).WillOnce( Invoke( []() { do_things; } ) ); Few ...
0 votes
1 answer
69 views
Gmock WillByDefault triggered despite matching EXPECT_CALL
I am using the WillByDefault(testing::Throw(...)) trick to terminate the test early, as described in https://stackoverflow.com/a/79534623/2894535 However, it seems to randomly trigger in some cases, ...
5 votes
1 answer
89 views
Return alternating values from mock
I want to test a function where one of its mocks should return alternating values many times. So e.g. I need something like this: EXPECT_CALL(my_mock, foo(_)) .WillOnce(Return(A)) .WillOnce(...
0 votes
1 answer
46 views
Use of gmock Field matcher with bitfields
I am trying to create a gmock matcher for a structure which contains bitfields: struct s { uint32_t x; uint32_t y : 12; uint32_t z : 20; }; I can create a testing::Field(&s::x, ...
5 votes
1 answer
444 views
How to stop gtest on first unexpected gmock call
Is there an equivalent to ASSERT_* for EXPECT_CALL, which ends the test on first uninteresting/unmatched call? I am using gtest+gmock to test HW register programming sequences, so all EXPECT_CALL are ...
2 votes
1 answer
63 views
Make one EXPECT_CALL unsequenced
I have a set of calls which I want to check in order, but they may be arbitrarily interspersed with a call to a log method. How can I tell gmock that that particular method can be called any number of ...
0 votes
0 answers
99 views
GMock leaks memory on 'Uninteresting mock function calls' since update
Since updating GTest framework from 1.8.x to 1.12.x, there have been a few tests that report memory leaks at the end of the test. I've stripped out all the complexity of our setups to the example ...
3 votes
1 answer
139 views
Google mock with `unique_ptr` and `std::move` object giving memory leak issue
This question is a follow-up on Google mock with unique_ptr object giving memory leak issue. My class under test takes owenership of the unique_ptr on its contructor: class Foo { public: virtual ...
0 votes
0 answers
69 views
Google mock global object triggers a segmentation fault/memory leak
I have the following setup for unit testing using googletest/gmock. class MockClass{ public: MOCK_METHOD0(log, void()); // -> this is fine MOCK_METHOD3(fcntl, int(int fd, int cmd, void* ...
2 votes
1 answer
102 views
How to test parameters/args in gtest/gmock within expect_call
i started unit-test with gtest and gmock. I want to test the content of an EXPECT_CALL in one line. How to do it the right way? My example code: class MockClientSignalEventHandler : public ...
0 votes
1 answer
123 views
Why does gmock capture only work reliably with an added Invoke in DoAll of an ON_CALL
In very short: the issue I face is that in an ON_CALL(...).WillByDefault(DoAll(..some capture..,Invoke([&captureValues]{..trace them...}))); the capture only works reliably if that "Invoke&...
0 votes
2 answers
154 views
How to mock dll function using Gmock?
I have searched on this and did not find much information. I have a below pattern of code where I have 1 class dedicated to load and unload dll in constructor and destructor respectively. Also the ...
2 votes
1 answer
278 views
How to blocking wait gmock object expect calls met
An operation will trigger another thread to call an expected fn(). Is that possible that main thread wait until the expectation meet? EXPECT_CALL(mockObj, fn()).Times(1); // operation will trigger ...