[Cppunit-cvs] cppunit2/include/opentest testrunner.h,1.1,1.2 texttestdriver.h,1.1,1.2
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2004-11-16 22:46:54
|
Update of /cvsroot/cppunit/cppunit2/include/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24939/include/opentest Modified Files: testrunner.h texttestdriver.h Log Message: * removed the addSuite() method during test declaration (make implementation of test driver more complex). Index: testrunner.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/testrunner.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testrunner.h 15 Nov 2004 08:33:30 -0000 1.1 --- testrunner.h 16 Nov 2004 22:46:44 -0000 1.2 *************** *** 40,45 **** const Properties &data ) = 0; - virtual void addSuite( TestId suite ) = 0; - virtual void endSuite() = 0; }; --- 40,43 ---- Index: texttestdriver.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/texttestdriver.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** texttestdriver.h 15 Nov 2004 08:34:13 -0000 1.1 --- texttestdriver.h 16 Nov 2004 22:46:44 -0000 1.2 *************** *** 89,94 **** const Properties &data ); - void addSuite( TestId suite ); - void endSuite(); --- 89,92 ---- *************** *** 112,121 **** private: struct TestInfo { ! TestInfo( TestId id, const std::string &name, const Properties &info ) : id_( id ) , name_( name ) , info_( info ) { } --- 110,125 ---- private: + typedef std::deque<TestId> ParentSuites; + struct TestInfo { ! TestInfo( TestId id, ! const std::string &name, ! const Properties &info, ! const ParentSuites &parents ) : id_( id ) , name_( name ) , info_( info ) + , parents_( parents ) { } *************** *** 124,132 **** std::string name_; Properties info_; }; typedef std::set<TestId> Tests; typedef std::map<TestId,TestId> Hierarchy; // suite <-> tests - typedef std::stack<TestId> DeclarationSuites; typedef std::deque<TestResult> Results; typedef std::vector<unsigned int> TestResultIndexes; --- 128,136 ---- std::string name_; 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; *************** *** 139,148 **** const TestInfo &getTestInfo( TestId id ) const; TestRunner &runner_; TestInfos testInfos_; Tests tests_; Tests suites_; Hierarchy hierarchy_; ! DeclarationSuites declarationSuites_; Tests testsToRun_; Results results_; --- 143,164 ---- const TestInfo &getTestInfo( TestId id ) const; + void declareTestOrSuite( TestId id, + const std::string &name, + const Properties &data ); + + std::string getTestPath( TestId test, unsigned int maxParent = -1 ) const; + TestRunner &runner_; + /// Information associated to each test/suite at declaration time TestInfos testInfos_; + /// TestId of all test cases. Tests tests_; + /// 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_; ! /// List of test to run. Tests testsToRun_; Results results_; *************** *** 301,308 **** { TestId id = nextTestId(); ! declarationSuites_.push( id ); suites_.insert( id ); - TestInfo info( id, name, data ); - testInfos_.insert( TestInfos::value_type( id, info ) ); return id; } --- 317,323 ---- { TestId id = nextTestId(); ! declareTestOrSuite( id, name, data ); ! declaratorParentSuites_.push_back( id ); suites_.insert( id ); return id; } *************** *** 314,321 **** { TestId id = nextTestId(); ! hierarchy_.insert( Hierarchy::value_type( declarationSuites_.top(), id ) ); tests_.insert( id ); - TestInfo info( id, name, data ); - testInfos_.insert( TestInfos::value_type( id, info ) ); return id; } --- 329,334 ---- { TestId id = nextTestId(); ! declareTestOrSuite( id, name, data ); tests_.insert( id ); return id; } *************** *** 323,336 **** inline void ! TextTestDriver::addSuite( TestId suite ) { ! hierarchy_.insert( Hierarchy::value_type( declarationSuites_.top(), suite ) ); } ! inline void ! TextTestDriver::endSuite() { ! declarationSuites_.pop(); } --- 336,354 ---- inline void ! TextTestDriver::endSuite() { ! declaratorParentSuites_.pop_back(); } ! void ! TextTestDriver::declareTestOrSuite( TestId id, ! const std::string &name, ! 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 ) ); } *************** *** 361,365 **** results_.push_back( result ); ! std::cout << "Testing '" << getTestInfo( testEntry.test() ).name_ << "' : "; std::cout.flush(); } --- 379,385 ---- results_.push_back( result ); ! const unsigned int maxParent = 1; ! std::cout << "Testing '" << getTestPath( testEntry.test(), ! maxParent ) << "' : "; std::cout.flush(); } *************** *** 445,449 **** } ! std::cout << getTestInfo( testResult.test() ).name_ << std::endl; std::string failureType = info["result"]["status"].getValue("type","").asString(); --- 465,469 ---- } ! std::cout << getTestPath( testResult.test() ) << std::endl; std::string failureType = info["result"]["status"].getValue("type","").asString(); *************** *** 460,463 **** --- 480,508 ---- } + + inline std::string + TextTestDriver::getTestPath( TestId test, unsigned int maxParent ) const + { + std::string path; + const TestInfo &info = getTestInfo( test ); + path = "/" + info.name_; + if ( info.parents_.empty() ) + return path; + + bool isPartialPath = maxParent < info.parents_.size(); + + for ( unsigned int index = info.parents_.size()-1; + index != -1 && maxParent-- >0; + --index ) + { + const TestInfo &parentInfo = getTestInfo( info.parents_[index] ); + path = "/" + parentInfo.name_ + path; + } + + if ( isPartialPath ) + path = ".." + path; + return path; + } + } // namespace OpenTest |