Thread: [Cppunit-cvs] cppunit2/include/opentest texttestdriver.h,1.10,1.11
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-12-11 17:49:28
|
Update of /cvsroot/cppunit/cppunit2/include/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2315/include/opentest Modified Files: texttestdriver.h Log Message: * reorganized code a bit Index: texttestdriver.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/texttestdriver.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** texttestdriver.h 28 Feb 2005 22:11:55 -0000 1.10 --- texttestdriver.h 11 Dec 2005 17:49:18 -0000 1.11 *************** *** 2,263 **** # define OPENTEST_TEXTTESTDRIVER_H_INCLUDED ! # include <opentest/properties.h> ! # include <opentest/testplan.h> ! # include <opentest/testrunner.h> ! # include <cpptl/enumerator.h> ! # include <deque> ! # include <map> ! # include <set> ! ! namespace OpenTest { ! ! class OPENTEST_API TestDriverTestPlan : public TestPlan ! { ! public: // overriden from TestPlan ! TestPlanEntryPtrEnum entries() const; ! ! public: ! void add( const TestPlanEntryPtr &entry ); ! ! private: ! std::deque<TestPlanEntryPtr> entries_; ! }; ! ! ! class OPENTEST_API TestResult ! { ! public: ! TestResult( TestPlanEntryId id, TestId test ); ! ! TestPlanEntryId id() const; ! ! TestId test() const; ! ! const Properties &result() const; ! ! Properties &result(); ! ! private: ! TestPlanEntryId id_; ! TestId test_; ! Properties result_; ! }; ! ! ! class OPENTEST_API TestDriverTestPlanEntry : public TestPlanEntry ! { ! public: ! TestDriverTestPlanEntry( TestPlanEntryId id, ! TestId test, ! const Properties &configuration ); ! ! public: // overriden from TestPlanEntry ! TestPlanEntryId id() const; ! ! /// Test to run ! TestId test() const; ! ! /// Used to pass configuration data to the test runner or the test itself ! const Properties &configuration() const; ! ! private: ! TestPlanEntryId id_; ! TestId test_; ! Properties configuration_; ! }; ! ! 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: ! TextTestDriver( TestRunner &runner ); ! ! // void selectTest( const CppTL::ConstString &name ); ! ! 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 ); ! ! TestId addTest( const CppTL::ConstString &name, ! const Properties &data ); ! ! void endSuite(); ! private: // overriden from TestRunTracker ! void startTestRun(); ! void startTest( const TestPlanEntry &testEntry ); ! void mergeInTestResult( const TestPlanEntry &testEntry, ! const Properties &result ); ! void mergeInTestResult( const TestPlanEntry &testEntry, ! const PropertyPath &path, ! const Value &value ); ! void appendToTestResult( const TestPlanEntry &testEntry, ! const PropertyPath &path, ! const Value &value ); ! void endTest( const TestPlanEntry &testEntry ); ! void endTestRun(); ! bool shouldStopTestRun(); ! void aqcuireResources( const ResourceList &resources ) {} ! 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; ! private: ! struct InternalTestInfo ! { ! InternalTestInfo( TestId id, ! const CppTL::ConstString &name, ! const Properties &info, ! const ParentSuites &parents ) ! : id_( id ) ! , name_( name ) ! , info_( info ) ! , parents_( parents ) { } ! TestId id_; ! CppTL::ConstString name_; ! 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(); - - void outputFailures(); - - const InternalTestInfo &getTestInfo( TestId id ) const; - InternalTestInfo &getTestInfo( TestId id ); - - void declareTestOrSuite( TestId id, - const CppTL::ConstString &name, - const Properties &data ); - - CppTL::ConstString getTestPath( TestId test, unsigned int maxParent = (unsigned int)-1 ) const; - - void reportFailure( const TestResult &testResult, - const Properties &failure, - bool isAssertion ); - - 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_; - /// Stack of parent suite for 'current' declared test. - ParentSuites declaratorParentSuites_; - /// List of test to run. - Tests testsToRun_; - Results results_; - TestResultIndexes failures_; - TestResultIndexes successes_; - TestId nextTestId_; }; - } // namespace OpenTest - - #endif // OPENTEST_TEXTTESTDRIVER_H_INCLUDED --- 2,127 ---- # define OPENTEST_TEXTTESTDRIVER_H_INCLUDED ! # include <opentest/connector.h> ! # include <opentest/interfaces.h> ! # include <stdio.h> ! namespace OpenTest { ! class TextTestDriver : private TestDriverInterface { ! public: ! TextTestDriver( int argc, const char *argv[] ) ! { ! } ! virtual ~TextTestDriver() ! { ! } ! void addTestRunner( TestRunnerInterface &testRunner ) ! { ! addConnector( new DirectConnector( testRunner, *this ) ); ! } ! void addConnector( const ConnectorPtr &connector ) ! { ! connectors_.push_back( connector ); ! } ! void runTests() ! { ! for ( Connectors::iterator it = connectors_.begin(); ! it != connectors_.end(); ! ++it ) ! { ! Connector &connector = **it; ! if ( connector.status().status_ != connectionEstablished ) ! connector.establishConnection(); ! } ! for ( Connectors::iterator it = connectors_.begin(); ! it != connectors_.end(); ! ++it ) ! { ! Connector &connector = **it; ! if ( connector.status().status_ == connectionEstablished ) ! { ! connector.testRunner().getTestDescriptions(); ! connector.testRunner().getTestPlans(); ! connector.testRunner().runTests(plans_); ! } ! } ! } ! private: // overridden from TestDriverInterface ! virtual void setTestDescriptions( const TestDescriptions &tests ) ! { ! descriptions_ = tests; ! } ! virtual void setDefaultTestPlans( const TestPlans &plans ) ! { ! plans_ = plans; ! } ! virtual void startTesting( TestPlanId testPlan ) ! { ! printf( "Start testing: %s\n", getTestCaseDesc( testPlan ).name_.c_str() ); ! } ! virtual void addResultLog( TestPlanId testPlan, ! const ResultLog &log ) ! { ! printf( "Log for %s:\n", ! getTestCaseDesc( testPlan ).name_.c_str() ); ! } ! virtual void addResultAssertion( TestPlanId testPlan, ! const ResultAssertion &assertion ) ! { ! printf( "- Assertion for %s:\n" ! "Type:%s\n" ! "Message:\n%s\n", ! getTestCaseDesc( testPlan ).name_.c_str(), ! assertion.assertionType_.c_str(), ! assertion.message_.c_str() ); ! } ! virtual void setResultInputActualOutput( TestPlanId testPlan, ! const ResultInputOutput &output ) ! { ! } ! virtual void setTestResult( TestPlanId testPlan, ! const ResultStatus &status ) ! { ! printf( "Result for %s:\n%s\n", ! getTestCaseDesc( testPlan ).name_.c_str(), ! status.status_.c_str() ); ! } ! virtual void testPlanDone( TestPlanId id ) ! { ! } ! private: ! OpenTest::TestCaseDescription &getTestCaseDesc( TestPlanId testPlan ) { + TestId testId = plans_.testPlans_.at( testPlan ).testCase_; + TestDescriptions::TestCases::iterator it = descriptions_.testCases_.find( testId ); + if ( it == descriptions_.testCases_.end() ) + throw std::runtime_error( "Invalid test plan" ); + return it->second; } ! typedef std::deque<ConnectorPtr> Connectors; ! Connectors connectors_; ! OpenTest::TestPlans plans_; ! OpenTest::TestDescriptions descriptions_; }; }; #endif // OPENTEST_TEXTTESTDRIVER_H_INCLUDED + |