Google मैक्स का उपयोग शुरू करने का प्रयास करते समय मैंने एक समस्या में भाग लिया है - किसी कारण से यह EXPECT_CALL
मैक्रो में निर्दिष्ट कॉल को नहीं बता सकता है, भले ही प्रकार सुसंगत हों। मैं जानना चाहता हूं कि यह सिर्फ पहले फ़ंक्शन से मेल नहीं खाता है, और इसे पहले फ़ंक्शन से मेल खाने के लिए मुझे क्या करना/जोड़ना है।Google मोक्स इस फ़ंक्शन को अस्पष्ट क्यों कहते हैं?
नकली वर्ग:
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));
}
परीक्षण कोड है कि त्रुटि फेंकता है:
__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));
संकलन त्रुटि:
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)'
धन्यवाद: cookbook से, सही प्रकार निर्दिष्ट करने के लिए
Matcher<T>
याTypedEq<T>
matchers उपयोग करके देखें। इस पर अधिक जानकारी के लिए – dlanod, आप देख सकते हैं: https://github.com/google/googlemock/blob/master/googlemock/docs/CookBook.md#using-matchers – parasrish
'का उपयोग :: परीक्षण :: Matcher;' और उसके बाद ऊपर सुझाए गए अनुसार उपयोग करें। अच्छी तरह से काम ! – parasrish