diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-22 16:53:56 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-22 16:53:56 +0100 |
commit | e9fc58cb304323f07aba736fc523903481404cff (patch) | |
tree | 59db450412ca101aa9601b3f2174436898f955c1 /unittest/Catch/include/internal/catch_section_info.hpp | |
parent | 8150ee4edc7e32d5c27cd3e0f68c630d90865638 (diff) | |
parent | 48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391 (diff) | |
download | libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.gz libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.bz2 |
Merge commit '48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391' as 'unittest/Catch'
Diffstat (limited to 'unittest/Catch/include/internal/catch_section_info.hpp')
-rw-r--r-- | unittest/Catch/include/internal/catch_section_info.hpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/unittest/Catch/include/internal/catch_section_info.hpp b/unittest/Catch/include/internal/catch_section_info.hpp new file mode 100644 index 0000000..6258a28 --- /dev/null +++ b/unittest/Catch/include/internal/catch_section_info.hpp @@ -0,0 +1,113 @@ +/* + * 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) + */ +#ifndef TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED + +#include "catch_common.h" + +#include <map> +#include <string> + +namespace Catch { + + class RunningSection { + public: + + typedef std::vector<RunningSection*> SubSections; + + enum State { + Root, + Unknown, + Branch, + TestedBranch, + TestedLeaf + }; + + RunningSection( RunningSection* parent, std::string const& name ) + : m_state( Unknown ), + m_parent( parent ), + m_name( name ) + {} + + RunningSection( std::string const& name ) + : m_state( Root ), + m_parent( CATCH_NULL ), + m_name( name ) + {} + + ~RunningSection() { + deleteAll( m_subSections ); + } + + std::string getName() const { + return m_name; + } + + bool shouldRun() const { + return m_state < TestedBranch; + } + + bool isBranch() const { + return m_state == Branch; + } + + const RunningSection* getParent() const { + return m_parent; + } + + bool hasUntestedSections() const { + if( m_state == Unknown ) + return true; + for( SubSections::const_iterator it = m_subSections.begin(); + it != m_subSections.end(); + ++it) + if( (*it)->hasUntestedSections() ) + return true; + return false; + } + + // Mutable methods: + + RunningSection* getParent() { + return m_parent; + } + + RunningSection* findOrAddSubSection( std::string const& name, bool& changed ) { + for( SubSections::const_iterator it = m_subSections.begin(); + it != m_subSections.end(); + ++it) + if( (*it)->getName() == name ) + return *it; + RunningSection* subSection = new RunningSection( this, name ); + m_subSections.push_back( subSection ); + m_state = Branch; + changed = true; + return subSection; + } + + bool ran() { + if( m_state >= Branch ) + return false; + m_state = TestedLeaf; + return true; + } + + void ranToCompletion() { + if( m_state == Branch && !hasUntestedSections() ) + m_state = TestedBranch; + } + + private: + State m_state; + RunningSection* m_parent; + std::string m_name; + SubSections m_subSections; + }; +} + +#endif // TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED |