Google Mock and SetArgPointee using Objects

Roxana Istrate

I am recently using GMock and I cannot successfully use SetArgPointee in the following code.

class rox{
public :
    int a, b;
    rox(){}
    rox(const rox &ana){
        a = ana.a;
        b = ana.b;
    }
    rox operator=(const rox& ana){
        a = ana.a;
        b = ana.b;
        return *this;
    }
};

TEST(Statistics, RandomReceived){
    MockClass ms; 
    rox ana1, ana2;
    EXPECT_CALL(ms, Read(_)).Times(1).WillOnce(DoAll(SetArgPointee<0>(ana1), Return(1)));
    ms.Read(&ana2);
    EXPECT_EQ(ana2.a, ana1.a);
    EXPECT_EQ(ana2.b, ana1.b);
}

The test fails because the ana2 object after calling the read function does not have the field a and b properly set. Using a watch in VS I can see ana2.a and ana2.b are garbage values.

I read in GMock cook book I also need a copy constructor and an assignment operator. If I use the debugger I can see the copy constructor is called 4 times and the assignment operator is never called.

Can anyone point the error here? What do I need to do to obtain after the read in ana2 the same object as ana1?

Roxana Istrate

SetArgPointee is not working with polymorphic objects :) If Read's signature is int Read(ARox *ana); and ARox is an abstract class and rox is inherited from ARox the expectations are not met

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用对象的Google Mock和SetArgPointee

来自分类Dev

How to test a Jersey rest service using mock objects

来自分类Dev

gtest_ 使用 setargpointee 在函数中赋值

来自分类Dev

使用Google Mock for C代码

来自分类Dev

自动生成Google Mock方法?

来自分类Dev

Using on UnitTest Mock-DbContext

来自分类Dev

How to mock a For Loop using Mockito

来自分类Dev

使用Google Mock实现模拟方法

来自分类Dev

使用Google Mock的无效指针错误

来自分类Dev

泄漏的Google Mock对象不会失败

来自分类Dev

Google Mock测试类的真实行为

来自分类Dev

如何在CppUnitTestFramework中使用Google Mock

来自分类Dev

Google Mock:测试对象的某些属性

来自分类Dev

在Google Mock上调用重载函数

来自分类Dev

避免使用 Google Mock 调用基类

来自分类Dev

比较Google Test或Google Mock中的本征矩阵

来自分类Dev

如何在Eclipse中安装Google Test和Google Mock

来自分类Dev

如何在Ubuntu 12.10上安装google-mock

来自分类Dev

在Google Test / Mock框架中引用数组参数

来自分类Dev

Google Mock:为什么NiceMock不忽略意外呼叫?

来自分类Dev

Google Mock:在EXPECT_CALL中设置参数

来自分类Dev

如何使模拟对象在Google Mock中引发异常?

来自分类Dev

无法使用Google Mock C ++模拟CDatabase Open / OpenEx

来自分类Dev

Google Mock:模拟fstream对象和测试中的执行控制

来自分类Dev

如何在Ubuntu 12.10上安装google-mock

来自分类Dev

使用Google Mock进行C ++高性能单元测试?

来自分类Dev

无法使用Google Mock C ++模拟CDatabase Open / OpenEx

来自分类Dev

Google Mock std::shared_prt 调用问题

来自分类Dev

How to inject fake, stubbed or mock dependencies for Integration tests using Typhoon

Related 相关文章

热门标签

归档