www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Unit tests for I/O functions

reply Jason House <jason.james.house gmail.com> writes:
If I have a class that reads from an InputStream and writes to an 
OutputStream, what is the recommended method for writing a unit test for 
sending commands in one stream and testing its output of the other 
stream?  Would a pair of MemoryStream's be most appropriate?
Apr 27 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Jason,

 If I have a class that reads from an InputStream and writes to an
 OutputStream, what is the recommended method for writing a unit test
 for sending commands in one stream and testing its output of the other
 stream?  Would a pair of MemoryStream's be most appropriate?
 
that's what I do.
Apr 27 2007
parent Jason House <jason.james.house gmail.com> writes:
BCS wrote:
 Reply to Jason,
 
 If I have a class that reads from an InputStream and writes to an
 OutputStream, what is the recommended method for writing a unit test
 for sending commands in one stream and testing its output of the other
 stream?  Would a pair of MemoryStream's be most appropriate?
that's what I do.
So far, I haven't had any success with the unit tests even though the normal usage works fine... The thread's run function has something to the effect of: while(1){ char[] command = inStream.readLine(); process(command); } It seems that readLine does not block with a memoryStream like it does with din and dout. What's the best work around? PS: I tried the following but had no luck. process(command) never got called after the unit test wrote to the stream (with writefln): while(1){ char[] command = inStream.readLine(); if (command.length == 0) continue; process(command); }
Apr 28 2007