【发布时间】:2021-05-26 11:41:45
【问题描述】:
我已经为我的地图编写了一个自定义键
struct custom_key {
string id;
string sector;
bool operator==(const custom_key& other) {
// I'm needed by gtest
return id == other.id && sector == other.sector;
}
};
我已经添加了少然后重载
namespace std
{
template<> struct less<custom_key>
{
bool operator() (const custom_key& lhs, const custom_key& rhs) const
{
return lhs.id < rhs.id;
}
};
}
我还定义了我的匹配器
MATCHER_P(match_eq, value, "")
{
return arg == value;
}
我试着写一个测试
EXPECT_CALL(
*stats_,
stats(
AllOf(
Field(&data,
Contains(
Pair(
custom_key{"id", "name"},
match_eq("expected_value")
)
)
)
)
);
我已经反对了
std::map<custom_key, std::string> my_map = { {"id", "name"}, "expected_value" }
并且 gtest 说他没有找到匹配项。我迷路了。 由于在 gtest 的 impl 中大量使用模板,我无法找到调试它的任何帮助。 任何想法将不胜感激。
【问题讨论】:
-
请提供minimal reproducible example,特别是足够的代码来运行这个
EXPECT_CALL(并重现错误)。
标签: c++ c++11 c++17 googletest