vrj::test::TestRunner Class Reference

Groups tests together and is also in charge of running them and capturing a list of any failures that occur. More...

#include <vrj/Test/TestRunner.h>

Collaboration diagram for vrj::test::TestRunner:

Collaboration graph
[legend]
List of all members.

Public Types

enum  State { Uninitialized, Processing, DoneProcessing }

Public Member Functions

 TestRunner ()
void initialize (vrj::App *app)
 Initializes the test suite.
void processTests ()
 Progresses the state of testing.
void addTest (Test *test)
State getState ()
 Are the tests done processing?
void printFailures ()
 Prints out the test failures.

Protected Attributes

vrj::AppmApp
 The application to test.
State mCurState
 Store the current state of processing.
int mCurTestIndex
 Index of the current test to run.
std::vector< Test * > mTests
 List of tests to run.
std::vector< TestFailuremTestFailures
 List of test failures.

Detailed Description

Groups tests together and is also in charge of running them and capturing a list of any failures that occur.

Definition at line 58 of file TestRunner.h.


Member Enumeration Documentation

enum vrj::test::TestRunner::State

Enumerator:
Uninitialized 
Processing 
DoneProcessing 

Definition at line 61 of file TestRunner.h.

00062    {
00063       Uninitialized,
00064       Processing,
00065       DoneProcessing
00066    };


Constructor & Destructor Documentation

vrj::test::TestRunner::TestRunner (  )  [inline]

Definition at line 69 of file TestRunner.h.

00070       : mApp(NULL)
00071       , mCurState(Uninitialized)
00072       , mCurTestIndex(-1)
00073    {;}


Member Function Documentation

void vrj::test::TestRunner::initialize ( vrj::App app  )  [inline]

Initializes the test suite.

Must be called before running the tests and after all tests have been added.

Definition at line 80 of file TestRunner.h.

References mApp, mCurState, mTestFailures, mTests, and Processing.

00081    {
00082       mApp = app;
00083 
00084       // Initialize the tests
00085       vprASSERT(mTests.size() > 0);
00086       for(unsigned t=0;t<mTests.size();t++)
00087       {
00088          mTests[t]->setApp(app);
00089       }
00090 
00091       // Clear the failures
00092       mTestFailures.clear();
00093 
00094       mCurState = Processing;
00095    }

void vrj::test::TestRunner::processTests (  )  [inline]

Progresses the state of testing.

Called at the end of preFrame by apps that want to run tests.

Definition at line 101 of file TestRunner.h.

References DoneProcessing, mApp, mCurState, mCurTestIndex, mTestFailures, mTests, and printFailures().

00102    {
00103       vprASSERT(NULL != mApp);
00104 
00105       bool test_failed(false);
00106 
00107       if(mCurTestIndex < (int)mTests.size())      // Check to see if there are tests to run
00108       {
00109          if(-1 == mCurTestIndex)                   // First time through
00110          {
00111             mCurTestIndex = 0;
00112             std::cout << "TestRunner: Starting test: " << mTests[mCurTestIndex]->getName() << std::endl;
00113             mTests[mCurTestIndex]->setUp();        // Setup the initial test
00114          }
00115          else
00116          {
00117             try
00118             {
00119                mTests[mCurTestIndex]->processTest();              // Process the current test
00120             }
00121             catch(vrj::test::TestFailure& tf)
00122             {
00123                mTestFailures.push_back(tf);
00124                test_failed = true;
00125             }
00126             catch(...)
00127             {
00128                std::cout << "Recieved unknown exception in TestRunner. rethrowing." << std::endl;
00129                throw;
00130             }
00131 
00132             if(test_failed || mTests[mCurTestIndex]->isDone())    // If current test is done or failed
00133             {
00134                mTests[mCurTestIndex]->tearDown();               // Tear down the test
00135                mCurTestIndex++;                                // Goto the next test
00136                if(mCurTestIndex < (int)mTests.size())          // If test is in range
00137                {
00138                   std::cout << "TestRunner: Starting test: " << mTests[mCurTestIndex]->getName() << std::endl;
00139                   mTests[mCurTestIndex]->setUp();              // - Initialize it
00140                }
00141                else
00142                {
00143                   mCurState = DoneProcessing;
00144                   printFailures();
00145                }
00146             }
00147          }
00148          
00149       }
00150    }

void vrj::test::TestRunner::addTest ( Test test  )  [inline]

Definition at line 152 of file TestRunner.h.

References mTests.

00153    {
00154       mTests.push_back(test);
00155    }

State vrj::test::TestRunner::getState (  )  [inline]

Are the tests done processing?

Returns:
true if there is no more processing to do.

Definition at line 161 of file TestRunner.h.

References mCurState.

00162    {
00163       return mCurState;
00164    }

void vrj::test::TestRunner::printFailures (  )  [inline]

Prints out the test failures.

Definition at line 167 of file TestRunner.h.

References mTestFailures.

Referenced by processTests().

00168    {
00169       if(mTestFailures.empty())
00170       {
00171          std::cout << "--- Tests all PASSED!!! ----\n" << std::flush;
00172       }
00173       else
00174       {
00175          std::cout << "----- Test failures: count: " << mTestFailures.size() << " -----\n" << std::flush;
00176 
00177          for(unsigned f=0; f<mTestFailures.size(); ++f)
00178          {
00179             TestFailure cur_failure = mTestFailures[f];
00180             std::cout << "   Failed: " << cur_failure.getFullDescription() << std::endl;
00181          }
00182       }
00183    }


Member Data Documentation

vrj::App* vrj::test::TestRunner::mApp [protected]

The application to test.

Definition at line 186 of file TestRunner.h.

Referenced by initialize(), and processTests().

State vrj::test::TestRunner::mCurState [protected]

Store the current state of processing.

Definition at line 187 of file TestRunner.h.

Referenced by getState(), initialize(), and processTests().

int vrj::test::TestRunner::mCurTestIndex [protected]

Index of the current test to run.

-1 means that we have to start.

Definition at line 188 of file TestRunner.h.

Referenced by processTests().

std::vector<Test*> vrj::test::TestRunner::mTests [protected]

List of tests to run.

Definition at line 189 of file TestRunner.h.

Referenced by addTest(), initialize(), and processTests().

std::vector<TestFailure> vrj::test::TestRunner::mTestFailures [protected]

List of test failures.

Definition at line 190 of file TestRunner.h.

Referenced by initialize(), printFailures(), and processTests().


The documentation for this class was generated from the following file:
Generated on Thu Jan 4 10:58:34 2007 for VR Juggler by  doxygen 1.5.1