Thread: [Cppunit-cvs] cppunit2/include/opentest connector.h,NONE,1.1 forwards.h,1.8,1.9 interfaces.h,1.6,1.7
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-12-11 17:16:17
|
Update of /cvsroot/cppunit/cppunit2/include/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29225/include/opentest Modified Files: forwards.h interfaces.h remoteinterfaces.h serializer.h Added Files: connector.h Log Message: * rough sketch of a working OpenTest driver with CppUT adaptor for TestRunner. Index: forwards.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/forwards.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** forwards.h 7 Nov 2005 22:43:07 -0000 1.8 --- forwards.h 11 Dec 2005 17:16:08 -0000 1.9 *************** *** 5,8 **** --- 5,9 ---- # include <cpptl/forwards.h> # include <cpptl/enumerator.h> + # include <cpptl/intrusiveptr.h> # include <cpptl/sharedptr.h> # include <json/forwards.h> *************** *** 30,33 **** --- 31,39 ---- class TestDescriptions; class TestPlan; + class TestRunnerInterface; + class TestDriverInterface; + + class Connector; + typedef unsigned int TestId; *************** *** 39,42 **** --- 45,49 ---- typedef CppTL::SharedPtr<TestPlanEntry> TestPlanEntryPtr; typedef CppTL::AnyEnumerator<TestPlanEntryPtr> TestPlanEntryPtrEnum; + typedef CppTL::IntrusivePtr<Connector> ConnectorPtr; typedef unsigned int TestId; Index: serializer.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/serializer.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** serializer.h 9 Nov 2005 22:59:09 -0000 1.10 --- serializer.h 11 Dec 2005 17:16:08 -0000 1.11 *************** *** 275,278 **** --- 275,306 ---- } + template<class SequenceType> + Stream &serializeSTLMap( Stream &stream, const SequenceType &sequence ) + { + CPPTL_TYPENAME SequenceType::const_iterator it = sequence.begin(); + CPPTL_TYPENAME SequenceType::const_iterator itEnd = sequence.end(); + unsigned int size( sequence.size() ); + stream << size; + for ( ; it != itEnd; ++it ) + stream << it->first << it->second; + return stream; + } + + template<class SequenceType, class KeyType> + Stream &unserializeSTLMap( Stream &stream, SequenceType &sequence, KeyType &key ) + { + unsigned int size; + stream >> size; + CPPTL_TYPENAME SequenceType::iterator itWhere = sequence.begin(); + CPPTL_TYPENAME SequenceType::mapped_type value; + typedef CPPTL_TYPENAME SequenceType::value_type ValueType; + while ( size-- > 0 ) + { + stream >> key >> value; + itWhere = sequence.insert( itWhere, ValueType(key,value ) ); + } + return stream; + } + } // namespace OpenTest --- NEW FILE: connector.h --- #ifndef OPENTEST_CONNECTOR_H_INCLUDED # define OPENTEST_CONNECTOR_H_INCLUDED # include <opentest/forwards.h> # include <opentest/interfaces.h> # include <cpptl/thread.h> # include <set> namespace OpenTest { enum ConnectionStatus { connectionNotEstablished = 0, connectionEstablished, connectionInProcess }; class OPENTEST_API ConnectionStatusListener { public: virtual ~ConnectionStatusListener() { } virtual void connectionStatusChanged( ConnectionStatus oldStatus, ConnectionStatus newStatus, const std::string &info ) = 0; }; class OPENTEST_API Connector : public CppTL::IntrusiveCount { public: class Status { public: Status( ConnectionStatus status, const std::string &info ) : status_( status ) , info_( info ) { } ConnectionStatus status_; std::string info_; }; Connector() : status_( connectionNotEstablished ) , version_( 0 ) , driver_( 0 ) , runner_( 0 ) { } virtual ~Connector() { if ( driver_ ) driver_->setConnector( 0 ); if ( runner_ ) runner_->setConnector( 0 ); } void addListener( ConnectionStatusListener &listener ) { CppTL::Mutex::ScopedLockGuard guard( lock_ ); listeners_.insert( &listener ); ++version_; } void removeListener( ConnectionStatusListener &listener ) { CppTL::Mutex::ScopedLockGuard guard( lock_ ); listeners_.erase( &listener ); ++version_; } Json::Value properties() const { CppTL::Mutex::ScopedLockGuard guard( lock_ ); return properties_; } //void setProperties( const Json::Value &properties ) //{ // properties_ = properties; //} Status status() const { CppTL::Mutex::ScopedLockGuard guard( lock_ ); return Status( status_, statusInfo_.str() ); } void updateStatus( ConnectionStatus status, const std::string &info = std::string() ) { ConnectionStatus oldStatus; Listeners listenersToNotify; VersionId version; { CppTL::Mutex::ScopedLockGuard guard( lock_ ); if ( status_ == status && statusInfo_ == info ) return; listenersToNotify = listeners_; oldStatus = status_; status_ = status; statusInfo_ = info; listenersToNotify = listeners_; version = version_; } Listeners notifiedListeners; while ( !listenersToNotify.empty() ) { ConnectionStatusListener &listener = **(listenersToNotify.begin()); listener.connectionStatusChanged( oldStatus, status, info ); listenersToNotify.erase( &listener ); if ( !listenersToNotify.empty() ) { notifiedListeners.insert( &listener ); CppTL::Mutex::ScopedLockGuard guard( lock_ ); if ( version != version_ ) // listener list changed { listenersToNotify = listeners_; listenersToNotify.erase( notifiedListeners.begin(), notifiedListeners.end() ); version = version_; } } } } void attachTestDriver( TestDriverInterface &driver ) { driver_ = &driver; driver_->setConnector( this ); } void attachTestRunner( TestRunnerInterface &runner ) { runner_ = &runner; runner_->setConnector( this ); } TestDriverInterface &testDriver() { return *driver_; } TestRunnerInterface &testRunner() { return *runner_; } virtual void establishConnection() = 0; virtual void disconnect() = 0; private: typedef std::set<ConnectionStatusListener *> Listeners; Listeners listeners_; mutable CppTL::Mutex lock_; Json::Value properties_; CppTL::ConstString statusInfo_; ConnectionStatus status_; TestRunnerInterface *runner_; TestDriverInterface *driver_; typedef volatile unsigned int VersionId; VersionId version_; }; class OPENTEST_API DirectConnector : public Connector { public: DirectConnector( TestRunnerInterface &runner, TestDriverInterface &driver ) { attachTestRunner( runner ); attachTestDriver( driver ); } public: // overridden from Connector virtual void establishConnection() { updateStatus( connectionEstablished, "direct connection" ); } virtual void disconnect() { updateStatus( connectionNotEstablished, "disconnected" ); } }; } // namespace OpenTest #endif // OPENTEST_CONNECTOR_H_INCLUDED Index: interfaces.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/interfaces.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** interfaces.h 14 Nov 2005 21:28:08 -0000 1.6 --- interfaces.h 11 Dec 2005 17:16:08 -0000 1.7 *************** *** 12,17 **** namespace OpenTest { ! class OPENTEST_API TestRunnerInterface { public: --- 12,43 ---- namespace OpenTest { + class OPENTEST_API Connectable + { + public: + Connectable() + : connector_( 0 ) + { + } ! virtual ~Connectable() ! { ! } ! ! void setConnector( Connector *connector ) ! { ! connector_ = connector; ! } ! ! Connector &connector() ! { ! return *connector_; ! } ! ! private: ! Connector *connector_; ! }; ! ! ! class OPENTEST_API TestRunnerInterface : public Connectable { public: *************** *** 28,32 **** ! class OPENTEST_API TestDriverInterface { public: --- 54,58 ---- ! class OPENTEST_API TestDriverInterface : public Connectable { public: *************** *** 35,52 **** virtual void setTestDescriptions( const TestDescriptions &tests ) = 0; ! virtual void setDefaultTestPlan( const TestPlan &plan ) = 0; ! virtual void startTesting( TestId testPlan ) = 0; ! virtual void addResultLog( TestId testPlan, const ResultLog &log ) = 0; ! virtual void addResultAssertion( TestId testPlan, const ResultAssertion &assertion ) = 0; ! virtual void setResultInputActualOutput( TestId testPlan, const ResultInputOutput &output ) = 0; ! virtual void setTestResult( TestId testPlan, const ResultStatus &status ) = 0; --- 61,78 ---- virtual void setTestDescriptions( const TestDescriptions &tests ) = 0; ! virtual void setDefaultTestPlans( const TestPlans &plans ) = 0; ! virtual void startTesting( TestPlanId testPlan ) = 0; ! virtual void addResultLog( TestPlanId testPlan, const ResultLog &log ) = 0; ! virtual void addResultAssertion( TestPlanId testPlan, const ResultAssertion &assertion ) = 0; ! virtual void setResultInputActualOutput( TestPlanId testPlan, const ResultInputOutput &output ) = 0; ! virtual void setTestResult( TestPlanId testPlan, const ResultStatus &status ) = 0; *************** *** 58,62 **** { public: - TestId id_; String name_; String description_; --- 84,87 ---- *************** *** 94,99 **** { public: ! std::deque<TestCaseDescription> testCases_; ! std::deque<TestSuiteDescription> testSuites_; Stream &serialize( Stream &stream ) const; --- 119,126 ---- { public: ! typedef std::map<TestId,TestCaseDescription> TestCases; ! typedef std::map<TestId,TestSuiteDescription> TestSuites; ! TestCases testCases_; ! TestSuites testSuites_; Stream &serialize( Stream &stream ) const; *************** *** 117,121 **** { public: ! std::deque<TestPlan> testPlans_; Stream &serialize( Stream &stream ) const; --- 144,149 ---- { public: ! typedef std::deque<TestPlan> Plans; ! Plans testPlans_; Stream &serialize( Stream &stream ) const; Index: remoteinterfaces.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/remoteinterfaces.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** remoteinterfaces.h 6 Sep 2005 07:31:42 -0000 1.4 --- remoteinterfaces.h 11 Dec 2005 17:16:08 -0000 1.5 *************** *** 82,102 **** void setTestDescriptions( const TestDescriptions &tests ); ! void setDefaultTestPlan( const TestPlan &plan ); ! void startTesting( TestId testPlan ); ! void addResultLog( TestId testPlan, const ResultLog &log ); ! void addResultAssertion( TestId testPlan, const ResultAssertion &assertion ); ! void setResultInputActualOutput( TestId testPlan, const ResultInputOutput &output ); ! void setTestResult( TestId testPlan, const ResultStatus &status ); ! void testPlanDone( TestId id ); }; --- 82,102 ---- void setTestDescriptions( const TestDescriptions &tests ); ! void setDefaultTestPlan( const TestPlans &plans ); ! void startTesting( TestPlanId testPlan ); ! void addResultLog( TestPlanId testPlan, const ResultLog &log ); ! void addResultAssertion( TestPlanId testPlan, const ResultAssertion &assertion ); ! void setResultInputActualOutput( TestPlanId testPlan, const ResultInputOutput &output ); ! void setTestResult( TestPlanId testPlan, const ResultStatus &status ); ! void testPlanDone( TestPlanId id ); }; |