1#ifndef UNIT_TEST_RUNNER_H
2#define UNIT_TEST_RUNNER_H
11#include "TestRunner.h"
12#include "TestException.h"
109template <
class UnitTestClass>
150 void method(
unsigned int i);
159 std::vector<MethodPtr> methodPtrs_;
162 std::vector<int> results_;
171template <
class UnitTestClass>
177 results_.reserve(mpiSize());
178 for (
int i=0; i < mpiSize(); ++i) {
179 results_.push_back(
false);
188template <
class UnitTestClass>
195template <
class UnitTestClass>
197{ methodPtrs_.push_back(methodPtr); }
202template <
class UnitTestClass>
204{
return methodPtrs_.size(); }
211template <
class UnitTestClass>
214 UnitTestClass testCase;
220 testCase.setFilePrefix(filePrefix());
225 (testCase.*methodPtrs_[i])();
234 std::cout << std::endl;
235 std::cout <<
" Failure " << std::endl << std::endl;
236 std::cout << e.
message() << std::endl;
248 MPI::COMM_WORLD.Barrier();
249 if (mpiRank() == 0) {
250 results_[0] = result;
251 if (results_[0] == 0) {
252 std::cout << std::endl;
253 std::cout <<
" Failure on Processor 0"
254 << std::endl << std::endl;
255 std::cout << exception.
message() << std::endl;
258 for (
int i=1; i < mpiSize(); ++i) {
260 MPI::COMM_WORLD.Recv(&(results_[i]), 1, MPI_INT, i, i);
262 if (results_[i] == 0) {
265 MPI::COMM_WORLD.Send(&(results_[i]), 1, MPI_INT, i, mpiSize() + i);
267 MPI::COMM_WORLD.Recv(&(results_[i]), 1, MPI_INT, i, 2*mpiSize() + i);
280 MPI::COMM_WORLD.Send(&result, 1, MPI_INT, 0, mpiRank());
284 MPI::COMM_WORLD.Recv(&result, 1, MPI_INT, 0,
285 mpiSize() + mpiRank());
287 std::cout << std::endl;
288 std::cout <<
" Failure on Processor " << mpiRank()
289 << std::endl << std::endl;
290 std::cout << exception.
message() << std::endl;
293 MPI::COMM_WORLD.Send(&result, 1, MPI_INT, 0,
294 2*mpiSize() + mpiRank());
297 MPI::COMM_WORLD.Barrier();
305template <
class UnitTestClass>
308 for (
unsigned int i = 0; i < methodPtrs_.size(); ++i) {
320#define TEST_RUNNER(UnitTestClass) UnitTestClass##_Runner
328#define TEST_BEGIN(UnitTestClass) \
329 class TEST_RUNNER(UnitTestClass) \
330 : public UnitTestRunner<UnitTestClass> \
331 { public: TEST_RUNNER(UnitTestClass)() {
336#define TEST_ADD(UnitTestClass, Method) \
337 addTestMethod(&UnitTestClass::Method);
344#define TEST_END(UnitTestClass) } };
An exception thrown by a failed unit test.
const std::string & message()
Return the error message.
Abstract base class for classes that run tests.
bool isIoProcessor() const
Is this the IO processor of an MPI communicator?
int nFailure() const
Return number of failed tests run.
Template for a TestRunner that runs test methods of an associated UnitTest.
bool isIoProcessor() const
Is this the IO processor of an MPI communicator?
void(UnitTestClass::* MethodPtr)()
Pointer to a test method of the associated UnitTest class.
UnitTestRunner()
Constructor.
void addTestMethod(MethodPtr methodPtr)
Register a test method of the associated unit test class.
virtual int run()
Run all registered test methods in the order added.
int nTestMethod()
Return the number of registered test methods.
~UnitTestRunner()
Destructor.
void method(unsigned int i)
Run test method number i.