0

I have tried "cmocka" in visual studio solution, and it works fine with simple asserts. But when it comes to "mocking" I can't find a way to "mock" the functions from the library I am testing.

It is a C project in visual studio and there isn't a "CMakeList.txt" file.

If anyone can help me with a solution, I will be very thankful.

EDIT

What I am trying to do is to test some functions from the library which are more complicated. And I am trying to mock them, is that possible at all?

I am using this as an example: https://gitlab.com/cmocka/cmocka/-/blob/master/example/mock/uptime/….

I am trying to reimplement my function from the library like the one on the example above, using: __wrap_myfunction(int i, char *c); Since my project is not a CMake project, I don't know how to define the "wrap" method.

the busybee
  • 10,755
  • 3
  • 13
  • 30
jst
  • 1
  • 1
  • Why do you want to mock functions of the library under test? Commonly you mock functions of all other components. -- However, please provide a [mre]. Oh, and please take the [tour] to learn how this site works. – the busybee Aug 19 '22 at 13:14
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 20 '22 at 00:19
  • @thebusybee thanks for your answer, what i am trying to do is test some functions from the library which are more complicated, and i am trying to mock them, is that possible at all ? I am using this as an example: https://gitlab.com/cmocka/cmocka/-/blob/master/example/mock/uptime/test_uptime.c, and i am trying to reimplement my function from the library like the one on the example above, using: __wrap_myfunction(int i, char *c); Since my project is not a CMakeProject and i don't have the CMakeLists.txt file, i don't know how to define the "wrap" method. – jst Aug 22 '22 at 08:02
  • The next time, please [edit] your question with new information. This time I did it for you. ;-) -- Yes, of course it is possible to mock functions of a system library. -- The linker option "--wrap" and the mock implementation "__wrap_xxx()" are specific to the linker of the GNU compiler collection, known as GCC. I'm sure the Microsoft compiler of Visual Studio does not understand this linker option, and as such you need another solution. But since I avoid Visual Studio as much as possible, I cannot help you here. – the busybee Aug 22 '22 at 09:19
  • @thebusybee thank you again, and sorry for the omissions, it's my first ever post on this page. :) – jst Aug 22 '22 at 09:25
  • That's why I asked you to take the [tour]. If you had done it, you would know. ;-) So now is the time to do so. And while you're at it, please read "[ask]". This is not a forum. – the busybee Aug 22 '22 at 09:27

0 Answers0