MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/fstream.cpp:7–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "test.h"
6
7FL_TEST_FILE(FL_FILEPATH) {
8
9FL_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
17FL_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
35FL_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
61FL_TEST_CASE("fstream errno - error persistence") {
62 fl::ifstream ifs("/nonexistent.txt");
63 FL_CHECK(!ifs.is_open());
64

Callers

nothing calls this directly

Calls 15

createDirectoryFunction · 0.85
removeFileFunction · 0.85
removeDirectoryFunction · 0.85
createTextFileFunction · 0.85
strncmpFunction · 0.85
tellgMethod · 0.80
stringClass · 0.50
is_openMethod · 0.45
failMethod · 0.45
errorMethod · 0.45
findMethod · 0.45
error_messageMethod · 0.45

Tested by

no test coverage detected