2015-10-23 19:20:33 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 1/10/2015.
|
|
|
|
* Copyright 2015 Two Blue Cubes Ltd
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
#include "internal/catch_suppress_warnings.h"
|
|
|
|
#include "internal/catch_compiler_capabilities.h"
|
|
|
|
#include "internal/catch_ptr.hpp"
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
//# pragma clang diagnostic ignored "-Wpadded"
|
|
|
|
//# pragma clang diagnostic ignored "-Wc++98-compat"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
2015-10-23 19:44:48 +02:00
|
|
|
struct IPartTracker : SharedImpl<> {
|
|
|
|
virtual ~IPartTracker() {}
|
2015-10-23 19:34:16 +02:00
|
|
|
|
2015-10-29 09:02:40 +01:00
|
|
|
// static queries
|
2015-10-23 19:20:33 +02:00
|
|
|
virtual std::string name() const = 0;
|
2015-10-29 09:02:40 +01:00
|
|
|
|
|
|
|
// dynamic queries
|
2015-10-23 19:34:16 +02:00
|
|
|
virtual bool hasStarted() const = 0; // true even if ended
|
|
|
|
virtual bool hasEnded() const = 0;
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual bool isSuccessfullyCompleted() const = 0;
|
2015-10-23 19:20:33 +02:00
|
|
|
virtual bool isOpen() const = 0;
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual IPartTracker& parent() = 0;
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:34:16 +02:00
|
|
|
// actions
|
2015-10-23 19:20:33 +02:00
|
|
|
virtual void close() = 0;
|
|
|
|
virtual void fail() = 0;
|
2015-10-29 09:02:40 +01:00
|
|
|
virtual void markAsNeedingAnotherRun() =0;
|
2015-10-23 19:34:16 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual void addChild( Ptr<IPartTracker> const& child ) = 0;
|
|
|
|
virtual IPartTracker* findChild( std::string const& name ) = 0;
|
2015-10-23 19:20:33 +02:00
|
|
|
virtual void openChild() = 0;
|
|
|
|
};
|
2015-10-23 19:34:16 +02:00
|
|
|
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
class TrackerContext {
|
|
|
|
|
|
|
|
enum RunState {
|
|
|
|
NotStarted,
|
|
|
|
Executing,
|
|
|
|
CompletedCycle
|
|
|
|
};
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
Ptr<IPartTracker> m_rootPart;
|
|
|
|
IPartTracker* m_currentPart;
|
2015-10-23 19:20:33 +02:00
|
|
|
RunState m_runState;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static TrackerContext& instance() {
|
|
|
|
static TrackerContext s_instance;
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackerContext()
|
|
|
|
: m_currentPart( CATCH_NULL ),
|
|
|
|
m_runState( NotStarted )
|
|
|
|
{}
|
|
|
|
|
2015-10-23 19:34:16 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& startRun();
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
void endRun() {
|
2015-10-23 19:34:16 +02:00
|
|
|
m_rootPart.reset();
|
2015-10-23 19:20:33 +02:00
|
|
|
m_currentPart = CATCH_NULL;
|
|
|
|
m_runState = NotStarted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void startCycle() {
|
2015-10-23 19:34:16 +02:00
|
|
|
m_currentPart = m_rootPart.get();
|
2015-10-23 19:20:33 +02:00
|
|
|
m_runState = Executing;
|
|
|
|
}
|
|
|
|
void completeCycle() {
|
|
|
|
m_runState = CompletedCycle;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool completedCycle() const {
|
|
|
|
return m_runState == CompletedCycle;
|
|
|
|
}
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& currentPart() {
|
2015-10-23 19:20:33 +02:00
|
|
|
return *m_currentPart;
|
|
|
|
}
|
2015-10-23 19:44:48 +02:00
|
|
|
void setCurrentPart( IPartTracker* part ) {
|
2015-10-23 19:20:33 +02:00
|
|
|
m_currentPart = part;
|
|
|
|
}
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker* findPart( std::string const& name ) {
|
2015-10-23 19:20:33 +02:00
|
|
|
return m_currentPart->findChild( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
class PartTrackerBase : public IPartTracker {
|
2015-10-29 09:02:40 +01:00
|
|
|
protected:
|
2015-10-23 19:20:33 +02:00
|
|
|
enum RunState {
|
|
|
|
NotStarted,
|
|
|
|
Executing,
|
|
|
|
ExecutingChildren,
|
2015-10-29 09:02:40 +01:00
|
|
|
NeedsAnotherRun,
|
2015-10-23 19:20:33 +02:00
|
|
|
CompletedSuccessfully,
|
2015-10-29 09:02:40 +01:00
|
|
|
Failed
|
2015-10-23 19:20:33 +02:00
|
|
|
};
|
|
|
|
class TrackerHasName {
|
|
|
|
std::string m_name;
|
|
|
|
public:
|
|
|
|
TrackerHasName( std::string const& name ) : m_name( name ) {}
|
2015-10-23 19:44:48 +02:00
|
|
|
bool operator ()( Ptr<IPartTracker> const& tracker ) {
|
2015-10-23 19:20:33 +02:00
|
|
|
return tracker->name() == m_name;
|
|
|
|
}
|
|
|
|
};
|
2015-10-23 19:44:48 +02:00
|
|
|
typedef std::vector<Ptr<IPartTracker> > Children;
|
2015-10-23 19:20:33 +02:00
|
|
|
std::string m_name;
|
|
|
|
TrackerContext& m_ctx;
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker* m_parent;
|
2015-10-23 19:20:33 +02:00
|
|
|
Children m_children;
|
|
|
|
RunState m_runState;
|
|
|
|
public:
|
2015-10-23 19:44:48 +02:00
|
|
|
PartTrackerBase( std::string const& name, TrackerContext& ctx, IPartTracker* parent )
|
2015-10-23 19:20:33 +02:00
|
|
|
: m_name( name ),
|
|
|
|
m_ctx( ctx ),
|
|
|
|
m_parent( parent ),
|
|
|
|
m_runState( NotStarted ) {}
|
|
|
|
|
|
|
|
virtual std::string name() const CATCH_OVERRIDE {
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2015-10-23 19:34:16 +02:00
|
|
|
virtual bool hasEnded() const CATCH_OVERRIDE {
|
2015-10-23 19:20:33 +02:00
|
|
|
return m_runState == CompletedSuccessfully || m_runState == Failed;
|
|
|
|
}
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
|
2015-10-23 19:20:33 +02:00
|
|
|
return m_runState == CompletedSuccessfully;
|
|
|
|
}
|
2015-10-23 19:34:16 +02:00
|
|
|
virtual bool hasStarted() const CATCH_OVERRIDE {
|
|
|
|
return m_runState != NotStarted;
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
virtual bool isOpen() const CATCH_OVERRIDE {
|
2015-10-29 09:02:40 +01:00
|
|
|
return hasStarted() && !hasEnded();
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual void addChild( Ptr<IPartTracker> const& child ) CATCH_OVERRIDE {
|
2015-10-23 19:20:33 +02:00
|
|
|
m_children.push_back( child );
|
|
|
|
size_t childCount = m_children.size();
|
|
|
|
}
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual IPartTracker* findChild( std::string const& name ) CATCH_OVERRIDE {
|
2015-10-23 19:20:33 +02:00
|
|
|
Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) );
|
|
|
|
return( it != m_children.end() )
|
2015-10-29 09:02:40 +01:00
|
|
|
? it->get()
|
|
|
|
: CATCH_NULL;
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
2015-10-23 19:44:48 +02:00
|
|
|
virtual IPartTracker& parent() CATCH_OVERRIDE {
|
2015-10-23 19:20:33 +02:00
|
|
|
assert( m_parent ); // Should always be non-null except for root
|
|
|
|
return *m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void openChild() CATCH_OVERRIDE {
|
|
|
|
if( m_runState != ExecutingChildren ) {
|
|
|
|
m_runState = ExecutingChildren;
|
|
|
|
if( m_parent )
|
|
|
|
m_parent->openChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void open() {
|
|
|
|
m_runState = Executing;
|
|
|
|
moveToThis();
|
|
|
|
if( m_parent )
|
|
|
|
m_parent->openChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void close() CATCH_OVERRIDE {
|
2015-10-29 09:02:40 +01:00
|
|
|
|
|
|
|
// Close any still open children (e.g. generators)
|
|
|
|
while( &m_ctx.currentPart() != this )
|
|
|
|
m_ctx.currentPart().close();
|
|
|
|
|
2015-10-23 19:20:33 +02:00
|
|
|
switch( m_runState ) {
|
2015-10-29 09:02:40 +01:00
|
|
|
case CompletedSuccessfully:
|
|
|
|
case Failed:
|
|
|
|
return;
|
|
|
|
|
2015-10-23 19:20:33 +02:00
|
|
|
case Executing:
|
|
|
|
m_runState = CompletedSuccessfully;
|
|
|
|
break;
|
|
|
|
case ExecutingChildren:
|
2015-10-29 09:02:40 +01:00
|
|
|
if( m_children.empty() || m_children.back()->hasEnded() )
|
2015-10-23 19:20:33 +02:00
|
|
|
m_runState = CompletedSuccessfully;
|
|
|
|
break;
|
2015-10-29 09:02:40 +01:00
|
|
|
case NeedsAnotherRun:
|
|
|
|
m_runState = Executing;
|
2015-10-23 19:20:33 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw std::logic_error( "Unexpected state" );
|
|
|
|
}
|
|
|
|
moveToParent();
|
|
|
|
m_ctx.completeCycle();
|
|
|
|
}
|
|
|
|
virtual void fail() CATCH_OVERRIDE {
|
|
|
|
m_runState = Failed;
|
|
|
|
if( m_parent )
|
2015-10-29 09:02:40 +01:00
|
|
|
m_parent->markAsNeedingAnotherRun();
|
2015-10-23 19:20:33 +02:00
|
|
|
moveToParent();
|
|
|
|
m_ctx.completeCycle();
|
|
|
|
}
|
2015-10-29 09:02:40 +01:00
|
|
|
virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
|
|
|
|
m_runState = NeedsAnotherRun;
|
|
|
|
}
|
2015-10-23 19:20:33 +02:00
|
|
|
private:
|
|
|
|
void moveToParent() {
|
2015-10-29 09:02:40 +01:00
|
|
|
assert( m_parent );
|
2015-10-23 19:20:33 +02:00
|
|
|
m_ctx.setCurrentPart( m_parent );
|
|
|
|
}
|
|
|
|
void moveToThis() {
|
|
|
|
m_ctx.setCurrentPart( this );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
class SectionTracker : public PartTrackerBase {
|
2015-10-23 19:20:33 +02:00
|
|
|
public:
|
2015-10-23 19:44:48 +02:00
|
|
|
SectionTracker( std::string const& name, TrackerContext& ctx, IPartTracker* parent )
|
|
|
|
: PartTrackerBase( name, ctx, parent )
|
2015-10-23 19:20:33 +02:00
|
|
|
{}
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) {
|
|
|
|
SectionTracker* section = CATCH_NULL;
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& currentPart = ctx.currentPart();
|
|
|
|
if( IPartTracker* part = currentPart.findChild( name ) ) {
|
|
|
|
section = dynamic_cast<SectionTracker*>( part );
|
2015-10-23 19:20:33 +02:00
|
|
|
assert( section );
|
|
|
|
}
|
|
|
|
else {
|
2015-10-23 19:44:48 +02:00
|
|
|
section = new SectionTracker( name, ctx, ¤tPart );
|
2015-10-23 19:20:33 +02:00
|
|
|
currentPart.addChild( section );
|
|
|
|
}
|
2015-10-23 19:34:16 +02:00
|
|
|
if( !ctx.completedCycle() && !section->hasEnded() ) {
|
2015-10-29 09:02:40 +01:00
|
|
|
|
2015-10-23 19:20:33 +02:00
|
|
|
section->open();
|
|
|
|
}
|
|
|
|
return *section;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-29 09:02:40 +01:00
|
|
|
class IndexTracker : public PartTrackerBase {
|
|
|
|
int m_size;
|
|
|
|
int m_index;
|
|
|
|
public:
|
|
|
|
IndexTracker( std::string const& name, TrackerContext& ctx, IPartTracker* parent, int size )
|
|
|
|
: PartTrackerBase( name, ctx, parent ),
|
|
|
|
m_size( size ),
|
|
|
|
m_index( -1 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) {
|
|
|
|
IndexTracker* tracker = CATCH_NULL;
|
|
|
|
|
|
|
|
IPartTracker& currentPart = ctx.currentPart();
|
|
|
|
if( IPartTracker* part = currentPart.findChild( name ) ) {
|
|
|
|
tracker = dynamic_cast<IndexTracker*>( part );
|
|
|
|
assert( tracker );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tracker = new IndexTracker( name, ctx, ¤tPart, size );
|
|
|
|
currentPart.addChild( tracker );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !ctx.completedCycle() && !tracker->hasEnded() ) {
|
|
|
|
if( tracker->m_runState != ExecutingChildren )
|
|
|
|
tracker->moveNext();
|
|
|
|
tracker->open();
|
|
|
|
}
|
|
|
|
|
|
|
|
return *tracker;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index() const { return m_index; }
|
|
|
|
|
|
|
|
void moveNext() {
|
|
|
|
m_index++;
|
|
|
|
m_children.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void close() CATCH_OVERRIDE {
|
|
|
|
PartTrackerBase::close();
|
|
|
|
if( m_runState == CompletedSuccessfully )
|
|
|
|
if( m_index < m_size-1 )
|
|
|
|
m_runState = Executing;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& TrackerContext::startRun() {
|
|
|
|
m_rootPart = new SectionTracker( "{root}", *this, CATCH_NULL );
|
|
|
|
m_currentPart = CATCH_NULL;
|
|
|
|
m_runState = Executing;
|
|
|
|
return *m_rootPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
class LocalContext {
|
|
|
|
|
|
|
|
public:
|
|
|
|
TrackerContext& operator()() const {
|
|
|
|
return TrackerContext::instance();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-23 19:20:33 +02:00
|
|
|
} // namespace Catch
|
|
|
|
|
|
|
|
inline Catch::TrackerContext& C_A_T_C_H_Context() {
|
|
|
|
return Catch::TrackerContext::instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------
|
|
|
|
|
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
using namespace Catch;
|
|
|
|
|
|
|
|
inline void testCase( Catch::LocalContext const& C_A_T_C_H_Context ) {
|
|
|
|
|
2015-10-23 19:34:16 +02:00
|
|
|
// REQUIRE( C_A_T_C_H_Context().i() == 42 );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "PartTracker" ) {
|
|
|
|
|
|
|
|
TrackerContext ctx;
|
|
|
|
ctx.startRun();
|
|
|
|
ctx.startCycle();
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& testCase = SectionTracker::acquire( ctx, "Testcase" );
|
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s1 = SectionTracker::acquire( ctx, "S1" );
|
|
|
|
REQUIRE( s1.isOpen() == true );
|
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
SECTION( "successfully close one section" ) {
|
|
|
|
s1.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == true );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( testCase.hasEnded() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
testCase.close();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
2015-10-29 09:02:40 +01:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION( "fail one section" ) {
|
|
|
|
s1.fail();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( s1.hasEnded() == true );
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( testCase.hasEnded() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
testCase.close();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
SECTION( "re-enter after failed section" ) {
|
|
|
|
ctx.startCycle();
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
2015-10-29 09:02:40 +01:00
|
|
|
REQUIRE( s1b.isOpen() == false );
|
|
|
|
|
2015-10-23 19:20:33 +02:00
|
|
|
testCase2.close();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( testCase.hasEnded() == true );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
SECTION( "re-enter after failed section and find next section" ) {
|
|
|
|
ctx.startCycle();
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
|
|
|
REQUIRE( s1b.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
2015-10-23 19:20:33 +02:00
|
|
|
REQUIRE( s2.isOpen() );
|
|
|
|
s2.close();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
|
|
|
|
|
|
|
testCase2.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( testCase.hasEnded() == true );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION( "successfully close one section, then find another" ) {
|
|
|
|
s1.close();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
2015-10-23 19:20:33 +02:00
|
|
|
REQUIRE( s2.isOpen() == false );
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s2.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
testCase.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
SECTION( "Re-enter - skips S1 and enters S2" ) {
|
2015-10-23 19:20:33 +02:00
|
|
|
ctx.startCycle();
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
|
|
|
REQUIRE( s1b.isOpen() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s2b = SectionTracker::acquire( ctx, "S2" );
|
2015-10-23 19:20:33 +02:00
|
|
|
REQUIRE( s2b.isOpen() );
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s2b.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
REQUIRE( ctx.completedCycle() == false );
|
|
|
|
|
|
|
|
SECTION ("Successfully close S2") {
|
|
|
|
s2b.close();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s2b.isSuccessfullyCompleted() == true );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( testCase2.hasEnded() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
testCase2.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == true );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
SECTION ("fail S2") {
|
|
|
|
s2b.fail();
|
|
|
|
REQUIRE( ctx.completedCycle() == true );
|
|
|
|
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s2b.isSuccessfullyCompleted() == false );
|
2015-10-23 19:34:16 +02:00
|
|
|
REQUIRE( s2b.hasEnded() == true );
|
|
|
|
REQUIRE( testCase2.hasEnded() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
testCase2.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION( "open a nested section" ) {
|
2015-10-23 19:44:48 +02:00
|
|
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
2015-10-23 19:20:33 +02:00
|
|
|
REQUIRE( s2.isOpen() == true );
|
|
|
|
|
|
|
|
s2.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s2.isSuccessfullyCompleted() == true );
|
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
s1.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == true );
|
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
2015-10-23 19:20:33 +02:00
|
|
|
|
|
|
|
testCase.close();
|
2015-10-23 19:44:48 +02:00
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 09:02:40 +01:00
|
|
|
SECTION( "start a generator" ) {
|
|
|
|
IndexTracker& g1 = IndexTracker::acquire( ctx, "G1", 2 );
|
|
|
|
REQUIRE( g1.isOpen() == true );
|
|
|
|
REQUIRE( g1.index() == 0 );
|
|
|
|
|
|
|
|
REQUIRE( g1.isSuccessfullyCompleted() == false );
|
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
SECTION( "close outer section" )
|
|
|
|
{
|
|
|
|
s1.close();
|
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
|
|
|
testCase.close();
|
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
SECTION( "Re-enter for second generation" ) {
|
|
|
|
ctx.startCycle();
|
|
|
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
|
|
|
REQUIRE( testCase2.isOpen() == true );
|
|
|
|
|
|
|
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
|
|
|
REQUIRE( s1b.isOpen() == true );
|
|
|
|
|
|
|
|
|
|
|
|
IndexTracker& g1b = IndexTracker::acquire( ctx, "G1", 2 );
|
|
|
|
REQUIRE( g1b.isOpen() == true );
|
|
|
|
REQUIRE( g1b.index() == 1 );
|
|
|
|
|
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
s1b.close();
|
|
|
|
REQUIRE( s1b.isSuccessfullyCompleted() == true );
|
|
|
|
REQUIRE( g1b.isSuccessfullyCompleted() == true );
|
|
|
|
testCase2.close();
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SECTION( "Start a new inner section" ) {
|
|
|
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
|
|
|
REQUIRE( s2.isOpen() == true );
|
|
|
|
|
|
|
|
s2.close();
|
|
|
|
REQUIRE( s2.isSuccessfullyCompleted() == true );
|
|
|
|
|
|
|
|
s1.close();
|
|
|
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
testCase.close();
|
|
|
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
SECTION( "Re-enter for second generation" ) {
|
|
|
|
ctx.startCycle();
|
|
|
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
|
|
|
REQUIRE( s1b.isSuccessfullyCompleted() == false );
|
|
|
|
|
|
|
|
// generator - next value
|
|
|
|
IndexTracker& g1b = IndexTracker::acquire( ctx, "G1", 2 );
|
|
|
|
REQUIRE( g1b.isOpen() == true );
|
|
|
|
REQUIRE( g1b.index() == 1 );
|
|
|
|
|
|
|
|
// inner section again
|
|
|
|
IPartTracker& s2b = SectionTracker::acquire( ctx, "S2" );
|
|
|
|
REQUIRE( s2b.isOpen() == true );
|
|
|
|
|
|
|
|
s2b.close();
|
|
|
|
REQUIRE( s2b.isSuccessfullyCompleted() == true );
|
|
|
|
|
|
|
|
s1b.close();
|
|
|
|
REQUIRE( s1b.isSuccessfullyCompleted() == true );
|
|
|
|
REQUIRE( g1b.isSuccessfullyCompleted() == true );
|
|
|
|
|
|
|
|
testCase2.close();
|
|
|
|
REQUIRE( testCase2.isSuccessfullyCompleted() == true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// !TBD"
|
|
|
|
// nested generator
|
|
|
|
// two sections within a generator
|
|
|
|
}
|
2015-10-23 19:20:33 +02:00
|
|
|
}
|