1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

FileSystem: update test case

This commit is contained in:
Ivan Grokhotkov 2015-07-30 13:58:00 +03:00
parent 5b82668a75
commit 47a24ef23a

View File

@ -1,6 +1,7 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include "FS.h" #include "FS.h"
void fail(const char* msg) { void fail(const char* msg) {
Serial.println(msg); Serial.println(msg);
while(true) { while(true) {
@ -14,8 +15,8 @@ void setup() {
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
Serial.println("\n\nFS test\n"); Serial.println("\n\nFS test\n");
if (!mount(SPIFFS, "/")) { if (!SPIFFS.begin()) {
fail("mount failed"); fail("SPIFFS init failed");
} }
String text = "write test"; String text = "write test";
@ -62,12 +63,38 @@ void setup() {
{ {
Dir root = SPIFFS.openDir("/"); Dir root = SPIFFS.openDir("/");
while (root.next()) { while (root.next()) {
String fileName = root.fileName(); String fileName = root.fileName();
File f = root.openFile("r"); File f = root.openFile("r");
Serial.printf("%s: %d\r\n", fileName.c_str(), f.size()); Serial.printf("%s: %d\r\n", fileName.c_str(), f.size());
} }
} }
{
Dir root = SPIFFS.openDir("/");
while(root.next()) {
String fileName = root.fileName();
Serial.print("deleting ");
Serial.println(fileName);
if (!SPIFFS.remove(fileName)) {
fail("remove failed");
}
}
}
{
File tmp = SPIFFS.open("/tmp1.txt", "w");
tmp.println("rename test");
}
{
if (!SPIFFS.rename("/tmp1.txt", "/tmp2.txt")) {
fail("rename failed");
}
File tmp2 = SPIFFS.open("/tmp2.txt", "r");
if (!tmp2) {
fail("open tmp2 failed");
}
}
Serial.println("success"); Serial.println("success");
} }