Public Member Functions | Private Member Functions | Private Attributes | List of all members
gnsstk::TestUtil Class Reference

Detailed Description

Definition at line 265 of file TestUtil.hpp.

#include <TestUtil.hpp>

Public Member Functions

void assert (bool testExpression, const std::string &testMsg, const int lineNumber)
 
void assert_binary_files_equal (int lineNumber, const std::string &file1Name, const std::string &file2Name, const std::string &testMsg, unsigned long long from=0, unsigned long long to=-1)
 
template<typename T >
void assert_equals (const gnsstk::Matrix< T > &expected, const gnsstk::Matrix< T > &got, int lineNumber, const std::string &testMsg=std::string(), T epsilon=-1)
 
template<typename T >
void assert_equals (const gnsstk::Vector< T > &expected, const gnsstk::Vector< T > &got, int lineNumber, const std::string &testMsg=std::string(), T epsilon=-1)
 
template<class T >
void assert_equals (const T &expected, const T &got, int lineNumber, const std::string &testMsg=std::string())
 
void assert_equals (double expected, double got, int lineNumber, const std::string &testMsg=std::string(), double epsilon=-1)
 
void assert_equals (float expected, float got, int lineNumber, const std::string &testMsg=std::string(), float epsilon=-1)
 
void assert_equals (long double expected, long double got, int lineNumber, const std::string &testMsg=std::string(), long double epsilon=-1)
 
template<typename T >
void assert_equals_fp (const T &expected, const T &got, int lineNumber, const std::string &testMsg=std::string(), T epsilon=-1)
 
template<typename T >
void assert_equals_fps (const T &expected, const T &got, int lineNumber, const std::string &testMsg=std::string())
 
void assert_files_equal (int lineNumber, const std::string &file1Name, const std::string &file2Name, const std::string &testMsg, int numLinesSkip=0, bool ignoreLeadingSpaces=false, bool ignoreTrailingSpaces=false, std::vector< std::string > ignoreRegex=std::vector< std::string >(0))
 
void changeSourceMethod (const std::string &newMethod)
 
int countFails (void)
 
int countTests (void)
 
bool fileCompTest (const std::string &refFile, const std::string &checkFile, unsigned long long from=0, unsigned long long to=-1)
 
bool fileEqualTest (const std::string &refFile, const std::string &checkFile, int numLinesSkip=0, bool ignoreLeadingSpaces=false, bool ignoreTrailingSpaces=false, std::vector< std::string > ignoreRegex=std::vector< std::string >(0))
 
void setTestLine (const int lineNumber)
 
void setTestMessage (const std::string &testMsg)
 
void setTestMessage (const std::string &testMsg, const int lineNumber)
 
 TestUtil (const std::string &sourceClassInput="Unknown", const std::string &sourceMethodInput="Unknown", const std::string &testFileInput="Unknown", const int &testLineInput=0, const int &verbosityInput=1)
 

Private Member Functions

void fail (const std::string &failMsg)
 
void fail (const std::string &failMsg, const int lineNumber)
 
void fail (void)
 
void next (void)
 
void pass (void)
 
void print (void)
 
void undo (void)
 

Private Attributes

int failBit
 store the result of a test (0=pass, 1=fail) More...
 
int failCount
 Count of tests that have failed. More...
 
std::string outputKeyword
 Identifies a stdout line as a test record from this class. More...
 
std::string sourceClass
 help locate source class causing a test failure More...
 
std::string sourceMethod
 help locate source method causing a test failure More...
 
int subtestID
 ID of the current sub-test, used in TestUtil::print() More...
 
int testCount
 Count of tests that have been run. More...
 
std::string testFileLine
 help locate test line where the failure occured More...
 
std::string testFileName
 help locate test file that discovered a failure More...
 
std::string testMessage
 
int verbosity
 

Constructor & Destructor Documentation

◆ TestUtil()

gnsstk::TestUtil::TestUtil ( const std::string &  sourceClassInput = "Unknown",
const std::string &  sourceMethodInput = "Unknown",
const std::string &  testFileInput = "Unknown",
const int &  testLineInput = 0,
const int &  verbosityInput = 1 
)

Constructor to be called at the start of each test method.

Parameters
[in]sourceClassInputthe name of the source class being tested
[in]sourceMethodInputthe name of the source method being tested
[in]testFileInputthe name of file containing the test code, e.g., FILE
[in]testLineInputthe line number in the file where testing is done, e.g. LINE
[in]verbosityInputthe level of verbosity in the print output, default=1, but set to 0 will supress fail messages

Definition at line 578 of file TestUtil.hpp.

Member Function Documentation

◆ assert()

void gnsstk::TestUtil::assert ( bool  testExpression,
const std::string &  testMsg,
const int  lineNumber 
)

Takes a boolean expression, passes or fails the test, depending on whether the assertion is true or false, and then prints the result.

Parameters
[in]testExpressionBoolean value that is expected to be true.
[in]testMsgA message to be printed on failure.
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.

Definition at line 607 of file TestUtil.hpp.

◆ assert_binary_files_equal()

void gnsstk::TestUtil::assert_binary_files_equal ( int  lineNumber,
const std::string &  file1Name,
const std::string &  file2Name,
const std::string &  testMsg,
unsigned long long  from = 0,
unsigned long long  to = -1 
)

Compare two binary files, byte-by-byte. Test passes if there are no differences in the data.

Parameters
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.
[in]file1NameThe full path to the reference file being compared against.
[in]file2NameThe full path to the test output file to compare to the reference.
[in]testMsgA message to be printed on failure.
[in]fromFirst byte to compare.
[in]toLast byte to compare.

Definition at line 758 of file TestUtil.hpp.

◆ assert_equals() [1/6]

template<typename T >
void gnsstk::TestUtil::assert_equals ( const gnsstk::Matrix< T > &  expected,
const gnsstk::Matrix< T > &  got,
int  lineNumber,
const std::string &  testMsg = std::string(),
epsilon = -1 
)

Takes two matricies, compares them and passes the test if the values are equal within an epsilon.

Parameters
[in]expectedThe expected value to be compared against.
[in]gotThe value produced by the method under test.
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.
[in]testMsgA message to be printed on failure. A default message will simply say what was expected and what the value actually was when expected != got.
[in]epsilonThe maximum difference between expected and got that will be considered "equal". If this number is less than zero, the type's epsilon is used.

Definition at line 698 of file TestUtil.hpp.

◆ assert_equals() [2/6]

template<typename T >
void gnsstk::TestUtil::assert_equals ( const gnsstk::Vector< T > &  expected,
const gnsstk::Vector< T > &  got,
int  lineNumber,
const std::string &  testMsg = std::string(),
epsilon = -1 
)

Definition at line 721 of file TestUtil.hpp.

◆ assert_equals() [3/6]

template<class T >
void gnsstk::TestUtil::assert_equals ( const T &  expected,
const T &  got,
int  lineNumber,
const std::string &  testMsg = std::string() 
)

Takes two values of the same type, compares them and passes the test if the values are equal.

Parameters
[in]expectedThe expected value to be compared against.
[in]gotThe value produced by the method under test.
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.
[in]testMsgA message to be printed on failure. A default message will simply say what was expected and what the value actually was when expected != got.

Definition at line 630 of file TestUtil.hpp.

◆ assert_equals() [4/6]

void gnsstk::TestUtil::assert_equals ( double  expected,
double  got,
int  lineNumber,
const std::string &  testMsg = std::string(),
double  epsilon = -1 
)
inline

Takes two floating point values, compares them and passes the test if the values are equal within an epsilon.

Parameters
[in]expectedThe expected value to be compared against.
[in]gotThe value produced by the method under test.
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.
[in]testMsgA message to be printed on failure. A default message will simply say what was expected and what the value actually was when expected != got.
[in]epsilonThe maximum difference between expected and got that will be considered "equal". If this number is less than zero, the type's epsilon is used.

Definition at line 329 of file TestUtil.hpp.

◆ assert_equals() [5/6]

void gnsstk::TestUtil::assert_equals ( float  expected,
float  got,
int  lineNumber,
const std::string &  testMsg = std::string(),
float  epsilon = -1 
)
inline

Definition at line 343 of file TestUtil.hpp.

◆ assert_equals() [6/6]

void gnsstk::TestUtil::assert_equals ( long double  expected,
long double  got,
int  lineNumber,
const std::string &  testMsg = std::string(),
long double  epsilon = -1 
)
inline

Definition at line 336 of file TestUtil.hpp.

◆ assert_equals_fp()

template<typename T >
void gnsstk::TestUtil::assert_equals_fp ( const T &  expected,
const T &  got,
int  lineNumber,
const std::string &  testMsg = std::string(),
epsilon = -1 
)

Definition at line 649 of file TestUtil.hpp.

◆ assert_equals_fps()

template<typename T >
void gnsstk::TestUtil::assert_equals_fps ( const T &  expected,
const T &  got,
int  lineNumber,
const std::string &  testMsg = std::string() 
)

Smart floating point number comparison taking into account the representable digits in the mantissa and the expected exponent.

Parameters
[in]expectedThe expected value to be compared against.
[in]gotThe value produced by the method under test.
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.
[in]testMsgA message to be printed on failure. A default message will simply say what was expected and what the value actually was when expected != got.

Definition at line 679 of file TestUtil.hpp.

◆ assert_files_equal()

void gnsstk::TestUtil::assert_files_equal ( int  lineNumber,
const std::string &  file1Name,
const std::string &  file2Name,
const std::string &  testMsg,
int  numLinesSkip = 0,
bool  ignoreLeadingSpaces = false,
bool  ignoreTrailingSpaces = false,
std::vector< std::string >  ignoreRegex = std::vector<std::string>(0) 
)

Compare two text files, line-by-line. Test passes if there are no differences according to the rules set by parameters.

Parameters
[in]lineNumberThe line of source in the test file where this assert is being performed, typically LINE.
[in]file1NameThe full path to the reference file being compared against.
[in]file2NameThe full path to the test output file to compare to the reference.
[in]testMsgA message to be printed on failure.
[in]numLinesSkipThe number of lines to ignore in the two files, starting from the beginning.
[in]ignoreLeadingSpacesIf true, changes are ignored between the two files in white space at the beginning of a line.
[in]ignoreTrailingSpacesIf true, changes are ignored between the two files in white space at the end of a line.
[in]ignoreRegexAn optional vector of regular expression strings that, if matched in the SOURCE FILE (i.e. file1name), differences on that line will be ignored.

Definition at line 741 of file TestUtil.hpp.

◆ changeSourceMethod()

void gnsstk::TestUtil::changeSourceMethod ( const std::string &  newMethod)

Change the method, function, or feature of the source class under test in the test output stream.

Parameters
[in]newMethodthe name of the method under test

Definition at line 785 of file TestUtil.hpp.

◆ countFails()

int gnsstk::TestUtil::countFails ( void  )
Returns
the number of tests that have failed so far.

Definition at line 771 of file TestUtil.hpp.

◆ countTests()

int gnsstk::TestUtil::countTests ( void  )
Returns
the number of tests that have been executed so far.

Definition at line 778 of file TestUtil.hpp.

◆ fail() [1/3]

void gnsstk::TestUtil::fail ( const std::string &  failMsg)
private

Fail the test! Record a failure by setting the failBit and incrementing failCount.

Definition at line 1024 of file TestUtil.hpp.

◆ fail() [2/3]

void gnsstk::TestUtil::fail ( const std::string &  failMsg,
const int  lineNumber 
)
private

Fail the test! Record a failure by setting the failBit and incrementing failCount.

Definition at line 1032 of file TestUtil.hpp.

◆ fail() [3/3]

void gnsstk::TestUtil::fail ( void  )
private

Fail the test! Record a failure by setting the failBit and incrementing failCount.

Definition at line 1015 of file TestUtil.hpp.

◆ fileCompTest()

bool gnsstk::TestUtil::fileCompTest ( const std::string &  refFile,
const std::string &  checkFile,
unsigned long long  from = 0,
unsigned long long  to = -1 
)

Compare two binary files for differences, byte by byte.

Parameters
[in]refFileThe reference file to compare against.
[in]checkFileThe generated file being compared.
[in]fromFirst byte to compare.
[in]toLast byte to compare.

Definition at line 919 of file TestUtil.hpp.

◆ fileEqualTest()

bool gnsstk::TestUtil::fileEqualTest ( const std::string &  refFile,
const std::string &  checkFile,
int  numLinesSkip = 0,
bool  ignoreLeadingSpaces = false,
bool  ignoreTrailingSpaces = false,
std::vector< std::string >  ignoreRegex = std::vector<std::string>(0) 
)

Compare two text files for differences, line by line.

Parameters
[in]refFileThe reference file to compare against.
[in]checkFileThe generated file being compared.
[in]numLinesSkipNumber of lines to ignore at the start of each file.
[in]ignoreLeadingSpacesIf true, ignore any changes in whitespace at the beginning of each line.
[in]ignoreTrailingSpacesIf true, ignore any changes in whitespace at the end of each line.
[in]ignoreRegexA vector of POSIX regular expressions that, if matched in refFile, differences in those lines will be ignored. Regular expressions are not matched against checkFile.
Returns
true if the files are equal, false if not.

Definition at line 815 of file TestUtil.hpp.

◆ next()

void gnsstk::TestUtil::next ( void  )
private

Increment the failCount and reset subtestID based on current testCount.

Definition at line 1041 of file TestUtil.hpp.

◆ pass()

void gnsstk::TestUtil::pass ( void  )
private

Pass the test! Record a pass by setting the failBit=0 and incrementing the testCount

Definition at line 1007 of file TestUtil.hpp.

◆ print()

void gnsstk::TestUtil::print ( void  )
private

Print test results and information on classes being tested to stdout in a common format that is both human-readable and easy to filter using tools like grep so as to help isolate where problems are happening.

Definition at line 975 of file TestUtil.hpp.

◆ setTestLine()

void gnsstk::TestUtil::setTestLine ( const int  lineNumber)

Definition at line 806 of file TestUtil.hpp.

◆ setTestMessage() [1/2]

void gnsstk::TestUtil::setTestMessage ( const std::string &  testMsg)

Set the message text that is reported when print() is called, usually a fail message.

Parameters
[in]testMsgthe text to be sent to a log, usually to describe what failed and why.

Definition at line 792 of file TestUtil.hpp.

◆ setTestMessage() [2/2]

void gnsstk::TestUtil::setTestMessage ( const std::string &  testMsg,
const int  lineNumber 
)

Set the message text that is reported when print() is called, usually a fail message.

Parameters
[in]testMsgThe text to be sent to a log, usually to describe what failed and why.
[in]lineNumberThe line number in the test app where pass(), fail(), assert() was called

Definition at line 798 of file TestUtil.hpp.

◆ undo()

void gnsstk::TestUtil::undo ( void  )
private

Undo the test! Undo a pass/fail by unsetting failBit and decrementing failCount (only if failed) and decrementing the testCount.

Definition at line 1053 of file TestUtil.hpp.

Member Data Documentation

◆ failBit

int gnsstk::TestUtil::failBit
private

store the result of a test (0=pass, 1=fail)

Definition at line 530 of file TestUtil.hpp.

◆ failCount

int gnsstk::TestUtil::failCount
private

Count of tests that have failed.

Definition at line 539 of file TestUtil.hpp.

◆ outputKeyword

std::string gnsstk::TestUtil::outputKeyword
private

Identifies a stdout line as a test record from this class.

Definition at line 515 of file TestUtil.hpp.

◆ sourceClass

std::string gnsstk::TestUtil::sourceClass
private

help locate source class causing a test failure

Definition at line 517 of file TestUtil.hpp.

◆ sourceMethod

std::string gnsstk::TestUtil::sourceMethod
private

help locate source method causing a test failure

Definition at line 519 of file TestUtil.hpp.

◆ subtestID

int gnsstk::TestUtil::subtestID
private

ID of the current sub-test, used in TestUtil::print()

Definition at line 538 of file TestUtil.hpp.

◆ testCount

int gnsstk::TestUtil::testCount
private

Count of tests that have been run.

Definition at line 537 of file TestUtil.hpp.

◆ testFileLine

std::string gnsstk::TestUtil::testFileLine
private

help locate test line where the failure occured

Definition at line 523 of file TestUtil.hpp.

◆ testFileName

std::string gnsstk::TestUtil::testFileName
private

help locate test file that discovered a failure

Definition at line 521 of file TestUtil.hpp.

◆ testMessage

std::string gnsstk::TestUtil::testMessage
private

if failBit==1 && verbosity>=1, print this string description of why the test failed to be set by the test app developer

Definition at line 527 of file TestUtil.hpp.

◆ verbosity

int gnsstk::TestUtil::verbosity
private

if verbosity>=0, print summary line; if verbosity>=1, print testMessage when fail() is called.

Definition at line 533 of file TestUtil.hpp.


The documentation for this class was generated from the following file:


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:46