![]() |
Utility
|
A Checker is used to compare expected against obtained results for unit testing. More...
#include <Checker.hh>
Public Member Functions | |
bool | check (const std::string &description, const std::ostringstream &expected, const std::ostringstream &obtained) |
Checks the contents of two ostringstream objects. | |
bool | check (bool passed) |
Updates the check accounting. | |
template<typename OBJECT > | |
bool | check (const std::string &description, OBJECT &expected, OBJECT &obtained) |
Checks two objects. | |
bool | check (const std::string &description, long double expected, long double obtained) |
Checks two long double values. | |
bool | check (const std::string &description, const std::string &expected, const std::string &obtained) |
Checks two string objects. | |
bool | check (const std::string &description, unsigned long long expected, unsigned long long obtained) |
Checks two unsigned long long values. | |
bool | check (const std::string &description, long long expected, long long obtained) |
Checks two long long values. | |
bool | check (const std::string &description, unsigned long expected, unsigned long obtained) |
Checks two unsigned long values. | |
bool | check (const std::string &description, long expected, long obtained) |
Checks two long values. | |
bool | check (const std::string &description, unsigned int expected, unsigned int obtained) |
Checks two unsigned int values. | |
bool | check (const std::string &description, int expected, int obtained) |
Checks two int values. | |
bool | check (const std::string &description, unsigned short expected, unsigned short obtained) |
Checks two short unsigned short. | |
bool | check (const std::string &description, short expected, short obtained) |
Checks two short values. | |
bool | check (const std::string &description, bool expected, bool obtained) |
Checks two bool values. | |
bool | check (const std::string &description, void *expected, void *obtained) |
Checks two addresses. | |
bool | check (const std::string &description, std::string &expected, std::string &obtained) |
Checks two string objects. | |
bool | check (const std::string &description, double expected, double obtained) |
Checks two double values. | |
bool | check (const std::string &description, std::ostringstream &expected, std::ostringstream &obtained) |
Checks the contents of two ostringstream objects. | |
Checker () | |
Public Attributes | |
int | Checks_Passed |
Total number of Checks where expected matched obtained. | |
int | Checks_Total |
Total number of Checks performed. | |
bool | Compare_Equals |
Set to true to have default comparison be ==. | |
bool | Reset_Values |
Set to true to reset (clear) the expected and obtained values when possible. | |
bool | Verbose |
Set to true to always show both the expected and obtained values. | |
Static Public Attributes | |
static const char *const | ID |
Class identification name with source code version and date. |
A Checker is used to compare expected against obtained results for unit testing.
Each check function compares the expected against the obtained. The comparison is equality (==) if Compare_Equals is true, otherwise the comparison is inequality (!=).
A message line is printed to cout of the form:
PASS|FAIL: <description>
where "PASS" is used if the comparison is true, "FAIL" otherwise.
If the comparison is false, or Verbose is true, the expected and obtained values are printed on the following lines:
====> expected|obtained [<length>:<NL>]: <expected>|<obtained>
For strings, and the strings contained in ostringstreams, their length is listed and they are started on a new line.
N.B.: The contents of string and ostringstream arguments are reset after use if the arguments are not const values and Reset_Values is true (the default).
Each function returns the result of the comparison.
Checker | ( | ) |
bool check | ( | const std::string & | description, |
const std::ostringstream & | expected, | ||
const std::ostringstream & | obtained | ||
) |
Checks the contents of two ostringstream objects.
N.B.: The expected and obtained results are const values so they will not be reset to empty regardles of the value of Reset_Values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
Referenced by Checker::check().
bool check | ( | const std::string & | description, |
std::ostringstream & | expected, | ||
std::ostringstream & | obtained | ||
) |
Checks the contents of two ostringstream objects.
N.B.: The expected and obtained results will be reset to empty if Reset_Values is true.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
const std::string & | expected, | ||
const std::string & | obtained | ||
) |
Checks two string objects.
N.B.: The expected and obtained results are const values so they will not be reset to empty regardles of the value of Reset_Values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
std::string & | expected, | ||
std::string & | obtained | ||
) |
Checks two string objects.
N.B.: The expected and obtained results will be reset to empty if Reset_Values is true.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
void * | expected, | ||
void * | obtained | ||
) |
Checks two addresses.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
bool | expected, | ||
bool | obtained | ||
) |
Checks two bool values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
short | expected, | ||
short | obtained | ||
) |
Checks two short values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
unsigned short | expected, | ||
unsigned short | obtained | ||
) |
Checks two short unsigned short.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
int | expected, | ||
int | obtained | ||
) |
Checks two int values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
unsigned int | expected, | ||
unsigned int | obtained | ||
) |
Checks two unsigned int values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
long | expected, | ||
long | obtained | ||
) |
Checks two long values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
unsigned long | expected, | ||
unsigned long | obtained | ||
) |
Checks two unsigned long values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
long long | expected, | ||
long long | obtained | ||
) |
Checks two long long values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
unsigned long long | expected, | ||
unsigned long long | obtained | ||
) |
Checks two unsigned long long values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
double | expected, | ||
double | obtained | ||
) |
Checks two double values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
long double | expected, | ||
long double | obtained | ||
) |
Checks two long double values.
description | A brief description of what is being checked. |
expected | The expected result. |
obtained | The obtained result. |
bool check | ( | const std::string & | description, |
OBJECT & | expected, | ||
OBJECT & | obtained | ||
) | [inline] |
Checks two objects.
The objects being checked must provide operator== and operator<< methods. The results of operator== will determine if the check passes (true) or fails (false). If the test fails or Verbose is true operator<< will be used to list each OBJECT to cout (stdout).
description | A brief description of what is being checked. |
expected | The expected OBJECT. |
obtained | The obtained OBJECT. |
References Checker::check(), and Checker::Verbose.
bool check | ( | bool | passed | ) |
Updates the check accounting.
The Checks_Total accumulator is incremented. The Checks_Passed accumulator is incremented if passed is true.
passed | true if the external test passed; false otherwise. |
const char* const ID [static] |
Class identification name with source code version and date.
int Checks_Total |
Total number of Checks performed.
int Checks_Passed |
Total number of Checks where expected matched obtained.
bool Verbose |
Set to true to always show both the expected and obtained values.
Referenced by Checker::check().
bool Compare_Equals |
Set to true to have default comparison be ==.
bool Reset_Values |
Set to true to reset (clear) the expected and obtained values when possible.