Class FunctionComparator

Inheritance Relationships

Base Type

Class Documentation

class FunctionComparator : public mu::tiny::mock::NamedValueComparator
[source]

NamedValueComparator backed by plain function pointers.

Convenient alternative to subclassing when you want to keep comparator logic in standalone functions.

Public Types

using IsEqualFunction = bool (*)(const void*, const void*)

Function type for the equality predicate.

using ValueToStringFunction = String (*)(const void*)

Function type for the string-conversion function.

Public Functions

inline FunctionComparator(IsEqualFunction equal, ValueToStringFunction val_to_string)

Construct from two plain function pointers.

Parameters:
  • equal – Equality predicate.

  • val_to_string – String-conversion function.

inline virtual bool is_equal(const void *object1, const void *object2) override

Return true if object1 and object2 are equal.

Both pointers point to objects of the type associated with this comparator.

Parameters:
  • object1 – Pointer to the first object (typically the expected value).

  • object2 – Pointer to the second object (typically the actual value).

Returns:

true if the two objects are considered equal.

inline virtual String value_to_string(const void *object) override

Return a human-readable string representation of object.

Used by the failure reporter to generate “expected X but got Y” output.

Parameters:

object – Pointer to an object of the associated type.

Returns:

Display string.