mercredi 31 août 2016

#define not replacing function name in C++

I am writing unit tests for some legacy code. The framework that we are using here is the cxxtest. It not that good while mocking functions.

So after some research, I found a workaround. I am using #define for changing the call from original function to mock function. For example, if I want to mock socket function in C, I just define another function mock_socket in my mock.hpp file and include it in the test.hpp file. In my test.hpp I used #define like this, #define socket mock_socket. But it is not replacing function socket with mock_socket. For building, I am using cmake. I think it is something associated with cmake. I am new to cmake. Can anyone tell what is the problem here?

PS: It works fine in a model project I created for the testing purpose. But I didn't use cmake in it.

Aucun commentaire:

Enregistrer un commentaire