Can Isolator++ fake the std::ifstream class?
The following is my test code. The CTouchFile::Touch() is the function under test which does the following:
1. Accepts a file name parameter
2. Calls std::ifstream::open() to open the file
3. Calls std::ifstream::is_open() to check if the file is opened
4. If std::ifstream::is_open() returns true, then calls std::ifstream::close() to close the file, otherwise not.
The test code is testing "if the file exists, then both std::ifstream::open() and std::ifstream::close() should be called". It tries to fake the std::ifstream class and control is_open() return value:
TEST(CTouchFileTests, Touch_FileExists_CallsFileOpenAndClose)
{
// Arrange
std::ifstream *fakeFileStream = FAKE_ALL<std::ifstream>();
WHEN_CALLED(fakeFileStream->is_open()).Return(true);
// Act
CTouchFile touchFile;
touchFile.Touch("somefile.dll");
// Assert
ASSERT_WAS_CALLED(fakeFileStream->open("somefile.dll", _));
ASSERT_WAS_CALLED(fakeFileStream->close());
}
The test code compiles without errors. However, when running the test, I got the following exception: "The class 'std::basic_ifstream<char,struct std::char_traits<char> >' is an internal system class, hence cannot be faked".
Is this a known limitation for Isolator++? If yes, is there any other way to fake the std::ifstream class?