11 #include "TestException.h" 109 void setCommunicator(MPI::Intracomm& communicator);
119 bool hasCommunicator();
124 MPI::Intracomm& communicator();
155 void openInputFile(
const std::string& name, std::ifstream& in)
const;
166 void openOutputFile(
const std::string& name, std::ofstream& out)
const;
178 FILE*
openFile(
const std::string& name,
const char* mode)
const;
188 static bool eq(
int s1,
int s2);
193 static bool eq(
double s1,
double s2);
198 std::string filePrefix_;
201 MPI::Intracomm* communicatorPtr_;
229 setCommunicator(MPI::COMM_WORLD);
263 { filePrefix_ = prefix; }
269 {
return filePrefix_; }
275 {
return isIoProcessor_; }
281 void UnitTest::setCommunicator(MPI::Intracomm& communicator)
283 communicatorPtr_ = &communicator;
284 mpiRank_ = communicator.Get_rank();
286 isIoProcessor_ =
true;
288 isIoProcessor_ =
false;
295 int UnitTest::mpiRank()
301 bool UnitTest::hasCommunicator()
302 {
return bool(communicatorPtr_ != 0); }
307 MPI::Intracomm& UnitTest::communicator()
308 {
return *communicatorPtr_; }
316 std::cout << std::endl;
317 std::cout << std::string(methodName);
333 std::cout << std::endl;
334 std::cout <<
"----------------------------------------------------";
335 std::cout << std::endl << std::endl;
346 std::string filename = filePrefix_;
348 in.open(filename.c_str());
350 std::cout << std::endl;
351 std::cout <<
"Failure to open input file " 352 << filename << std::endl;
353 TEST_THROW(
"Failure to open file");
364 std::string filename = filePrefix_;
366 out.open(filename.c_str());
368 std::cout << std::endl;
369 std::cout <<
"Failure to open output file " 370 << filename << std::endl;
371 TEST_THROW(
"Failure to open file");
382 std::string filename = filePrefix_;
384 FILE* fp = fopen(filename.c_str(), mode);
386 std::cout << std::endl;
387 std::cout <<
"Failure of fopen to open file " 388 << filename << std::endl;
389 TEST_THROW(
"Failure to open file");
404 {
return (s1 == s2); }
411 double epsilon = 1.0E-10;
412 return ( fabs(s1-s2) < epsilon );
virtual ~UnitTest()
Destructor.
void setVerbose(int verbose)
Set verbosity level.
int verbose() const
Return integer verbosity level (0 == silent).
bool isIoProcessor() const
Should this processor read and write to file?
FILE * openFile(const std::string &name, const char *mode) const
Open C file handle with specified mode.
void printEndl()
Write carriage return, iff isIoProcessor.
void openOutputFile(const std::string &name, std::ofstream &out) const
Open C++ output file ofstream.
virtual void setUp()
Set up before each test method (empty default implementation).
UnitTest is a base class for classes that define unit tests.
void setFilePrefix(const std::string &prefix)
Set file prefix.
virtual void endMarker()
Print a line of hashes, iff isIoProcessor.
virtual void tearDown()
Tear down after each test method (empty default implementation).
const std::string & filePrefix()
Get file prefix string.
void printMethod(const char *methodName)
Write name of a class method, iff ioProcessor.
static bool eq(int s1, int s2)
Return true if two integers are equal.
void openInputFile(const std::string &name, std::ifstream &in) const
Open C++ input file ifstream.