cmocka

Mock/Wrap static functions called by a non-static function under test

孤街醉人 提交于 2020-05-28 05:41:32
问题 I would like to test some functions by implementing unit tests with cmocka framework. For example I have a non-static function under test which calls two static functions. Because of the fact that these static functions interact with hardware I want to mock/wrap them and use a wrap function instead of the real function when testing. Like described in the cmocka documentation I've used the --wrap=myfunction linker flags when building/linking my tests. The tests compile but when I run them the

CMOCKA / Linker : 'wrap'ping lots of functions

我怕爱的太早我们不能终老 提交于 2020-01-03 03:06:23
问题 I recently came across the 'cmocka' mocking library for C. I was able to mock a single function and test the caller function successfully. Now i need it to use it for a project that i am working on, where it is required to mock a large number of functions. How to pass all the functions that I want to mock to the 'wrap' argument of Linker ? Is it possible to store the names of functions in a file, so that it could be picked up the linker ? 回答1: gcc -g -Wl,--wrap=something,--wrap=somethingElse

Unit test run configuration

跟風遠走 提交于 2019-12-11 14:48:10
问题 I need to get up and running with Cmocka unit testing framework. My setup is: src/math/addition/add.c (+add.h) int add(int a, int b) {return a + b;} src/math/subtraction/sub.c (+sub.h) int sub(int a, int b) {return a - b;} Makefile VPATH := src src/math src/math/addition CFLAGS += -Isrc -Isrc/math -Isrc/math/addition all: libMath clean libMath: add.o sub.o ar rcs bin/libMath add.o sub.o clean: rm -rf *.o %.o: %.c %.h Unit Tests test/math/addition/add_test.c #include "../src/math/addition/add

Wrapping function in c

自古美人都是妖i 提交于 2019-12-11 07:36:25
问题 I got task to write unit tests(using cunit and cmocka) for existing project(written in C), and a met following problem. When I wrap function that is defined in tested file, only original function is called. Additional, a can't change source of tested file. Everything I read didn't met the second condition, but on the other hard it is pretty hard to believe that unit test framework is not prepared for this kind of problem. So is it possible to wrap function call to function that is defined and

Cmocka: checking a structure passed as a parameter

会有一股神秘感。 提交于 2019-12-11 05:59:58
问题 Let's say that I declare a C struct called foo, which has an int field called bar and a char * called baz. How do I use the Cmocka expect_ and check_expected macros to check that the structure passed was correct and both fields have the expected values? If there is an example in the documentation, I missed it. [Update] Perhaps I can use expect_check()? But I can't find an example :-( 回答1: Use expect_memory(...) and check_expected(...) : Example: I assume you have a function under test fut

visual studio c linker wrap option?

元气小坏坏 提交于 2019-12-07 12:37:57
问题 From this article Unit testing with mock objects in C: This is done by using the --wrap linker option which takes the name of the wrapped function as an argument. If the test was compiled using gcc, the invocation might look like: $ gcc -g -Wl,--wrap=chef_cook waiter_test.c chef.c How can I do this when compiling a C project in visual studio? 来源: https://stackoverflow.com/questions/33790425/visual-studio-c-linker-wrap-option

visual studio c linker wrap option?

时光怂恿深爱的人放手 提交于 2019-12-05 19:37:12
From this article Unit testing with mock objects in C : This is done by using the --wrap linker option which takes the name of the wrapped function as an argument. If the test was compiled using gcc, the invocation might look like: $ gcc -g -Wl,--wrap=chef_cook waiter_test.c chef.c How can I do this when compiling a C project in visual studio? 来源: https://stackoverflow.com/questions/33790425/visual-studio-c-linker-wrap-option