mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 04:07:10 +01:00 
			
		
		
		
	Removed use of dynamic_cast from test_case_tracker.
(Thanks to #631 and #648)
This commit is contained in:
		| @@ -41,6 +41,10 @@ namespace TestCaseTracking { | |||||||
|         virtual void addChild( Ptr<ITracker> const& child ) = 0; |         virtual void addChild( Ptr<ITracker> const& child ) = 0; | ||||||
|         virtual ITracker* findChild( std::string const& name ) = 0; |         virtual ITracker* findChild( std::string const& name ) = 0; | ||||||
|         virtual void openChild() = 0; |         virtual void openChild() = 0; | ||||||
|  |          | ||||||
|  |         // Debug/ checking | ||||||
|  |         virtual bool isSectionTracker() const = 0; | ||||||
|  |         virtual bool isIndexTracker() const = 0; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     class TrackerContext { |     class TrackerContext { | ||||||
| @@ -167,6 +171,10 @@ namespace TestCaseTracking { | |||||||
|                     m_parent->openChild(); |                     m_parent->openChild(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; } | ||||||
|  |         virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; } | ||||||
|  |          | ||||||
|         void open() { |         void open() { | ||||||
|             m_runState = Executing; |             m_runState = Executing; | ||||||
|             moveToThis(); |             moveToThis(); | ||||||
| @@ -230,13 +238,16 @@ namespace TestCaseTracking { | |||||||
|         {} |         {} | ||||||
|         virtual ~SectionTracker(); |         virtual ~SectionTracker(); | ||||||
|  |  | ||||||
|  |         virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; } | ||||||
|  |          | ||||||
|         static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) { |         static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) { | ||||||
|             SectionTracker* section = CATCH_NULL; |             SectionTracker* section = CATCH_NULL; | ||||||
|  |  | ||||||
|             ITracker& currentTracker = ctx.currentTracker(); |             ITracker& currentTracker = ctx.currentTracker(); | ||||||
|             if( ITracker* childTracker = currentTracker.findChild( name ) ) { |             if( ITracker* childTracker = currentTracker.findChild( name ) ) { | ||||||
|                 section = dynamic_cast<SectionTracker*>( childTracker ); |                 assert( childTracker ); | ||||||
|                 assert( section ); |                 assert( childTracker->isSectionTracker() ); | ||||||
|  |                 section = static_cast<SectionTracker*>( childTracker ); | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 section = new SectionTracker( name, ctx, ¤tTracker ); |                 section = new SectionTracker( name, ctx, ¤tTracker ); | ||||||
| @@ -261,13 +272,16 @@ namespace TestCaseTracking { | |||||||
|         {} |         {} | ||||||
|         virtual ~IndexTracker(); |         virtual ~IndexTracker(); | ||||||
|  |  | ||||||
|  |         virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; } | ||||||
|  |          | ||||||
|         static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) { |         static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) { | ||||||
|             IndexTracker* tracker = CATCH_NULL; |             IndexTracker* tracker = CATCH_NULL; | ||||||
|  |  | ||||||
|             ITracker& currentTracker = ctx.currentTracker(); |             ITracker& currentTracker = ctx.currentTracker(); | ||||||
|             if( ITracker* childTracker = currentTracker.findChild( name ) ) { |             if( ITracker* childTracker = currentTracker.findChild( name ) ) { | ||||||
|                 tracker = dynamic_cast<IndexTracker*>( childTracker ); |                 assert( childTracker ); | ||||||
|                 assert( tracker ); |                 assert( childTracker->isIndexTracker() ); | ||||||
|  |                 tracker = static_cast<IndexTracker*>( childTracker ); | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 tracker = new IndexTracker( name, ctx, ¤tTracker, size ); |                 tracker = new IndexTracker( name, ctx, ¤tTracker, size ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash