Here's a short example. Let's look at our Product class' method IsExpired:
bool Product::IsExpired()
{
SYSTEMTIME now;
::GetSystemTime(&now);
if (now.wYear > 2017)
return true;
return false;
}
The method has a dependency on the time when the code is run. How can we test the result for a year after 2017?
With Isolator++'s macros (in red), you can simply change the behavior of the GetSystemTime method:
TEST_F(IsolatorPPTests, IsExpired_YearIs2018_ReturnTrue)
{
Product product;
// Prepare a future time construct
SYSTEMTIME fakeTime;
fakeTime.wYear = 2018;
// Fake the GetSystemTime method
FAKE_GLOBAL(GetSystemTime);
// Replace the returned value when the method is called
// with the fake value.
WHEN_CALLED(GetSystemTime(RET(&fakeTime))).Ignore();
ASSERT_TRUE(product.IsExpired());
}
When the IsExpired method is called, the call to GetSystemTime is ignored, and then returns the value we supply - our future time construct.
Without changing the code, we actually we able to simulate the GetSystemTime to check a second path in the code.
Isolator++ works with Visual Studio 2005, 2008, 2010, 2012 and 2013 in both 32 and 64 bit.