0
懲戒使用庫捕獲一個void *參數:GMock從模擬函數調用
我試着去捕捉void*
參數作爲模擬對象的函數調用的一部分傳遞。林能夠捕捉到國際價值通過SaveArg<N>
過去了,但是當我嘗試使用它來捕捉void*
參數,它拋出編譯錯誤
錯誤:gmock/include/gmock/gmock-more-actions.h:155: error: ‘const void*’ is not a pointer-to-object type
代碼(相關部分):
Struct Blah
{
int a;
int b;
};
class SomeClass {
void some_function(const void* arg0, u64 arg1);
};
class MockSomeClass : public SomeClass {
.
. // Holds the mock definition
.
};
class MyClass
{
SomeClass* _dep;
MyClass(SomeClass* dep)
{
_dep = dep;
};
void test_function()
{
Blah b = new Blah();
_dep->some_function(b, sizeof(Blah));
}
};
TEST(SomeTestCase, One)
{
MockSomeClass mock_object = new MockSomeClass();
void* actual_arg;
EXPECT_CALL(*mock_object, some_function(_,_)).WillOnce(SaveArg<0>(actual_arg)); // throws compilation err
MyClass test_obj = new MyClass(mock_object);
test_obj->test_function();
}