Search code examples
c++mockingoverloadinghippomocks

Hippomock static function with overload, how to use ExpectCallFuncOverload?


With the following class:

class Math {
public:
    static int Add(int a, int b) {
        return a + b;
    }

    static int Add(int a, int b, int c) {
        return a + b + c;
    }
};

How to use ExpectCallFuncOverload?

I try

#include <hippomock.h>

int main() {
    HippoMock::MockRepository mocks;
    mocks.ExpectCallFuncOverload(Math::Add).Return(5);

    Math::Add(2, 3);
    return 0;
}

gcc tells "call of overloaded 'RegisterExpect_...' is ambiguous"

How to tell Hippomock which overload we want to use? I don't find anything in the documentation

Thanks,


Solution

  • I found it!

    Use a cast to determine the function to use

    mocks.ExpectCallFuncOverload((int (*)(int, int))Math::Add).Return(5);