我不确定我想做的事情是否可行,但我很难让编译器尝试模拟包含模板化引用参数的方法。
接口(interface)(删除了所有不相关的方法)
class iat_protocol
{
public:
virtual void get_available_operators(etl::vector<network_operator, 5>&) = 0;
};
我的模拟
class at_protocol_mock : public iat_protocol
{
public:
MOCK_METHOD((void), get_available_operators, (etl::vector<network_operator, 5>&), (override));
};
这会导致
In file included from /home/bp/dev/unode/eclipse/thirdparty/googletest/googlemock/include/gmock/gmock-actions.h:145,
from /home/bp/dev/unode/eclipse/thirdparty/googletest/googlemock/include/gmock/gmock.h:57,
from ../tests/shared/hal/at/at_channel_tests.cpp:1: /home/bp/dev/unode/eclipse/unit_tests/tests/shared/hal/at/mocks/at_protocol_mock.hpp: In member function ‘testing::internal::MockSpec<void(etl::vector<iobox::hal::at::network_operator, 5>&)> iobox::hal::at_protocol_mock::gmock_get_available_operators(const testing::internal::WithoutMatchers&, testing::internal::Function<void(etl::vector<iobox::hal::at::network_operator, 5>&)>*) const’: /home/bp/dev/unode/eclipse/thirdparty/googletest/googlemock/include/gmock/gmock-function-mocker.h:343:74: error: invalid combination of multiple type-specifiers 343 | typename ::testing::internal::Function<__VA_ARGS__>::template Arg<_i>::type
| ^~~~ /home/bp/dev/unode/eclipse/thirdparty/googletest/googlemock/include/gmock/internal/gmock-pp.h:17:31: note: in definition of macro ‘GMOCK_PP_IDENTITY’
我的 C++ 技能还不够好,无法了解编译器试图告诉我什么。
谁能帮助我?
最佳答案
嗯,这很奇怪,但是简单的using
就可以解决你的问题。
#include "gmock/gmock.h"
struct network_operator {};
namespace etl {
template <typename T, unsigned N>
struct vector {};
} // namespace etl
using vector_5 = etl::vector<network_operator, 5>;
class iat_protocol {
public:
virtual void get_available_operators(vector_5&) = 0;
};
class at_protocol_mock : public iat_protocol {
public:
MOCK_METHOD(void, get_available_operators,
(vector_5&),(override));
};
来自 gMock 食谱 Dealing with unprotected commas
关于c++ - 谷歌模拟无法模拟带有模板化参数的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71538502/