CppUnit project page CppUnit home page

testcase.h

Go to the documentation of this file.
00001 #ifndef CPPUT_TESTCASE_H_INCLUDED
00002 # define CPPUT_TESTCASE_H_INCLUDED
00003 
00004 # include <cpput/forwards.h>
00005 # include <cpptl/functor.h>
00006 # include <cpput/resource.h>
00007 # include <cpput/test.h>
00008 # include <string>
00009 # include <set>
00010 # include <vector>
00011 
00012 
00013 namespace CppUT {
00014 
00018 class CPPUT_API AbstractTestCase : public Test
00019 {
00020 public:
00021    AbstractTestCase( const std::string &name );
00022 
00031    void requireResource( const std::string &resourceName );
00032 
00042    void prepareResourceAcquisition();
00043 
00049    bool runTest();
00050 
00063    bool runTest( const ExceptionGuard &guardsChain );
00064 
00065 public: // overridden from Test
00066    void accept( TestVisitor &visitor );
00067 
00069    bool isTestCase() const;
00070 
00071 // Those member functions are public to allow decoration of setUp/run/tearDown
00072 public:
00073    virtual void setUp();
00074 
00075    virtual void run() = 0;
00076 
00077    virtual void tearDown();
00078 
00079 private:
00085    virtual void acquireTestResources( bool &allResourceAcquired );
00086 
00089    void setUpTestResources();
00090 
00091    void tearDownTestResources();
00092 
00093 private:
00094    typedef std::set<ResourceName> ResourceNames;
00096    ResourceNames resourceNames_;
00097    typedef std::vector<ResourceLazyPtr> RequiredResources;
00098    RequiredResources requiredResources_;
00099 };
00100 
00101 
00105 class CPPUT_API TestCase : public AbstractTestCase
00106 {
00107 public:
00108    TestCase( const CppTL::Functor0 &run,
00109              const std::string &name );
00110 
00111    TestCase( const CppTL::Functor0 &setUp,
00112              const CppTL::Functor0 &run,
00113              const CppTL::Functor0 &tearDown,
00114              const std::string &name );
00115 
00116 public: // overridden from AbstractTestCase
00117    void setUp();
00118 
00119    void run();
00120 
00121    void tearDown();
00122 
00123 private:
00124    CppTL::Functor0 setUp_;
00125    CppTL::Functor0 run_;
00126    CppTL::Functor0 tearDown_;
00127 };
00128 
00129 
00130 
00134 TestPtr CPPUT_API makeTestCase( void (*run)(),
00135                                 const std::string &name );
00136 
00137 
00141 TestPtr CPPUT_API makeTestCase( const CppTL::Functor0 &run,
00142                                 const std::string &name );
00143 
00144 
00148 TestPtr CPPUT_API makeTestCase( const CppTL::Functor0 &setUp,
00149                                 const CppTL::Functor0 &run,
00150                                 const CppTL::Functor0 &tearDown,
00151                                 const std::string &name );
00152 
00162 TestPtr CPPUT_API makeFailingTestCase( const std::string &name,
00163                                        const Message &message );
00164 
00171 template<typename FixtureType>
00172 TestPtr makeFixtureTestCase( const CppTL::IntrusivePtr<FixtureType> &fixture,
00173                              const CppTL::Functor0 &run,
00174                              const std::string &name )
00175 {
00177    return makeTestCase( CppTL::memfn0( fixture, &FixtureType::setUp ),
00178                         run,
00179                         CppTL::memfn0( fixture, &FixtureType::tearDown ),
00180                         name );
00181 }
00182 
00183 
00184 } // namespace CppUT
00185 
00186 #endif // CPPUT_TESTCASE_H_INCLUDED

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers