我在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提供不同的值,但没有运气。
当我尝试运行测试时,它总是失败的。
implicit declaration of function ‘TestFunc_ExpectWithArray’ [-Wimplicit-function-declaration]根据我的经验,当要模拟的函数没有用正确的参数调用并且CMock无法生成模拟版本时,总是会发生这种情况。我做错了什么?有人能给出一个如何正确使用_ExpectWithArray的例子吗?
发布于 2018-10-16 20:52:38
作为另一种选择,尝试使用_StubWithCallback并使用自定义函数实现自己的数组检查。
// 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();
}https://stackoverflow.com/questions/49172343
复制相似问题