micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
Operators

Overloaded operators. More...

Functions

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator and (const Lhs_T &lhs, const Rhs_T &rhs)
 Logical && (and) operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class T , type_traits::requires_t< type_traits::is_op_v< T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator not (const T &t)
 Logical ! (not) operator. It matches only if the operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator or (const Lhs_T &lhs, const Rhs_T &rhs)
 Logical || (or) operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator!= (const Lhs_T &lhs, const Rhs_T &rhs)
 Non-equality operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator< (const Lhs_T &lhs, const Rhs_T &rhs)
 Less than operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator<= (const Lhs_T &lhs, const Rhs_T &rhs)
 Less than or equal operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator== (const Lhs_T &lhs, const Rhs_T &rhs)
 Equality operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator> (const Lhs_T &lhs, const Rhs_T &rhs)
 Greater than operator. It matches only if at least one operand is of local type (derived from local op).
 
template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator>= (const Lhs_T &lhs, const Rhs_T &rhs)
 Greater than or equal operator. It matches only if at least one operand is of local type (derived from local op).
 

Detailed Description

Overloaded operators.

As in most other C++ test frameworks, it is also possible to overload the ==, !=, <, >, <=, >= operators.

To avoid possible interferences with other operators defined by the application, these operators match only for operands of specific types and are located in a separate namespace (micro_test_plus::operators); when applied to regular values, the standard operands are used; the comparisons are performed properly, but in case of failures the actual values are not shown.

The operators match only operands derived from the local detail::op type, which can be enforced for constant values by using the provided literals (like 1_i) or, for dynamic values, by using the provided casts (like _i {expression}, which are actually the constructors of the internal classes).

Examples
mt::test_case ("Operators", [] {
using namespace micro_test_plus::operators;
using namespace micro_test_plus::literals;
mt::expect (compute_answer () == 42_i) << "answer is 42 (with literal)";
mt::expect (mt::to_i {compute_answer ()} == 42) << "answer is 42 (with cast)";
mt::expect (compute_answer () != 43_i) << "answer is not 43";
mt::expect (compute_answer () < 43_i) << "answer is < 43";
mt::expect (compute_answer () <= 43_i) << "answer is <= 42";
mt::expect (compute_answer () > 41_i) << "answer is > 43";
mt::expect (compute_answer () >= 42_i) << "answer is >= 42";
});

Logical operators

The logical operators can be used in exactly the same way as standard operators, but the additional functionality is enabled only when matching the typed operands.

Example
mt::expect (compute_answer () == 42_i && compute_float () == 42.0_f);

Function Documentation

◆ operator and()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator and ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Logical && (and) operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 646 of file micro-test-plus.h.

◆ operator not()

template<class T , type_traits::requires_t< type_traits::is_op_v< T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator not ( const T & t)
constexpr

Logical ! (not) operator. It matches only if the operand is of local type (derived from local op).

Definition at line 673 of file micro-test-plus.h.

◆ operator or()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator or ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Logical || (or) operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 661 of file micro-test-plus.h.

◆ operator!=()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator!= ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Non-equality operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 571 of file micro-test-plus.h.

◆ operator<()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator< ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Less than operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 615 of file micro-test-plus.h.

◆ operator<=()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator<= ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Less than or equal operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 630 of file micro-test-plus.h.

◆ operator==()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator== ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Equality operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 556 of file micro-test-plus.h.

◆ operator>()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator> ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Greater than operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 586 of file micro-test-plus.h.

◆ operator>=()

template<class Lhs_T , class Rhs_T , type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator>= ( const Lhs_T & lhs,
const Rhs_T & rhs )
constexpr

Greater than or equal operator. It matches only if at least one operand is of local type (derived from local op).

Definition at line 601 of file micro-test-plus.h.