vendredi 22 mai 2020

How can i set a parameter sent by reference using the gmock framework?

I will try to reproduce an example...

class Object{
     public:
     Object(){}
     virtual void doSomething(vector<int>& x) {x.push_back(14);}
     virtual int foo(){return 0;} 
};

class ObjectMock : public Object
{
    public:
    MyMock(){}
    ~MyMock(){}
    MOCK_METHOD1(doSomething, void(std::vector<int>&));
    MOCK_METHOD0(foo, int());
};

class MyClass{
    public:
    Object* _obj;
    MyClass(){
        _obj = new Object;
    }
    void func()
    {
        int error = _obj->foo();
        if(error == 0)
        {
           int result;
           _obj->doSomething(result);
           if(result.size())
           {
               //the code where I'm trying to cover 
           }
        }
    }
};    
int main()
{
    //test 
    MyClass *item = new MyClass;
    ObjectMock* mock = new ObjectMock;
    item->obj = mock;
   //test for function foo 
   EXPECT_CALL(*mock, foo).WillOnce(Return(1));
   //this is my problem
   EXPECT_CALL(*mock, doSomething)//. What????
}

How can i change the output as above keeping in mind that it is received by reference? I want that vector to have at least one element in it.

I tried to look in the documentation from gmock. Everything I found

EXPECT_CALL(mock_object, method(matchers))

.With(multi_argument_matcher) ?

.Times(cardinality) ?

.InSequence(sequences) *

.After(expectations) *

.WillOnce(action) *

.WillRepeatedly(action) ?

.RetiresOnSaturation(); ?

Aucun commentaire:

Enregistrer un commentaire