CallOriginal Behavior |
Top Previous Next |
This method is usually used on fully faked instances, to make just one of the functions of them behave as the real implementation. From that moment on, the function will use the original implementation, but other method it calls internally on that same class will return fake results.
class Person { public: int GetAge() { return 10; } string GetName() { return "Mr. Jones"; } };
TEST_F(Examples, CallingOriginalImplementationOnFakedObject) { Person* fakePerson = FAKE<Person>();
WHEN_CALLED(fakePerson->GetAge()).CallOriginal();
// Real implementation called ASSERT_EQ(10, fakePerson->GetAge());
// Fake implementation called ASSERT_STREQ("", fakePerson->GetName());
ISOLATOR_CLEANUP();
}
Calling the original and returning a fake result
To call a method and then return another fake result use the following API
WHEN_CALLED(fakePerson->GetAge()).CallOriginal().Return(5);
Note: To catch an exception thrown in a CallOriginal method on a 64-bit system in your test, use the HandleExceptionInTest flag. For more details, see Setting Default Behavior of a Faked Class. |
Copyright Typemock Ltd. 2009-2025. All Rights Reserved.