0

I am writing unit tests with gtest at the moment and want to test if the command line output of a function is correct. It would be best if I could determine what was written exactly but if that is not possible, being able to differentiate if something was written or not would suffice.

The only thing I have available is the pointer to the output stream defined as following:

std::ostream* outStream = &std::cout;

I tried casting outStream to a pointer on a String and the other way around but that (obviously) didn't work and threw SEH exeptions.

I am pretty lost with what to do so even some general advice on what to look into would be helpful.

Thank you for your help.

cout
  • 1
  • However, as the comments there also mention, it could be better to just enable injection of ostream in the tested class, so that it would write to what you want instead of `std::cout` always. – Yksisarvinen Jun 13 '21 at 10:59

0 Answers0