forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_FS.ino
More file actions
143 lines (119 loc) · 2.81 KB
/
Copy pathtest_FS.ino
File metadata and controls
143 lines (119 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <ESP8266WiFi.h>
#include "FS.h"
#include <BSTest.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}
TEST_CASE("read-write test","[fs]")
{
REQUIRE(SPIFFS.begin());
String text = "write test";
{
File out = SPIFFS.open("/tmp.txt", "w");
REQUIRE(out);
out.print(text);
}
{
File in = SPIFFS.open("/tmp.txt", "r");
REQUIRE(in);
CHECK(in.size() == text.length());
in.setTimeout(0);
String result = in.readString();
CHECK(result == text);
}
}
TEST_CASE("A bunch of files show up in openDir, and can be removed", "[fs]")
{
REQUIRE(SPIFFS.begin());
const int n = 10;
int found[n] = {0};
{
Dir root = SPIFFS.openDir("");
while (root.next()) {
CHECK(SPIFFS.remove(root.fileName()));
}
}
for (int i = 0; i < n; ++i) {
String name = "/seq_";
name += i;
name += ".txt";
File out = SPIFFS.open(name, "w");
REQUIRE(out);
out.println(i);
}
{
Dir root = SPIFFS.openDir("/");
while (root.next()) {
String fileName = root.fileName();
CHECK(fileName.indexOf("/seq_") == 0);
int i = fileName.substring(5).toInt();
CHECK(i >= 0 && i < n);
found[i]++;
}
for (auto f : found) {
CHECK(f == 1);
}
}
{
Dir root = SPIFFS.openDir("/");
while (root.next()) {
String fileName = root.fileName();
CHECK(SPIFFS.remove(fileName));
}
}
}
TEST_CASE("files can be renamed", "[fs]")
{
REQUIRE(SPIFFS.begin());
{
File tmp = SPIFFS.open("/tmp1.txt", "w");
tmp.println("rename test");
}
{
CHECK(SPIFFS.rename("/tmp1.txt", "/tmp2.txt"));
File tmp2 = SPIFFS.open("/tmp2.txt", "r");
CHECK(tmp2);
}
}
TEST_CASE("FS::info works","[fs]")
{
REQUIRE(SPIFFS.begin());
FSInfo info;
CHECK(SPIFFS.info(info));
Serial.printf("Total: %u\nUsed: %u\nBlock: %u\nPage: %u\nMax open files: %u\nMax path len: %u\n",
info.totalBytes,
info.usedBytes,
info.blockSize,
info.pageSize,
info.maxOpenFiles,
info.maxPathLength
);
}
TEST_CASE("FS is empty after format","[fs]")
{
REQUIRE(SPIFFS.begin());
REQUIRE(SPIFFS.format());
Dir root = SPIFFS.openDir("/");
int count = 0;
while (root.next()) {
++count;
}
CHECK(count == 0);
}
TEST_CASE("Can reopen empty file","[fs]")
{
REQUIRE(SPIFFS.begin());
{
File tmp = SPIFFS.open("/tmp.txt", "w");
}
{
File tmp = SPIFFS.open("/tmp.txt", "w");
CHECK(tmp);
}
}
void loop()
{
}