c++ - Capture a void* argument from a mock function call -
mocking library used: gmock
im trying capture void*
argument passed part of function call on mock object. im able capture int values passed through savearg<n>
when try use capture void*
argument throws compilation error
error: gmock/include/gmock/gmock-more-actions.h:155: error: ‘const void*’ not pointer-to-object type
code (relevant parts):
struct blah { int a; int b; }; class someclass { void some_function(const void* arg0, u64 arg1); }; class mocksomeclass : public someclass { . . // holds 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(); }
the problem savearg expects address location save contents. since im capturing pointer save address arg-pointer points in address-location give savearg. had savearg<0>(&actual_arg). bottom line: got confused since im capturing pointer, though actual_arg pointer savearg expects address in memory can save contents.
Comments
Post a Comment