Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes Faking abstract classes

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:

 

class MyPureClass

{

public:

   virtual int GetResult() = 0;

}

 

We'll use the following code

 

 

MyPureClass* fakeMyClass = FAKE<MyPureClass>();

WHEN_CALLED(fakeMyClass->GetResult()).Return(10);

 

 

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:

 

 

MyPureClass* fakeMyClass = FAKE<MyPureClass>(ISOLATOR_FORCE_SYMBOL);

 

 

and

 

 

MyPureClass* fakeMyClass = FAKE_ALL<MyPureClass>(ISOLATOR_FORCE_SYMBOL);

 

 


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