使用TypedEq()匹配类型std :: vector <std :: vector>

时间:2017-02-25 02:19:59

标签: c++ googletest gmock

我有2个模拟方法

struct temp_struct
{
int x;
};

using range = std::vector<std::vector<temp_struct>>;

Class MockA: public A
{
public:
   MOCK_METHOD1(write_data, int(int a, int b));
   MOCK_METHOD1(write_data, int(int a, const range &ranges));
}

我希望调用write_data并将range作为参数。我想要 匹配类型以避免歧义。我不想比较那个论点的价值。

TEST_F(MyTest, test1)
{
    ...
    EXPECT_CALL(MOCKA_obj, write_data(_, TypedEq<const range_t&>(_)))
       .Times(1)
       .WillOnce(Return(0));
    ...
}

它给了我以下错误:

test.cc.cc:256:1:从这里需要构建/../ gmock / include / gmock / gmock.h:5564:41:错误:不匹配&#39;运营商==&#39 ; (操作数类型是&#39; std :: vector&gt;&#39;&#39; const testing :: internal :: AnythingMatcher&#39;)  GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq,==,&#34;等于&#34;,&#34; isn等于&#34;);                                          ^

build /../ gmock / include / gmock / gmock.h:5544:20:注意:在宏的定义中&#39; GMOCK_IMPLEMENT_COMPARISON_MATCHER _&#39;          return lhs op rhs_; \                     ^

build /../ gmock / include / gmock / gmock.h:5564:41:注意:候选人是:  GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq,==,&#34;等于&#34;,&#34; isn等于&#34;);                                          ^

build /../ gmock / include / gmock / gmock.h:5544:20:注意:在宏的定义中&#39; GMOCK_IMPLEMENT_COMPARISON_MATCHER _&#39;          return lhs op rhs_; \                     ^

在test.cc.cc:3:0中包含的文件中: build /../ gmock / include / gtest / gtest.h:9173:6:注意:模板bool测试:: internal :: operator ==(T *,const testing :: internal :: linked_ptr&amp;)  bool operator ==(T * ptr,const linked_ptr&amp; x){       ^

build /../ gmock / include / gtest / gtest.h:9173:6:注意:模板参数扣除/替换失败: 在build /../ test.h:11:0中包含的文件中,                  来自test.cc.cc:7:

build /../ gmock / include / gmock / gmock.h:5564:41:注意:不匹配的类型&#39; T *&#39;和&#39; std :: vector&gt;&#39;  GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq,==,&#34;等于&#34;,&#34; isn等于&#34;);                                          ^

build /../ gmock / include / gmock / gmock.h:5544:20:注意:在宏的定义中&#39; GMOCK_IMPLEMENT_COMPARISON_MATCHER _&#39;          return lhs op rhs_; \                     ^

1 个答案:

答案 0 :(得分:1)

根据docsTypedEq接受一个值,而不是匹配器。如果您只想静态验证类型,请使用A匹配器:

EXPECT_CALL(MOCKA_obj, write_data(_, A<const range_t&>()))