[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is it possible to mock static functions?
- Subject: Re: Is it possible to mock static functions?
- From: "Daniel." <danielhilst@xxxxxxxxx>
- Date: Fri, 30 Dec 2016 14:54:22 -0200
- To: Andreas Schneider <asn@xxxxxxxxxxxxxx>
- Cc: cmocka@xxxxxxxxxxxxxx
Hi, I ended up using weak references on my "mockable" functions, I will try your approach next! Thanks! 2016-12-29 10:19 GMT-02:00 Andreas Schneider <asn@xxxxxxxxxxxxxx>: > On Thursday, 22 December 2016 23:08:32 CET Daniel. wrote: >> Hi > > Hello, > >> 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 > > > -- > Andreas Schneider GPG-ID: CC014E3D > www.cryptomilk.org asn@xxxxxxxxxxxxxx -- "Do or do not. There is no try" Yoda Master