Class ExpectedCall

Class Documentation

class ExpectedCall
[source]

Abstract fluent interface for configuring a single call expectation.

Each method returns *this for chaining. Concrete implementations are created internally by Support. See also ActualCall.

Public Functions

ExpectedCall() = default
[source]
virtual ~ExpectedCall() = default
[source]
virtual ExpectedCall &with_name(StringView name) = 0

Set the expected function name.

Parameters:

name – Function name.

Returns:

*this.

virtual ExpectedCall &with_call_order(unsigned int order) = 0

Require this call to happen at a specific position in call order.

Parameters:

order – Expected call order index.

Returns:

*this for chaining.

virtual ExpectedCall &with_call_order(unsigned int min_order, unsigned int max_order) = 0

Require this call to happen within a range of call order positions.

Parameters:
  • min_order – Earliest acceptable order index.

  • max_order – Latest acceptable order index.

Returns:

*this for chaining.

template<typename T>
inline ExpectedCall &with_parameter(StringView name, T value)

Constrain a parameter of any supported type.

The template creates a NamedValue and passes it to the single with_typed_parameter() virtual method. Overload resolution for NamedValue::set_value() selects the correct storage type.

Template Parameters:

T – Parameter type (deduced).

Parameters:
  • name – Parameter name, must match what the mock implementation reports.

  • value – Expected parameter value.

Returns:

*this for chaining.

inline ExpectedCall &with_parameter(StringView name, double value, double tolerance)

Constrain a double parameter with an explicit tolerance.

Parameters:
  • name – Parameter name.

  • value – Expected double value.

  • tolerance – Maximum allowed absolute difference from value.

Returns:

*this for chaining.

inline ExpectedCall &with_parameter(StringView name, const unsigned char *value, size_t size)

Constrain a memory buffer parameter.

Parameters:
  • name – Parameter name.

  • value – Pointer to the expected buffer content.

  • size – Number of bytes to compare.

Returns:

*this for chaining.

virtual ExpectedCall &with_typed_parameter(NamedValue parameter) = 0

Type-erased virtual entry point for parameter constraints.

All non-virtual with_parameter() overloads delegate here after constructing a NamedValue. Subclasses override this single method instead of one method per type.

Parameters:

parameter – Named, typed parameter value.

Returns:

*this for chaining.

virtual ExpectedCall &with_parameter_of_type(StringView type_name, StringView name, const void *value) = 0

Constrain an object parameter identified by a type name string.

Uses the NamedValueComparator installed for type_name to compare the expected value against the actual call’s parameter.

Parameters:
  • type_name – Type name; must match the comparator key and the actual call.

  • name – Parameter name.

  • value – Const pointer to the expected object.

Returns:

*this for chaining.

virtual ExpectedCall &with_output_parameter_returning(StringView name, const void *value, size_t size) = 0

Configure an output parameter: the framework will copy value into the caller’s buffer when the actual call reports this parameter.

Parameters:
  • name – Parameter name.

  • value – Pointer to the data to copy out (plain memcpy).

  • size – Number of bytes to copy.

Returns:

*this for chaining.

virtual ExpectedCall &with_output_parameter_of_type_returning(StringView type_name, StringView name, const void *value) = 0

Configure an output parameter for a custom object type.

Uses the NamedValueCopier installed for type_name to copy the object into the caller’s buffer.

Parameters:
  • type_name – Type name; must match the copier key.

  • name – Parameter name.

  • value – Pointer to the expected object to copy out.

Returns:

*this for chaining.

virtual ExpectedCall &with_unmodified_output_parameter(StringView name) = 0

Expect an output parameter to be passed but leave the buffer unmodified.

Parameters:

name – Parameter name.

Returns:

*this for chaining.

virtual ExpectedCall &ignore_other_parameters() = 0
[source]

Allow the actual call to pass parameters not listed in this expectation.

By default every parameter must be explicitly listed.

Returns:

*this for chaining.

template<typename T>
inline ExpectedCall &and_return_value(T value)

Configure the return value the mock will produce.

The template creates a NamedValue and passes it to the single and_return_typed_value() virtual method.

Template Parameters:

T – Return value type (deduced).

Parameters:

value – Value to return when this expectation is matched.

Returns:

*this for chaining.

virtual ExpectedCall &and_return_typed_value(NamedValue value) = 0

Type-erased virtual entry point for return-value configuration.

All non-virtual and_return_value() overloads delegate here after constructing a NamedValue. Subclasses override this single method instead of one method per type.

Parameters:

value – Named return value.

Returns:

*this for chaining.

virtual ExpectedCall &on_object(void *object_ptr) = 0

Restrict this expectation to calls made on a specific object.

Only an actual call that reports the same object_ptr via ActualCall::on_object() will match this expectation.

Parameters:

object_ptr – Pointer to the expected object instance.

Returns:

*this for chaining.