So, I assume that you have a global function that is implemented in the library, in which you both include the header file (to get the definition) and the link (to get the implementation).
You obviously need to replace the library implementation with your own - one that does nothing, so you can do this in two ways:
- you replace .dll (or .so) with your own implementation, which has all the methods provided by a third-party library. This is easy once you have written a new version of all third-party lib functions, but writing them all can be a pain.
- you temporarily delete the library and replace the calls you make with the original .cpp file that implements these functions. Thus, you will create your own sendMail () function in the .cpp file and include it in the program instead of mailsender.h.
The latter is simpler, but you may also need to modify your program so as not to mess with a third party lib. This may also require a #include change, as some compilers (such as VC ++) allow you to embed linker directives in your source code. If you do this, you cannot stop the linker from including a third-party library.
Another option is to change the code to use another call to sendMail, for example test__sendMail (), which you implement yourself. Wrap this macro to conditionally enable your or actual function call depending on your build options.
If it was a C ++ library, then you can probably use the fake infrastructure, as you are used to, but it looks like its C library, and they just provide a list of functions that you use directly in your code. You can wrap the library in your own class and use this, and not directly reference third-party lib functions.
There is a list of C mocking frameworks.
source share