The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::SpartaTester Class Reference

A simple testing class. More...

#include <SpartaTester.hpp>

Public Member Functions

bool expectAllReached (uint32_t expected_reached, const uint32_t line, const char *file)
 
bool expect (bool val, const char *test_type, const uint32_t line, const char *file)
 
bool expectEqual (uint8_t v1, uint8_t v2, bool expected, const char *test_type, const uint32_t line, const char *file)
 
template<typename T >
bool expectEqual (const T &v1, const T &v2, bool expected, const char *test_type, const uint32_t line, const char *file)
 
template<typename T , typename U = T>
bool expectEqual (const T &v1, const U &v2, bool expected, const char *test_type, const uint32_t line, const char *file)
 
template<typename T , typename U >
std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value &&(std::is_signed< T >::value!=std::is_signed< U >::value), bool >::type compare (const T &t, const U &u)
 
template<typename T , typename U >
std::enable_if<!(std::is_integral< T >::value &&std::is_integral< U >::value &&(std::is_signed< T >::value!=std::is_signed< U >::value)), bool >::type compare (const T &t, const U &u)
 
template<typename T >
bool expectEqual (const T &v1, const std::nullptr_t, bool expected, const char *test_type, const uint32_t line, const char *file)
 
template<typename T >
bool expectEqual (const std::nullptr_t, const T &v1, bool expected, const char *test_type, const uint32_t line, const char *file)
 
template<typename T >
std::enable_if< std::is_floating_point< T >::value, bool >::type expectEqualWithinTolerance (const T &v1, const T &v2, const T &tol, const char *test_type, const uint32_t line, const char *file)
 
void throwTestFailed (const char *test_type, const uint32_t line, const char *file, const char *exception_what="")
 
void expectFilesEqual (const std::string &a, const std::string &b, bool expected, uint32_t line, const char *file, const bool ignore_commented_lines=true)
 Compares two files.
 
void fileComparisonFailed (const std::string &a, const std::string &b, const uint32_t line, const char *file, const std::string &error)
 
void reachedMethod (const std::string &method_title)
 

Static Public Member Functions

static SpartaTestergetInstance ()
 
static std::unique_ptr< SpartaTestermakeTesterWithUserCError (std::ostream &cerr)
 
static uint32_t getErrorCode (const SpartaTester *tester=getInstance())
 

Detailed Description

A simple testing class.

The user of this framework should not have to instantiate this class directly. You can if you want to, but you should use the TEST_INIT macro.

Example usage:

int main() {
EXPECT_TRUE(true);
EXPECT_FALSE(false);
EXPECT_NOTHROW(int a = 3;);
EXPECT_THROW(throw a;);
EXPECT_EQUAL(2+2, 4);
EXPECT_NOTEQUAL(p, nullptr) // Given: Thingy* p;
return ERROR_CODE;
}
#define EXPECT_FALSE(x)
Determine if the block x evaluates to false.
#define EXPECT_NOTHROW(x)
Determine if the block x throws an exception incorrectly.
#define EXPECT_NOTEQUAL(x, y)
Determine if the block x is not equal (using operator= on x) to y.
#define EXPECT_TRUE(x)
Determine if the block x evaluates to true.
#define EXPECT_EQUAL(x, y)
Determine if the block x is equal (using operator= on x) to y.
#define TEST_INIT
Initialized the test. Should be placed OUTSIDE of a code block SOMEWHERE in the test source.
#define EXPECT_THROW(x)
Determine if the block x correctly throws an exception.
#define REPORT_ERROR
Prints the error code with a nice pretty message.
#define ERROR_CODE
The number of errors found in the testing.

Definition at line 51 of file SpartaTester.hpp.

Constructor & Destructor Documentation

◆ SpartaTester()

sparta::SpartaTester::SpartaTester ( )
inline

Definition at line 54 of file SpartaTester.hpp.

Member Function Documentation

◆ compare() [1/2]

template<typename T , typename U >
std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value &&(std::is_signed< T >::value!=std::is_signed< U >::value), bool >::type sparta::SpartaTester::compare ( const T &  t,
const U &  u 
)
inline

Definition at line 155 of file SpartaTester.hpp.

◆ compare() [2/2]

template<typename T , typename U >
std::enable_if<!(std::is_integral< T >::value &&std::is_integral< U >::value &&(std::is_signed< T >::value!=std::is_signed< U >::value)), bool >::type sparta::SpartaTester::compare ( const T &  t,
const U &  u 
)
inline

Definition at line 164 of file SpartaTester.hpp.

◆ expect()

bool sparta::SpartaTester::expect ( bool  val,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 80 of file SpartaTester.hpp.

◆ expectAllReached()

bool sparta::SpartaTester::expectAllReached ( uint32_t  expected_reached,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 57 of file SpartaTester.hpp.

◆ expectEqual() [1/5]

template<typename T >
bool sparta::SpartaTester::expectEqual ( const std::nullptr_t  ,
const T &  v1,
bool  expected,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 191 of file SpartaTester.hpp.

◆ expectEqual() [2/5]

template<typename T >
bool sparta::SpartaTester::expectEqual ( const T &  v1,
const std::nullptr_t  ,
bool  expected,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 171 of file SpartaTester.hpp.

◆ expectEqual() [3/5]

template<typename T >
bool sparta::SpartaTester::expectEqual ( const T &  v1,
const T &  v2,
bool  expected,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 112 of file SpartaTester.hpp.

◆ expectEqual() [4/5]

template<typename T , typename U = T>
bool sparta::SpartaTester::expectEqual ( const T &  v1,
const U &  v2,
bool  expected,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 132 of file SpartaTester.hpp.

◆ expectEqual() [5/5]

bool sparta::SpartaTester::expectEqual ( uint8_t  v1,
uint8_t  v2,
bool  expected,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 92 of file SpartaTester.hpp.

◆ expectEqualWithinTolerance()

template<typename T >
std::enable_if< std::is_floating_point< T >::value, bool >::type sparta::SpartaTester::expectEqualWithinTolerance ( const T &  v1,
const T &  v2,
const T &  tol,
const char *  test_type,
const uint32_t  line,
const char *  file 
)
inline

Definition at line 213 of file SpartaTester.hpp.

◆ expectFilesEqual()

void sparta::SpartaTester::expectFilesEqual ( const std::string &  a,
const std::string &  b,
bool  expected,
uint32_t  line,
const char *  file,
const bool  ignore_commented_lines = true 
)
inline

Compares two files.

Parameters
afilename 1
bfilename 2
expectedExpected file equality. true expects files to match,
ignore_commented_linesDo not compare text for lines that begin with '#' false expects differences.
Postcondition
Generates a test error if any of the following conditions are true
  • Either file cannot be opened
  • Files differ in length and exptected=true with the exception of lines starting with '#'
  • Files differ at any position and expected=true with the exception of lines starting with '#'
  • Files are same length and each char is identical and expected=false
Exceptions
Doesnot throw

Tracks line and col positions for error printouts. Newlines mode is always '
'.

Definition at line 268 of file SpartaTester.hpp.

◆ fileComparisonFailed()

void sparta::SpartaTester::fileComparisonFailed ( const std::string &  a,
const std::string &  b,
const uint32_t  line,
const char *  file,
const std::string &  error 
)
inline

Definition at line 368 of file SpartaTester.hpp.

◆ getErrorCode()

static uint32_t sparta::SpartaTester::getErrorCode ( const SpartaTester tester = getInstance())
inlinestatic

Definition at line 389 of file SpartaTester.hpp.

◆ getInstance()

static SpartaTester * sparta::SpartaTester::getInstance ( )
inlinestatic

Definition at line 380 of file SpartaTester.hpp.

◆ makeTesterWithUserCError()

static std::unique_ptr< SpartaTester > sparta::SpartaTester::makeTesterWithUserCError ( std::ostream &  cerr)
inlinestatic

Definition at line 385 of file SpartaTester.hpp.

◆ reachedMethod()

void sparta::SpartaTester::reachedMethod ( const std::string &  method_title)
inline

Definition at line 376 of file SpartaTester.hpp.

◆ throwTestFailed()

void sparta::SpartaTester::throwTestFailed ( const char *  test_type,
const uint32_t  line,
const char *  file,
const char *  exception_what = "" 
)
inline

Definition at line 239 of file SpartaTester.hpp.


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