source: git/libpolys/tests/cxxtest/ErrorPrinter.h @ 405407

spielwiese
Last change on this file since 405407 was 4aa8610, checked in by Mohamed Barakat <mohamed.barakat@…>, 13 years ago
created libpolys/tests and set up the beginning of a test-suite using cxxtest
  • Property mode set to 100644
File size: 1.6 KB
Line 
1#ifndef __cxxtest__ErrorPrinter_h__
2#define __cxxtest__ErrorPrinter_h__
3
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//
10
11#include <cxxtest/Flags.h>
12
13#ifndef _CXXTEST_HAVE_STD
14#   define _CXXTEST_HAVE_STD
15#endif // _CXXTEST_HAVE_STD
16
17#include <cxxtest/ErrorFormatter.h>
18#include <cxxtest/StdValueTraits.h>
19
20#ifdef _CXXTEST_OLD_STD
21#   include <iostream.h>
22#else // !_CXXTEST_OLD_STD
23#   include <iostream>
24#endif // _CXXTEST_OLD_STD
25
26namespace 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(); }
34
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}
54
55#endif // __cxxtest__ErrorPrinter_h__
Note: See TracBrowser for help on using the repository browser.