- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我是 GoogleMock 的新手,但对 mocking 并不陌生(我有 python 经验)。
对于基于 C 代码的界面,我们希望使用 Googlemock。直到编译一切顺利。定义基于 C 的代码没有问题:模拟头文件
#include "gmock/gmock.h"
extern "C"
{
#include "interface/interfacetype.h"
}
struct HELPER
{
virtual ~HELPER() {}
virtual int interface_func( ID_ENUM_TYPE id, MY_STRUCT_TYPE *params) = 0;
};
struct INTERFACE_MOCK : public HELPER
{
MOCK_METHOD2( interface_func, int( ID_ENUM_TYPE id, MY_STRUCT_TYPE *params) );
};
extern INTERFACE_MOCK *mock_create_mock();
extern void mock_delete_mock();
模拟实现:
#include mock.h
extern "C"
{
#include "interface/interfacetype.h"
}
INTERFACE_MOCK *interface_2_mock = NULL;
extern "C"
{
int interface_func( ID_ENUM_TYPE id, MY_STRUCT_TYPE *params )
{
return interface_2_mock->interface_func( id, params );
}
}
INTERFACE_MOCK *mock_create_mock()
{
if ( interface_2_mock == NULL )
{
interface_2_mock = new( INTERFACE_MOCK );
}
return interface_2_mock;
}
void mock_delete_mock()
{
delete interface_2_mock;
}
MY_STRUCT_TYPE 如下:
typedef struct my_struct_tag
{
float value[196]
} MY_STRUCT_TYPE
单元测试代码如下:
INTERFACE_MOCK *interface_2_mock;
class fixture : public ::testing::Test
{
protected:
virtual void SetUp()
{
interface_2_mock = mock_create_mock();
}
virtual void TearDown()
{
mock_delete_mock();
}
};
TEST_F( fixture, test_case )
{
MY_STRUCT_TYPE params;
int result = 0;
for ( int i=0; i<196; i++)
{
params.value[i] = 1.23;
}
// I'm only interested in checking that function is called,
// mocking the return-value and mocking 'params' which is an output-param
EXPECT_CALL( *interface_2_mock, interface_func( _, _ ) )
.Times(2)
.WillRepeatedly( DoAll( SetArgReferee<1>( ¶ms ), return 0 ) ) );
// Call function_under_test which calls interface_func
result = function_under_test();
ASSERT_EQ( 0, result ) << "Return-value " << result << " not as expected"
}
编译时一切顺利,直到编译了 EXPECT_CALL 行。我们有以下我们不理解的错误:
Rebuilding "<target>.oppsparc" on host "<host>"
======== Finished "<target>.oppsparc" on host "<host>" ========
Sun native compile : test_my_test.cpp to test_my_test.oppsparc
In file included from ./gmock/gmock.h:65,
from mock/interface_2_mock.hpp:33,
from test_my_test.cpp:23:
./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 = ID_ENUM_TYPE , arg1_type = MY_STRUCT_TYPE*, 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( ID_ENUM_TYPE , MY_STRUCT_TYPE*), int k = 1, value_type = MY_STRUCT_TYPE*]':
./gmock/gmock-generated-actions.h:664: instantiated from 'static Result testing::internal::ActionHelper<Result, Impl>::Perform(Impl*, const std::tr1::tuple<_U1, _U2>&) [with A0 = ID_ENUM_TYPE , A1 =MY_STRUCT_TYPE*, Result = void, Impl = testing::SetArgRefereeActionP<1, MY_STRUCT_TYPE*>::gmock_Impl<void( ID_ENUM_TYPE ,MY_STRUCT_TYPE*)>]'
./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( ID_ENUM_TYPE , MY_STRUCT_TYPE*), int k = 1, value_type = MY_STRUCT_TYPE*]'
test_my_test.cpp:251: instantiated from here
./gmock/gmock-more-actions.h:175: error: creating array with negative size ('-0x00000000000000001')
./gmock/gmock-more-actions.h:177: error: assignment of read-only location 'std::tr1::get [with int __i = 1, _Elements = ID_ENUM_TYPE, MY_STRUCT_TYPE*](((const std::tr1::tuple<ID_ENUM_TYPE, MY_STRUCT_TYPE*>&)((const std::tr1::tuple<ID_ENUM_TYPE, MY_STRUCT_TYPE*>*)args)))'
*** Error code 1
========================================================
Aborting...
你能帮我们吗?
/* edit */我看到我遗漏了夹具
最佳答案
这次我找到了答案。而不是 SetArgReferee<1>( ¶ms ),我应该使用 SetArgPointee<1>( params )
关于编译错误 : "creating array with negative size (' -0x0000000000000000 1')", "assignment of read-only location",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26614040/
在嵌入式系统的背景下,给出以下函数结构: 返回变量的条件赋值: int foo(int x) { int status; if (is_valid(x)) {
#input |--IDs-|--Value-| |--da1-|--100---| |--da2-|---80---| |--da3-|--200---| |--da4-|--300---| |--
您可以declare a list of variables and assign them some value在 Perl 6 my ($a, $b) = 33,44 # $a will be 3
在下面的代码中实现对象的浅拷贝,但是不同的输出让我很困惑: 对象.分配: var obj = { name: 'wsscat', age: 0, add: { a: 'beijin
我正在查看一位已不复存在的开发人员的一些旧代码,并注意到有时他使用 Object.assign({}, xyz) 还有他用过的其他东西 Object.assign([], abc); 两者有区别吗?
这个问题在这里已经有了答案: Why were ES5 Object methods not added to Object.prototype? (2 个答案) 关闭 4 个月前。 我正在做一个
我想知道这之间的区别: Object.assign(otherObject, { someNewProperty: '' }); 和 otherObject.someNewProperty = '
考虑以下代码: const defaultState = () => { return { profile: { id: '', displayName: '',
我刚刚偶然发现this line of TS code : const { title = item.text } = item; 这似乎是一个destructuring assigment但是大括号
我是一个没有经验的 JavaScript 用户,正在阅读这本书 CoffeeScript: Accelerated JavaScript Development ,其中作者制作了一种 Scrabble
当我查看日志文件时 D:\SAS\XXX\Lev1\SASMain\BatchServer\Logs 我看到了这两行 NOTE: Libref TESTLIB successfully assigne
我似乎不明白为什么要使用移动赋值运算符: CLASSA & operator=(CLASSA && other); //move assignment operator 结束了,复制赋值运算符: CL
在Eiffel Studio中,我一直试图访问从另一个类定义的一个类的对象的字段。但是,它不断给出我无法理解和解决的错误。以下是示例代码片段: 创建对象的类: class TEST1 feat
为什么这个片段在 Node (10.5) .then(function() { this = {...this, ...payload}; this.update();
我在我的 React 应用程序中使用以下包来生成 Recaptcha 组件:https://github.com/appleboy/react-recaptcha 组件如下所示,带有 eslint 警
我有以下代码: #include #include using std::cout; struct SomeType { SomeType() {} SomeType(const Some
我有这个代码示例: var a = 10; ({a}) = 0; 在 Google Chrome 中,它显示错误:SyntaxError:无效的解构赋值目标 在 Firefox 中,它显示错误:Ref
我有一个函数,用于对两个输入字段的输入求和并将其分配给一个。我的函数如下所示: function sum(id) { nextId = id+2 console.log
我收到这个警告 "Automatic Reference Counting Issue: Assigning retained object to unsafe_unretained variable
在使用 Shopify 的 Liquid 语言编码时,我注意到使用以下语法分配了一些变量: {%- assign variable = value -%} 和使用以下语法分配的其他变量: {% ass
我是一名优秀的程序员,十分优秀!