引用谷歌测试/模拟框架中的数组参数
Reference to an array parameter in google test/mock framework
我有一个引用数组输出参数的成员函数,我想在谷歌模拟中使用它,但它不起作用。
班级:
class Class
{
// returns: number of the rewritten elements in the array
int foo(Struct (&bar)[ArraySize]) const;
};
模拟课:
class MockClass : public Class
{
MOCK_CONST_METHOD1(foo, int(Struct (&)[ArraySize]));
};
当我想使用它时,我会写以下内容:
ON_CALL(mMockClass, foo(_))
.WillByDefault( DoAll( SetArgReferee<0>(mBar)
, Return(5)
)
);
mBar 是一个合适的结构数组 (Struct mBar[ArraySize];
)。当我编译它时,我收到以下错误消息:
../../../../vendor/gmock-1.7.0/include/gmock/gmock-more-actions.h: In member
function ‘typename testing::internal::Function<F>::Result
testing::SetArgRefereeActionP<k,
value_type>::gmock_Impl<F>::gmock_PerformImpl(const typename
testing::internal::Function<F>::ArgumentTuple&, arg0_type, arg1_type,
arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type,
arg9_type) const [with arg0_type = Struct (&)[32], arg1_type =
testing::internal::ExcessiveArg, arg2_type = testing::internal::ExcessiveArg,
arg3_type = testing::internal::ExcessiveArg, arg4_type =
testing::internal::ExcessiveArg, arg5_type = testing::internal::ExcessiveArg,
arg6_type = testing::internal::ExcessiveArg, arg7_type =
testing::internal::ExcessiveArg, arg8_type = testing::internal::ExcessiveArg,
arg9_type = testing::internal::ExcessiveArg, F = void(Struct (&)[32]), int k =
0, value_type = Struct*]’:
../../../../vendor/gmock-1.7.0/include/gmock/gmock-generated-actions.h:655:
instantiated from ‘static Result testing::internal::ActionHelper<Result,
Impl>::Perform(Impl*, const std::tr1::tuple<A0>&) [with A0 = Struct (&)[32],
Result = void, Impl = testing::SetArgRefereeActionP<0,
Struct*>::gmock_Impl<void(Struct (&)[32])>]’
../../../../vendor/gmock-1.7.0/include/gmock/gmock-more-actions.h:170:
instantiated from ‘typename testing::internal::Function<F>::Result
testing::SetArgRefereeActionP<k, value_type>::gmock_Impl<F>::Perform(const
typename testing::internal::Function<F>::ArgumentTuple&) [with F = void(Struct
(&)[32]), int k = 0, value_type = Struct*]’
SomeTest.cpp:120: instantiated from here
../../../../vendor/gmock-1.7.0/include/gmock/gmock-more-actions.h:177: error:
incompatible types in assignment of ‘Struct* const’ to ‘Struct [32]’
make: *** [SomeTest] Error 1
对于错误消息格式,我很抱歉。据我了解,编译器的问题是它假设对数组的引用,但它得到了一个指针。我做错了什么?
更新:解决方案
对于传递数组类型的参数,应使用SetArrayArgument<N>(first, last)
。
将源范围 [第一个、最后一个) 中的元素复制到指向的数组 由第 N 个(从 0 开始)参数,该参数可以是指针或 迭 代。该操作不获取 源范围
更多关于谷歌C++模拟框架[这里][1]
http://code.google.com/p/googlemock/wiki/CheatSheet
相关文章:
- C++函数模板需要 &for 数组参数
- C++ 数组参数不起作用
- 使用数组参数进行函数专用化
- 为什么我的数组参数的方法无法正常工作?(C )
- SWIG - Java 代理类数组参数
- 在 gcc 中使用数组参数编译外部"c"代码
- 从 VB6 调用的 C++ DLL 函数中的输出数组参数
- 如何根据数组参数项类型重载 IDL 中的函数
- 引用谷歌测试/模拟框架中的数组参数
- C++将数组参数传递给函数
- 字符星形数组参数未正确终止
- 如何将德尔菲的"字符串数组"参数翻译成C++?
- 为什么 gcc 无法推断数组参数的模板化大小?(C++11)
- 使用 const char 数组参数分析 constexpr 显示运行时执行
- C++指针数组参数
- 固定大小的多维数组参数
- 为什么数组参数被视为常量数组
- 如何在pgsql中格式化数组参数
- C++字符数组参数在x86编译中包含奇怪的字符
- 对象数组参数 - 错误:字段“字母”的类型不完整