googlemock

Mocking free function

别说谁变了你拦得住时间么 提交于 2019-12-17 06:46:11
问题 I am stuck in a problem and can't seem to find the solution. I am using VS2005 SP1 for compiling the code. I have a global function: A* foo(); I have a mock class class MockA : public A { public: MOCK_METHOD0 (bar, bool()); ... }; In the sources, it is accessed like this: foo()->bar() . I cannot find a way to mock this behavior. And I cannot change the sources, so the solution in google mock cook book is out of question. Any help or pointers in the right direction will be highly appreciated.

Can Google Mock a method with a smart pointer return type?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 06:27:35
问题 I have a factory that returns a smart pointer. Regardless of what smart pointer I use, I can't get Google Mock to mock the factory method. The mock object is the implementation of a pure abstract interface where all methods are virtual. I have a prototype: MOCK_METHOD0(Create, std::unique_ptr<IMyObjectThing>()); And I get: "...gmock/gmock-spec-builders.h(1314): error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'" The type

Actual function call count doesn't match EXPECT_CALL(*mock, display())

与世无争的帅哥 提交于 2019-12-11 18:22:56
问题 I'm calling EXPECT_CALL on a mocked function display() , but it is returning the run time error Actual function call count doesn't match EXPECT_CALL(*mock, display())... output ./GTest_static_example.tst [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from GTest_static_example [ RUN ] GTest_static_example.case1 inside the GTEST_static_class:: display display called from GTest_static_example package/web/webscr/GTest_static_example

Mocking free function

吃可爱长大的小学妹 提交于 2019-12-11 09:33:01
问题 I am stuck in a problem and can't seem to find the solution. I am using VS2005 SP1 for compiling the code. I have a global function: A* foo(); I have a mock class class MockA : public A { public: MOCK_METHOD0 (bar, bool()); ... }; In the sources, it is accessed like this: foo()->bar() . I cannot find a way to mock this behavior. And I cannot change the sources, so the solution in google mock cook book is out of question. Any help or pointers in the right direction will be highly appreciated.

How to compare special fields in google mock?

冷暖自知 提交于 2019-12-11 07:29:46
问题 I have got question connected with google test. I would like to ask if while inducing "EXPECT_CALL(*A, some_method(mes1));" in test case there is possiblity to compare fields included in mes1 class. struct Mes { int a; }; //short section of test case: Mes mes1 = Mes(); EXPECT_CALL(*A, some_method(mes1)); I would like to ask if in google mock is a possiblity to compare special fields included in Mes. Something like: EXPECT_CALL(*A, some_method(mes1), compare(Mes.a));//in this case google mock

Google mock global mock object memory leak

爷,独闯天下 提交于 2019-12-11 07:00:43
问题 I am using VS2005, and C++ for unit testing using google mock. I had a global free function in unit testing, and I used the following code to mock free function: NiceMock <MockA> mockObj; struct IFoo { virtual A* foo() = 0; virtual ~IFoo() {} }; struct FooMock : public IFoo { FooMock() {} virtual ~FooMock() {} MOCK_METHOD0(foo, A*()); }; FooMock fooMock; // foo() implementation A* foo() { return fooMock.foo(); } In the SetUp() function, I set Expectations on the global object like EXPECT_CALL

How to use Google Mock with CppUnitTestFramework

人走茶凉 提交于 2019-12-11 05:17:58
问题 TL;DR: You can use GMock to add mocking capability to your Microsoft native c++ unit tests. See my answer below for details. I want to start adding mocks to my existing set of native unit tests. The tests are written using Microsoft's CppUnitTestFramework framework, which doesn't have support for mocking. I don't really want to convert the entire test suite to another framework just to add a few mocks. Google's GMock framework seems to provide everything I need and the documentation suggests

Why does Google Test not print a stack trace or file name?

拥有回忆 提交于 2019-12-10 20:59:25
问题 When I use Google Test and Google Mock, with diagnostic level set to "info", I get messages like this: Uninteresting mock function call - taking default action specified at: src/pkgtest/test_Foo.cpp:216: Function call: GetBar() Returns: 4-byte object <00-00 00-00> Stack trace: Uninteresting mock function call - taking default action specified at: src/pkgtest/test_Foo.cpp:126: Function call: GetBaz() Returns: {} Stack trace: unknown file: Failure C++ exception with description "Uninteresting

How can I create a partial (hybrid) mock in googlemock?

本小妞迷上赌 提交于 2019-12-10 16:12:15
问题 Google suggests delegating calls to a parent object when you need to invoke functionality of the real object, however this does not really create a partial (hybrid) mock. When invoking the real object, any method calls are those of the real object and not the mock object, on which you may have set up actions/expectations. How do I create a partial mock that delegates only specific methods to the real object, and all other method calls to the mock object? Delegate to real object example using

How to Configure GoogleMock in Visual Studio 2017 After Already Installing GoogleTest?

笑着哭i 提交于 2019-12-10 14:49:59
问题 I installed the Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn package into my VS 2017 application solution. This was accomplished by adding a new GoogleTest project to my solution via "Add New Project/Other Languages/C++/Test/Google Test". The testing works well, but now I am ready to try some mocking with gmock. So, I installed googlemock.v140.windesktop.static.rt-dyn via NuGet, but I have no idea of how to get it integrated into my test project. My packages.config looks like