2012-05-05 20:32:52 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil Nash on 4/5/2012
|
|
|
|
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
2012-09-17 07:42:29 +02:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED
|
2012-05-05 20:32:52 +02:00
|
|
|
|
|
|
|
#include "catch_common.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
class SectionInfo {
|
2012-05-05 20:32:52 +02:00
|
|
|
public:
|
2012-05-16 00:58:23 +02:00
|
|
|
|
|
|
|
enum Status {
|
2012-05-05 20:32:52 +02:00
|
|
|
Root,
|
|
|
|
Unknown,
|
|
|
|
Branch,
|
|
|
|
TestedBranch,
|
|
|
|
TestedLeaf
|
|
|
|
};
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
SectionInfo( SectionInfo* parent )
|
2012-05-05 20:32:52 +02:00
|
|
|
: m_status( Unknown ),
|
|
|
|
m_parent( parent )
|
2012-05-16 00:58:23 +02:00
|
|
|
{}
|
2012-05-05 20:32:52 +02:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
SectionInfo()
|
2012-05-05 20:32:52 +02:00
|
|
|
: m_status( Root ),
|
|
|
|
m_parent( NULL )
|
2012-05-16 00:58:23 +02:00
|
|
|
{}
|
2012-05-05 20:32:52 +02:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
~SectionInfo() {
|
2012-05-05 20:32:52 +02:00
|
|
|
deleteAllValues( m_subSections );
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool shouldRun() const {
|
2012-05-05 20:32:52 +02:00
|
|
|
return m_status < TestedBranch;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool ran() {
|
|
|
|
if( m_status < Branch ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_status = TestedLeaf;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-16 00:58:23 +02:00
|
|
|
|
2012-08-31 09:10:36 +02:00
|
|
|
bool isBranch() const {
|
|
|
|
return m_status == Branch;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
void ranToCompletion() {
|
2012-05-05 20:32:52 +02:00
|
|
|
if( m_status == Branch && !hasUntestedSections() )
|
|
|
|
m_status = TestedBranch;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
SectionInfo* findSubSection( const std::string& name ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
|
|
|
|
return it != m_subSections.end()
|
|
|
|
? it->second
|
|
|
|
: NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
SectionInfo* addSubSection( const std::string& name ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
SectionInfo* subSection = new SectionInfo( this );
|
|
|
|
m_subSections.insert( std::make_pair( name, subSection ) );
|
|
|
|
m_status = Branch;
|
|
|
|
return subSection;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
SectionInfo* getParent() {
|
2012-05-05 20:32:52 +02:00
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool hasUntestedSections() const {
|
2012-05-05 20:32:52 +02:00
|
|
|
if( m_status == Unknown )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
|
|
|
|
std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
|
2012-05-16 00:58:23 +02:00
|
|
|
for(; it != itEnd; ++it ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
if( it->second->hasUntestedSections() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Status m_status;
|
|
|
|
std::map<std::string, SectionInfo*> m_subSections;
|
|
|
|
SectionInfo* m_parent;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED
|