Googletest Googlemock-WillOnce中的多个操作导致生成错误

Googletest Googlemock-WillOnce中的多个操作导致生成错误,googletest,googlemock,Googletest,Googlemock,我已经使用gtest一段时间了,但最近想试用gmock。我试图用返回值但也通过引用返回输出参数中的某些内容的方法来模拟类。这是我的小代码 #包括 #包括“gmock/gmock.h” #包括“gtest/gtest.h” 使用namespace::测试; 类面积 { 公众: 虚拟bool-foo(std::vector&v)const=0; }; 类别:公共区域 { 公众: 模拟常量方法1(foo,bool(std::vector&)); }; B类 { 公众: B(面积*_a):a(_a){}

我已经使用
gtest
一段时间了,但最近想试用
gmock
。我试图用返回值但也通过引用返回输出参数中的某些内容的方法来模拟类。这是我的小代码

#包括
#包括“gmock/gmock.h”
#包括“gtest/gtest.h”
使用namespace::测试;
类面积
{
公众:
虚拟bool-foo(std::vector&v)const=0;
};
类别:公共区域
{
公众:
模拟常量方法1(foo,bool(std::vector&));
};
B类
{
公众:
B(面积*_a):a(_a){}
boolfoo(std::vector&v)const{returna->foo(v);}
私人:
面积*a;
};
类最长:公共测试{};
测试F(最足部,
DummyTestVector){
阿莫克a;
B&a;
向量exp={1,2,3};
期望呼叫(a,foo()
.次(1)
.WillOnce(AllOf(setargreference(exp),Return(true));
std::矢量载荷;
EXPECT_TRUE(a.foo(load));
预期均衡器(exp,load);
}
int main(int argc,字符**argv){
::测试::InitGoogleMock(&argc,argv);
返回运行所有测试();
}
然而,这段代码给了我这个错误

$ g++ -Wall -Wextra -std=c++14 -I. -o test test.cpp gmock-gtest-all.cc -lpthread
test.cpp: In member function ‘virtual void FooTest_DummyTestVector_Test::TestBody()’:
test.cpp:40:61: error: no matching function for call to ‘testing::internal::TypedExpectation<bool(std::vector<int>&)>::WillOnce(testing::internal::AllOfResult2<testing::SetArgRefereeActionP<0, std::vector<int> >, testing::internal::ReturnAction<bool> >::type)’
         .WillOnce(AllOf(SetArgReferee<0>(exp), Return(true)));
                                                             ^
In file included from test.cpp:2:0:
gmock/gmock.h:10172:21: note: candidate: testing::internal::TypedExpectation<F>& testing::internal::TypedExpectation<F>::WillOnce(const testing::Action<F>&) [with F = bool(std::vector<int>&)]
   TypedExpectation& WillOnce(const Action<F>& action) {
                     ^
gmock/gmock.h:10172:21: note:   no known conversion for argument 1 from ‘testing::internal::AllOfResult2<testing::SetArgRefereeActionP<0, std::vector<int> >, testing::internal::ReturnAction<bool> >::type {aka testing::internal::BothOfMatcher<testing::SetArgRefereeActionP<0, std::vector<int> >, testing::internal::ReturnAction<bool> >}’ to ‘const testing::Action<bool(std::vector<int>&)>&’
$g++-Wall-Wextra-std=c++14-I.-o test test.cpp gmock-gtest-all.cc-lpthread
test.cpp:在成员函数“virtual void FooTest\u DummyTestVector\u test::TestBody()”中:
test.cpp:40:61:错误:调用“testing::internal::TypedExpectation::WillOnce(testing::internal::AllOfResult2::type)”时没有匹配的函数
.WillOnce(AllOf(setargreference(exp),Return(true));
^
在test.cpp中包含的文件中:2:0:
gmock/gmock.h:10172:21:注:候选者:测试::内部::TypedExpectation&测试::内部::TypedExpectation::WillOnce(常量测试::动作&)[带F=bool(标准::向量&]
类型检查和WillOnce(持续行动和行动){
^
gmock/gmock.h:10172:21:注意:参数1没有从“testing::internal::AllOfResult2::type{aka testing::internal::BothOfMatcher}”到“const testing::Action&”的已知转换

如果我不使用
AllOf
,而是只指定一个动作,无论是
setargreference
还是
Return
,一切都很好。使用
AllOf
会导致这种错误。我在这里找到了关于
AllOf
,基本上我的代码与答案是一样的。

经过一个下午的尝试我发现这一切都是我的愚蠢。一直以来,我不知怎么地认为,
AllOf==DoAll
。现在才意识到这一点