首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExpectWithArray在CMock中的使用示例

ExpectWithArray在CMock中的使用示例
EN

Stack Overflow用户
提问于 2018-03-08 11:47:10
回答 1查看 2K关注 0票数 4

我在Ubuntu16.04和Eclipse4.7.2下使用Ceedling。到目前为止,除了我无法使_ExpectWithArray模拟函数正常工作之外,一切都很好。

例如,我有下面的函数来模拟void TestFunc(uint8_t * data);。在我的测试文件中,我有以下调用uint8_t TEST_DATA[5] = { 0xFF, 0x00, 0xA0, 0x00, 0x09 }; TestFunc_ExpectWithArray(TEST_DATA, 5)

我还尝试为param_depth提供不同的值,但没有运气。

当我尝试运行测试时,它总是失败的。

代码语言:javascript
复制
implicit declaration of function ‘TestFunc_ExpectWithArray’ [-Wimplicit-function-declaration]

根据我的经验,当要模拟的函数没有用正确的参数调用并且CMock无法生成模拟版本时,总是会发生这种情况。我做错了什么?有人能给出一个如何正确使用_ExpectWithArray的例子吗?

EN

回答 1

Stack Overflow用户

发布于 2018-10-16 20:52:38

作为另一种选择,尝试使用_StubWithCallback并使用自定义函数实现自己的数组检查。

代码语言:javascript
复制
// Can be any name. Same signature as void TestFunc(uint8_t * data);
void TestFunc_CustomMock(uint8_t* array) {
  // Loop through the array and ASSERT each element
  uint8_t TEST_DATA[5] = { 0xFF, 0x00, 0xA0, 0x00, 0x09 };

  for (uint8_t i = 0; i < 5; i++) {
    TEST_ASSERT_EQUAL(TEST_DATA[i], array[i]);
  }
  // Also possible to use this to check custom structs, etc. 

  // Can also return a value from this callback function, if the signature
  // says so
}

void test_MyFunc() {
  // Mock TestFunc(uint8_t * data)
  TestFunc_StubWithCallback((void *)&TestFunc_CustomMock);

  // Call TestFunc(uint8_t * data) which is located in MyFunc()
  MyFunc();

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49172343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档