[Cppunit-cvs] cppunit2/include/opentest texttestdriver.h,1.8,1.9
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-02-28 20:54:55
|
Update of /cvsroot/cppunit/cppunit2/include/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6393/opentest Modified Files: texttestdriver.h Log Message: * added TestInfoExplorer interface to inspect declared tests. Index: texttestdriver.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/texttestdriver.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** texttestdriver.h 27 Feb 2005 10:15:57 -0000 1.8 --- texttestdriver.h 28 Feb 2005 20:54:45 -0000 1.9 *************** *** 5,8 **** --- 5,9 ---- # include <opentest/testplan.h> # include <opentest/testrunner.h> + # include <cpptl/enumerator.h> # include <deque> # include <map> *************** *** 68,75 **** --- 69,142 ---- }; + class TestInfo; + class TestCaseInfo; + class TestSuiteInfo; + + typedef CppTL::AnyEnumerator<TestInfo> TestInfoEnumerator; + + class TestInfoHolder + { + public: + virtual ~TestInfoHolder() + { + } + + virtual const String &getTestName( TestId id ) const = 0; + virtual PropertiesAccessor getTestDescription( TestId id ) const = 0; + virtual PropertiesAccessor getTestInput( TestId id ) const = 0; + virtual bool isTestSuite( TestId id ) const = 0; + virtual TestInfoEnumerator getTestChildren( TestId id ) const = 0; + virtual TestInfoEnumerator getTestParents( TestId id ) const = 0; + }; + + + class OPENTEST_API TestInfo + { + public: + TestInfo( const TestInfoHolder &holder, + TestId id ); + + virtual ~TestInfo() + { + } + + const String &getName() const; + PropertiesAccessor getDescription() const; + bool isTestSuite() const; + bool isTestCase() const; + TestInfoEnumerator getParents() const; + + // test case specifics + PropertiesAccessor getInput() const; + + // test suite specifics + TestInfoEnumerator getChildren() const; + TestInfoEnumerator getChildTestSuites() const; + TestInfoEnumerator getChildTestCases() const; + + protected: + const TestInfoHolder &holder_; + TestId id_; + }; + + + class OPENTEST_API TestInfoExplorer + { + public: + virtual ~TestInfoExplorer() + { + } + + virtual TestInfoEnumerator getAllTestCases() const = 0; + virtual TestInfoEnumerator getAllTestSuites() const = 0; + virtual TestInfo getRootTestSuite() const = 0; + }; + class OPENTEST_API TextTestDriver : private TestRunTracker , private TestDeclarator + , private TestInfoHolder + , public TestInfoExplorer { public: *************** *** 80,84 **** bool run(); ! private: // overriden from TestDeclarator TestId beginSuite( const CppTL::ConstString &name, const Properties &data ); --- 147,156 ---- bool run(); ! public: // overridden from TestInfoExplorer ! TestInfoEnumerator getAllTestCases() const; ! TestInfoEnumerator getAllTestSuites() const; ! TestInfo getRootTestSuite() const; ! ! private: // overridden from TestDeclarator TestId beginSuite( const CppTL::ConstString &name, const Properties &data ); *************** *** 115,118 **** --- 187,198 ---- void releaseResources( const ResourceList &resources ) {} + private: // overridden from TestInfoHolder + const String &getTestName( TestId id ) const; + PropertiesAccessor getTestDescription( TestId id ) const; + PropertiesAccessor getTestInput( TestId id ) const; + bool isTestSuite( TestId id ) const; + TestInfoEnumerator getTestChildren( TestId id ) const; + TestInfoEnumerator getTestParents( TestId id ) const; + public: typedef std::deque<TestId> ParentSuites; *************** *** 120,126 **** private: ! struct TestInfo { ! TestInfo( TestId id, const CppTL::ConstString &name, const Properties &info, --- 200,206 ---- private: ! struct InternalTestInfo { ! InternalTestInfo( TestId id, const CppTL::ConstString &name, const Properties &info, *************** *** 137,147 **** Properties info_; ParentSuites parents_; }; typedef std::set<TestId> Tests; - typedef std::map<TestId,TestId> Hierarchy; // suite <-> tests typedef std::deque<TestResult> Results; typedef std::vector<unsigned int> TestResultIndexes; ! typedef std::map<TestId,TestInfo> TestInfos; TestId nextTestId(); --- 217,227 ---- Properties info_; ParentSuites parents_; + ParentSuites children_; }; typedef std::set<TestId> Tests; typedef std::deque<TestResult> Results; typedef std::vector<unsigned int> TestResultIndexes; ! typedef std::map<TestId,InternalTestInfo> TestInfos; TestId nextTestId(); *************** *** 149,153 **** void outputFailures(); ! const TestInfo &getTestInfo( TestId id ) const; void declareTestOrSuite( TestId id, --- 229,234 ---- void outputFailures(); ! const InternalTestInfo &getTestInfo( TestId id ) const; ! InternalTestInfo &getTestInfo( TestId id ); void declareTestOrSuite( TestId id, *************** *** 168,173 **** /// TestId of all suites. Tests suites_; - /// Parent/Child association to describe the hierarchy - Hierarchy hierarchy_; /// Stack of parent suite for 'current' declared test. ParentSuites declaratorParentSuites_; --- 249,252 ---- *************** *** 352,359 **** const Properties &data ) { ! TestInfo info( id, name, data, declaratorParentSuites_ ); testInfos_.insert( TestInfos::value_type( id, info ) ); if ( declaratorParentSuites_.size() > 0 ) ! hierarchy_.insert( Hierarchy::value_type( declaratorParentSuites_.back(), id ) ); } --- 431,441 ---- const Properties &data ) { ! InternalTestInfo info( id, name, data, declaratorParentSuites_ ); testInfos_.insert( TestInfos::value_type( id, info ) ); if ( declaratorParentSuites_.size() > 0 ) ! { ! TestId parentId = declaratorParentSuites_.back(); ! getTestInfo(parentId).children_.push_back( id ); ! } } *************** *** 452,456 **** ! inline const TextTestDriver::TestInfo & TextTestDriver::getTestInfo( TestId test ) const { --- 534,538 ---- ! inline const TextTestDriver::InternalTestInfo & TextTestDriver::getTestInfo( TestId test ) const { *************** *** 462,465 **** --- 544,557 ---- + inline TextTestDriver::InternalTestInfo & + TextTestDriver::getTestInfo( TestId test ) + { + TestInfos::iterator it = testInfos_.find( test ); + if ( it == testInfos_.end() ) + throw std::invalid_argument( "TextTestDriver::getTestInfo() : bad TestId." ); + return it->second; + } + + inline void TextTestDriver::outputFailures() *************** *** 569,573 **** { CppTL::ConstString path; ! const TestInfo &info = getTestInfo( test ); path = "/" + info.name_; if ( info.parents_.empty() ) --- 661,665 ---- { CppTL::ConstString path; ! const InternalTestInfo &info = getTestInfo( test ); path = "/" + info.name_; if ( info.parents_.empty() ) *************** *** 580,584 **** --index ) { ! const TestInfo &parentInfo = getTestInfo( info.parents_[index] ); path = "/" + parentInfo.name_ + path; } --- 672,676 ---- --index ) { ! const InternalTestInfo &parentInfo = getTestInfo( info.parents_[index] ); path = "/" + parentInfo.name_ + path; } *************** *** 589,592 **** --- 681,876 ---- } + // Implementation of TestInfoExplorer + // ////////////////////////////////////////////////////////////////// + + namespace Impl { + + struct IsTestSuiteOrTestCaseFilter + { + IsTestSuiteOrTestCaseFilter( bool keepSuite ) + : keepSuite_( keepSuite ) + { + } + + bool operator()( const TestInfo &info ) const + { + return info.isTestSuite() == keepSuite_; + } + + bool keepSuite_; + }; + + struct TestId2TestInfoAdapator + { + typedef TestInfo result_type; + TestId2TestInfoAdapator( const TestInfoHolder &holder ) + : holder_( holder ) + { + } + + TestInfo operator()( TestId id ) const + { + return TestInfo( holder_, id ); + } + + const TestInfoHolder &holder_; + }; + + } // namespace Impl + + + inline TestInfoEnumerator + TextTestDriver::getAllTestCases() const + { + return CppTL::Enum::anyTransform( CppTL::Enum::container( tests_, CppTL::Type<TestId>() ), + Impl::TestId2TestInfoAdapator( *this ) ); + } + + + inline TestInfoEnumerator + TextTestDriver::getAllTestSuites() const + { + return CppTL::Enum::anyTransform( CppTL::Enum::container( suites_, CppTL::Type<TestId>() ), + Impl::TestId2TestInfoAdapator( *this ) ); + } + + + inline TestInfo + TextTestDriver::getRootTestSuite() const + { + TestId id; + if ( !tests_.empty() ) + id = *(tests_.begin()); + else if ( !suites_.empty() ) + id = *(suites_.begin()); + else + throw std::logic_error( "TextTestDriver::getRootTestSuite(): no suite defined." ); + + while ( !getTestInfo(id).parents_.empty() ) + id = *(getTestInfo(id).parents_.begin()); + return TestInfo( *this, id ); + } + + + + // Implementation of TestInfoHolder + // ////////////////////////////////////////////////////////////////// + + inline const String & + TextTestDriver::getTestName( TestId id ) const + { + return getTestInfo(id).name_; + } + + + inline PropertiesAccessor + TextTestDriver::getTestDescription( TestId id ) const + { + return getTestInfo(id).info_.accessor()["description"]; + } + + + inline PropertiesAccessor + TextTestDriver::getTestInput( TestId id ) const + { + return getTestInfo(id).info_.accessor()["input"]; + } + + + inline bool + TextTestDriver::isTestSuite( TestId id ) const + { + return suites_.count(id) > 0; + } + + + inline TestInfoEnumerator + TextTestDriver::getTestChildren( TestId id ) const + { + return CppTL::Enum::anyTransform( CppTL::Enum::container( getTestInfo(id).children_ ), + Impl::TestId2TestInfoAdapator( *this ) ); + } + + + inline TestInfoEnumerator + TextTestDriver::getTestParents( TestId id ) const + { + return CppTL::Enum::anyTransform( CppTL::Enum::container( getTestInfo(id).parents_ ), + Impl::TestId2TestInfoAdapator( *this ) ); + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class TestInfo + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + inline + TestInfo::TestInfo( const TestInfoHolder &holder, + TestId id ) + : id_( id ) + , holder_( holder ) + { + } + + inline const String & + TestInfo::getName() const + { + return holder_.getTestName( id_ ); + } + + inline PropertiesAccessor + TestInfo::getDescription() const + { + return holder_.getTestDescription( id_ ); + } + + inline bool + TestInfo::isTestSuite() const + { + return holder_.isTestSuite( id_ ); + } + + inline bool + TestInfo::isTestCase() const + { + return !isTestSuite(); + } + + + inline TestInfoEnumerator + TestInfo::getParents() const + { + return holder_.getTestParents( id_ ); + } + + + inline PropertiesAccessor + TestInfo::getInput() const + { + return holder_.getTestInput( id_ ); + } + + inline TestInfoEnumerator + TestInfo::getChildren() const + { + return holder_.getTestChildren( id_ ); + } + + inline TestInfoEnumerator + TestInfo::getChildTestSuites() const + { + return CppTL::Enum::anyFilter( getChildren(), + Impl::IsTestSuiteOrTestCaseFilter(true) ); + } + + inline TestInfoEnumerator + TestInfo::getChildTestCases() const + { + return CppTL::Enum::anyFilter( getChildren(), + Impl::IsTestSuiteOrTestCaseFilter(false) ); + } + } // namespace OpenTest |