我不確定我想要做的事情是否可行,但我很難讓編譯器嘗試模擬包含模板化參考引數的方法。
介面(洗掉了所有不相關的方法)
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 技能還不足以知道編譯器試圖告訴我什么。
誰能幫我 ?
uj5u.com熱心網友回復:
好吧,這很奇怪,但很簡單可以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));
};
uj5u.com熱心網友回復:
最新的 gmock 庫顯示了更具描述性的內容:
error: static_assert failed due to requirement '::testing::tuple_size<std::tuple<etl::vector<network_operator, 5> &>>::value == 2' "This method does not take 2 arguments. Parenthesize all types with unproctected commas."
MOCK_METHOD(void, get_available_operators,
用不受保護的逗號將所有型別括起來。
沒有的另一種解決方案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(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));
// ^ ^
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/447694.html
上一篇:在Python中發布單元測驗
下一篇:MERN單元測驗失敗
