Devirtualize nested tracker handling

This commit is contained in:
Martin Hořeňovský 2020-07-27 19:53:54 +02:00
parent 125d4b4164
commit ef92178058
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 36 additions and 28 deletions

View File

@ -31,6 +31,23 @@ namespace TestCaseTracking {
ITracker::~ITracker() = default;
void ITracker::addChild( ITrackerPtr const& child ) {
m_children.push_back( child );
}
ITrackerPtr ITracker::findChild( NameAndLocation const& nameAndLocation ) {
auto it = std::find_if(
m_children.begin(),
m_children.end(),
[&nameAndLocation]( ITrackerPtr const& tracker ) {
return tracker->nameAndLocation().location ==
nameAndLocation.location &&
tracker->nameAndLocation().name == nameAndLocation.name;
} );
return ( it != m_children.end() ) ? *it : nullptr;
}
ITracker& TrackerContext::startRun() {
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
@ -79,26 +96,7 @@ namespace TestCaseTracking {
bool TrackerBase::isOpen() const {
return m_runState != NotStarted && !isComplete();
}
bool TrackerBase::hasChildren() const {
return !m_children.empty();
}
void TrackerBase::addChild( ITrackerPtr const& child ) {
m_children.push_back( child );
}
ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) {
auto it = std::find_if( m_children.begin(), m_children.end(),
[&nameAndLocation]( ITrackerPtr const& tracker ){
return
tracker->nameAndLocation().location == nameAndLocation.location &&
tracker->nameAndLocation().name == nameAndLocation.name;
} );
return( it != m_children.end() )
? *it
: nullptr;
}
ITracker& TrackerBase::parent() {
assert( m_parent ); // Should always be non-null except for root
return *m_parent;

View File

@ -36,6 +36,11 @@ namespace TestCaseTracking {
class ITracker {
NameAndLocation m_nameAndLocation;
using Children = std::vector<ITrackerPtr>;
protected:
Children m_children;
public:
ITracker(NameAndLocation const& nameAndLoc) :
m_nameAndLocation(nameAndLoc)
@ -54,7 +59,6 @@ namespace TestCaseTracking {
virtual bool isComplete() const = 0; // Successfully completed or failed
virtual bool isSuccessfullyCompleted() const = 0;
virtual bool isOpen() const = 0; // Started but not complete
virtual bool hasChildren() const = 0;
virtual bool hasStarted() const = 0;
virtual ITracker& parent() = 0;
@ -64,8 +68,20 @@ namespace TestCaseTracking {
virtual void fail() = 0;
virtual void markAsNeedingAnotherRun() = 0;
virtual void addChild( ITrackerPtr const& child ) = 0;
virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0;
//! Register a nested ITracker
void addChild( ITrackerPtr const& child );
/**
* Returns ptr to specific child if register with this tracker.
*
* Returns nullptr if not found.
*/
ITrackerPtr findChild( NameAndLocation const& nameAndLocation );
//! Have any children been added?
bool hasChildren() const {
return !m_children.empty();
}
virtual void openChild() = 0;
// Debug/ checking
@ -109,10 +125,8 @@ namespace TestCaseTracking {
Failed
};
using Children = std::vector<ITrackerPtr>;
TrackerContext& m_ctx;
ITracker* m_parent;
Children m_children;
CycleState m_runState = NotStarted;
public:
@ -121,14 +135,10 @@ namespace TestCaseTracking {
bool isComplete() const override;
bool isSuccessfullyCompleted() const override;
bool isOpen() const override;
bool hasChildren() const override;
bool hasStarted() const override {
return m_runState != NotStarted;
}
void addChild( ITrackerPtr const& child ) override;
ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override;
ITracker& parent() override;
void openChild() override;