Sto cercando di scrivere finto per una classe che contiene tre metodi di overload, cioè .:GMock - tornando valore di default con ON_CALL per metodi di overload
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using ::testing::_;
using ::testing::Return;
using ::testing::A;
using ::testing::ByRef;
using ::testing::Ref;
using ::testing::TypedEq;
struct Foo {
int fooMethod(const int& intParam) { return 0; }
int fooMethod(const float& floatParam) { return 0; }
int fooMethod(const std::string& stringParam) { return 0; }
};
struct FooMock {
FooMock() {
ON_CALL(*this, fooMethod(_)).WillByDefault(Return(-1));
}
MOCK_METHOD1(fooMethod, int(const int& intParam));
MOCK_METHOD1(fooMethod, int(const float& floatParam));
MOCK_METHOD1(fooMethod, int(const std::string& stringParam));
};
ma questo dà un errore:
error: call of overloaded ‘gmock_fooMethod(const testing::internal::AnythingMatcher&)’ is ambiguous
Ho anche provato TypedEq() invece di "_", ma dà errori più oscuri. Ho controllato le FAQ di GMock, Wiki e io non ho trovato una soluzione: come posso restituire il valore di default con ON_CALL per i metodi sovraccaricati?
BR, Lukasz
TX34, Fraser - grazie! – lgromanowski