I have a piece of code implementing a class that I want to test, lets call it A.cpp and the test test_A.cpp.
The A.cpp file uses some functions from a library that commands a particular device, lets call this libdevice.
In particular, the A class offers a method connect() which internally calls send_conf() function, which is defined inside libdevice. In code:
- A.cpp file
#include <libdevice.h>; public class A{ //private public: bool connect() { int myconf = 3; if(send_conf(myconf) == -1) { return false; } return true; } }
- test_A.cpp
extern "C" { MOCK_FUNCTION(send_conf, 1, int(int)); }; BOOST_AUTO_TEST_CASE(connect_test) { bool ret; A* myA= new A(); MOCK_EXPECT(send_conf).once().with(3).returns(-1); ret = myA->connect(); BOOST_CHECK_EQUAL(ret, false); }
Now, if I use the related MOCK_FUNCTION() macro from mock-turtle library when I compile my test I receive a linker error:
A.cpp: undefined reference to 'send_conf'.
This is due to not linking the library, which at this step is not available. How can I achieve a mock for this set-up in mock-turtle?