Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

C:/marty/b3/wxTest/include/wxTest/TestCaller.h

Go to the documentation of this file.
00001 
00002 // Name:        TestCaller.h
00003 // Purpose:     
00004 // Author:      Marty Saxton
00005 // Modified by:
00006 // Created:     10/27/2001
00007 // RCS-ID:      $Id: TestCaller.h,v 1.3 2001/11/09 02:18:32 marty Exp $
00008 // Copyright:   (c) Marty Saxton, Thundercow Software
00009 // Licence:     wxWindows license
00011 
00012 
00013 #ifndef CPPUNIT_TESTCALLER_H
00014 #define CPPUNIT_TESTCALLER_H
00015 
00016 #include "guards.h"
00017 #include "TestCaseMultiThreaded.h"
00018 
00019 /* 
00020  * A test caller provides access to a test case method
00021  * on a test case class.  Test callers are useful when
00022  * you want to run an individual test or add it to a
00023  * suite.
00024  *
00025  * Here is an example:
00026  *
00027  * class MathTest : public TestCase {
00028  *         ...
00029  *     public:
00030  *         void         setUp ();
00031  *         void         tearDown ();
00032  *
00033  *         void         testAdd ();
00034  *         void         testSubtract ();
00035  * };
00036  *
00037  * Test *MathTest::suite () {
00038  *     TestSuite *suite = new TestSuite;
00039  *
00040  *     suite->addTest (new wxTestCaller<MathTest> ("testAdd", testAdd));
00041  *     return suite;
00042  * }
00043  *
00044  * You can use a wxTestCaller to bind any test method on a TestCase
00045  * class, as long as it returns accepts void and returns void.
00046  *
00047  * See TestCase
00048  */
00049 
00050 template <class Fixture> class wxTestCaller : public wxTestCaseMultiThreaded
00051 {
00052         REFERENCEOBJECT (wxTestCaller);
00053         typedef void (Fixture::*TestMethod)( wxITestRunner* , long unsigned );
00054 
00055         public:
00056                 wxTestCaller (const char* name, TestMethod test, wxITest* pParent = 0 ) :
00057                         wxTestCaseMultiThreaded (name), 
00058                         m_pFixture (new Fixture (name)), 
00059                         m_state( unknown ),
00060                         m_test (test)
00061                 {
00062                 }
00063 
00064         virtual ~wxTestCaller()
00065         {
00066                 delete m_pFixture;
00067         }
00068 
00069 
00070         protected:
00071                 void runTest ()
00072                 { 
00073                         (m_pFixture.get ()->*m_test)(); 
00074                 }
00075 
00076 
00077 
00078 
00079         private:
00080 
00081 
00082 
00086         virtual void Delete() { delete this; }
00087 
00093         virtual const char* GetDescription() { return m_pFixture->GetDescription(); }
00094 
00100         virtual TestState GetState() { return m_state; }
00101 
00102         virtual void SetState( TestState newState ) { m_state = newState; }
00103 
00109         virtual bool IsThreadSafe() { return m_pFixture->IsThreadSafe(); }
00110 
00115         virtual int GetNumSubTests() { return m_pFixture->GetNumSubTests(); }
00116 
00122         virtual void GetSubTests( wxITest ** pOutTests ) { m_pFixture->GetSubTests(pOutTests); }
00123 
00129         virtual const wxITest* GetParent() const  { return m_pFixture->GetParent(); }
00130 
00136         virtual wxITest* GetParent() { return m_pFixture->GetParent(); }
00137 
00143         virtual void SetParent( wxITest* pParent ) { m_pFixture->SetParent( pParent ); }
00144 
00148         virtual void Setup() { m_pFixture->Setup(); }
00149 
00153         virtual void TearDown() { m_pFixture->TearDown(); }
00154 
00155 protected:
00156         virtual void RunUnitTest( wxITestRunner* pResult, long unsigned nThreadId ) { (m_pFixture->*m_test)( pResult, nThreadId ); };
00157 
00158 private:
00159         TestMethod m_test;
00160         Fixture* m_pFixture;
00161         TestState m_state;
00162 };
00163 #endif

ThunderCow Software (c) 2001 Marty Saxton, ThunderCow Software. Generated on Sat Nov 17 14:08:31 2001 for wxTest by Doxygen 1.2.11