Faking abstract classes and pure virtual methods
|Top Previous Next|
With Isolator++ Professional, you use the same syntax for changing the behavior of any classes, including abstract ones.
Let's say we want to change the behavior of a virtual method:
We'll use the following code
First, we're creating a fake object using the FAKE API. This fakes all the methods on the MyClass class. Primitives return 0, and methods returning pointers, return pointers to fake objects. To further change specific methods, we used the regular WHEN_CALLED API to declare the behavior we want. In this case, we're returning the value 10.
Note: Isolator++ Professional will automatically fake all the methods in the hierarchy.
Note: There are times that the compiler optimizes out the virtual methods, and Isolator++ won't be able to fake them. In order to force the compiler to create the method so it can be faked use: ISOLATOR_FORCE_SYMBOL as follows:
Copyright Typemock Ltd. 2009-2023. All Rights Reserved.