Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods Faking overloaded methods

Faking overloaded methods

Top  Previous  Next

Public Methods:

 

By default, using WHEN_CALLED(function) will work on all overloads of a function, so there is no special handling needed.

 

 

Non Public Methods:

 

In order to fake non public overloaded methods, specify an overloaded method by passing the types of the arguments using TYPEOF(Type) macro.

 

Examples:

 

class Person

{

private:

   bool CanPing();

   bool CanPing(bool force);

};

 

To fake CanPing(boolof class Person, use the following statement

 

 

PRIVATE_WHEN_CALLED(person, CanPing, TYPEOF(bool)).Return(true);

 

 

To fake CanPing() of class Person, use the following statement

 

 

PRIVATE_WHEN_CALLED(person, CanPing).Return(true);

 

 

To fake CanPing(bool) for specific arguments, use the IS<> macro instead of TYPEOF and pass the matching arguments predicate:

 

PRIVATE_WHEN_CALLED(person, CanPing, IS<bool>([](bool isVal){ return isVal; })).Return(true);

 

Note: Using the IS<> macro also specifies the types of the arguments.

 

 

Static Methods:

 

To fake static member pass _ as the first argument as follows

 

class House

{

private:

   static bool CanRing();

   static bool CanRing(bool now);

};

 

To fake static CanRing(boolof class House, use the following statement

 

 

PRIVATE_WHEN_CALLED(_, House::CanRing, TYPEOF(bool)).Return(true);

 

 


Copyright  Typemock Ltd. 2009-2023.  All Rights Reserved.