I will try to make this a purely minimal example, to be applicable to as many people as possible, as well as to protect any kind of code sharing that may violate the NDA. Hope all is well!
I use CppUTest and CppUMock (compiling with gcc / g ++ and make files created with CMake) in combination with the Gitlab Continuous Integration software to create a single test environment for future commits and software releases. However, I ran into a problem. Let's say I have the following folder setting (I have the minimal ability to change it besides the contents of the / tests folder):
+-- src +-- driver1.c +-- driver2.c +-- inc +-- driver1.h +-- driver2.h +-- tests +-- test_driver1.cpp +-- test_driver2.cpp +-- main.cpp +-- cmakelists.txt
The CMakeLists file will include the inc folder, the compilation of the src folder, and the compilation of the test folder. However, let's say that driver2.c relies on methods defined by driver1.c. This is normal if there is no mocking setup, because you can just check the results of calls using driver2 methods. However, say that I want to mock the driver1 method1 function so that I can correctly check the operator1 method of operator1 method (using CppUMock). This is usually normal if driver1 does not compile, but adds something like the file test_driver2.cpp:
void method1(int n) { mock().actualCall("method1").withParameter("n", n); }
There will be a collision with the actual method1 in driver 1.c with a linker error:
CMakeFiles/Tests.dir/.../src/driver1.c:(.text+0x11d): multiple definition of 'method1' CMakeFiles/Tests.dir/.../src/test_driver2.cpp:(.text+0x0): first defined here
As requested by the commentator, here is what the include structure is:
driver1.c includes driver1.h (obviously) driver2.c includes driver2.h (obviously) driver2.h includes driver1.h (for calling method1) test cpp files include their respective .h files (test_driver1.cpp -> driver1.h and test_driver2.cpp -> driver2.h)
method1 is declared in driver1.h and defined in driver1.c. I can not edit these files.
I am pleased to add data on request.
What is the best way to get around this mocking problem?