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 |
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.
[in] | sourceClassInput | the name of the source class being tested |
[in] | sourceMethodInput | the name of the source method being tested |
[in] | testFileInput | the name of file containing the test code, e.g., FILE |
[in] | testLineInput | the line number in the file where testing is done, e.g. LINE |
[in] | verbosityInput | the 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.
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.
[in] | testExpression | Boolean value that is expected to be true. |
[in] | testMsg | A message to be printed on failure. |
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
Definition at line 607 of file TestUtil.hpp.
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.
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
[in] | file1Name | The full path to the reference file being compared against. |
[in] | file2Name | The full path to the test output file to compare to the reference. |
[in] | testMsg | A message to be printed on failure. |
[in] | from | First byte to compare. |
[in] | to | Last byte to compare. |
Definition at line 758 of file TestUtil.hpp.
void gnsstk::TestUtil::assert_equals | ( | const gnsstk::Matrix< T > & | expected, |
const gnsstk::Matrix< T > & | got, | ||
int | lineNumber, | ||
const std::string & | testMsg = std::string() , |
||
T | epsilon = -1 |
||
) |
Takes two matricies, compares them and passes the test if the values are equal within an epsilon.
[in] | expected | The expected value to be compared against. |
[in] | got | The value produced by the method under test. |
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
[in] | testMsg | A 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] | epsilon | The 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.
void gnsstk::TestUtil::assert_equals | ( | const gnsstk::Vector< T > & | expected, |
const gnsstk::Vector< T > & | got, | ||
int | lineNumber, | ||
const std::string & | testMsg = std::string() , |
||
T | epsilon = -1 |
||
) |
Definition at line 721 of file TestUtil.hpp.
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.
[in] | expected | The expected value to be compared against. |
[in] | got | The value produced by the method under test. |
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
[in] | testMsg | A 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.
|
inline |
Takes two floating point values, compares them and passes the test if the values are equal within an epsilon.
[in] | expected | The expected value to be compared against. |
[in] | got | The value produced by the method under test. |
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
[in] | testMsg | A 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] | epsilon | The 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.
|
inline |
Definition at line 343 of file TestUtil.hpp.
|
inline |
Definition at line 336 of file TestUtil.hpp.
void gnsstk::TestUtil::assert_equals_fp | ( | const T & | expected, |
const T & | got, | ||
int | lineNumber, | ||
const std::string & | testMsg = std::string() , |
||
T | epsilon = -1 |
||
) |
Definition at line 649 of file TestUtil.hpp.
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.
[in] | expected | The expected value to be compared against. |
[in] | got | The value produced by the method under test. |
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
[in] | testMsg | A 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.
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.
[in] | lineNumber | The line of source in the test file where this assert is being performed, typically LINE. |
[in] | file1Name | The full path to the reference file being compared against. |
[in] | file2Name | The full path to the test output file to compare to the reference. |
[in] | testMsg | A message to be printed on failure. |
[in] | numLinesSkip | The number of lines to ignore in the two files, starting from the beginning. |
[in] | ignoreLeadingSpaces | If true, changes are ignored between the two files in white space at the beginning of a line. |
[in] | ignoreTrailingSpaces | If true, changes are ignored between the two files in white space at the end of a line. |
[in] | ignoreRegex | An 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.
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.
[in] | newMethod | the name of the method under test |
Definition at line 785 of file TestUtil.hpp.
int gnsstk::TestUtil::countFails | ( | void | ) |
Definition at line 771 of file TestUtil.hpp.
int gnsstk::TestUtil::countTests | ( | void | ) |
Definition at line 778 of file TestUtil.hpp.
|
private |
Fail the test! Record a failure by setting the failBit and incrementing failCount.
Definition at line 1024 of file TestUtil.hpp.
Fail the test! Record a failure by setting the failBit and incrementing failCount.
Definition at line 1032 of file TestUtil.hpp.
|
private |
Fail the test! Record a failure by setting the failBit and incrementing failCount.
Definition at line 1015 of file TestUtil.hpp.
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.
[in] | refFile | The reference file to compare against. |
[in] | checkFile | The generated file being compared. |
[in] | from | First byte to compare. |
[in] | to | Last byte to compare. |
Definition at line 919 of file TestUtil.hpp.
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.
[in] | refFile | The reference file to compare against. |
[in] | checkFile | The generated file being compared. |
[in] | numLinesSkip | Number of lines to ignore at the start of each file. |
[in] | ignoreLeadingSpaces | If true, ignore any changes in whitespace at the beginning of each line. |
[in] | ignoreTrailingSpaces | If true, ignore any changes in whitespace at the end of each line. |
[in] | ignoreRegex | A vector of POSIX regular expressions that, if matched in refFile, differences in those lines will be ignored. Regular expressions are not matched against checkFile. |
Definition at line 815 of file TestUtil.hpp.
|
private |
Increment the failCount and reset subtestID based on current testCount.
Definition at line 1041 of file TestUtil.hpp.
|
private |
Pass the test! Record a pass by setting the failBit=0 and incrementing the testCount
Definition at line 1007 of file TestUtil.hpp.
|
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.
void gnsstk::TestUtil::setTestLine | ( | const int | lineNumber | ) |
Definition at line 806 of file TestUtil.hpp.
void gnsstk::TestUtil::setTestMessage | ( | const std::string & | testMsg | ) |
Set the message text that is reported when print() is called, usually a fail message.
[in] | testMsg | the text to be sent to a log, usually to describe what failed and why. |
Definition at line 792 of file TestUtil.hpp.
Set the message text that is reported when print() is called, usually a fail message.
[in] | testMsg | The text to be sent to a log, usually to describe what failed and why. |
[in] | lineNumber | The line number in the test app where pass(), fail(), assert() was called |
Definition at line 798 of file TestUtil.hpp.
|
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.
|
private |
store the result of a test (0=pass, 1=fail)
Definition at line 530 of file TestUtil.hpp.
|
private |
Count of tests that have failed.
Definition at line 539 of file TestUtil.hpp.
|
private |
Identifies a stdout line as a test record from this class.
Definition at line 515 of file TestUtil.hpp.
|
private |
help locate source class causing a test failure
Definition at line 517 of file TestUtil.hpp.
|
private |
help locate source method causing a test failure
Definition at line 519 of file TestUtil.hpp.
|
private |
ID of the current sub-test, used in TestUtil::print()
Definition at line 538 of file TestUtil.hpp.
|
private |
Count of tests that have been run.
Definition at line 537 of file TestUtil.hpp.
|
private |
help locate test line where the failure occured
Definition at line 523 of file TestUtil.hpp.
|
private |
help locate test file that discovered a failure
Definition at line 521 of file TestUtil.hpp.
|
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.
|
private |
if verbosity>=0, print summary line; if verbosity>=1, print testMessage when fail() is called.
Definition at line 533 of file TestUtil.hpp.