使用 TypedEq() 匹配类型 std::vector<std::vector>
Use TypedEq() to match the type std::vector<std::vector>
我有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));
}
我想期望call write_data以范围作为参数。我想要匹配该类型以避免歧义。我不想比较该论点的价值。
TEST_F(MyTest, test1)
{
...
EXPECT_CALL(MOCKA_obj, write_data(_, TypedEq<const range_t&>(_)))
.Times(1)
.WillOnce(Return(0));
...
}
它给了我以下错误:
test.cc.cc:256:1: required from here build/../gmock/include/gmock/gmock.h:5564:41: error: no match for 'operator==' (operand types are 'std::vector<std::vector<temp_struct> >' and 'const testing::internal::AnythingMatcher')
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");
^
build/../gmock/include/gmock/gmock.h:5544:20: note: in definition of macro 'GMOCK_IMPLEMENT_COMPARISON_MATCHER_'
return lhs op rhs_;
^
build/../gmock/include/gmock/gmock.h:5564:41: note: candidates are:
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");
^
build/../gmock/include/gmock/gmock.h:5544:20: note: in definition of macro 'GMOCK_IMPLEMENT_COMPARISON_MATCHER_'
return lhs op rhs_;
^
In file included from test.cc.cc:3:0:
build/../gmock/include/gtest/gtest.h:9173:6: note: template<class T> bool testing::internal::operator==(T*, const testing::internal::linked_ptr<T>&)
bool operator==(T* ptr, const linked_ptr<T>& x) {
^
build/../gmock/include/gtest/gtest.h:9173:6: note: template argument deduction/substitution failed:
In file included from build/../test.h:11:0,
from test.cc.cc:7:
build/../gmock/include/gmock/gmock.h:5564:41: note: mismatched types 'T*' and 'std::vector<std::vector<temp_struct> >'
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");
^
build/../gmock/include/gmock/gmock.h:5544:20: note: in definition of macro 'GMOCK_IMPLEMENT_COMPARISON_MATCHER_'
return lhs op rhs_;
^
根据文档,TypedEq
接受一个值,而不是匹配器。如果要简单地在静态上验证类型,请使用A
Matcher:
EXPECT_CALL(MOCKA_obj, write_data(_, A<const range_t&>()))
相关文章:
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- std::vector的包装器,使数组的结构看起来像结构的数组
- 编译器如何区分std::vector的构造函数
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 在std::vector上存储带有模板的类实例
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 为什么std::vector比数组慢
- std::vector::迭代器是否可以合法地作为指针
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 为什么std::vector和std::valarray初始化构造函数不同
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- 在没有未定义行为的情况下实现类似std::vector的容器
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- 使用 std::vector::reverse_iterator 将 int 序列化为字节向量?
- 如何将AERT_Allocate与 std:vector 一起使用
- 推导 std::vector::back() 的返回类型
- 如何将原始字节附加到 std::vector?
- std::vector 没有重载函数的实例与参数列表匹配
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?