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 {
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
class RunningSection {
|
2012-05-05 20:32:52 +02:00
|
|
|
public:
|
2012-11-29 10:17:08 +01:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
typedef std::vector<RunningSection*> SubSections;
|
2012-05-16 00:58:23 +02:00
|
|
|
|
2012-11-29 10:05:51 +01:00
|
|
|
enum State {
|
2012-05-05 20:32:52 +02:00
|
|
|
Root,
|
|
|
|
Unknown,
|
|
|
|
Branch,
|
|
|
|
TestedBranch,
|
|
|
|
TestedLeaf
|
|
|
|
};
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
RunningSection( RunningSection* parent, const std::string& name )
|
2012-11-29 10:05:51 +01:00
|
|
|
: m_state( Unknown ),
|
|
|
|
m_parent( parent ),
|
|
|
|
m_name( name )
|
2012-05-16 00:58:23 +02:00
|
|
|
{}
|
2012-05-05 20:32:52 +02:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
RunningSection( const std::string& name )
|
2012-11-29 10:05:51 +01:00
|
|
|
: m_state( Root ),
|
|
|
|
m_parent( NULL ),
|
|
|
|
m_name( name )
|
2012-05-16 00:58:23 +02:00
|
|
|
{}
|
2012-05-05 20:32:52 +02:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
~RunningSection() {
|
2012-11-29 10:17:08 +01:00
|
|
|
deleteAll( m_subSections );
|
2012-05-05 20:32:52 +02:00
|
|
|
}
|
2012-05-16 00:58:23 +02:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
std::string getName() const {
|
2012-11-29 10:05:51 +01:00
|
|
|
return m_name;
|
2012-08-31 09:10:36 +02:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:05:51 +01:00
|
|
|
bool shouldRun() const {
|
|
|
|
return m_state < TestedBranch;
|
2012-05-05 20:32:52 +02:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:05:51 +01:00
|
|
|
bool isBranch() const {
|
|
|
|
return m_state == Branch;
|
2012-05-05 20:32:52 +02:00
|
|
|
}
|
2012-11-29 10:05:51 +01:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
const RunningSection* getParent() const {
|
2012-05-05 20:32:52 +02:00
|
|
|
return m_parent;
|
|
|
|
}
|
2012-11-29 10:05:51 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool hasUntestedSections() const {
|
2012-11-29 10:05:51 +01:00
|
|
|
if( m_state == Unknown )
|
2012-05-05 20:32:52 +02:00
|
|
|
return true;
|
2012-11-29 10:17:08 +01:00
|
|
|
for( SubSections::const_iterator it = m_subSections.begin();
|
|
|
|
it != m_subSections.end();
|
|
|
|
++it)
|
|
|
|
if( (*it)->hasUntestedSections() )
|
2012-05-05 20:32:52 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-29 10:05:51 +01:00
|
|
|
|
|
|
|
// Mutable methods:
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
RunningSection* getParent() {
|
2012-11-29 10:05:51 +01:00
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
RunningSection* findOrAddSubSection( const std::string& name, bool& changed ) {
|
2012-11-29 10:17:08 +01:00
|
|
|
for( SubSections::const_iterator it = m_subSections.begin();
|
|
|
|
it != m_subSections.end();
|
|
|
|
++it)
|
|
|
|
if( (*it)->getName() == name )
|
|
|
|
return *it;
|
2012-11-29 21:31:17 +01:00
|
|
|
RunningSection* subSection = new RunningSection( this, name );
|
2012-11-29 10:17:08 +01:00
|
|
|
m_subSections.push_back( subSection );
|
2012-11-29 10:05:51 +01:00
|
|
|
m_state = Branch;
|
|
|
|
changed = true;
|
|
|
|
return subSection;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ran() {
|
2012-11-29 21:11:46 +01:00
|
|
|
if( m_state >= Branch )
|
|
|
|
return false;
|
|
|
|
m_state = TestedLeaf;
|
|
|
|
return true;
|
2012-11-29 10:05:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ranToCompletion() {
|
|
|
|
if( m_state == Branch && !hasUntestedSections() )
|
|
|
|
m_state = TestedBranch;
|
|
|
|
}
|
|
|
|
|
2012-05-05 20:32:52 +02:00
|
|
|
private:
|
2012-11-29 10:05:51 +01:00
|
|
|
State m_state;
|
2012-11-29 21:31:17 +01:00
|
|
|
RunningSection* m_parent;
|
2012-11-29 10:05:51 +01:00
|
|
|
std::string m_name;
|
2012-11-29 10:17:08 +01:00
|
|
|
SubSections m_subSections;
|
2012-05-05 20:32:52 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED
|