|
Boost Users : |
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2006-06-12 04:30:37
Gennadiy Rozental wrote:
> <hfye-wila_at_[hidden]> wrote in message
> news:000501c68bea$0018c7f0$6501a8c0_at_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 <boost/test/auto_unit_test.hpp> #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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net