Skip to content

Commit fd1d9da

Browse files
committed
FileSystem: update test case
1 parent 71b2166 commit fd1d9da

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

hardware/esp8266com/esp8266/tests/FSWrapper/FSWrapper.ino

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <ESP8266WiFi.h>
22
#include "FS.h"
33

4+
45
void fail(const char* msg) {
56
Serial.println(msg);
67
while(true) {
@@ -14,8 +15,8 @@ void setup() {
1415
WiFi.mode(WIFI_OFF);
1516
Serial.println("\n\nFS test\n");
1617

17-
if (!mount(SPIFFS, "/")) {
18-
fail("mount failed");
18+
if (!SPIFFS.begin()) {
19+
fail("SPIFFS init failed");
1920
}
2021

2122
String text = "write test";
@@ -62,12 +63,38 @@ void setup() {
6263
{
6364
Dir root = SPIFFS.openDir("/");
6465
while (root.next()) {
66+
String fileName = root.fileName();
67+
File f = root.openFile("r");
68+
Serial.printf("%s: %d\r\n", fileName.c_str(), f.size());
69+
}
70+
}
71+
72+
{
73+
Dir root = SPIFFS.openDir("/");
74+
while(root.next()) {
6575
String fileName = root.fileName();
66-
File f = root.openFile("r");
67-
Serial.printf("%s: %d\r\n", fileName.c_str(), f.size());
76+
Serial.print("deleting ");
77+
Serial.println(fileName);
78+
if (!SPIFFS.remove(fileName)) {
79+
fail("remove failed");
80+
}
6881
}
6982
}
7083

84+
{
85+
File tmp = SPIFFS.open("/tmp1.txt", "w");
86+
tmp.println("rename test");
87+
}
88+
89+
{
90+
if (!SPIFFS.rename("/tmp1.txt", "/tmp2.txt")) {
91+
fail("rename failed");
92+
}
93+
File tmp2 = SPIFFS.open("/tmp2.txt", "r");
94+
if (!tmp2) {
95+
fail("open tmp2 failed");
96+
}
97+
}
7198

7299
Serial.println("success");
73100
}

0 commit comments

Comments
 (0)