I am currently building an application with a layered architecture in C. Currently, I have built and tested the bottom layer, which is a networking module, providing functionality such as connecting/disconnecting, sending messages, etc.
On top of it, I am building another layer, that implements a communication protocol. It has functionality such as connect, which calls network_connect internally to create the actual connection and does some protocol related business, such as registering on a server.
Now, the problem is how should I test the second layer? The original approach was to create 2 threads, open a server on one of them, connect to it and monitor the traffic (basically check if the required protocol-related data has been transferred). However, I do not need to test the actual network connection, since that is already tested in the tests for the networking module and I feel this approach is too complicated.
One approach I could think of was to expose the internal socket file descriptor from the networking module through getters/setters (which I needed anyway) and replace the network connection with a pipe. This approach works for most of the operations, except for the actual connection, where the network connect routine is called internally. Also, the connection in this case is made to a server whose ip/port is not exposed outside of this module (it is currently defined as a constant and will soon be moved into a config file).
How should I approach the testing of this module?