2013-07-23 19:48:36 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil Nash on 23/7/2013
|
|
|
|
* Copyright 2013 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_TEST_CASE_TRACKER_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
|
|
|
|
|
2015-07-01 08:33:27 +02:00
|
|
|
#include "catch_compiler_capabilities.h"
|
2017-04-25 22:51:44 +02:00
|
|
|
#include "catch_common.h"
|
2015-07-01 08:33:27 +02:00
|
|
|
|
2013-07-23 19:48:36 +02:00
|
|
|
#include <string>
|
2015-11-02 07:14:52 +01:00
|
|
|
#include <vector>
|
2017-04-26 18:04:00 +02:00
|
|
|
#include <memory>
|
2013-07-23 19:48:36 +02:00
|
|
|
|
2017-03-29 20:30:59 +02:00
|
|
|
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
|
|
|
|
|
2013-07-23 19:48:36 +02:00
|
|
|
namespace Catch {
|
2015-11-02 07:14:52 +01:00
|
|
|
namespace TestCaseTracking {
|
|
|
|
|
2017-01-12 18:10:38 +01:00
|
|
|
struct NameAndLocation {
|
|
|
|
std::string name;
|
|
|
|
SourceLineInfo location;
|
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
NameAndLocation( std::string const& _name, SourceLineInfo const& _location );
|
2017-01-12 18:10:38 +01:00
|
|
|
};
|
|
|
|
|
2017-04-25 21:57:43 +02:00
|
|
|
struct ITracker;
|
|
|
|
|
|
|
|
using ITrackerPtr = std::shared_ptr<ITracker>;
|
|
|
|
|
|
|
|
struct ITracker {
|
2017-07-19 10:13:47 +02:00
|
|
|
virtual ~ITracker() = default;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
// static queries
|
2017-01-12 18:10:38 +01:00
|
|
|
virtual NameAndLocation const& nameAndLocation() const = 0;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
// dynamic queries
|
|
|
|
virtual bool isComplete() const = 0; // Successfully completed or failed
|
|
|
|
virtual bool isSuccessfullyCompleted() const = 0;
|
|
|
|
virtual bool isOpen() const = 0; // Started but not complete
|
2015-11-02 20:21:46 +01:00
|
|
|
virtual bool hasChildren() const = 0;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
virtual ITracker& parent() = 0;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
// actions
|
|
|
|
virtual void close() = 0; // Successfully complete
|
|
|
|
virtual void fail() = 0;
|
|
|
|
virtual void markAsNeedingAnotherRun() = 0;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 21:57:43 +02:00
|
|
|
virtual void addChild( ITrackerPtr const& child ) = 0;
|
|
|
|
virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0;
|
2015-11-02 07:14:52 +01:00
|
|
|
virtual void openChild() = 0;
|
2017-01-26 23:13:12 +01:00
|
|
|
|
2016-04-28 09:10:10 +02:00
|
|
|
// Debug/ checking
|
|
|
|
virtual bool isSectionTracker() const = 0;
|
|
|
|
virtual bool isIndexTracker() const = 0;
|
2015-11-02 07:14:52 +01:00
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
class TrackerContext {
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
enum RunState {
|
|
|
|
NotStarted,
|
|
|
|
Executing,
|
|
|
|
CompletedCycle
|
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 21:57:43 +02:00
|
|
|
ITrackerPtr m_rootTracker;
|
2017-04-25 19:56:53 +02:00
|
|
|
ITracker* m_currentTracker = nullptr;
|
|
|
|
RunState m_runState = NotStarted;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
public:
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
static TrackerContext& instance();
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
ITracker& startRun();
|
2017-07-19 10:13:47 +02:00
|
|
|
void endRun();
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
void startCycle();
|
|
|
|
void completeCycle();
|
|
|
|
|
|
|
|
bool completedCycle() const;
|
|
|
|
ITracker& currentTracker();
|
|
|
|
void setCurrentTracker( ITracker* tracker );
|
2015-11-02 07:14:52 +01:00
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
class TrackerBase : public ITracker {
|
|
|
|
protected:
|
|
|
|
enum CycleState {
|
|
|
|
NotStarted,
|
|
|
|
Executing,
|
|
|
|
ExecutingChildren,
|
|
|
|
NeedsAnotherRun,
|
|
|
|
CompletedSuccessfully,
|
|
|
|
Failed
|
|
|
|
};
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
class TrackerHasName {
|
2017-01-12 18:10:38 +01:00
|
|
|
NameAndLocation m_nameAndLocation;
|
2015-11-02 07:14:52 +01:00
|
|
|
public:
|
2017-07-19 10:13:47 +02:00
|
|
|
TrackerHasName( NameAndLocation const& nameAndLocation );
|
2017-07-25 17:16:28 +02:00
|
|
|
bool operator ()( ITrackerPtr const& tracker ) const;
|
2015-11-02 07:14:52 +01:00
|
|
|
};
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2017-04-25 21:57:43 +02:00
|
|
|
typedef std::vector<ITrackerPtr> Children;
|
2017-01-12 18:10:38 +01:00
|
|
|
NameAndLocation m_nameAndLocation;
|
2015-11-02 07:14:52 +01:00
|
|
|
TrackerContext& m_ctx;
|
|
|
|
ITracker* m_parent;
|
|
|
|
Children m_children;
|
2017-04-25 19:56:53 +02:00
|
|
|
CycleState m_runState = NotStarted;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
public:
|
2017-07-19 10:13:47 +02:00
|
|
|
TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
|
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
NameAndLocation const& nameAndLocation() const override;
|
|
|
|
bool isComplete() const override;
|
|
|
|
bool isSuccessfullyCompleted() const override;
|
|
|
|
bool isOpen() const override;
|
|
|
|
bool hasChildren() const override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
void addChild( ITrackerPtr const& child ) override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override;
|
|
|
|
ITracker& parent() override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
void openChild() override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
bool isSectionTracker() const override;
|
|
|
|
bool isIndexTracker() const override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
|
|
|
void open();
|
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
void close() override;
|
|
|
|
void fail() override;
|
|
|
|
void markAsNeedingAnotherRun() override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
private:
|
2017-07-19 10:13:47 +02:00
|
|
|
void moveToParent();
|
|
|
|
void moveToThis();
|
2015-11-02 07:14:52 +01:00
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
class SectionTracker : public TrackerBase {
|
2017-01-12 18:10:38 +01:00
|
|
|
std::vector<std::string> m_filters;
|
2015-11-02 07:14:52 +01:00
|
|
|
public:
|
2017-07-19 10:13:47 +02:00
|
|
|
SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
|
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
bool isSectionTracker() const override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
|
|
|
static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation );
|
|
|
|
|
|
|
|
void tryOpen();
|
|
|
|
|
|
|
|
void addInitialFilters( std::vector<std::string> const& filters );
|
|
|
|
void addNextFilters( std::vector<std::string> const& filters );
|
2015-11-02 07:14:52 +01:00
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
class IndexTracker : public TrackerBase {
|
|
|
|
int m_size;
|
2017-04-25 19:56:53 +02:00
|
|
|
int m_index = -1;
|
2015-11-02 07:14:52 +01:00
|
|
|
public:
|
2017-07-19 10:13:47 +02:00
|
|
|
IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size );
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
bool isIndexTracker() const override;
|
|
|
|
void close() override;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
|
|
|
static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size );
|
|
|
|
|
|
|
|
int index() const;
|
|
|
|
|
|
|
|
void moveNext();
|
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
} // namespace TestCaseTracking
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-11-02 07:14:52 +01:00
|
|
|
using TestCaseTracking::ITracker;
|
|
|
|
using TestCaseTracking::TrackerContext;
|
|
|
|
using TestCaseTracking::SectionTracker;
|
|
|
|
using TestCaseTracking::IndexTracker;
|
2013-07-23 19:48:36 +02:00
|
|
|
|
|
|
|
} // namespace Catch
|
|
|
|
|
2017-03-29 20:30:59 +02:00
|
|
|
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
|
|
|
|
|
2013-07-23 19:48:36 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
|