idaeim studio
 Utility

Public Member Functions | Public Attributes | Static Public Attributes
Checker Class Reference

A Checker is used to compare expected against obtained results for unit testing. More...

#include <Checker.hh>

List of all members.

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.

Detailed Description

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.

Author:
Bradford Castalia
Version:
1.21

Constructor & Destructor Documentation

Checker ( )

Member Function Documentation

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.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.

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.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
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.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
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.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
void *  expected,
void *  obtained 
)

Checks two addresses.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
bool  expected,
bool  obtained 
)

Checks two bool values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
short  expected,
short  obtained 
)

Checks two short values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
unsigned short  expected,
unsigned short  obtained 
)

Checks two short unsigned short.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
int  expected,
int  obtained 
)

Checks two int values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
unsigned int  expected,
unsigned int  obtained 
)

Checks two unsigned int values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
long  expected,
long  obtained 
)

Checks two long values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
unsigned long  expected,
unsigned long  obtained 
)

Checks two unsigned long values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
long long  expected,
long long  obtained 
)

Checks two long long values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
unsigned long long  expected,
unsigned long long  obtained 
)

Checks two unsigned long long values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
double  expected,
double  obtained 
)

Checks two double values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
bool check ( const std::string &  description,
long double  expected,
long double  obtained 
)

Checks two long double values.

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected result.
obtainedThe obtained result.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.
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).

Parameters:
descriptionA brief description of what is being checked.
expectedThe expected OBJECT.
obtainedThe obtained OBJECT.
Returns:
true if the check passed; false otherwise. The check accumulators will be updated accordingly.

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.

Parameters:
passedtrue if the external test passed; false otherwise.
Returns:
The passed value.

Member Data Documentation

const char* const ID [static]

Class identification name with source code version and date.

Total number of Checks performed.

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().

Set to true to have default comparison be ==.

Set to true to reset (clear) the expected and obtained values when possible.


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