Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

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 <TestRunner.h>

Collaboration diagram for vrj::test::TestRunner:

Collaboration graph
[legend]
List of all members.

Public Types

enum  State { Uninitialized, Processing, DoneProcessing }

Public Methods

 TestRunner ()
void initialize (vrj::App *app)
 Initialize the test suite. More...

void processTests ()
 Progresses the state of testing Called at the end of preFrame by apps that want to run tests. More...

void addTest (Test *test)
State getState ()
 Are the tests done processing. More...

void printFailures ()
 Print out the test failures. More...


Protected Attributes

vrj::AppmApp
 The application to test. More...

State mCurState
 Store the current state of processing. More...

int mCurTestIndex
 Index of the current test to run. More...

std::vector< Test * > mTests
 List of tests to run. More...

std::vector< TestFailuremTestFailures
 List of test failures. More...


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
 

Enumeration values:
Uninitialized 
Processing 
DoneProcessing 

Definition at line 61 of file TestRunner.h.

Referenced by getState.

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


Constructor & Destructor Documentation

vrj::test::TestRunner::TestRunner   [inline]
 

Definition at line 68 of file TestRunner.h.

References mApp, mCurState, mCurTestIndex, and Uninitialized.

00069       : mApp(NULL), mCurState(Uninitialized), mCurTestIndex(-1)
00070    {;}


Member Function Documentation

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

Initialize the test suite.

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

Definition at line 76 of file TestRunner.h.

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

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

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 96 of file TestRunner.h.

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

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

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

Definition at line 147 of file TestRunner.h.

References mTests.

00148    {
00149       mTests.push_back(test);
00150    }

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

Are the tests done processing.

Returns:
true - There is no more processing to do

Definition at line 155 of file TestRunner.h.

References mCurState, and State.

00156    { return mCurState; }

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

Print out the test failures.

Definition at line 161 of file TestRunner.h.

References mTestFailures.

Referenced by processTests.

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


Member Data Documentation

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

The application to test.

Definition at line 180 of file TestRunner.h.

Referenced by initialize, processTests, and TestRunner.

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

Store the current state of processing.

Definition at line 181 of file TestRunner.h.

Referenced by getState, initialize, processTests, and TestRunner.

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

Index of the current test to run.

-1 means that we have to start.

Definition at line 182 of file TestRunner.h.

Referenced by processTests, and TestRunner.

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

List of tests to run.

Definition at line 183 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 184 of file TestRunner.h.

Referenced by initialize, printFailures, and processTests.


The documentation for this class was generated from the following file:
Generated on Sun May 2 15:11:17 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002