2
我正在寫單元測試,想知道如何測試函數指針與Cmockery。驗證函數指針指向函數的地址。 CMockery
File A.c
void (*FunctionPtr)(void) = &funcA;
void funcA()
{
//calls func B
funcB();
}
TestA.c
void Test_A(void ** state)
{
/// test for FunA
// working as expected
}
void Test_FunctionPtr(void** state)
{
/// how to check here that FunctionPtr holds memory location of funcA
// I tried something like below
assert_memory_equal(FunctionPtr, funcA(), sizeof(funcA()));
}
在運行期間,我收到錯誤,我不知道如何解決這個問題。可能是我使用錯誤的API來斷言,但不知道哪一個打電話。 下面是我的錯誤在運行時
錯誤:
Test_FunctionPtr:開始測試 沒有找到符號funcB條目。
「如何在這裏檢查FunctionPtr保存funcA的內存位置」 - >你試過'assert(FunctionPtr == funcA);'?注意:在'void(* FunctionPtr)(void)= &funcA;' – chux
'funcA()'中調用'funcA'函數之前使用_define_'funcA()'的最佳實踐'funcA',它會返回任何無法比較的函數。 – mch
@mch看起來幾乎就像一個答案。你想成爲一個嗎?也許添加一個解決方案,我認爲它會使用'funcA'而不是'funcA()'。 – Yunnosch