1 #ifndef SEEN_MULTI_PRINTER_H
2 #define SEEN_MULTI_PRINTER_H
5 #include <cxxtest/Flags.h>
7 #ifndef _CXXTEST_HAVE_STD
8 # define _CXXTEST_HAVE_STD
9 #endif // _CXXTEST_HAVE_STD
11 #include <cxxtest/ErrorFormatter.h>
12 #include <cxxtest/StdValueTraits.h>
14 #ifdef _CXXTEST_OLD_STD
15 # include <iostream.h>
16 # include <fstream.h>
17 # include <string.h>
18 #else // !_CXXTEST_OLD_STD
19 # include <iostream>
20 # include <fstream>
21 # include <string>
22 #endif // _CXXTEST_OLD_STD
25 #include <cxxtest/TeeListener.h>
26 #include "TRPIFormatter.h"
27 #include "PylogFormatter.h"
29 namespace CxxTest {
31 class MultiPrinter : public TeeListener
32 {
33 public:
34 MultiPrinter( const char* baseName = "result" ) :
35 TeeListener(),
36 _baseName( baseName ),
37 _xmlName( _baseName + ".xml" ),
38 _logName( _baseName + ".log" ),
39 _xmlFile( _xmlName.c_str(), CXXTEST_STD(ios::out)),
40 _logFile( _logName.c_str(), CXXTEST_STD(ios::out)),
41 _dstOne( new FileAdapter( CXXTEST_STD(cout) ) ),
42 _dstXml( new FileAdapter( _xmlFile ) ),
43 _dstPylog( new FileAdapter( _logFile ), _baseName.c_str() )
44 {
45 setFirst( _dstOne );
46 setSecond( _subTee );
47 _subTee.setFirst( _dstXml );
48 _subTee.setSecond( _dstPylog );
49 }
51 virtual ~MultiPrinter()
52 {
53 _xmlFile.close();
54 _logFile.close();
55 }
57 int run()
58 {
59 TestRunner::runAllTests( *this );
60 return tracker().failedTests();
61 }
63 protected:
64 CXXTEST_STD(string) _baseName;
65 CXXTEST_STD(string) _xmlName;
66 CXXTEST_STD(string) _logName;
67 CXXTEST_STD(fstream) _xmlFile;
68 CXXTEST_STD(fstream) _logFile;
70 TeeListener _subTee;
71 ErrorFormatter _dstOne;
72 TRPIFormatter _dstXml;
73 PylogFormatter _dstPylog;
75 private:
76 class FileAdapter : public OutputStream
77 {
78 FileAdapter( const FileAdapter & );
79 FileAdapter &operator=( const FileAdapter & );
81 CXXTEST_STD(ostream) &_o;
83 public:
84 FileAdapter( CXXTEST_STD(ostream) &o ) : _o(o) {}
85 void flush() { _o.flush(); }
86 OutputStream &operator<<( const char *s ) { _o << s; return *this; }
87 OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); }
88 OutputStream &operator<<( unsigned i )
89 {
90 char s[1 + 3 * sizeof(unsigned)];
91 numberToString( i, s );
92 _o << s;
93 return *this;
94 }
95 };
97 };
99 }
101 /*
102 Local Variables:
103 mode:c++
104 c-file-style:"stroustrup"
105 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
106 indent-tabs-mode:nil
107 fill-column:99
108 End:
109 */
110 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
112 #endif //SEEN_MULTI_PRINTER_H