I have a large function, like the following:
void processMsg(uint8_t *msg) {
//Some structure initialisation, msg parsing and the like
for (int i=0;i<msgRegisters;++i) {
//Process each message register
}
}
and I have refactored the code, extracting a method, into the following:
static void processMsgRegister(uint8_t *msg, int i)
{
//Process one register
}
void processMsg(uint8_t *msg) {
//Some structure initialisation, msg parsing and the like
for (int i=0;i<msgRegisters;++i) {
processMsgRegister(msg, i);
}
}
Now, I want to unit test this functions.
I can easily test processMsg
since it is publicly available from the .h
, and I have done the necessary tests for checking that the structure initialisation and parsing is correct.
The problem comes with testing the processMsgRegister
internal function. I want to test it alone, without having to test each time all the processMsg
external function, since I have to clutter the tests with all the msg processing callbacks, expectations and so, for no point, since it is already tested by itself.
After some comments, I think the best approach would be to move this methods to a new class
, making them public
there, but not publishing the class, so it can be tested independently from the rest.
So my question now is:
- How can I implement this approach in
plain C
?
This question is both, from a point of view of code organisation (spliting into multiple files, and so) and from a point of view of useful compiler/linker flags for this matter.
My setup: gcc, cmake, unity, cmock