Tag: 模拟cmock

在MSVC中模拟C函数(Visual Studio)

我正在阅读几篇关于模拟 C函数的文章(比如CMock或CMocka ),但我不确定在这个过程中如何用模拟函数替换实际函数。 例如,CMocka依赖于使用GNU编译器的自动换行,GNU编译器支持诸如–wrap参数将__wrap前缀附加到函数调用,或者弱符号允许您覆盖任何您喜欢的符号。 但是你如何在Visual Studio中为几乎所有其他框架做到这一点? 例如, CMock有一个与此类似的例子 (这里简化了很多): // myfunc.c #include // this is the function we would like to test int MyFunc(char* Command) { // this is the call to the function we will mock return ParseStuff(Command); } 还有实际的实现,它包含链接器在实际应用程序中应该找到的实际function: // parsestuff.c int ParseStuff(char* cmd) { // do some actual work return 42; } […]