xmscore  1.0
TestTools.cpp File Reference

Functions for running unit or intermediate tests. More...

#include <xmscore/testing/TestTools.h>
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
#include <boost/predef.h>
#include <cxxtest/GlobalFixture.h>
#include <cxxtest/TestSuite.h>
#include <xmscore/misc/XmLog.h>
#include <xmscore/misc/environment.h>
#include <xmscore/points/pt.h>

Go to the source code of this file.

Functions

void xms::ttByPassMessages (int a_defaultChoice)
 Bypass the ui elements and just set return value. More...
 
bool xms::ttSkippingMessages ()
 Has ttByPassMessages been called without calling ttClearSkippingMessages. More...
 
int xms::ttByPassDefault ()
 Get the default choice when skipping messages. More...
 
void xms::ttClearSkippingMessages ()
 Turn off skipping ui elements.
 
ETestMessagingState & xms::ttTestMessagingState ()
 Get the batch mode singleton. More...
 
void xms::ttCheckXmLogForEachTest (bool a_setting)
 Set check of XM_LOG before and after each test. More...
 
bool xms::ttCheckXmLogForEachTest ()
 Turn on check of XM_LOG before and after each test. More...
 
void xms::ttAssertStackedErrors (const char *a_file, int a_line, const std::string &a_expected)
 CXX Test assert that the stackable XM_LOG has the expected errors. More...
 
void xms::ttGetTestFilePaths (const std::string &a_path, const std::string &a_fileBase, const std::string &a_extension, std::string &a_baseFilePath, std::string &a_outFilePath)
 Get testing base and output file using the compiled for architecture. Checks for appended "MacOsX" for Mac OS X and "64" for 64-bit builds. For example with Mac OS 64-bit build looks for test_baseMacOsX.vtu then if not found test_base64.vtu, then if neither found then uses test_base.vtu. More...
 
bool xms::ttTextFilesEqual (const std::string &a_file1, const std::string &a_file2, std::string &a_message)
 Returns true if the two files are equal. More...
 
void xms::ttTextFilesEqual (const std::string &a_srcFile, unsigned a_line, const std::string &a_file1, const std::string &a_file2)
 Returns true if the two files are equal. More...
 
void xms::ttStreamsEqual (const std::string &a_src, unsigned int a_line, std::istream &a_strm1, std::istream &a_strm2)
 Returns true if the two streams are equal. More...
 
bool xms::ttEqualPointsXYZ (const Pt3d &a_pt1, const Pt3d &a_pt2, double a_tolerance)
 Returns true if the points are equal to within tolerance. More...
 
bool xms::ttEqualPointsXYZ (double a_x1, double a_y1, double a_z1, double a_x2, double a_y2, double a_z2, double a_tolerance)
 Returns true if the points are equal to within tolerance. More...
 
bool xms::ttEqualPointsXY (double a_x1, double a_y1, double a_x2, double a_y2, double a_tolerance)
 Returns true if the points are equal to within tolerance. More...
 
bool xms::ttEqualPointsXY (const Pt2d &a_pt1, const Pt2d &a_pt2, double a_tolerance)
 
bool xms::ttEqualPointsXY (const Pt3d &a_pt1, const Pt3d &a_pt2, double a_tolerance)
 

Detailed Description

Functions for running unit or intermediate tests.

Definition in file TestTools.cpp.

Function Documentation

◆ ttAssertStackedErrors()

void xms::ttAssertStackedErrors ( const char *  a_file,
int  a_line,
const std::string &  a_expected 
)

CXX Test assert that the stackable XM_LOG has the expected errors.

Parameters
a_fileFile.
a_lineLine.
a_expectedstring

Definition at line 257 of file TestTools.cpp.

References xms::XmLog::GetAndClearStackStr(), xms::Singleton< XmLog >::Instance(), xms::ttAssertStackedErrors(), and xms::ttCheckXmLogForEachTest().

Referenced by xms::ttAssertStackedErrors(), and xms::ttEqualWithinTolerance().

◆ ttByPassDefault()

int xms::ttByPassDefault ( )

Get the default choice when skipping messages.

Returns
The default choice.

Definition at line 214 of file TestTools.cpp.

References xms::ETestMessagingState::GetDefault(), xms::ttByPassDefault(), and xms::ttTestMessagingState().

Referenced by xms::ttByPassDefault().

◆ ttByPassMessages()

void xms::ttByPassMessages ( int  a_defaultChoice)

Bypass the ui elements and just set return value.

Parameters
a_defaultChoiceThe option to use automatically when the user would otherwise be prompted for input.

Definition at line 196 of file TestTools.cpp.

References xms::ETestMessagingState::SetDefault(), xms::ETestMessagingState::SetSkipping(), xms::ttByPassMessages(), and xms::ttTestMessagingState().

Referenced by xms::ttByPassMessages().

◆ ttCheckXmLogForEachTest() [1/2]

void xms::ttCheckXmLogForEachTest ( bool  a_setting)

Set check of XM_LOG before and after each test.

Parameters
a_settingtrue to check.

Definition at line 239 of file TestTools.cpp.

References xms::ttCheckXmLogForEachTest().

Referenced by xms::ttAssertStackedErrors(), and xms::ttCheckXmLogForEachTest().

◆ ttCheckXmLogForEachTest() [2/2]

bool xms::ttCheckXmLogForEachTest ( )

Turn on check of XM_LOG before and after each test.

Returns
true if currently checking.

Definition at line 247 of file TestTools.cpp.

References xms::ttCheckXmLogForEachTest().

◆ ttEqualPointsXY() [1/3]

bool xms::ttEqualPointsXY ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
double  a_tolerance 
)

Returns true if the points are equal to within tolerance.

Parameters
a_x1x of point 1.
a_y1y of point 1.
a_x2x of point 2.
a_y2y of point 2.
a_tolerancea_tolerance.
Returns
true if equal.

Definition at line 478 of file TestTools.cpp.

References xms::ttEqualPointsXY().

Referenced by xms::ttEqualPointsXY(), and xms::ttEqualWithinTolerance().

◆ ttEqualPointsXY() [2/3]

bool xms::ttEqualPointsXY ( const Pt2d a_pt1,
const Pt2d a_pt2,
double  a_tolerance 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
a_pt1Point 1.
a_pt2Point 2.
a_tolerancetolerance.
Returns
true if equal within tolerance.

Definition at line 496 of file TestTools.cpp.

References xms::ttEqualPointsXY(), xms::Pt2< T >::x, and xms::Pt2< T >::y.

◆ ttEqualPointsXY() [3/3]

bool xms::ttEqualPointsXY ( const Pt3d a_pt1,
const Pt3d a_pt2,
double  a_tolerance 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
a_pt1Point 1.
a_pt2Point 2.
a_tolerancetolerance.
Returns
true if equal within tolerance.

Definition at line 507 of file TestTools.cpp.

References xms::ttEqualPointsXY(), xms::Pt3< T >::x, and xms::Pt3< T >::y.

Referenced by xms::ttAssertDeltaPt2d(), and xms::ttAssertDeltaVecPt2d().

◆ ttEqualPointsXYZ() [1/2]

bool xms::ttEqualPointsXYZ ( const Pt3d a_pt1,
const Pt3d a_pt2,
double  a_tolerance 
)

Returns true if the points are equal to within tolerance.

Parameters
a_pt1Point 1.
a_pt2Point 2.
a_tolerancetolerance.
Returns
true if equal within tolerance.

Definition at line 441 of file TestTools.cpp.

References xms::ttEqualPointsXYZ(), xms::Pt3< T >::x, xms::Pt3< T >::y, and xms::Pt3< T >::z.

Referenced by xms::ttEqualPointsXYZ(), and xms::ttEqualWithinTolerance().

◆ ttEqualPointsXYZ() [2/2]

bool xms::ttEqualPointsXYZ ( double  a_x1,
double  a_y1,
double  a_z1,
double  a_x2,
double  a_y2,
double  a_z2,
double  a_tolerance 
)

Returns true if the points are equal to within tolerance.

Parameters
a_x1x of point 1.
a_y1y of point 1.
a_z1z of point 1.
a_x2x of point 2.
a_y2y of point 2.
a_z2z of point 2.
a_tolerancetolerance.
Returns
true if equal.

Definition at line 456 of file TestTools.cpp.

References xms::ttEqualPointsXYZ().

Referenced by xms::ttAssertDeltaPt3d(), and xms::ttAssertDeltaVecPt3d().

◆ ttGetTestFilePaths()

void xms::ttGetTestFilePaths ( const std::string &  a_path,
const std::string &  a_fileBase,
const std::string &  a_extension,
std::string &  a_baseFilePath,
std::string &  a_outFilePath 
)

Get testing base and output file using the compiled for architecture. Checks for appended "MacOsX" for Mac OS X and "64" for 64-bit builds. For example with Mac OS 64-bit build looks for test_baseMacOsX.vtu then if not found test_base64.vtu, then if neither found then uses test_base.vtu.

Parameters
[in]a_pathPath to the file.
[in]a_fileBaseFile name without extension.
[in]a_extensionFile extension.
[out]a_baseFilePathPath to base file.
[out]a_outFilePathPath to output file.

Definition at line 277 of file TestTools.cpp.

References xms::ttGetTestFilePaths().

Referenced by xms::ttEqualWithinTolerance(), and xms::ttGetTestFilePaths().

◆ ttSkippingMessages()

bool xms::ttSkippingMessages ( )

Has ttByPassMessages been called without calling ttClearSkippingMessages.

Returns
true if we are skipping messages.

Definition at line 206 of file TestTools.cpp.

References xms::ETestMessagingState::GetSkipping(), xms::ttSkippingMessages(), and xms::ttTestMessagingState().

Referenced by xms::ttSkippingMessages().

◆ ttStreamsEqual()

void xms::ttStreamsEqual ( const std::string &  a_src,
unsigned int  a_line,
std::istream &  a_strm1,
std::istream &  a_strm2 
)

Returns true if the two streams are equal.

Parameters
[in]a_srcSource code file where this is called from.
[in]a_lineLine in source code file where this is called from.
[in]a_strm1First stream.
[in]a_strm2Second stream.

Definition at line 395 of file TestTools.cpp.

References xms::ttStreamsEqual().

Referenced by xms::ttEqualWithinTolerance(), and xms::ttStreamsEqual().

◆ ttTestMessagingState()

ETestMessagingState & xms::ttTestMessagingState ( )

Get the batch mode singleton.

Returns
Reference to ETestMessagingState

Definition at line 230 of file TestTools.cpp.

References xms::ttTestMessagingState().

Referenced by xms::ttByPassDefault(), xms::ttByPassMessages(), xms::ttClearSkippingMessages(), xms::ttSkippingMessages(), and xms::ttTestMessagingState().

◆ ttTextFilesEqual() [1/2]

bool xms::ttTextFilesEqual ( const std::string &  a_file1,
const std::string &  a_file2,
std::string &  a_message 
)

Returns true if the two files are equal.

Parameters
[in]a_file1Path to first file.
[in]a_file2Path to second file.
[out]a_messageError message if the files aren't equal.
Returns
true if files are equal, else false.

Definition at line 324 of file TestTools.cpp.

References xms::ttTextFilesEqual().

Referenced by xms::ttEqualWithinTolerance(), and xms::ttTextFilesEqual().

◆ ttTextFilesEqual() [2/2]

void xms::ttTextFilesEqual ( const std::string &  a_srcFile,
unsigned  a_line,
const std::string &  a_file1,
const std::string &  a_file2 
)

Returns true if the two files are equal.

Parameters
[in]a_srcFileSource code file where this is called from.
[in]a_lineLine in source code file where this is called from.
[in]a_file1Path to first file.
[in]a_file2Path to second file.

Definition at line 379 of file TestTools.cpp.

References xms::ttTextFilesEqual().