I'm designing a library for myself that allows the chaining of streams of data. Let me paint the scenario:
I create a SerialDatastream which is the bottom layer and reads from and writes to a COM port.
I pass a pointer to this to the constructor of a ProtocolDatastream, which interprets the bytes when read from the serial datastream (although it only has knowledge that it fulfills my Datastream interface), and returns them as protocol data units.
Now let's say I want to take the information from the serial port and also log it byte for byte. I insert a TeeDatastream in the middle which reads from one source, but outputs to two destinations:
+-----> Log | Serial ----> Tee ----> Protocol
TeeDatastream is implemented in the following way: when a read operation is performed from one branch, it buffers the data into a member variable. Then, when a read operation is performed on the other branch, it reads the already-buffered data.
(this works fine, by the way)
What this means is that, after each operation, the class must check to see if there exists data that has been read from both branches. This data can then be discarded and so the buffer shrinks as well as growing. However, this is completely invisible to any client of the class. So my question is: what pattern should be used to test invisible but necessary parts of an implementation?