Re: Is it possible to mock static functions?
- Subject: Re: Is it possible to mock static functions?
- From: Andreas Schneider <asn@xxxxxxxxxxxxxx>
- Date: Thu, 29 Dec 2016 13:19:54 +0100
- To: cmocka@xxxxxxxxxxxxxx
- Cc: "Daniel." <danielhilst@xxxxxxxxx>
On Thursday, 22 December 2016 23:08:32 CET Daniel. wrote:
> I have a library that I want to test using cmocka. By the way, what a
> wonderful project!!!
thank you very much.
> That library has a static predicate function that returns true for
> connection and false for lack of it. There is another public write
> function that send data. I want to test the write function, but it
> checks if there is connection, returning error if not, so how can I
> mock the predicate to return a fake true? Is possible to mock static
> functions from a shared object?
Yes, it is possible if you include the .c file in your test source code.
Andreas Schneider GPG-ID: CC014E3D