1 #ifndef __cxxtest__TestTracker_h__
2 #define __cxxtest__TestTracker_h__
4 //
5 // The TestTracker tracks running tests
6 // The actual work is done in CountingListenerProxy,
7 // but this way avoids cyclic references TestListener<->CountingListenerProxy
8 //
10 #include <cxxtest/TestListener.h>
11 #include <cxxtest/DummyDescriptions.h>
13 namespace CxxTest
14 {
15 class TestListener;
17 class TestTracker : public TestListener
18 {
19 public:
20 virtual ~TestTracker();
22 static TestTracker &tracker();
24 const TestDescription *fixTest( const TestDescription *d ) const;
25 const SuiteDescription *fixSuite( const SuiteDescription *d ) const;
26 const WorldDescription *fixWorld( const WorldDescription *d ) const;
28 const TestDescription &test() const { return *_test; }
29 const SuiteDescription &suite() const { return *_suite; }
30 const WorldDescription &world() const { return *_world; }
32 bool testFailed() const { return (testFailedAsserts() > 0); }
33 bool suiteFailed() const { return (suiteFailedTests() > 0); }
34 bool worldFailed() const { return (failedSuites() > 0); }
36 unsigned warnings() const { return _warnings; }
37 unsigned failedTests() const { return _failedTests; }
38 unsigned testFailedAsserts() const { return _testFailedAsserts; }
39 unsigned suiteFailedTests() const { return _suiteFailedTests; }
40 unsigned failedSuites() const { return _failedSuites; }
42 void enterWorld( const WorldDescription &wd );
43 void enterSuite( const SuiteDescription &sd );
44 void enterTest( const TestDescription &td );
45 void leaveTest( const TestDescription &td );
46 void leaveSuite( const SuiteDescription &sd );
47 void leaveWorld( const WorldDescription &wd );
48 void trace( const char *file, unsigned line, const char *expression );
49 void warning( const char *file, unsigned line, const char *expression );
50 void failedTest( const char *file, unsigned line, const char *expression );
51 void failedAssert( const char *file, unsigned line, const char *expression );
52 void failedAssertEquals( const char *file, unsigned line,
53 const char *xStr, const char *yStr,
54 const char *x, const char *y );
55 void failedAssertSameData( const char *file, unsigned line,
56 const char *xStr, const char *yStr,
57 const char *sizeStr, const void *x,
58 const void *y, unsigned size );
59 void failedAssertDelta( const char *file, unsigned line,
60 const char *xStr, const char *yStr, const char *dStr,
61 const char *x, const char *y, const char *d );
62 void failedAssertDiffers( const char *file, unsigned line,
63 const char *xStr, const char *yStr,
64 const char *value );
65 void failedAssertLessThan( const char *file, unsigned line,
66 const char *xStr, const char *yStr,
67 const char *x, const char *y );
68 void failedAssertLessThanEquals( const char *file, unsigned line,
69 const char *xStr, const char *yStr,
70 const char *x, const char *y );
71 void failedAssertPredicate( const char *file, unsigned line,
72 const char *predicate, const char *xStr, const char *x );
73 void failedAssertRelation( const char *file, unsigned line,
74 const char *relation, const char *xStr, const char *yStr,
75 const char *x, const char *y );
76 void failedAssertThrows( const char *file, unsigned line,
77 const char *expression, const char *type,
78 bool otherThrown );
79 void failedAssertThrowsNot( const char *file, unsigned line, const char *expression );
81 private:
82 TestTracker( const TestTracker & );
83 TestTracker &operator=( const TestTracker & );
85 static bool _created;
86 TestListener _dummyListener;
87 DummyWorldDescription _dummyWorld;
88 unsigned _warnings, _failedTests, _testFailedAsserts, _suiteFailedTests, _failedSuites;
89 TestListener *_l;
90 const WorldDescription *_world;
91 const SuiteDescription *_suite;
92 const TestDescription *_test;
94 const TestDescription &dummyTest() const;
95 const SuiteDescription &dummySuite() const;
96 const WorldDescription &dummyWorld() const;
98 void setWorld( const WorldDescription *w );
99 void setSuite( const SuiteDescription *s );
100 void setTest( const TestDescription *t );
101 void countWarning();
102 void countFailure();
104 friend class TestRunner;
106 TestTracker();
107 void initialize();
108 void setListener( TestListener *l );
109 };
111 inline TestTracker &tracker() { return TestTracker::tracker(); }
112 };
114 #endif // __cxxtest__TestTracker_h__