I want to get references to the MyObjectClass instance passed to "somePrivateMethod" called by myMock.
我希望获得传递给myMock调用的“somePrivateMethod”的MyObjectClass实例的引用。
Now I use the following snippet but I'm sure there is a better way.
现在我使用以下代码片段,但我确信有更好的方法。
namespace {
MyObjectClass *myObjectPtr;
ACTION( getIt )
{
myObjectPtr = &arg0;
}
}
...
...
EXPECT_CALL( *myMock, somePrivateMethod( testing::_ ) ).WillOnce( testing::WithArg< 0 >( getIt( ) ) );
My problem is clearly stated I need to get the reference to that argument. The reason for what I want it has no matter here. I only need to know how to set a pointer to the argument of the somePrivateMethod.
我的问题清楚地表明我需要获得对该论点的引用。我想要它的原因无论如何。我只需要知道如何设置指向somePrivateMethod参数的指针。
1 个解决方案
#1
0
One of the way to do this is write public get
method in declaration of class A
其中一种方法是在A类声明中使用write public get方法
public: const int * get_b { return &b; }
public:const int * get_b {return&b; }
But since you want to check the value of this variable you don't need a pointer and can return value of variable in get
function
但是既然你想检查这个变量的值,你就不需要指针,并且可以在get函数中返回变量的值
public: int get_b { return b; }
public:int get_b {return b; }
#1
0
One of the way to do this is write public get
method in declaration of class A
其中一种方法是在A类声明中使用write public get方法
public: const int * get_b { return &b; }
public:const int * get_b {return&b; }
But since you want to check the value of this variable you don't need a pointer and can return value of variable in get
function
但是既然你想检查这个变量的值,你就不需要指针,并且可以在get函数中返回变量的值
public: int get_b { return b; }
public:int get_b {return b; }