Bob
Bob

Reputation: 4970

google mock - mock return value of a (free-standing) function called

I have a function that I'm testing, f1().

f1() calls g1() which can return a few different values.

How do I mock g1() so I can iterate through the different values it returns in order to test the paths inside f1()?

int f1()
{
    int res = g1();
    int ret = 0;
    switch(res):
    {
        case 0:
           // ret = something
        case 1:
           // ret = something else
        default:
           // ret = bad result
    }
    return ret;
}

Upvotes: 0

Views: 111

Answers (1)

Dipankar Saha
Dipankar Saha

Reputation: 312

Probably you can try cmocka tool to do the above mentioned use case.

Upvotes: 1

Related Questions