• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test-runner.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include <wibble/sys/macros.h>
00003 
00004 #include <unistd.h>
00005 #ifdef POSIX
00006 #include <wibble/sys/pipe.h>
00007 #endif
00008 #include <cstdio>
00009 
00010 #define RUN(x, y) x().y()
00011 
00012 struct RunTest {
00013     const char *name;
00014     void (*run)();
00015 };
00016 
00017 struct RunSuite {
00018     const char *name;
00019     RunTest *tests;
00020     int testCount;
00021 
00022     int findTest( std::string name ) {
00023         for ( int i = 0; i < testCount; ++i )
00024             if ( tests[i].name == name )
00025                 return i;
00026         return -1;
00027     }
00028 
00029 };
00030 
00031 struct RunFeedback {
00032     virtual void status( std::string l ) = 0;
00033     virtual void waitForAck() = 0;
00034 };
00035 
00036 #ifdef POSIX
00037 struct RunAll {
00038     RunSuite *suites;
00039     int suiteCount;
00040     RunFeedback *feedback;
00041 
00042     RunSuite *findSuite( std::string name ) {
00043         for ( int i = 0; i < suiteCount; ++i )
00044             if ( suites[i].name == name )
00045                 return suites + i;
00046         return 0;
00047     }
00048 
00049     void runSuite( RunSuite &s, int fromTest, int suite, int suiteCount )
00050     {
00051         feedback->status( wibble::str::fmtf(
00052             "s/s: (%d/%d) %s", suite + 1, suiteCount, s.name ) );
00053         for ( int i = fromTest; i < s.testCount; ++i ) {
00054             feedback->status( wibble::str::fmtf(
00055                 "t/s: (%d/%d) %s", i, s.testCount, s.tests[i].name ) );
00056             feedback->waitForAck();
00057             s.tests[i].run();
00058             feedback->status( std::string( "t/d: " ) + s.tests[i].name );
00059             feedback->waitForAck();
00060             // exit( 0 ); // TODO make this optional; safety vs
00061                           // performance tradeoff
00062         }
00063         feedback->status( std::string( "s/d: " ) + s.name );
00064     }
00065 
00066     void runTest( RunSuite &s, int test )
00067     {
00068         feedback->status( std::string( "s/s: (1/1) " ) + s.name );
00069         feedback->status( std::string( "t/s: (1/1) " ) + s.tests[test].name );
00070         feedback->waitForAck();
00071         s.tests[test].run();
00072         feedback->status( std::string( "t/d: " ) + s.tests[test].name );
00073         feedback->waitForAck();
00074         feedback->status( std::string( "s/d: " ) + s.name );
00075     }
00076 
00077     void runFrom( int suite, int test )
00078     {
00079         for ( int i = suite; i < suiteCount; ++i ) {
00080             assert( suite <= suiteCount );
00081             runSuite( suites[i], test, i, suiteCount );
00082             test = 0;
00083         }
00084     }
00085 };
00086 #endif

Generated on Sun Feb 17 2013 02:35:46 for wibble by  doxygen 1.7.1