Code

Initialize pointer.
[inkscape.git] / cxxtest / cxxtest / ErrorPrinter.h
1 #ifndef __cxxtest__ErrorPrinter_h__
2 #define __cxxtest__ErrorPrinter_h__
4 //
5 // The ErrorPrinter is a simple TestListener that
6 // just prints "OK" if everything goes well, otherwise
7 // reports the error in the format of compiler messages.
8 // The ErrorPrinter uses std::cout
9 //
11 #include <cxxtest/Flags.h>
13 #ifndef _CXXTEST_HAVE_STD
14 #   define _CXXTEST_HAVE_STD
15 #endif // _CXXTEST_HAVE_STD
17 #include <cxxtest/ErrorFormatter.h>
18 #include <cxxtest/StdValueTraits.h>
20 #ifdef _CXXTEST_OLD_STD
21 #   include <iostream.h>
22 #else // !_CXXTEST_OLD_STD
23 #   include <iostream>
24 #endif // _CXXTEST_OLD_STD
26 namespace CxxTest 
27 {
28     class ErrorPrinter : public ErrorFormatter
29     {
30     public:
31         ErrorPrinter( CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char *preLine = ":", const char *postLine = "" ) :
32             ErrorFormatter( new Adapter(o), preLine, postLine ) {}
33         virtual ~ErrorPrinter() { delete outputStream(); }
35     private:
36         class Adapter : public OutputStream
37         {
38             CXXTEST_STD(ostream) &_o;
39         public:
40             Adapter( CXXTEST_STD(ostream) &o ) : _o(o) {}
41             void flush() { _o.flush(); }
42             OutputStream &operator<<( const char *s ) { _o << s; return *this; }
43             OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); }
44             OutputStream &operator<<( unsigned i )
45             {
46                 char s[1 + 3 * sizeof(unsigned)];
47                 numberToString( i, s );
48                 _o << s;
49                 return *this;
50             }
51         };
52     };
53 }
55 #endif // __cxxtest__ErrorPrinter_h__