I use cxxtest as a test environment for my C ++ classes and would like to figure out a way to simulate sending data to classes that would normally expect to receive it from standard input. I have several different files that I would like to send to classes during different tests, so redirecting from the command line to the test suite executable is not an option.
Basically, I would like to find a way to override or redirect the 'stdin' descriptor to another value that I create inside my program, and then use fwrite () from these tests so that the corresponding fread () inside the class will extract data from the program, not from the actual standard I / O handles associated with the executable.
Is it possible? Bonus points for a platform-independent solution, but at least I need it to work with Visual Studio 9 under Windows.
source share