| 5 | #include "test.h" |
| 6 | |
| 7 | FL_TEST_FILE(FL_FILEPATH) { |
| 8 | |
| 9 | FL_TEST_CASE("fstream errno - file not found") { |
| 10 | fl::ifstream ifs("/nonexistent/file.txt"); |
| 11 | FL_CHECK(!ifs.is_open()); |
| 12 | FL_CHECK(ifs.fail()); |
| 13 | FL_CHECK(ifs.error() == ENOENT); |
| 14 | FL_CHECK(fl::string(ifs.error_message()).find("No such file") != fl::string::npos); |
| 15 | } |
| 16 | |
| 17 | FL_TEST_CASE("fstream errno - write after close") { |
| 18 | fl::string test_dir = "test_fstream_errors"; |
| 19 | fl::StubFileSystem::createDirectory(test_dir); |
| 20 | fl::string file_path = test_dir + "/test.txt"; |
| 21 | |
| 22 | fl::ofstream ofs(file_path.c_str()); |
| 23 | FL_REQUIRE(ofs.is_open()); |
| 24 | |
| 25 | ofs.close(); |
| 26 | ofs.write("data", 4); // Write after close |
| 27 | |
| 28 | FL_CHECK(ofs.fail()); |
| 29 | FL_CHECK(ofs.error() != 0); |
| 30 | |
| 31 | fl::StubFileSystem::removeFile(file_path); |
| 32 | fl::StubFileSystem::removeDirectory(test_dir); |
| 33 | } |
| 34 | |
| 35 | FL_TEST_CASE("fstream errno - clear_error recovery") { |
| 36 | fl::string test_dir = "test_fstream_clear"; |
| 37 | fl::StubFileSystem::createDirectory(test_dir); |
| 38 | fl::string file_path = test_dir + "/test.txt"; |
| 39 | fl::StubFileSystem::createTextFile(file_path, "data"); |
| 40 | |
| 41 | fl::ifstream ifs(file_path.c_str()); |
| 42 | FL_REQUIRE(ifs.is_open()); |
| 43 | |
| 44 | // Read to EOF |
| 45 | char buf[10]; |
| 46 | ifs.read(buf, 10); |
| 47 | FL_CHECK(ifs.eof()); |
| 48 | |
| 49 | // Clear and retry |
| 50 | ifs.clear_error(); |
| 51 | FL_CHECK(ifs.good()); |
| 52 | |
| 53 | ifs.seekg(0); |
| 54 | FL_CHECK(ifs.good()); |
| 55 | |
| 56 | ifs.close(); |
| 57 | fl::StubFileSystem::removeFile(file_path); |
| 58 | fl::StubFileSystem::removeDirectory(test_dir); |
| 59 | } |
| 60 | |
| 61 | FL_TEST_CASE("fstream errno - error persistence") { |
| 62 | fl::ifstream ifs("/nonexistent.txt"); |
| 63 | FL_CHECK(!ifs.is_open()); |
| 64 |
nothing calls this directly
no test coverage detected