Gennadiy Rozental wrote:
wrote in message
news:000501c68bea$0018c7f0$6501a8c0@Furst...
[snip]
You don't really need to rewrite main to implement redirection. There
are several ways to do this. One of simplest id to use global fixture:
std::ofstream logStream;
std::ofstream reportStream;
struct output_setup {
output_setup()
{
logStream.open( "c:\\log.xml" );
unit_test_log.set_stream( logStream );
reportStream.open( "c:\\report.xml" );
results_reporter::set_stream( reportStream );
}
};
BOOST_GLOBAL_FIXTURE( output_setup );
I originally did something similar:
---
#define BOOST_TEST_MODULE foo
#include
#include <fstream>
#include <iostream>
using namespace boost::unit_test;
struct output_setup {
output_setup()
{
logStream_.open( "c:\\temp\\log.xml" );
if (logStream_.is_open())
unit_test_log.set_stream( logStream_ );
}
~output_setup()
{
if (logStream_.is_open())
unit_test_log.set_stream( std::cout );
}
std::ofstream logStream_;
};
BOOST_GLOBAL_FIXTURE( output_setup );
---
The above kind-of works, but the final "</TestLog>" goes to stdout (which
was unexpected, at least for me). I understand what happens, but wouldn't it
be more intuitive to have the above working?
OTOH, defining the output_setup instance as a static instance:
output_setup g_outputSetup;
seems to work just fine though, and does not require 1.34 either.
// Johan