| 4 | #include "platforms/stub/fs_stub.hpp" |
| 5 | |
| 6 | FL_TEST_FILE(FL_FILEPATH) { |
| 7 | |
| 8 | // RAII guard for test files |
| 9 | class FilebufTestGuard { |
| 10 | fl::string mDir; |
| 11 | public: |
| 12 | explicit FilebufTestGuard(const char* dir) : mDir(dir) { |
| 13 | fl::StubFileSystem::forceRemoveDirectory(mDir); |
| 14 | fl::StubFileSystem::createDirectory(mDir); |
| 15 | } |
| 16 | ~FilebufTestGuard() { |
| 17 | fl::StubFileSystem::forceRemoveDirectory(mDir); |
| 18 | } |
| 19 | fl::string filePath(const char* name) const { |
| 20 | fl::string p = mDir; |
| 21 | p.append("/"); |
| 22 | p.append(name); |
| 23 | return p; |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | FL_TEST_CASE("posix_filebuf::size() returns correct file size") { |
| 28 | FilebufTestGuard guard("test_fh_size"); |
| 29 | fl::string path = guard.filePath("test.bin"); |
| 30 | fl::StubFileSystem::createTextFile(path, "0123456789"); |
| 31 | |
| 32 | fl::detail::posix_filebuf fh(path.c_str(), "rb"); |
| 33 | FL_REQUIRE(fh.is_open()); |
| 34 | FL_CHECK_EQ(fh.size(), 10); |
| 35 | } |
| 36 | |
| 37 | FL_TEST_CASE("posix_filebuf::path() returns path passed to constructor") { |
| 38 | FilebufTestGuard guard("test_fh_path"); |
| 39 | fl::string path = guard.filePath("hello.txt"); |
| 40 | fl::StubFileSystem::createTextFile(path, "hi"); |
| 41 | |
| 42 | fl::detail::posix_filebuf fh(path.c_str(), "rb"); |
| 43 | FL_REQUIRE(fh.is_open()); |
| 44 | FL_CHECK_EQ(fl::string(fh.path()), path); |
| 45 | } |
| 46 | |
| 47 | FL_TEST_CASE("filebuf::available() default implementation") { |
| 48 | FilebufTestGuard guard("test_fh_avail"); |
| 49 | fl::string path = guard.filePath("data.txt"); |
| 50 | fl::StubFileSystem::createTextFile(path, "abcd"); |
| 51 | |
| 52 | fl::detail::posix_filebuf fh(path.c_str(), "rb"); |
| 53 | FL_REQUIRE(fh.is_open()); |
| 54 | FL_CHECK(fh.available()); |
| 55 | |
| 56 | // Read all data to trigger EOF |
| 57 | char buf[10]; |
| 58 | fh.read(buf, 10); |
| 59 | FL_CHECK(!fh.available()); // EOF reached |
| 60 | } |
| 61 | |
| 62 | FL_TEST_CASE("filebuf::bytes_left() tracks correctly") { |
| 63 | FilebufTestGuard guard("test_fh_bytes_left"); |
nothing calls this directly
no test coverage detected