gmock

GMock passing a mocked object into another, and calling a stubed method is still calling real logic

ぐ巨炮叔叔 提交于 2019-12-14 04:22:40
问题 I'm trying to pass a mocked object to another object's method and call it, i get the same result as I would call real method. fooa.h - this is the real class #ifndef FOOA_H #define FOOA_H class FooA { public: FooA(); virtual int method(int a, int b, int c, int d); }; #endif // FOOA_H fooa.cpp #include "fooa.h" FooA::FooA() { } int FooA::method(int a, int b, int c, int d) { return a+b+c+d; } mockedfooa.h - mocked version of fooa #ifndef MOCKEDFOOA_H #define MOCKEDFOOA_H #include "fooa.h"

google mock with boost::test causes memory leak

跟風遠走 提交于 2019-12-12 04:44:34
问题 I am trying to create unit tests using boost::test and google mock. Adding a call to InitGoogleMock causes boost to signal some memory leaks. I searched for some sort of "DeInitGoogleMock" but didn't find any. Why does this memory leak come up? How can it be fixed? main.cpp: #include <gmock/gmock.h> #define BOOST_TEST_MODULE my_testt #include <boost/test/unit_test.hpp> struct InitGMock { InitGMock() { ::testing::GTEST_FLAG(throw_on_failure) = true; //::testing::InitGoogleMock(&boost::unit

Bad Reloc Address using MinGW

こ雲淡風輕ζ 提交于 2019-12-11 01:49:02
问题 I use MinGW on Windows 7 64bit. I used Google Test with NetBeans (followed Bo Qian instruction: http://www.youtube.com/watch?v=TS2CTf11k1U&feature=c4-overview-vl&list=PL5jc9xFGsL8GyES7nh-1yqljjdTvIFSsh&hd=1) and it worked correctly. Recently I tried to link Google Mock (with Google Test inside) to my project. I used Cmake and this is my CmakeLists.txt file: CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(FS_Report) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}) SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall

How can I test a call is made after a delay in google test using a mocking framework

南笙酒味 提交于 2019-12-10 22:47:44
问题 I'm currently trying to evaluate different testing frameworks. When using mocking frameworks (I'm leaning towards FakeIt, but google mock is good too), I know that you can roll your own "performance" testing by using the OS's timer calls before and after calling a function to verify the function's performance. This is not what I'm after. What I do have are classes that implement delays on outputs given certain inputs. For example: input 1 goes from low to high output 1 goes from low to high

Matching C-style array passed as void* with GMock

烈酒焚心 提交于 2019-12-10 14:17:24
问题 I'm trying to mock such function: int write(int fd, const void* buffer, size_t size, bool something) I want to check the correctness of data passed with buffer (first and last argument are not important for the test). There are few nice matchers to help us with that, namely ElementsAreArray. If the pointer was e.g. char* , then it's simple: EXPECT_CALL(myMock, write(_, NotNull(), expectedSize, _) .With(Args<1,2>(ElementsAreArray(dummyArray)); Problem: void* can't be dereferenced. Thus, it's

mock method with 11 parameters with gmock

邮差的信 提交于 2019-12-10 13:36:37
问题 I'm using gmock to mock my dependencies in legacy code. One of the class have a method with 11 parameters. When I tried to use MOCK_METHOD11_WITH_CALLTYPE to mock it, I found this macro doesn't exist. gmock only supoort up to 10 parameters. What do you suggest for this? Do I implement this method with dummy body? Or copy & extend the macro? Thanks! PS, I don't need to mock this method in my tests right now, but probably need to do so in the future. Best regards, 回答1: Methods with more than 10

Google Mock: Is it ok to use global mock objects?

本秂侑毒 提交于 2019-12-10 09:44:16
问题 In all the documentation about gmock I always find the mock object to be instantiated inside a test, like that: TEST(Bim, Bam) { MyMockClass myMockObj; EXPECT_CALL(MyMockObj, foo(_)); ... } So, the object is created and destroyed per test. I believe it's also perfectly fine to create and destroy the object per test fixture . But I'm wondering if it's also ok to have a file-global instance of the mock object, like that: MyMockClass myMockObj; TEST(Bim, Bam) { EXPECT_CALL(MyMockObj, foo(_)) ...

Mocking Parametrized Constructor using Gmock

喜欢而已 提交于 2019-12-08 17:19:01
问题 I have class to be mocked but it is not having default constructor. I cannot change the source code. So is there any way to mock a parametrized constructor using Gmock 回答1: Yes there is. Just let your Mock's constructor call the mocked class' constructor with the right arguments: class base_class { public: base_class(int, int) {} virtual int foo(int); }; class base_mock : public base_class { public: base_mock() : base_class(23, 42) {} MOCK_METHOD1(foo, int(int)); }; or even class base_mock :

What is the easiest way to invoke a member function on an argument passed to a mocked function?

不打扰是莪最后的温柔 提交于 2019-12-07 15:30:51
问题 Given the interfaces class IFooable { virtual void Fooable() = 0; }; class IFoo { virtual void Foo(IFooable* pFooable) = 0; }; and the goole mock mock class TMockFoo : public IFoo { MOCK_METHOD1(Foo, void (IFooable*)); }; what is the easiest way to specify an action which calls Fooable() on the argument to the mocked method Foo() ? I have tried TMockFoo MockFoo; ON_CALL(MockFoo, Foo(_)) .WithArg<0>(Invoke(&IFooable::Fooable)); but this doesn't compile because Invoke() with one argument

MySQL编译gmock出错的解决方法

北慕城南 提交于 2019-12-06 12:47:06
最近发现编译安装MySQL 5.6.13在cmake时报错: CMake Error: Problem with tar_extract_all(): Invalid argument CMake Error: Problem extracting tar: /usr/local/src/mysql-5.6.13/source_downloads/gmock-1.6.0.zip 报错的大概原因是tar解包gmock-1.6.0.zip出错了。 囧了……cmake的时候,怎么能用tar去解包zip压缩包呢?! 另外网上搜索了以下,gmock-1.6.0.zip是google的c++mock框架,从mysql 5.6开始支持。 cmake参数中设置了DENABLE_DOWNLOADS=1且服务器能连接Internet的话,就会自动下载。 上面报错信息可知,cmake时gmock-1.6.0.zip自动下载到了/usr/local/src/mysql-5.6.13/source_downloads/目录下。 解决办法: 手动编译安装gmock,然后再cmake: # cd到mysql5.6源码文件夹下的source_downloads文件夹 # cd /usr/local/src/mysql-5.6.13/source_downloads/ # unzip gmock-1.6.0.zip