MQLUNIT
Static Public Member Functions | List of all members
MQLUNIT_Assert Class Reference

A set of assert methods. More...

Static Public Member Functions

template<typename T >
static string assertEquals (string message, T &expected, T &actual)
 Asserts that two objects are equal. Object are passed by reference. Pointers must be dereferenced to objects before passed to this method, therefore they must be checked for NULL before checking for equality. More...
 
template<typename T >
static string assertEquals (string message, T expected, T actual)
 Asserts that two entities are equal. More...
 
template<typename T >
static string assertEquals (const string message, const T &expected[], const T &actual[])
 Assert that two arrays are equal. Arrays are considered equal if they have the same size and their elements are equal in each position. Equality check for the elements will work with primitive types, strings, object references and pointers. More...
 
template<typename T >
static string assertSame (string message, T &expected, T &actual)
 Asserts that two object references refer to the same object. Object are passed by reference. Pointers must be dereferenced to objects before passed to this method, therefore they must be checked for NULL before checking for equality. More...
 
template<typename T >
static string assertNotSame (string message, T &expected, T &actual)
 Asserts that two object references do bot refer to the same object. Object are passed by reference. Pointers must be dereferenced to objects before passed to this method, therefore they must be checked for NULL before checking for equality. More...
 
template<typename T >
static string assertNotNull (string message, T entity)
 Asserts that the entity is not NULL. Entity can be a variable of a primitive type, object reference or a pointer. More...
 
template<typename T >
static string assertNull (string message, T entity)
 Asserts that the entity is NULL. Entity can be a variable of a primitive type, object reference or a pointer. More...
 
static string assertTrue (string message, bool condition)
 Asserts that the condition is true. More...
 
static string assertEqualsDelta (string message, double expected, double actual, double delta)
 Asserts that two doubles are equal concerning a delta. More...
 
static string assertFalse (string message, bool condition)
 Asserts that the condition is false. More...
 
static string fail ()
 Fail the test providing a genertc failure description. More...
 
static string fail (string message)
 Fail the test providing a specific failure description. More...
 
static string getMessage (const string message)
 Helper function made public for code reuse. More...
 
template<typename T >
static string assertEquals (string message, T &expected, T &actual)
 
template<typename T >
static string assertNotNull (string message, T entity)
 
template<typename T >
static string assertNull (string message, T entity)
 
template<typename T >
static string assertSame (string message, T &expected, T &actual)
 
template<typename T >
static string assertNotSame (string message, T &expected, T &actual)
 
template<typename T >
static string assertEquals (string message, const T &expected[], const T &actual[])
 
template<typename T >
static string assertArrayElement (string message, T &expected, T &actual, uint i)
 

Detailed Description

A set of assert methods.

Due to the absence of exceptions in MQL the following convention is used to specify an assertion error. Each assertion function will return a NULL string in case of a success and the detailed failure description in case of an assertion failure.

Member Function Documentation

◆ assertArrayElement()

template<typename T >
static string MQLUNIT_Assert::assertArrayElement ( string  message,
T &  expected,
T &  actual,
uint  i 
)
static

◆ assertEquals() [1/5]

template<typename T >
static string MQLUNIT_Assert::assertEquals ( string  message,
T &  expected,
T &  actual 
)
static

Asserts that two objects are equal. Object are passed by reference. Pointers must be dereferenced to objects before passed to this method, therefore they must be checked for NULL before checking for equality.

Parameters
message: assertion description
expected: expected object
actual: actual object
Returns
NULL on success or the failure description
See also
MQLUNIT_Assert::assertNull

◆ assertEquals() [2/5]

template<typename T >
static string MQLUNIT_Assert::assertEquals ( string  message,
expected,
actual 
)
inlinestatic

Asserts that two entities are equal.

Parameters
message: assertion description
expected: expected value
actual: actual value
Returns
NULL on success or the failure description

◆ assertEquals() [3/5]

template<typename T >
static string MQLUNIT_Assert::assertEquals ( const string  message,
const T &  expected[],
const T &  actual[] 
)
static

Assert that two arrays are equal. Arrays are considered equal if they have the same size and their elements are equal in each position. Equality check for the elements will work with primitive types, strings, object references and pointers.

Parameters
expected: expected array
actual: actual array
message: assertion description
Returns
NULL on success or the failure description

◆ assertEquals() [4/5]

template<typename T >
static string MQLUNIT_Assert::assertEquals ( string  message,
T &  expected,
T &  actual 
)
static

◆ assertEquals() [5/5]

template<typename T >
static string MQLUNIT_Assert::assertEquals ( string  message,
const T &  expected[],
const T &  actual[] 
)
static

◆ assertEqualsDelta()

static string MQLUNIT_Assert::assertEqualsDelta ( string  message,
double  expected,
double  actual,
double  delta 
)
static

Asserts that two doubles are equal concerning a delta.

Parameters
message: assertion description
expected: expected value
actual: actual value
delta: allowed error
Returns
NULL on success or the failure description

◆ assertFalse()

static string MQLUNIT_Assert::assertFalse ( string  message,
bool  condition 
)
static

Asserts that the condition is false.

Parameters
message: assertion description
condition: boolean expression to check
Returns
NULL on success or the failure description

◆ assertNotNull() [1/2]

template<typename T >
static string MQLUNIT_Assert::assertNotNull ( string  message,
entity 
)
static

Asserts that the entity is not NULL. Entity can be a variable of a primitive type, object reference or a pointer.

Parameters
entity: variable, object reference or a pointer to check
message: assertion description
Returns
NULL on success or the failure description

◆ assertNotNull() [2/2]

template<typename T >
static string MQLUNIT_Assert::assertNotNull ( string  message,
entity 
)
static

◆ assertNotSame() [1/2]

template<typename T >
static string MQLUNIT_Assert::assertNotSame ( string  message,
T &  expected,
T &  actual 
)
static

Asserts that two object references do bot refer to the same object. Object are passed by reference. Pointers must be dereferenced to objects before passed to this method, therefore they must be checked for NULL before checking for equality.

Parameters
expected: expected object
actual: actual object
message: assertion description
Returns
NULL on success or the failure description

◆ assertNotSame() [2/2]

template<typename T >
static string MQLUNIT_Assert::assertNotSame ( string  message,
T &  expected,
T &  actual 
)
static

◆ assertNull() [1/2]

template<typename T >
static string MQLUNIT_Assert::assertNull ( string  message,
entity 
)
static

Asserts that the entity is NULL. Entity can be a variable of a primitive type, object reference or a pointer.

Parameters
entity: variable, object reference or a pointer to check
message: assertion description
Returns
NULL on success or the failure description

◆ assertNull() [2/2]

template<typename T >
static string MQLUNIT_Assert::assertNull ( string  message,
entity 
)
static

◆ assertSame() [1/2]

template<typename T >
static string MQLUNIT_Assert::assertSame ( string  message,
T &  expected,
T &  actual 
)
static

Asserts that two object references refer to the same object. Object are passed by reference. Pointers must be dereferenced to objects before passed to this method, therefore they must be checked for NULL before checking for equality.

Parameters
expected: expected object
actual: actual object
message: assertion description
Returns
NULL on success or the failure description

◆ assertSame() [2/2]

template<typename T >
static string MQLUNIT_Assert::assertSame ( string  message,
T &  expected,
T &  actual 
)
static

◆ assertTrue()

static string MQLUNIT_Assert::assertTrue ( string  message,
bool  condition 
)
static

Asserts that the condition is true.

Parameters
message: assertion description
condition: boolean expression to check
Returns
NULL on success or the failure description

◆ fail() [1/2]

static string MQLUNIT_Assert::fail ( )
inlinestatic

Fail the test providing a genertc failure description.

Returns
Generic failure description ("Assertion failed")

◆ fail() [2/2]

static string MQLUNIT_Assert::fail ( string  message)
inlinestatic

Fail the test providing a specific failure description.

Parameters
message: failure description
Returns
Failure description (always not NULL)

◆ getMessage()

static string MQLUNIT_Assert::getMessage ( const string  message)
static

Helper function made public for code reuse.

Not a part of the API. Maybe removed at any time.

Note
Since MQL doesn't suport friend classes, we are forced to make some "private" helper methods "public" to avoid copying and pasting the same code to multiple classes.

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

Copyright © 2017 Eneset Group Trust