Ho riscontrato un problema durante il tentativo di iniziare a utilizzare Google Mock: per qualche motivo non è in grado di dire la chiamata che sto specificando nella macro EXPECT_CALL
, anche se i tipi sono coerenti. Voglio sapere perché non si abbina solo alla prima funzione, e cosa devo fare/aggiungere per farlo corrispondere alla prima funzione.Perché Google Mock trova questa funzione ambigua?
La classe finto:
class GMockTest : public ITest
{
public:
MOCK_METHOD2(SetParameter,
int(int nParameter, double value));
MOCK_METHOD2(SetParameter,
int(int nParameter, int value));
MOCK_METHOD2(SetParameter,
int(int nParameter, __int64 value));
}
Il codice di prova che genera l'errore:
__int64 nFrom = 0,
nTo = 0;
EXPECT_CALL(mock, SetParameter(2, nFrom))
.Times(1)
.WillOnce(Return(0));
EXPECT_CALL(mock, SetParameter(3, nTo))
.Times(1)
.WillOnce(Return(0));
L'errore di compilazione:
test.cpp(1343) : error C2668: GMockTest::gmock_SetParameter' : ambiguous call to overloaded function
testmocks.h(592): could be 'testing::internal::MockSpec<F>
&GMockTest::gmock_SetParameter(const testing::Matcher<T> &,const testing::Matcher<A2> &)
'
with
[
F=int (int,__int64),
T=int,
A2=__int64
]
testmocks.h(590): or 'testing::internal::MockSpec<F>
&GMockTest::gmock_SetParameter(const testing::Matcher<T> &,const testing::Matcher<T> &)'
with
[
F=int (int,int),
T=int
]
testmocks.h(580): or 'testing::internal::MockSpec<F>
&GMockTest::gmock_SetParameter(const testing::Matcher<T> &,const testing::Matcher<FloatT
ype> &)'
with
[
F=int (int,double),
T=int,
FloatType=double
]
while trying to match the argument list '(int, __int64)'
Grazie (doppiamente così per il link), che ha funzionato perfettamente. – dlanod
per ulteriori informazioni su questo, è possibile fare riferimento a: https://github.com/google/googlemock/blob/master/googlemock/docs/CookBook.md#using-matchers – parasrish
'using :: testing :: Matcher;' e quindi usando come suggerito sopra. funziona perfettamente! – parasrish