vendredi 5 février 2016

Capture a void* argument from a mock function call

Mocking library used: GMock

Im trying to capture a void* argument passed as part of a function call on a mock object. Im able to capture int values passed through SaveArg<N> but when i try to use it to capture a void* argument it throws compilation error

Error: gmock/include/gmock/gmock-more-actions.h:155: error: ‘const void*’ is not a 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 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();
}

Aucun commentaire:

Enregistrer un commentaire