PSCF v1.1
CompositeTestRunner.h
1#ifndef COMPOSITE_TEST_RUNNER_H
2#define COMPOSITE_TEST_RUNNER_H
3
4/*
5* Simpatico - Simulation Package for Polymeric and Molecular Liquids
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "TestRunner.h"
12#include <vector>
13
20{
21
22public:
23
24 // Default constructor.
25
29 virtual ~CompositeTestRunner();
30
39 void addChild(TestRunner& child);
40
49 void addChild(TestRunner* childPtr);
50
63 void addChild(TestRunner* childPtr, const std::string& prefix);
64
75 virtual void addFilePrefix(const std::string& prefix);
76
80 virtual int run();
81
82private:
83
85 std::vector<TestRunner*> children_;
86
88 std::vector<TestRunner*> ownedChildren_;
89
90};
91
92// Function definitions
93
94/*
95* Destructor.
96*/
98{
99 unsigned int i;
100 for (i = 0; i < children_.size(); ++i) {
101 delete ownedChildren_[i];
102 }
103}
104
105/*
106* Add an existing TestRunner as a child.
107*/
109{
110 children_.push_back(&child);
111 child.setParent(*this);
112}
113
114/*
115* Add a TestRunner as a child, and accept ownership.
116*/
118{
119 children_.push_back(childPtr);
120 ownedChildren_.push_back(childPtr);
121 childPtr->setParent(*this);
122}
123
124/*
125* Add a TestRunner as a child, accept ownership, and set file prefix.
126*/
128 const std::string& prefix)
129{
130 addChild(childPtr);
131 childPtr->addFilePrefix(prefix);
132}
133
134/*
135* Prepend argument prefix to existing filePrefix.
136*/
137void CompositeTestRunner::addFilePrefix(const std::string& prefix)
138{
140 for (unsigned int i = 0; i < children_.size(); ++i) {
141 children_[i]->addFilePrefix(prefix);
142 }
143}
144
145/*
146* Run all children in sequence, using depth-first recursion.
147*/
149{
150 for (unsigned int i = 0; i < children_.size(); ++i) {
151 children_[i]->run();
152 }
153 report();
154 return nFailure();
155}
156
157// Preprocessor macros
158
164#define TEST_COMPOSITE_BEGIN(CompositeClass) \
165 class CompositeClass : public CompositeTestRunner { public: \
166 CompositeClass () {
167
176#define TEST_COMPOSITE_ADD_UNIT(UnitTestClass) \
177 addChild(new TEST_RUNNER(UnitTestClass));
178
188#define TEST_COMPOSITE_ADD_CHILD(TestRunner, Prefix) \
189 addChild(new TestRunner, Prefix);
190
196#define TEST_COMPOSITE_END } };
197
198#endif
A TestRunner comprised of one or more child TestRunners.
void addChild(TestRunner &child)
Add an existing TestRunner as a child.
virtual int run()
Run all children in sequence, using depth-first recursion.
virtual ~CompositeTestRunner()
Destructor.
virtual void addFilePrefix(const std::string &prefix)
Prepend argument prefix to existing filePrefix.
Abstract base class for classes that run tests.
Definition: TestRunner.h:74
int nFailure() const
Return number of failed tests run.
Definition: TestRunner.h:223
virtual void addFilePrefix(const std::string &prefix)
Prepend argument prefix to existing filePrefix.
Definition: TestRunner.h:323
void report() const
If this object has no parent, report success and failure counters.
Definition: TestRunner.h:310
void setParent(TestRunner &parent)
Set another TestRunner as the parent.
Definition: TestRunner.h:199