Introduce proper error handling for file streams
This commit is contained in:
@@ -41,6 +41,7 @@ class TestFileSys : public TestBase
|
||||
void testRemoveRelativePathComponent();
|
||||
void testSafeWriteToFile();
|
||||
void testCopyFileContents();
|
||||
void testNonExist();
|
||||
};
|
||||
|
||||
static TestFileSys g_test_instance;
|
||||
@@ -54,6 +55,7 @@ void TestFileSys::runTests(IGameDef *gamedef)
|
||||
TEST(testRemoveRelativePathComponent);
|
||||
TEST(testSafeWriteToFile);
|
||||
TEST(testCopyFileContents);
|
||||
TEST(testNonExist);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -311,3 +313,27 @@ void TestFileSys::testCopyFileContents()
|
||||
UASSERT(fs::ReadFile(file2, contents_actual));
|
||||
UASSERTEQ(auto, contents_actual, test_data);
|
||||
}
|
||||
|
||||
void TestFileSys::testNonExist()
|
||||
{
|
||||
const auto path = getTestTempFile();
|
||||
fs::DeleteSingleFileOrEmptyDirectory(path);
|
||||
|
||||
UASSERT(!fs::IsFile(path));
|
||||
UASSERT(!fs::IsDir(path));
|
||||
UASSERT(!fs::IsExecutable(path));
|
||||
|
||||
std::string s;
|
||||
UASSERT(!fs::ReadFile(path, s));
|
||||
UASSERT(s.empty());
|
||||
|
||||
UASSERT(!fs::Rename(path, getTestTempFile()));
|
||||
|
||||
std::filebuf buf;
|
||||
// with logging enabled to test that code path
|
||||
UASSERT(!fs::OpenStream(buf, path.c_str(), std::ios::in, false, true));
|
||||
UASSERT(!buf.is_open());
|
||||
|
||||
auto ifs = open_ifstream(path.c_str(), false);
|
||||
UASSERT(!ifs.good());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user