Faking overloaded methods |
Top Previous Next |
Public Methods:
By default, when you call CallTo(function), it works on the specific overloaded function you mention in the call. Isolator++ handles method overloading based on the arguments you pass, so no special handling is needed for public methods.
Non Public Methods:
In order to fake non public overloaded methods, specify an overloaded method by passing the types of the arguments using the A::Type<type>() API.
Examples:
class Person { private: bool CanPing(); bool CanPing(bool force); };
To fake CanPing(bool) of class Person, use the following statement
a.CallToPrivate(A::Member(person, CanPing),A::Type<bool>())).WillReturn(true);
To fake CanPing() of class Person, use the following statement
a.CallToPrivate(A::Member(person, CanPing)).WillReturn(true);
To fake CanPing(bool) for specific arguments, use A::Matches instead of A::Type<type> and pass the matching arguments predicate:
a.CallToPrivate(A::Member(person, CanPing),A::Matches([](bool isVal){ return isVal; }).WillReturn(true);
Note: By using A::Matches you can also specifies the types of the arguments using A::Matches<bool>
Static Methods:
To fake static member use A::Global:
class House { private: static bool CanRing(); static bool CanRing(bool now); };
To fake static CanRing(bool) of class House, use the following statement:
a.CallToPrivate(A::Global(House::CanRing),A::Type<bool>()).WillReturn(true);
|
Copyright Typemock Ltd. 2009-2025. All Rights Reserved.