MultiPrinter.h revision 5acd50728a4deae35313988cbd5b72faf5e8445a
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifndef SEEN_MULTI_PRINTER_H
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define SEEN_MULTI_PRINTER_H
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock#include <cxxtest/Flags.h>
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifndef _CXXTEST_HAVE_STD
fa9e4066f08beec538e775443c5be79dd423fcabahrens# define _CXXTEST_HAVE_STD
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif // _CXXTEST_HAVE_STD
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <cxxtest/ErrorFormatter.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <cxxtest/StdValueTraits.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifdef _CXXTEST_OLD_STD
fa9e4066f08beec538e775443c5be79dd423fcabahrens# include <iostream.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens# include <fstream.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens# include <string.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#else // !_CXXTEST_OLD_STD
fa9e4066f08beec538e775443c5be79dd423fcabahrens# include <iostream>
fa9e4066f08beec538e775443c5be79dd423fcabahrens# include <fstream>
fa9e4066f08beec538e775443c5be79dd423fcabahrens# include <string>
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock#endif // _CXXTEST_OLD_STD
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <cxxtest/TeeListener.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "TRPIFormatter.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "PylogFormatter.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensnamespace CxxTest {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensclass MultiPrinter : public TeeListener
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrenspublic:
fa9e4066f08beec538e775443c5be79dd423fcabahrens MultiPrinter( const char* baseName = "result" ) :
fa9e4066f08beec538e775443c5be79dd423fcabahrens TeeListener(),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _baseName( baseName ),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _xmlName( _baseName + ".xml" ),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _logName( _baseName + ".log" ),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _xmlFile( _xmlName.c_str(), CXXTEST_STD(ios::out)),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _logFile( _logName.c_str(), CXXTEST_STD(ios::out)),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _dstOne( new FileAdapter( CXXTEST_STD(cout) ) ),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _dstXml( new FileAdapter( _xmlFile ) ),
fa9e4066f08beec538e775443c5be79dd423fcabahrens _dstPylog( new FileAdapter( _logFile ), _baseName.c_str() )
fa9e4066f08beec538e775443c5be79dd423fcabahrens {
fa9e4066f08beec538e775443c5be79dd423fcabahrens setFirst( _dstOne );
fa9e4066f08beec538e775443c5be79dd423fcabahrens setSecond( _subTee );
fa9e4066f08beec538e775443c5be79dd423fcabahrens _subTee.setFirst( _dstXml );
fa9e4066f08beec538e775443c5be79dd423fcabahrens _subTee.setSecond( _dstPylog );
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens virtual ~MultiPrinter()
fa9e4066f08beec538e775443c5be79dd423fcabahrens {
fa9e4066f08beec538e775443c5be79dd423fcabahrens _xmlFile.close();
fa9e4066f08beec538e775443c5be79dd423fcabahrens _logFile.close();
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens int run()
fa9e4066f08beec538e775443c5be79dd423fcabahrens {
fa9e4066f08beec538e775443c5be79dd423fcabahrens TestRunner::runAllTests( *this );
fa9e4066f08beec538e775443c5be79dd423fcabahrens return tracker().failedTests();
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensprotected:
fa9e4066f08beec538e775443c5be79dd423fcabahrens CXXTEST_STD(string) _baseName;
fa9e4066f08beec538e775443c5be79dd423fcabahrens CXXTEST_STD(string) _xmlName;
fa9e4066f08beec538e775443c5be79dd423fcabahrens CXXTEST_STD(string) _logName;
fa9e4066f08beec538e775443c5be79dd423fcabahrens CXXTEST_STD(fstream) _xmlFile;
fa9e4066f08beec538e775443c5be79dd423fcabahrens CXXTEST_STD(fstream) _logFile;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
22ac5be40819d45ddf9d12dc1db410dbcdaac4abperrin TeeListener _subTee;
c5c6ffa0498b9c8555798756141b4a3061a138c1maybee ErrorFormatter _dstOne;
fa9e4066f08beec538e775443c5be79dd423fcabahrens TRPIFormatter _dstXml;
fa9e4066f08beec538e775443c5be79dd423fcabahrens PylogFormatter _dstPylog;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensprivate:
fa9e4066f08beec538e775443c5be79dd423fcabahrens class FileAdapter : public OutputStream
fa9e4066f08beec538e775443c5be79dd423fcabahrens {
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileAdapter( const FileAdapter & );
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileAdapter &operator=( const FileAdapter & );
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens CXXTEST_STD(ostream) &_o;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens public:
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileAdapter( CXXTEST_STD(ostream) &o ) : _o(o) {}
fa9e4066f08beec538e775443c5be79dd423fcabahrens void flush() { _o.flush(); }
fa9e4066f08beec538e775443c5be79dd423fcabahrens OutputStream &operator<<( const char *s ) { _o << s; return *this; }
fa9e4066f08beec538e775443c5be79dd423fcabahrens OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); }
fa9e4066f08beec538e775443c5be79dd423fcabahrens OutputStream &operator<<( unsigned i )
fa9e4066f08beec538e775443c5be79dd423fcabahrens {
fa9e4066f08beec538e775443c5be79dd423fcabahrens char s[1 + 3 * sizeof(unsigned)];
fa9e4066f08beec538e775443c5be79dd423fcabahrens numberToString( i, s );
fa9e4066f08beec538e775443c5be79dd423fcabahrens _o << s;
fa9e4066f08beec538e775443c5be79dd423fcabahrens return *this;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens };
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
22ac5be40819d45ddf9d12dc1db410dbcdaac4abperrin Local Variables:
22ac5be40819d45ddf9d12dc1db410dbcdaac4abperrin mode:c++
a24e15ce89c6323e2a61a78fe040efaa2d9a0e81perrin c-file-style:"stroustrup"
fa9e4066f08beec538e775443c5be79dd423fcabahrens c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
fa9e4066f08beec538e775443c5be79dd423fcabahrens indent-tabs-mode:nil
fa9e4066f08beec538e775443c5be79dd423fcabahrens fill-column:99
fa9e4066f08beec538e775443c5be79dd423fcabahrens End:
fa9e4066f08beec538e775443c5be79dd423fcabahrens*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif //SEEN_MULTI_PRINTER_H
fa9e4066f08beec538e775443c5be79dd423fcabahrens