Code

Store cached icons to disk between runs, and invalidate/purge as needed.
[inkscape.git] / cxxtest / cxxtest / TestRunner.h
1 #ifndef __cxxtest_TestRunner_h__
2 #define __cxxtest_TestRunner_h__
4 //
5 // TestRunner is the class that runs all the tests.
6 // To use it, create an object that implements the TestListener
7 // interface and call TestRunner::runAllTests( myListener );
8 // 
10 #include <cxxtest/TestListener.h>
11 #include <cxxtest/RealDescriptions.h>
12 #include <cxxtest/TestSuite.h>
13 #include <cxxtest/TestTracker.h>
15 namespace CxxTest 
16 {
17     class TestRunner
18     {
19     public:
20         static void runAllTests( TestListener &listener )
21         {
22             tracker().setListener( &listener );
23             _TS_TRY { TestRunner().runWorld(); }
24             _TS_LAST_CATCH( { tracker().failedTest( __FILE__, __LINE__, "Exception thrown from world" ); } );
25             tracker().setListener( 0 );
26         }
28         static void runAllTests( TestListener *listener )
29         {
30             if ( listener ) {
31                 listener->warning( __FILE__, __LINE__, "Deprecated; Use runAllTests( TestListener & )" );
32                 runAllTests( *listener );
33             }
34         }        
35     
36     private:
37         void runWorld()
38         {
39             RealWorldDescription wd;
40             WorldGuard sg;
41             
42             tracker().enterWorld( wd );
43             if ( wd.setUp() ) {
44                 for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() )
45                     if ( sd->active() )
46                         runSuite( *sd );
47             
48                 wd.tearDown();
49             }
50             tracker().leaveWorld( wd );
51         }
52     
53         void runSuite( SuiteDescription &sd )
54         {
55             StateGuard sg;
56             
57             tracker().enterSuite( sd );
58             if ( sd.setUp() ) {
59                 for ( TestDescription *td = sd.firstTest(); td; td = td->next() )
60                     if ( td->active() )
61                         runTest( *td );
63                 sd.tearDown();
64             }
65             tracker().leaveSuite( sd );
66         }
68         void runTest( TestDescription &td )
69         {
70             StateGuard sg;
71             
72             tracker().enterTest( td );
73             if ( td.setUp() ) {
74                 td.run();
75                 td.tearDown();
76             }
77             tracker().leaveTest( td );
78         }
79         
80         class StateGuard
81         {
82 #ifdef _CXXTEST_HAVE_EH
83             bool _abortTestOnFail;
84 #endif // _CXXTEST_HAVE_EH
85             unsigned _maxDumpSize;
86             
87         public:
88             StateGuard()
89             {
90 #ifdef _CXXTEST_HAVE_EH
91                 _abortTestOnFail = abortTestOnFail();
92 #endif // _CXXTEST_HAVE_EH
93                 _maxDumpSize = maxDumpSize();
94             }
95             
96             ~StateGuard()
97             {
98 #ifdef _CXXTEST_HAVE_EH
99                 setAbortTestOnFail( _abortTestOnFail );
100 #endif // _CXXTEST_HAVE_EH
101                 setMaxDumpSize( _maxDumpSize );
102             }
103         };
105         class WorldGuard : public StateGuard
106         {
107         public:
108             WorldGuard() : StateGuard()
109             {
110 #ifdef _CXXTEST_HAVE_EH
111                 setAbortTestOnFail( CXXTEST_DEFAULT_ABORT );
112 #endif // _CXXTEST_HAVE_EH
113                 setMaxDumpSize( CXXTEST_MAX_DUMP_SIZE );
114             }
115         };
116     };
118     //
119     // For --no-static-init
120     //
121     void initialize();
122 };
125 #endif // __cxxtest_TestRunner_h__